B
    uffN  ã            	   @   s  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ	 d dlm
Z ddlmZ ddlmZ ddlmZ dd	lmZ yd dlZejZW n, eefk
rÂ   dZG d
d„ deƒZY nX yeZW n$ ek
rð   G dd„ deƒZY nX yeZW n& ek
r    G dd„ deƒZY nX ddlmZ ddl m!Z! ddl"m#Z#m$Z$m%Z%m&Z& ddl'm(Z(m)Z)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4 e 5e6¡Z7dddœZ8e 9ddd¡Z:e ;d¡Z<G dd„ dee=ƒZG dd„ deƒZ>dd „ Z?d!d"„ Z@G d#d$„ d$e=ƒZAeseAZ>e>ZBdS )%é    )Úabsolute_importN)Úerror)Útimeouté   )Úsix)ÚHTTPConnection)ÚHTTPException)Úcreate_proxy_ssl_contextc               @   s   e Zd ZdS )ÚBaseSSLErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú`/home/ankuromar296_gmail_com/myenv/lib/python3.7/site-packages/pip/_vendor/urllib3/connection.pyr
      s   r
   c               @   s   e Zd ZdS )ÚConnectionErrorN)r   r   r   r   r   r   r   r   !   s   r   c               @   s   e Zd ZdS )ÚBrokenPipeErrorN)r   r   r   r   r   r   r   r   *   s   r   )ÚHTTPHeaderDict)Ú__version__)ÚConnectTimeoutErrorÚNewConnectionErrorÚSubjectAltNameWarningÚSystemTimeWarning)ÚSKIP_HEADERÚSKIPPABLE_HEADERSÚ
connection)Úassert_fingerprintÚcreate_urllib3_contextÚis_ipaddressÚresolve_cert_reqsÚresolve_ssl_versionÚssl_wrap_socket)ÚCertificateErrorÚmatch_hostnameéP   i»  )ÚhttpÚhttpsiæ  z[^-!#$%&'*+.^_`|~0-9a-zA-Z]c                   sž   e Zd ZdZed ZejejdfgZ	dZ
dZdd„ Zedd	„ ƒZejd
d	„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd‡ fdd„	Zddd„Z‡  ZS )r   a5  
    Based on :class:`http.client.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.
    - ``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:

      .. code-block:: python

         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., ``[]``).
    r$   r   FNc             O   s`   t js| dd ¡ | d¡| _| d| j¡| _| dd ¡| _| dd ¡| _t	j
| f|ž|Ž d S )NÚstrictÚsource_addressÚsocket_optionsÚproxyÚproxy_config)r   ÚPY2ÚpopÚgetr'   Údefault_socket_optionsr(   r)   r*   Ú_HTTPConnectionÚ__init__)ÚselfÚargsÚkwr   r   r   r0   s   s    zHTTPConnection.__init__c             C   s   | j  d¡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)r1   r   r   r   Úhost„   s    zHTTPConnection.hostc             C   s
   || _ dS )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   r   r7   —   s    c          
   C   s    i }| j r| j |d< | jr$| j|d< ytj| j| jf| jf|Ž}W nX tk
rl   t| d| j	| jf ƒ‚Y n0 t
k
rš } zt| d| ƒ‚W dd}~X Y nX |S )zoEstablish a socket connection and set nodelay settings on it.

        :return: New socket connection.
        r'   r(   z0Connection to %s timed out. (connect timeout=%s)z(Failed to establish a new connection: %sN)r'   r(   r   Úcreate_connectionr5   Úportr   ÚSocketTimeoutr   r7   ÚSocketErrorr   )r1   Zextra_kwÚconnÚer   r   r   Ú	_new_conn¡   s"    

