HOME


Mini Shell 1.0
DIR: /usr/lib/python3/dist-packages/twisted/web/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/twisted/web/__pycache__/server.cpython-312.pyc
�

Ϫ�f�s��\�dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZddlm
ZddlmZddlmZdd	lmZdd
lmZmZddlmZmZddlmZdd
lmZmZm Z ddl!m"Z"m#Z#ddl$m%Z%ddl&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/ddl0m1Z1dZ2gd�Z3e%edddd�ddd�e%edddd�ddd�e*jhZ5e*jlZ7dZ8d�Z
d�Z9ee+jt�Gd �d!e'e*jvejx��Z;ee+jz�Gd"�d#��Z>ee+j~�Gd$�d%��Z@Gd&�d'�ZAGd(�d)ejx�ZBe#d*ej����ZCeej��Gd+�d,e*j���ZFy)-a�
This is a web server which integrates with the twisted.internet infrastructure.

@var NOT_DONE_YET: A token value which L{twisted.web.resource.IResource.render}
    implementations can return to indicate that the application will later call
    C{.write} and C{.finish} to complete the request, and that the HTTP
    connection should be left open.
@type NOT_DONE_YET: Opaque; do not depend on any particular type for this
    value.
�N)�hexlify)�escape)�List�Optional)�quote)�implementer)�Version)�	copyright)�address�
interfaces)�
AlreadyCalled�AlreadyCancelled)�Logger)�
components�failure�reflect)�nativeString�
networkString)�deprecatedModuleAttribute)�Copyable�	ViewPoint)�http�iweb�resource�util)�UnsupportedMethod)�unquote�)�supportedMethods�Request�Session�Site�version�NOT_DONE_YET�GzipEncoderFactory�Twisted�z4Please use twisted.web.http.datetimeToString insteadztwisted.web.server�date_time_stringz4Please use twisted.web.http.stringToDatetime instead�string_date_time)�GET�HEADsPOSTc�\�t|jd�g|��i|��jd�S)N�charmap)�_quote�decode�encode)�string�args�kwargss   �4/usr/lib/python3/dist-packages/twisted/web/server.pyrrKs+���&�-�-�	�*�<�T�<�V�<�C�C�I�N�N�c���t|tj�rd|j|jfSt|tj
�rd|jfSt|�S)N�INET�UNIX)�
isinstancer�IPv4Address�host�port�UNIXAddress�name�tuple)�addrs r4�_addressToTuplerAOsP���$��+�+�,���	�	�4�9�9�-�-�	�D�'�-�-�	.���	�	�"�"��T�{�r5c�4�eZdZUdZdZeeed<dZdZ	dZ
eeeed<dZeeeed<dZ
dZdZe�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d$d�Z"d�Z#d�Z$dZ%dZ&e'd��Z(d%d�Z)d�Z*d�Z+d �Z,d!�Z-d"�Z.d#�Z/y)&r a�
    An HTTP request.

    @ivar defaultContentType: A L{bytes} giving the default I{Content-Type}
        value to send in responses if no other value is set.  L{None} disables
        the default.

    @ivar _insecureSession: The L{Session} object representing state that will
        be transmitted over plain-text HTTP.

    @ivar _secureSession: The L{Session} object representing the state that
        will be transmitted only over HTTPS.
    �	text/html�defaultContentTypeN�prepath�postpathzunusednames=issuerFc��tjj|g|��i|��tjj|�y�N)rr �__init__r�
Componentized)�selfr2�kws   r4rIzRequest.__init__rs2�������d�0�T�0�R�0�� � �)�)�$�/r5c�d�|jj�}|d=|d=|d=|d=|jjdd�|jj	�|d<t||�|d<t
|d�|d<t
|d	�|d	<t|d
j��|d
<|S)N�	transport�channel�content�siter�content_data�remoter;�client�requestHeaders)	�__dict__�copyrP�seek�readrrA�list�getAllRawHeaders)rK�issuer�xs   r4�getStateToCopyForzRequest.getStateToCopyForvs����M�M��� ��
�k�N�
�i�L�
�i�L�
�f�I������!�Q�� �L�L�-�-�/��.�����-��(��$�A�f�I�.��&�	�%�a��k�2��(��#�1�%5�#6�#G�#G�#I�J��
���r5c�T�|jrt|j�dz|zS|S)z�
        Return the text that links to a sibling of the requested resource.

        @param name: The sibling resource
        @type name: C{bytes}

        @return: A relative URL.
        @rtype: C{bytes}
        �../)rF�len)rKr>s  r4�sibLinkzRequest.sibLink�s)���=�=���
