o
    lhXx                     @   s^   d dl Z d dlZddlmZ ddlmZmZ ddddd	d
ddZedZ	G dd deZ
dS )    N   )JsonSchemaDefinitionException)CodeGeneratorenforce_listNoneTypeboolzint, float, Decimalintstrzlist, tupledict)nullbooleannumberintegerstringarrayobjectz	(?<!\\)\$c                       s  e Zd ZdddddddZdi d	d	d	f fd
d	Ze 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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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Z  Z S )@CodeGeneratorDraft04zk^\d{4}-[01]\d-[0-3]\d(t|T)[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:[+-][0-2]\d:[0-5]\d|[+-][0-2]\d[0-5]\d|z|Z)\Zz.^(?!.*\.\..*@)[^@.][^@]*(?<!\.)@[^@]+\.[^@]+\Zzv^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9])\ZzS^((25[0-5]|2[0-4][0-9]|1?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\Za  ^(?:(?:[0-9A-Fa-f]{1,4}:){6}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|::(?:[0-9A-Fa-f]{1,4}:){5}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){4}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){3}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){,2}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){2}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){,3}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}:(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){,4}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|(?:(?:[0-9A-Fa-f]{1,4}:){,6}[0-9A-Fa-f]{1,4})?::)\Zz^\w+:(\/?\/?)[^\s]+\Z)z	date-timeemailhostnameipv4ipv6uriNTc                    s   t  ||| || _|| _|| _| jd| jfd| jfd| j	fd| j
fd| jfd| jfd| jfd| jfd	| jfd
| jfd| jfd| jfd| jfd| jfd| jfd| jfd| jfd| jfd| jfd| jfd| jfd| jfd| jfd| jff d| _d S )NtypeenumallOfanyOfoneOfnot	minLength	maxLengthpatternformatminimummaximum
multipleOfminItemsmaxItemsuniqueItemsitemsminPropertiesmaxPropertiesrequireddependencies
propertiespatternPropertiesadditionalPropertiesr   ) super__init___custom_formats_use_formats_use_default_json_keywords_to_functionupdategenerate_typegenerate_enumgenerate_all_ofgenerate_any_ofgenerate_one_ofgenerate_notgenerate_min_lengthgenerate_max_lengthgenerate_patterngenerate_formatgenerate_minimumgenerate_maximumgenerate_multiple_ofgenerate_min_itemsgenerate_max_itemsgenerate_unique_itemsgenerate_itemsgenerate_min_propertiesgenerate_max_propertiesgenerate_requiredgenerate_dependenciesgenerate_propertiesgenerate_pattern_propertiesgenerate_additional_properties_any_or_one_of_count)self
definitionresolverformatsuse_defaultuse_formatsdetailed_exceptions	__class__ j/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fastjsonschema/draft04.pyr1   %   s>   
zCodeGeneratorDraft04.__init__c                    s   t  j}| j|d< |S )Ncustom_formats)r0   global_stater2   )rP   resrW   rY   rZ   r\   G   s   
z!CodeGeneratorDraft04.global_statec              
   C   s   t | jd }zddd |D }W n ty& } ztd|d}~ww d}d|v s1d	|v r<d
|vr<dj| jd}| d|| | jdd|dd W d   dS 1 sZw   Y  dS )z
        Validation of type. Can be one type or list of types.

        .. code-block:: python

            {'type': 'string'}
            {'type': ['string', 'number']}
        r   z, c                 s   s    | ]}t | V  qd S N)JSON_TYPE_TO_PYTHON_TYPE).0trY   rY   rZ   	<genexpr>X   s    z5CodeGeneratorDraft04.generate_type.<locals>.<genexpr>zUnknown type: {}N r   r   r   z  or isinstance({variable}, bool))variablez&if not isinstance({variable}, ({})){}:{name} must be {}z or rule)	r   _definitionjoinKeyErrorr   r!   	_variablelexc)rP   typespython_typesrm   extrarY   rY   rZ   r7   M   s   	"z"CodeGeneratorDraft04.generate_typec                 C   sf   | j d }t|ttfstd| d | jd| |dd W d   dS 1 s,w   Y  dS )z
        Means that only value specified in the enum is valid.

        .. code-block:: python

            {
                'enum': ['a', 'b'],
            }
        r   zenum must be an arrayzif {variable} not in {enum}:z{name} must be one of {}rf   N)rh   
