Mercurial > cpython-lru_cache-weakref
annotate Lib/email/_parseaddr.py @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | d4db5ded76ce |
| children | f6b3e64b7620 |
| 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 |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
16 import time |
| 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 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
110 tzoffset = None |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
111 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
|
112 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
|
113 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
|
114 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
115 try: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
116 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
|
117 except ValueError: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
118 pass |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
119 # 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
|
120 if tzoffset: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
121 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
|
122 tzsign = -1 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
123 tzoffset = -tzoffset |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
124 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
125 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
|
126 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
|
127 # 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
|
128 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
|
129 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
130 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
131 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
|
132 """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
|
133 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
|
134 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
|
135 return t[:9] |
| 26850 | 136 else: |
| 137 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
|
138 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
139 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
140 def mktime_tz(data): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
141 """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
142 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
|
143 # 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
|
144 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
|
145 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
146 t = time.mktime(data[:8] + (0,)) |
|
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 - data[9] - time.timezone |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
148 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
149 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
150 def quote(str): |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
151 """Add quotes around a string.""" |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
152 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
|
153 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
154 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
155 class AddrlistClass: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
156 """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
|
157 |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
158 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
|
159 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
|
160 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
161 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
|
162 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
|
163 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
164 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
165 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
|
166 """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
|
167 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
168 `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
|
169 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
|
170 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
171 self.specials = '()<>@,:;.\"[]' |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 # 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
|
178 # 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
|
179 # 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
|
180 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
|
181 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
|
182 self.commentlist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
183 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
184 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
|
185 """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
|
186 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
|
187 if self.field[self.pos] in self.LWS + '\n\r': |
| 26850 | 188 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
|
189 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
|
190 self.commentlist.append(self.getcomment()) |
| 26850 | 191 else: |
| 192 break | |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
193 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
194 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
|
195 """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
|
196 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
197 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
|
198 """ |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
199 result = [] |
|
28317
023d3b50e597
getaddrlist(): Make sure this consumes all the data, and if there is
Barry Warsaw <barry@python.org>
parents:
26853
diff
changeset
|
200 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
|
201 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
|
202 if ad: |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
203 result += ad |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
204 else: |
|
28317
023d3b50e597
getaddrlist(): Make sure this consumes all the data, and if there is
Barry Warsaw <barry@python.org>
parents:
26853
diff
changeset
|
205 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
|
206 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
|
207 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
208 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
|
209 """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
|
210 self.commentlist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
211 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
212 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
217 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
218 returnlist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
219 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
220 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
|
221 # 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
|
222 if plist: |
| 26850 | 223 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
|
224 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
225 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
|
226 # 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
|
227 # 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
|
228 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
|
229 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
|
230 addrspec = self.getaddrspec() |
| 26850 | 231 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
|
232 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
233 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
|
234 # 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
|
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 fieldlen = len(self.field) |
| 26850 | 238 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
|
239 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
|
240 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
241 if self.pos < fieldlen and self.field[self.pos] == ';': |
| 26850 | 242 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
|
243 break |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
244 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
|
245 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
246 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
|
247 # 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
|
248 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
|
249 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
250 if self.commentlist: |
| 26850 | 251 returnlist = [(SPACE.join(plist) + ' (' + |
| 252 ' '.join(self.commentlist) + ')', routeaddr)] | |
| 253 else: | |
| 254 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
|
255 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
256 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
257 if plist: |
| 26850 | 258 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
|
259 elif self.field[self.pos] in self.specials: |
| 26850 | 260 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
|
261 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
262 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
263 if self.pos < len(self.field) and self.field[self.pos] == ',': |
| 26850 | 264 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
|
265 return returnlist |
|
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 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
|
268 """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
|
269 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
270 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
|
271 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
272 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
|
273 return |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
274 |
| 26850 | 275 expectroute = False |
| 276 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
|
277 self.gotonext() |
| 26850 | 278 adlist = '' |
|
26046
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
279 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
|
280 if expectroute: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
281 self.getdomain() |
| 26850 | 282 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
|
283 elif self.field[self.pos] == '>': |
| 26850 | 284 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
|
285 break |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
286 elif self.field[self.pos] == '@': |
| 26850 | 287 self.pos += 1 |
| 288 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
|
289 elif self.field[self.pos] == ':': |
| 26850 | 290 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
|
291 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
292 adlist = self.getaddrspec() |
| 26850 | 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 break |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
295 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
296 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
297 return adlist |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
298 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
299 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
|
300 """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
|
301 aslist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
302 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
303 self.gotonext() |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
304 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
|
305 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
|
306 aslist.append('.') |
| 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 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
|
309 aslist.append('"%s"' % self.getquote()) |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
310 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
|
311 break |
| 26850 | 312 else: |
| 313 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
|
314 self.gotonext() |
|
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 if self.pos >= len(self.field) or self.field[self.pos] != '@': |
| 26850 | 317 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
|
318 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
319 aslist.append('@') |
| 26850 | 320 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
|
321 self.gotonext() |
| 26850 | 322 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
|
323 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
324 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
|
325 """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
|
326 sdlist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
327 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
|
328 if self.field[self.pos] in self.LWS: |
| 26850 | 329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 elif self.field[self.pos] == '.': |
| 26850 | 335 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
|
336 sdlist.append('.') |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
337 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
|
338 break |
| 26850 | 339 else: |
| 340 sdlist.append(self.getatom()) | |
| 341 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
|
342 |
| 26850 | 343 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
|
344 """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
|
345 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
346 `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
|
347 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
|
348 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
|
349 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
350 `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
|
351 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
|
352 |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
353 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
|
354 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
|
355 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
356 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
|
357 return '' |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
358 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
359 slist = [''] |
| 26850 | 360 quote = False |
| 361 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
|
362 while self.pos < len(self.field): |
| 26850 | 363 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
|
364 slist.append(self.field[self.pos]) |
| 26850 | 365 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
|
366 elif self.field[self.pos] in endchars: |
| 26850 | 367 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
|
368 break |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
369 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
|
370 slist.append(self.getcomment()) |
|
38063
f62bd5118c78
Port forward from 2.4 branch:
Barry Warsaw <barry@python.org>
parents:
37421
diff
changeset
|
371 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
|
372 elif self.field[self.pos] == '\\': |
| 26850 | 373 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
|
374 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
375 slist.append(self.field[self.pos]) |
| 26850 | 376 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
|
377 |
| 26850 | 378 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
|
379 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
380 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
|
381 """Get a quote-delimited fragment from self's field.""" |
| 26850 | 382 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
|
383 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
384 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
|
385 """Get a parenthesis-delimited fragment from self's field.""" |
| 26850 | 386 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
|
387 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
388 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
|
389 """Parse an RFC 2822 domain-literal.""" |
| 26850 | 390 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
|
391 |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
392 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
|
393 """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
|
394 |
|
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
395 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
|
396 (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
|
397 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
|
398 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
|
399 atomlist = [''] |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
400 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
|
401 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
|
402 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
403 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
|
404 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
|
405 break |
| 26850 | 406 else: |
| 407 atomlist.append(self.field[self.pos]) | |
| 408 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
|
409 |
| 26850 | 410 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
|
411 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
412 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
|
413 """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
|
414 |
|
26848
865c59b5bfd7
Port rfc822.py changes that didn't make it into this copy,
Barry Warsaw <barry@python.org>
parents:
26046
diff
changeset
|
415 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
|
416 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
|
417 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
|
418 """ |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
419 plist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
420 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
421 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
|
422 if self.field[self.pos] in self.FWS: |
| 26850 | 423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 break |
| 26850 | 430 else: |
| 431 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
|
432 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
433 return plist |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
434 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
435 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
|
436 """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
|
437 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
|
438 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
|
439 if field: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
440 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
|
441 else: |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
442 self.addresslist = [] |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
443 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
444 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
|
445 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
|
446 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
447 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
|
448 # Set union |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
449 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
|
450 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
|
451 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
|
452 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
|
453 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
|
454 return newaddr |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
455 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
456 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
|
457 # 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
|
458 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
|
459 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
|
460 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
|
461 return self |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
462 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
463 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
|
464 # Set difference |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
465 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
|
466 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
|
467 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
|
468 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
|
469 return newaddr |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
470 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
471 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
|
472 # 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
|
473 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
|
474 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
|
475 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
|
476 return self |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
477 |
|
1dbabc5beff7
Jason Mastaler's patch to break the dependence on rfc822.py for the
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
478 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
|
479 # 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
|
480 return self.addresslist[index] |
