Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use bytes for all custom email validations
Browse files Browse the repository at this point in the history
salehe committed Dec 5, 2015
1 parent 12b75f0 commit dbdfb65
Showing 6 changed files with 43 additions and 43 deletions.
10 changes: 5 additions & 5 deletions flanker/addresslib/plugins/aol.py
Original file line number Diff line number Diff line change
@@ -21,23 +21,23 @@
import re
from flanker.addresslib.tokenizer import TokenStream

ALPHA = re.compile(r'''
ALPHA = re.compile(br'''
[A-Za-z]+
''', re.MULTILINE | re.VERBOSE)

NUMERIC = re.compile(r'''
NUMERIC = re.compile(br'''
[0-9]+
''', re.MULTILINE | re.VERBOSE)

ALPHANUM = re.compile(r'''
ALPHANUM = re.compile(br'''
[A-Za-z0-9]+
''', re.MULTILINE | re.VERBOSE)

DOT = re.compile(r'''
DOT = re.compile(br'''
\.
''', re.MULTILINE | re.VERBOSE)

UNDERSCORE = re.compile(r'''
UNDERSCORE = re.compile(br'''
\_
''', re.MULTILINE | re.VERBOSE)

12 changes: 6 additions & 6 deletions flanker/addresslib/plugins/gmail.py
Original file line number Diff line number Diff line change
@@ -32,18 +32,18 @@
from flanker.addresslib.tokenizer import ATOM


GMAIL_BASE = re.compile(r'''
GMAIL_BASE = re.compile(br'''
[A-Za-z0-9\.]+
''', re.MULTILINE | re.VERBOSE)

ALPHANUM = re.compile(r'''
ALPHANUM = re.compile(br'''
[A-Za-z0-9]+
''', re.MULTILINE | re.VERBOSE)

PLUS = re.compile(r'''
PLUS = re.compile(br'''
[\+]
''', re.MULTILINE | re.VERBOSE)
DOT = re.compile(r'''
DOT = re.compile(br'''
[\.]
''', re.MULTILINE | re.VERBOSE)

@@ -53,9 +53,9 @@ def validate(localpart):
if not localpart:
return False

lparts = localpart.split('+')
lparts = localpart.split(b'+')
real_localpart = lparts[0]
stripped_localpart = real_localpart.replace('.', '')
stripped_localpart = real_localpart.replace(b'.', b'')

# length check
l = len(stripped_localpart)
16 changes: 8 additions & 8 deletions flanker/addresslib/plugins/google.py
Original file line number Diff line number Diff line change
@@ -32,31 +32,31 @@
from flanker.addresslib.tokenizer import ATOM


GOOGLE_BASE = re.compile(r'''
GOOGLE_BASE = re.compile(br'''
[A-Za-z0-9_\-'\.]+
''', re.MULTILINE | re.VERBOSE)

ALPHANUM = re.compile(r'''
ALPHANUM = re.compile(br'''
[A-Za-z0-9]+
''', re.MULTILINE | re.VERBOSE)

UNDERSCORE = re.compile(r'''
UNDERSCORE = re.compile(br'''
[_]+
''', re.MULTILINE | re.VERBOSE)

APOSTROPHES = re.compile(r'''
APOSTROPHES = re.compile(br'''
[']+
''', re.MULTILINE | re.VERBOSE)

DASH = re.compile(r'''
DASH = re.compile(br'''
[-]+
''', re.MULTILINE | re.VERBOSE)

DOTS = re.compile(r'''
DOTS = re.compile(br'''
[.]+
''', re.MULTILINE | re.VERBOSE)

PLUS = re.compile(r'''
PLUS = re.compile(br'''
[\+]+
''', re.MULTILINE | re.VERBOSE)

@@ -66,7 +66,7 @@ def validate(localpart):
if not localpart:
return False

lparts = localpart.split('+')
lparts = localpart.split(b'+')
real_localpart = lparts[0]

# length check
14 changes: 7 additions & 7 deletions flanker/addresslib/plugins/hotmail.py
Original file line number Diff line number Diff line change
@@ -32,23 +32,23 @@
import re
from flanker.addresslib.tokenizer import TokenStream

HOTMAIL_PREFIX = re.compile(r'''
HOTMAIL_PREFIX = re.compile(br'''
[A-Za-z0-9]+
''', re.MULTILINE | re.VERBOSE)

HOTMAIL_BASE = re.compile(r'''
HOTMAIL_BASE = re.compile(br'''
[A-Za-z0-9\.\-\_]+
''', re.MULTILINE | re.VERBOSE)

HOTMAIL_SUFFIX = re.compile(r'''
HOTMAIL_SUFFIX = re.compile(br'''
[A-Za-z0-9\-\_]+
''', re.MULTILINE | re.VERBOSE)

PLUS = re.compile(r'''
PLUS = re.compile(br'''
\+
''', re.MULTILINE | re.VERBOSE)

PERIODS = re.compile(r'''
PERIODS = re.compile(br'''
\.{2,}
''', re.MULTILINE | re.VERBOSE)

@@ -59,7 +59,7 @@ def validate(localpart):
return False

# remove tag if it exists
lparts = localpart.split('+')
lparts = localpart.split(b'+')
real_localpart = lparts[0]

# length check
@@ -76,7 +76,7 @@ def validate(localpart):
return False

# no more than one plus (+)
if localpart.count('+') > 1:
if localpart.count(b'+') > 1:
return False

# no consecutive periods (..)
16 changes: 8 additions & 8 deletions flanker/addresslib/plugins/icloud.py
Original file line number Diff line number Diff line change
@@ -35,28 +35,28 @@
import re
from flanker.addresslib.tokenizer import TokenStream

ALPHA = re.compile(r'''
ALPHA = re.compile(br'''
[A-Za-z]+
''', re.MULTILINE | re.VERBOSE)

ALPHANUM = re.compile(r'''
ALPHANUM = re.compile(br'''
[A-Za-z0-9]+
''', re.MULTILINE | re.VERBOSE)


ICLOUD_PREFIX = re.compile(r'''
ICLOUD_PREFIX = re.compile(br'''
[A-Za-z]+
''', re.MULTILINE | re.VERBOSE)

ICLOUD_BASE = re.compile(r'''
ICLOUD_BASE = re.compile(br'''
[A-Za-z0-9\+]+
''', re.MULTILINE | re.VERBOSE)

DOT = re.compile(r'''
DOT = re.compile(br'''
\.
''', re.MULTILINE | re.VERBOSE)

UNDERSCORE = re.compile(r'''
UNDERSCORE = re.compile(br'''
\_
''', re.MULTILINE | re.VERBOSE)

@@ -66,7 +66,7 @@ def validate(localpart):
if not localpart:
return False

lparts = localpart.split('+')
lparts = localpart.split(b'+')
real_localpart = lparts[0]

# length check
@@ -75,7 +75,7 @@ def validate(localpart):
return False

# can not end with +
if localpart[-1] == '+':
if localpart[-1] == b'+':
return False

# must start with letter
18 changes: 9 additions & 9 deletions flanker/addresslib/plugins/yahoo.py
Original file line number Diff line number Diff line change
@@ -44,27 +44,27 @@
import re
from flanker.addresslib.tokenizer import TokenStream

ALPHA = re.compile(r'''
ALPHA = re.compile(br'''
[A-Za-z]+
''', re.MULTILINE | re.VERBOSE)

NUMERIC = re.compile(r'''
NUMERIC = re.compile(br'''
[0-9]+
''', re.MULTILINE | re.VERBOSE)

ALPHANUM = re.compile(r'''
ALPHANUM = re.compile(br'''
[A-Za-z0-9]+
''', re.MULTILINE | re.VERBOSE)

DOT = re.compile(r'''
DOT = re.compile(br'''
\.
''', re.MULTILINE | re.VERBOSE)

UNDERSCORE = re.compile(r'''
UNDERSCORE = re.compile(br'''
\_
''', re.MULTILINE | re.VERBOSE)

HYPHEN = re.compile(r'''
HYPHEN = re.compile(br'''
\-
''', re.MULTILINE | re.VERBOSE)

@@ -97,7 +97,7 @@ def _validate_primary(localpart):
return False

# no more than one dot (.)
if localpart.count('.') > 1:
if localpart.count(b'.') > 1:
return False

# Grammar: local-part -> alpha { [ dot | underscore ] ( alpha | num ) }"
@@ -130,11 +130,11 @@ def _validate_disposable(localpart):
return False

# single hyphen
if localpart.count('-') != 1:
if localpart.count(b'-') != 1:
return False

# base and keyword length limit
parts = localpart.split('-')
parts = localpart.split(b'-')
for part in parts:
l = len(part)
if l < 1 or l > 32:

0 comments on commit dbdfb65

Please sign in to comment.