
    ~f                     J    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y)    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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                  j                  d| j                  fd| j
                  fd| j                  fd| j                  fd| j                  ff       y )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	__class__s         Q/var/www/cvtools/html/venv/lib/python3.12/site-packages/fastjsonschema/draft06.pyr   zCodeGeneratorDraft06.__init__   sw    Xw[Q''..!@!@A!@!@Ad::;//0d))*0
 	    c                     t        |t              r| j                          y d|v r| j                          y | j	                  |       y )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   s:    j$'((*z!''
3r!   c                     | j                   du r| j                  d       | j                   du r| j                  d       yy)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&   s=    
 t#FF6Nu$HH/0 %r!   c                    t        | j                  d         }	 dj                  d |D              }d}d|v r|dj                  | j                  	      z  }d
|v sd|v r#d|vr|dj                  | j                  	      z  }| j                  d||      5  | j                  ddj                  |      d       ddd       y# t        $ r}t	        dj                  |            d}~ww xY w# 1 sw Y   yxY w)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   .   K   | ]  }t         |     y w)N)r   ).0ts     r    	<genexpr>z5CodeGeneratorDraft06.generate_type.<locals>.<genexpr>=   s     $PQ%=a%@$Ps   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	P99$P%$PPL [bb c  E e!3%9O7>>>WWEVV<lER 	KHH(&++e*<6HJ	K 	K  	P/0B0I0I#0NOO	P	K 	Ks#   C $C-	C*C%%C*-C6c                 <   | j                  d      5  t        | j                  d   t        t        t
        j                  f      st        d      | j                  d      5  | j                  dd       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)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.   r/   s    r    r   z/CodeGeneratorDraft06.generate_exclusive_minimumN   s    VVGH 	cd../ABS%QXQ`Q`Dab34opp>? cHOabc	c 	cc c	c 	c$   AB!B5BB	BBc                 <   | j                  d      5  t        | j                  d   t        t        t
        j                  f      st        d      | j                  d      5  | j                  dd       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrF   r   z9exclusiveMaximum must be an integer, a float or a decimalz$if {variable} >= {exclusiveMaximum}:z.{name} must be smaller than {exclusiveMaximum}r;   rG   r/   s    r    r   z/CodeGeneratorDraft06.generate_exclusive_maximumU   s    VVGH 	dd../ABS%QXQ`Q`Dab34opp>? dIPbcd	d 	dd d	d 	drL   c           
         | j                   j                  di       }|du ry|du r>| j                          | j                  d      5  | j	                  dd       ddd       y| j                          | j                  d      5  | j                          | j                  d	      5  | j                  d
       | j                  d      5  | j                  d      5  | j                  |dj                  | j                        | j                  d       ddd       | j                  d      5  | j                  d       ddd       ddd       | j                  d      5  | j	                  dd       ddd       ddd       ddd       y# 1 sw Y   yxY w# 1 sw Y   xY w# 1 sw Y   gxY w# 1 sw Y   kxY w# 1 sw Y   JxY w# 1 sw Y   NxY w# 1 sw Y   yxY w)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?   r@   _variable_name)r   property_names_definitions     r    r   z,CodeGeneratorDraft06.generate_property_names\   s    %)$4$4$8$8"$M!$,&%/%%'-. K3/JK K ((*01 j002VV56 jFF=> CD 	H!VVF^  99 9 ( ? $ 3 304	 :  "VV$FG H FF#FGH	H  CD j!RYhijjj j	K K H H	H 	Hj jj jj js   F"G'#G

F29F	F2.F&	 F2G
!F>5G
=GFF#F2&F/+F22F;7G
>GG

G	GGc           	      >   | j                          | j                  d      5  | j                  d   }|du r| j                  dd       n|du r.| j                  d      5  | j                  dd       d	d	d	       n| j                  d
       | j                  d      5  | j                  d      5  | j	                  |dj                  | j                        | j                  d       | j                  d       | j                  d       d	d	d	       | j                  d       d	d	d	       | j                  d      5  | j                  dd       d	d	d	       d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   dxY w# 1 sw Y   WxY w# 1 sw Y   6xY w# 1 sw Y   y	xY w)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 = FalserO   rP   rQ   rR   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.   rX   r?   r@   rY   )r   contains_definitions     r    r   z&CodeGeneratorDraft06.generate_contains   s    	$$&VV,- 	`"&"2"2:">"e+3*E$,VV01 JHH7jHIJ J 45VV?@ 
D (55/$OODNN; //,0	 6  ;<w( FFBC
D VV9: `HHMT^H_`-	` 	`J J
( (
D 
D` `-	` 	`sl   >F E#4+FE;1AE/E;%F>FF#E,	(F/E84E;;F	 FF	FFc                     | j                   d   }t        |t              r dj                  | j	                  |            }| j                  d|      5  | j                  dd       ddd       y# 1 sw Y   yxY w)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   sn       )eS!MM$&&-0EVV*E2 	aHHQX_H`	a 	a 	as   A//A8)__name__
__module____qualname__dictr   FORMAT_REGEXSr   r(   r%   rD   r   r   r   r   r   __classcell__)r   s   @r    r	   r	      sm    -;; 	4C0		@ 	M -1"$\` 41K<cd&jP&`Par!   r	   )	rJ   draft04r   r   
exceptionsr   	generatorr   r	    r!   r    <module>rl      s"     C 5 #ua/ uar!   