
    k"gLO                        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 	 d dlZej*                  Z	 eZ	 eZ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jj                  e6      Z7dddZ8 ejr                  ddd      Z: ejv                  d      Z< G d dee=      Z G d de      Z>d Z?d  Z@ G d! d"e=      ZAeseAZ>e>ZBy# eef$ r dZ G d
 de      ZY w xY w# e$ r  G d de      ZY w xY w# e$ r  G d de      ZY w xY w)#    )absolute_importN)error)timeout   )six)HTTPConnection)HTTPException)create_proxy_ssl_contextc                       e Zd Zy)BaseSSLErrorN__name__
__module____qualname__     W/var/www/html/djangosite/lib/python3.12/site-packages/pip/_vendor/urllib3/connection.pyr   r          r   r   c                       e Zd Zy)ConnectionErrorNr   r   r   r   r   r   !   r   r   r   c                       e Zd Zy)BrokenPipeErrorNr   r   r   r   r   r   *   r   r   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_hostnameP   i  )httphttpsi  z[^-!#$%&'*+.^_`|~0-9a-zA-Z]c                        e Zd ZdZed   Zej                  ej                  dfgZ	dZ
dZd Zed        Zej                  d        Zd	 Zd
 Zd Zd Zd Zd Zd fd	ZddZ x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                 D   t         j                  s|j                  dd        |j                  d      | _        |j                  d| j
                        | _        |j                  dd       | _        |j                  dd       | _        t        j                  | g|i | y )Nstrictsource_addresssocket_optionsproxyproxy_config)r   PY2popgetr1   default_socket_optionsr2   r3   r4   _HTTPConnection__init__)selfargskws      r   r:   zHTTPConnection.__init__s   s    wwFF8T" !ff%56 !ff%5t7R7RS VVGT*
FF>48  333r   c                 8    | j                   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r;   s    r   hostzHTTPConnection.host   s    " ~~$$S))r   c                     || _         y)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)r@   )r;   values     r   rC   zHTTPConnection.host   s     r   c           	         i }| j                   r| j                   |d<   | j                  r| j                  |d<   	 t        j                  | j                  | j
                  f| j                  fi |}|S # t        $ r( t        | d| j                  d| j                  d      t        $ r}t        | d|z        d}~ww xY w)zoEstablish a socket connection and set nodelay settings on it.

        :return: New socket connection.
        r1   r2   zConnection to z timed out. (connect timeout=)z(Failed to establish a new connection: %sN)r1   r2   r"   create_connectionr@   portr   SocketTimeoutr   rC   SocketErrorr   )r;   extra_kwconnes       r   	_new_connzHTTPConnection._new_conn   s    
 )-)<)<H%&)-)<)<H%&	//+T\\=ED    	%99dll,   	$@1D 	s   7A3 38B?+B::B?c                     t        | dd       S )N_tunnel_host)getattrrB   s    r   _is_using_tunnelzHTTPConnection._is_using_tunnel   s    t^T22r   c                 b    || _         | j                         r| j                          d| _        y y )Nr   )sockrS   _tunnel	auto_openr;   rM   s     r   _prepare_connzHTTPConnection._prepare_conn   s*    	  "LLNDN	 #r   c                 F    | j                         }| j                  |       y N)rO   rY   rX   s     r   connectzHTTPConnection.connect   s    ~~4 r   c                     t         j                  |      }|r t        d|d|j                         d      t	        j
                  | ||g|i |S ) z+Method cannot contain non-token characters z (found at least rG   )_CONTAINS_CONTROL_CHAR_REsearch
