ó
o€
\c           @   sÏ   d  Z  d d l Z d d l m Z d Z i d d 6d d	 6d
 d 6Z e j d d d g ƒ Z d e f d „  ƒ  YZ d „  Z	 d „  Z
 d „  Z d d „ Z d „  Z d „  Z d d d d „ Z d d d „ Z d S(   sG   This module provides functions for dumping information about responses.iÿÿÿÿN(   t   compatt   dump_responset   dump_alls   0.9i	   s   1.0i
   s   1.1i   t   PrefixSettingst   requestt   responsec           B   s   e  Z d  „  Z RS(   c         C   s4   t  | ƒ } t  | ƒ } t t |  ƒ j |  | | ƒ S(   N(   t   _coerce_to_bytest   superR   t   __new__(   t   clsR   R   (    (    sQ   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/utils/dump.pyR      s    (   t   __name__t
   __module__R   (    (    (    sQ   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/utils/dump.pyR      s   c         C   sU   t  |  j d t ƒ rQ i  } |  j j } | j d ƒ rC d | d <n  | | d <| Sd  S(   Nt   proxy_managers   https://t   CONNECTt   methodt   request_path(   t   getattrt
   connectiont   FalseR   t   urlt
   startswitht   None(   R   t
   proxy_infot   request_url(    (    sQ   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/utils/dump.pyt   _get_proxy_information   s    
c         C   s   t  |  ƒ d t  | ƒ d S(   Ns   : s   
(   R   (   t   namet   value(    (    sQ   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/utils/dump.pyt   _format_header&   s    c         C   sp   t  j |  ƒ } | j d ƒ } | d  k	 r4 | | f St | j ƒ } | j rf | d t | j ƒ 7} n  | | f S(   NR   t   ?(   R    t   urlparset   getR   R   t   patht   query(   R   R   t   urit	   proxy_urlR   (    (    sQ   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/utils/dump.pyt   _build_request_path+   s    
	c         C   sU  | d  k r i  } n  | j } t | j d |  j ƒ ƒ } t |  j | ƒ \ } } | j | | d | d ƒ |  j j	 ƒ  } t | j d | j
 ƒ ƒ }	 | j | d |	 d ƒ x4 | j ƒ  D]& \ }
 } | j | t |
 | ƒ ƒ q¾ W| j | d ƒ |  j rDt |  j t j ƒ r4| j | t |  j ƒ ƒ qD| j d ƒ n  | j d ƒ d  S(   NR   t    s    HTTP/1.1
t   Hosts   Host: s   
s,   << Request body is not a string-like type >>(   R   R   R   t   popR   R#   R   t   extendt   headerst   copyt   netloct   itemsR   t   bodyt
   isinstanceR    t
   basestring(   R   t   prefixest   bytearrR   t   prefixR   R   R!   R(   t   host_headerR   R   (    (    sQ   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/utils/dump.pyt   _dump_request_data8   s"    			c   	      C   sä   | j  } |  j } t j | j d ƒ } | j | d | d t | j ƒ j d ƒ d t	 |  j
 ƒ d ƒ | j } xH | j ƒ  D]: } x1 | j | ƒ D]  } | j | t | | ƒ ƒ q— Wq W| j | d ƒ | j |  j ƒ d  S(   NR   s   HTTP/R$   t   asciis   
(   R   t   rawt   HTTP_VERSIONSR   t   versionR'   t   strt   statust   encodeR   t   reasonR(   t   keyst   getlistR   t   content(	   R   R/   R0   R1   R5   t   version_strR(   R   R   (    (    sQ   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/utils/dump.pyt   _dump_response_dataV   s    		>	"c         C   s5   t  |  t ƒ r1 t |  d ƒ r1 |  j d ƒ }  n  |  S(   NR:   s   utf-8(   R-   t   bytest   hasattrR:   (   t   data(    (    sQ   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/utils/dump.pyR   m   s    s   < s   > c         C   s   | d k	 r | n t ƒ  } t | | ƒ } t |  d ƒ sH t d ƒ ‚ n  t |  ƒ } t |  j | | d | ƒt |  | | ƒ | S(   s  Dump a single request-response cycle's information.

    This will take a response object and dump only the data that requests can
    see for that single request-response cycle.

    Example::

        import requests
        from requests_toolbelt.utils import dump

        resp = requests.get('https://api.github.com/users/sigmavirus24')
        data = dump.dump_response(resp)
        print(data.decode('utf-8'))

    :param response:
        The response to format
    :type response: :class:`requests.Response`
    :param request_prefix: (*optional*)
        Bytes to prefix each line of the request data
    :type request_prefix: :class:`bytes`
    :param response_prefix: (*optional*)
        Bytes to prefix each line of the response data
    :type response_prefix: :class:`bytes`
    :param data_array: (*optional*)
        Bytearray to which we append the request-response cycle data
    :type data_array: :class:`bytearray`
    :returns: Formatted bytes of request and response information.
    :rtype: :class:`bytearray`
    R   s"   Response has no associated requestR   N(	   R   t	   bytearrayR   RB   t
   ValueErrorR   R3   R   R@   (   R   t   request_prefixt   response_prefixt
   data_arrayRC   R/   R   (    (    sQ   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/utils/dump.pyR   s   s    c         C   sN   t  ƒ  } t |  j ƒ } | j |  ƒ x! | D] }  t |  | | | ƒ q- W| S(   s›  Dump all requests and responses including redirects.

    This takes the response returned by requests and will dump all
    request-response pairs in the redirect history in order followed by the
    final request-response.

    Example::

        import requests
        from requests_toolbelt.utils import dump

        resp = requests.get('https://httpbin.org/redirect/5')
        data = dump.dump_all(resp)
        print(data.decode('utf-8'))

    :param response:
        The response to format
    :type response: :class:`requests.Response`
    :param request_prefix: (*optional*)
        Bytes to prefix each line of the request data
    :type request_prefix: :class:`bytes`
    :param response_prefix: (*optional*)
        Bytes to prefix each line of the response data
    :type response_prefix: :class:`bytes`
    :returns: Formatted bytes of request and response information.
    :rtype: :class:`bytearray`
    (   RD   t   listt   historyt   appendR   (   R   RF   RG   RC   RJ   (    (    sQ   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/utils/dump.pyR   Ÿ   s    	(   s   dump_responses   dump_all(   t   __doc__t   collectionst   requestsR    t   __all__R6   t
   namedtuplet   _PrefixSettingsR   R   R   R#   R   R3   R@   R   R   R   (    (    (    sQ   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/utils/dump.pyt   <module>   s&   
						+