U
    d9                     @  s  U d dl mZ d dlmZ d dlmZ d dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZ e	jegef Ze	jdedZe	je	je e	je	je df f Zed	ejZG d
d dZe Ze Ze Ze Ze Z e Z!e"eeeee e!dZ#de$d< dgddddZ%e%dde%dddddddZ&e%ddddddej'dddddd Z(e%d!ej'd"dddd#d$Z)ee*6 d d%l+m,Z, e%d&d'd'd'd'd'ddddd(d)Z-W 5 Q R X ee*4 d dl.Z.e%d*d*d*e.j/e0fd+dddd,d-Z1W 5 Q R X zd dl2Z2W nr e*k
rv   ee*N d d.l3m4Z4 e%d/ddddd0d1Z5e%d2d2d2d2e6d3dddd4d5Z7W 5 Q R X Y nX e%d6d6d6e6d+dddd7d8Z8e%d9d9d9e6d+dddd:d;Z9e%d/e6d"dddd<d1Z5e%d2d2d2d2e6d3dddd=d5Z7ee*J d d>l:m;Z; e%d?ddddd@dAZ<e%dBdBdBdCddddDdEZ=W 5 Q R X e%dFej>d"ddddGdHZ?e%dIdIdIdIe6dJddddKdLZ@e%dBe6dMddddNdOZAee*J d dPlBmCZC d dlBZBddddQdRZDe%dSe6eEfdMddddTdUZFW 5 Q R X ee*T d dlGZGe%dVdVdVdVeGjHd3ddddWdXZIe%dYdYdYeGjHd+ddddZd[ZJW 5 Q R X ee*. d dlKZKe%d\d\d\d\d]dddd^d_ZLW 5 Q R X ee*. d dlMZMe%d`d`eMjNdaddddbdcZOW 5 Q R X e%dddde6daddddedfZPdS )h    )annotations)suppress)UUIDN)FormatError_F)bound.z^\d{4}-\d{2}-\d{2}$c                   @  s   e Zd ZU dZi Zded< dddddZd	d
 ZdddddddZe	d ddddddZ
e	d!ddddddZddddddZddddddZdS )"FormatCheckeray  
    A ``format`` property checker.

    JSON Schema does not mandate that the ``format`` property actually do any
    validation. If validation is desired however, instances of this class can
    be hooked into validators to enable format validation.

    `FormatChecker` objects always return ``True`` when asked about
    formats that they do not know how to validate.

    To add a check for a custom format use the `FormatChecker.checks`
    decorator.

    Arguments:

        formats:

            The known formats to validate. This argument can be used to
            limit which formats will be used during validation.
    z3dict[str, tuple[_FormatCheckCallable, _RaisesType]]checkersNztyping.Iterable[str] | None)formatsc                   s*   |d kr j  } fdd|D  _ d S )Nc                   s   i | ]}| j | qS  r	   ).0kselfr   6/tmp/pip-unpacked-wheel-afshzn49/jsonschema/_format.py
<dictcomp>5   s      z*FormatChecker.__init__.<locals>.<dictcomp>)r	   keys)r   r
   r   r   r   __init__2   s    
zFormatChecker.__init__c                 C  s   dt | j dS )Nz<FormatChecker checkers=>)sortedr	   r   r   r   r   __repr__7   s    zFormatChecker.__repr__r   str_RaisesTypetyping.Callable[[_F], _F])formatraisesreturnc                   s   ddd fdd}|S )a  
        Register a decorated function as validating a new format.

        Arguments:

            format:

                The format that the decorated function will check.

            raises:

                The exception(s) raised by the decorated function when an
                invalid instance is found.

                The exception object will be accessible as the
                `jsonschema.exceptions.ValidationError.cause` attribute of the
                resulting validation error.
        r   funcr   c                   s   | fj  < | S Nr   r   r   r   r   r   r   _checksP   s    z%FormatChecker.checks.<locals>._checksr   )r   r   r   r#   r   r"   r   checks:   s    zFormatChecker.checksc                 C  s   t jdtdd | j||dS )NzoFormatChecker.cls_checks is deprecated. Call FormatChecker.checks on a specific FormatChecker instance instead.   )
