o
    i                     @   sT   d Z ddlZeeZddlZddlmZ ddlm	Z	 G dd de
Zdd	d
ZdS )z/A Convenience module for wsgi wrapper routines.    N)Application)WsgiApplicationc                   @   s.   e Zd ZdZedd Zd	ddZdd ZdS )
WsgiMountera  Simple mounter object for wsgi callables. Takes a dict where the keys are
    uri fragments and values are :class:`spyne.application.Application`
    instances.

    :param mounts: dict of :class:`spyne.application.Application` instances
    whose keys are url fragments. Use ``''`` or ``'/'`` as key to set the
    default handler. When a default handler is not set, an empty 404 page is
    returned.
    c                 C   s   |dg  g S )Nz404 Not found )esr   r   W/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/util/wsgi_wrapper.pydefault*   s   
zWsgiMounter.defaultNc                 C   sf   i | _ |pi  D ]'\}}t|trt|}nt|s!J d| |}|dv r+|| _q	|| j |< q	d S )Nz%r is not a valid wsgi app.) /)mountsitems
isinstancer   r   callabler	   )selfr   kvappr   r   r   __init__/   s   

zWsgiMounter.__init__c           	      C   s   | dd}dd |dD }d}t|dkr|d }| j || j}|| ju r.|||S | dd}t|dkr>d| }dd||f|d< ddd|dd  f}|dkr_d|d< n||d< |||S )	N	PATH_INFOr
   c                 S   s   g | ]
}t |d kr|qS )r   )len).0ar   r   r   
<listcomp>@   s    z(WsgiMounter.__call__.<locals>.<listcomp>r   r   SCRIPT_NAME   )getsplitr   r   r	   join)	r   environstart_response	path_info	fragmentsscriptr   original_script_namepir   r   r   __call__>   s"   



zWsgiMounter.__call__)N)__name__
__module____qualname____doc__staticmethodr	   r   r&   r   r   r   r   r      s    


r   .0.0.0.0c                 C   s   ddl }ddl}ddlm} ddlm} ddlm} |dkr3tj	
|}td|  |jj|}n| }| D ]\}	}
||||	}td|	|
f  ||
| q8|jj|}|j|||d td	||f  | S )
a  Twisted wrapper for the spyne.server.wsgi.WsgiApplication. Twisted can
    use one thread per request to run services, so code wrapped this way does
    not necessarily have to respect twisted way of doing things.

    :param apps: List of tuples containing (application, url) pairs
    :param port: Port to listen to.
    :param static_dir: The directory that contains static files. Pass `None` if
        you don't want to server static content. Url fragments in the `apps`
        argument take precedence.
    :param interface: The network interface to which the server binds, if not
        specified, it will accept connections on any interface by default.
    r   N)Resource)WSGIResource)reactorz!registering static folder %r on /zregistering %r on /%s)	interfacezlistening on: %s:%d)twisted.web.servertwisted.web.statictwisted.web.resourcer.   twisted.web.wsgir/   twisted.internetr0   ospathabspathlogginginfowebstaticFileputChildserverSite	listenTCPrun)appsport
static_dirr1   twistedr.   r/   r0   rootr   urlresourcesiter   r   r   run_twistedY   s$   rL   )r,   r-   )r*   r:   	getLoggerr'   loggerr7   spyner   spyne.server.wsgir   objectr   rL   r   r   r   r   <module>   s   
: