
    8'h(                         d dl mZ 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 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 Y Ew xY w)    )absolute_import)implementer)ProtocolWrapper
NoResource)	IResourceResource)PY3)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/html/trade_iq/venv/lib/python3.12/site-packages/autobahn/twisted/resource.pyr   zWSGIRootResource.__init__D   s!     	$)     c                     |j                   j                          |j                  j                  d|       | j                  S )Nr   )prepathpoppostpathinsertr   )r   pathrequests      r   getChildzWSGIRootResource.getChildP   s4    4(!!!r   N)__name__
__module____qualname____doc__r   r    r   r   r   r   4   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.r   )r   namer   s      r   getChildWithDefaultz%WebSocketResource.getChildWithDefaultf   s     344r   c                      y)zS
        This resource cannot have children, hence this is always ignored.
        Nr#   )r   r   childs      r   putChildzWebSocketResource.putChildl   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||_        n||_        |j                  |       t!        |d      r|j"                  j%                          nt!        |d      r|j%                          t&        r|j(                  dz   |j*                  z   dz   }|j,                  j/                         D ]%  }||d   dz   dj1                  |d         z   dz   z  }' |dz  }||j2                  j5                         z  }n`|j(                  d|j*                  d}|j,                  j/                         D ]"  }||d   ddj1                  |d         dz  }$ |dz  }|j7                  |       t8        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   
 z HTTP/1.1
z: ,z
)channel	transportautobahn.websocketr/   setResponseCode	setHeader_SERVER_STATUS_TEMPLATE__version__encoder&   buildProtocolgetPeer
isinstancer   wrappedProtocolmakeConnectionhasattrr2   r3   r
   methodurirequestHeadersgetAllRawHeadersjoincontentreaddataReceivedr   )r   r   r/   htmlr:   datahs          r   renderzWebSocketResource.renderq   s    ??$$,3##C)<= j,733r8;O;O6PPD;;v&& ==..w/@/@/H/H/JK##C( 07/H/H$,	7??, i1(0I%!)I	* 901&&668Y 12%%' >>D(7;;69MMD++<<> E!utyy16DDEKDGOO((**D 07~~w{{KD++<<> BAaD#((1Q4.AABJDd#r   N)	r   r    r!   r"   isLeafr   r*   r-   rR   r#   r   r   r   r   V   s#     F 5
Hr   r   N)
__future__r   zope.interfacer   twisted.protocols.policiesr   twisted.web.errorr   ImportErrortwisted.web.resourcer   r	   sixr
   twisted.web.serverr   __all__r   objectr   r#   r   r   <module>r^      sq   8 ' & 60, 5  ,"x "D Yb b bg  0/0s   A A A 