stacklevel)r   r   )warningswarnDeprecationWarning_cls_checksclsr   r   r   r   r   
cls_checksV   s    	zFormatChecker.cls_checksc                   s   ddd fdd}|S )Nr   r   c                   s   | f j < | S r    r   r!   r+   r   r   r#   i   s    z*FormatChecker._cls_checks.<locals>._checksr   )r,   r   r   r#   r   r+   r   r*   e   s    zFormatChecker._cls_checksobjectNone)instancer   r   c              
   C  sv   || j krdS | j | \}}d\}}z||}W n& |k
rV } z|}W 5 d}~X Y nX |srt|d||ddS )a  
        Check whether the instance conforms to the given format.

        Arguments:

            instance (*any primitive type*, i.e. str, number, bool):

                The instance to check

            format:

                The format that instance should conform to

        Raises:

            FormatError:

                if the instance does not conform to ``format``
        N)NNz
 is not a )cause)r	   r   )r   r0   r   r   r   resultr1   er   r   r   checko   s    
zFormatChecker.checkboolc                 C  s0   z|  || W n tk
r&   Y dS X dS dS )aV  
        Check whether the instance conforms to the given format.

        Arguments:

            instance (*any primitive type*, i.e. str, number, bool):

                The instance to check

            format:

                The format that instance should conform to

        Returns:

            bool: whether it conformed
        FTN)r4   r   )r   r0   r   r   r   r   conforms   s
    zFormatChecker.conforms)N)r   )r   )r   )__name__
__module____qualname____doc__r	   __annotations__r   r   r$   classmethodr-   r*   r4   r6   r   r   r   r   r      s   

   	 r   )draft3draft4draft6draft7draft201909draft202012zdict[str, FormatChecker]_draft_checkersr   r   )r   c           	        sT   p| p| p| p|  p&|  p.| ddd fdd}|S )Nr   r   c                   s   rt d | } r0t d | } rHt d | } r`t d | }  rxt d  | } rt d | } tp pppp|  | S )Nr=   r>   r?   r@   rA   rB   )rC   r$   r   r*   r!   rA   rB   r=   r>   r?   r@   r   r   r   wrap   s.    z_checks_drafts.<locals>.wrapr   )	namer=   r>   r?   r@   rA   rB   r   rE   r   rD   r   _checks_drafts   s    
 rG   z	idn-email)rF   emailr.   r5   )r0   r   c                 C  s   t | tsdS d| kS )NT@)
isinstancer   r0   r   r   r   is_email   s    
rL   z
ip-addressZipv4)r=   r>   r?   r@   rA   rB   r   c                 C  s   t | tsdS tt| S NT)rJ   r   r5   	ipaddressIPv4AddressrK   r   r   r   is_ipv4   s    

rP   Zipv6)rF   r   c                 C  s&   t | tsdS t| }t|dd S )NTZscope_id )rJ   r   rN   IPv6Addressgetattr)r0   addressr   r   r   is_ipv6   s    

rU   )FQDNz	host-namehostnamec                 C  s   t | tsdS t| jS rM   )rJ   r   rV   Zis_validrK   r   r   r   is_host_name
  s    	
rX   zidn-hostname)r@   rA   rB   r   c                 C  s   t | tsdS t|  dS rM   )rJ   r   idnaencoderK   r   r   r   is_idn_host_name  s    

r[   )validate_rfc3986uric                 C  s   t | tsdS t| ddS NTURIZrulerJ   r   r\   rK   r   r   r   is_uri/  s    
rb   zuri-reference)r?   r@   rA   rB   r   c                 C  s   t | tsdS t| ddS NTZURI_referencer`   ra   rK   r   r   r   is_uri_reference5  s    
rd   Ziric                 C  s   t | tsdS tj| ddS )NTZIRIr`   rJ   r   rfc3987parserK   r   r   r   is_iriC  s    
rh   ziri-referencec                 C  s   t | tsdS tj| ddS )NTZIRI_referencer`   re   rK   r   r   r   is_iri_referenceN  s    
ri   c                 C  s   t | tsdS tj| ddS r^   re   rK   r   r   r   rb   Y  s    
c                 C  s   t | tsdS tj| ddS rc   re   rK   r   r   r   rd   _  s    
)validate_rfc3339z	date-timec                 C  s   t | tsdS t|  S rM   )rJ   r   rj   upperrK   r   r   r   is_datetimeo  s    
rl   time)r@   rA   rB   c                 C  s   t | tsdS td|  S )NTz1970-01-01T)rJ   r   rl   rK   r   r   r   is_timeu  s    
rn   regexc                 C  s   t | tsdS tt| S rM   )rJ   r   r5   recompilerK   r   r   r   is_regex  s    
rr   date)r=   r@   rA   rB   r   c                 C  s(   t | tsdS tt| o$tj| S rM   )rJ   r   r5   _RE_DATE	fullmatchdatetimers   fromisoformatrK   r   r   r   is_date  s    


