
†Kðh~  ã               @   sœ   d  Z  d d l Z d d l Z y d d l Z Wn e k
 rH d Z Yn Xd Z Gd 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   ú[/mod/web/acousticsspace/venv/lib/python3.5/site-packages/urllib3/util/ssl_match_hostname.pyr      s   r   é   c       
      C   sU  g  } |  s d S|  j  d ƒ } | d } | d d … } | j d ƒ } | | k rj t d t |  ƒ ƒ ‚ | s† |  j ƒ  | j ƒ  k S| d k r¢ | j d ƒ nY | j d	 ƒ sÀ | j d	 ƒ rÙ | j t j | ƒ ƒ n" | j t j | ƒ j	 d
 d ƒ ƒ x$ | D] } | j t j | ƒ ƒ qWt j
 d d j | ƒ d 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   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Úpatr   r   r   Ú_dnsname_match   s*    
"&r"   c             C   s:   t  |  t ƒ r6 t j d k  r6 t |  d d d d ƒ}  |  S)Né   ÚencodingÚasciiÚerrorsÚstrict)r#   )Ú
isinstanceÚstrÚsysÚversion_infoÚunicode)Úobjr   r   r   Ú_to_unicodeO   s    r.   c             C   s%   t  j t |  ƒ j ƒ  ƒ } | | 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    r5   c             C   sù  |  s t  d ƒ ‚ y t j t | ƒ ƒ } WnG t t  f k
 rK d } Yn* t k
 rt t d k rm d } n ‚  Yn Xg  } |  j d f  ƒ } x‡ | D] \ } } | d k rÛ | d k rË t | | ƒ rË d S| j | ƒ q” | d k r” | d k	 rt	 | | ƒ rd S| j | ƒ q” W| s}x] |  j d f  ƒ D]I } x@ | D]8 \ } } | d k r=t | | ƒ rhd S| j | ƒ q=Wq0Wt
 | ƒ d k rºt d	 | d
 j t t | ƒ ƒ f ƒ ‚ n; t
 | ƒ d k rét 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ÚsubjectAltNameÚ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/   r0   r.   ÚUnicodeErrorÚAttributeErrorÚgetr"   r   r5   Úlenr   r   Úmapr   )Úcertr   r3   ÚdnsnamesÚsanÚkeyÚvalueÚsubr   r   r   Úmatch_hostnameb   sJ    	
	%rF   )Ú__doc__r   r*   r/   ÚImportErrorÚ__version__r:   r   r"   r.   r5   rF   r   r   r   r   Ú<module>   s   6