zHTTPConnection._new_connc             C   s   t | dd ƒS )NÚ_tunnel_host)Úgetattr)r1   r   r   r   Ú_is_using_tunnelÀ   s    zHTTPConnection._is_using_tunnelc             C   s    || _ |  ¡ r|  ¡  d| _d S )Nr   )ÚsockrB   Ú_tunnelÚ	auto_open)r1   r=   r   r   r   Ú_prepare_connÄ   s    zHTTPConnection._prepare_connc             C   s   |   ¡ }|  |¡ d S )N)r?   rF   )r1   r=   r   r   r   ÚconnectÌ   s    zHTTPConnection.connectc             O   s8   t  |¡}|r"td|| ¡ f ƒ‚tj| ||f|ž|ŽS )ú zAMethod cannot contain non-token characters %r (found at least %r))Ú_CONTAINS_CONTROL_CHAR_REÚsearchÚ
ValueErrorÚgroupr/   Ú
putrequest)r1   ÚmethodÚurlr2   ÚkwargsÚmatchr   r   r   rM   Ð   s    
zHTTPConnection.putrequestc             G   s\   t dd„ |D ƒƒs&tj| |f|žŽ  n2t | ¡ ¡tkrXtdd t	t
jttƒƒ¡f ƒ‚dS )rH   c             s   s    | ]}t |tƒo|tkV  qd S )N)Ú
isinstanceÚstrr   )Ú.0Úvr   r   r   ú	<genexpr>ß   s    z+HTTPConnection.putheader.<locals>.<genexpr>z+urllib3.util.SKIP_HEADER only supports '%s'z', 'N)Úanyr/   Ú	putheaderr   Ú
ensure_strÚlowerr   rK   ÚjoinÚmaprS   ÚtitleÚsorted)r1   ÚheaderÚvaluesr   r   r   rX   Ý   s    zHTTPConnection.putheaderc                sN   |d kri }n|  ¡ }ddd„ |D ƒkr2tƒ |d< tt| ƒj||||d d S )Nz
user-agentc             s   s   | ]}t  | ¡ ¡V  qd S )N)r   rY   rZ   )rT   Úkr   r   r   rV   í   s    z)HTTPConnection.request.<locals>.<genexpr>z
User-Agent)ÚbodyÚheaders)ÚcopyÚ_get_default_user_agentÚsuperr   Úrequest)r1   rN   rO   rb   rc   )Ú	__class__r   r   rg   ç   s    
zHTTPConnection.requestc             C   s.  |pi }t dd„ |D ƒƒ}d|k}d|k}| j||||d d|krR|  dtƒ ¡ x | ¡ D ]\}}	|  ||	¡ q\W d|krˆ|  d	d
¡ |  ¡  |dk	r tjtf }
t	||
ƒr¶|f}xh|D ]`}|sÆq¼t	|tƒsÚ| 
d¡}tt|ƒƒdd… }t| 
¡ ƒ}|d7 }||7 }|d7 }|  |¡ q¼W |  d¡ dS )zƒ
        Alternative to the common request method, which sends the
        body with chunked encoding and not as one block
        c             S   s   g | ]}t  | ¡ ¡‘qS r   )r   rY   rZ   )rT   ra   r   r   r   ú
<listcomp>÷   s    z2HTTPConnection.request_chunked.<locals>.<listcomp>zaccept-encodingr7   )Úskip_accept_encodingÚ	skip_hostz
user-agentz
User-Agentztransfer-encodingzTransfer-EncodingÚchunkedNÚutf8é   s   
s   0

)ÚsetrM   rX   re   ÚitemsÚ
endheadersr   Ústring_typesÚbytesrR   ÚencodeÚhexÚlenÚ	bytearrayÚsend)r1   rN   rO   rb   rc   Zheader_keysrj   rk   r_   r8   Zstringish_typesÚchunkZlen_strZto_sendr   r   r   Úrequest_chunkedñ   s:    




zHTTPConnection.request_chunked)NN)NN)r   r   r   Ú__doc__Úport_by_schemeÚdefault_portÚsocketÚIPPROTO_TCPÚTCP_NODELAYr.   Úis_verifiedÚproxy_is_verifiedr0   Úpropertyr7   Úsetterr?   rB   rF   rG   rM   rX   rg   rz   Ú__classcell__r   r   )rh   r   r   L   s    


r   c            	   @   sj   e Zd ZdZed ZdZdZdZdZ	dZ
dZdZdddddejddfdd„Zddd„Zd	d
„ Zdd„ ZdS )ÚHTTPSConnectionz•
    Many of the parameters to this constructor are passed to the underlying SSL
    socket by means of :py:func:`urllib3.util.ssl_wrap_socket`.
    r%   NFc
             K   sD   t j| ||f||dœ|
—Ž || _|| _|| _|| _|	| _d| _d S )N)r&   r   r%   )r   r0   Úkey_fileÚ	cert_fileÚkey_passwordÚssl_contextÚserver_hostnameÚ	_protocol)r1   r7   r:   r‡   rˆ   r‰   r&   r   rŠ   r‹   r3   r   r   r   r0   )  s    zHTTPSConnection.__init__c
       
      C   sv   |dkr$| j dk	r| j j}ntdƒ}|| _|| _|| _|| _|| _|| _|oVt	j
 |¡| _|oht	j
 |¡| _|	| _dS )zX
        This method should only be called once, before the connection is used.
        N)rŠ   Úverify_moder   r‡   rˆ   Ú	cert_reqsr‰   Úassert_hostnamer   ÚosÚpathÚ
expanduserÚca_certsÚca_cert_dirÚca_cert_data)
r1   r‡   rˆ   rŽ   r‰   r“   r   r   r”   r•   r   r   r   Úset_certC  s    

zHTTPSConnection.set_certc       	      C   s  |   ¡  | _}| j}d}|  ¡ rP| jr<|  ||¡ | _}d}|  ¡  d| _| j}|}| j	d k	rd| j	}t
j ¡ tk }|rˆt d t¡t¡ d}| jd kr´d}tt| jƒt| jƒd| _| j}t| jƒ|_| jsî| jsî| jsî|rît|dƒrî| ¡  t|| j| j | j!| j| j| j|||d
| _|rd| jd krdt| jdƒrd| j "¡ d	krdt d
| j| j "¡ f t#¡ | j$r„t$| jj%dd| j$ƒ nd|jt&j'krèt(|ddƒsè| j)dk	rè| j %¡ }| *dd¡sÖt d |¡t+¡ t,|| j)pä|ƒ |jt&j-kpþ| j$d k	| _.d S )NFTr   zWSystem time is way off (before {0}). This will probably lead to SSL verification errors)Ússl_versionrŽ   Úload_default_certs)
rC   ÚkeyfileÚcertfiler‰   r“   r”   r•   r‹   rŠ   Ú
tls_in_tlsÚversion>   ÚTLSv1úTLSv1.1z±Negotiating TLSv1/TLSv1.1 by default is deprecated and will be disabled in urllib3 v2.0.0. Connecting to '%s' with '%s' can be enabled by explicitly opting-in with 'ssl_version')Úbinary_formÚcheck_hostnameÚsubjectAltNamer   zë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/urllib3/urllib3/issues/497 for details.))/r?   rC   r7   rB   Útls_in_tls_requiredÚ_connect_tls_proxyrD   rE   r@   r‹   ÚdatetimeÚdateÚtodayÚRECENT_DATEÚwarningsÚwarnÚformatr   rŠ   r   r   r—   r   rŽ   r   r“   r”   r•   Úhasattrr˜   r    r‡   rˆ   r‰   rœ   ÚDeprecationWarningr   ÚgetpeercertÚsslÚ	CERT_NONErA   r   r-   r   Ú_match_hostnameÚCERT_REQUIREDr   )	r1   r=   Úhostnamer›   r‹   Zis_time_offZdefault_ssl_contextÚcontextÚcertr   r   r   rG   d  s†    




zHTTPSConnection.connectc             C   s¬   | j }|j}|rt|||dS t| j| j| j| j| jƒ}t|| j| j| j||d}|j	t
jkršt|ddƒsš| ¡ }| dd¡st d |¡t¡ t||ƒ |j	t
jk| _|S )zY
        Establish a TLS connection to the proxy using the provided SSL context.
        )rC   r‹   rŠ   )rC   r“   r”   r•   r‹   rŠ   r    Fr¡   r   zë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/urllib3/urllib3/issues/497 for details.))r*   rŠ   r    r	   r—   rŽ   r“   r”   r•   r   r®   r¯   rA   r­   r-   r¨   r©   rª   r   r°   r±   r‚   )r1   r²   r=   r*   rŠ   r~   r´   r   r   r   r£   Ú  s>    

z"HTTPSConnection._connect_tls_proxy)	NNNNNNNNN)r   r   r   r{   r|   r}   rŽ   r“   r”   r•   r—   r   r¢   r~   Ú_GLOBAL_DEFAULT_TIMEOUTr0   r–   rG   r£   r   r   r   r   r†     s8           
vr†   c          
   C   sb   |  d¡}t|ƒr|}yt| |ƒ W n8 tk
r\ } zt d|| ¡ | |_‚ W d d }~X Y nX d S )Nzu[]z@Certificate did not match expected hostname: %s. Certificate: %s)Ústripr   r"   r!   ÚlogÚwarningZ
_peer_cert)r´   Zasserted_hostnameZstripped_hostnamer>   r   r   r   r°     s    
r°   c               C   s   dt  S )Nzpython-urllib3/%s)r   r   r   r   r   re   )  s    re   c               @   s   e Zd ZdZdS )ÚDummyConnectionz-Used to detect a failed ConnectionCls import.N)r   r   r   r{   r   r   r   r   r¹   -  s   r¹   )CÚ
__future__r   r¤   Úloggingr   Úrer~   r¨   r   r<   r   r;   Úpackagesr   Zpackages.six.moves.http_clientr   r/   r   Ú
util.proxyr	   r®   ÚSSLErrorr
   ÚImportErrorÚAttributeErrorÚBaseExceptionr   Ú	NameErrorÚ	Exceptionr   Ú_collectionsr   Ú_versionr   Ú
exceptionsr   r   r   r   Úutilr   r   r   Z	util.ssl_r   r   r   r   r   r    Úutil.ssl_match_hostnamer!   r"   Ú	getLoggerr   r·   r|   r¥   r§   ÚcompilerI   Úobjectr†   r°   re   r¹   ÚVerifiedHTTPSConnectionr   r   r   r   Ú<module>   s\   
 


 N {