o
    e9                     @  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< 								dgdhddZ%e%dde%dddiddZ&e%ddddddej'ddidd Z(e%d!ej'd"did#d$Z)ee* d d%l+m,Z, e%d&d'd'd'd'd'ddid(d)Z-W d   n1 sw   Y  ee* d dl.Z.e%d*d*d*e.j/e0fd+did,d-Z1W d   n	1 sw   Y  zd dl2Z2W n= e*yK   ee*& d d.l3m4Z4 e%d/ddid0d1Z5e%d2d2d2d2e6d3did4d5Z7W d   n	1 sDw   Y  Y n4w e%d6d6d6e6d+did7d8Z8e%d9d9d9e6d+did:d;Z9e%d/e6d"did<d1Z5e%d2d2d2d2e6d3did=d5Z7ee*$ d d>l:m;Z; e%d?ddid@dAZ<e%dBdBdBdCdidDdEZ=W d   n	1 sw   Y  e%dFej>d"didGdHZ?e%dIdIdIdIe6dJdidKdLZ@e%dBe6dMdidNdOZAee*$ d dPlBmCZC d dlBZBdidQdRZDe%dSe6eEfdMdidTdUZFW d   n	1 sw   Y  ee*) d dlGZGe%dVdVdVdVeGjHd3didWdXZIe%dYdYdYeGjHd+didZd[ZJW d   n	1 s7w   Y  ee* d dlKZKe%d\d\d\d\d]did^d_ZLW d   n	1 s]w   Y  ee* d dlMZMe%d`d`eMjNdadidbdcZOW d   n	1 sw   Y  e%dddde6dadidedfZPdS )j    )annotations)suppress)UUIDN)FormatError_F)bound.z^\d{4}-\d{2}-\d{2}$c                   @  sx   e Zd ZU dZi Zded< d d!ddZd	d
 Z	d"d#ddZe		d"d#ddZ
e		d"d#ddZd$ddZ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]]checkersNformatstyping.Iterable[str] | Nonec                   s*   |d u r	 j  } fdd|D  _ d S )Nc                   s   i | ]}| j | qS  r	   ).0kselfr   BD:\Projects\ConvertPro\env\Lib\site-packages\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   formatstrraises_RaisesTypereturntyping.Callable[[_F], _F]c                   s   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.
        funcr   r   c                   s   | fj  < | S Nr   r   r   r   r   r   r   _checksP      z%FormatChecker.checks.<locals>._checksNr   r   r   r   r   )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 fdd}|S )Nr   r   r   c                   s   | f j < | S r    r   r!   r-   r   r   r#   i   r$   z*FormatChecker._cls_checks.<locals>._checksr%   r   )r.   r   r   r#   r   r-   r   r,   e   s   zFormatChecker._cls_checksinstanceobjectNonec              
   C  sx   || j vrdS | j | \}}d\}}z||}W n |y, } z|}W Y d}~nd}~ww |s:t|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   resultr3   er   r   r   checko   s   
zFormatChecker.checkboolc                 C  s(   z	|  || W dS  ty   Y dS w )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
        FT)r6   r   )r   r0   r   r   r   r   conforms   s   zFormatChecker.conformsr    )r
   r   )r   )r   r   r   r   r   r   )r0   r1   r   r   r   r2   )r0   r1   r   r   r   r7   )__name__
__module____qualname____doc__r	   __annotations__r   r   r&   classmethodr/   r,   r6   r8   r   r   r   r   r      s    
 

	 r   )draft3draft4draft6draft7draft201909draft202012zdict[str, FormatChecker]_draft_checkersr   r   r   c           	        sN   p| p| p| p|  p|  p| d fdd}|S )Nr   r   r   c                   s   rt d | } rt d | } r$t d | } r0t d | }  r<t d  | } rHt d | } tpU pUpUpUpU|  | S )Nr?   r@   rA   rB   rC   rD   )rE   r&   r   r,   r!   rC   rD   r?   r@   rA   rB   r   r   r   wrap   s.   z_checks_drafts.<locals>.wrapr%   r   )	namer?   r@   rA   rB   rC   rD   r   rG   r   rF   r   _checks_drafts   s   
rI   z	idn-email)rH   emailr0   r1   r7   c                 C  s   t | tsdS d| v S )NT@)
isinstancer   r0   r   r   r   is_email   s   
rN   z
ip-addressZipv4)r?   r@   rA   rB   rC   rD   r   c                 C     t | tsdS tt| S NT)rL   r   r7   	ipaddressIPv4AddressrM   r   r   r   is_ipv4   s   

