MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / parse

Method parse

suds/sax/date.py:186–209  ·  view source on GitHub ↗

Parse the string datetime. This supports the subset of ISO8601 used by xsd:dateTime, but is lenient with what is accepted, handling most reasonable syntax. @param value: A datetime string. @type value: str @return: A datetime object. @rtype: B{dateti

(value)

Source from the content-addressed store, hash-verified

184
185 @staticmethod
186 def parse(value):
187 """Parse the string datetime.
188
189 This supports the subset of ISO8601 used by xsd:dateTime, but is
190 lenient with what is accepted, handling most reasonable syntax.
191
192 @param value: A datetime string.
193 @type value: str
194 @return: A datetime object.
195 @rtype: B{datetime}.I{datetime}
196
197 """
198 match_result = RE_DATETIME.match(value)
199 if match_result is None:
200 raise ValueError('date data has invalid format "%s"' % (value, ))
201
202 date = date_from_match(match_result)
203 time = time_from_match(match_result)
204 tzinfo = tzinfo_from_match(match_result)
205
206 value = datetime.datetime.combine(date, time)
207 value = value.replace(tzinfo=tzinfo)
208
209 return value
210
211 def __str__(self):
212 return self.value.isoformat()

Callers 1

__init__Method · 0.95

Calls 4

date_from_matchFunction · 0.85
time_from_matchFunction · 0.85
tzinfo_from_matchFunction · 0.85
matchMethod · 0.45

Tested by

no test coverage detected