o Qa@sddlmZmZddlZddlZddlmZmZmZmZm Z m Z m Z m Z m Z mZzddlmZWney?ddlmZYnwddlmZgdZdd Zd d Zd d ZdddZdZdddZGdddeZddZeej_eej_ eej_!eej_"eej_#eej_$dS))absolute_importprint_functionN) _CS_REQ_SENT_CS_REQ_STARTEDCONTINUEUnknownProtocolCannotSendHeader NO_CONTENT NOT_MODIFIEDEXPECTATION_FAILED HTTPMessage HTTPException)StringIO) encode_to_s3)PATCHPOSTPUTcCs|jdurdS|\}}}||_||_|dkrd|_n|dr'd|_n |dkr/d|_nt||jdkrId|_d|_ d |_ t t |_dSt |j d|_|jdkrc|jjD] }td |d d qYd|j_ |jd }|r||dkr|d |_ d|_nd|_ ||_ |jd}|r|j szt||_Wn tyd|_Yn w|jdkrd|_nd|_|tks|tksd|krdksn|jdkrd|_|j s|j s|jdurd |_ dSdSdSdS)z Re-implemented httplib begin function to not loop over "100 CONTINUE" status replies but to report it to higher level so it can be processed. NzHTTP/1.0 zHTTP/1. zHTTP/0.9 rrzheader: )endztransfer-encodingchunkedcontent-lengthdHEAD)msg _read_statusstatusstripreasonversion startswithrlengthr will_closer rfp debuglevelheadersprint getheaderlower chunk_left _check_closeint ValueErrorr r _method)selfr#r r"hdrtr_encr%r55/usr/lib/python3/dist-packages/S3/Custom_httplib27.pyhttpresponse_patched_beginsf                 r7c Csd}|dur|tvrd}n9|durHztt|}Wn,ttfyGz tt|j }Wntt fyD|j dkrBt dYnwYnw|durT| d|dSdS)N0rz Cannot stat!!zContent-Length)upper_METHODS_EXPECTING_BODYstrlen TypeErrorAttributeErrorosfstatfilenost_sizeOSErrorr(r* putheader)r2bodymethodthelenr5r5r6)httpconnection_patched_set_content_lengthgs$ rHc Cs(tdd|D}i}d|vrd|d<d|vrd|d<d}|D]\}} d |kr4d | vr4d }q"t|}|j||fi|d |vrM||||D]\}} |t|t| qQ|si||dS|sot d || } | t |_ | jtkrt| jtkr||dSdS)NcSsg|]}|qSr5)r,).0kr5r5r6 sz7httpconnection_patched_send_request..hostr skip_hostzaccept-encodingskip_accept_encodingFexpectz 100-continueTrz.A body is required when expecting 100-continue)dictfromkeys iteritemsr,r putrequest_set_content_lengthrD endheadersr getresponsereadr_HTTPConnection__stater r ExpectationFailedrsend) r2rFurlrEr) header_namesskipsexpect_continuer3valuerespr5r5r6#httpconnection_patched_send_requests<   racCs&|jtkr t|_nt||dS)aoIndicate 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. The message body will be sent in the same packet as the message headers if it is string, otherwise it is sent as a separate packet. N)rXrrr _send_outputr2 message_bodyr5r5r6!httpconnection_patched_endheaderss rei@cCsr|jdd|j}|jdd=t|}t|tr't|tkr'||7}d}|||dur7||dSdS)zSend 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. )rfs N) _bufferextendjoinr isinstancer;r<mssrZ)r2rdrr5r5r6"httpconnection_patched_send_outputs    rlc@s eZdZdS)rYN)__name__ __module__ __qualname__r5r5r5r6rYsrYcCs||dSN)rZrcr5r5r6(httpconnection_patched_wrapper_send_bodysrqrp)% __future__rrr?httplibrrrrrr r r r r cStringIOr ImportError BaseUtilsrr:r7rHrarerkrlrYrq HTTPResponsebeginHTTPConnectionrUrbrT _send_requestwrapper_send_bodyr5r5r5r6s20  N (