B
    EDb                 @   s\   d dl 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G d
d deZdS )    Nc               @   s   e Zd ZdZdd Zedd Zedd Zedd	 Zed
d Z	dd Z
dddZdddZd ddZdd Zdd Zd!ddZdd ZdS )"BaseInterfacea*  All interface implementations must descend from BaseInterface. The interface
	implementation can be thought of as an aggregator that ties the three basic functions
	of a web service protocol together:
	
		1. ServiceDescriptor - A generator class that can provide a description for the service.
		   ie. WSDL for soap.
		2. BaseRequestHandler - A handler that can parse the raw request objects from the client and
		   convert them into a so-called req_dict (Request dictionary)
		3. BaseResponseHandler - A handler that can process the res_dict (Result Dictionary) of a
		   service call and build a response object that fit's the protocol being implemented.
		4. BaseFaultHandler - A handler that can convert a ladon.exceptions.service.ServiceFault object
		   to a fault response that fits the interface.
	
	c             K   s   || _ t }d|kr4|d }t|tr4| | _d|kr\|d }t|tr\| | _d|kr|d }t|tr| | _	d|kr|d }t|t
r| | _d S )NZservice_descriptorZrequest_handlerZresponse_handlerfault_handler)_sinfoServiceDescriptorinspectZgetmrocount_service_descriptorBaseRequestHandler_request_handlerBaseResponseHandler_response_handlerBaseFaultHandler_fault_handler)selfsinfokwZsdZreq_handlerZresp_handlerr    r   5G:\easytimepro\master/mysite/ladon\interfaces\base.py__init__   s$    zBaseInterface.__init__c             C   s   d S )Nr   )typr   r   r   _interface_name(   s    zBaseInterface._interface_namec             C   s   dS )NFr   )r   r   r   r   _accept_basetype,   s    zBaseInterface._accept_basetypec               C   s   dS )NFr   r   r   r   r   _accept_list0   s    zBaseInterface._accept_listc               C   s   dS )NFr   r   r   r   r   _accept_dict4   s    zBaseInterface._accept_dictc             C   s   | j S )N)r   )r   r   r   r   service_info8   s    zBaseInterface.service_infoUTF-8c             C   s   | j || j|S )N)r
   parse_requestr   )r   Z	soap_bodyencodingr   r   r   r   ;   s    zBaseInterface.parse_requestc             C   s   | j || j|S )N)r   build_responser   )r   Zres_dictr   r   r   r   r   >   s    zBaseInterface.build_responseNc             C   s   | j || j|||S )N)r   build_fault_responser   )r   exc
methodnamer   Z
reflectionr   r   r   r   A   s    z"BaseInterface.build_fault_responsec             C   s   | j jS )N)r   _stringify_res_dict)r   r   r   r   stringify_res_dictD   s    z BaseInterface.stringify_res_dictc             C   s   | j jS )N)r   _content_type)r   r   r   r   response_content_typeG   s    z#BaseInterface.response_content_typec             C   s(   | j | jj| jj| jj| j ||S )N)r   generater   servicenameservicenumbertypemanagerZmethod_list)r   Zservice_urlr   r   r   r   descriptionJ   s    zBaseInterface.descriptionc             C   s   | j jS )N)r   r$   )r   r   r   r   description_content_typeR   s    z&BaseInterface.description_content_type)r   )r   )Nr   N)r   )__name__
__module____qualname____doc__r   staticmethodr   r   r   r   r   r   r   r   r#   r%   r*   r+   r   r   r   r   r      s   



r   c               @   s   e Zd ZdZdd ZdS )r   z
text/plainc             C   s   dS )aU  
		Implement the method that can generate a service description file for the
		type of interface you are developing. Thus if you were developing a new
		and better SOAP interface and a new and better service descriptor for it,
		you will be implementing a WSDL generator in this method.
		
		@param servicename This is a string containing the service class name
		@param servicenumber An integer that reflects the order in which the service classes are parsed (useful for creating namespaces)
		@param typemanager An instance of ladon.ladonizer.collection.TypeManager which manages the types used by the service
		@param methodlist The list of methods exposed by the service
		@param encoding The client-side controlled encoding to use in the descriptor
		
		@rtype String representation of the service descriptor (ie. wsdl-formatted if it were SOAP)
		 r   )r   r'   r(   r)   Z
methodlistr   r   r   r   r&   Y   s    zServiceDescriptor.generateN)r,   r-   r.   r$   r&   r   r   r   r   r   U   s   r   c               @   s   e Zd Zdd ZdS )r	   c             C   s   i S )Nr   )r   Zreqr   r   r   r   r   r   m   s    z BaseRequestHandler.parse_requestN)r,   r-   r.   r   r   r   r   r   r	   k   s   r	   c               @   s    e Zd ZdZdZdZdd ZdS )r   a0  
	This is the base class of all response handlers. To implement a new response handler
	inherit it and overload the build_response() method so it implements the protocol you are
	extending Ladon with.
	
	set _stringify_res_dict to True if you want the Ladon dispatcher to convert all result
	values to unicode regardless of their defined types during ladonization. This can be useful
	in some interfaces. ie. SOAP where all values are presented the same way inside XML tags no
	matter if it is a string or a number (example: <name>string</name><age>37</age>)
	z
text/plainFc             C   s   dS )Nr1   r   )r   Zmethod_resultr   r   r   r   r   r      s    z"BaseResponseHandler.build_responseN)r,   r-   r.   r/   r$   r"   r   r   r   r   r   r   q   s   r   c               @   s    e Zd ZdZdZdZdd ZdS )r   a0  
	This is the base class of all fault handlers. To implement a new fault handler
	inherit it and overload the build_fault_response() method so it implements the
	protocol you are extending Ladon with.
	
	set _stringify_res_dict to True if you want the Ladon dispatcher to convert all result
	values to unicode regardless of their defined types during ladonization. This can be useful
	in some interfaces. ie. SOAP where all values are presented the same way inside XML tags no
	matter if it is a string or a number (example: <name>string</name><age>37</age>)
	z
text/plainFc             C   s   dS )Nr1   r   )r   r    r   r!   r   r   r   r   r      s    z%BaseFaultHandler.build_fault_responseN)r,   r-   r.   r/   r$   r"   r   r   r   r   r   r      s   r   )r   objectr   r   r	   r   r   r   r   r   r   <module>   s
   P