a
    QSic~  ã                   @   sr   d Z ddlZddlZzddlZW n ey6   dZY n0 dZG dd„ deƒZddd„Zd	d
„ Z	dd„ Z
dd„ ZdS )zJThe match_hostname() function from Python 3.3.3, essential when using SSL.é    Nz3.5.0.1c                   @   s   e Zd ZdS )ÚCertificateErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú[/var/www/html/django/DPS/env/lib/python3.9/site-packages/urllib3/util/ssl_match_hostname.pyr      s   r   é   c           
      C   sò   g }| sdS |   d¡}|d }|dd… }| d¡}||krLtdt| ƒ ƒ‚|s`|  ¡ | ¡ kS |dkrt| d¡ n>| d	¡sˆ| d	¡rš| t |¡¡ n| t |¡ 	d
d¡¡ |D ]}| t |¡¡ q¶t 
dd |¡ d tj¡}	|	 |¡S )zhMatching according to RFC 6125, section 6.4.3

    http://tools.ietf.org/html/rfc6125#section-6.4.3
    FÚ.r   r   NÚ*z,too many wildcards in certificate DNS name: z[^.]+zxn--z\*z[^.]*z\Az\.z\Z)ÚsplitÚcountr   ÚreprÚlowerÚappendÚ
startswithÚreÚescapeÚreplaceÚcompileÚjoinÚ
IGNORECASEÚmatch)
ÚdnÚhostnameZmax_wildcardsZpatsÚpartsZleftmostÚ	remainderÚ	wildcardsÚfragÚpatr   r   r   Ú_dnsname_match   s,    


ÿr   c                 C   s&   t | tƒr"tjdk r"t| ddd} | S )N)é   ÚasciiÚstrict)ÚencodingÚerrors)Ú
isinstanceÚstrÚsysÚversion_infoÚunicode)Úobjr   r   r   Ú_to_unicodeO   s    r+   c                 C   s   t  t| ƒ ¡ ¡}||kS )zˆExact matching of IP addresses.

    RFC 6125 explicitly doesn't define an algorithm for this
    (section 1.7.2 - "Out of Scope").
    )Ú	ipaddressÚ
ip_addressr+   Úrstrip)ÚipnameÚhost_ipÚipr   r   r   Ú_ipaddress_matchV   s    r2   c              	   C   sv  | st dƒ‚zt t|ƒ¡}W n: tt fy8   d}Y n" tyX   tdu rRd}n‚ Y n0 g }|  dd¡}|D ]^\}}|dkr¢|du r–t||ƒr– dS | |¡ qn|dkrn|durÂt	||ƒrÂ dS | |¡ qn|s|  dd¡D ]8}|D ].\}}|dkrèt||ƒr  dS | |¡ qèqàt
|ƒd	krFtd
|d tt|ƒ¡f ƒ‚n,t
|ƒd	krjtd||d f ƒ‚ntdƒ‚dS )a)  Verify that *cert* (in decoded format as returned by
    SSLSocket.getpeercert()) matches the *hostname*.  RFC 2818 and RFC 6125
    rules are followed, but IP addresses are not accepted for *hostname*.

    CertificateError is raised on failure. On success, the function
    returns nothing.
    ztempty or no certificate, match_hostname needs a SSL socket or SSL context with either CERT_OPTIONAL or CERT_REQUIREDNÚsubjectAltNamer   ÚDNSz
IP AddressÚsubjectÚ
commonNamer   z&hostname %r doesn't match either of %sz, zhostname %r doesn't match %rr   z=no appropriate commonName or subjectAltName fields were found)Ú
ValueErrorr,   r-   r+   ÚUnicodeErrorÚAttributeErrorÚgetr   r   r2   Úlenr   r   Úmapr   )Úcertr   r0   ÚdnsnamesÚsanÚkeyÚvalueÚsubr   r   r   Úmatch_hostnameb   sR    ÿÿÿÿrC   )r   )Ú__doc__r   r'   r,   ÚImportErrorÚ__version__r7   r   r   r+   r2   rC   r   r   r   r   Ú<module>   s   

6