U
    e~                     @   s    d dl mZ G dd deZdS )   )CodeGeneratorDraft06c                	       sX   e Zd ZeejfdddddddZdi d	f fd
d	Zdd Zdd Zdd Z	  Z
S )CodeGeneratorDraft07z6^(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})\Zz^\w+:(\/?\/?)[^\s]+\Zz'^(\w+:(\/?\/?))?[^#\\\s]*(#[^\\\s]*)?\Zz^[^@]+@[^@]+\.[^@]+\Zz1^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)\Zzu^(?P<hour>\d{1,2}):(?P<minute>\d{1,2})(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6}))?([zZ]|[+-]\d\d:\d\d)?)?\Z)dateZiriziri-referencez	idn-emailzrelative-json-pointertimeNTc                    s:   t  |||| | jd| jfd| jfd| jff d S )NifcontentEncodingcontentMediaType)super__init__Z_json_keywords_to_functionupdategenerate_if_then_elsegenerate_content_encodinggenerate_content_media_type)selfZ
definitionZresolverformatsZuse_default	__class__ 5lib/python3.8/site-packages/fastjsonschema/draft07.pyr
      s    zCodeGeneratorDraft07.__init__c              	   C   s   | j ddd" | j| jd | j| jdd W 5 Q R X |  d8 d| jkrj| j| jd | j| jdd n
|  d	 W 5 Q R X d
| jkr|  d" | j| jd
 | j| jdd W 5 Q R X dS )a  
        Implementation of if-then-else.

        .. code-block:: python

            {
                'if': {
                    'exclusiveMaximum': 0,
                },
                'then': {
                    'minimum': -10,
                },
                'else': {
                    'multipleOf': 2,
                },
            }

        Valid values are any between -10 and 0 or any multiplication of two.
        try:F)optimizer   T)Zclear_variablesz except JsonSchemaValueException:elsepassZthenzelse:N)lZgenerate_func_code_block_definitionZ	_variableZ_variable_namer   r   r   r   r      s0    

z*CodeGeneratorDraft07.generate_if_then_elsec              
   C   s   | j d dkr| dp | d | d | d W 5 Q R X | d | d W 5 Q R X | d	 | d
 W 5 Q R X W 5 Q R X dS )z
        Means decoding value when it's encoded by base64.

        .. code-block:: python

            {
                'contentEncoding': 'base64',
            }
        r   base64if isinstance({variable}, str):r   zimport base64z){variable} = base64.b64decode({variable})except Exception:z {name} must be encoded by base64zif {variable} == "":zcontentEncoding must be base64Nr   r   excr   r   r   r   r   K   s    

z.CodeGeneratorDraft07.generate_content_encodingc              
   C   s   | j d dkr| dF | d | d W 5 Q R X | d | d W 5 Q R X W 5 Q R X | dP | d | d	 | d
 W 5 Q R X | d | d W 5 Q R X W 5 Q R X dS )z
        Means loading value when it's specified as JSON.

        .. code-block:: python

            {
                'contentMediaType': 'application/json',
            }
        r   zapplication/jsonz!if isinstance({variable}, bytes):r   z'{variable} = {variable}.decode("utf-8")r   z{name} must encoded by utf8r   zimport jsonz#{variable} = json.loads({variable})z{name} must be valid JSONNr   r   r   r   r   r   _   s    

z0CodeGeneratorDraft07.generate_content_media_type)__name__
__module____qualname__dictr   ZFORMAT_REGEXSr
   r   r   r   __classcell__r   r   r   r   r      s   	.r   N)Zdraft06r   r   r   r   r   r   <module>   s   