o
    j)                      @   s   d Z ddlZeeZddlmZ ddlmZ ddl	m
Z
 ddlmZ G dd deZG d	d
 d
eZe
eG dd deZe
eG dd deZeZdS )zI
This module contains the :class:`Service` class and its helper objects.
    N)Sequence)EventManager)six)osetc                       (   e Zd ZdZ fddZdd Z  ZS )ServiceBaseMetazAdds event managers.c                    s0   t t| ||| i | _t| | || _d S N)superr   __init__public_methodsr   )_ServiceBaseMeta__get_base_event_handlersevent_manager)selfcls_name	cls_basescls_dict	__class__ M/var/www/html/LicenciasMiG/venv/lib/python3.10/site-packages/spyne/service.pyr
   %   s
   
zServiceBaseMeta.__init__c           	      C   sf   i }|D ],}t |dd }|d u rq|j D ]\}}||t }|D ]}|| q#|||< qq|S )Nr   )getattrhandlersitemsgetr   add)	r   r   r   baseevmgrkvhandlerhr   r   r   __get_base_event_handlers,   s   
z)ServiceBaseMeta.__get_base_event_handlers)__name__
__module____qualname____doc__r
   r   __classcell__r   r   r   r   r   "   s    r   c                       r   )ServiceMetaz^Creates the :class:`spyne.MethodDescriptor` objects by iterating over
    tagged methods.
    c              	      s   t t| ||| | jd u| _d }| D ]Q\}}t|ds q||| d}t| |t|j	 |
t| | z|t| |_W n	 tyH   Y nw || j|< |jd u r[| jd u r[d}nd| _| jrg|rgtdqd S )N_is_rpc)_default_function_name_service_classTzKYou can't mix primary and auxiliary methods in a single service definition.)r	   r'   r
   __aux___ServiceMeta__has_aux_methodsr   hasattrsetattrstaticmethodfunctionreset_functionr   
descriptorAttributeErrorr   aux	Exception)r   r   r   r   has_nonaux_methodsr   r   r2   r   r   r   r
   A   s,   


zServiceMeta.__init__c                 C      | j S r   )r,   )r   r   r   r   is_auxiliaryb   s   zServiceMeta.is_auxiliary)r"   r#   r$   r%   r
   r8   r&   r   r   r   r   r'   <   s    !r'   c                   @   s   e Zd ZdZ	 dZ	 dZ	 dZ	 dZ	 dZ	 e	dd Z
e	dd Ze	dd Ze	d	d
 Ze	dd Ze	dd Ze	dd Ze	dddZe	dd ZdS )ServiceBaseBaseNr   c                 C   r7   r   )r"   clsr   r   r   get_service_class_name      z&ServiceBaseBase.get_service_class_namec                 C      | j d u r| jS | j S r   )__service_name__r"   r:   r   r   r   get_service_name      
z ServiceBaseBase.get_service_namec                 C   r>   r   )__service_module__r#   r:   r   r   r   get_service_module   rA   z"ServiceBaseBase.get_service_modulec                 C   s   d|   |  f S )Nz%s.%s)rC   r@   r:   r   r   r   get_internal_key   s   z ServiceBaseBase.get_internal_keyc                 C   r7   r   )__port_types__r:   r   r   r   get_port_types   r=   zServiceBaseBase.get_port_typesc                 C   s    | j  D ]}|jr dS qdS )zBDetermines if this service definition has callback methods or not.TF)r   valuesis_callback)r;   methodr   r   r   _has_callbacks   s
   zServiceBaseBase._has_callbacksc                 C   s   dS )zsReturns a user defined context. Override this in your ServiceBase
        subclass to customize context generation.Nr   r:   r   r   r   get_context   s   zServiceBaseBase.get_contextc                 C   s^   |j dur-|du r(|j}t|tjrJ t|tst|}|jjs(|ft| }|j | S dS )zCalled in place of the original method call. You can override this to
        do your own exception handling.

        :param ctx: The method context.

        The overriding function must call this function by convention.
        N)	r0   	in_object
isinstancer   string_typesr   tupler2   no_ctx)r;   ctxargsr   r   r   call_wrapper   s   



zServiceBaseBase.call_wrapperc                 C   s   d S r   r   )r;   appr   r   r   
initialize   s   zServiceBaseBase.initializer   )r"   r#   r$   __in_header____out_header__r?   rB   rE   r+   classmethodr<   r@   rC   rD   rF   rJ   rK   rS   rU   r   r   r   r   r9   g   s>    





	
r9   c                   @   s   e Zd ZdZdS )ServiceaB  The ``Service`` class is the base class for all service definitions.

    The convention is to have public methods defined under a subclass of this
    class along with common properties of public methods like header classes or
    auxiliary processors. The :func:`spyne.decorator.srpc` decorator or its
    wrappers should be used to flag public methods.

    This class is designed to be subclassed just once. You're supposed to
    combine Service subclasses in order to get the public method mix you
    want.

    It is a natural abstract base class, because it's of no use without any
    method definitions, hence the 'Base' suffix in the name.

    This class supports the following events:
        * ``method_call``
            Called right before the service method is executed

        * ``method_return_object``
            Called right after the service method is executed

        * ``method_exception_object``
            Called when an exception occurred in a service method, before the
            exception is serialized.

        * ``method_accept_document``
            Called by the transport right after the incoming stream is parsed to
            the incoming protocol's document type.

        * ``method_return_document``
            Called by the transport right after the outgoing object is
            serialized to the outgoing protocol's document type.

        * ``method_exception_document``
            Called by the transport right before the outgoing exception object
            is serialized to the outgoing protocol's document type.

        * ``method_return_string``
            Called by the transport right before passing the return string to
            the client.

        * ``method_exception_string``
            Called by the transport right before passing the exception string to
            the client.
    N)r"   r#   r$   r%   r   r   r   r   rY      s    rY   )r%   logging	getLoggerr"   logger$spyne.util.six.moves.collections_abcr   spyne.evmgrr   
spyne.utilr   spyne.util.osetr   typer   r'   add_metaclassobjectr9   rY   ServiceBaser   r   r   r   <module>   s   
+a1