�
-�c~ � �z � d Z ddlZddlZ ddlZn
# e$ r dZY nw xY wdZ G d� de� � Zdd�Zd� Z d � Z
d
� ZdS )zJThe match_hostname() function from Python 3.3.3, essential when using SSL.� Nz3.5.0.1c � � e Zd ZdS )�CertificateErrorN)�__name__�
__module__�__qualname__� � �A/usr/lib/python3/dist-packages/urllib3/util/ssl_match_hostname.pyr r s � � � � � ��Dr r � c �l � g }| sdS | � d� � }|d }|dd� }|� d� � }||k rt dt | � � z � � �|s*| � � � |� � � k S |dk r|� d� � n�|� d � � s|� d � � r(|� t j |� � � � n;|� t j |� � � d
d� � � � |D ])}|� t j |� � � � �*t j
dd
� |� � z dz 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[^.]+zxn--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& |