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