isinstancelisttupler   rl   rm   e)rP   r   rY   rY   rZ   r8   c   s   

"z"CodeGeneratorDraft04.generate_enumc                 C   s*   | j d D ]}| j|| j| jdd qdS )a  
        Means that value have to be valid by all of those definitions. It's like put it in
        one big definition.

        .. code-block:: python

            {
                'allOf': [
                    {'type': 'number'},
                    {'minimum': 5},
                ],
            }

        Valid values for this definition are 5, 6, 7, ... but not 4 or 'abc' for example.
        r   Tclear_variablesN)rh   generate_func_code_blockrk   _variable_name)rP   definition_itemrY   rY   rZ   r9   s   s   z$CodeGeneratorDraft04.generate_all_ofc              
   C   s  |  j d7  _ | j }| jd|d | jd D ]H}| jd|dd6 | jddd	 | j|| j| jd
d | jd|d W d   n1 sEw   Y  | d W d   n1 sYw   Y  q| jd|dd | jddd W d   dS 1 szw   Y  dS )a  
        Means that value have to be valid by any of those definitions. It can also be valid
        by all of them.

        .. code-block:: python

            {
                'anyOf': [
                    {'type': 'number', 'minimum': 10},
                    {'type': 'number', 'maximum': 5},
                ],
            }

        Valid values for this definition are 3, 4, 5, 10, 11, ... but not 8 for example.
        r   z"{variable}_any_of_count{count} = 0countr   z&if not {variable}_any_of_count{count}:Fr{   optimizetry:r}   Tru   z#{variable}_any_of_count{count} += 1N%except JsonSchemaValueException: passz,{name} cannot be validated by any definitionrf   rO   rl   rh   rw   rk   rx   rm   )rP   r{   ry   rY   rY   rZ   r:      s   "z$CodeGeneratorDraft04.generate_any_ofc              
   C   s  |  j d7  _ | j }| jd|d | jd D ]H}| jd|dd6 | jddd	 | j|| j| jd
