o
    iT                     @   s   d dl Z e eZd dlmZmZ d dlZd dlm	Z	m
Z
 d dlmZ d dlmZmZmZmZ d dlmZ d dlmZ G dd	 d	eZG d
d deZG dd deZG dd deZdS )    N)dequedefaultdict)EventManagerMethodDescriptor)six)	ModelBaseArrayIterableComplexModelBase)XmlModifier)xmlc                   @   s    e Zd Zdd Zedd ZdS )InterfaceDocumentsBasec                 C   s   || _ || _d S N)	interfacewsdl11)selfr   r    r   U/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/interface/_base.py__init__#   s   
zInterfaceDocumentsBase.__init__c                 C   s"   ddl m} t| j|sJ | jS )Nr   )	XmlSchema)spyne.interfacer   
isinstancer   )r   r   r   r   r   
xml_schema)   s   z!InterfaceDocumentsBase.xml_schemaN)__name__
__module____qualname__r   propertyr   r   r   r   r   r   "   s    r   c                       s   e Zd Z fddZ  ZS )InterfaceDocumentsc                    s:   t t| j|d d tjjrddlm} ||| _d S d S )N)r   r   )Wsdl11)	superr   r   spyner   HAS_WSDLspyne.interface.wsdlr   r   )r   r   r   	__class__r   r   r   1   s   zInterfaceDocuments.__init__)r   r   r   r   __classcell__r   r   r#   r   r   0   s    r   c                   @   s   e Zd ZdZddefddZedd Zejdd Zd	d
 Z	dd Z
ee
e	Ze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d  Zd*d!d"ZeeZd#d$ Zd+d&d'Zd(d) ZdS ),	InterfacezThe ``Interface`` class holds all information needed to build an
    interface document.

    :param app: A :class:`spyne.application.Application` instance.
    NFc                 C   sh   d| _ d | _d | _i | _i | _i | _i | _i | _i | _t	 | _
i | _tt| _|| _|| _|| | _d S )Nr   )_Interface__ns_counter_Interface__appurlclassesimportsservice_method_mapmethod_id_mapnsmapprefmapr   member_methodsmethod_descriptor_id_to_keyr   dictservice_attrsimport_base_namespacesappdocs)r   r5   r4   documents_containerr   r   r   r   A   s   
zInterface.__init__c                 C      | j S r   r6   r   r   r   r   	documentsV   s   zInterface.documentsc                 C   s
   || _ d S r   r9   )r   whatr   r   r   r;   Z   s   
c                 C   s,   | j d u s	J d|| _ |   |   d S )NzCOne interface instance can belong to only one application instance.)r(   reset_interfacepopulate_interface)r   valuer   r   r   set_app^   s   zInterface.set_appc                 C   r8   r   )r(   r:   r   r   r   get_appf   s   zInterface.get_appc                 C   s   | j r| j jS g S r   )r(   servicesr:   r   r   r   rB   k   s   zInterface.servicesc                 C   sl   i | _ |  t i| _i | _i | _ttj| _	ttj
| _t | _|  | j	d< d| j|  < tt| _d S )Ntns)r*   get_tnssetr+   r,   r-   r2   	namespaceNSMAPr.   PREFMAPr/   r   r0   r   depsr:   r   r   r   r=   q   s   zInterface.reset_interfacec                 C   s   |  }| }d||f }| j|}|du rdS t|trQt|trQt|ddp+|}t|ddp3|}||u r:dS t||fttt	fkrHdS t
d|||f dS )z^Returns true if the given class is already included in the interface
        object somewhere.{%s}%sNF__orig__Tz.classes %r and %r have conflicting names: '%s')get_namespaceget_type_namer*   get
issubclassr
   getattrrE   r   r	   
ValueError)r   clsnstnkeyco1o2r   r   r   	has_class~   s&   
zInterface.has_classc                 C   s
   | j | S )zReturns the class definition that corresponds to the given key.
        Keys are in '{namespace}class_name' form.

        Not meant to be overridden.
        r*   r   rU   r   r   r   	get_class   s   
