OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import re | |
6 import urllib2 | |
7 | |
8 # FIXME: This probably belongs in config.py? | |
9 BLINK_SHERIFF_URL = ( | |
10 'http://build.chromium.org/p/chromium.webkit/sheriff_webkit.js') | |
11 | |
12 | |
13 # Does not support unicode or special characters. | |
14 VALID_EMAIL_REGEXP = re.compile(r'^[A-Za-z0-9\.&\'\+-/=_]+@' | |
15 '[A-Za-z0-9\.-]+$') | |
ojan
2014/06/01 02:59:09
Nit: Why the linewrap?
| |
16 | |
17 | |
18 def _complete_email(name): | |
ojan
2014/06/01 02:59:09
All these functions should be super easy to unitte
| |
19 """If the name does not include '@', append '@chromium.org'.""" | |
20 if '@' not in name: | |
21 return name + '@chromium.org' | |
22 return name | |
23 | |
24 | |
25 def _names_from_sheriff_js(sheriff_js): | |
26 match = re.match(r'document.write\(\'(.*)\'\)', sheriff_js) | |
27 emails_string = match.group(1) | |
28 # Detect 'none (channel is sheriff)' text and ignore it. | |
29 if 'channel is sheriff' in emails_string.lower(): | |
30 return [] | |
31 return map(str.strip, emails_string.split(',')) | |
32 | |
33 | |
34 def _email_is_valid(email): | |
35 """Determines whether the given email address is valid.""" | |
36 return VALID_EMAIL_REGEXP.match(email) is not None | |
37 | |
38 | |
39 def _filter_emails(emails): | |
40 """Returns the given list with any invalid email addresses removed.""" | |
41 rv = [] | |
42 for email in emails: | |
43 if _email_is_valid(email): | |
44 rv.append(email) | |
45 else: | |
46 print 'WARNING: Not including %s (invalid email address)' % email | |
47 return rv | |
48 | |
49 | |
50 def _emails_from_url(sheriff_url): | |
51 sheriff_js = urllib2.urlopen(sheriff_url).read() | |
52 return map(_complete_email, _names_from_sheriff_js(sheriff_js)) | |
53 | |
54 | |
55 def current_gardener_emails(): | |
56 return _emails_from_url(BLINK_SHERIFF_URL) | |
OLD | NEW |