Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix regexp to match rfc 6532 addresses #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ def test_email(self):
res = extract_error(t.Email, 123)
self.assertEqual(res, 'value is not a string')

def test_with_cyrillic_C_in_contact(self):
res = t.Email.check(u'contaсt@kmgaszbut.104.ua')
self.assertEqual(res, u'contaсt@kmgaszbut.104.ua')

class TestEnumTrafaret(unittest.TestCase):
def test_enum(self):
Expand Down
6 changes: 4 additions & 2 deletions trafaret/internet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@

MAX_EMAIL_LEN = 254

ATEXT = r"-!#$%&'*+/=?^_`{}|~0-9A-Z"
ATEXT_UTF8 = ATEXT + u"\u0080-\U0010FFFF"

EMAIL_REGEXP = re.compile(
# dot-atom
r"(?P<name>^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"
r"(?P<name>^[" + ATEXT_UTF8 + "]+(\.[" + ATEXT_UTF8 + "]+)*"
# quoted-string
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"'
# domain
r')@(?P<domain>(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)$)'
# literal form, ipv4 address (SMTP 4.1.3)
r'|\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$',
re.IGNORECASE,
re.IGNORECASE | re.UNICODE,
)


Expand Down