
    af(                         d dl mZ d dlmZ 	 d dlmZ n$# e$ r 	 d dlmZ n# e$ r	 d dl	mZ Y nw xY wY nw xY wd dlm
Z
mZ d dlmZ dZ G d d	e          Z ee
           G d
 de                      ZdS )    )implementer)ProtocolWrappernotFound)
NoResource)	IResourceResource)NOT_DONE_YET)WebSocketResourceWSGIRootResourcec                       e Zd ZdZd Zd ZdS )r   a  
    Root resource when you want a WSGI resource be the default serving
    resource for a Twisted Web site, but have subpaths served by
    different resources.

    This is a hack needed since
    `twisted.web.wsgi.WSGIResource <http://twistedmatrix.com/documents/current/api/twisted.web.wsgi.WSGIResource.html>`_.
    does not provide a ``putChild()`` method.

    .. seealso::

       * `Autobahn Twisted Web WSGI example <https://github.com/crossbario/autobahn-python/tree/master/examples/twisted/websocket/echo_wsgi>`_
       * `Original hack <http://blog.vrplumber.com/index.php?/archives/2426-Making-your-Twisted-resources-a-url-sub-tree-of-your-WSGI-resource....html>`_
    c                 J    t          j        |            || _        || _        dS )a}  

        :param wsgiResource: The WSGI to serve as root resource.
        :type wsgiResource: Instance of `twisted.web.wsgi.WSGIResource <http://twistedmatrix.com/documents/current/api/twisted.web.wsgi.WSGIResource.html>`_.
        :param children: A dictionary with string keys constituting URL subpaths, and Twisted Web resources as values.
        :type children: dict
        N)r	   __init___wsgiResourcechildren)selfwsgiResourcer   s      K/var/www/html/env/lib/python3.11/site-packages/autobahn/twisted/resource.pyr   zWSGIRootResource.__init__F   s(     	$)     c                 x    |j                                          |j                            d|           | j        S )Nr   )prepathpoppostpathinsertr   )r   pathrequests      r   getChildzWSGIRootResource.getChildR   s8    4(((!!r   N)__name__
__module____qualname____doc__r   r    r   r   r   r   6   s<         
! 
! 
!" " " " "r   r   c                   .    e Zd ZdZdZd Zd Zd Zd ZdS )r   z/
    A Twisted Web resource for WebSocket.
    Tc                     || _         dS )z

        :param factory: An instance of :class:`autobahn.twisted.websocket.WebSocketServerFactory`.
        :type factory: obj
        N)_factory)r   factorys     r   r   zWebSocketResource.__init___   s      r   c                 "    t          d          S )zR
        This resource cannot have children, hence this will always fail.
        zNo such child resource.)messager   )r   namer   s      r   getChildWithDefaultz%WebSocketResource.getChildWithDefaulth   s      9::::r   c                     dS )zS
        This resource cannot have children, hence this is always ignored.
        Nr"   )r   r   childs      r   putChildzWebSocketResource.putChildn   s      r   c                 "   |j         j        Xddlm} |                    dd           |                    dd           |j        d|j        fz  }|                    d	          S | j	        
                    |j                                                  }|s|                    d
           dS |j         j        dc}|j         _        t          |t                    r||_        n.t          |j        t                    r||j        _        n||_        |                    |           t!          |d          r|j                                         n$t!          |d          r|                                 |j        dz   |j        z   dz   }|j                                        D ]/}||d         dz   d                    |d                   z   dz   z  }0|dz  }||j                                        z  }|                    |           t6          S )z
        Render the resource. This will takeover the transport underlying
        the request, create a :class:`autobahn.twisted.websocket.WebSocketServerProtocol`
        and let that do any subsequent communication.
        Nr   )protocoli  s   Upgrade requireds   Upgrades	   WebSocket utf8i  r   _networkProducerresumeProducing    s    HTTP/1.1
s   :    ,   s   
)channel	transportautobahn.websocketr/   setResponseCode	setHeader_SERVER_STATUS_TEMPLATE__version__encoder%   buildProtocolgetPeer
isinstancer   wrappedProtocolmakeConnectionhasattrr2   r3   methodurirequestHeadersgetAllRawHeadersjoincontentreaddataReceivedr
   )r   r   r/   htmlr8   datahs          r   renderzWebSocketResource.renders   s)    ?$,333333##C)<=== j,7773r8;O6PPD;;v&&& =..w/@/H/H/J/JKK 	##C(((3 07/H$,	7?, i11 	*(0I%%	*O<< 	*19I..!)I	*** 9011 	(&668888Y 122 	(%%''' ~$w{25II'88:: 	A 	AAAaD5L499QqT??2[@@DD$$&&&d###r   N)	r   r   r    r!   isLeafr   r*   r-   rP   r"   r   r   r   r   X   sf          F     ; ; ;  
C C C C Cr   r   N)zope.interfacer   twisted.protocols.policiesr   twisted.web.pagesr   ImportErrortwisted.web.resourcer   twisted.web.errorr   r	   twisted.web.serverr
   __all__r   objectr   r"   r   r   <module>r[      sd  8 ' & & & & & 6 6 6 6 6 6	=******* = = ==??????? = = =<<<<<<<<=	= 5 4 4 4 4 4 4 4 , + + + + +" " " " "x " " "D Y] ] ] ] ] ] ] ] ] ]s$    6"606066