U m^}`@sddlZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl Z ddlmZddlmZmZmZmZmZmZddlmZeeZGd d d eZGd d d eZGd ddeeZGdddeeZGddde Z Gddde Z!d'ddZ"ddZ#ddZ$GdddeZ%GdddeZ&Gdd d eZ'Gd!d"d"eZ(Gd#d$d$eZ)Gd%d&d&eZ*dS)(N)VerifiedHTTPSConnection)HTTPConnection)HTTPConnectionPool)HTTPSConnectionPool)six) HTTPHeaders HTTPResponse urlunspliturlsplit urlencodeMutableMapping)UnseekableStreamErrorc@seZdZddZddZdS)AWSHTTPResponsecOs"|d|_tj|f||dS)N status_tuple)pop _status_tupler__init__selfargskwargsrm/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/botocore/botocore/awsrequest.pyr&s zAWSHTTPResponse.__init__cCs(|jdk r|j}d|_|St|SdSN)rr _read_status)rrrrrr*s  zAWSHTTPResponse._read_statusN)__name__ __module__ __qualname__rrrrrrr#srcseZdZdZfddZfddZfddZfdd 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|_dSNF)superrrresponse_class_original_response_cls_response_received_expect_header_setr __class__rrr?s zAWSConnection.__init__cs&tt|d|_d|_|j|_dSr)r rcloser#r$r"r!rr%rrr'MszAWSConnection.closecstjdddkr tt|S||j|j|d|j |j f|j D]\}}|d||fqP|d|j |j|j|jd}|\}}}|dkr|td||f|j}|sq|d krqqdS) N)r)zCONNECT %s:%d HTTP/1.0 z%s: %s z )strictmethodzTunnel connection failed: %d %s)  )sys version_infor r_tunnelZ _set_hostport _tunnel_host _tunnel_portsendhostport_tunnel_headers iteritemsr!sockr+_methodrr'socketerrorstripfpreadline)rheadervalueresponseversioncodemessageliner%rrr3Ts*    zAWSConnection._tunnelcsTd|_|dddkrd|_nd|_|j|_tt|j||||f||}d|_|S)NFZExpectr0s 100-continueT)r#getr$r"r!r r _send_request)rr,urlbodyheadersrrrvalr%rrrJts" zAWSConnection._send_requestcCsDg}|D],}t|tjr*||dq||qd|}|S)Nutf-8r.) isinstancer text_typeappendencodejoin)rZ mixed_bufferZ bytes_bufferchunkmsgrrr_convert_to_bytess   zAWSConnection._convert_to_bytesNcOs|jd||j}|jdd=t|tr:||7}d}|||jr|tdt j |j drr| |dStd|dk r||dS)N)r0r0z"Waiting for 100 Continue response.zCNo response seen from server, continuing to send the response body.)_bufferextendrWrPbytesr6r$loggerdebugurllib3util wait_for_readr;_handle_expect_response)r message_bodyrrrVrrr _send_outputs        zAWSConnection._send_outputcCsd}|dkr|}qdS)Nr.)rA)rr@currentrrr_consume_headersszAWSConnection._consume_headerscCs|jdd}z|}|dd}||rN||td| |ndt |dkr|d drtd|d dt |d |d df}tjt|d }||_d |_W5|XdS) Nrbrr)z5100 Continue response seen, now sending request body.HTTP/zOReceived a non 100 Continue response from the server, NOT sending request body.asciirX)rT)r;makefiler'rAsplit_is_100_continue_statusrer\r]_send_message_bodylen startswithdecodeint functoolspartialrr!r#)rrbr@maybe_status_linepartsrr!rrrras*         z%AWSConnection._handle_expect_responsecCs|dk r||dSr)r6)rrbrrrrmsz AWSConnection._send_message_bodycs$|jrtddStt||S)Nz@send() called, but reseponse already received. Not sending data.)r#r\r]r rr6)rstrr%rrr6s zAWSConnection.sendcCs2|dd}t|dko0|ddo0|ddkS)Nr)rgrrhrXs100)rkrnro)rrtrurrrrls  z%AWSConnection._is_100_continue_status)N)rrr__doc__rr'r3rJrWrcrerarmr6rl __classcell__rrr%rr3s    $ % rc@seZdZdZdS)AWSHTTPConnectionz8 An HTTPConnection that supports 100 Continue behavior. Nrrrrwrrrrrysryc@seZdZdZdS)AWSHTTPSConnectionz9 An HTTPSConnection that supports 100 Continue behavior. Nrzrrrrr{sr{c@seZdZeZdS)AWSHTTPConnectionPoolN)rrrry ConnectionClsrrrrr|sr|c@seZdZeZdS)AWSHTTPSConnectionPoolN)rrrr{r}rrrrr~sr~c Cs|}|dk r|d}||d<|d}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. NrMz User-Agent host_prefixurl_pathZ query_string?z?%sz&%srKcontext)rI_urljoinbotocoreutilspercent_encode_sequence) request_dict endpoint_urlr user_agentrrMrrKrZencoded_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,rKrLrM)r,rKdatarMr) AWSRequestr)rrZrequest_objectrrrcreate_request_object-s  rcCst|}|r|dkr,|ds"d}qf|d}n:|ddrZ|drZ|ddd|}n |d|}|d}|dk r~||}t|d|||d|df}|S)N/r)rXrrg)r endswithror )rrrpnew_pathZ new_netlocZ reconstructedrrrrAs   rc@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,rKrLrMrrrrprepareqs    zAWSRequestPreparer.preparecCs2|j}|jr.tt|jdd}d||f}|S)NTdoseqz%s?%s)rKparamsr listitems)rrrKrrrrrzs  zAWSRequestPreparer._prepare_urlNcCslt|j}d|ksd|kr"|S|jdkrh||}|dk rLt||d<nt|}td|d|d<|S)NzTransfer-EncodingzContent-Length)GETHEADOPTIONSz Failed to determine length of %schunked) HeadersDictrMrr,_determine_content_lengthrvtyper\r])rrZ prepared_bodyrMlengthZ body_typerrrrs   z#AWSRequestPreparer._prepare_headerscCs<|\}}t|tjr|d}t|tjr4|d}||fSNrO)rPrrQrS)ritemkeyrCrrr_to_utf8s     zAWSRequestPreparer._to_utf8csB|j}|dkrd}t|tr>fdd|D}t|dd}|S)z"Prepares the given HTTP body data.r0Ncsg|]}|qSr)r).0rr(rr sz4AWSRequestPreparer._prepare_body..Tr)rrPdictrr )rrrLrrr(rrs  z AWSRequestPreparer._prepare_bodyc Cs|sdSz t|WSttfk r8}zW5d}~XYnXt|dr|t|dr||}|dd|}||||SdS)Nrseektellr))rnAttributeError TypeErrorhasattrrr)rrLeZorig_posZ end_file_posrrrrs   z,AWSRequestPreparer._determine_content_length)N) rrrrwrrrrrrrrrrr]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 Cst||_|dkrin|}||_||_t|_||_||_||_||_ |dk rj| D]\}} | |j|<qVi|_ dSr) _REQUEST_PREPARER_CLS_request_preparerr,rKrrMrr auth_pathrrr) rr,rKrMrrrrrrCrrrrs  zAWSRequest.__init__cCs |j|S)z>Constructs a :class:`AWSPreparedRequest `.)rrr(rrrrszAWSRequest.preparecCs$|j}t|tjr |d}|Sr)rrLrPrrQrS)rrLrrrrLs   zAWSRequest.body)NNNNNNF) rrrrwrrrrpropertyrLrrrrrs #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"||_||_||_||_||_dSr)r,rKrMrLr)rr,rKrMrLrrrrrs zAWSPreparedRequest.__init__cCsd}||j|j|j|jfS)NzD)rr,rKrM)rfmtrrr__repr__ szAWSPreparedRequest.__repr__c Cstjtjtf}|jdks$t|j|r(dSztd|j|jdWn:t k r}ztd|t |jdW5d}~XYnXdS)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_typerQ bytearrayrLrPr\r]r Exceptionr )rZnon_seekable_typesrrrr reset_streams  zAWSPreparedRequest.reset_streamN)rrrrwrrrrrrrrs 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)rK status_coderrMraw_content)rrKrrMrrrrr9s  zAWSResponse.__init__cCs*|jdkr$t|jp t|_|jS)z!Content of the response as bytes.N)rr[rTrstreamr(rrrcontentAs zAWSResponse.contentcCs.tj|j}|r|j|S|jdSdS)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. rON)rrget_encoding_from_headersrMrrp)rencodingrrrtextNs zAWSResponse.textN)rrrrwrrrrrrrrr,s   rc@s4eZdZddZddZddZddZd d Zd S) _HeaderKeycCs||_||_dSr)_keylower_lowerrrrrrr^sz_HeaderKey.__init__cCs t|jSr)hashrr(rrr__hash__bsz_HeaderKey.__hash__cCst|to|j|jkSr)rPrr)rotherrrr__eq__esz_HeaderKey.__eq__cCs|jSr)rr(rrr__str__hsz_HeaderKey.__str__cCs t|jSr)reprrr(rrrrksz_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||dSr)_dictupdaterrrrrqszHeadersDict.__init__cCs||jt|<dSrrr)rrrCrrr __setitem__uszHeadersDict.__setitem__cCs|jt|Srrrrrr __getitem__xszHeadersDict.__getitem__cCs|jt|=dSrrrrrr __delitem__{szHeadersDict.__delitem__cCsdd|jDS)Ncss|]}t|VqdSr)rv)rrrrr sz'HeadersDict.__iter__..)rr(rrr__iter__~szHeadersDict.__iter__cCs t|jSr)rnrr(rrr__len__szHeadersDict.__len__cCs t|jSr)rrr(rrrrszHeadersDict.__repr__cCs t|Sr)rrr(rrrcopyszHeadersDict.copyN) rrrrwrrrrrrrrrrrrrosr)NN)+r1loggingrrr=Z urllib3.utilr^Zurllib3.connectionrrZurllib3.connectionpoolrrZbotocore.utilsrZbotocore.compatrrrr r r r Zbotocore.exceptionsr getLoggerrr\robjectrryr{r|r~rrrrrrrrrrrrrs>        C (d921