MCPcopy Index your code
hub / github.com/python/cpython / _parsedate_tz

Function _parsedate_tz

Lib/email/_parseaddr.py:57–180  ·  view source on GitHub ↗

Convert date to extended time tuple. The last (additional) element is the time zone offset in seconds, except if the timezone was specified as -0000. In that case the last element is None. This indicates a UTC timestamp that explicitly declaims knowledge of the source timezone, as

(data)

Source from the content-addressed store, hash-verified

55 return tuple(res)
56
57def _parsedate_tz(data):
58 """Convert date to extended time tuple.
59
60 The last (additional) element is the time zone offset in seconds, except if
61 the timezone was specified as -0000. In that case the last element is
62 None. This indicates a UTC timestamp that explicitly declaims knowledge of
63 the source timezone, as opposed to a +0000 timestamp that indicates the
64 source timezone really was UTC.
65
66 """
67 if not data:
68 return None
69 data = data.split()
70 if not data: # This happens for whitespace-only input.
71 return None
72 # The FWS after the comma after the day-of-week is optional, so search and
73 # adjust for this.
74 if data[0].endswith(',') or data[0].lower() in _daynames:
75 # There's a dayname here. Skip it
76 del data[0]
77 else:
78 i = data[0].rfind(',')
79 if i >= 0:
80 data[0] = data[0][i+1:]
81 if len(data) == 3: # RFC 850 date, deprecated
82 stuff = data[0].split('-')
83 if len(stuff) == 3:
84 data = stuff + data[1:]
85 if len(data) == 4:
86 s = data[3]
87 i = s.find('+')
88 if i == -1:
89 i = s.find('-')
90 if i > 0:
91 data[3:] = [s[:i], s[i:]]
92 else:
93 data.append('') # Dummy tz
94 if len(data) < 5:
95 return None
96 data = data[:5]
97 [dd, mm, yy, tm, tz] = data
98 if not (dd and mm and yy):
99 return None
100 mm = mm.lower()
101 if mm not in _monthnames:
102 dd, mm = mm, dd.lower()
103 if mm not in _monthnames:
104 return None
105 mm = _monthnames.index(mm) + 1
106 if mm > 12:
107 mm -= 12
108 if dd[-1] == ',':
109 dd = dd[:-1]
110 i = yy.find(':')
111 if i > 0:
112 yy, tm = tm, yy
113 if yy[-1] == ',':
114 yy = yy[:-1]

Callers 2

parsedate_to_datetimeFunction · 0.90
parsedate_tzFunction · 0.85

Calls 10

isdigitMethod · 0.80
splitMethod · 0.45
endswithMethod · 0.45
lowerMethod · 0.45
rfindMethod · 0.45
findMethod · 0.45
appendMethod · 0.45
indexMethod · 0.45
upperMethod · 0.45
startswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…