Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/urllib3/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/urllib3/__pycache__/connection.cpython-35.pyc



[�8�@s_ddlmZddlZddlZddlZddlZddlZddlmZm	Z
ddlZddlm
Z
ddlmZddlmZyddlZejZWn4eefk
r�dZGdd	�d	e�ZYnXy
eZWn(ek
r"Gd
d�de�ZYnXddlmZmZmZmZdd
l m!Z!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*ddl+m,Z,ej-e.�Z/ddddiZ0ej1ddd�Z2Gdd�de3�Z4Gdd�dee3�ZGdd�de�Z5Gdd�de5�Z6d d!�Z7erUe5Z8e6Z5ne4Z5dS)"�)�absolute_importN)�error�timeout�)�six)�HTTPConnection)�
HTTPExceptionc@seZdZdS)�BaseSSLErrorN)�__name__�
__module__�__qualname__�r
r
�C/opt/alt/python35/lib/python3.5/site-packages/urllib3/connection.pyr	sr	c@seZdZdS)�ConnectionErrorN)r
rrr
r
r
rrsr)�NewConnectionError�ConnectTimeoutError�SubjectAltNameWarning�SystemTimeWarning)�match_hostname�CertificateError)�resolve_cert_reqs�resolve_ssl_version�assert_fingerprint�create_urllib3_context�ssl_wrap_socket)�
connection)�HTTPHeaderDict�http�P�httpsi�i���c@seZdZdZdS)�DummyConnectionz-Used to detect a failed ConnectionCls import.N)r
rr�__doc__r
r
r
rr"Bsr"c@s�eZdZdZedZejejdfgZ	dZ
dd�Zedd��Z
e
jd	d��Z
d
d�Zdd
�Zdd�Zdddd�ZdS)ra{
    Based on httplib.HTTPConnection but provides an extra constructor
    backwards-compatibility layer between older and newer Pythons.

    Additional keyword parameters are used to configure attributes of the connection.
    Accepted parameters include:

      - ``strict``: See the documentation on :class:`urllib3.connectionpool.HTTPConnectionPool`
      - ``source_address``: Set the source address for the current connection.

        .. note:: This is ignored for Python 2.6. It is only applied for 2.7 and 3.x

      - ``socket_options``: Set specific options on the underlying socket. If not specified, then
        defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling
        Nagle's algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy.

        For example, if you wish to enable TCP Keep Alive in addition to the defaults,
        you might pass::

            HTTPConnection.default_socket_options + [
                (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
            ]

        Or you may want to disable the defaults by passing an empty list (e.g., ``[]``).
    rrFcOsytjr|jdd�|jd�|_tjdkrJ|jdd�|jd|j�|_t	j
|||�dS)N�strict�source_address���socket_options)r&r')r�PY3�pop�getr%�sys�version_info�default_socket_optionsr(�_HTTPConnection�__init__)�self�args�kwr
r
rr0ks	zHTTPConnection.__init__cCs|jjd�S)a�
        Getter method to remove any trailing dots that indicate the hostname is an FQDN.

        In general, SSL certificates don't include the trailing dot indicating a
        fully-qualified domain name, and thus, they don't validate properly when
        checked against a domain name that includes the dot. In addition, some
        servers may not expect to receive the trailing dot when provided.

        However, the hostname with trailing dot is critical to DNS resolution; doing a
        lookup with the trailing dot will properly only resolve the appropriate FQDN,
        whereas a lookup without a trailing dot will search the system's search domain
        list. Thus, it's important to keep the original host around for use only in
        those cases where it's appropriate (i.e., when doing DNS lookup to establish the
        actual TCP connection across which we're going to send HTTP requests).
        �.)�	_dns_host�rstrip)r1r
r
r�host�szHTTPConnection.hostcCs
||_dS)z�
        Setter for the `host` property.

        We assume that only urllib3 uses the _dns_host attribute; httplib itself
        only uses `host`, and it seems reasonable that other libraries follow suit.
        N)r5)r1�valuer
r
rr7�scCs�i}|jr|j|d<|jr2|j|d<y(tj|j|jf|j|�}Wn{tk
r�}z$t|d|j	|jf��WYdd}~Xn8t
k
r�}zt|d|��WYdd}~XnX|S)zp Establish a socket connection and set nodelay settings on it.

        :return: New socket connection.
        r%r(z0Connection to %s timed out. (connect timeout=%s)Nz(Failed to establish a new connection: %s)r%r(r�create_connectionr5�portr�
SocketTimeoutrr7�SocketErrorr)r1Zextra_kw�conn�er
r
r�	_new_conn�s 	
	
"(#zHTTPConnection._new_conncCs2||_t|dd�r.|j�d|_dS)N�_tunnel_hostr)�sock�getattr�_tunnel�	auto_open)r1r=r
r
r�
_prepare_conn�s	
zHTTPConnection._prepare_conncCs|j�}|j|�dS)N)r?rE)r1r=r
r
r�connect�szHTTPConnection.connectNcCs�t|dk	r|ni�}d|k}d|k}|j||d|d|�x*|j�D]\}}|j||�q_Wd|kr�|jdd�|j�|dk	rptjtjf}	t||	�r�|f}x�|D]�}
|
s�q�t|
tj�s|
j	d	�}
t
t|
��d
d�}|j|j	d��|jd�|j|
�|jd�q�W|jd
�dS)z�
        Alternative to the common request method, which sends the
        body with chunked encoding and not as one block
        Nzaccept-encodingr7�skip_accept_encoding�	skip_hostztransfer-encodingzTransfer-EncodingZchunked�utf8r&zutf-8s
