
    Mh                     R    d dl Z ddlmZmZ ddlmZ ddlmZ  G d de          ZdS )    N   )CodeGeneratorDraft04JSON_TYPE_TO_PYTHON_TYPE)JsonSchemaDefinitionException)enforce_listc                   ~     e Zd Z eej        fi ddddZdi dddf fd	Zd Zd	 Zd
 Z	d Z
d Zd Zd Zd Z x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                     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___json_keywords_to_functionupdategenerate_exclusive_minimumgenerate_exclusive_maximumgenerate_property_namesgenerate_containsgenerate_const)self
definitionresolverformatsuse_defaultuse_formatsdetailed_exceptions	__class__s          V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/fastjsonschema/draft06.pyr   zCodeGeneratorDraft06.__init__   s    Xw[Refff'..!@A!@Ad:;/0d)*0
 	 	 	 	 	    c                     t          |t                    r|                                  d S d|v r|                                  d S |                     |           d S )Nz$ref)
isinstanceboolgenerate_boolean_schemagenerate_refrun_generate_functions)r   r   s     r!   _generate_func_code_blockz.CodeGeneratorDraft06._generate_func_code_block   si    j$'' 	4((*****z!!''
33333r"   c                     | 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   s    r!   r&   z,CodeGeneratorDraft06.generate_boolean_schema&   sP    
 t##FF6NNNu$$HH/00000 %$r"   c                 6   t          | j        d                   }	 d                    d |D                       }n4# t          $ r'}t	          d                    |                    d}~ww xY wd}d|v r|d                    | j        	          z  }d
|v sd|v r"d|vr|d                    | j        	          z  }|                     d||          5  |                     dd                    |          d           ddd           dS # 1 swxY w 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              3   0   K   | ]}t           |         V  d S )N)r   ).0ts     r!   	<genexpr>z5CodeGeneratorDraft06.generate_type.<locals>.<genexpr>=   s(      $P$PQ%=a%@$P$P$P$P$P$Pr"   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   typespython_typesr/   extras        r!   generate_typez"CodeGeneratorDraft06.generate_type0   s    T-f566	P99$P$P%$P$P$PPPLL 	P 	P 	P/0B0I0I#0N0NOOO	P [bb c   E e!3!3%9O9O7>>>WWWEVV<lERR 	K 	KHH(&++e*<*<6HJJJ	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	Ks'   < 
A-"A((A-,DDDc                 l   |                      d          5  t          | j        d         t          t          t
          j        f          st          d          |                      d          5  |                     dd           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w 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}r<   	r.   r$   r-   intfloatdecimalDecimalr   r/   r0   s    r!   r   z/CodeGeneratorDraft06.generate_exclusive_minimumN   sT   VVGHH 	c 	cd./ABS%QXQ`Dabb q34oppp>?? c cHOabbbc c c c c c c c c c c c c c c	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c6   AB)-BB)B	B)B	B))B-0B-c                 l   |                      d          5  t          | j        d         t          t          t
          j        f          st          d          |                      d          5  |                     dd           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrG   r   z9exclusiveMaximum must be an integer, a float or a decimalz$if {variable} >= {exclusiveMaximum}:z.{name} must be smaller than {exclusiveMaximum}r<   rH   r0   s    r!   r   z/CodeGeneratorDraft06.generate_exclusive_maximumU   sT   VVGHH 	d 	dd./ABS%QXQ`Dabb q34oppp>?? d dIPbcccd d d d d d d d d d d d d d d	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	drM   c           
      b   | j                             di           }|du rdS |du r[|                                  |                     d          5  |                     dd           ddd           dS # 1 swxY w Y   dS |                                  |                     d          5  |                                  |                     d	          5  |                     d
           |                     d          5  |                     d          5  |                     |d                    | j	                  | j
        d           ddd           n# 1 swxY w Y   |                     d          5  |                     d           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                     d          5  |                     dd           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w 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,   r<   Nzif {variable}_is_dict:zif {variable}_len != 0:z {variable}_property_names = True!for {variable}_key in {variable}:try:{}_keyclear_variablesz except JsonSchemaValueException:z!{variable}_property_names = Falsez!if not {variable}_property_names:z/{name} must be named by propertyName definition)r-   getcreate_variable_keysr.   r/   create_variable_is_dictcreate_variable_with_lengthgenerate_func_code_blockr@   rA   _variable_name)r   property_names_definitions     r!   r   z,CodeGeneratorDraft06.generate_property_names\   sb    %)$4$8$8"$M$M!$,,D&%//%%'''-.. K K3/JJJK K K K K K K K K K K K K K K K K K ((***011 j j00222VV566 j jFF=>>> CDD 	H 	H!VVF^^   99 9 ( ? ? $ 304	 :                  "VV$FGG H H FF#FGGGH H H H H H H H H H H H H H H	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H  CDD j j!RYhiiij j j j j j j j j j j j j j jj j j j j j j j j j j j j j jj j j j j j j j j j j j j j j j j js   A44A8;A8**H$+H?F17E	F1EF1E F18F	F1FF1!F"F1%H1F55H8F59HG5)H5G99H<G9=H H$H	H$H	H$$H(+H(c           	         |                                   |                     d          5  | j        d         }|du r|                     dd           nr|du rF|                     d          5  |                     dd           d	d	d	           n# 1 swxY w Y   n(|                     d
           |                     d          5  |                     d          5  |                     |d                    | j                  | j        d           |                     d           |                     d           d	d	d	           n# 1 swxY w Y   |                     d           d	d	d	           n# 1 swxY w Y   |                     d          5  |                     dd           d	d	d	           n# 1 swxY w Y   d	d	d	           d	S # 1 swxY w 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 invalidr<   Tzif not {variable}:z{name} must not be emptyNz{variable}_contains = FalserP   rQ   rR   rS   z{variable}_contains = Truebreakz%except JsonSchemaValueException: passzif not {variable}_contains:z.{name} must contain one of contains definition)create_variable_is_listr.   r-   r/   rY   r@   rA   rZ   )r   contains_definitions     r!   r   z&CodeGeneratorDraft06.generate_contains   si    	$$&&&VV,-- 	` 	`"&"2:">"e++3*EEEE$,,VV011 J JHH7jHIIIJ J J J J J J J J J J J J J J 4555VV?@@ 
D 
D ( (55/$OODN;; /,0	 6    ;<<<w( ( ( ( ( ( ( ( ( ( ( ( ( ( ( FFBCCC
D 
D 
D 
D 
D 
D 
D 
D 
D 
D 
D 
D 
D 
D 
D VV9:: ` `HHMT^H___` ` ` ` ` ` ` ` ` ` ` ` ` ` `-	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	`s   AG.BGB	GB	/G	E8A!E E8EE8EE8,G8E<	<G?E<	 GF<0G<G 	 GG 	GGGc                 &   | j         d         }t          |t                    r(d                    |                     |                    }|                     d|          5  |                     dd           ddd           dS # 1 swxY 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}r<   N)r-   r$   strr@   er.   r/   )r   r   s     r!   r   z#CodeGeneratorDraft06.generate_const   s      )eS!! 	1MM$&&--00EVV*E22 	a 	aHHQX_H```	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	as   !BB
B
)__name__
__module____qualname__dictr   FORMAT_REGEXSr   r)   r&   rE   r   r   r   r   r   __classcell__)r    s   @r!   r	   r	      s       D-; 	 	4C0		@ 	@ 	 	M -1"$\`vz      4 4 41 1 1K K K<c c cd d d&j &j &jP&` &` &`Pa a a a a a ar"   r	   )	rK   draft04r   r   
exceptionsr   	generatorr   r	    r"   r!   <module>rm      s     C C C C C C C C 5 5 5 5 5 5 # # # # # #ua ua ua ua ua/ ua ua ua ua uar"   