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_parse_rfc3339_datetime(string, expected):
assert parse_rfc3339(string) == expected
from tomlkit._utils import parse_rfc3339
from tomlkit.exceptions import TOMLKitError
def to_bool(s):
assert s in ["true", "false"]
return s == "true"
stypes = {
"string": unicode,
"bool": to_bool,
"integer": int,
"float": float,
"datetime": parse_rfc3339,
}
def untag(value):
if isinstance(value, list):
return [untag(i) for i in value]
elif "type" in value and "value" in value and len(value) == 2:
if value["type"] in stypes:
val = decode(value["value"])
return stypes[value["type"]](val)
elif value["type"] == "array":
return [untag(i) for i in value["value"]]
else:
raise Exception("Unsupported type {}".format(value["type"]))
else:
def test_parse_rfc3339_time(string, expected):
assert parse_rfc3339(string) == expected
def date(raw): # type: (str) -> Date
value = parse_rfc3339(raw)
if not isinstance(value, _datetime.date):
raise ValueError("date() only accepts date strings.")
return item(value)
return item
raise self.parse_error(InvalidNumberError)
elif c in string.digits:
# Integer, Float, Date, Time or DateTime
while self._current not in " \t\n\r#,]}" and self.inc():
pass
raw = self.extract()
m = RFC_3339_LOOSE.match(raw)
if m:
if m.group(1) and m.group(5):
# datetime
try:
dt = parse_rfc3339(raw)
return DateTime(
dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second,
dt.microsecond,
dt.tzinfo,
trivia,
raw,
)
except ValueError:
raise self.parse_error(InvalidDateTimeError)
if m.group(1):
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second,
dt.microsecond,
dt.tzinfo,
trivia,
raw,
)
except ValueError:
raise self.parse_error(InvalidDateTimeError)
if m.group(1):
try:
dt = parse_rfc3339(raw)
return Date(dt.year, dt.month, dt.day, trivia, raw)
except ValueError:
raise self.parse_error(InvalidDateError)
if m.group(5):
try:
t = parse_rfc3339(raw)
return Time(
t.hour,
t.minute,
t.second,
t.microsecond,
t.tzinfo,
trivia,
raw,
)
trivia,
raw,
)
except ValueError:
raise self.parse_error(InvalidDateTimeError)
if m.group(1):
try:
dt = parse_rfc3339(raw)
return Date(dt.year, dt.month, dt.day, trivia, raw)
except ValueError:
raise self.parse_error(InvalidDateError)
if m.group(5):
try:
t = parse_rfc3339(raw)
return Time(
t.hour,
t.minute,
t.second,
t.microsecond,
t.tzinfo,
trivia,
raw,
)
except ValueError:
raise self.parse_error(InvalidTimeError)
item = self._parse_number(raw, trivia)
if item is not None:
return item