zInterface.get_classc                 C   s   | j |  S )zReturns the default class instance that corresponds to the given key.
        Keys are in '{namespace}class_name' form, a.k.a. XML QName format.
        Classes should not enforce arguments to the constructor.

        Not meant to be overridden.
        rZ   r[   r   r   r   get_class_instance   s   zInterface.get_class_instancec                 C      | j r| j jS dS )zReturns service name that is seen in the name attribute of the
        definitions tag.

        Not meant to be overridden.
        N)r5   namer:   r   r   r   get_name   s   zInterface.get_namec                 C   r^   )zReturns default namespace that is seen in the targetNamespace
        attribute of the definitions tag.

        Not meant to be overridden.
        N)r5   rC   r:   r   r   r   rD      s   zInterface.get_tnsc           
      c   sV   |j durBt|j ttfs|j f|_ |j D ]+}|||   |jdu r(|V  | }||  krA| |rA| j	|   
| q|jdurt|jttfsT|jf|_|jD ]+}|||   |jdu ri|V  | }||  kr| |r| j	|   
| qW|jdu rg |_nt|jttfs|jf|_|jD ]}|  |_|||   |jdu r|V  q|j|j|   |j }||  kr| |r| j	|   
|j  |jdu r|jV  |j|j|   |j |jjusJ |j }||  kr| |r| j	|   
| |jdu r|jV  |jD ]}	||	_q"dS )a  Generator method that adds the given method descriptor to the
        interface. Also extracts and yields all the types found in there.

        :param method: A :class:`MethodDescriptor` instance
        :returns: Sequence of :class:`spyne.model.ModelBase` subclasses.
        N)	in_headerr   listtupleresolve_namespacerD   auxrL   is_valid_importr+   add
out_headerfaults__namespace__
in_messageout_messagerM   Emptypatternsendpoint)
r   methodra   in_header_nsrh   out_header_nsfaultin_message_nsout_message_nspr   r   r   
add_method   sr   

















zInterface.add_methodc           
      C   s  t |tsJ d| jj|jf }t|tr0|jddd }| |kr0d| jj| |jf }|	|}|| j
v r| j
| j}|d u rG	 d S ||u rN	 d S |jd u re||ju scJ d|||j|f d S |jd u r||j|u szJ d|j|||f d S |j|ju sJ d|j||j|f d S td||t|j| || j
|< | j|d }|d u rg  }| j|< t|dkr|| d S |jd ur|| d S |d jd ur||d d S |d }|j}	|	d u r|j}	td|j|j|j|	j|	jf )	NrJ   .   r   z	{%s}%s.%sz%r.%s conflicts with %r.%sz&  adding method %s.%s to match %r tag.z3
The message %r defined in both '%s.%s' and '%s.%s')r   r   r5   rC   r_   rO   r
   splitrM   gen_interface_keyr-   parent_classrK   loggerdebugget_owner_namer   get_function_namefunctionr,   rN   lenappendre   insertservice_classrQ   r   r   )
r   srp   
method_keymethod_object_namerU   rV   valomosr   r   r   process_method  sl   






zInterface.process_methodc                 C   s   dS )zYOverride this if you need to cherry-pick methods added to the
        interface document.Tr   )r   rp   r   r   r   check_method>  s   zInterface.check_methodc                 C   s  | j D ]]}td|  |j D ]M}|jdu r|j|_|jdu r&|j	|_|j
du r/|j|_
|j
dur>|j
j|| | |sKtd|j qtd|j | |D ]}| | qWqq| jjD ]}| | qe| j D ]"}|  | j| d< td|j|j |j D ]}| || qqp| jD ]=\}}d}|jdur|| j}td||j |r|j}|dur|jdu r|j|_|jdu r|j	|_| |jp|| qtd	d
 | j ! D | _"td dS )zHarvests the information stored in individual classes' _type_info
        dictionaries. It starts from function definitions and includes only
        the used objects.
        zpopulating %s types...Nz$method %s' discarded by check_methodz%  enumerating classes for method '%s'rC   zpopulating '%s.%s' routes...Tz7static_when returned %r for %s while populating methodsc                 s   s$    | ]\}}t |d  |fV  qdS )r   N)id).0kvr   r   r   	<genexpr>  s    z/Interface.populate_interface.<locals>.<genexpr>zvFrom this point on, you're not supposed to make any changes to the class and method structure of the exposed services.)#rB   r}   r~   get_internal_keypublic_methodsvaluesra   __in_header__rh   __out_header__re   __aux__methodsr   r{   r   	class_keyrw   	add_classr5   r*   rD   r3   r   r   r   r0   static_wheninternal_keyr   rK   r2   r,   itemsr1   )r   typesr   rp   rR   rV   	should_wer   r   r   r>   D  sj   