d | jd|d W d   n1 sEw   Y  | d W d   n1 sYw   Y  q| jd|d d}| jd||dd W d   dS 1 s}w   Y  dS )a  
        Means that value have to be valid by only one of those definitions. It can't be valid
        by two or more of them.

        .. code-block:: python

            {
                'oneOf': [
                    {'type': 'number', 'multipleOf': 3},
                    {'type': 'number', 'multipleOf': 5},
                ],
            }

        Valid values for this definition are 3, 5, 6, ... but not 15 for example.
        r   z"{variable}_one_of_count{count} = 0rz   r   z&if {variable}_one_of_count{count} < 2:Fr|   r~   r   Tru   z#{variable}_one_of_count{count} += 1Nr   z'if {variable}_one_of_count{count} != 1:z9" (" + str({variable}_one_of_count{}) + " matches found)"z.{name} must be valid exactly by one definition)append_to_msgrg   r   )rP   r{   ry   dynamicrY   rY   rZ   r;      s    "z$CodeGeneratorDraft04.generate_one_ofc                 C   s   | j d }|du r| jddd dS |du rdS |s#| jddd dS | jddd	 | || j| j W d   n1 s>w   Y  | d
 | d | jddd W d   dS 1 s`w   Y  dS )aT  
        Means that value have not to be valid by this definition.

        .. code-block:: python

            {'not': {'type': 'null'}}

        Valid values for this definition are 'hello', 42, {} ... but not None.

        Since draft 06 definition can be boolean. False means nothing, True
        means everything is invalid.
        r   T{name} must not be thererf   FNz-{name} must NOT match a disallowed definitionr~   r   r   zelse:)rh   rm   rl   rw   rk   rx   )rP   not_definitionrY   rY   rZ   r<      s   

"z!CodeGeneratorDraft04.generate_notc              	   C      |  d? |   t| jd tt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 sGw   Y  d S )Nif isinstance({variable}, str):r   zminLength must be a numberz if {variable}_len < {minLength}:z={name} must be longer than or equal to {minLength} charactersrf   rl   create_variable_with_lengthrq   rh   r   floatr   rm   rP   rY   rY   rZ   r=         "z(CodeGeneratorDraft04.generate_min_lengthc              	   C   r   )Nr   r   zmaxLength must be a numberz if {variable}_len > {maxLength}:z>{name} must be shorter than or equal to {maxLength} charactersrf   r   r   rY   rY   rZ   r>      r   z(CodeGeneratorDraft04.generate_max_lengthc              	   C   s   |  dN | jd }|dddd}td|}t|| j|< |  dt| | j	d	|dd
 W d    n1 s>w   Y  W d    d S W d    d S 1 sVw   Y  d S )Nr   r    \z\\"z\"z\\Zz-if not REGEX_PATTERNS[{}].search({variable}):z{name} must match pattern {}rf   )
rl   rh   replaceDOLLAR_FINDERsubrecompile_compile_regexpsreprrm   )rP   r    safe_patternend_of_string_fixed_patternrY   rY   rZ   r?      s   
"z%CodeGeneratorDraft04.generate_patternc              	   C   s  | j sdS | d | jd }|| jv rH| j| }t|tr)| ||d | n| d| | jd|dd W d   n1 sBw   Y  n\|| jv r\| j| }| ||d | nX|dkrd	g| _	| jd
dd | d W d   n1 s{w   Y  | d | jddd W d   n1 sw   Y  nt
d|W d   dS W d   dS W d   dS W d   dS 1 sw   Y  dS )z
        Means that value have to be in specified format. For example date, email or other.

        .. code-block:: python

            {'format': 'email'}

        Valid value for this definition is user@example.com but not @username
        Nr   r!   _re_patternz(if not custom_formats["{}"]({variable}):re   rf   regexz	import rer~   Fr   zre.compile({variable})zexcept Exception:z{name} must be a valid regexzUnknown format: {})r3   rl   rh   r2   rq   r	   _generate_formatrm   FORMAT_REGEXS_extra_imports_linesr   r!   )rP   format_custom_formatformat_regexrY   rY   rZ   r@      sB   






" z$CodeGeneratorDraft04.generate_formatc                 C   sn   | j d |kr5|| jvrt|| j|< | d| | jd|dd W d    d S 1 s.w   Y  d S d S )Nr!   z.if not REGEX_PATTERNS["{}"].match({variable}):re   rf   )rh   r   r   r   rl   rm   )rP   format_nameregexp_nameregexprY   rY   rZ   r     s   
"z%CodeGeneratorDraft04._generate_formatc              	   C      |  di t| jd tttjfstd| jddr:|  d | j	ddd W d    n1 s4w   Y  n$|  d	 | j	d
dd W d    n1 sQw   Y  W d    d S W d    d S W d    d S 1 sqw   Y  d S )N1if isinstance({variable}, (int, float, Decimal)):r"   zminimum must be a numberexclusiveMinimumFzif {variable} <= {minimum}:z${name} must be bigger than {minimum}rf   zif {variable} < {minimum}:z0{name} must be bigger than or equal to {minimum}
rl   rq   rh   r   r   decimalDecimalr   getrm   r   rY   rY   rZ   rA   "       "z%CodeGeneratorDraft04.generate_minimumc              	   C   r   )Nr   r#   zmaximum must be a numberexclusiveMaximumFzif {variable} >= {maximum}:z%{name} must be smaller than {maximum}rf   zif {variable} > {maximum}:z1{name} must be smaller than or equal to {maximum}r   r   rY   rY   rZ   rB   -  r   z%CodeGeneratorDraft04.generate_maximumc              	   C   s   |  dl t| jd tttjfstdt| jd tr$|  d n|  d |  d | jddd W d    n1 s@w   Y  |  d	 | jd
dd W d    n1 s\w   Y  W d    d S W d    d S 1 stw   Y  d S )Nr   r$   zmultipleOf must be a numberzBquotient = Decimal(repr({variable})) / Decimal(repr({multipleOf}))z$quotient = {variable} / {multipleOf}zif int(quotient) != quotient:z'{name} must be multiple of {multipleOf}rf   z-if {variable} / {multipleOf} == float("inf"):zinifinity reached)	rl   rq   rh   r   r   r   r   r   rm   r   rY   rY   rZ   rC   8  s   
"z)CodeGeneratorDraft04.generate_multiple_ofc              	   C      |    | d? t| jd ttfstd|   | d | jddd W d    n1 s3w   Y  W d    d S W d    d S 1 sKw   Y  d S )Nif {variable}_is_list:r%   zminItems must be a numberzif {variable}_len < {minItems}:z-{name} must contain at least {minItems} itemsrf   	create_variable_is_listrl   rq   rh   r   r   r   r   rm   r   rY   rY   rZ   rD   H     "z'CodeGeneratorDraft04.generate_min_itemsc              	   C   r   )Nr   r&   zmaxItems must be a numberzif {variable}_len > {maxItems}:z:{name} must contain less than or equal to {maxItems} itemsrf   r   r   rY   rY   rZ   rE   Q  r   z'CodeGeneratorDraft04.generate_max_itemsc              	   C   s   | j d }|s	dS |   | d6 | d |   | d | jddd W d   n1 s3w   Y  W d   dS W d   dS 1 sKw   Y  dS )a  
        With Python 3.4 module ``timeit`` recommended this solutions:

        .. code-block:: python

            >>> timeit.timeit("len(x) > len(set(x))", "x=range(100)+range(100)", number=100000)
            0.5839540958404541
            >>> timeit.timeit("len({}.fromkeys(x)) == len(x)", "x=range(100)+range(100)", number=100000)
            0.7094449996948242
            >>> timeit.timeit("seen = set(); any(i in seen or seen.add(i) for i in x)", "x=range(100)+range(100)", number=100000)
            2.0819358825683594
            >>> timeit.timeit("np.unique(x).size == len(x)", "x=range(100)+range(100); import numpy as np", number=100000)
            2.1439831256866455
        r'   Nr   zdef fn(var): return frozenset(dict((k, fn(v)) for k, v in var.items()).items()) if hasattr(var, "items") else tuple(fn(v) for v in var) if isinstance(var, (dict, list)) else str(var) if isinstance(var, bool) else varzNif {variable}_len > len(set(fn({variable}_x) for {variable}_x in {variable})):z {name} must contain unique itemsrf   )rh   r   rl   r   rm   )rP   unique_definitionrY   rY   rZ   rF   Z  s   

"z*CodeGeneratorDraft04.generate_unique_itemsc                 C   s  | j d }|du rdS |   | d= |   |du r;| d | jddd W d   n1 s5w   Y  nt|trt|D ]G\}}| d	| | d
| | |d	| j
|d	| j| W d   n1 spw   Y  | jrt|trd|v r| dt|d  qDd| j v r| j d du r| d	t| | jddd W d   n1 sw   Y  n| dt|% | | j d d	| j
d	| j| j
}|dkr| d W d   n1 sw   Y  nL|r2| d# | |d	| j
d	| j| j
}|dkr| d W d   n11 sw   Y  W d   dS W d   dS W d   dS W d   dS W d   dS W d   dS 1 sVw   Y  dS )a  
        Means array is valid only when all items are valid by this definition.

        .. code-block:: python

            {
                'items': [
                    {'type': 'integer'},
                    {'type': 'string'},
                ],
            }

        Valid arrays are those with integers or strings, nothing else.

        Since draft 06 definition can be also boolean. True means nothing, False
        means everything is invalid.
        r(   TNr   Fzif {variable}:r   rf   zif {variable}_len > {}:z!{variable}__{0} = {variable}[{0}]{}__{}z{}[{}]defaultzelse: {variable}.append({})additionalItemsz({name} must contain only specified itemszFfor {variable}_x, {variable}_item in enumerate({variable}[{0}:], {0}):z{}_itemz{}[{{{}_x}}]r   passz;for {variable}_x, {variable}_item in enumerate({variable}):)rh   r   rl   r   rm   rq   rr   	enumeraterw   r!   rk   rx   r4   r
   r   len)rP   items_definitionidxitem_definitionr{   rY   rY   rZ   rG   {  s~   




	


     $z#CodeGeneratorDraft04.generate_itemsc              	   C   r   )Nif {variable}_is_dict:r)   zminProperties must be a numberz$if {variable}_len < {minProperties}:z7{name} must contain at least {minProperties} propertiesrf   	create_variable_is_dictrl   rq   rh   r   r   r   r   rm   r   rY   rY   rZ   rH     r   z,CodeGeneratorDraft04.generate_min_propertiesc              	   C   r   )Nr   r*   zmaxProperties must be a numberz$if {variable}_len > {maxProperties}:zD{name} must contain less than or equal to {maxProperties} propertiesrf   r   r   rY   rY   rZ   rI     r   z,CodeGeneratorDraft04.generate_max_propertiesc              	      s       d| t jd ttfstdt jd tt jd kr,td j	ddsJ fdd jd D }|rJtd	
 j| d
  d d} jd  jd d|d W d    n1 spw   Y  W d    d S W d    d S 1 sw   Y  d S )Nr   r+   zrequired must be an arrayz%required must contain unique elementsr/   Tc                    sB   g | ]  j d i vrt fddj di D s qS )r-   c                 3   s    | ]	}t | V  qd S r^   )r   search)r`   r   proprY   rZ   rb     s    zDCodeGeneratorDraft04.generate_required.<locals>.<listcomp>.<genexpr>r.   )rh   r   any)r`   r   r   rZ   
<listcomp>  s    z:CodeGeneratorDraft04.generate_required.<locals>.<listcomp>z){}: items {} are required but not allowedz>{variable}__missing_keys = set({required}) - {variable}.keys()zif {variable}__missing_keys:z5str(sorted({variable}__missing_keys)) + " properties"z{name} must contain )rg   r   )r   rl   rq   rh   rr   rs   r   r   setr   r!   rk   rm   rt   )rP   not_possibler   rY   r   rZ   rJ     s(    

 "z&CodeGeneratorDraft04.generate_requiredc                 C   s>  |    | d |   | jd  D ]w\}}tdd|}t|tt	fs0t
d| j|| d| |1 | d| | | d|| | | j|d	| j|d
| j| |dd W d   n1 smw   Y  | jrt|trd|v r| d| |t|d  qW d   dS 1 sw   Y  dS )a  
        Means object with defined keys.

        .. code-block:: python

            {
                'properties': {
                    'key': {'type': 'number'},
                },
            }

        Valid object is containing key called 'key' and value any number.
        r   r-   z($[^a-zA-Z]|[^a-zA-Z0-9])rc   z{}[{}] must be objectzif "{}" in {variable}_keys:z{variable}_keys.remove("{}")z#{variable}__{0} = {variable}["{1}"]r   z{}.{}Tru   Nr   zelse: {variable}["{}"] = {})r   rl   create_variable_keysrh   r(   r   r   rq   r
   r   r   r!   rk   rt   rw   rx   r4   r   )rP   keyprop_definitionkey_namerY   rY   rZ   rL     s,   	"z(CodeGeneratorDraft04.generate_propertiesc                 C   sD  |    | d |   | jd  D ]\}}t|| j|< q| dY | jd  D ]I\}}| dt|5 | d | d W d   n1 sQw   Y  | j	|d
| jd	
| j| jd
d W d   n1 ssw   Y  q/W d   n1 sw   Y  W d   dS W d   dS 1 sw   Y  dS )a4  
        Means object with defined keys as patterns.

        .. code-block:: python

            {
                'patternProperties': {
                    '^x': {'type': 'number'},
                },
            }

        Valid object is containing key starting with a 'x' and value any number.
        r   r.   z9for {variable}_key, {variable}_val in {variable}.items():z-if REGEX_PATTERNS[{}].search({variable}_key):z%if {variable}_key in {variable}_keys:z&{variable}_keys.remove({variable}_key)Nz{}_val{}.{{{}_key}}Tru   )r   rl   r   rh   r(   r   r   r   r   rw   r!   rk   rx   )rP   r    rQ   rY   rY   rZ   rM     s0   
"z0CodeGeneratorDraft04.generate_pattern_propertiesc                 C   sb  |    | d |   | jd }|du s|i kr$	 W d   dS |rst| jdi  }| d4 | d| | d | |d	| j	d
| j
| j	 W d   n1 s^w   Y  W d   n1 smw   Y  n$| d | jddd W d   n1 sw   Y  W d   dS W d   dS W d   dS 1 sw   Y  dS )a  
        Means object with keys with values defined by definition.

        .. code-block:: python

            {
                'properties': {
                    'key': {'type': 'number'},
                }
                'additionalProperties': {'type': 'string'},
            }

        Valid object is containing key called 'key' and it's value any number and
        any other key with any string.
        r   r/   TNr-   z&for {variable}_key in {variable}_keys:zif {variable}_key not in {}:z1{variable}_value = {variable}.get({variable}_key)z{}_valuer   zif {variable}_keys:z;{name} must not contain "+str({variable}_keys)+" propertiesrf   )r   rl   r   rh   rr   r   keysrw   r!   rk   rx   rm   )rP   add_prop_definitionproperties_keysrY   rY   rZ   rN   #  s:   


	 "z3CodeGeneratorDraft04.generate_additional_propertiesc                 C   sP  |    | d d}| jd  D ]s\}}|g ks|du r qd}| d| |S |du r9| jd|dd n>t|trl|D ]*}| d| | | jd	| || |dd W d
   n1 sew   Y  q@n| j|| j	| j
dd W d
   n1 sw   Y  q|r| d W d
   d
S W d
   d
S 1 sw   Y  d
S )a  
        Means when object has property, it needs to have also other property.

        .. code-block:: python

            {
                'dependencies': {
                    'bar': ['foo'],
                },
            }

        Valid object is containing only foo, both bar and foo or none of them, but not
        object with only bar.

        Since draft 06 definition can be boolean or empty array. True and empty array
        means nothing, False means that key cannot be there at all.
        r   Tr,   Fzif "{}" in {variable}:z{} in {name} must not be thererf   zif "{}" not in {variable}:z#{name} missing dependency {} for {}Nru   r   )r   rl   rh   r(   rt   rm   rq   rr   rw   rk   rx   )rP   is_emptyr   valuesvaluerY   rY   rZ   rK   G  s4   
 	"z*CodeGeneratorDraft04.generate_dependencies)!__name__
__module____qualname__r   r1   propertyr\   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   r   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rL   rM   rN   rK   __classcell__rY   rY   rW   rZ   r      sH    	"	$		!@		!$r   )r   r   
exceptionsr   	generatorr   r   r_   r   r   r   rY   rY   rY   rZ   <module>   s    

