ó
h€
\c           @   s„   d  d l  Z  d  d l Z d  d l m Z d  d l Z d  d l m Z d  d l m Z m	 Z	 d  d l
 m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   contextmanager(   t   urlparse(   t   get_media_typet   get_version(   t   etree_to_stringt	   Transportc           B   sb   e  Z d  Z d	 d d	 d	 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 e
 d	 d „ ƒ Z RS(
   s   The transport object handles all communication to the SOAP server.

    :param cache: The cache object to be used to cache GET requests
    :param timeout: The timeout for loading wsdl and xsd documents.
    :param operation_timeout: The timeout for operations (POST/GET). By
                              default this is None (no timeout).
    :param session: A :py:class:`request.Session()` object (optional)

    i,  c         C   s]   | |  _  | |  _ | |  _ t j t ƒ |  _ | p< t j ƒ  |  _	 d t
 ƒ  |  j	 j d <d  S(   Ns   Zeep/%s (www.python-zeep.org)s
   User-Agent(   t   cachet   load_timeoutt   operation_timeoutt   loggingt	   getLoggert   __name__t   loggert   requestst   Sessiont   sessionR   t   headers(   t   selfR   t   timeoutR   R   (    (    sD   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/transports.pyt   __init__   s    			c         C   s+   |  j  j | d | d | d |  j ƒ} | S(   sº   Proxy to requests.get()

        :param address: The URL for the request
        :param params: The query parameters
        :param headers: a dictionary with the HTTP headers.

        t   paramsR   R   (   R   t   getR   (   R   t   addressR   R   t   response(    (    sD   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/transports.pyR   "   s    	c         C   s  |  j  j t j ƒ rU | } t | t ƒ r< | j d ƒ } n  |  j  j d | | ƒ n  |  j j	 | d | d | d |  j
 ƒ} |  j  j t j ƒ rt | j j d d ƒ ƒ } | d k rÄ | j } n* | j } t | t ƒ rî | j d ƒ } n  |  j  j d	 | | j | ƒ n  | S(
   sÁ   Proxy to requests.posts()

        :param address: The URL for the request
        :param message: The content for the body
        :param headers: a dictionary with the HTTP headers.

        s   utf-8s   HTTP Post to %s:
%st   dataR   R   s   Content-Types   text/xmls   multipart/relateds&   HTTP Response from %s (status: %d):
%s(   R   t   isEnabledForR	   t   DEBUGt
   isinstancet   bytest   decodet   debugR   t   postR   R   R   R   t   contentt   status_code(   R   R   t   messageR   t   log_messageR   t
   media_type(    (    sD   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/transports.pyR   1   s,    			c         C   s   t  | ƒ } |  j | | | ƒ S(   s.  Post the envelope xml element to the given address with the headers.

        This method is intended to be overriden if you want to customize the
        serialization of the xml element. By default the body is formatted
        and encoded as utf-8. See ``zeep.wsdl.utils.etree_to_string``.

        (   R   R   (   R   R   t   envelopeR   R"   (    (    sD   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/transports.pyt   post_xmlV   s    c         C   sí   | s t  d ƒ ‚ n  t | ƒ j } | d	 k r |  j r^ |  j j | ƒ } | r^ t | ƒ Sn  |  j | ƒ } |  j rŒ |  j j | | ƒ n  | S| d k r» | j d ƒ r» | d } q» n  t	 t
 j j | ƒ d ƒ  } | j ƒ  SWd QXd S(
   s#   Load the content from the given URLs   No url given to loadt   httpt   httpst   files   file://i   t   rbN(   R'   R(   (   t
   ValueErrorR   t   schemeR   R   R   t   _load_remote_datat   addt
   startswitht   opent   ost   patht
   expandusert   read(   R   t   urlR,   R   R    t   fh(    (    sD   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/transports.pyt   loada   s"    		c         C   s?   |  j  j d | ƒ |  j j | d |  j ƒ} | j ƒ  | j S(   Ns   Loading remote data from: %sR   (   R   R   R   R   R   t   raise_for_statusR    (   R   R5   R   (    (    sD   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/transports.pyR-   |   s    
c         c   s$   |  j  } | |  _  d V| |  _  d S(   sb  Context manager to temporarily overrule options.

        Example::

            transport = zeep.Transport()
            with transport.settings(timeout=10):
                client.service.fast_call()

        :param timeout: Set the timeout for POST/GET operations (not used for
                        loading external WSDL or XSD documents)

        N(   R   (   R   R   t   old_timeout(    (    sD   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/transports.pyt   settings‚   s    		N(   R   t
   __module__t   __doc__t   NoneR   R   R   R&   R7   R-   R    R:   (    (    (    sD   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/transports.pyR      s   		
		%			(   R	   R1   t
   contextlibR    R   t   six.moves.urllib.parseR   t
   zeep.utilsR   R   t   zeep.wsdl.utilsR   t   objectR   (    (    (    sD   /data/av2000/b2b/venv/lib/python2.7/site-packages/zeep/transports.pyt   <module>   s   