Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: Lib/email/_parseaddr.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/email/feedparser.py ('k') | Lib/email/utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2002-2007 Python Software Foundation 1 # Copyright (C) 2002-2007 Python Software Foundation
2 # Contact: email-sig@python.org 2 # Contact: email-sig@python.org
3 3
4 """Email address parsing code. 4 """Email address parsing code.
5 5
6 Lifted directly from rfc822.py. This should eventually be rewritten. 6 Lifted directly from rfc822.py. This should eventually be rewritten.
7 """ 7 """
8 8
9 __all__ = [ 9 __all__ = [
10 'mktime_tz', 10 'mktime_tz',
(...skipping 28 matching lines...) Expand all
39 'CST': -600, 'CDT': -500, # Central 39 'CST': -600, 'CDT': -500, # Central
40 'MST': -700, 'MDT': -600, # Mountain 40 'MST': -700, 'MDT': -600, # Mountain
41 'PST': -800, 'PDT': -700 # Pacific 41 'PST': -800, 'PDT': -700 # Pacific
42 } 42 }
43 43
44 44
45 def parsedate_tz(data): 45 def parsedate_tz(data):
46 """Convert a date string to a time tuple. 46 """Convert a date string to a time tuple.
47 47
48 Accounts for military timezones. 48 Accounts for military timezones.
49 """
50 res = _parsedate_tz(data)
51 if res[9] is None:
52 res[9] = 0
53 return tuple(res)
54
55 def _parsedate_tz(data):
56 """Convert date to extended time tuple.
57
58 The last (additional) element is the time zone offset in seconds, except if
59 the timezone was specified as -0000. In that case the last element is
60 None. This indicates a UTC timestamp that explicitly declaims knowledge of
61 the source timezone, as opposed to a +0000 timestamp that indicates the
62 source timezone really was UTC.
63
64 """ 49 """
65 data = data.split() 50 data = data.split()
66 # The FWS after the comma after the day-of-week is optional, so search and 51 # The FWS after the comma after the day-of-week is optional, so search and
67 # adjust for this. 52 # adjust for this.
68 if data[0].endswith(',') or data[0].lower() in _daynames: 53 if data[0].endswith(',') or data[0].lower() in _daynames:
69 # There's a dayname here. Skip it 54 # There's a dayname here. Skip it
70 del data[0] 55 del data[0]
71 else: 56 else:
72 i = data[0].rfind(',') 57 i = data[0].rfind(',')
73 if i >= 0: 58 if i >= 0:
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 yy += 2000 131 yy += 2000
147 tzoffset = None 132 tzoffset = None
148 tz = tz.upper() 133 tz = tz.upper()
149 if tz in _timezones: 134 if tz in _timezones:
150 tzoffset = _timezones[tz] 135 tzoffset = _timezones[tz]
151 else: 136 else:
152 try: 137 try:
153 tzoffset = int(tz) 138 tzoffset = int(tz)
154 except ValueError: 139 except ValueError:
155 pass 140 pass
156 if tzoffset==0 and tz.startswith('-'):
157 tzoffset = None
158 # Convert a timezone offset into seconds ; -0500 -> -18000 141 # Convert a timezone offset into seconds ; -0500 -> -18000
159 if tzoffset: 142 if tzoffset:
160 if tzoffset < 0: 143 if tzoffset < 0:
161 tzsign = -1 144 tzsign = -1
162 tzoffset = -tzoffset 145 tzoffset = -tzoffset
163 else: 146 else:
164 tzsign = 1 147 tzsign = 1
165 tzoffset = tzsign * ( (tzoffset//100)*3600 + (tzoffset % 100)*60) 148 tzoffset = tzsign * ( (tzoffset//100)*3600 + (tzoffset % 100)*60)
166 # Daylight Saving Time flag is set to -1, since DST is unknown. 149 # Daylight Saving Time flag is set to -1, since DST is unknown.
167 return [yy, mm, dd, thh, tmm, tss, 0, 1, -1, tzoffset] 150 return yy, mm, dd, thh, tmm, tss, 0, 1, -1, tzoffset
168 151
169 152
170 def parsedate(data): 153 def parsedate(data):
171 """Convert a time string to a time tuple.""" 154 """Convert a time string to a time tuple."""
172 t = parsedate_tz(data) 155 t = parsedate_tz(data)
173 if isinstance(t, tuple): 156 if isinstance(t, tuple):
174 return t[:9] 157 return t[:9]
175 else: 158 else:
176 return t 159 return t
177 160
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 def __isub__(self, other): 510 def __isub__(self, other):
528 # Set difference, in-place 511 # Set difference, in-place
529 for x in other.addresslist: 512 for x in other.addresslist:
530 if x in self.addresslist: 513 if x in self.addresslist:
531 self.addresslist.remove(x) 514 self.addresslist.remove(x)
532 return self 515 return self
533 516
534 def __getitem__(self, index): 517 def __getitem__(self, index):
535 # Make indexing, slices, and 'in' work 518 # Make indexing, slices, and 'in' work
536 return self.addresslist[index] 519 return self.addresslist[index]
OLDNEW
« no previous file with comments | « Lib/email/feedparser.py ('k') | Lib/email/utils.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+