rS   Zipv6)rH   r   c                 C  s&   t | tsdS t| }t|dd S )NTscope_id )rL   r   rQ   IPv6Addressgetattr)r0   addressr   r   r   is_ipv6   s   

rY   )FQDNz	host-namehostnamec                 C  s   t | tsdS t| jS rP   )rL   r   rZ   Zis_validrM   r   r   r   is_host_name
  s   
	
r\   zidn-hostname)rB   rC   rD   r   c                 C  s   t | tsdS t|  dS rP   )rL   r   idnaencoderM   r   r   r   is_idn_host_name  s   

r_   )validate_rfc3986uric                 C     t | tsdS t| ddS NTURIrulerL   r   r`   rM   r   r   r   is_uri/     
rh   zuri-reference)rA   rB   rC   rD   r   c                 C  rb   NTZURI_referencere   rg   rM   r   r   r   is_uri_reference5  s   
rk   Ziric                 C     t | tsdS tj| ddS )NTZIRIre   rL   r   rfc3987parserM   r   r   r   is_iriC     
rp   ziri-referencec                 C  rl   )NTZIRI_referencere   rm   rM   r   r   r   is_iri_referenceN  rq   rr   c                 C  rl   rc   rm   rM   r   r   r   rh   Y     
c                 C  rl   rj   rm   rM   r   r   r   rk   _     
)validate_rfc3339z	date-timec                 C  s   t | tsdS t|  S rP   )rL   r   ru   upperrM   r   r   r   is_datetimeo  ri   rw   time)rB   rC   rD   c                 C  s   t | tsdS td|  S )NTz1970-01-01T)rL   r   rw   rM   r   r   r   is_timeu  s   
ry   regexc                 C  rO   rP   )rL   r   r7   recompilerM   r   r   r   is_regex  rs   r}   date)r?   rB   rC   rD   r   c                 C  s(   t | tsdS tt| otj| S rP   )rL   r   r7   _RE_DATE	fullmatchdatetimer~   fromisoformatrM   r   r   r   is_date  s   


r   )r?   r   c                 C  s    t | tsdS ttj| dS )NTz%H:%M:%S)rL   r   r7   r   strptimerM   r   r   r   is_draft3_time  s   
r   )CSS21_NAMES_TO_HEXc                 C  s
   t | S r    )	webcolorsZnormalize_hexrM   r   r   r   is_css_color_code  s   
r   colorc                 C  s"   t | tr|  tv rdS t| S rP   )rL   r   lowerr   r   rM   r   r   r   is_css21_color  s
   r   zjson-pointerc                 C  rO   rP   )rL   r   r7   jsonpointerJsonPointerrM   r   r   r   is_json_pointer  rt   r   zrelative-json-pointerc                 C  s   t | tsdS | sdS g d}}t| D ]*\}}| r3|dkr-t| |d  dkr- dS || q|s8 dS | |d  } |dkpItt|S )NTFrU   r      #)	rL   r   	enumerateisdigitintappendr7   r   r   )r0   Znon_negative_integerresti	characterr   r   r   is_relative_json_pointer  s    
	

r   zuri-template)rA   rB   rC   rD   c                 C  s   t | tsdS t| S rP   )rL   r   uri_templatevalidaterM   r   r   r   is_uri_template  s   

r   duration)rC   rD   r   c                 C  s&   t | tsdS t|  | tdS )NTZDMYWHMS)rL   r   isodurationZparse_durationendswithtuplerM   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   positionrM   r   r   	<genexpr>
  s    zis_uuid.<locals>.<genexpr>)            )rL   r   r   allrM   r   rM   r   is_uuid  s   
r   )NNNNNNNr   )r   r   )r0   r1   r   r7   )Q
__future__r   
contextlibr   r   r   r   rQ   r{   typingr)   Zjsonschema.exceptionsr   Callabler1   r7   Z_FormatCheckCallableTypeVarr   UnionType	ExceptionTupler   r|   ASCIIr   r   Zdraft3_format_checkerZdraft4_format_checkerZdraft6_format_checkerZdraft7_format_checkerZdraft201909_format_checkerZdraft202012_format_checkerdictrE   r=   rI   rN   AddressValueErrorrS   rY   ImportErrorfqdnrZ   r\   r]   	IDNAErrorUnicodeErrorr_   rn   Zrfc3986_validatorr`   rh   
ValueErrorrk   rp   rr   Zrfc3339_validatorru   rw   ry   errorr}   r   r   r   r   r   	TypeErrorr   r   ZJsonPointerExceptionr   r   r   r   r   ZDurationParsingExceptionr   r   r   r   r   r   <module>   s    .	





	


	
3