�
�&��/�4�7�7��Kr5c���t|j�}|dkDr|dz
dz|zS|dk(r|St|j�r$|jdr|jddz|zS|S)z�
        Return the text that links to a child of the requested resource.

        @param name: The child resource
        @type name: C{bytes}

        @return: A relative URL.
        @rtype: C{bytes}
        rr`����/)rarFrE)rKr>�lpps   r4�	childLinkzRequest.childLink�sn���$�-�-� ����7��1�W��&�$�.�.�
�A�X��K��4�<�<� �T�\�\�"�%5��|�|�B�'�$�.��5�5��r5c��	|jjj}||�|_y#t$r#t
jj||�YywxYw)a0
        Called when HTTP channel got length of content in this request.

        This method is not intended for users.

        @param length: The length of the request body, as indicated by the
            request headers.  L{None} if the request headers do not indicate a
            length.
        N)rOrQ�getContentFilerP�AttributeErrorrr �	gotLength)rK�lengthris   r4rkzRequest.gotLength�sO��	2�!�\�\�.�.�=�=�N�*�&�1�D�L���	1��L�L�"�"�4��0�	1�s� 0�)A�Ac��|jj|_|jdt�|jdt	j
��g|_ttt|jddjd���|_|jdk(r|j�y	|jj|�}tj j#|�r|j%|�}|�||_|j)|�y#t*$r&|j-t/j0��YywxYw)z�
        Process a request.

        Find the addressed resource in this request's L{Site},
        and call L{self.render()<Request.render()>} with it.

        @see: L{Site.getResourceFor()}
        sserversdaterNre�*)rOrQ�	setHeaderr#r�datetimeToStringrErZ�mapr�path�splitrF�_handleStar�getResourceForr�_IEncodingResource�
providedBy�
getEncoder�_encoder�render�
BaseException�processingFailedr�Failure)rK�resrc�encoders   r4�processzRequest.process�s���L�L�%�%��	�	
���y�'�*����w�� 5� 5� 7�8�����S��$�)�)�A�B�-�*=�*=�d�*C�D�E��
��9�9��������	5��I�I�,�,�T�2�E��*�*�5�5�e�<��*�*�4�0���&�$+�D�M��K�K�����	5��!�!�'�/�/�"3�4�	5�s�8A%D�,E
�E
c��|js�|jtjtjfv}|j
j
d�}|j
j
d�}|xr|ddk(}|r7|�5|j�)|s'|j
jd|jg�|jsH|jr|jj|�}tjj||�yy)z�
        Write data to the transport (if not responding to a HEAD request).

        @param data: A string to write to the response.
        @type data: L{bytes}
        �content-type�content-lengthr�0N)�startedWriting�coder�NOT_MODIFIED�
NO_CONTENT�responseHeaders�
getRawHeadersrD�
setRawHeaders�_inFakeHeadryr0r �write)rK�data�needsCT�contentType�
contentLength�contentLengthZeros      r4r�z
Request.write�s����"�"��i�i��(9�(9�4�?�?�'K�K�G��.�.�<�<�_�M�K� �0�0�>�>�?P�Q�M� -� L�=��3C�t�3K����'��+�+�7�)��$�$�2�2�#�d�&=�&=�%>������}�}��}�}�+�+�D�1���L�L���t�T�*� r5c���|jr<|jj�}|r tjj	||�tjj|�S)zH
        Override C{http.Request.finish} for possible encoding.
        )ry�finishrr r��rKr�s  r4r�zRequest.finishsI���=�=��=�=�'�'�)�D�����"�"�4��.��|�|�"�"�4�(�(r5c
�~�	|j|�}|turyt/|t0�s�t#j$t&j2ddt5j6t9j:|��zdzdzt5j6t9j:|��zdzdzt5j6t9j:|��z�j|�}|jdk(r]t|�dkDr=|jjd||� �|jddt|�fz�|jd
�n0|jddt|�fz�|j|�|j�y#t$�r}|j}|jdk(r�d|vr�|jjd|��d|_d|_|j|�}|tur|jjd|��n|jddt|�fz�d	|_d|_|jd
�|j�Yd}~y|jtvr�|jdd
j|��dtt|j ��t|j�t|�dkDxrdxsddj|D�cgc]
}t|���ncc}wc}�d�z}t#j$t&j(d|�}|j|�}n\t#j$t&j*ddt|jj-d���d��}|j|�}Yd}~���d}~wwxYw)!ah
        Ask a resource to render itself.

        If the resource does not support the requested method,
        generate a C{NOT IMPLEMENTED} or C{NOT ALLOWED} response.

        @param resrc: The resource to render.
        @type resrc: L{twisted.web.resource.IResource}

        @see: L{IResource.render()<twisted.web.resource.IResource.render()>}
        r+r*z,Using GET to fake a HEAD request for {resrc})r~TzBTried to fake a HEAD request for {resrc}, but it got away from me.r��%dFr5N�Allows, zzYour browser approached me (at %(URI)s) with the method "%(method)s".  I only allow the method%(plural)s %(allowed)s here.r�s�z, )�URI�method�plural�allowedzMethod Not AllowedzHuh?zI don't know how to treat a r-z	 request.zRequest did not return bytesz	Request: z<br />z
Resource: zValue: rzbWarning: HEAD request {slf} for resource {resrc} is returning a message body. I think I'll eat it.)�slfr~)rzr�allowedMethodsr��_log�infor�r$rorar�r�r�joinrr�urir�_UnsafeErrorPager�NOT_ALLOWED�NOT_IMPLEMENTEDr/r9�bytes�INTERNAL_SERVER_ERRORr�_PREr�	safe_repr)rKr~�body�er�r]r��epages        r4rzzRequest.rendersF��:	*��<�<��%�D�x�<����$��&��,�,��*�*�.���)�)�G�-�-�d�3�4�5����	�
�)�)�G�-�-�e�4�5�6��
����)�)�G�-�-�d�3�4�5���f�T�l�
��;�;�'�!��4�y�1�}��	�	���F���	�����0�%�3�t�9�,�2F�G��J�J�s�O��N�N�,�e�s�4�y�l�.B�C��J�J�t�����
��u!�8	*��-�-�N����w�&�V�~�-E�
�	�	���B�%���%���#'�� ��|�|�D�)���<�'��I�I�N�N�/�#�#���N�N�#4�e�s�4�y�l�6J�K�#(�� �%����
�
�3�����
���{�{�/�0����x����N�)C�D�B� &�l�4�8�8�&<�=�".�t�{�{�";�$'��$7�!�$;�#D��"K��#'�9�9�~�-V�!�l�1�o�-V��-V�#W�	���!�1�1��$�$�&:�A����|�|�D�)�� �1�1��(�(���d�k�k�0�0��;�<�?����|�|�D�)����q8	*�s,�F�
N<�CN7�2B	N7�;L�
B$N7�7N<c��|jjd|��|jjrdt	j
|�zdz}nd}|j
tj�|jdd�|jdd	t|�fz�|j|�|j�|S)
aO
        Finish this request with an indication that processing failed and
        possibly display a traceback.

        @param reason: Reason this request has failed.
        @type reason: L{twisted.python.failure.Failure}

        @return: The reason passed to this method.
        @rtype: L{twisted.python.failure.Failure}
        r�)rs�<html><head><title>web.Server Traceback (most recent call last)</title></head><body><b>web.Server Traceback (most recent call last):</b>

s

</body></html>
s_<html><head><title>Processing Failed</title></head><body><b>Processing Failed</b></body></html>r�rCr�r�)
r�rrQ�displayTracebacksr�
formatFailure�setResponseCoderr�rorar�r�)rK�reasonr�s   r4r|zRequest.processingFailed�s���	
�	�	���"�f��-��9�9�&�&�5��$�$�V�,�	-�
*�*�
�:�
�	
���T�7�7�8������5����(�%�3�t�9�,�*>�?��
�
�4�����
��
r5c�&�|j|�y)z(Remote version of write; same interface.N)r�)rKr\r�s   r4�
view_writezRequest.view_write�s���
�
�4�r5c�$�|j�y)z)Remote version of finish; same interface.N)r��rKr\s  r4�view_finishzRequest.view_finish�s�����
r5c�,�|j||fi|��y)z,Remote version of addCookie; same interface.N)�	addCookie)rKr\�k�vr3s     r4�view_addCookiezRequest.view_addCookie�s������q�!�&�v�&r5c�(�|j||�y)z,Remote version of setHeader; same interface.N)ro)rKr\r�r�s    r4�view_setHeaderzRequest.view_setHeader�s�����q�!�r5c�&�|j|�y)z2Remote version of setLastModified; same interface.N)�setLastModified)rKr\�whens   r4�view_setLastModifiedzRequest.view_setLastModified�s�����T�"r5c�&�|j|�y)z*Remote version of setETag; same interface.N)�setETag)rKr\�tags   r4�view_setETagzRequest.view_setETag�s�����S�r5c�(�|j||�y)zD
        Remote version of setResponseCode; same interface.
        N)r�)rKr\r��messages    r4�view_setResponseCodezRequest.view_setResponseCode�s��	
���T�7�+r5c�:�|jt|�|�y)zbRemote version of registerProducer; same interface.
        (requires a remote producer.)
        N)�registerProducer�_RemoteProducerWrapper)rKr\�producer�	streamings    r4�view_registerProducerzRequest.view_registerProducer�s��	
���4�X�>�	�Jr5c�$�|j�yrH)�unregisterProducerr�s  r4�view_unregisterProducerzRequest.view_unregisterProducer�s�����!r5c�R�|j�r|jS|jS)a�
        If a session has already been created or looked up with
        L{Request.getSession}, this will return that object.  (This will always
        be the session that matches the security of the request; so if
        C{forceNotSecure} is used on a secure request, this will not return
        that session.)

        @return: the session attribute
        @rtype: L{Session} or L{None}
        )�isSecure�_secureSession�_insecureSession�rKs r4�sessionzRequest.session�s%���=�=�?��&�&�&��(�(�(r5c�&�|j�xr|}|sd}d}nd}d}t||�}|�	|j�|��dj|g|jz�}|j|�}|r	|jj|�}|s9|jj�}|j||jd|��t|||�|r|j|�S|S#ttf$rd}Y��wxYw#t$rY�wxYw)	a
        Check if there is a session cookie, and if not, create it.

        By default, the cookie with be secure for HTTPS requests and not secure
        for HTTP requests.  If for some reason you need access to the insecure
        cookie from a secure request you can set C{forceNotSecure = True}.

        @param forceNotSecure: Should we retrieve a session that will be
            transmitted over HTTP, even if this L{Request} was delivered over
            HTTPS?
        @type forceNotSecure: L{bool}
        sTWISTED_SESSIONr�sTWISTED_SECURE_SESSIONr�N�_re)rr�secure)r��getattr�touchr
rr��sitepath�	getCookierQ�
getSession�KeyError�makeSessionr��uid�setattr�getComponent)	rK�sessionInterface�forceNotSecurer��cookieString�sessionAttributer��
cookiename�
sessionCookies	         r4r�zRequest.getSession�s ������7��%7���-�L�1��4�L�/���$� 0�1����
��
�
��
�?����L�>�D�M�M�#A�B�J� �N�N�:�6�M���"�i�i�2�2�=�A�G���)�)�/�/�1�����z�7�;�;�T�&��Q���&��0���'�'�(8�9�9����/"�#3�4�
���
�� ����s#�C-�5D�-D�D�	D�Dc	�d�|j�j}|j�rd}nd}||k(rd}nd|z}td|j�xrdxsd�dt	|j���|�d��}d	j
|D�cgc]}t|d
����c}�}||zScc}w)Ni��Pr�z:%drr�z://�/rer5)�safe)�getHostr<r�rr�getRequestHostnamer�r)rKrEr<�default�hostport�prefix�segmentrrs        r4�_prePathURLzRequest._prePathURLs����|�|�~�"�"���=�=�?��G��G��7�?��H��t�|�H���
�
��'�C�-�2�-��T�4�4�6�7��	
�
���y�y�'�J�w�%��c�2�J�K����}���Ks�
B-c�8�|j|j�SrH)r�rEr�s r4�
prePathURLzRequest.prePathURL,s��������-�-r5c�D�ddlm}|jj|�S)Nr)�urlpath)�twisted.pythonr��URLPath�fromRequest)rKr�s  r4r�zRequest.URLPath/s��*����*�*�4�0�0r5c�N�|j|jdd�}||_y)z_
        Remember the currently-processed part of the URL for later
        recalling.
        Nrd)r�rE�
appRootURL)rK�urls  r4�rememberRootURLzRequest.rememberRootURL4s&��
���t�|�|�C�R�0�1����r5c��|jS)zn
        Get a previously-remembered URL.

        @return: An absolute URL.
        @rtype: L{bytes}
        )rr�s r4�
getRootURLzRequest.getRootURL<s�����r5c��|jdk(r |jtj�n1|jtj�|jdd�|jdd�|j
�y)a�
        Handle receiving a request whose path is '*'.

        RFC 7231 defines an OPTIONS * request as being something that a client
        can send as a low-effort way to probe server capabilities or readiness.
        Rather than bother the user with this, we simply fast-path it back to
        an empty 200 OK. Any non-OPTIONS verb gets a 405 Method Not Allowed
        telling the client they can only use OPTIONS.
        sOPTIONSr�sContent-Lengthr�N)r�r�r�OKr�ror�r�s r4rtzRequest._handleStarEs^���;�;�*�$�� � ����)�� � ��!1�!1�2��N�N�8�Z�0�	
���(�$�/����
r5rH)NF)0�__name__�
__module__�__qualname__�__doc__rDrr��__annotations__rQrrErrF�
__pychecker__r�ryrr�rIr^rbrgrkr�r�r�rzr|r�r�r�r�r�r�r�r�r�r�r��propertyr�r�r�r�r�rrrt�r5r4r r Xs���+7�����6��D��J�%)�G�X�d�5�k�
"�)�&*�H�h�t�E�{�#�*�(�M��K��H��8�D�0��.
��*2�""5�H$+�L)�h�T!�F��'��#��,�K�"�
�N���
�)��)� 5�n�*.�1�
��r5r c�>�eZdZdZej
d�ZdZd�Zy)r%z~
    @cvar compressLevel: The compression level used by the compressor, default
        to 9 (highest).

    @since: 12.3
    s(:?^|[\s,])gzip(:?$|[\s,])�	c�`�dj|jjdg��}|jj	|�rh|j
