U
    H4fn#                     @   s   d Z 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	 ej
rPddlmZ ndZeddd	gZG d
d dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZdS )aD  
    zeep.wsdl.definitions
    ~~~~~~~~~~~~~~~~~~~~~

    A WSDL document exists out of a number of definitions. There are 6 major
    definitions, these are:

     - types
     - message
     - portType
     - binding
     - port
     - service

    This module defines the definitions which occur within a WSDL document,

    N)OrderedDict
namedtuple)etree)IncompleteOperation)
DefinitionMessagePartelementtypec                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )AbstractMessagea  Messages consist of one or more logical parts.

    Each part is associated with a type from some type system using a
    message-typing attribute. The set of message-typing attributes is
    extensible. WSDL defines several such message-typing attributes for use
    with XSD:

        - element: Refers to an XSD element using a QName.
        - type: Refers to an XSD simpleType or complexType using a QName.

    c                 C   s   || _ t | _d S N)namer   partsselfr    r   9/tmp/pip-unpacked-wheel-04z2hmy8/zeep/wsdl/definitions.py__init__/   s    zAbstractMessage.__init__c                 C   s   d| j j| jjf S Nz<%s(name=%r)>	__class____name__r   textr   r   r   r   __repr__3   s    zAbstractMessage.__repr__c                 C   s   d S r   r   r   definitionsr   r   r   resolve6   s    zAbstractMessage.resolvec                 C   s   || j |< d S r   )r   )r   r   r   r   r   r   add_part9   s    zAbstractMessage.add_partN)r   
__module____qualname____doc__r   r   r   r   r   r   r   r   r
   "   s
   r
   c                   @   s   e Zd ZdZdddZdS )AbstractOperationz@Abstract operations are defined in the wsdl's portType elements.Nc                 C   s(   || _ || _|| _|| _|| _|| _dS )a  Initialize the abstract operation.

        :param name: The name of the operation
        :type name: str
        :param input_message: Message to generate the request XML
        :type input_message: AbstractMessage
        :param output_message: Message to process the response XML
        :type output_message: AbstractMessage
        :param fault_messages: Dict of messages to handle faults
        :type fault_messages: dict of str: AbstractMessage

        N)r   input_messageoutput_messagefault_messagesparameter_order
wsa_action)r   r   r"   r#   r$   r%   r&   r   r   r   r   @   s    zAbstractOperation.__init__)NNNNN)r   r   r   r    r   r   r   r   r   r!   =   s        r!   c                   @   s8   e Zd Zejejeef dddZ	dd Z
dd ZdS )	PortTyper   
operationsc                 C   s   || _ || _d S r   r(   )r   r   r)   r   r   r   r   ^   s    zPortType.__init__c                 C   s   d| j j| jjf S r   r   r   r   r   r   r   d   s    zPortType.__repr__c                 C   s   d S r   r   r   r   r   r   r   g   s    zPortType.resolveN)r   r   r   r   QNametypingDictstrr!   r   r   r   r   r   r   r   r'   ]   s
    r'   c                   @   sh   e Zd ZdZdd ZeddddZdd	 Zd
d Zdd Z	dd Z
dd Zedd Zedd ZdS )Bindinga  Base class for the various bindings (SoapBinding / HttpBinding)

    .. raw:: ascii

        Binding
           |
           +-> Operation
                   |
                   +-> ConcreteMessage
                             |
                             +-> AbstractMessage

    c                 C   s"   || _ || _d| _|| _i | _dS )zBinding

        :param wsdl:
        :type wsdl:
        :param name:
        :type name: string
        :param port_name:
        :type port_name: string

        N)r   	port_name	port_typewsdl_operations)r   r1   r   r/   r   r   r   r   z   s
    zBinding.__init__N)r   returnc                 C   sv   | d| jj| _t| j D ]P\}}z|| W q  tk
rn } zt	
t| | j|= W 5 d }~X Y q X q d S )NZ
port_types)getr/   r   r0   listr2   itemsr   r   warningswarnr-   )r   r   r   	operationexcr   r   r   r      s    zBinding.resolvec                 C   s   || j |j< d S r   )r2   r   )r   r9   r   r   r   _operation_add   s    zBinding._operation_addc                 C   s   d| j j| jjf S )Nz%s: %sr   r   r   r   r   __str__   s    zBinding.__str__c                 C   s   d| j j| jj| jf S )Nz<%s(name=%r, port_type=%r)>)r   r   r   r   r0   r   r   r   r   r      s
    zBinding.__repr__c                 C   s   | j S r   )r2   r   r   r   r   all   s    zBinding.allc                 C   s8   z| j | W S  tk
r2   td|| jf Y nX d S )NzNo such operation %r on %s)r2   KeyError
ValueErrorr   )r   keyr   r   r   r4      s    zBinding.getc                 C   s
   t  d S r   NotImplementedError)clsnoder   r   r   match   s    zBinding.matchc                 C   s
   t  d S r   rA   )rC   r   