ValueErrorgroupr9   
putrequest)r;   methodurlr<   kwargsmatchs         r   rc   zHTTPConnection.putrequest   sU     *0085;;=* 
 ))$MdMfMMr   c                 0   t        d |D              st        j                  | |g|  yt        j                  |j                               t        vrCt        ddj                  t        t        j                  t        t                          d      y)r^   c              3   R   K   | ]  }t        |t              xr	 |t        k(   ! y wr[   )
isinstancestrr    ).0vs     r   	<genexpr>z+HTTPConnection.putheader.<locals>.<genexpr>   s$     Kq:a%:!{*::Ks   %'z(urllib3.util.SKIP_HEADER only supports 'z', ''N)anyr9   	putheaderr   
ensure_strlowerr!   ra   joinmaprk   titlesorted)r;   headervaluess      r   rq   zHTTPConnection.putheader   ss    KFKK%%dF<V<^^FLLN+3DD;;s399f5F.GHIL  Er   c                     t        | dd       %| j                  j                  | j                         |i }n|j	                         }dd |D        vrt               |d<   t        t        | #  ||||       y )NrU   
user-agentc              3   b   K   | ]'  }t        j                  |j                                ) y wr[   )r   rr   rs   )rl   ks     r   rn   z)HTTPConnection.request.<locals>.<genexpr>   s     Kaqwwy 9Ks   -/
User-Agent)bodyheaders)	rR   rU   
settimeoutr   copy_get_default_user_agentsuperr   request)r;   rd   re   r   r   	__class__s        r   r   zHTTPConnection.request   st     4&2II  .?G llnGK7KK$;$=GL!nd+FCdG+Tr   c           	         |xs i }t        |D cg c]%  }t        j                  |j                               ' c}      }d|v }d|v }| j	                  ||||       d|vr| j                  dt                      |j                         D ]  \  }	}
| j                  |	|
        d|vr| j                  dd       | j                          |t        j                  t        fz   }t        ||      r|f}|D ]v  }|st        |t              s|j                  d
      }t        t        |            dd	 }t        |j                               }|dz  }||z  }|dz  }| j!                  |       x | j!                  d       y	c c}w )z
        Alternative to the common request method, which sends the
        body with chunked encoding and not as one block
        zaccept-encodingrC   )skip_accept_encoding	skip_hostr{   r~   ztransfer-encodingzTransfer-EncodingchunkedNutf8   s   
s   0

)setr   rr   rs   rc   rq   r   items
endheadersstring_typesbytesrj   encodehexlen	bytearraysend)r;   rd   re   r   r   r}   header_keysr   r   rx   rE   stringish_typeschunklen_strto_sends                  r   request_chunkedzHTTPConnection.request_chunked   s~   
 -RgF3>>!'')4FG0K?k)	C.Bi 	 	
 {*NN<)@)BC$]]_ 	*MFENN65)	*k1NN.	:!..%9O$0w 
#!%/!LL0Ec%j/!"-#GNN$457"5 7"		'"
# 			,? Gs   *F)NN)r   r   r   __doc__port_by_schemedefault_portsocketIPPROTO_TCPTCP_NODELAYr8   is_verifiedproxy_is_verifiedr:   propertyrC   setterrO   rS   rY   r\   rc   rq   r   r   __classcell__)r   s   @r   r   r   L   s    2 "&)L  &1163E3EqIJ K 4" * *$ 
[[ >3!NU% r   r   c                       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Z	 	 	 	 	 	 	 	 	 d	dZd Zd Zy)
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
                     t        j                  | ||f||d|
 || _        || _        || _        || _        |	| _        d| _        y )N)r0   r   r-   )r   r:   key_file	cert_filekey_passwordssl_contextserver_hostname	_protocol)r;   rC   rI   r   r   r   r0   r   r   r   r=   s              r   r:   zHTTPSConnection.__init__.  sR     	dDWWTVW "(&. !r   c
                 f   |.| j                   | j                   j                  }nt        d      }|| _        || _        || _        || _        || _        || _        |xr t        j                  j                  |      | _        |xr t        j                  j                  |      | _        |	| _        y)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)
r;   r   r   r   r   r   r   r#   r   r   s
             r   set_certzHTTPSConnection.set_certH  s    " + ,,88	-d3	 ""(."4 ARWW%7%7%A&J277+=+=k+J(r   c                    | j                         x| _        }| j                  }d}| j                         rJ| j                  r| j                  ||      x| _        }d}| j                          d| _        | j                  }|}| j                  | j                  }t        j                  j                         t        k  }|r-t        j                  dj!                  t              t"               d}| j$                  :d}t'        t)        | j*                        t-        | j.                              | _        | j$                  }t-        | j.                        |_        | j2                  s6| j4                  s*| j6                  s|rt9        |d      r|j;                          t=        || j>                  | j@                  | jB                  | j2                  | j4                  | j6                  |||
      | _        |r| j*                  ut9        | j                  d      r_| j                  jE                         d	v rCt        j                  d