jd�}|rdj|dgz�}nd}|j
j
d|g�t|j|�Sy)zo
        Check the headers if the client accepts gzip encoding, and encodes the
        request if so.
        �,saccept-encodingscontent-encodingsgzipN)	r�rUr��_gzipCheckRegex�searchr�r��_GzipEncoder�
compressLevel)rK�request�
acceptHeaders�encodings    r4�encoderForRequestz$GzipEncoderFactory.encoderForRequestgs���
�	�	��"�"�0�0�1C�R�H�
�
����&�&�}�5��.�.�<�<�=P�Q�H���9�9�X��	�%9�:��"���#�#�1�1�2E��z�R��� 2� 2�G�<�<�6r5N)	rrr	r
�re�compilerrrrr5r4r%r%[s$���!�b�j�j�!?�@�O��M�=r5r%c�&�eZdZdZdZd�Zd�Zd�Zy)rz�
    An encoder which supports gzip.

    @ivar _zlibCompressor: The zlib compressor instance used to compress the
        stream.

    @ivar _request: A reference to the originating request.

    @since: 12.3
    Nc��tj|tjdtjz�|_||_y)N�)�zlib�compressobj�DEFLATED�	MAX_WBITS�_zlibCompressor�_request)rKrrs   r4rIz_GzipEncoder.__init__�s2��#�/�/��4�=�=�"�t�~�~�*=� 
