o ?cPY@s^ddlZddlZddlmZddlZddlmZmZddl m Z m Z ddl Z ddlmZmZmZmZmZmZmZddlmZeeZGdddeZGd d d ZGd d d eeZGd ddeeZGddde ZGddde Z d%ddZ!ddZ"ddZ#GdddZ$GdddZ%GdddZ&Gdd d Z'Gd!d"d"Z(Gd#d$d$eZ)dS)&N)Mapping)HTTPConnectionVerifiedHTTPSConnection)HTTPConnectionPoolHTTPSConnectionPool) HTTPHeaders HTTPResponseMutableMapping urlencodeurlparseurlsplit urlunsplit)UnseekableStreamErrorc@seZdZddZddZdS)AWSHTTPResponsecOs(|d|_tj|g|Ri|dS)N status_tuple)pop _status_tupler__init__selfargskwargsrn/private/var/folders/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/botocore/awsrequest.pyr(s zAWSHTTPResponse.__init__cCs$|jdur |j}d|_|St|SN)rr _read_status)rrrrrr,s  zAWSHTTPResponse._read_statusN)__name__ __module__ __qualname__rrrrrrr%s rcsveZdZdZfddZfddZfddZdd Zdd d Zd dZ ddZ ddZ fddZ ddZ ZS) AWSConnectionaMixin for HTTPConnection that supports Expect 100-continue. This when mixed with a subclass of httplib.HTTPConnection (though technically we subclass from urllib3, which subclasses httplib.HTTPConnection) and we only override this class to support Expect 100-continue, which we need for S3. As far as I can tell, this is general purpose enough to not be specific to S3, but I'm being tentative and keeping it in botocore because I've only tested this against AWS services. cs*tj|i||j|_d|_d|_dSNF)superrresponse_class_original_response_cls_response_received_expect_header_setr __class__rrrBs zAWSConnection.__init__cs"td|_d|_|j|_dSr )r!closer$r%r#r"rr&rrr(Ps  zAWSConnection.closecsVd|_|dddkrd|_nd|_|j|_tj||||g|Ri|}d|_|S)NFZExpects 100-continueT)r$getr%r#r"r! _send_request)rmethodurlbodyheadersrrrvalr&rrr,WszAWSConnection._send_requestcCsBg}|D]}t|tr||dq||qd|}|S)Nutf-8 ) isinstancestrappendencodejoin)rZ mixed_bufferZ bytes_bufferchunkmsgrrr_convert_to_bytesds   zAWSConnection._convert_to_bytesNcOs|jd||j}|jdd=t|tr||7}d}|||jr>tdt j |j dr9| |dStd|durI||dSdS)N)r*r*z"Waiting for 100 Continue response.zCNo response seen from server, continuing to send the response body.)_bufferextendr;r4bytessendr%loggerdebugurllib3util wait_for_readsock_handle_expect_response)r message_bodyrrr:rrr _send_outputqs$        zAWSConnection._send_outputcCs$d}|dkr|}|dksdSdS)Nr3)readline)rfpcurrentrrr_consume_headersszAWSConnection._consume_headerscCs|jdd}zm|}|dd}||r'||td||n@t |dkr`|d drntd|d dt |d |d df}t jt|d }||_d |_W|dSW|dSW|dSW|dS|w) Nrbrz5100 Continue response seen, now sending request body.HTTP/zOReceived a non 100 Continue response from the server, NOT sending request body.asciir<)rT)rFmakefilerJsplit_is_100_continue_statusrMrArB_send_message_bodylen startswithdecodeint functoolspartialrr"r$r()rrHrKmaybe_status_linepartsrr"rrrrGs<           z%AWSConnection._handle_expect_responsecCs|dur ||dSdSr)r@)rrHrrrrVsz AWSConnection._send_message_bodycs |jr tddSt|S)Nz@send() called, but reseponse already received. Not sending data.)r$rArBr!r@)rr5r&rrr@s  zAWSConnection.sendcCs2|dd}t|dko|ddo|ddkS)NrOrPrrQr<s100)rTrWrX)rr]r^rrrrUs    z%AWSConnection._is_100_continue_statusr)rrr__doc__rr(r,r;rIrMrGrVr@rU __classcell__rrr&rr5s   & ,  rc@eZdZdZdS)AWSHTTPConnectionz6An HTTPConnection that supports 100 Continue behavior.Nrrrr_rrrrrbrbc@ra)AWSHTTPSConnectionz7An HTTPSConnection that supports 100 Continue behavior.Nrcrrrrrerdrec@eZdZeZdS)AWSHTTPConnectionPoolN)rrrrb ConnectionClsrrrrrgrdrgc@rf)AWSHTTPSConnectionPoolN)rrrrerhrrrrrirdric Cs|}|dur|d}||d<|d}t||d|}|dr:tjj}||d} d|vr4|d| 7}n|d | 7}||d <||d <|durLi|d <dSdS) a; This method prepares a request dict to be created into an AWSRequestObject. This prepares the request dict by adding the url and the user agent to the request dict. :type request_dict: dict :param request_dict: The request dict (created from the ``serialize`` module). :type user_agent: string :param user_agent: The user agent to use for this request. :type endpoint_url: string :param endpoint_url: The full endpoint url, which contains at least the scheme, the hostname, and optionally any path components. Nr0z User-Agent host_prefixurl_pathZ query_string?z?%sz&%sr.context)r+_urljoinbotocoreutilspercent_encode_sequence) request_dict endpoint_urlrm user_agentrr0rjr.rqZencoded_query_stringrrrprepare_request_dicts"    rvcCs2|}t|d|d|d|dd}|d|_|S)aK This method takes a request dict and creates an AWSRequest object from it. :type request_dict: dict :param request_dict: The request dict (created from the ``prepare_request_dict`` method). :rtype: ``botocore.awsrequest.AWSRequest`` :return: An AWSRequest object based on the request_dict. r-r.r/r0)r-r.datar0rm) AWSRequestrm)rrruZrequest_objectrrrcreate_request_objects   rycCst|}|r |dkr|dsd}n"|d}n|ddr-|dr-|ddd|}n|d|}|d}|dur?||}t|d|||d|df}|S)N/rOr<rrP)r endswithrXr )rsrkrjpnew_pathZ new_netlocZ reconstructedrrrrn4s   rnc@sBeZdZdZddZddZdddZd d Zd d Zd dZ dS)AWSRequestPreparera  This class performs preparation on AWSRequest objects similar to that of the PreparedRequest class does in the requests library. However, the logic has been boiled down to meet the specific use cases in botocore. Of note there are the following differences: This class does not heavily prepare the URL. Requests performed many validations and corrections to ensure the URL is properly formatted. Botocore either performs these validations elsewhere or otherwise consistently provides well formatted URLs. This class does not heavily prepare the body. Body preperation is simple and supports only the cases that we document: bytes and file-like objects to determine the content-length. This will also additionally prepare a body that is a dict to be url encoded params string as some signers rely on this. Finally, this class does not support multipart file uploads. This class does not prepare the method, auth or cookies. cCs<|j}||}||}|||}|j}t|||||Sr)r- _prepare_url _prepare_body_prepare_headers stream_outputAWSPreparedRequest)roriginalr-r.r/r0rrrrpreparees    zAWSRequestPreparer.preparecCsb|j}|jr/t|}|jrdnd}t|jtrt|j}n|j}t|dd}| ||f}|S)N&rlTdoseq) r.paramsr queryr4rlistitemsr r8)rrr.Z url_partsdelimZparams_to_encoderrrrrns  zAWSRequestPreparer._prepare_urlNcCsnt|j}d|vsd|vr|S|jdvr5||}|dur't||d<|St|}td|d|d<|S)NzTransfer-EncodingzContent-Length)GETHEADOPTIONSz Failed to determine length of %schunked) HeadersDictr0rr-_determine_content_lengthr5typerArB)rrZ prepared_bodyr0lengthZ body_typerrrr{s    z#AWSRequestPreparer._prepare_headerscCs8|\}}t|tr|d}t|tr|d}||fSNr2)r4r5r7)ritemkeyvaluerrr_to_utf8s     zAWSRequestPreparer._to_utf8csB|j}|dkr d}t|trfdd|D}t|dd}|S)z"Prepares the given HTTP body data.r*Ncsg|]}|qSr)r).0rr)rr sz4AWSRequestPreparer._prepare_body..Tr)rwr4dictrr )rrr/rrr)rrs  z AWSRequestPreparer._prepare_bodycCs tj|Sr)rorpZdetermine_content_lengthrr/rrrr z,AWSRequestPreparer._determine_content_lengthr) rrrr_rrrrrrrrrrrPs  rc@s@eZdZdZeZ       d ddZddZedd Z dS) rxa Represents the elements of an HTTP request. This class was originally inspired by requests.models.Request, but has been boiled down to meet the specific use cases in botocore. That being said this class (even in requests) is effectively a named-tuple. NFc Cst||_|dur in|}||_||_t|_||_||_||_||_ |dur5| D] \}} | |j|<q+i|_ dSr) _REQUEST_PREPARER_CLS_request_preparerr-r.rr0rwr auth_pathrrrm) rr-r.r0rwrrrrrrrrrs   zAWSRequest.__init__cCs |j|S)z>Constructs a :class:`AWSPreparedRequest `.)rrr)rrrrs zAWSRequest.preparecCs"|j}t|tr|d}|Sr)rr/r4r5r7rrrrr/s   zAWSRequest.body)NNNNNNF) rrrr_rrrrpropertyr/rrrrrxs %rxc@s(eZdZdZddZddZddZdS) raA data class representing a finalized request to be sent over the wire. Requests at this stage should be treated as final, and the properties of the request should not be modified. :ivar method: The HTTP Method :ivar url: The full url :ivar headers: The HTTP headers to send. :ivar body: The HTTP body. :ivar stream_output: If the response for this request should be streamed. cCs"||_||_||_||_||_dSr)r-r.r0r/r)rr-r.r0r/rrrrrs  zAWSPreparedRequest.__init__cCsd}||j|j|j|jfS)NzD)rr-r.r0)rfmtrrr__repr__szAWSPreparedRequest.__repr__c Csvtttf}|jdust|j|rdSztd|j|jdWdSty:}z td|t |jdd}~ww)a+Resets the streaming body to it's initial position. If the request contains a streaming body (a streamable file-like object) seek to the object's initial position to ensure the entire contents of the object is sent. This is a no-op for static bytes-like body types. NzRewinding stream: %srzUnable to rewind stream: %s)Z stream_object) r?r5 bytearrayr/r4rArBseek Exceptionr)rZnon_seekable_typeserrr reset_streams   zAWSPreparedRequest.reset_streamN)rrrr_rrrrrrrrs   rc@s0eZdZdZddZeddZeddZdS) AWSResponseaA data class representing an HTTP response. This class was originally inspired by requests.models.Response, but has been boiled down to meet the specific use cases in botocore. This has effectively been reduced to a named tuple. :ivar url: The full url. :ivar status_code: The status code of the HTTP response. :ivar headers: The HTTP headers received. :ivar body: The HTTP response body. cCs&||_||_t||_||_d|_dSr)r. status_coderr0raw_content)rr.rr0rrrrr#s   zAWSResponse.__init__cCs*|jdurt|jpt|_|jS)z!Content of the response as bytes.N)rr?r8rstreamr)rrrcontent+s zAWSResponse.contentcCs*tj|j}|r|j|S|jdS)a Content of the response as a proper text type. Uses the encoding type provided in the reponse headers to decode the response content into a proper text type. If the encoding is not present in the headers, UTF-8 is used as a default. r2)rorpget_encoding_from_headersr0rrY)rencodingrrrtext8s  zAWSResponse.textN)rrrr_rrrrrrrrrs   rc@s4eZdZddZddZddZddZd d Zd S) _HeaderKeycCs||_||_dSr)_keylower_lowerrrrrrrHsz_HeaderKey.__init__cC t|jSr)hashrr)rrr__hash__L z_HeaderKey.__hash__cCst|to |j|jkSr)r4rr)rotherrrr__eq__Osz_HeaderKey.__eq__cCs|jSr)rr)rrr__str__Rsz_HeaderKey.__str__cCrr)reprrr)rrrrUrz_HeaderKey.__repr__N)rrrrrrrrrrrrrGs  rc@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)rz9A case-insenseitive dictionary to represent HTTP headers.cOsi|_|j|i|dSr)_dictupdaterrrrr\szHeadersDict.__init__cCs||jt|<dSrrr)rrrrrr __setitem__`szHeadersDict.__setitem__cCs|jt|Srrrrrr __getitem__cszHeadersDict.__getitem__cCs|jt|=dSrrrrrr __delitem__fzHeadersDict.__delitem__cCsdd|jDS)Ncss|]}t|VqdSr)r5)rrrrr jsz'HeadersDict.__iter__..)rr)rrr__iter__irzHeadersDict.__iter__cCrr)rWrr)rrr__len__lrzHeadersDict.__len__cCrr)rrr)rrrrorzHeadersDict.__repr__cCs t|Sr)rrr)rrrcopyrrzHeadersDict.copyN) rrrr_rrrrrrrrrrrrrYs r)NN)*r[loggingcollections.abcrZ urllib3.utilrCZurllib3.connectionrrZurllib3.connectionpoolrrZbotocore.utilsroZbotocore.compatrrr r r r r Zbotocore.exceptionsr getLoggerrrArrrbrergrirvryrnrrxrrrrrrrrs6  $ 2 )X;31