????
Your IP : 18.191.70.86
o
�?Og���@sPdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Zddlm
Z
gd�ZdZdZdZdZd Zd
Ze��ejj�dd�ejj��D�Zd
ZdZe�d�jZe�d�j Z!e�d�Z"e�d�Z#hd�Z$d?dd�Z%Gdd�dej&j'�Z(dd�Z)e(fdd�Z*Gdd�dej+�Z,Gdd �d �Z-zddl.Z.Wn e/y�YnwGd!d"�d"e-�Z0e�1d"�Gd#d$�d$e2�Z3Gd%d&�d&e3�Z4Gd'd(�d(e3�Z5Gd)d*�d*e3�Z6Gd+d,�d,e3�Z7Gd-d.�d.e3�Z8Gd/d0�d0e3�Z9Gd1d2�d2e3�Z:Gd3d4�d4e:�Z;Gd5d6�d6e:�Z<Gd7d8�d8e:�Z=Gd9d:�d:e3�Z>Gd;d<�d<e3�Z?Gd=d>�d>e@e>�ZAe3ZBdS)@a�
HTTP/1.1 client library
<intro stuff goes here>
<other stuff, too>
HTTPConnection goes through a number of "states", which define when a client
may legally make another request or fetch the response for a particular
request. This diagram details these state transitions:
(null)
|
| HTTPConnection()
v
Idle
|
| putrequest()
v
Request-started
|
| ( putheader() )* endheaders()
v
Request-sent
|\_____________________________
| | getresponse() raises
| response = getresponse() | ConnectionError
v v
Unread-response Idle
[Response-headers-read]
|\____________________
| |
| response.read() | putrequest()
v v
Idle Req-started-unread-response
______/|
/ |
response.read() | | ( putheader() )* endheaders()
v v
Request-started Req-sent-unread-response
|
| response.read()
v
Request-sent
This diagram presents the following rules:
-- a second request may not be started until {response-headers-read}
-- a response [object] cannot be retrieved until {request-sent}
-- there is no differentiation between an unread response body and a
partially read response body
Note: this enforcement is applied by the HTTPConnection class. The
HTTPResponse class does not enforce this state machine, which
implies sophisticated clients may accelerate the request/response
pipeline. Caution should be taken, though: accelerating the states
beyond the above pattern may imply knowledge of the server's
connection-close behavior for certain requests. For example, it
is impossible to tell whether the server will close the connection
UNTIL the response headers have been read; this means that further
requests cannot be placed into the pipeline until it is known that
the server will NOT be closing the connection.
Logical State __state __response
------------- ------- ----------
Idle _CS_IDLE None
Request-started _CS_REQ_STARTED None
Request-sent _CS_REQ_SENT None
Unread-response _CS_IDLE <response_class>
Req-started-unread-response _CS_REQ_STARTED <response_class>
Req-sent-unread-response _CS_REQ_SENT <response_class>
�N)�urlsplit)�HTTPResponse�HTTPConnection�
HTTPException�NotConnected�UnknownProtocol�UnknownTransferEncoding�UnimplementedFileMode�IncompleteRead�
InvalidURL�ImproperConnectionState�CannotSendRequest�CannotSendHeader�ResponseNotReady�
BadStatusLine�LineTooLong�RemoteDisconnected�error� responses�Pi�ZUNKNOWNZIdlezRequest-startedzRequest-sentcCsi|]}||j�qS�)�phrase)�.0�vrr�2/opt/alt/python310/lib64/python3.10/http/client.py�
<dictcomp>lsri�ds[^:\s][^:\r\n]*s\n(?![ \t])|\r(?![ \t\n])z[- ]z[-]>ZPATCHZPUTZPOST�datac
CsZz|�d�WSty,}zt|j|j|j|jd|��||j|j�|f�d�d}~ww)z<Call data.encode("latin-1") but show a better error message.�latin-1z`%s (%.20r) is not valid Latin-1. Use %s.encode('utf-8') if you want to send it encoded in UTF-8.N)�encode�UnicodeEncodeError�encoding�object�start�end�title)r�name�errrrr�_encode�s �����r(c@�eZdZdd�ZdS)�HTTPMessagecCsj|��d}t|�}g}d}|��D] }|d|���|kr!d}n
|dd���s+d}|r2|�|�q|S)a�Find all header lines matching a given header name.
Look through the list of headers and find all lines matching a given
header name (and their continuation lines). A list of the lines is
returned, without interpretation. If the header does not occur, an
empty list is returned. If the header occurs multiple times, all
occurrences are returned. Case is not important in the header name.
�:rN�)�lower�len�keys�isspace�append)�selfr&�nZlstZhit�linerrr�getallmatchingheaders�s
�z!HTTPMessage.getallmatchingheadersN)�__name__�
__module__�__qualname__r5rrrrr*�sr*cCsZg} |�td�}t|�tkrtd��|�|�t|�tkr%tdt��|dvr, |Sq)z�Reads potential header lines into a list from a file pointer.
Length of line is limited by _MAXLINE, and number of
headers is limited by _MAXHEADERS.
Tr,�header linezgot more than %d headers��
�
�)�readline�_MAXLINEr.rr1�_MAXHEADERSr)�fp�headersr4rrr�
_read_headers�s
�rCcCs,t|�}d�|��d�}tjj|d��|�S)aGParses only RFC2822 headers from a file pointer.
email Parser wants to see strings rather than bytes.
But a TextIOWrapper around self.rfile would buffer too many bytes
from the stream, bytes which we later need to read as bytes.
So we read the correct bytes here, as bytes, for email Parser
to parse.
r=�
iso-8859-1)�_class)rC�join�decode�email�parserZParserZparsestr)rArErBZhstringrrr�
parse_headers�s
rJcseZdZd@dd�Zdd�Zdd�Zd d
�Zdd�Z�fd
d�Z�fdd�Z dd�Z
dd�ZdAdd�Zdd�Z
dd�Zdd�Zdd�ZdAdd �Zd!d"�Zd#d$�Zd%d&�ZdBd(d)�ZdBd*d+�ZdB�fd,d-� Zd.d/�Zd0d1�Zd2d3�ZdAd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Z �Z!S)CrrNcCsR|�d�|_||_||_d|_|_t|_t|_t|_ t|_
t|_t|_t|_
dS)N�rb)ZmakefilerA�
debuglevel�_methodrB�msg�_UNKNOWN�version�status�reason�chunked�
chunk_left�length�
will_close)r2�sockrL�method�urlrrr�__init__�s
zHTTPResponse.__init__cCst|j�td�d�}t|�tkrtd��|jdkr!tdt|��|s't d��z|�
dd�\}}}Wn!tySz|�
dd�\}}d}WntyPd}YnwYnw|�d �sa|�
�t|��zt|�}|d
ksn|dkrrt|��Wnty~t|��w|||fS)Nr,rDzstatus linerzreply:z-Remote end closed connection without response��zHTTP/ri�)�strrAr>r?r.rrL�print�reprr�split�
ValueError�
startswith�_close_connr�int)r2r4rPrQrRrrr�_read_statuss<
���
��
zHTTPResponse._read_statusc Cs�|jdurdS |��\}}}|tkrnt|j�}|jdkr#td|�~q||_|_|� �|_
|dvr8d|_n
|�d�rAd|_nt
|��t|j�|_|_|jdkre|j��D]\}}td|d |�qX|j�d
�}|rz|��dkrzd|_d|_nd|_|��|_d|_|j�d
�}|r�|js�zt|�|_Wnty�d|_Yn
w|jdkr�d|_nd|_|tks�|tks�d|kr�dks�n|jdkr�d|_|js�|js�|jdur�d|_dSdSdSdS)NTrzheaders:)zHTTP/1.0zHTTP/0.9�
zHTTP/1.��header:r+�transfer-encodingrSF�content-lengthr���HEAD)rBreZCONTINUErCrArLr^�coderQ�striprRrPrbrrJrN�items�getr-rSrT�_check_closerVrUrdraZ
NO_CONTENTZNOT_MODIFIEDrM) r2rPrQrRZskipped_headers�hdr�valZtr_encrUrrr�begin7sf
�
�
�
�
�zHTTPResponse.begincCsv|j�d�}|jdkr|rd|��vrdSdS|j�d�rdS|r)d|��vr)dS|j�d�}|r9d|��vr9dSdS)NZ
connectionrg�closeTFz
keep-alivezproxy-connection)rBrprPr-)r2ZconnZpconnrrrrqs
zHTTPResponse._check_closecCs|j}d|_|��dS�N)rAru)r2rArrrrc�szHTTPResponse._close_conncs6zt���W|jr|��dSdS|jr|��wwrv)�superrurArc�r2�� __class__rrru�s
�
�zHTTPResponse.closecs"t���|jr|j��dSdSrv)rw�flushrArxryrrr{�s
�zHTTPResponse.flushcCsdS)zAlways returns TrueTrrxrrr�readable�szHTTPResponse.readablecCs
|jduS)z!True if the connection is closed.N)rArxrrr�isclosed�s
zHTTPResponse.isclosedcCs�|jdurdS|jdkr|��dS|jr|�|�S|durR|jdur+||jkr+|j}|j�|�}|s;|r;|��|S|jdurP|jt|�8_|jsP|��|S|jdur]|j��}nz|�|j�}Wnt yq|���wd|_|��|S)z?Read and return the response body, or up to the next amt bytes.Nr=rlr)
rArMrcrS�
_read_chunkedrU�readr.�
_safe_readr
)r2�amt�srrrr�s<
�
�zHTTPResponse.readcCs�|jdurdS|jdkr|��dS|jr|�|�S|jdur/t|�|jkr/t|�d|j�}|j�|�}|s?|r?|��|S|jdurR|j|8_|jsR|��|S)z^Read up to len(b) bytes into bytearray b and return the number
of bytes read.
Nrrl) rArMrcrS�_readinto_chunkedrUr.�
memoryview�readinto)r2�br3rrrr��s&
�zHTTPResponse.readintocCsh|j�td�}t|�tkrtd��|�d�}|dkr!|d|�}zt|d�WSty3|���w)Nr,z
chunk size�;r�) rAr>r?r.r�findrdrarc)r2r4�irrr�_read_next_chunk_sizes
�z"HTTPResponse._read_next_chunk_sizecCs< |j�td�}t|�tkrtd��|sdS|dvrdSq)NTr,ztrailer liner:)rAr>r?r.r�r2r4rrr�_read_and_discard_trailers�z&HTTPResponse._read_and_discard_trailercCsf|j}|s1|dur|�d�z|��}Wntytd��w|dkr.|��|��d}||_|S)Nr[r=r)rTr�r�rar
r�rc)r2rTrrr�_get_chunk_left*s
�zHTTPResponse._get_chunk_leftcCs�g}z: |��}|dur
n*|dur#||kr#|�|�|��|||_n|�|�|��|dur3||8}d|_qd�|�WStyJtd�|���w)NTrr=)r�r1r�rTrFr
)r2r��valuerTrrrr~Bs&
��zHTTPResponse._read_chunkedcCs�d}t|�}z: |��}|dur|WSt|�|kr(|�|�}|||_||WS|d|�}|�|�}||d�}||7}d|_qtyQtt|d|����w)Nr)r�r�r.�_safe_readintorTr
�bytes)r2r�Ztotal_bytesZmvbrTr3Ztemp_mvbrrrr�Xs(
��zHTTPResponse._readinto_chunkedcCs.|j�|�}t|�|krt||t|���|S)aRead the number of bytes requested.
This function should be used when <amt> bytes "should" be present for
reading. If the bytes are truly not available (due to EOF), then the
IncompleteRead exception can be used to detect the problem.
)rArr.r
)r2r�rrrrr�pszHTTPResponse._safe_readcCs:t|�}|j�|�}||krtt|d|��||��|S)z2Same as _safe_read, but for reading into a buffer.N)r.rAr�r
r�)r2r�r�r3rrrr�|s
zHTTPResponse._safe_readinto���cCs�|jdus
|jdkrdS|jr|�|�S|jdur%|dks"||jkr%|j}|j�|�}|s5|r5|��|S|jdurC|jt|�8_|S)zvRead with at most one underlying system call. If at least one
byte is buffered, return that instead.
Nrlr=r)rArMrS�_read1_chunkedrU�read1rcr.)r2r3�resultrrrr��s
�zHTTPResponse.read1cCs4|jdus
|jdkrdS|jr|�|�S|j�|�S)Nrlr=)rArMrS�
_peek_chunked�peek)r2r3rrrr��s
zHTTPResponse.peekcs�|jdus
|jdkrdS|jrt��|�S|jdur&|dks#||jkr&|j}|j�|�}|s6|r6|��|S|jdurD|jt|�8_|S)Nrlr=r)rArMrSrwr>rUrcr.)r2�limitr�ryrrr>�s
�zHTTPResponse.readlinecCsd|��}|dus|dkrdSd|kr|ksn|}|j�|�}|jt|�8_|s0td��|S)Nrr=)r�rAr�rTr.r
)r2r3rTrrrrr��szHTTPResponse._read1_chunkedcCsBz|��}Wn
tyYdSw|durdS|j�|�d|�S)Nr=)r�r
rAr�)r2r3rTrrrr��s�zHTTPResponse._peek_chunkedcCs
|j��Srv)rA�filenorxrrrr���
zHTTPResponse.filenocCsB|jdurt��|j�|�p|}t|t�st|d�s|Sd�|�S)axReturns the value of the header matching *name*.
If there are multiple matching headers, the values are
combined into a single string separated by commas and spaces.
If no matching header is found, returns *default* or None if
the *default* is not specified.
If the headers are unknown, raises http.client.ResponseNotReady.
N�__iter__z, )rBrZget_all�
isinstancer]�hasattrrF)r2r&�defaultrBrrr� getheader�s
zHTTPResponse.getheadercCs|jdurt��t|j���S)z&Return list of (header, value) tuples.N)rBr�listrorxrrr�
getheaders�s
zHTTPResponse.getheaderscCs|Srvrrxrrrr��szHTTPResponse.__iter__cC�|jS)ajReturns an instance of the class mimetools.Message containing
meta-information associated with the URL.
When the method is HTTP, these headers are those returned by
the server at the head of the retrieved HTML page (including
Content-Length and Content-Type).
When the method is FTP, a Content-Length header will be
present if (as is now usual) the server passed back a file
length in response to the FTP retrieval request. A
Content-Type header will be present if the MIME type can be
guessed.
When the method is local-file, returned headers will include
a Date representing the file's last-modified time, a
Content-Length giving file size, and a Content-Type
containing a guess at the file's type. See also the
description of the mimetools module.
)rBrxrrr�info�szHTTPResponse.infocCr�)aZReturn the real URL of the page.
In some cases, the HTTP server redirects a client to another
URL. The urlopen() function handles this transparently, but in
some cases the caller needs to know which URL the client was
redirected to. The geturl() method can be used to get at this
redirected URL.
)rYrxrrr�geturls
zHTTPResponse.geturlcCr�)zuReturn the HTTP status code that was sent with the response,
or None if the URL is not an HTTP URL.
)rQrxrrr�getcodeszHTTPResponse.getcode)rNNrv)r�)"r6r7r8rZrertrqrcrur{r|r}rr�r�r�r�r~r�r�r�r�r�r>r�r�r�r�r�r�r�r�r��
__classcell__rrryrr�s>
!H
("
rc@seZdZdZdZeZeZdZ dZ
edd��Zedd��Z
d ejd d
fdd�Zd7d
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd8d d!�Z d9d"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Z d:dd.�d/d0�Z!d ifdd.�d1d2�Z"d3d4�Z#d5d6�Z$d S);rrgzHTTP/1.1r,rcCst|tj�S)zFTest whether a file-like object is a text or a binary stream.
)r��io�
TextIOBase)�streamrrr�
_is_textIO szHTTPConnection._is_textIOcCsd|dur|��tvrdSdSt|d�rdSzt|�}|jWSty&Ynwt|t�r0t|�SdS)aGet the content-length based on the body.
If the body is None, we set Content-Length: 0 for methods that expect
a body (RFC 7230, Section 3.3.2). We also set the Content-Length for
any method if the body is a str or bytes-like object and not a file.
Nrr) �upper�_METHODS_EXPECTING_BODYr�r��nbytes� TypeErrorr�r]r.)�bodyrXZmvrrr�_get_content_length&s
�
z"HTTPConnection._get_content_lengthN� cCsn||_||_||_d|_g|_d|_t|_d|_d|_ d|_
i|_|�||�\|_
|_|�|j
�tj|_dSrv)�timeout�source_address� blocksizerW�_buffer�_HTTPConnection__response�_CS_IDLE�_HTTPConnection__staterM�_tunnel_host�_tunnel_port�_tunnel_headers�
_get_hostport�host�port�_validate_host�socketZcreate_connection�_create_connection)r2r�r�r�r�r�rrrrZFszHTTPConnection.__init__cCs>|jrtd��|�||�\|_|_|r||_dS|j��dS)aDSet up host and port for HTTP CONNECT tunnelling.
In a connection that uses HTTP CONNECT tunneling, the host passed to the
constructor is used as a proxy server that relays all communication to
the endpoint passed to `set_tunnel`. This done by sending an HTTP
CONNECT request to the proxy server when the connection is established.
This method must be called before the HTTP connection has been
established.
The headers argument should be a mapping of extra HTTP headers to send
with the CONNECT request.
z.Can't set up tunnel for established connectionN)rW�RuntimeErrorr�r�r�r��clear)r2r�r�rBrrr�
set_tunnel\s
zHTTPConnection.set_tunnelcCs�|dur`|�d�}|�d�}||krIzt||dd��}Wn#tyA||dd�dkr3|j}ntd||dd���Ynw|d|�}n|j}|r`|ddkr`|ddkr`|dd�}||fS) Nr+�]r,r\znonnumeric port: '%s'r�[r�)�rfindrdra�default_portr)r2r�r�r��jrrrr�ts"
��zHTTPConnection._get_hostportcCs
||_dSrv)rL)r2�levelrrr�set_debuglevel�r�zHTTPConnection.set_debuglevelc
Csd|j�d�|jf}|g}|j��D]\}}|�|�d|�d��d��q|�d�|�d�|��~|j|j |j
d�}|��\}}}|tj
jkrZ|��td |�d
|������ |j�td�} t| �tkrmtd
��| sqdS| dvrwdS|jdkr�td| ���q[)NsCONNECT %s:%d HTTP/1.0
�asciiz: �
rr;r=�rXzTunnel connection failed: � Tr,r9r:rrh)r�rr�r�ror1�sendrF�response_classrWrMre�http�
HTTPStatusZOKru�OSErrorrnrAr>r?r.rrLr^rG)
r2�connectrB�headerr��responserPrm�messager4rrr�_tunnel�s2�
�zHTTPConnection._tunnelc
Cs�t�d||j|j�|�|j|jf|j|j�|_z|j�t j
t jd�Wnty=}z
|j
t
jkr3�WYd}~nd}~ww|jrG|��dSdS)z3Connect to the host and port specified in __init__.zhttp.client.connectr,N)�sys�auditr�r�r�r�r�rWZ
setsockoptr�ZIPPROTO_TCPZTCP_NODELAYr��errnoZENOPROTOOPTr�r��r2�errrr��s�����zHTTPConnection.connectcCs^t|_z|j}|rd|_|��W|j}|rd|_|��dSdS|j}|r.d|_|��ww)z(Close the connection to the HTTP server.N)r�r�rWrur�)r2rWr�rrrru�s"���
�zHTTPConnection.closecCs |jdur|jr
|��nt��|jdkrtdt|��t|d�r[|jdkr*td�|�|�}|r:|jdkr:td� |� |j
�}|sF dS|rM|�d�}t�
d ||�|j�|�q;t�
d ||�z |j�|�WdSty�t|tjj�r�|D]}|j�|�q{YdStd
t|���w)z�Send `data' to the server.
``data`` can be a string object, a bytes object, an array object, a
file-like object that supports a .read() method, or an iterable object.
Nrzsend:r�sendIng a read()able�encoding file using iso-8859-1r,rDzhttp.client.sendz9data should be a bytes-like object or an iterable, got %r)rW� auto_openr�rrLr^r_r�r�rr�rr�r�Zsendallr�r��collections�abc�Iterable�type)r2rr� datablock�drrrr��sD
�
� ���zHTTPConnection.sendcCs|j�|�dS)zuAdd a line of output to the current request buffer.
Assumes that the line does *not* end with \r\n.
N)r�r1)r2r�rrr�_output�szHTTPConnection._outputccs`�|jdkr
td�|�|�}|r|jdkrtd� |�|j�}|s%dS|r,|�d�}|Vq)Nrr�r�TrD)rLr^r�rr�r)r2r|rr�rrr�_read_readable�s�
�zHTTPConnection._read_readableFcCs|j�d�d�|j�}|jdd�=|�|�|dur�t|d�r&|�|�}n)zt|�WntyKzt|�}WntyHtdt |���wYnw|f}|D])}|s_|j
dkr^td�qQ|ru|jdkrut
|�d �d
��d�|d}|�|�qQ|r�|jdkr�|�d�dSdSdSdS)
z�Send the currently buffered request and clear the buffer.
Appends an extra \r\n to the buffer.
A message_body may be specified, to be appended to the request.
)r=r=r;NrzAmessage_body should be a bytes-like object or an iterable, got %rrzZero length chunk ignoredrg�Xr�r�s0
)r��extendrFr�r�r�r�r��iterr�rLr^� _http_vsnr.r)r2�message_body�encode_chunkedrNZchunks�chunkrrr�_send_outputsD
����
��'zHTTPConnection._send_outputcCs�|jr|j��rd|_|jtkrt|_nt|j��|�|�||_|p$d}|�|�d|||j f}|�
|�|��|jdkr�|s�d}|�
d�rQt|�\}}}}}|rpz|�d�}Wntyh|�d�}Ynw|�d |�nN|jrz|j} |j}
n|j} |j}
z| �d�}Wnty�| �d�}Ynw| �d
�dkr�d|d
}|
|jkr�|�d |�n|�d�}|�d d||
f�|s�|�dd�dSdS dS)a`Send a request to the server.
`method' specifies an HTTP request method, e.g. 'GET'.
`url' specifies the object being requested, e.g. '/index.html'.
`skip_host' if True does not add automatically a 'Host:' header
`skip_accept_encoding' if True does not add automatically an
'Accept-Encoding:' header
N�/z%s %s %srgr\r�r�ZidnaZHostr+r�[�]z%s:%szAccept-EncodingZidentity)r�r}r�r��_CS_REQ_STARTEDr
�_validate_methodrM�_validate_path�
_http_vsn_strr��_encode_requestr�rbrrr � putheaderr�r�r�r�r�r�rG)r2rXrY� skip_host�skip_accept_encoding�requestZnetlocZnilZ
netloc_encr�r�Zhost_encrrr�
putrequest;sV
��
�
zHTTPConnection.putrequestcCs
|�d�S)Nr�)r)r2r�rrrr��s
zHTTPConnection._encode_requestcC�,t�|�}|rtd|�d|���d���dS)z&Validate a method name for putrequest.z)method can't contain control characters. � (found at least �)N)�$_contains_disallowed_method_pchar_re�searchra�group)r2rX�matchrrrr��s
���zHTTPConnection._validate_methodcCr�)zValidate a url for putrequest.�&URL can't contain control characters. rrN��!_contains_disallowed_url_pchar_rerrr)r2rYrrrrr���
��zHTTPConnection._validate_pathcCr�)z9Validate a host so it doesn't contain control characters.rrrNr)r2r�rrrrr��r zHTTPConnection._validate_hostcGs�|jtkrt��t|d�r|�d�}t|�std|f��t|�}t|�D].\}}t|d�r6|�d�||<nt |t
�rDt|��d�||<t||�rStd||f��q%d�
|�}|d|}|�|�dS) zkSend a request header line to the server.
For example: h.putheader('Accept', 'text/html')
rr�zInvalid header name %rrzInvalid header value %rs
s: N)r�r�rr�r�_is_legal_header_namerar�� enumerater�rdr]�_is_illegal_header_valuerFr�)r2r��valuesr�Z one_valuer�rrrr��s$
�
zHTTPConnection.putheader�r�cCs*|jtkr t|_nt��|j||d�dS)z�Indicate that the last header line has been sent to the server.
This method sends the request to the server. The optional message_body
argument can be used to pass a message body associated with the
request.
rN)r�r��_CS_REQ_SENTrr�)r2r�r�rrr�
endheaders�s
zHTTPConnection.endheaderscCs|�|||||�dS)z&Send a complete request to the server.N)�
_send_request)r2rXrYr�rBr�rrrr�szHTTPConnection.requestcCs�tdd�|D��}i}d|vrd|d<d|vrd|d<|j||fi|��d|vrZd |vrYd
}|�||�}|durQ|durP|jdkrHtd|�d
}|�dd�n|�dt|��nd
}|��D]
\} }
|�| |
�q`t|t�rut |d�}|j
||d�dS)Ncss�|]}|��VqdSrv)r-)r�krrr� <genexpr>s�z/HTTPConnection._send_request.<locals>.<genexpr>r�r,r�zaccept-encodingr�rjriFrzUnable to determine size of %rTzTransfer-EncodingrSzContent-Lengthr�r)� frozensetr�r�rLr^r�r]ror�r(r)r2rXrYr�rBr�Zheader_namesZskipsZcontent_lengthrrr�rrrrs4
��
zHTTPConnection._send_requestcCs�|jr|j��rd|_|jtks|jrt|j��|jdkr)|j|j|j|jd�}n |j|j|jd�}z&z|� �Wnt
yE|���wt|_|j
rS|��|WS||_|WS|���)a)Get the response from the server.
If the HTTPConnection is in the correct state, returns an
instance of HTTPResponse or of whatever object is returned by
the response_class variable.
If a request has not been sent or if a previous response has
not be handled, ResponseNotReady is raised. If the HTTP
response indicates that the connection should be closed, then
it will be closed before the response is returned. When the
connection is closed, the underlying socket is closed.
Nrr�)r�r}r�rrrLr�rWrMrt�ConnectionErrorrur�rV)r2r�rrr�getresponse3s2
���zHTTPConnection.getresponse)NN)NF)FFrv)%r6r7r8r�r�rr�� HTTP_PORTr�r�rL�staticmethodr�r�r��_GLOBAL_DEFAULT_TIMEOUTrZr�r�r�r�r�rur�r�r�r�r�r�r�r�r�r�rr�rrrrrrrsL
�
(
6
�
�.rcsHeZdZdZeZdddejdfdddd��fdd�Z�fdd�Z �Z
S) �HTTPSConnectionz(This class allows communication via SSL.Nr�)�context�check_hostnamer�cs�tt|�j||||| d�|dus|dus|dur$ddl}
|
�dtd�||_||_|durEt� �}|j
dkr=|�dg�|jdurEd|_|j
tjk}|durR|j}|rZ|sZtd��|s^|rl|�||�|jdurld|_||_|dury||j_dSdS) N)r�rzTkey_file, cert_file and check_hostname are deprecated, use a custom context instead.r[rgzhttp/1.1TzMcheck_hostname needs a SSL context with either CERT_OPTIONAL or CERT_REQUIRED)rwrrZ�warnings�warn�DeprecationWarning�key_file� cert_file�sslZ_create_default_https_contextr�Zset_alpn_protocolsZpost_handshake_authZverify_modeZ CERT_NONErraZload_cert_chain�_context)r2r�r�r r!r�r�rrr�rZwill_verifyryrrrZ~s>��
�zHTTPSConnection.__init__cs6t���|jr|j}n|j}|jj|j|d�|_dS)z(Connect to a host on a given (SSL) port.)�server_hostnameN)rwr�r�r�r#Zwrap_socketrW)r2r$ryrrr��s
�zHTTPSConnection.connect)r6r7r8�__doc__�
HTTPS_PORTr�r�rrZr�r�rrryrrws��'rc@�eZdZdS)rN�r6r7r8rrrrr�src@r')rNr(rrrrr��rc@r')rNr(rrrrr�r)rc@r))rcCs|f|_||_dSrv)�argsrP)r2rPrrrrZ�s
zUnknownProtocol.__init__N�r6r7r8rZrrrrr��rc@r')rNr(rrrrr�r)rc@r')r Nr(rrrrr �r)r c@s$eZdZddd�Zdd�ZejZdS)r
NcCs|f|_||_||_dSrv)r*�partial�expected)r2r-r.rrrrZ�s
zIncompleteRead.__init__cCs2|jdurd|j}nd}d|jjt|j�|fS)Nz, %i more expectedr\z%s(%i bytes read%s))r.rzr6r.r-r�rrr�__repr__�s
�zIncompleteRead.__repr__rv)r6r7r8rZr/r"�__str__rrrrr
�s
r
c@r')rNr(rrrrr�r)rc@r')r
Nr(rrrrr
�r)r
c@r')rNr(rrrrr�r)rc@r')rNr(rrrrr�r)rc@r))rcCs|st|�}|f|_||_dSrv)r_r*r4r�rrrrZ�s
zBadStatusLine.__init__Nr+rrrrr�r,rc@r))rcCst�|dt|f�dS)Nz&got more than %d bytes when reading %s)rrZr?)r2Z line_typerrrrZ�s
�zLineTooLong.__init__Nr+rrrrr�r,rc@r))rcOs(t�|d�tj|g|�Ri|��dS)Nr\)rrZ�ConnectionResetError)r2�pos�kwrrrrZ�szRemoteDisconnected.__init__Nr+rrrrr�r,r)r)Cr%Zemail.parserrHZ
email.messager�r�r��rer�r�Zcollections.abcr�Zurllib.parser�__all__rr&rOr�r�r�globals�updater��__members__r
rr?r@�compile� fullmatchr
rrrrr�r(r�ZMessager*rCrJ�BufferedIOBaserrr"�ImportErrorrr1� Exceptionrrrrrr r
rr
rrrrr1rrrrrr�<module>s~F
+`�
;