��� ��
r5c��|jjs%|jjjd�|jj|�S)zR
        Write to the request, automatically compressing data on the fly.
        r�)r%r�r��removeHeaderr$�compressr�s  r4r0z_GzipEncoder.encode�sC���}�}�+�+�
�M�M�)�)�6�6�7H�I��#�#�,�,�T�2�2r5c�H�|jj�}d|_|S)zf
        Finish handling the request request, flushing any data from the zlib
        buffer.
        N)r$�flush)rK�remains  r4r�z_GzipEncoder.finish�s%��
�%�%�+�+�-��#����
r5)rrr	r
r$rIr0r�rr5r4rrzs��	��O� �3�r5rc��eZdZd�Zy)r�c��|jd�|_|jd�|_|jd�|_y)N�resumeProducing�pauseProducing�
stopProducing)�remoteMethodr.r/r0)rKrSs  r4rIz_RemoteProducerWrapper.__init__�s=��%�2�2�3D�E���$�1�1�2B�C���#�0�0��A��r5N)rrr	rIrr5r4r�r��s��Br5r�c�D��eZdZdZdZdZd	�fd�	Zd�Zd�Zd�Z	d�Z
�xZS)
r!a�
    A user's session with a system.

    This utility class contains no functionality, but is used to
    represent a session.

    @ivar site: The L{Site} that generated the session.
    @type site: L{Site}

    @ivar uid: A unique identifier for the session.
    @type uid: L{bytes}

    @ivar _reactor: An object providing L{IReactorTime} to use for scheduling
        expiration.

    @ivar sessionTimeout: Time after last modification the session will expire,
        in seconds.
    @type sessionTimeout: L{float}

    @ivar lastModified: Time the C{touch()} method was last called (or time the
        session was created). A UNIX timestamp as returned by
        L{IReactorTime.seconds()}.
    @type lastModified: L{float}
    i�Nc���t�|��|�|j}||_||_||_g|_|j�i|_y)z�
        Initialize a session with a unique ID for that session.

        @param reactor: L{IReactorTime} used to schedule expiration of the
            session. If C{None}, the reactor associated with I{site} is used.
        N)	�superrI�reactor�_reactorrQr��expireCallbacksr��sessionNamespaces)rKrQr�r5�	__class__s    �r4rIzSession.__init__�sL���	�����?��l�l�G���
