Viewing File: /opt/alt/python35/lib/python3.5/site-packages/urllib3/__pycache__/connection.cpython-35.opt-1.pyc



`Wa-@sddlmZddlZddlZddlZddlZddlZddlmZm	Z
ddlZddlm
Z
y$ddlmZddlmZWn2ek
rddlmZddlmZYnXyddlZejZWn4eefk
r&dZGdd	d	eZYnXy
eZWn(ek
r[Gd
ddeZYnXddlmZmZmZm Z dd
l!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*ddl+m,Z,ej-e.Z/ddddiZ0ej1dddZ2Gddde3Z4Gdddee3ZGdddeZ5Gddde5Z6ddZ7ere5Z8e6Z5ne4Z5dS) )absolute_importN)errortimeout)six)HTTPConnection)
HTTPExceptionc@seZdZdS)BaseSSLErrorN)__name__
__module____qualname__r
r
/connection.pyr	sr	c@seZdZdS)ConnectionErrorN)r
rrr
r
r
rr sr)NewConnectionErrorConnectTimeoutErrorSubjectAltNameWarningSystemTimeWarning)match_hostnameCertificateError)resolve_cert_reqsresolve_ssl_versionssl_wrap_socketassert_fingerprint)
connection)HTTPHeaderDicthttpPhttpsiic@seZdZdZdS)DummyConnectionz-Used to detect a failed ConnectionCls import.N)r
rr__doc__r
r
r
rrBsrc@seZdZdZedZejejdfgZ	dZ
ddZddZd	d
Z
ddZd
d
ddZd
S)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)Nstrictsource_addresssocket_options)r#r$)rZPY3popgetr"sysversion_infodefault_socket_optionsr%_HTTPConnection__init__)selfargskwr
r
rr,ks	zHTTPConnection.__init__cCsi}|jr|j|d<|jr2|j|d<y(tj|j|jf|j|}Wn{tk
r}z$t|d|j|jfWYdd}~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%rcreate_connectionhostportr
SocketTimeoutrSocketErrorr)r-Zextra_kwconner
r
r	_new_conns 	
	
"(#zHTTPConnection._new_conncCs2||_t|ddr.|jd|_dS)N_tunnel_hostr)sockgetattr_tunnel	auto_open)r-r5r
r
r
_prepare_conns	
zHTTPConnection._prepare_conncCs|j}|j|dS)N)r7r=)r-r5r
r
rconnectszHTTPConnection.connectNcCsot|dk	r|ni}d|k}|j||d|x*|jD]\}}|j||qMWd|kr|jdd|j|dk	r^tjtjf}t||r|f}x|D]}	|	sqt|	tjs|	j	d}	t
t|	dd}
|j|
j	d	|jd
|j|	|jd
qW|jddS)z
        Alternative to the common request method, which sends the
        body with chunked encoding and not as one block
        Nzaccept-encodingskip_accept_encodingztransfer-encodingzTransfer-EncodingZchunkedutf8r#zutf-8s
s0

)
rZ
putrequestitemsZ	putheaderZ
endheadersrZstring_typesZbinary_type
isinstanceencodehexlensend)r-methodZurlZbodyZheadersr?headervalueZstringish_typeschunkZlen_strr
r
rrequest_chunkeds.
	


zHTTPConnection.request_chunked)r
rrr port_by_schemedefault_portsocketIPPROTO_TCPTCP_NODELAYr*is_verifiedr,r7r=r>rKr
r
r
rrGs
rc@sDeZdZedZddddejddZddZdS)HTTPSConnectionrNc	KsAtj|||d|d||||_||_d|_dS)Nr!rr)rr,key_file	cert_fileZ	_protocol)r-r1r2rSrTr!rr/r
r
rr,s

		zHTTPSConnection.__init__cCs;|j}|j|tj||j|j|_dS)N)r7r=sslZwrap_socketrSrTr9)r-r5r
r
rr>s
zHTTPSConnection.connect)	r
rrrLrMrN_GLOBAL_DEFAULT_TIMEOUTr,r>r
r
r
rrRs
	rRc	@saeZdZdZdZdZdZdZdZdddddddddZ	ddZ
dS)VerifiedHTTPSConnectionz[
    Based on httplib.HTTPSConnection but wraps the socket with
    SSL certification.
    NcCs|s|r|dkrd}||_||_||_||_||_|o`tjj||_|o{tjj||_	dS)N
CERT_REQUIRED)
rSrT	cert_reqsassert_hostnamerospath
expanduserca_certsca_cert_dir)r-rSrTrYr^rZrr_r
r
rset_certs					z VerifiedHTTPSConnection.set_certcCs|j}t|j}t|j}|j}t|ddrj||_|jd|_	|j
}tjj
tk}|rtjdjttt||j|jd|d|jd|jd|d||_|jrt|jjd	d
|jnn|tjkrv|jdk	rv|jj}|jdfs`tjd
j|tt||jpr||tj kp|jdk	|_!dS)Nr8rzWSystem time is way off (before {0}). This will probably lead to SSL verification errorsrYr^r_Zserver_hostnamessl_versionZbinary_formTFZsubjectAltNamezCertificate 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.))"r7rrYrrar1r:r9r;r<r8datetimedateZtodayRECENT_DATEwarningswarnformatrrrSrTr^r_rZgetpeercertrUZ	CERT_NONErZr'r_match_hostnamerXrQ)r-r5Zresolved_cert_reqsZresolved_ssl_versionhostnameZis_time_offcertr
r
rr>sF		
					
zVerifiedHTTPSConnection.connect)r
rrr rYr^r_rarr`r>r
r
r
rrWs
rWcCs\yt||WnDtk
rW}z$tjd||||_WYdd}~XnXdS)Nz@Certificate did not match expected hostname: %s. Certificate: %s)rrlogrZ
_peer_cert)rjZasserted_hostnamer6r
r
rrh7s
	rh)9Z
__future__rrbloggingr[r(rNrr4rr3reZpackagesrZhttp.clientrr+rImportErrorhttplibrUZSSLErrorr	AttributeError
BaseExceptionr	NameError	Exception
exceptionsrrrrZpackages.ssl_match_hostnamerrZ	util.ssl_rrrrutilr_collectionsr	getLoggerr
rkrLrcrdobjectrrRrWrhZUnverifiedHTTPSConnectionr
r
r
r<module>sT



""V	
Back to Directory File Manager