Mercurial > cpython-lru_cache-weakref
annotate Lib/email/_parseaddr.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | a283563c8cc4 |
| children |
| rev | line source |
|---|---|
|
41118
d850bf56fdf6
Tokio Kikuchi's fix for SF bug #1629369; folding whitespace allowed in the
Barry Warsaw <barry@python.org>
parents:
38063
diff
changeset
|
1 # Copyright (C) 2002-2007 Python Software Foundation |
|
33651
946612f64a83
Big email 3.0 API changes, with updated unit tests and documentation.
Barry Warsaw <barry@python.org>
parents:
33002
diff
changeset
|
2 # Contact: email-sig@python.org |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
3 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
4 """Email address parsing code. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
5 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
6 Lifted directly from rfc822.py. This should eventually be rewritten. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
7 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
8 |
|
37078
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36433
diff
changeset
|
9 __all__ = [ |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36433
diff
changeset
|
10 'mktime_tz', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36433
diff
changeset
|
11 'parsedate', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36433
diff
changeset
|
12 'parsedate_tz', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36433
diff
changeset
|
13 'quote', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36433
diff
changeset
|
14 ] |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36433
diff
changeset
|
15 |
|
77562
a283563c8cc4
Issue #14653: email.utils.mktime_tz() no longer relies on system
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65064
diff
changeset
|
16 import time, calendar |
| 26850 | 17 |
| 18 SPACE = ' ' | |
| 19 EMPTYSTRING = '' | |
| 20 COMMASPACE = ', ' | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
21 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
22 # Parse a date field |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
23 _monthnames = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
24 'aug', 'sep', 'oct', 'nov', 'dec', |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
25 'january', 'february', 'march', 'april', 'may', 'june', 'july', |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
26 'august', 'september', 'october', 'november', 'december'] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
27 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
28 _daynames = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
29 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
30 # The timezone table does not include the military time zones defined |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
31 # in RFC822, other than Z. According to RFC1123, the description in |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
32 # RFC822 gets the signs wrong, so we can't rely on any such time |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
33 # zones. RFC1123 recommends that numeric timezone indicators be used |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
34 # instead of timezone names. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
35 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
36 _timezones = {'UT':0, 'UTC':0, 'GMT':0, 'Z':0, |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
37 'AST': -400, 'ADT': -300, # Atlantic (used in Canada) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
38 'EST': -500, 'EDT': -400, # Eastern |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
39 'CST': -600, 'CDT': -500, # Central |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
40 'MST': -700, 'MDT': -600, # Mountain |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
41 'PST': -800, 'PDT': -700 # Pacific |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
42 } |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
43 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
44 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
45 def parsedate_tz(data): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
46 """Convert a date string to a time tuple. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
47 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
48 Accounts for military timezones. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
49 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
50 data = data.split() |
|
26853
2ce8cf284b15
parsedate_tz(): Fix SF bug #552345, optional FWS between the comma and
Barry Warsaw <barry@python.org>
parents:
26850
diff
changeset
|
51 # The FWS after the comma after the day-of-week is optional, so search and |
|
2ce8cf284b15
parsedate_tz(): Fix SF bug #552345, optional FWS between the comma and
Barry Warsaw <barry@python.org>
parents:
26850
diff
changeset
|
52 # adjust for this. |
|
2ce8cf284b15
parsedate_tz(): Fix SF bug #552345, optional FWS between the comma and
Barry Warsaw <barry@python.org>
parents:
26850
diff
changeset
|
53 if data[0].endswith(',') or data[0].lower() in _daynames: |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
54 # There's a dayname here. Skip it |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
55 del data[0] |
|
26853
2ce8cf284b15
parsedate_tz(): Fix SF bug #552345, optional FWS between the comma and
Barry Warsaw <barry@python.org>
parents:
26850
diff
changeset
|
56 else: |
|
2ce8cf284b15
parsedate_tz(): Fix SF bug #552345, optional FWS between the comma and
Barry Warsaw <barry@python.org>
parents:
26850
diff
changeset
|
57 i = data[0].rfind(',') |
|
29027
6bba48d1ce3b
parsedate_tz(): Be slightly more lenient when there's no day of the
Barry Warsaw <barry@python.org>
parents:
28317
diff
changeset
|
58 if i >= 0: |
|
6bba48d1ce3b
parsedate_tz(): Be slightly more lenient when there's no day of the
Barry Warsaw <barry@python.org>
parents:
28317
diff
changeset
|
59 data[0] = data[0][i+1:] |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
60 if len(data) == 3: # RFC 850 date, deprecated |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
61 stuff = data[0].split('-') |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
62 if len(stuff) == 3: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
63 data = stuff + data[1:] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
64 if len(data) == 4: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
65 s = data[3] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
66 i = s.find('+') |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
67 if i > 0: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
68 data[3:] = [s[:i], s[i+1:]] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
69 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
70 data.append('') # Dummy tz |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
71 if len(data) < 5: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
72 return None |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
73 data = data[:5] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
74 [dd, mm, yy, tm, tz] = data |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
75 mm = mm.lower() |
| 26850 | 76 if mm not in _monthnames: |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
77 dd, mm = mm, dd.lower() |
| 26850 | 78 if mm not in _monthnames: |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
79 return None |
| 26850 | 80 mm = _monthnames.index(mm) + 1 |
| 81 if mm > 12: | |
| 82 mm -= 12 | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
83 if dd[-1] == ',': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
84 dd = dd[:-1] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
85 i = yy.find(':') |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
86 if i > 0: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
87 yy, tm = tm, yy |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
88 if yy[-1] == ',': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
89 yy = yy[:-1] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
90 if not yy[0].isdigit(): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
91 yy, tz = tz, yy |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
92 if tm[-1] == ',': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
93 tm = tm[:-1] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
94 tm = tm.split(':') |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
95 if len(tm) == 2: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
96 [thh, tmm] = tm |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
97 tss = '0' |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
98 elif len(tm) == 3: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
99 [thh, tmm, tss] = tm |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
100 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
101 return None |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
102 try: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
103 yy = int(yy) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
104 dd = int(dd) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
105 thh = int(thh) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
106 tmm = int(tmm) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
107 tss = int(tss) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
108 except ValueError: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
109 return None |
|
64275
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
110 # Check for a yy specified in two-digit format, then convert it to the |
|
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
111 # appropriate four-digit format, according to the POSIX standard. RFC 822 |
|
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
112 # calls for a two-digit yy, but RFC 2822 (which obsoletes RFC 822) |
|
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
113 # mandates a 4-digit yy. For more information, see the documentation for |
|
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
114 # the time module. |
|
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
115 if yy < 100: |
|
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
116 # The year is between 1969 and 1999 (inclusive). |
|
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
117 if yy > 68: |
|
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
118 yy += 1900 |
|
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
119 # The year is between 2000 and 2068 (inclusive). |
|
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
120 else: |
|
f6b3e64b7620
Merged revisions 84310 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
48150
diff
changeset
|
121 yy += 2000 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
122 tzoffset = None |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
123 tz = tz.upper() |
|
48150
d4db5ded76ce
Remove a dict.has_key() usage in email._parseaddr found while running -3.
Brett Cannon <bcannon@gmail.com>
parents:
41118
diff
changeset
|
124 if tz in _timezones: |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
125 tzoffset = _timezones[tz] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
126 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
127 try: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
128 tzoffset = int(tz) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
129 except ValueError: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
130 pass |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
131 # Convert a timezone offset into seconds ; -0500 -> -18000 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
132 if tzoffset: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
133 if tzoffset < 0: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
134 tzsign = -1 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
135 tzoffset = -tzoffset |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
136 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
137 tzsign = 1 |
|
33651
946612f64a83
Big email 3.0 API changes, with updated unit tests and documentation.
Barry Warsaw <barry@python.org>
parents:
33002
diff
changeset
|
138 tzoffset = tzsign * ( (tzoffset//100)*3600 + (tzoffset % 100)*60) |
|
37421
7986a5b131ed
The email module's parsedate_tz function now sets the daylight savings
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37078
diff
changeset
|
139 # Daylight Saving Time flag is set to -1, since DST is unknown. |
|
7986a5b131ed
The email module's parsedate_tz function now sets the daylight savings
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37078
diff
changeset
|
140 return yy, mm, dd, thh, tmm, tss, 0, 1, -1, tzoffset |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
141 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
142 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
143 def parsedate(data): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
144 """Convert a time string to a time tuple.""" |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
145 t = parsedate_tz(data) |
|
32025
f4376f7674a2
Update to Python 2.3, getting rid of backward compatiblity crud.
Barry Warsaw <barry@python.org>
parents:
29443
diff
changeset
|
146 if isinstance(t, tuple): |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
147 return t[:9] |
| 26850 | 148 else: |
| 149 return t | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
150 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
151 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
152 def mktime_tz(data): |
|
77562
a283563c8cc4
Issue #14653: email.utils.mktime_tz() no longer relies on system
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65064
diff
changeset
|
153 """Turn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp.""" |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
154 if data[9] is None: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
155 # No zone info, so localtime is better assumption than GMT |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
156 return time.mktime(data[:8] + (-1,)) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
157 else: |
|
77562
a283563c8cc4
Issue #14653: email.utils.mktime_tz() no longer relies on system
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65064
diff
changeset
|
158 t = calendar.timegm(data) |
|
a283563c8cc4
Issue #14653: email.utils.mktime_tz() no longer relies on system
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65064
diff
changeset
|
159 return t - data[9] |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
160 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
161 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
162 def quote(str): |
|
65064
f3a70d99d7e0
Merged revisions 85179 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
64275
diff
changeset
|
163 """Prepare string to be used in a quoted string. |
|
f3a70d99d7e0
Merged revisions 85179 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
64275
diff
changeset
|
164 |
|
f3a70d99d7e0
Merged revisions 85179 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
64275
diff
changeset
|
165 Turns backslash and double quote characters into quoted pairs. These |
|
f3a70d99d7e0
Merged revisions 85179 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
64275
diff
changeset
|
166 are the only characters that need to be quoted inside a quoted string. |
|
f3a70d99d7e0
Merged revisions 85179 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
64275
diff
changeset
|
167 Does not add the surrounding double quotes. |
|
f3a70d99d7e0
Merged revisions 85179 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
64275
diff
changeset
|
168 """ |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
169 return str.replace('\\', '\\\\').replace('"', '\\"') |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
170 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
171 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
172 class AddrlistClass: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
173 """Address parser class by Ben Escoto. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
174 |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
175 To understand what this class does, it helps to have a copy of RFC 2822 in |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
176 front of you. |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
177 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
178 Note: this class interface is deprecated and may be removed in the future. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
179 Use rfc822.AddressList instead. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
180 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
181 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
182 def __init__(self, field): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
183 """Initialize a new instance. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
184 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
185 `field' is an unparsed address header field, containing |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
186 one or more addresses. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
187 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
188 self.specials = '()<>@,:;.\"[]' |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
189 self.pos = 0 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
190 self.LWS = ' \t' |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
191 self.CR = '\r\n' |
|
41118
d850bf56fdf6
Tokio Kikuchi's fix for SF bug #1629369; folding whitespace allowed in the
Barry Warsaw <barry@python.org>
parents:
38063
diff
changeset
|
192 self.FWS = self.LWS + self.CR |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
193 self.atomends = self.specials + self.LWS + self.CR |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
194 # Note that RFC 2822 now specifies `.' as obs-phrase, meaning that it |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
195 # is obsolete syntax. RFC 2822 requires that we recognize obsolete |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
196 # syntax, so allow dots in phrases. |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
197 self.phraseends = self.atomends.replace('.', '') |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
198 self.field = field |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
199 self.commentlist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
200 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
201 def gotonext(self): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
202 """Parse up to the start of the next address.""" |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
203 while self.pos < len(self.field): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
204 if self.field[self.pos] in self.LWS + '\n\r': |
| 26850 | 205 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
206 elif self.field[self.pos] == '(': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
207 self.commentlist.append(self.getcomment()) |
| 26850 | 208 else: |
| 209 break | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
210 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
211 def getaddrlist(self): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
212 """Parse all addresses. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
213 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
214 Returns a list containing all of the addresses. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
215 """ |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
216 result = [] |
|
28317
023d3b50e597
getaddrlist(): Make sure this consumes all the data, and if there is
Barry Warsaw <barry@python.org>
parents:
26853
diff
changeset
|
217 while self.pos < len(self.field): |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
218 ad = self.getaddress() |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
219 if ad: |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
220 result += ad |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
221 else: |
|
28317
023d3b50e597
getaddrlist(): Make sure this consumes all the data, and if there is
Barry Warsaw <barry@python.org>
parents:
26853
diff
changeset
|
222 result.append(('', '')) |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
223 return result |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
224 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
225 def getaddress(self): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
226 """Parse the next address.""" |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
227 self.commentlist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
228 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
229 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
230 oldpos = self.pos |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
231 oldcl = self.commentlist |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
232 plist = self.getphraselist() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
233 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
234 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
235 returnlist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
236 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
237 if self.pos >= len(self.field): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
238 # Bad email address technically, no domain. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
239 if plist: |
| 26850 | 240 returnlist = [(SPACE.join(self.commentlist), plist[0])] |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
241 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
242 elif self.field[self.pos] in '.@': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
243 # email address is just an addrspec |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
244 # this isn't very efficient since we start over |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
245 self.pos = oldpos |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
246 self.commentlist = oldcl |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
247 addrspec = self.getaddrspec() |
| 26850 | 248 returnlist = [(SPACE.join(self.commentlist), addrspec)] |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
249 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
250 elif self.field[self.pos] == ':': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
251 # address is a group |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
252 returnlist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
253 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
254 fieldlen = len(self.field) |
| 26850 | 255 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
256 while self.pos < len(self.field): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
257 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
258 if self.pos < fieldlen and self.field[self.pos] == ';': |
| 26850 | 259 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
260 break |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
261 returnlist = returnlist + self.getaddress() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
262 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
263 elif self.field[self.pos] == '<': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
264 # Address is a phrase then a route addr |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
265 routeaddr = self.getrouteaddr() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
266 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
267 if self.commentlist: |
| 26850 | 268 returnlist = [(SPACE.join(plist) + ' (' + |
| 269 ' '.join(self.commentlist) + ')', routeaddr)] | |
| 270 else: | |
| 271 returnlist = [(SPACE.join(plist), routeaddr)] | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
272 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
273 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
274 if plist: |
| 26850 | 275 returnlist = [(SPACE.join(self.commentlist), plist[0])] |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
276 elif self.field[self.pos] in self.specials: |
| 26850 | 277 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
278 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
279 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
280 if self.pos < len(self.field) and self.field[self.pos] == ',': |
| 26850 | 281 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
282 return returnlist |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
283 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
284 def getrouteaddr(self): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
285 """Parse a route address (Return-path value). |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
286 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
287 This method just skips all the route stuff and returns the addrspec. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
288 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
289 if self.field[self.pos] != '<': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
290 return |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
291 |
| 26850 | 292 expectroute = False |
| 293 self.pos += 1 | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
294 self.gotonext() |
| 26850 | 295 adlist = '' |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
296 while self.pos < len(self.field): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
297 if expectroute: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
298 self.getdomain() |
| 26850 | 299 expectroute = False |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
300 elif self.field[self.pos] == '>': |
| 26850 | 301 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
302 break |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
303 elif self.field[self.pos] == '@': |
| 26850 | 304 self.pos += 1 |
| 305 expectroute = True | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
306 elif self.field[self.pos] == ':': |
| 26850 | 307 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
308 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
309 adlist = self.getaddrspec() |
| 26850 | 310 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
311 break |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
312 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
313 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
314 return adlist |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
315 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
316 def getaddrspec(self): |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
317 """Parse an RFC 2822 addr-spec.""" |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
318 aslist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
319 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
320 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
321 while self.pos < len(self.field): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
322 if self.field[self.pos] == '.': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
323 aslist.append('.') |
| 26850 | 324 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
325 elif self.field[self.pos] == '"': |
|
65064
f3a70d99d7e0
Merged revisions 85179 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
64275
diff
changeset
|
326 aslist.append('"%s"' % quote(self.getquote())) |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
327 elif self.field[self.pos] in self.atomends: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
328 break |
| 26850 | 329 else: |
| 330 aslist.append(self.getatom()) | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
331 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
332 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
333 if self.pos >= len(self.field) or self.field[self.pos] != '@': |
| 26850 | 334 return EMPTYSTRING.join(aslist) |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
335 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
336 aslist.append('@') |
| 26850 | 337 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
338 self.gotonext() |
| 26850 | 339 return EMPTYSTRING.join(aslist) + self.getdomain() |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
340 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
341 def getdomain(self): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
342 """Get the complete domain name from an address.""" |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
343 sdlist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
344 while self.pos < len(self.field): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
345 if self.field[self.pos] in self.LWS: |
| 26850 | 346 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
347 elif self.field[self.pos] == '(': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
348 self.commentlist.append(self.getcomment()) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
349 elif self.field[self.pos] == '[': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
350 sdlist.append(self.getdomainliteral()) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
351 elif self.field[self.pos] == '.': |
| 26850 | 352 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
353 sdlist.append('.') |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
354 elif self.field[self.pos] in self.atomends: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
355 break |
| 26850 | 356 else: |
| 357 sdlist.append(self.getatom()) | |
| 358 return EMPTYSTRING.join(sdlist) | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
359 |
| 26850 | 360 def getdelimited(self, beginchar, endchars, allowcomments=True): |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
361 """Parse a header fragment delimited by special characters. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
362 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
363 `beginchar' is the start character for the fragment. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
364 If self is not looking at an instance of `beginchar' then |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
365 getdelimited returns the empty string. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
366 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
367 `endchars' is a sequence of allowable end-delimiting characters. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
368 Parsing stops when one of these is encountered. |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
369 |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
370 If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
371 within the parsed fragment. |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
372 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
373 if self.field[self.pos] != beginchar: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
374 return '' |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
375 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
376 slist = [''] |
| 26850 | 377 quote = False |
| 378 self.pos += 1 | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
379 while self.pos < len(self.field): |
| 26850 | 380 if quote: |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
381 slist.append(self.field[self.pos]) |
| 26850 | 382 quote = False |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
383 elif self.field[self.pos] in endchars: |
| 26850 | 384 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
385 break |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
386 elif allowcomments and self.field[self.pos] == '(': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
387 slist.append(self.getcomment()) |
|
38063
f62bd5118c78
Port forward from 2.4 branch:
Barry Warsaw <barry@python.org>
parents:
37421
diff
changeset
|
388 continue # have already advanced pos from getcomment |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
389 elif self.field[self.pos] == '\\': |
| 26850 | 390 quote = True |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
391 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
392 slist.append(self.field[self.pos]) |
| 26850 | 393 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
394 |
| 26850 | 395 return EMPTYSTRING.join(slist) |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
396 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
397 def getquote(self): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
398 """Get a quote-delimited fragment from self's field.""" |
| 26850 | 399 return self.getdelimited('"', '"\r', False) |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
400 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
401 def getcomment(self): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
402 """Get a parenthesis-delimited fragment from self's field.""" |
| 26850 | 403 return self.getdelimited('(', ')\r', True) |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
404 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
405 def getdomainliteral(self): |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
406 """Parse an RFC 2822 domain-literal.""" |
| 26850 | 407 return '[%s]' % self.getdelimited('[', ']\r', False) |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
408 |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
409 def getatom(self, atomends=None): |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
410 """Parse an RFC 2822 atom. |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
411 |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
412 Optional atomends specifies a different set of end token delimiters |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
413 (the default is to use self.atomends). This is used e.g. in |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
414 getphraselist() since phrase endings must not include the `.' (which |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
415 is legal in phrases).""" |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
416 atomlist = [''] |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
417 if atomends is None: |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
418 atomends = self.atomends |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
419 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
420 while self.pos < len(self.field): |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
421 if self.field[self.pos] in atomends: |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
422 break |
| 26850 | 423 else: |
| 424 atomlist.append(self.field[self.pos]) | |
| 425 self.pos += 1 | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
426 |
| 26850 | 427 return EMPTYSTRING.join(atomlist) |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
428 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
429 def getphraselist(self): |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
430 """Parse a sequence of RFC 2822 phrases. |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
431 |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
432 A phrase is a sequence of words, which are in turn either RFC 2822 |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
433 atoms or quoted-strings. Phrases are canonicalized by squeezing all |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
434 runs of continuous whitespace into one space. |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
435 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
436 plist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
437 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
438 while self.pos < len(self.field): |
|
41118
d850bf56fdf6
Tokio Kikuchi's fix for SF bug #1629369; folding whitespace allowed in the
Barry Warsaw <barry@python.org>
parents:
38063
diff
changeset
|
439 if self.field[self.pos] in self.FWS: |
| 26850 | 440 self.pos += 1 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
441 elif self.field[self.pos] == '"': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
442 plist.append(self.getquote()) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
443 elif self.field[self.pos] == '(': |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
444 self.commentlist.append(self.getcomment()) |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
445 elif self.field[self.pos] in self.phraseends: |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
446 break |
| 26850 | 447 else: |
| 448 plist.append(self.getatom(self.phraseends)) | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
449 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
450 return plist |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
451 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
452 class AddressList(AddrlistClass): |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
453 """An AddressList encapsulates a list of parsed RFC 2822 addresses.""" |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
454 def __init__(self, field): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
455 AddrlistClass.__init__(self, field) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
456 if field: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
457 self.addresslist = self.getaddrlist() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
458 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
459 self.addresslist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
460 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
461 def __len__(self): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
462 return len(self.addresslist) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
463 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
464 def __add__(self, other): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
465 # Set union |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
466 newaddr = AddressList(None) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
467 newaddr.addresslist = self.addresslist[:] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
468 for x in other.addresslist: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
469 if not x in self.addresslist: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
470 newaddr.addresslist.append(x) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
471 return newaddr |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
472 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
473 def __iadd__(self, other): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
474 # Set union, in-place |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
475 for x in other.addresslist: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
476 if not x in self.addresslist: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
477 self.addresslist.append(x) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
478 return self |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
479 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
480 def __sub__(self, other): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
481 # Set difference |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
482 newaddr = AddressList(None) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
483 for x in self.addresslist: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
484 if not x in other.addresslist: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
485 newaddr.addresslist.append(x) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
486 return newaddr |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
487 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
488 def __isub__(self, other): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
489 # Set difference, in-place |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
490 for x in other.addresslist: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
491 if x in self.addresslist: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
492 self.addresslist.remove(x) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
493 return self |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
494 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
495 def __getitem__(self, index): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
496 # Make indexing, slices, and 'in' work |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
497 return self.addresslist[index] |