���	����!����
�
��!#��r5c�n�|jj|j|j�|_y)zF
        Start expiration tracking.

        @return: L{None}
        N)r6�	callLater�sessionTimeout�expire�_expireCallr�s r4�startCheckingExpirationzSession.startCheckingExpiration�s'�� �=�=�2�2�4�3F�3F����T��r5c�:�|jj|�y)zJ
        Call this callback when the session expires or logs out.
        N)r7�append)rK�callbacks  r4�notifyOnExpirezSession.notifyOnExpire�s��	
���#�#�H�-r5c��|jj|j=|jD]	}|��g|_|jr=|jj�r"|jj
�d|_yyy)z/
        Expire/logout of the session.
        N)rQ�sessionsr�r7r>�active�cancel)rK�cs  r4r=zSession.expire�sx��
�I�I���t�x�x�(��%�%�	�A�
�C�	�!������� 0� 0� 7� 7� 9����#�#�%�#�D��!:�r5c��|jj�|_|j�&|jj	|j
�yy)zN
        Mark the session as modified, which resets expiration timer.
        N)r6�seconds�lastModifiedr>�resetr<r�s r4r�z
Session.touch�sD��!�M�M�1�1�3������'����"�"�4�#6�#6�7�(r5rH)rrr	r
r<r>rIr?rCr=r��
__classcell__�r9s@r4r!r!�s.����2�N��K�$�&U�.�$�8r5r!zTwistedWeb/c���eZdZdZdZeZdZeZ	dZ
ejZ
d�fd�	Zd�Zd�Zd�Zd	�Zd
�Z�fd�ZdZd�Zd
�Zd�Zd�Z�xZS)r"a*
    A web site: manage log, sessions, and resources.

    @ivar requestFactory: A factory which is called with (channel)
        and creates L{Request} instances. Default to L{Request}.

    @ivar displayTracebacks: If set, unhandled exceptions raised during
        rendering are returned to the client as HTML. Default to C{False}.

    @ivar sessionFactory: factory for sessions objects. Default to L{Session}.

    @ivar sessions: Mapping of session IDs to objects returned by
        C{sessionFactory}.
    @type sessions: L{dict} mapping L{bytes} to L{Session} given the default
        C{sessionFactory}

    @ivar counter: The number of sessions that have been generated.
    @type counter: L{int}

    @ivar sessionCheckTime: Deprecated and unused. See
        L{Session.sessionTimeout} instead.
    rFic�T��t�|�|i|��i|_||_|�||_yy)a�
        @param resource: The root of the resource hierarchy.  All request
            traversal for requests received by this factory will begin at this
            resource.
        @type resource: L{IResource} provider
        @param requestFactory: Overwrite for default requestFactory.
        @type requestFactory: C{callable} or C{class}.

        @see: L{twisted.web.http.HTTPFactory.__init__}
        N)r4rIrEr�requestFactory)rKrrQr2r3r9s     �r4rIz
