Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_iso8601_regex():
assert iso8601.ISO8601_REGEX.match("2006-10-11T00:14:33Z")
def test_iso8601_regex():
assert iso8601.ISO8601_REGEX.match("2006-10-11T00:14:33Z")
def serialize(self, field, cstruct, **kw):
if cstruct in (null, None):
cstruct = ""
readonly = kw.get("readonly", self.readonly)
if cstruct:
parsed = ISO8601_REGEX.match(cstruct)
if parsed: # strip timezone if it's there
timezone = parsed.groupdict()["timezone"]
if timezone and cstruct.endswith(timezone):
cstruct = cstruct[: -len(timezone)]
try:
date, time = cstruct.split("T", 1)
try:
# get rid of milliseconds
time, _ = time.split(".", 1)
except ValueError:
pass
kw["date"], kw["time"] = date, time
except ValueError: # need more than one item to unpack
kw["date"] = kw["time"] = ""
def getISO8601Granularity(iso8601string):
'''Determine the precision of an ISO8601 datetime string'''
def _getPrecision(gran, granule):
if gran.precision == None:
return len(granule)
else:
return gran.precision
if not isinstance(iso8601string, basestring):
raise ParseError("Expecting a string %r" % iso8601string)
m = ISO8601_REGEX.match(iso8601string)
if not m:
raise ParseError("Unable to parse date string %r" % iso8601string)
groups = m.groupdict()
sandsOfTime = [
Granularity("year", 4, 1),
Granularity("month", 2, 2),
Granularity("day", 2, 3),
Granularity("hour", 2, 4),
Granularity("minute",2, 5),
Granularity("second",2, 6),
Granularity("fraction", None, 7) ]
curGrain = Granularity()
for s in sandsOfTime:
if groups[s.granule] != None:
curGrain.granule = s.granule
curGrain.precision = _getPrecision(s, groups[s.granule])