
    od                     J    d dl mZmZ d dlmZ d dlmZ  G d de          ZdS )   )CodeGeneratorDraft04JSON_TYPE_TO_PYTHON_TYPE)JsonSchemaDefinitionException)enforce_listc                   z     e Zd Z eej        fi ddddZdi 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	__class__s        6lib/python3.11/site-packages/fastjsonschema/draft06.pyr   zCodeGeneratorDraft06.__init__   s    XwDDD'..!@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   sk    j$'' 	4((*****z! 	4''
33333r   c                 F    | 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.
        F{name} must not be thereN)_definitionexcr   s    r   r#   z,CodeGeneratorDraft06.generate_boolean_schema%   s7    
 u$ 	1HH/00000	1 	1r   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	_variablelr*   )r   typespython_typesr*   extras        r   generate_typez"CodeGeneratorDraft06.generate_type-   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  	Xe!3 	X%9O 	X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                 V   |                      d          5  t          | j        d         t          t          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 )N(if isinstance({variable}, (int, float)):r
   z.exclusiveMinimum must be an integer or a floatz$if {variable} <= {exclusiveMinimum}:z-{name} must be bigger than {exclusiveMinimum}r7   r=   r!   r)   intfloatr   r*   r+   s    r   r   z/CodeGeneratorDraft06.generate_exclusive_minimumK   sM   VV>?? 	c 	cd./ABS%LQQ f34deee>?? 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"%B"c                 V   |                      d          5  t          | j        d         t          t          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 )NrC   r   z.exclusiveMaximum must be an integer or a floatz$if {variable} >= {exclusiveMaximum}:z.{name} must be smaller than {exclusiveMaximum}r7   rD   r+   s    r   r   z/CodeGeneratorDraft06.generate_exclusive_maximumR   sM   VV>?? 	d 	dd./ABS%LQQ f34deee>?? 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rG   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(   r7   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;   r<   _variable_name)r   property_names_definitions     r   r   z,CodeGeneratorDraft06.generate_property_namesY   sh    %)$4$8$8"$M$M!$, 	jD&%/ 	j%%'''-.. 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 invalidr7   Tzif not {variable}:z{name} must not be emptyNz{variable}_contains = FalserJ   rK   rL   rM   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*   rS   r;   r<   rT   )r   contains_definitions     r   r   z&CodeGeneratorDraft06.generate_contains   so    	$$&&&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}r7   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#   rA   r   r   r   r   r   __classcell__)r   s   @r   r   r      s       D-; 	 	4C0		@ 	@ 	 	M -1"$      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   N)draft04r   r   
exceptionsr   	generatorr   r    r   r   <module>rg      s    C C C C C C C C 5 5 5 5 5 5 # # # # # #sa sa sa sa sa/ sa sa sa sa sar   