3 B\`@sddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddl ZddlmZddlmZmZmZmZmZddlmZejeZGd d d eZGd d d eZGd ddee ZGdddeeZGddde Z Gddde Z!d'ddZ"ddZ#ddZ$GdddeZ%GdddeZ&Gdd d eZ'Gd!d"d"eZ(Gd#d$d$eZ)Gd%d&d&ej*Z+dS)(N)VerifiedHTTPSConnection)HTTPConnection)HTTPConnectionPool)HTTPSConnectionPool)six) HTTPHeaders HTTPResponse urlunspliturlsplit urlencode)UnseekableStreamErrorc@seZdZddZddZdS)AWSHTTPResponsecOs"|jd|_tj|f||dS)N status_tuple)pop _status_tupler__init__)selfargskwargsrm/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/botocore/botocore/awsrequest.pyr's zAWSHTTPResponse.__init__cCs(|jdk r|j}d|_|Stj|SdS)N)rr _read_status)rrrrrr+s  zAWSHTTPResponse._read_statusN)__name__ __module__ __qualname__rrrrrrr $sr cseZdZdZfddZfddZfddZfdd Zd d Zdd dZ ddZ ddZ ddZ fddZ ddZZS) 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*tt|j|||j|_d|_d|_dS)NF)superrrresponse_class_original_response_cls_response_received_expect_header_set)rrr) __class__rrr@s zAWSConnection.__init__cs&tt|jd|_d|_|j|_dS)NF)rrcloserr rr)r)r!rrr"NszAWSConnection.closecstjddd kr tt|jS|j|j|j|jd|j |j fx(|j j D]\}}|jd||fqRW|jd|j |j|j|jd}|j\}}}|dkr|jtjd||jfx|jj}|sP|d krPqWdS)NzCONNECT %s:%d HTTP/1.0 z%s: %s z )strictmethodzTunnel connection failed: %d %s  )r#r$)r(r)r*)sys version_inforr_tunnelZ _set_hostport _tunnel_host _tunnel_portsendhostport_tunnel_headers iteritemsrsockr%_methodrr"socketerrorstripfpreadline)rheadervalueresponseversioncodemessageline)r!rrr-Us(    zAWSConnection._tunnelcsTd|_|jdddkrd|_nd|_|j|_tt|j||||f||}d|_|S)NFZExpectr*s 100-continueT)rgetr rrrr _send_request)rr&urlbodyheadersrrrval)r!rrrDus zAWSConnection._send_requestcCsHg}x4|D],}t|tjr,|j|jdq |j|q Wdj|}|S)Nzutf-8s ) isinstancer text_typeappendencodejoin)rZ mixed_bufferZ bytes_bufferchunkmsgrrr_convert_to_bytess   zAWSConnection._convert_to_bytesNcOs|jjd|j|j}|jdd=t|tr:||7}d}|j||jr|tjdt j j |j drr|j |dStjd|dk r|j|dS)Nr*z"Waiting for 100 Continue response.zCNo response seen from server, continuing to send the response body.)r*r*)_bufferextendrPrIbytesr0r loggerdebugurllib3util wait_for_readr5_handle_expect_response)r message_bodyrrrOrrr _send_outputs        zAWSConnection._send_outputcCsd}x|dkr|j}qWdS)Ns )r;)rr:currentrrr_consume_headerss zAWSConnection._consume_headersc Cs|jjdd}z|j}|jdd}|j|rN|j|tjd|j|ndt |dkr|dj drtjd|dj dt |d |dj df}t jt|d }||_d |_Wd|jXdS) Nrbrr#z5100 Continue response seen, now sending request body.sHTTP/zOReceived a non 100 Continue response from the server, NOT sending request body.asciirQ)rT)r5makefiler;split_is_100_continue_statusr^rUrV_send_message_bodylen startswithdecodeint functoolspartialr rrr")rr[r:maybe_status_linepartsrrrrrrZs"         z%AWSConnection._handle_expect_responsecCs|dk r|j|dS)N)r0)rr[rrrresz AWSConnection._send_message_bodycs$|jrtjddStt|j|S)Nz@send() called, but reseponse already received. Not sending data.)rrUrVrrr0)rstr)r!rrr0s zAWSConnection.sendcCs2|jdd}t|dko0|djdo0|ddkS)Nr#r`rsHTTP/rQs100)rcrfrg)rrlrmrrrrds z%AWSConnection._is_100_continue_status)N)rrr__doc__rr"r-rDrPr\r^rZrer0rd __classcell__rr)r!rr4s     $ % rc@seZdZdZdS)AWSHTTPConnectionz8 An HTTPConnection that supports 100 Continue behavior. N)rrrrorrrrrqsrqc@seZdZdZdS)AWSHTTPSConnectionz9 An HTTPSConnection that supports 100 Continue behavior. N)rrrrorrrrrrsrrc@seZdZeZdS)AWSHTTPConnectionPoolN)rrrrq ConnectionClsrrrrrssrsc@seZdZeZdS)AWSHTTPSConnectionPoolN)rrrrrrtrrrrrusruc Cs|}|dk r|d}||d<|jd}t||d|}|drttjj}||d} d|krh|d| 7}n |d | 7}||d <||d <|dkri|d <dS) 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. NrGz User-Agent host_prefixurl_pathZ query_string?z?%sz&%srEcontext)rC_urljoinbotocoreutilspercent_encode_sequence) request_dict endpoint_urlry user_agentrrGrvrEr}Zencoded_query_stringrrrprepare_request_dicts    rcCs2|}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&rErFrG)r&rEdatarGry) AWSRequestry)r~rZrequest_objectrrrcreate_request_object.s  rcCst|}| s|dkr.|ds$d}qh|d}n:|djdr\|jdr\|ddd|}n |d|}|d}|dk r||}t|d|||d|df}|S)N/r#rQrr`)r endswithrgr )rrwrvpnew_pathZ new_netlocZ reconstructedrrrrzBs  rzc@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|}|j|}|j||}|j}t|||||S)N)r& _prepare_url _prepare_body_prepare_headers stream_outputAWSPreparedRequest)roriginalr&rErFrGrrrrpreparers    zAWSRequestPreparer.preparecCs2|j}|jr.tt|jjdd}d||f}|S)NT)doseqz%s?%s)rEparamsr listitems)rrrErrrrr{s  zAWSRequestPreparer._prepare_urlNcCslt|jj}d|ksd|kr"|S|jdkrh|j|}|dk rLt||d<nt|}tjd|d|d<|S) NzTransfer-EncodingzContent-LengthGETHEADOPTIONSz Failed to determine length of %schunked)rrr) HeadersDictrGrr&_determine_content_lengthrntyperUrV)rrZ prepared_bodyrGlengthZ body_typerrrrs   z#AWSRequestPreparer._prepare_headerscCs<|\}}t|tjr|jd}t|tjr4|jd}||fS)Nzutf-8)rIrrJrL)ritemkeyr=rrr_to_utf8s     zAWSRequestPreparer._to_utf8csB|j}|dkrd}t|tr>fdd|jD}t|dd}|S)z"Prepares the given HTTP body data.r*Ncsg|]}j|qSr)r).0r)rrr sz4AWSRequestPreparer._prepare_body..T)r)rrIdictrr )rrrFrr)rrrs  z AWSRequestPreparer._prepare_bodycCs~|sdSyt|Sttfk r6}zWYdd}~XnXt|drzt|drz|j}|jdd|j}|j|||SdS)Nrseektellr#)rfAttributeError TypeErrorhasattrrr)rrFeZorig_posZ end_file_posrrrrs  z,AWSRequestPreparer._determine_content_length)N) rrrrorrrrrrrrrrr^s   rc@s2eZdZdZeZd ddZddZedd Z dS) ra 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 Csx|j|_|dkrin|}||_||_t|_||_||_||_||_ |dk rnx|j D]\}} | |j|<qXWi|_ dS)N) _REQUEST_PREPARER_CLS_request_preparerr&rErrGrr auth_pathrrry) rr&rErGrrrrrr=rrrrs  zAWSRequest.__init__cCs |jj|S)z>Constructs a :class:`AWSPreparedRequest `.)rr)rrrrrszAWSRequest.preparecCs$|jj}t|tjr |jd}|S)Nzutf-8)rrFrIrrJrL)rrFrrrrFs   zAWSRequest.body)NNNNNNF) rrrrorrrrpropertyrFrrrrrs rc@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"||_||_||_||_||_dS)N)r&rErGrFr)rr&rErGrFrrrrrs zAWSPreparedRequest.__init__cCsd}||j|j|j|jfS)NzD)rr&rErG)rfmtrrr__repr__szAWSPreparedRequest.__repr__cCstjtjtf}|jdks$t|j|r(dSytjd|j|jjdWn:t k r}ztjd|t |jdWYdd}~XnXdS)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 binary_typerJ bytearrayrFrIrUrVr Exceptionr )rZnon_seekable_typesrrrr reset_streams  zAWSPreparedRequest.reset_streamN)rrrrorrrrrrrrs 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|_dS)N)rE status_coderrGraw_content)rrErrGrrrrr:s  zAWSResponse.__init__cCs*|jdkr$tj|jjp t|_|jS)z!Content of the response as bytes.N)rrTrMrstream)rrrrcontentBs zAWSResponse.contentcCs.tjj|j}|r|jj|S|jjdSdS)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. zutf-8N)r{r|get_encoding_from_headersrGrrh)rencodingrrrtextOs zAWSResponse.textN)rrrrorrrrrrrrr-s  rc@s4eZdZddZddZddZddZd d Zd S) _HeaderKeycCs||_|j|_dS)N)_keylower_lower)rrrrrr_sz_HeaderKey.__init__cCs t|jS)N)hashr)rrrr__hash__csz_HeaderKey.__hash__cCst|to|j|jkS)N)rIrr)rotherrrr__eq__fsz_HeaderKey.__eq__cCs|jS)N)r)rrrr__str__isz_HeaderKey.__str__cCs t|jS)N)reprr)rrrrrlsz_HeaderKey.__repr__N)rrrrrrrrrrrrr^s rc@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)rz:A case-insenseitive dictionary to represent HTTP headers. cOsi|_|j||dS)N)_dictupdate)rrrrrrrrszHeadersDict.__init__cCs||jt|<dS)N)rr)rrr=rrr __setitem__vszHeadersDict.__setitem__cCs|jt|S)N)rr)rrrrr __getitem__yszHeadersDict.__getitem__cCs|jt|=dS)N)rr)rrrrr __delitem__|szHeadersDict.__delitem__cCsdd|jDS)Ncss|]}t|VqdS)N)rn)rrrrr sz'HeadersDict.__iter__..)r)rrrr__iter__szHeadersDict.__iter__cCs t|jS)N)rfr)rrrr__len__szHeadersDict.__len__cCs t|jS)N)rr)rrrrrszHeadersDict.__repr__cCs t|jS)N)rr)rrrrcopyszHeadersDict.copyN) rrrrorrrrrrrrrrrrrpsr)NN),r+loggingrjr7 collectionsZ urllib3.utilrWZurllib3.connectionrrZurllib3.connectionpoolrrZbotocore.utilsr{Zbotocore.compatrrrr r r Zbotocore.exceptionsr getLoggerrrUr objectrrqrrrsrurrrzrrrrrMutableMappingrrrrrs>       C 'd921