xmlelementr   r   r   parse   s    zBinding.parse)r   r   r   r    r   r   r   r;   r<   r   r=   r4   classmethodrE   rG   r   r   r   r   r.   k   s   

r.   c                   @   sL   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	e
dd ZdS )	OperationzJConcrete operation

    Contains references to the concrete messages

    c                 C   s.   || _ || _d | _d | _d | _d | _i | _d S r   )r   bindingabstractstyleinputoutputZfaults)r   r   rJ   r   r   r   r      s    zOperation.__init__c                 C   sJ   z| j jj| j | _W n. tk
rD   td| j| j jjjf Y nX d S )Nz;The wsdl:operation %r was not found in the wsdl:portType %r)rJ   r0   r)   r   rK   r>   r   r   r   r   r   r   r      s    zOperation.resolvec                 C   s   d| j j| j| jf S )Nz<%s(name=%r, style=%r)>)r   r   r   rL   r   r   r   r   r      s
    zOperation.__repr__c                 C   sD   | j sd| j S d| j| j  f }| jr@|d| jjdd 7 }|S )Nz%s(missing input message)z%s(%s)z -> %sT)Z	as_output)rM   r   	signaturerN   )r   retvalr   r   r   r<      s    
zOperation.__str__c                 O   s   | j d k	st| j j||S r   )rM   AssertionError	serialize)r   argskwargsr   r   r   create   s    zOperation.createc                 C   s
   t  d S r   rA   )r   Zenveloper   r   r   process_reply   s    zOperation.process_replyc                 C   s
   t  dS )a'  

        Definition::

            <wsdl:operation name="nmtoken"> *
               <-- extensibility element (2) --> *
               <wsdl:input name="nmtoken"? > ?
                   <-- extensibility element (3) -->
               </wsdl:input>
               <wsdl:output name="nmtoken"? > ?
                   <-- extensibility element (4) --> *
               </wsdl:output>
               <wsdl:fault name="nmtoken"> *
                   <-- extensibility element (5) --> *
               </wsdl:fault>
            </wsdl:operation>

        NrA   )rC   r1   rF   rJ   r   r   r   rG      s    zOperation.parseN)r   r   r   r    r   r   r   r<   rU   rV   rH   rG   r   r   r   r   rI      s   			rI   c                   @   s:   e Zd ZdZejrdZdd Zdd Zdd Z	d	d
 Z
dS )Portz\Specifies an address for a binding, thus defining a single communication
    endpoint.

    Nc                 C   s"   || _ ||d| _d | _i | _d S )N)binding_namerF   )r   _resolve_contextrJ   binding_options)r   r   rX   rF   r   r   r   r     s    zPort.__init__c                 C   s   d| j j| j| j| jf S )Nz<%s(name=%r, binding=%r, %r)>)r   r   r   rJ   rZ   r   r   r   r   r     s    zPort.__repr__c                 C   s   d| j | jf S )NzPort: %s (%s))r   rJ   r   r   r   r   r<     s    zPort.__str__c                 C   s   | j d krd S z|d| j d j| _W n tk
r>   Y dS X |jr`| jjjjr`|j	d}nd}| j
| j d || _d | _ dS )NbindingsrX   FhttpsrF   T)rY   r4   r   rJ   
IndexErrorlocationr1   settingsforce_https
startswithZprocess_service_portrZ   )r   r   r`   r   r   r   r     s$    
 

 zPort.resolve)r   r   r   r    r+   TYPE_CHECKINGrY   r   r   r<   r   r   r   r   r   rW      s   rW   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zed
dddZ	d
S )Servicez)Used to aggregate a set of related ports.c                 C   s   t  | _|| _d| _d S )NF)r   portsr   _is_resolvedr   r   r   r   r   2  s    zService.__init__c                 C   s
   d| j  S )NzService: %s)r   r   r   r   r   r<   7  s    zService.__str__c                 C   s   d| j j| j| jf S )Nz<%s(name=%r, ports=%r)>)r   r   r   rd   r   r   r   r   r   :  s
    zService.__repr__c                 C   sV   | j r
d S g }| j D ] \}}||}|s|| q|D ]}| j|= q>d| _ d S )NT)re   rd   r6   r   append)r   r   Z
unresolvedr   portZis_resolvedr   r   r   r   A  s    

zService.resolveN)rg   r3   c                 C   s   || j |j< d S r   )rd   r   )r   rg   r   r   r   add_portQ  s    zService.add_port)
r   r   r   r    r   r<   r   r   rW   rh   r   r   r   r   rc   /  s   rc   )r    r+   r7   collectionsr   r   lxmlr   Zzeep.exceptionsr   rb   Zzeep.wsdl.wsdlr   r   r
   r!   r'   r.   rI   rW   rc   r   r   r   r   <module>   s     JG3