
                         t    S r SSKrSSKr SSKrSr " S S\5      rS
S jrS r	S r
S	 rg! \ a    Sr N&f = f)zJThe match_hostname() function from Python 3.3.3, essential when using SSL.    Nz3.5.0.1c                       \ rS rSrSrg)CertificateError    N)__name__
__module____qualname____firstlineno____static_attributes__r       :platform/bq/third_party/urllib3/util/ssl_match_hostname.pyr   r      s    r   r   c                 &   / nU (       d  gU R                  S5      nUS   nUSS nUR                  S5      nXr:  a  [        S[        U 5      -   5      eU(       d!  U R	                  5       UR	                  5       :H  $ US:X  a  UR                  S5        OUR                  S	5      (       d  UR                  S	5      (       a&  UR                  [        R                  " U5      5        O5UR                  [        R                  " U5      R                  S
S5      5        U H(  nUR                  [        R                  " U5      5        M*     [        R                  " SSR                  U5      -   S-   [        R                  5      n	U	R                  U5      $ )z`Matching 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)      sI   
 D HHTNEQxHab	Is#I 
 :T"XE
 	

 xxzX^^---
 3 	G			V	$	$(;(;F(C(C
 	BIIh'( 	BIIh'//w?@ BIIdO$  **UUZZ--5r}}
EC99Xr   c                 n    [        U [        5      (       a  [        R                  S:  a  [	        U SSS9n U $ )N)   asciistrict)encodingerrors)
isinstancestrsysversion_infounicode)objs    r   _to_unicoder6   P   s/    #s 0 04 7cGH=Jr   c                 d    [         R                  " [        U 5      R                  5       5      nX!:H  $ )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_addressr6   rstrip)ipnamehost_ipips      r   _ipaddress_matchr>   W   s*     
		k&188:	;B=r   c                 F   U (       d  [        S5      e [        R                  " [        U5      5      n/ nU R                  SS5      nU Ha  u  pVUS:X  a(  Uc  [        Xa5      (       a    gUR                  U5        M3  US:X  d  M;  Ub  [        Xb5      (       a    gUR                  U5        Mc     U(       dP  U R                  SS5       H:  nU H1  u  pVUS:X  d  M  [        Xa5      (       a      gUR                  U5        M3     M<     [        U5      S	:  a0  [        S
U< SSR                  [        [        U5      5      < 35      e[        U5      S	:X  a  [        S
U< SUS   < 35      e[        S5      e! [        [         4 a    Sn GNV[
         a    [        c  Sn GNke f = f)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)
ValueErrorr8   r9   r6   UnicodeErrorAttributeErrorgetr)   r   r>   lenr   r   mapr   )certr    r<   dnsnamessankeyvaluesubs           r   match_hostnamerP   c   s    -
 	

&&{8'<= H
((#R
(C
%<>%#B#BOOE"L "'7'G'GOOE"   88Ir*C!
 ,&%e66OOE* " + 8}q,4diiD(@S6TV
 	
 
X!	8TU;WXXK
 	
U *% 
  Gs   E4 4F 	F F )r   )__doc__r   r2   r8   ImportError__version__rD   r   r)   r6   r>   rP   r   r   r   <module>rT      sW    P
 
 
 	z 	3l	=
g  Is   , 77