aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/requests/users/emails.py
diff options
context:
space:
mode:
authorDavid Medina <davidmedina9@gmail.com>2012-02-11 19:28:32 +0100
committerDavid Medina <davidmedina9@gmail.com>2012-02-11 21:44:10 +0100
commit122a623d83bdcf90df79e71b6a8637f32322b281 (patch)
treee324a48ed8755d8cc44cb1e19fdc56a3c54b954a /pygithub3/requests/users/emails.py
parentChange requests.Body to suppor required attributes (diff)
downloadpython-github3-122a623d83bdcf90df79e71b6a8637f32322b281.tar.xz
python-github3-122a623d83bdcf90df79e71b6a8637f32322b281.zip
Email pattern to requests.emails
Diffstat (limited to 'pygithub3/requests/users/emails.py')
-rw-r--r--pygithub3/requests/users/emails.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/pygithub3/requests/users/emails.py b/pygithub3/requests/users/emails.py
index 410bd9a..ae4d8b8 100644
--- a/pygithub3/requests/users/emails.py
+++ b/pygithub3/requests/users/emails.py
@@ -5,6 +5,14 @@ import re
from . import Request, ValidationError
+# Src: http://code.djangoproject.com/svn/django/trunk/django/core/validators.py
+email_re = re.compile(
+ r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
+ # quoted-string, see also http://tools.ietf.org/html/rfc2822#section-3.2.5
+ r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"'
+ r')@((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$)' # domain
+ 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)
+
class List(Request):
@@ -17,7 +25,7 @@ class Add(Request):
def clean_body(self):
def is_email(email):
- return re.match(r'.*', email) # TODO: email regex ;)
+ return bool(email_re.match(email)) # TODO: email regex ;)
if not self.body:
raise ValidationError("'%s' request needs emails"
% (self.__class__.__name__))
@@ -28,3 +36,9 @@ class Add(Request):
class Delete(Request):
uri = 'user/emails'
+
+ def clean_body(self):
+ if not self.body:
+ raise ValidationError("'%s' request needs emails"
+ % (self.__class__.__name__))
+ return self.body