openapi-core/openapi_core/schema/schemas/util.py

27 lines
571 B
Python
Raw Normal View History

2018-04-17 12:18:40 +00:00
"""OpenAPI core schemas util module"""
import datetime
2018-04-17 12:18:40 +00:00
from distutils.util import strtobool
2018-07-28 20:57:49 +00:00
from json import dumps
from six import string_types
import strict_rfc3339
2018-04-17 12:18:40 +00:00
def forcebool(val):
if isinstance(val, string_types):
2018-04-17 12:18:40 +00:00
val = strtobool(val)
return bool(val)
2018-07-28 20:57:49 +00:00
def dicthash(d):
return hash(dumps(d, sort_keys=True))
def format_date(value):
return datetime.datetime.strptime(value, '%Y-%m-%d').date()
2018-08-22 10:51:06 +00:00
def format_datetime(value):
timestamp = strict_rfc3339.rfc3339_to_timestamp(value)
return datetime.datetime.fromtimestamp(timestamp)