ó
Òbc           @@ so  d  d l  m Z m Z d  d l Z d  d l Z d  d l m Z m Z m Z m Z m	 Z	 m
 Z
 m Z m Z m Z m Z y d  d l m Z Wn! e k
 r« d  d l m Z n Xd d l m Z d d d	 g Z d
 „  Z d „  Z d „  Z d d „ Z d Z d d „ Z d e f d „  ƒ  YZ d „  Z e e j _ e e j  _! e e j  _" e e j  _# e e j  _$ e e j  _% d S(   i    (   t   absolute_importt   print_functionN(
   t   _CS_REQ_SENTt   _CS_REQ_STARTEDt   CONTINUEt   UnknownProtocolt   CannotSendHeadert
   NO_CONTENTt   NOT_MODIFIEDt   EXPECTATION_FAILEDt   HTTPMessaget   HTTPException(   t   StringIOi   (   t   encode_to_s3t   PATCHt   POSTt   PUTc         C@ s†  |  j  d k	 r d S|  j ƒ  \ } } } | |  _ | j ƒ  |  _ | d k rX d |  _ n? | j d ƒ rs d |  _ n$ | d k r‹ d |  _ n t | ƒ ‚ |  j d k r× d |  _	 d |  _
 d	 |  _ t t ƒ  ƒ |  _  d St |  j d ƒ |  _  |  j d k r(x* |  j  j D] } t d
 | d d ƒqWn  d |  j  _ |  j  j d ƒ } | rs| j ƒ  d k rsd	 |  _
 d |  _ n	 d |  _
 |  j ƒ  |  _ |  j  j d ƒ } | rû|  j
 rûy t | ƒ |  _	 Wn t k
 rÜd |  _	 qX|  j	 d k  rd |  _	 qn	 d |  _	 | t k sG| t k sGd | k o3d k  n sG|  j d k rSd |  _	 n  |  j r‚|  j
 r‚|  j	 d k r‚d	 |  _ n  d S(   s›    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.
    Ns   HTTP/1.0i
   s   HTTP/1.i   s   HTTP/0.9i	   i    i   s   header:t   endt    s   transfer-encodingt   chunkeds   content-lengthid   iÈ   t   HEAD(   t   msgt   Nonet   _read_statust   statust   stript   reasont   versiont
   startswithR   t   lengthR   t
   will_closeR
   R   t   fpt
   debuglevelt   headerst   printt	   getheadert   lowert
   chunk_leftt   _check_closet   intt
   ValueErrorR   R   t   _method(   t   selfR   R   R   t   hdrt   tr_encR   (    (    sS   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/Custom_httplib27.pyt   httpresponse_patched_begin   s\    							

c         C@ sç   d  } | d  k r- | j ƒ  t k r- d } n— | d  k	 rÄ y t t | ƒ ƒ } WqÄ t t f k
 rÀ y" t t j | j	 ƒ  ƒ j
 ƒ } WqÁ t t f k
 r¼ |  j d k r½ t d ƒ q½ qÁ XqÄ Xn  | d  k	 rã |  j d | ƒ n  d  S(   Nt   0i    s   Cannot stat!!s   Content-Length(   R   t   uppert   _METHODS_EXPECTING_BODYt   strt   lent	   TypeErrort   AttributeErrort   ost   fstatt   filenot   st_sizet   OSErrorR    R"   t	   putheader(   R*   t   bodyt   methodt   thelen(    (    sS   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/Custom_httplib27.pyt)   httpconnection_patched_set_content_lengthg   s    	" c         C@ s¹  t  j g  | D] } | j ƒ  ^ q ƒ } i  } d | k rG d | d <n  d | k r` d | d <n  t } xG | j ƒ  D]9 \ }	 }
 d |	 j ƒ  k rs d |
 j ƒ  k rs t } qs qs Wt | ƒ } |  j | | |  d | k rî |  j | | ƒ n  x6 | j ƒ  D]( \ }	 }
 |  j	 t |	 ƒ t |
 ƒ ƒ qû W| s=|  j
 | ƒ nx | sRt d	 ƒ ‚ n  |  j
 ƒ  |  j ƒ  } | j ƒ  t |  _ | j t k r–t ƒ  ‚ n | j t k rµ|  j | ƒ n  d  S(
   Nt   hosti   t	   skip_hosts   accept-encodingt   skip_accept_encodingt   expects   100-continues   content-lengths.   A body is required when expecting 100-continue(   t   dictt   fromkeysR$   t   Falset	   iteritemst   TrueR   t
   putrequestt   _set_content_lengthR:   t
   endheadersR   t   getresponset   readR   t   _HTTPConnection__stateR   R	   t   ExpectationFailedR   t   send(   R*   R<   t   urlR;   R!   t   kt   header_namest   skipst   expect_continueR+   t   valuet   resp(    (    sS   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/Custom_httplib27.pyt#   httpconnection_patched_send_request   s8    ($ 

	c         C@ s5   |  j  t k r t |  _  n	 t ƒ  ‚ |  j | ƒ d S(   so  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.  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(   RM   R   R   R   t   _send_output(   R*   t   message_body(    (    sS   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/Custom_httplib27.pyt!   httpconnection_patched_endheaders§   s    		i @  c         C@ s–   |  j  j d ƒ d j |  j  ƒ } |  j  2t | ƒ } t | t ƒ ri t | ƒ t k  ri | | 7} d } n  |  j	 | ƒ | d k	 r’ |  j	 | ƒ n  d S(   s¬   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.
    t    s   
N(   R[   R[   (
   t   _buffert   extendt   joinR   t
   isinstanceR1   R2   t   mssR   RO   (   R*   RY   R   (    (    sS   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/Custom_httplib27.pyt"   httpconnection_patched_send_output¿   s    !
	RN   c           B@ s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sS   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/Custom_httplib27.pyRN   ×   s   c         C@ s   |  j  | ƒ d  S(   N(   RO   (   R*   RY   (    (    sS   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/Custom_httplib27.pyt(   httpconnection_patched_wrapper_send_bodyÜ   s    (&   t
   __future__R    R   R5   t   httplibR   R   R   R   R   R   R   R	   R
   R   t	   cStringIOR   t   ImportErrort	   BaseUtilsR   R0   R-   R>   RW   R   RZ   R`   Ra   RN   Rd   t   HTTPResponset   begint   HTTPConnectionRJ   RX   RI   t   _send_requestt   wrapper_send_body(    (    (    sS   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/Custom_httplib27.pyt   <module>   s.   F	N		(	