o
    tf                     @   sD   d dl Z ddlmZmZ ddlmZ ddlmZ G dd deZdS )    N   )CodeGeneratorDraft04JSON_TYPE_TO_PYTHON_TYPE)JsonSchemaDefinitionException)enforce_listc                       s   e Zd Zeejfi ddddZdi ddf fdd	Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Z  ZS )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-templateNTc                    sL   t  ||||| | jd| jfd| jfd| jfd| jfd| jff d S )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_defaultZuse_formats	__class__ _/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/fastjsonschema/draft06.pyr      s   
zCodeGeneratorDraft06.__init__c                 C   s8   t |tr|   d S d|v r|   d S | | d S )Nz$ref)
isinstanceboolgenerate_boolean_schemaZgenerate_refZrun_generate_functions)r   r   r   r   r   _generate_func_code_block   s
   
z.CodeGeneratorDraft06._generate_func_code_blockc                 C   s0   | j du r
| d | j du r| d dS dS )z
        Means that schema can be specified by boolean.
        True means everything is valid, False everything is invalid.
        TpassF{name} must not be thereN)_definitionlexcr   r   r   r   r   &   s
   


z,CodeGeneratorDraft06.generate_boolean_schemac              
   C   s   t | jd }zddd |D }W n ty& } ztd|d}~ww d}d|v r6|d	j| jd
7 }d|v s>d|v rKd|vrK|dj| jd
7 }| d|| | jdd|dd W d   dS 1 siw   Y  dS )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, c                 s   s    | ]}t | V  qd S )N)r   ).0tr   r   r   	<genexpr>=   s    z5CodeGeneratorDraft06.generate_type.<locals>.<genexpr>zUnknown 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)	r   r#   joinKeyErrorr   format	_variabler$   r%   )r   typesZpython_typesr%   extrar   r   r   generate_type0   s"   "z"CodeGeneratorDraft06.generate_typec              	   C      |  d= t| jd tttjfstd|  d | jddd W d    n1 s-w   Y  W d    d S W d    d S 1 sEw   Y  d S )N1if isinstance({variable}, (int, float, Decimal)):r   z9exclusiveMinimum must be an integer, a float or a decimalz$if {variable} <= {exclusiveMinimum}:z-{name} must be bigger than {exclusiveMinimum}r0   	r$   r   r#   intfloatdecimalDecimalr   r%   r&   r   r   r   r   N      "z/CodeGeneratorDraft06.generate_exclusive_minimumc              	   C   r9   )Nr:   r	   z9exclusiveMaximum must be an integer, a float or a decimalz$if {variable} >= {exclusiveMaximum}:z.{name} must be smaller than {exclusiveMaximum}r0   r;   r&   r   r   r   r   U   r@   z/CodeGeneratorDraft06.generate_exclusive_maximumc                 C   s  | j di }|du rdS |du r4|   | d | jddd W d   dS 1 s-w   Y  dS |   | d |   | d	{ | d
 | dE | d | j|d| j	| j
dd W d   n1 sqw   Y  | d | d W d   n1 sw   Y  W d   n1 sw   Y  | d | jddd W d   n1 sw   Y  W d   n1 sw   Y  W d   dS W d   dS 1 sw   Y  dS )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
   TFzif {variable}_keys:r"   r0   Nzif {variable}_is_dict:zif {variable}_len != 0:z {variable}_property_names = True!for {variable}_key in {variable}:try:{}_keyZclear_variablesz except JsonSchemaValueException:z!{variable}_property_names = Falsez!if not {variable}_property_names:z/{name} must be named by propertyName definition)r#   getZcreate_variable_keysr$   r%   Zcreate_variable_is_dictZcreate_variable_with_lengthgenerate_func_code_blockr4   r5   _variable_name)r   Zproperty_names_definitionr   r   r   r   \   sF   "


"z,CodeGeneratorDraft06.generate_property_namesc              
   C   s  |    | d | jd }|du r| jddd n|du r<| d | jddd W d	   n1 s6w   Y  nx| d
 | d: | d  | j|d| j| jdd | d | d W d	   n1 sow   Y  | d W d	   n1 sw   Y  | d | jddd W d	   n 1 sw   Y  W d	   d	S W d	   d	S W d	   d	S W d	   d	S 1 sw   Y  d	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.
        zif {variable}_is_list:r   Fz{name} is always invalidr0   Tzif not {variable}:z{name} must not be emptyNz{variable}_contains = FalserA   rB   rC   rD   z{variable}_contains = Truebreakz%except JsonSchemaValueException: passzif not {variable}_contains:z.{name} must contain one of contains definition)Zcreate_variable_is_listr$   r#   r%   rF   r4   r5   rG   )r   Zcontains_definitionr   r   r   r      sD   



	 "z&CodeGeneratorDraft06.generate_containsc                 C   sd   | j d }t|trd| |}| d| | jddd W d   dS 1 s+w   Y  dS )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"{}"zif {variable} != {}:z:{name} must be same as const definition: {definition_rule}r0   N)r#   r   strr4   er$   r%   )r   r   r   r   r   r      s   

"z#CodeGeneratorDraft06.generate_const)__name__
__module____qualname__dictr   ZFORMAT_REGEXSr   r    r   r8   r   r   r   r   r   __classcell__r   r   r   r   r      s    


	
((r   )	r>   Zdraft04r   r   
exceptionsr   	generatorr   r   r   r   r   r   <module>   s
    