rx   )r=   r   c                 C  s    t | tsdS ttj| dS )NTz%H:%M:%S)rJ   r   r5   rv   strptimerK   r   r   r   is_draft3_time  s    
rz   )CSS21_NAMES_TO_HEXc                 C  s
   t | S r    )	webcolorsZnormalize_hexrK   r   r   r   is_css_color_code  s    r}   colorc                 C  s"   t | tr|  tkrdS t| S rM   )rJ   r   lowerr{   r}   rK   r   r   r   is_css21_color  s    
r   zjson-pointerc                 C  s   t | tsdS tt| S rM   )rJ   r   r5   jsonpointerJsonPointerrK   r   r   r   is_json_pointer  s    
r   zrelative-json-pointerc                 C  s   t | tsdS | sdS g d }}t| D ]X\}}| rf|dkrZt| |d  dkrZ dS || q(|sp dS | |d  } qq(|dkptt|S )NTFrQ   r      #)	rJ   r   	enumerateisdigitintappendr5   r   r   )r0   Znon_negative_integerresti	characterr   r   r   is_relative_json_pointer  s     	


r   zuri-template)r?   r@   rA   rB   c                 C  s   t | tsdS t| S rM   )rJ   r   uri_templatevalidaterK   r   r   r   is_uri_template  s    
r   duration)rA   rB   r   c                 C  s&   t | tsdS t|  | tdS )NTZDMYWHMS)rJ   r   isodurationZparse_durationendswithtuplerK   r   r   r   is_duration  s    

r   uuidc                   s,   t  tsdS t  t fdddD S )NTc                 3  s   | ]} | d kV  qdS )-Nr   )r   positionrK   r   r   	<genexpr>
  s     zis_uuid.<locals>.<genexpr>)            )rJ   r   r   allrK   r   rK   r   is_uuid  s    
r   )NNNNNNNr   )Q
__future__r   
contextlibr   r   r   rv   rN   rp   typingr'   Zjsonschema.exceptionsr   Callabler.   r5   Z_FormatCheckCallableTypeVarr   UnionType	ExceptionTupler   rq   ASCIIrt   r   Zdraft3_format_checkerZdraft4_format_checkerZdraft6_format_checkerZdraft7_format_checkerZdraft201909_format_checkerZdraft202012_format_checkerdictrC   r;   rG   rL   AddressValueErrorrP   rU   ImportErrorZfqdnrV   rX   rY   	IDNAErrorUnicodeErrorr[   rf   Zrfc3986_validatorr\   rb   
ValueErrorrd   rh   ri   Zrfc3339_validatorrj   rl   rn   errorrr   rx   rz   r|   r{   r}   	TypeErrorr   r   ZJsonPointerExceptionr   r   r   r   r   ZDurationParsingExceptionr   r   r   r   r   r   <module>   sl            .	


"

	

	
	