Site.__init__"s8���	���$�)�&�)���
� ��
��%�"0�D��&r5c��ddlm}|jtjj|�tjj
|��S)Nr)�logfile)r�rS�LogFile�osrr�basename�dirname)rKrrrSs   r4�_openLogFilezSite._openLogFile3s2��*����r�w�w�/�/��5�r�w�w���t�7L�M�Mr5c�D�|jj�}i|d<|S)NrE)rVrW)rK�ds  r4�__getstate__zSite.__getstate__8s"���M�M��� ����*�
��r5c�^�|jdz|_t|jd��S)zP
        (internal) Generate an opaque, unique ID for a user's session.
        r� )�counterr�_entropyr�s r4�_mkuidzSite._mkuid=s(���|�|�a�'����t�}�}�R�(�)�)r5c��|j�}|j||�x}|j|<|j�|S)zU
        Generate a new Session instance, and store it for future reference.
        )r`�sessionFactoryrEr?)rKr�r�s   r4r�zSite.makeSessionDs@���k�k�m��'+�':�':�4��'E�E��$�-�-��$��'�'�)��r5c� �|j|S)z�
        Get a previously generated session.

        @param uid: Unique ID of the session.
        @type uid: L{bytes}.

        @raise KeyError: If the session is not found.
        )rE)rKr�s  r4r�zSite.getSessionMs���}�}�S�!�!r5c�V��t�|�|�}|j|_||_|S)z;
        Generate a channel attached to this site.
        )r4�
buildProtocolrQrQ)rKr@rOr9s   �r4rezSite.buildProtocolXs.����'�'��-��!%�!4�!4�������r5c�h�|j|j�dz�|j�y)z@
        Redirect because a Site is always a directory.
        reN)�redirectr�r��rKrs  r4rzzSite.rendercs*��	����+�+�-��4�5����r5c�H�||_|jj||�S)z7
        Emulate a resource's getChild method.
        )rQr�getChildWithDefault)rK�pathElrs   r4rjzSite.getChildWithDefaultjs"������}�}�0�0���A�Ar5c��||_tj|j�|_t	j
|j|�S)z�
        Get a resource for a request.

        This iterates through the resource hierarchy, calling
        getChildWithDefault on each resource it finds for a path element,
        stopping when it hits an element where isLeaf is true.
        )rQrWrEr�r�getChildForRequestrhs  r4ruzSite.getResourceForqs9����� �9�9�W�_�_�5����*�*�4�=�=�'�B�Br5c�P�dg}tjr|jdd�|S)z2
        Protocols this server can speak.
        shttp/1.1rsh2)r�
H2_ENABLED�insert)rK�
baseProtocolss  r4�acceptableProtocolszSite.acceptableProtocols�s(��%�
�
��?�?�� � ��E�*��r5rH)rrr	r
r^r rQr�r!rb�sessionCheckTimerU�urandomr_rIrXr[r`r�r�re�isLeafrzrjrurrrMrNs@r4r"r"so����.�G��N����N����z�z�H�1�"N�
�
*��	"���F��B�C�	r5r")Gr
rWrUrr �binasciir�htmlr�typingrr�urllib.parserr.�zope.interfacer�incrementalr	�twistedr
�twisted.internetrr�twisted.internet.errorr
r�twisted.loggerrr�rrr�twisted.python.compatrr�twisted.python.deprecater�twisted.spread.pbrr�twisted.webrrrr�twisted.web.errorr�twisted.web.httprr$�__all__rpr(�stringToDatetimer)rrA�IRequestr rJ�_IRequestEncoderFactoryr%�_IRequestEncoderrr�r!r#�IProtocolNegotiationFactory�HTTPFactoryr"rr5r4�<module>r�s���
	��	�	����!�(�&���0�B�!�7�7�=�>�1�2�2�/�$�������I�r�1�a� �:���	���I�r�1�a� �:���	��(�(���(�(��.��O��
�T�]�]���h����j�&>�&>����D
�T�
)�
)�*�=�=�+�=�<
�T�
"�
"�#�%�%�$�%�PB�B�R8�j�&�&�R8�j�+�i�&7�&7�%8�9�
:��
�Z�
3�
3�4�F�4���F�5�Fr5