def infer_types(d: Any) -> Any: is_str = isinstance(d, str) if is_str and _is_iso(d): return iso_parse(d) elif is_str: return _maybe_convert_s(d) else: return d
def key_parser(key, prefix): """ Given a key, parse out the prefix and parse the iso date into a datetime object (for comparison). """ try: key_prefix, iso_date = key.split('|') except: # some weird key that was not put there by easydump log.debug("found weird key: %s" % key) return None if prefix == key_prefix: return iso_parse(iso_date) else: # a dump from another manifest log.debug("wrong prefix: %s" % key) return None
def make_db_object(d): # Given a dict straight from the JSON, return a more functional object # which maybe a proxy or wrapper version object. # cls = d.get('CK_type', None) # Look for ISO datetimes. This is a little risky, but I know about the # server we're talking with, so... # # example: 2014-07-07T18:48:34.880819 # for k, v in d.items(): if isinstance(v, basestring) and DATETIME_RE.match(v): try: d[k] = iso_parse(v) except: pass if not cls or cls not in CK_DB_OBJECTS: return CKObject(d) # Return a CKUser (for example) if the incoming data looks like one return globals()[cls](d)