
    h(                         d dl mZ d dlmZ 	 d dlmZ 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y# e$ r 	 d dlmZ n# e$ r	 d dl	mZ Y nw xY wY Rw xY w)    )implementer)ProtocolWrappernotFound)
NoResource)	IResourceResource)NOT_DONE_YET)WebSocketResourceWSGIRootResourcec                       e Zd ZdZd Zd Zy)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                  |        || _        || _        y)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      U/var/www/Befach/backend/env/lib/python3.12/site-packages/autobahn/twisted/resource.pyr   zWSGIRootResource.__init__F   s!     	$)     c                     |j                   j                          |j                  j                  d|       | j                  S )Nr   )prepathpoppostpathinsertr   )r   pathrequests      r   getChildzWSGIRootResource.getChildR   s4    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y)r   z/
    A Twisted Web resource for WebSocket.
    Tc                     || _         y)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                      y)zS
        This resource cannot have children, hence this is always ignored.
        Nr"   )r   r   childs      r   putChildzWebSocketResource.putChildn   s    r   c                 *   |j                   j                  Vddlm} |j	                  dd       |j                  dd       |j                  d|j                  fz  }|j                  d	      S | j                  j                  |j                  j                               }|s|j	                  d
       y|j                   j                  dc}|j                   _        t        |t              r||_        n3t        |j                  t              r||j                  _        n||_        |j                  |       t!        |d      r|j"                  j%                          nt!        |d      r|j%                          |j&                  dz   |j(                  z   dz   }|j*                  j-                         D ]%  }||d   dz   dj/                  |d         z   dz   z  }' |dz  }||j0                  j3                         z  }|j5                  |       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##C)<= j,733r8;O;O6PPD;;v&& ==..w/@/@/H/H/JK##C( 07/H/H$,	7??, i1(0I%	**O<19I.!)I	* 901&&668Y 12%%' ~~$w{{25II''88:AAaD5L499QqT?2[@@D ;$$&&d#r   N)	r   r   r    r!   isLeafr   r*   r-   rP   r"   r   r   r   r   X   s#     F ;
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[      s   8 ' 6	=* 5 ,"x "D Y] ] ]o  ==? =<=	=s5   A A'AA'A!A' A!!A'&A'