s0

)
rZ
putrequest�itemsZ	putheaderZ
endheadersr�string_types�binary_type�
isinstance�encode�hex�len�send)r1�method�url�body�headersrGrH�headerr8Zstringish_types�chunkZlen_strr
r
r�request_chunked�s8
	


zHTTPConnection.request_chunked)r
rrr#�port_by_scheme�default_port�socket�IPPROTO_TCP�TCP_NODELAYr.�is_verifiedr0�propertyr7�setterr?rErFrXr
r
r
rrGs

rc@sMeZdZedZdZddddejddd�Zdd�Z	dS)�HTTPSConnectionrNc		KsJtj|||d|d||�||_||_||_d|_dS)Nr$rr)rr0�key_file�	cert_file�ssl_contextZ	_protocol)	r1r7r:rbrcr$rrdr3r
r
rr0�s
			zHTTPSConnection.__init__c	Cs}|j�}|j|�|jdkrLtdtd�dtd��|_td|d|jd|jd|j�|_	dS)N�ssl_version�	cert_reqsrA�keyfile�certfilerd)
r?rErdrrrrrbrcrA)r1r=r
r
rrFs
		zHTTPSConnection.connect)
r
rrrYrZrer[�_GLOBAL_DEFAULT_TIMEOUTr0rFr
r
r
rra�s
		
rac	@saeZdZdZdZdZdZdZdZddddddddd�Z	dd�Z
dS)�VerifiedHTTPSConnectionz[
    Based on httplib.HTTPSConnection but wraps the socket with
    SSL certification.
    NcCs�|dkr<|s|r!d}n|jdk	r<|jj}||_||_||_||_||_|o~tjj	|�|_
|o�tjj	|�|_dS)zX
        This method should only be called once, before the connection is used.
        N�
CERT_REQUIRED)rd�verify_moderbrcrf�assert_hostnamer�os�path�
expanduser�ca_certs�ca_cert_dir)r1rbrcrfrqrmrrrr
r
r�set_certs						z VerifiedHTTPSConnection.set_certcCs�|j�}|j}t|dd�rL||_|j�d|_|j}tjj	�t
k}|r�tjdj
t
�t�|jdkr�tdt|j�dt|j��|_|j}t|j�|_td|d|jd|jd	|jd
|jd|d|�|_|jrAt|jjd
d�|j�n�|jtjkr�t|dd�r�|jdk	r�|jj�}|j df�s�tjdj
|�t!�t"||jp�|�|jtj#kp�|jdk	|_$dS)Nr@rzWSystem time is way off (before {0}). This will probably lead to SSL verification errorsrerfrArgrhrqrrZserver_hostnamerdZbinary_formTZcheck_hostnameFZsubjectAltNamez�Certificate for {0} has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.))%r?r7rBrArCrDr@�datetime�date�today�RECENT_DATE�warnings�warn�formatrrdrrrerrfrlrrbrcrqrrrZgetpeercert�sslZ	CERT_NONErmr+r�_match_hostnamerkr^)r1r=�hostnameZis_time_off�context�certr
r
rrF8sT		
								
zVerifiedHTTPSConnection.connect)r
rrr#rfrqrrrerrsrFr
r
r
rrjsrjcCs\yt||�WnDtk
rW}z$tjd||�||_�WYdd}~XnXdS)Nz@Certificate did not match expected hostname: %s. Certificate: %s)rr�logrZ
_peer_cert)rZasserted_hostnamer>r
r
rr|�s
	r|)9�
__future__rrtZloggingrnr,r[rr<rr;rx�packagesrZpackages.six.moves.http_clientrr/rr{ZSSLErrorr	�ImportError�AttributeError�
BaseExceptionr�	NameError�	Exception�
exceptionsrrrrZpackages.ssl_match_hostnamerrZ	util.ssl_rrrrr�utilr�_collectionsrZ	getLoggerr
r�rYrurw�objectr"rarjr|ZUnverifiedHTTPSConnectionr
r
r
r�<module>sL


"(	�&l