| j                  d| j                  jE                         dtF               | jH                  r1tI        | j                  jK                  d      | jH                         n|j0                  tL        jN                  k7  rtQ        |dd      s}| jR                  duro| j                  jK                         }|jU                  dd      s)t        j                  dj!                  |      tV               tY        || jR                  xs |       |j0                  tL        jZ                  k(  xs | jH                  d u| _.        y )NFTr   zWSystem time is way off (before {0}). This will probably lead to SSL verification errors)ssl_versionr   load_default_certs)
rU   keyfilecertfiler   r   r   r   r   r   
tls_in_tlsversion>   TLSv1.1TLSv1zjNegotiating TLSv1/TLSv1.1 by default is deprecated and will be disabled in urllib3 v2.0.0. Connecting to 'z' with 'z;' can be enabled by explicitly opting-in with 'ssl_version')binary_formcheck_hostnamesubjectAltNamer   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.))/rO   rU   rC   rS   tls_in_tls_required_connect_tls_proxyrV   rW   rQ   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_NONErR   r   r7   r   _match_hostnameCERT_REQUIREDr   )	r;   rM   hostnamer   r   is_time_offdefault_ssl_contextcontextcerts	            r   r\   zHTTPSConnection.connecti  s   >>++	D99
  "''#'#:#:8T#JJ	D!
 LLNDN ((H"+"22Omm))+k9MM6&%! $#"&5/0@0@A+DNN; D
 ""/?
 $$%%#!56&&(#MM^^**]]((**+!
	"    (		9-		!!#';;MM )-		4993D3D3FH # ""		%%$%79P9P 3==0G%5u=$$E1
 99((*D88,b1( )/x(8) D$"6"6"I/J 3#4#44 3&&d2 	r   c                 ~   | j                   }|j                  }|rt        |||      S t        | j                  | j
                  | j                  | j                  | j                        }t        || j                  | j                  | j                  ||      }|j                  t        j                  k7  ret        |dd      sX |j                         }|j                  dd      s)t        j                   dj#                  |      t$               t'        ||       |j                  t        j(                  k(  | _        |S )zY
        Establish a TLS connection to the proxy using the provided SSL context.
        )rU   r   r   )rU   r   r   r   r   r   r   Fr   r   r   )r4   r   r(   r
   r   r   r   r   r   r   r   r   rR   r   r7   r   r   r   r   r   r   r   )r;   r   rM   r4   r   r   r   s          r   r   z"HTTPSConnection._connect_tls_proxy  s&    ((".. # ('  /NNMM
 !]]((**$#
 ""cmm3G)5=
 &6%%'D88,b1( )/x(8) D(+!,!8!8C<M<M!Mr   )	NNNNNNNNN)r   r   r   r   r   r   r   r   r   r   r   r#   r   r   _GLOBAL_DEFAULT_TIMEOUTr:   r   r\   r   r   r   r   r   r     s    
 "'*LIHKLK
 ..!8 )Bt
l6r   r   c                     |j                  d      }t        |      r|}	 t        | |       y # t        $ r$}t        j                  d||        | |_         d }~ww xY w)Nzu[]z@Certificate did not match expected hostname: %s. Certificate: %s)stripr%   r*   r)   logwarning
_peer_cert)r   asserted_hostnamestripped_hostnamerN   s       r   r   r     se     *//6%&-t./ 	N	
 	s   - 	AAAc                      dt         z  S )Nzpython-urllib3/%sr   r   r   r   r   r   .  s    ,,r   c                       e Zd ZdZy)DummyConnectionz-Used to detect a failed ConnectionCls import.N)r   r   r   r   r   r   r   r   r   2  s    7r   r   )C
__future__r   r   loggingr   rer   r   r   rK   r   rJ   packagesr   packages.six.moves.http_clientr   r9   r	   
util.proxyr
   r   SSLErrorr   ImportErrorAttributeErrorBaseExceptionr   	NameError	Exceptionr   _collectionsr   _versionr   
exceptionsr   r   r   r   utilr    r!   r"   	util.ssl_r#   r$   r%   r&   r'   r(   util.ssl_match_hostnamer)   r*   	getLoggerr   r   r   r   r   compiler_   objectr   r   r   r   VerifiedHTTPSConnectionr   r   r   <module>r      sg   &   	 	   ' +  M 9 0<<L%O%O ) !  = <  Fg!s+ hmmD!Q'&BJJ'EF O _f O dwn wt,-	f 	 %O * O 	^$ 
C}   )   ) s6   D  D D0  DDD-,D-0EE