B wÏ1`íã@s<ddlmZmZddlmZddlmZGdd„deƒZdS)é)ÚCodeGeneratorDraft04ÚJSON_TYPE_TO_PYTHON_TYPE)ÚJsonSchemaDefinitionException)Ú enforce_listcszeZdZeejfddddœŽZdidf‡fdd„ Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Z‡ZS)ÚCodeGeneratorDraft06z^(/(([^/~])|(~[01]))*)*\Zz'^(\w+:(\/?\/?))?[^#\\\s]*(#[^\\\s]*)?\Zz³^(?:(?:[^\x00-\x20\"\'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*\Z)z json-pointerz uri-referencez uri-templateNTcsJtƒ ||||¡|j d|jfd|jfd|jfd|jfd|jff¡dS)NÚexclusiveMinimumÚexclusiveMaximumÚ propertyNamesÚcontainsÚconst) ÚsuperÚ__init__Z_json_keywords_to_functionÚupdateÚgenerate_exclusive_minimumÚgenerate_exclusive_maximumÚgenerate_property_namesÚgenerate_containsÚgenerate_const)ÚselfÚ definitionÚresolverÚformatsZ use_default)Ú __class__©ú:/tmp/pip-unpacked-wheel-vlg95h98/fastjsonschema/draft06.pyr szCodeGeneratorDraft06.__init__cCs4t|tƒr| ¡nd|kr&| ¡n | |¡dS)Nz$ref)Ú isinstanceÚboolÚgenerate_boolean_schemaZ generate_refZrun_generate_functions)rrrrrÚ_generate_func_code_blocks    z.CodeGeneratorDraft06._generate_func_code_blockcCs|jdkr| d¡dS)z… Means that schema can be specified by boolean. True means everything is valid, False everything is invalid. Fz{name} must not be thereN)Ú _definitionÚexc)rrrrr%s z,CodeGeneratorDraft06.generate_boolean_schemac CsÔt|jdƒ}yd dd„|Dƒ¡}Wn0tk rV}ztd |¡ƒ‚Wdd}~XYnXd}d|krv|d j|jd 7}d |ks†d|kr d |kr |d j|jd 7}| d||¡|jdd |¡ddWdQRXdS)zù Validation of type. Can be one type or list of types. Since draft 06 a float without fractional part is an integer. .. code-block:: python {'type': 'string'} {'type': ['string', 'number']} Útypez, css|]}t|VqdS)N)r)Ú.0Útrrrú :sz5CodeGeneratorDraft06.generate_type..zUnknown type: {}NÚÚintegerzD and not (isinstance({variable}, float) and {variable}.is_integer()))ÚvariableÚnumberÚbooleanz or isinstance({variable}, bool)z&if not isinstance({variable}, ({})){}:z{name} must be {}z or )Úrule) rrÚjoinÚKeyErrorrÚformatÚ _variableÚlr )rÚtypesZ python_typesr ÚextrarrrÚ generate_type-s   z"CodeGeneratorDraft06.generate_typec CsZ| d¡Ft|jdttfƒs(tdƒ‚| d¡|jdddWdQRXWdQRXdS)Nz(if isinstance({variable}, (int, float)):rz.exclusiveMinimum must be an integer or a floatz$if {variable} <= {exclusiveMinimum}:z-{name} must be bigger than {exclusiveMinimum})r*)r/rrÚintÚfloatrr )rrrrrKs   z/CodeGeneratorDraft06.generate_exclusive_minimumc CsZ| d¡Ft|jdttfƒs(tdƒ‚| d¡|jdddWdQRXWdQRXdS)Nz(if isinstance({variable}, (int, float)):rz.exclusiveMaximum must be an integer or a floatz$if {variable} >= {exclusiveMaximum}:z.{name} must be smaller than {exclusiveMaximum})r*)r/rrr3r4rr )rrrrrRs   z/CodeGeneratorDraft06.generate_exclusive_maximumc Cs&|j di¡}|dkrn|dkrP| ¡| d¡|jdddWdQRXnÒ| ¡| d¡º| ¡| d ¡œ| d ¡| d ¡X| d ¡"|j|d  |j ¡|j ddWdQRX| d¡| d¡WdQRXWdQRX| d¡|jdddWdQRXWdQRXWdQRXdS)aB Means that keys of object must to follow this definition. .. code-block:: python { 'propertyNames': { 'maxLength': 3, }, } Valid keys of object for this definition are foo, bar, ... but not foobar for example. r TFzif {variable}_keys:z{name} must not be there)r*Nzif {variable}_is_dict:zif {variable}_len != 0:z {variable}_property_names = Truez!for {variable}_key in {variable}:ztry:z{}_key)Úclear_variablesz except JsonSchemaValueException:z!{variable}_property_names = Falsez!if not {variable}_property_names:z/{name} must be named by propertyName definition) rÚgetZcreate_variable_keysr/r Zcreate_variable_is_dictZcreate_variable_with_lengthÚgenerate_func_code_blockr-r.Ú_variable_name)rZproperty_names_definitionrrrrYs.         z,CodeGeneratorDraft06.generate_property_namesc Cs| ¡| d¡ê|jd}|dkr6|jdddnÂ|dkrd| d¡|jdddWd QRXn”| d ¡| d ¡V| d ¡6|j|d  |j¡|jdd| d¡| d¡Wd QRX| d¡Wd QRX| d¡|jdddWd QRXWd QRXd S)a Means that array must contain at least one defined item. .. code-block:: python { 'contains': { 'type': 'number', }, } Valid array is any with at least one number. zif {variable}_is_list:r Fz{name} is always invalid)r*Tzif not {variable}:z{name} must not be emptyNz{variable}_contains = Falsez!for {variable}_key in {variable}:ztry:z{}_key)r5z{variable}_contains = TrueÚbreakz%except JsonSchemaValueException: passzif not {variable}_contains:z.{name} must contain one of contains definition)Zcreate_variable_is_listr/rr r7r-r.r8)rZcontains_definitionrrrrs*         z&CodeGeneratorDraft06.generate_containsc CsN|jd}t|tƒr$d | |¡¡}| d|¡|jdddWdQRXdS)zÚ Means that value is valid when is equeal to const definition. .. code-block:: python { 'const': 42, } Only valid value is 42 in this example. r z"{}"zif {variable} != {}:z:{name} must be same as const definition: {definition_rule})r*N)rrÚstrr-Úer/r )rr rrrr©s  z#CodeGeneratorDraft06.generate_const)Ú__name__Ú __module__Ú __qualname__ÚdictrZ FORMAT_REGEXSr rrr2rrrrrÚ __classcell__rr)rrrs   ((rN)Zdraft04rrÚ exceptionsrÚ generatorrrrrrrÚs