zInterface.populate_interfacec                 C   s   t |tst |tjst||| jvrBd| j }|| jv r/|  jd7  _d| j }|| jv s|| j|< || j|< |  jd7  _|S | j| }|S )zReturns the namespace prefix for the given namespace. Creates a new
        one automatically if it doesn't exist.

        Not meant to be overridden.
        zs%dry   )r   strr   	text_type	TypeErrorr/   r'   r.   )r   rS   prefr   r   r   get_namespace_prefix  s   







zInterface.get_namespace_prefixTc              	   C   sL  |  |rd S | }| }|d usJ d|| jvr'| |r't | j|< d||f }tdt|| || j	vsGJ d| j	| ||f | |j
usRJ || j|  || j	|< ||  krg|| j	|< t|dd }|d ur| tj
u rt|dd }|d ur| tj
u sx|r|d urt|tsJ | j| | | | | }||kr|| j| vr| |r| j| | td||| |  t|tr |j D ]\}}	|	d u rq| j| |	 td| ||	 |	 d u r|	|	| | |	 |	 d u r| d ur|	|	|  |	 }
|
|krD|
| j| vrD| |
rD| j| |
 td|
|| ||	 t|	tr}| |	j |	j }
|
|kr}|
| j| vr}| |
r}| j| |
 td|
||	 ||	j q|jjd urtd	| |  |jj D ]<\}}t||sJ d
}|jd ur|| j}td||j |r| j||f |  |D ]}| | qȐq|jj!d ur"td| |  |jj!D ]:}||| | }
|
|kr|  |s| j|dd | j| | qtd|
|| |  qd S d S d S )Nzceither assign a namespace to the class or call cls.resolve_namespace(cls, "some_default_ns") on it.rJ   z    adding class %r for %rz>Somehow, you're trying to overwrite %r by %r for class key %r.__extends__z,    importing %r to %r because %r extends %rz    adding %s.%s = %rz$    importing %r to %r for %s.%s(%r)z,    populating member methods for '%s.%s'...Tz7static_when returned %r for %s while populating classesz#    adding subclasses of '%s.%s'...F)
add_parentz|    not adding %r to %r because it would cause circular imports because %r extends %r and they don't have the same namespace)"rY   rL   rM   r+   rf   rE   r}   r~   reprr*   rm   rI   rD   rP   r   rO   rg   r   r
   
_type_infor   rd   r   type
Attributesr   hasattrr   r5   r   r0   r   rw   _subclasses)r   rR   r   rS   rT   r   extends	parent_nsr   r   child_nsr   
descriptorr   rV   r   r   r   r     s   








4zInterface.add_classc                 C   s    |du rt || jp|tjvS )zAThis will return False for base namespaces unless told otherwise.N)rQ   r4   rF   rH   )r   rS   r   r   r   rf      s   zInterface.is_valid_importr   )T)r   r   r   __doc__r   r   r   r;   setterr@   rA   r5   rB   r=   rY   r\   r]   r`   rD   rw   r   r   r>   rC   r   r   rf   r   r   r   r   r&   :   s8    




	
	D<
L
tr&   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	InterfaceDocumentBasezBase class for all interface document implementations.

    :param interface: A :class:`spyne.interface.InterfaceBase` instance.
    c                 C   s   || _ t| | _d S r   )r   r   event_manager)r   r   r   r   r   r   /  s   zInterfaceDocumentBase.__init__c                 C      t d)a6  This function is supposed to be called just once, as late as possible
        into the process start. It builds the interface document and caches it
        somewhere. The overriding function should never call the overridden
        function as this may result in the same event firing more than once.
        Extend and override.NotImplementedErrorr:   r   r   r   build_interface_document3  s   z.InterfaceDocumentBase.build_interface_documentc                 C   r   )zThis function is called by server transports that try to satisfy the
        request for the interface document. This should just return a previously
        cached interface document.
        r   r   r:   r   r   r   get_interface_document<  s   z,InterfaceDocumentBase.get_interface_documentN)r   r   r   r   r   r   r   r   r   r   r   r   )  s
    	r   )logging	getLoggerr   r}   collectionsr   r   r   r    r   r   
spyne.utilr   spyne.modelr   r   r	   r
   spyne.model.complexr   spyne.constr   rF   objectr   r   r&   r   r   r   r   r   <module>   s    

   r