U af @sddlZddlZddlmZmZddlZddlZddlmZddlm Z m Z m Z ddl m Zddl mZddlmZdZd ZeeZe e e fe e e fed d d Ze e e fed ddZe edddZee dddZGdddeZedZ GdddeZ!dS)N) JSONEncoder JSONDecoder) import_module)AnyCallableDict)validate) exceptions)CANONICAL_TIMESTRING_FORMATg?) json_dict schema_dictreturncCsF|dk s t|dk stzt||WdStjk r@YdSXdS)aTest that json_dict dictionary conforms to the swagger schema provided. :param json_dict: A dictionary of values :param schema_dict: A dict representation of swagger schema :returns: True or False :raises AssertionError: if either is None NTF)AssertionError json_validatejson_exceptionsZValidationError)r r rE/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/primordial/jsonutils.pyvalidate_swaggers   r)r rcCstj|tdddS)aYReturn a pretty-formatted string containing the values in json_dict. :param json_dict: A dictionary or other object that is serializable as a json string :returns: a (unicode) string representation with a default format of sorted keys and indent of 4 spaces :raises TypeError: if the thing in question cannot be json serialized T),:)cls sort_keys separators)jsondumpsDateTimeEncoder)r rrrpretty_json_str&sr)funcrcCsd|j|jfS)zCreate a string for a python function in a module. Class and object methods not supported currently. :param func: a python function :returns: a string representing this function z%s.%s) __module____name__)rrrr func_to_str0sr!)func_strrcCs*|d}|}td|}t||S)a=Use importlib to turn a string into a function. At the moment, this is limited to module functions and not classes. :param func_str: the string representation of a function, e.g. ``tests.test_workflow.ex_tst_func`` :returns: a python function :raises ImportError: if the function does not exist .)splitpoprjoingetattr)r"Z funcnotationsymbolmodulerrr str_to_func;s r*c@s eZdZdZeedddZdS)rUses our canonical format.)objrcCs(t|tjr|t}n t||}|SN) isinstancedatetimestrftimer rdefault)selfr,retrrrr1Ls   zDateTimeEncoder.defaultN)r r __qualname____doc__rr1rrrrrJsrz:^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d{6})Z$cs8eZdZdZfddZeeefedddZZS)DateTimeDecoderr+cstj|d|ji|dS)N object_hook)super__init__dict_to_object)r2argskwargs __class__rrr9ZszDateTimeDecoder.__init__)drcCs<|D].\}}t|trt|rtj|t||<q|Sr-)itemsr.strDATETIME_REGEXmatchr/strptimer )r2r?keyvaluerrrr:]szDateTimeDecoder.dict_to_object) r rr4r5r9rrr: __classcell__rrr=rr6Xs r6)"r/rrrloggingre importlibrtypingrrrZ jsonschemarrr rZprimordial.constantsr ZDELAY_INCREASE_SECSZ MAX_RETRIES getLoggerr LOGGERboolrrArr!r*rcompilerBr6rrrrs&     "