o
    g                     @   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   s4   t |d| | _||jv r|| _d S ||| _d S )Nzget_%s)getattr_method
namespaces_nsget_ns_prefix)selftypeskind	namespace r   D/home/ubuntu/webapp/venv/lib/python3.10/site-packages/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'd
eje deje f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deje def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 ur|n|  | _t|tr || _n
t|| j| jd| _|| _|d ur3|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   
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*   r+   c                 C   8   | j jsdS | |}| ||}t| |jfi |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+   r0   portr   r   r   r/   m   
   
zClient.bindc              	   C   sH   z| j j| }W n ty   tdd| j j  w 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   binding_namer;   r6   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   r0   operation_nameargskwargsenvelope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      | 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   rN         zClient.get_typec                 C   rM   )z\Return the element for the given qualified name.

        :rtype: zeep.xsd.Element

        )r#   r   get_elementrO   r   r   r   rR      rQ   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   rS      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   s6   |r|j |}|std|S t|j  d }|S )NzPort not foundr   )portsgetr    listvalues)r   r0   rP   r9   r   r   r   r5      s   zClient._get_portrP   returnc                 C   s<   |r| j j|}|std|S tt| j j d }|S )NzService not found)r#   r3   rX   r    nextiterrZ   )r   rP   r0   r   r   r   r4      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 d S )Nclose)hasattrr!   r_   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   r0   Optionalstrr/   rA   rJ   rL   rN   rR   rS   rV   r5   r4   r^   re   r   r   r   r   r   &   s@   
 



		r   c                   @   sH   e Zd ZeZ		ddeje deje fddZdd Z	ddd	d
Z
dS )AsyncClientNr*   r+   c                 C   r1   r2   )r#   r3   r4   r5   r   r6   r7   r8   r   r   r   r/      r:   zAsyncClient.bindc                    s   | S r,   r   r.   r   r   r   
__aenter__   s   zAsyncClient.__aenter__r[   c                    s   | j  I d H  d S r,   )r!   aclosera   r   r   r   	__aexit__   s   zAsyncClient.__aexit__rf   rg   )r[   N)r   r   r   r   r   ri   rm   rn   r/   rp   rr   r   r   r   r   ro      s    
ro   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                    s<   ddl m} |dpt| d|d< t j|i | d S )Nr   )SqliteCacher!   )cache)
zeep.cachert   rX   r   superr   )r   rF   rG   rt   	__class__r   r   r     s   zCachingClient.__init__)r   r   r   rh   r   __classcell__r   r   rx   r   rs      s    rs   )loggingri   
zeep.proxyr   r   zeep.settingsr   zeep.transportsr   r   	zeep.wsdlr   	getLoggerr   loggerr   r   ro   rs   r   r   r   r   <module>   s    
 <