Skip to content

Commit 122a623

Browse files
committed
Email pattern to requests.emails
1 parent 668d6ad commit 122a623

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pygithub3/requests/users/emails.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
from . import Request, ValidationError
77

8+
# Src: http://code.djangoproject.com/svn/django/trunk/django/core/validators.py
9+
email_re = re.compile(
10+
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
11+
# quoted-string, see also http://tools.ietf.org/html/rfc2822#section-3.2.5
12+
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"'
13+
r')@((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$)' # domain
14+
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) # literal form, ipv4 address (SMTP 4.1.3)
15+
816

917
class List(Request):
1018

@@ -17,7 +25,7 @@ class Add(Request):
1725

1826
def clean_body(self):
1927
def is_email(email):
20-
return re.match(r'.*', email) # TODO: email regex ;)
28+
return bool(email_re.match(email)) # TODO: email regex ;)
2129
if not self.body:
2230
raise ValidationError("'%s' request needs emails"
2331
% (self.__class__.__name__))
@@ -28,3 +36,9 @@ def is_email(email):
2836
class Delete(Request):
2937

3038
uri = 'user/emails'
39+
40+
def clean_body(self):
41+
if not self.body:
42+
raise ValidationError("'%s' request needs emails"
43+
% (self.__class__.__name__))
44+
return self.body

0 commit comments

Comments
 (0)