
    Dh~                     p    d Z ddlZddlZ	 ddlZdZ G d de      Zd
dZd Z	d Z
d	 Zy# e$ r dZY $w xY w)zJThe match_hostname() function from Python 3.3.3, essential when using SSL.    Nz3.5.0.1c                       e Zd Zy)CertificateErrorN)__name__
__module____qualname__     /var/www/fastuser/data/www/generator.snapmosaic.io/flask_app/venv/lib/python3.12/site-packages/urllib3/util/ssl_match_hostname.pyr   r      s    r	   r   c                    g }| sy| j                  d      }|d   }|dd }|j                  d      }||kD  rt        dt        |       z         |s!| j	                         |j	                         k(  S |dk(  r|j                  d       n{|j                  d	      s|j                  d	      r%|j                  t        j                  |             n4|j                  t        j                  |      j                  d
d             |D ]&  }|j                  t        j                  |             ( t        j                  ddj                  |      z   dz   t        j                        }	|	j                  |      S )zhMatching according to RFC 6125, section 6.4.3

    http://tools.ietf.org/html/rfc6125#section-6.4.3
    F.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hostnamemax_wildcardspatspartsleftmost	remainder	wildcardsfragpats
             r
   _dnsname_matchr&      sJ   
 D HHTNEQxHab	Is#I= 
 :T"XE
 	

 xxzX^^---
 3 	G			V	$(;(;F(C
 	BIIh'( 	BIIh'//w?@  %BIIdO$% **UUZZ--5r}}
EC99Xr	   c                 h    t        | t              r!t        j                  dk  rt	        | dd      } | S )N)   asciistrict)encodingerrors)
isinstancestrsysversion_infounicode)objs    r
   _to_unicoder3   O   s,    #s 0 04 7cGH=Jr	   c                 d    t        j                  t        |       j                               }||k(  S )zExact matching of IP addresses.

    RFC 6125 explicitly doesn't define an algorithm for this
    (section 1.7.2 - "Out of Scope").
    )	ipaddress
ip_addressr3   rstrip)ipnamehost_ipips      r
   _ipaddress_matchr;   V   s,     
		k&188:	;B=r	   c                    | st        d      	 t        j                  t        |            }g }| j                  dd      }|D ]S  \  }}|dk(  r"|t        ||      r y|j                  |       -|dk(  s3|t        ||      r y|j                  |       U |sG| j                  dd      D ]2  }|D ]+  \  }}|dk(  st        ||      r  y|j                  |       - 4 t        |      d	kD  r.t        d
|ddj                  t        t        |                  t        |      d	k(  rt        d
|d|d         t        d      # t        t         f$ r d}Y 2t
        $ r t        d}n Y Gw xY w)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 z doesn't match either of z, z doesn't match r   z=no appropriate commonName or subjectAltName fields were found)
ValueErrorr5   r6   r3   UnicodeErrorAttributeErrorgetr&   r   r;   lenr   r   mapr   )certr   r9   dnsnamessankeyvaluesubs           r
   match_hostnamerM   b   s    -
 	

&&{8'<= H
((#R
(C #
U%<>%#BOOE"L "'7w'GOOE"#  88Ir* 	+C! +
U ,&%eX6OOE*+	+ 8}q,4diiD(@S6TV
 	
 
X!	8TU;WXXK
 	
U *% 
  G s   E E5E54E5)r   )__doc__r   r/   r5   ImportError__version__rA   r   r&   r3   r;   rM   r   r	   r
   <module>rQ      sW    P
 
 
 	z 	3l	=
g  Is   + 55