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_duration_type_simple(self):
value = 'P1Y'
_type = types.DurationType(self.field)
self.assertEquals(_type.cast(value), isodate.Duration(years=1))
def parse_ISO8601(time_gap):
"""
P1D to (1, ("DAYS", isodate.Duration(days=1)).
P1Y to (1, ("YEARS", isodate.Duration(years=1)).
:param time_gap: ISO8601 string.
:return: tuple with quantity and unit of time.
"""
matcher = None
if time_gap.count("T"):
units = {
"H": ("HOURS", isodate.Duration(hours=1)),
"M": ("MINUTES", isodate.Duration(minutes=1)),
"S": ("SECONDS", isodate.Duration(seconds=1))
}
matcher = re.search("PT(\d+)([HMS])", time_gap)
if matcher:
quantity = int(matcher.group(1))
unit = matcher.group(2)
return quantity, units.get(unit)
else:
raise Exception("Does not match the pattern: {}".format(time_gap))
else:
units = {
"Y": ("YEARS", isodate.Duration(years=1)),
"M": ("MONTHS", isodate.Duration(months=1)),
"W": ("WEEKS", isodate.Duration(weeks=1)),
"D": ("DAYS", isodate.Duration(days=1))
}
"M": ("MINUTES", isodate.Duration(minutes=1)),
"S": ("SECONDS", isodate.Duration(seconds=1))
}
matcher = re.search("PT(\d+)([HMS])", time_gap)
if matcher:
quantity = int(matcher.group(1))
unit = matcher.group(2)
return quantity, units.get(unit)
else:
raise Exception("Does not match the pattern: {}".format(time_gap))
else:
units = {
"Y": ("YEARS", isodate.Duration(years=1)),
"M": ("MONTHS", isodate.Duration(months=1)),
"W": ("WEEKS", isodate.Duration(weeks=1)),
"D": ("DAYS", isodate.Duration(days=1))
}
matcher = re.search("P(\d+)([YMWD])", time_gap)
if matcher:
quantity = int(matcher.group(1))
unit = matcher.group(2)
else:
raise Exception("Does not match the pattern: {}".format(time_gap))
return quantity, units.get(unit)
if time_gap.count("T"):
units = {
"H": ("HOURS", isodate.Duration(hours=1)),
"M": ("MINUTES", isodate.Duration(minutes=1)),
"S": ("SECONDS", isodate.Duration(seconds=1))
}
matcher = re.search("PT(\d+)([HMS])", time_gap)
if matcher:
quantity = int(matcher.group(1))
unit = matcher.group(2)
return quantity, units.get(unit)
else:
raise Exception("Does not match the pattern: {}".format(time_gap))
else:
units = {
"Y": ("YEARS", isodate.Duration(years=1)),
"M": ("MONTHS", isodate.Duration(months=1)),
"W": ("WEEKS", isodate.Duration(weeks=1)),
"D": ("DAYS", isodate.Duration(days=1))
}
matcher = re.search("P(\d+)([YMWD])", time_gap)
if matcher:
quantity = int(matcher.group(1))
unit = matcher.group(2)
else:
raise Exception("Does not match the pattern: {}".format(time_gap))
return quantity, units.get(unit)
def parse_ISO8601(time_gap):
"""
P1D to (1, ("DAYS", isodate.Duration(days=1)).
P1Y to (1, ("YEARS", isodate.Duration(years=1)).
:param time_gap: ISO8601 string.
:return: tuple with quantity and unit of time.
"""
matcher = None
if time_gap.count("T"):
units = {
"H": ("HOURS", isodate.Duration(hours=1)),
"M": ("MINUTES", isodate.Duration(minutes=1)),
"S": ("SECONDS", isodate.Duration(seconds=1))
}
matcher = re.search("PT(\d+)([HMS])", time_gap)
if matcher:
quantity = int(matcher.group(1))
unit = matcher.group(2)
return quantity, units.get(unit)
else:
raise Exception("Does not match the pattern: {}".format(time_gap))
else:
units = {
"Y": ("YEARS", isodate.Duration(years=1)),
"M": ("MONTHS", isodate.Duration(months=1)),
"W": ("WEEKS", isodate.Duration(weeks=1)),
"D": ("DAYS", isodate.Duration(days=1))
FIVE_MINUTE = duration_isoformat(Duration(minutes=5))
HOUR = duration_isoformat(Duration(hours=1))
DAY = duration_isoformat(Duration(days=1))
class AtlasPeriods(object):
"""Helper class to create ISO 8601 durations to send to the Atlas period parameter.
To add more periods, add them here.
"""
MINUTES_15 = duration_isoformat(Duration(minutes=15))
HOURS_1 = duration_isoformat(Duration(hours=1))
HOURS_8 = duration_isoformat(Duration(hours=8))
HOURS_24 = duration_isoformat(Duration(hours=24))
HOURS_48 = duration_isoformat(Duration(hours=48))
WEEKS_1 = duration_isoformat(Duration(weeks=1))
WEEKS_4 = duration_isoformat(Duration(weeks=4))
MONTHS_1 = duration_isoformat(Duration(months=1))
MONTHS_2 = duration_isoformat(Duration(months=2))
YEARS_1 = duration_isoformat(Duration(years=1))
YEARS_2 = duration_isoformat(Duration(years=2))
# noinspection PyCallByClass
class _GetAll(object):
is_leaf = False
@classmethod
def get_all(cls) -> Iterator[str]:
out = cls.__dict__
for item in out:
if '_' not in item and not item[0].isupper():
def parse_ISO8601(time_gap):
"""
P1D to (1, ("DAYS", isodate.Duration(days=1)).
P1Y to (1, ("YEARS", isodate.Duration(years=1)).
:param time_gap: ISO8601 string.
:return: tuple with quantity and unit of time.
"""
matcher = None
if time_gap.count("T"):
units = {
"H": ("HOURS", isodate.Duration(hours=1)),
"M": ("MINUTES", isodate.Duration(minutes=1)),
"S": ("SECONDS", isodate.Duration(seconds=1))
}
matcher = re.search("PT(\d+)([HMS])", time_gap)
if matcher:
quantity = int(matcher.group(1))
unit = matcher.group(2)
return quantity, units.get(unit)
else:
raise Exception("Does not match the pattern: {}".format(time_gap))
else:
units = {
"Y": ("YEARS", isodate.Duration(years=1)),
"M": ("MONTHS", isodate.Duration(months=1)),
"W": ("WEEKS", isodate.Duration(weeks=1)),
"D": ("DAYS", isodate.Duration(days=1))
}
class AtlasPeriods(object):
"""Helper class to create ISO 8601 durations to send to the Atlas period parameter.
To add more periods, add them here.
"""
MINUTES_15 = duration_isoformat(Duration(minutes=15))
HOURS_1 = duration_isoformat(Duration(hours=1))
HOURS_8 = duration_isoformat(Duration(hours=8))
HOURS_24 = duration_isoformat(Duration(hours=24))
HOURS_48 = duration_isoformat(Duration(hours=48))
WEEKS_1 = duration_isoformat(Duration(weeks=1))
WEEKS_4 = duration_isoformat(Duration(weeks=4))
MONTHS_1 = duration_isoformat(Duration(months=1))
MONTHS_2 = duration_isoformat(Duration(months=2))
YEARS_1 = duration_isoformat(Duration(years=1))
YEARS_2 = duration_isoformat(Duration(years=2))
# noinspection PyCallByClass
class _GetAll(object):
is_leaf = False
@classmethod
def get_all(cls) -> Iterator[str]:
out = cls.__dict__
for item in out:
if '_' not in item and not item[0].isupper():
yield cls.__getattribute__(cls, item)
elif '_' not in item and item[0].isupper():
sub_out = cls.__getattribute__(cls, item).__dict__
for sub_item in sub_out:
if '_' not in sub_item and not sub_item[0].isupper():