U
    H4f                     @   s   d dl Z d dlZd dlmZmZ d dlmZ d dlmZm	Z	 d dl
mZ e eZG dd dZG dd	 d	ZG d
d deZG dd deZdS )    N)AsyncServiceProxyServiceProxy)Settings)AsyncTransport	Transport)Documentc                   @   s$   e Zd Zdd Zdd Zdd ZdS )Factoryc                 C   s2   t |d| | _||jkr"|| _n||| _d S )Nzget_%s)getattr_method
namespaces_nsZget_ns_prefix)selftypeskind	namespace r   //tmp/pip-unpacked-wheel-04z2hmy8/zeep/client.py__init__   s    
zFactory.__init__c                 C   s   | | S )Return the complexType or simpleType for the given localname.

        :rtype: zeep.xsd.ComplexType or zeep.xsd.AnySimpleType

        r   r   keyr   r   r   __getattr__   s    zFactory.__getattr__c                 C   s   |  d| j|f S )r   z{%s}%s)r
   r   r   r   r   r   __getitem__   s    zFactory.__getitem__N)__name__
__module____qualname__r   r   r   r   r   r   r   r      s   r   c                   @   s   e Zd ZU dZeZejeef e	d< d$ddZ
edd Zedd	 Zd%eje eje d
ddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zeje edddZd d! Zd&d"d#ZdS )'Clienta@  The zeep Client.

    :param wsdl: Url/local WSDL location or preparsed WSDL Document
    :param wsse:
    :param transport: Custom transport class.
    :param service_name: The service name for the service binding. Defaults to
                         the first service in the WSDL document.
    :param port_name: The port name for the default binding. Defaults to the
                      first port defined in the service element in the WSDL
                      document.
    :param plugins: a list of Plugin instances
    :param settings: a zeep.Settings() object

    _default_transportNc                 C   s   |st d|pt | _|d k	r$|n|  | _t|tr@|| _nt|| j| jd| _|| _|d k	rf|ng | _	d | _
|| _|| _d | _d S )NzNo URL given for the wsdl)settings)
ValueErrorr   r   r   	transport
isinstancer   wsdlwsseplugins_default_service_default_service_name_default_port_name_default_soapheaders)r   r"   r#   r    service_name	port_namer$   r   r   r   r   r   8   s    

zClient.__init__c                 C   s
   | j jjS N)r"   r   Z
prefix_mapr   r   r   r   r   U   s    zClient.namespacesc                 C   s4   | j r| j S | j| j| jd| _ | j s.td| j S )zIThe default ServiceProxy instance

        :rtype: ServiceProxy

        r)   r*   zhThere is no default service defined. This is usually due to missing wsdl:service definitions in the WSDL)r%   bindr&   r'   r   r,   r   r   r   serviceY   s     zClient.servicer-   c                 C   s4   | j jsdS | |}| ||}t| |jf|jS a  Create a new ServiceProxy for the given service_name and port_name.

        The default ServiceProxy instance (`self.service`) always referes to
        the first service/port in the wsdl Document.  Use this when a specific
        port is required.

        N)r"   services_get_service	_get_portr   bindingbinding_optionsr   r)   r*   r/   portr   r   r   r.   m   s
    
zClient.bindc              	   C   sN   z| j j| }W n. tk
r>   tdd| j j  Y nX t| ||dS )zCreate a new ServiceProxy for the given binding name and address.

        :param binding_name: The QName of the binding
        :param address: The address of the endpoint

        zANo binding found with the given QName. Available bindings are: %sz, )address)r"   bindingsKeyErrorr   joinkeysr   )r   Zbinding_namer8   r4   r   r   r   create_service   s    
zClient.create_servicec                 O   s   |j j|||| d\}}|S )zZCreate the payload for the given operation.

        :rtype: lxml.etree._Element

        )client)_binding_create)r   r/   Zoperation_nameargskwargsZenvelopeZhttp_headersr   r   r   create_message   s       
zClient.create_messagec                 C   s   t | jjd|S )zReturn a type factory for the given namespace.

        Example::

            factory = client.type_factory('ns0')
            user = factory.User(name='John')

        :rtype: Factory

        type)r   r"   r   )r   r   r   r   r   type_factory   s    zClient.type_factoryc                 C   s   | j j|S )zwReturn the type for the given qualified name.

        :rtype: zeep.xsd.ComplexType or zeep.xsd.AnySimpleType

        )r"   r   get_typer   namer   r   r   rF      s    zClient.get_typec                 C   s   | j j|S )z\Return the element for the given qualified name.

        :rtype: zeep.xsd.Element

        )r"   r   get_elementrG   r   r   r   rI      s    zClient.get_elementc                 C   s   | j j|| dS )z'Set a shortcut for the given namespace.N)r"   r   set_ns_prefix)r   prefixr   r   r   r   rJ      s    zClient.set_ns_prefixc                 C   s
   || _ dS )a  Set the default soap headers which will be automatically used on
        all calls.

        Note that if you pass custom soapheaders using a list then you will
        also need to use that during the operations. Since mixing these use
        cases isn't supported (yet).

        N)r(   )r   headersr   r   r   set_default_soapheaders   s    	zClient.set_default_soapheadersc                 C   s4   |r|j |}|s0tdnt|j  d }|S )NzPort not foundr   )Zportsgetr   listvalues)r   r/   rH   r7   r   r   r   r3      s    
zClient._get_port)rH   returnc                 C   s:   |r | j j|}|s6tdntt| j j d }|S )NzService not found)r"   r1   rN   r   nextiterrP   )r   rH   r/   r   r   r   r2      s    
zClient._get_servicec                 C   s   | S r+   r   r,   r   r   r   	__enter__   s    zClient.__enter__c                 C   s   t | jdr| j  d S )Nclose)hasattrr    rU   r   exc_type	exc_value	tracebackr   r   r   __exit__   s    zClient.__exit__)NNNNNN)NN)NNN)r   r   r   __doc__r   r   typingUnionr   __annotations__r   propertyr   r/   Optionalstrr.   r=   rC   rE   rF   rI   rJ   rM   r3   r2   rT   r[   r   r   r   r   r   &   s<   
      


  		r   c                   @   sF   e Zd ZeZd
eje eje dddZdd Z	ddddd	Z
dS )AsyncClientNr-   c                 C   s4   | j jsdS | |}| ||}t| |jf|jS r0   )r"   r1   r2   r3   r   r4   r5   r6   r   r   r   r.      s
    
zAsyncClient.bindc                    s   | S r+   r   r,   r   r   r   
__aenter__   s    zAsyncClient.__aenter__)rQ   c                    s   | j  I d H  d S r+   )r    acloserW   r   r   r   	__aexit__   s    zAsyncClient.__aexit__)NN)NNN)r   r   r   r   r   r]   ra   rb   r.   rd   rf   r   r   r   r   rc      s     rc   c                       s    e Zd ZdZ fddZ  ZS )CachingClientzShortcut to create a caching client, for the lazy people.

    This enables the SqliteCache by default in the transport as was the default
    in earlier versions of zeep.

    c                    s8   ddl m} |dp t| d|d< t j|| d S )Nr   )SqliteCacher    )cache)Z
zeep.cacherh   rN   r   superr   )r   rA   rB   rh   	__class__r   r   r     s    zCachingClient.__init__)r   r   r   r\   r   __classcell__r   r   rk   r   rg      s   rg   )loggingr]   Z
zeep.proxyr   r   Zzeep.settingsr   Zzeep.transportsr   r   Z	zeep.wsdlr   	getLoggerr   loggerr   r   rc   rg   r   r   r   r   <module>   s   
 <