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__/distrib.cpython-312.pyc
�

Ϫ�f5/���dZddlZddlZddlZ	ddlZddlmZddlm	Z	ddl
mZmZddl
mZddlmZddlmZdd	lmZdd
lmZmZmZmZmZddlmZGd�d
ej:�ZGd�dej>ej@�Z ejBej@e �Gd�d�Z"Gd�dejF�Z$Gd�dejJejL�Z'Gd�dejF�Z(y#e$rdZY��wxYw)z�
Distributed web servers.

This is going to have to be refactored so that argument parsing is done
by each subprocess and not by the main web server (i.e. GET, POST etc.).
�N)�BytesIO)�getDOMImplementation)�address�reactor)�Logger)�styles)�pb)�
SIZE_LIMIT)�http�resource�server�static�util)�Headersc�$�eZdZd�Zd�Zd�Zd�Zy)�_ReferenceableProducerWrapperc��||_y�N)�producer)�selfrs  �5/usr/lib/python3/dist-packages/twisted/web/distrib.py�__init__z&_ReferenceableProducerWrapper.__init__!s	�� ��
�c�8�|jj�yr)r�resumeProducing�rs r�remote_resumeProducingz4_ReferenceableProducerWrapper.remote_resumeProducing$s���
�
�%�%�'rc�8�|jj�yr)r�pauseProducingrs r�remote_pauseProducingz3_ReferenceableProducerWrapper.remote_pauseProducing's���
�
�$�$�&rc�8�|jj�yr)r�
stopProducingrs r�remote_stopProducingz2_ReferenceableProducerWrapper.remote_stopProducing*s���
�
�#�#�%rN)�__name__�
__module__�__qualname__rrr r#�rrrr s��!�(�'�&rrc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�Requestzn
    A request which was received by a L{ResourceSubscription} and sent via
    PB to a distributed node.
    c�����dD]+}||�ddd��d���fd��fd�d���}|||<�-tt|d	��|d	<tjj	||�t|j�|_|jjd
�|_
|jjd�|_|jjd�|_|jjd
�|_
|jjd�|_|jjd�|_|jjd�|_y)z�
        Initialize this L{twisted.web.distrib.Request} based on the copied
        state so that it closely resembles a L{twisted.web.server.Request}.
        )�host�client�TCP�UNIX)�INETr.rc�>��tj��d�d�S)N��)r�IPv4Address)�addrdesc�tups��r�<lambda>z*Request.setCopyableState.<locals>.<lambda>=s���w�2�2�8�S��V�S��V�L�rc�4��tj�d�S)Nr1)r�UNIXAddress)r5s�rr6z*Request.setCopyableState.<locals>.<lambda>>s���� 3� 3�C��F� ;�r)r-r.�requestHeaders�finish�	setHeader�	addCookie�setETag�setResponseCode�setLastModified�writeN)r�dictr	�
RemoteCopy�setCopyableStater�content_data�content�remote�remoteMethodr:r;r<r=r>r?�_write)r�state�k�addrr4r5s    @@rrCzRequest.setCopyableState4s?���
"�	�A���(�C� %�v�6�s�1�v�>�H��L�;�����D��E�!�H�	�#*�$�u�5E�/F�*G�"H����
�
�
�&�&�t�U�3��t�0�0�1����k�k�.�.�x�8������1�1�+�>������1�1�+�>����{�{�/�/�	�:���#�{�{�7�7�8I�J���#�{�{�7�7�8I�J����k�k�.�.�w�7��rc��d}t}	|j|||�|tz
}|tz
}|t|�k\ry�6)z�
        Write the given bytes to the response body.

        @param bytes: The bytes to write.  If this is longer than 640k, it
            will be split up into smaller pieces.
        rN)r
rH�len)r�bytes�start�ends    rr@z
Request.writePsL��������K�K��e�C�(�)��Z��E��:��C���E�
�"��rc��|jjdt|�|�j|j�y)N�registerProducer)rF�
callRemoter�
addErrback�fail)rr�	streamings   rrRzRequest.registerProducer`s/�������� =�h� G��	
�
�*�T�Y�Y�
rc�l�|jjd�j|j�y)N�unregisterProducer)rFrSrTrUrs rrXzRequest.unregisterProduceres$�������3�4�?�?��	�	�Jrc�>�|jjd|��y)N�)�failure)�_logr[�rr[s  rrUzRequest.failhs���	�	���"�g��.rN)	r$r%r&�__doc__rCr@rRrXrUr'rrr)r).s!���
8�8�  �
K�/rr)c�,�eZdZe�Zd�Zd�Zd�Zy)�Issuec��||_yr)�request)rrbs  rrzIssue.__init__rs	����rc���|tjurMt|t�sJd��|jj|�|jj
�yy)Nzreturn value not a string)r
�NOT_DONE_YET�
isinstance�strrbr@r:)r�results  r�finishedzIssue.finishedusM����,�,�,��f�c�*�G�,G�G�*��L�L���v�&��L�L���!�-rc
�^�t|�}|jjtjt
jddtj|�z�j|j��|jj�|jj|�y)NzServer Connection Lostz&Connection to distributed server lost:)
rfrbr@r�_UnsafeErrorPager�INTERNAL_SERVER_ERRORr�_PRE�renderr:r\�infor]s  r�failedzIssue.failed{sz���g�,��������%�%��*�*�(�8�4�9�9�W�;M�M�	
�
�f�T�\�\�"�
	
�	
�������	�	���w�rN)r$r%r&rr\rrhror'rrr`r`os���8�D��"� rr`c�F�eZdZdZdZe�Zd�Zd�Zd�Z	d�Z
d�Zd�Zy	)
�ResourceSubscriptionr1rc�z�tjj|�||_||_g|_d|_yr)r�Resourcerr+�port�pending�	publisher)rr+rts   rrzResourceSubscription.__init__�s2�����"�"�4�(���	���	������rc�b�tj|j�}d|d<d|d<g|d<|S)z3Get persistent state for this ResourceSubscription.Nrvr�waitingru)�copy�__dict__)rrIs  r�__getstate__z!ResourceSubscription.__getstate__�s9���	�	�$�-�-�(��!��k����i����i���rc���|jjd�|jj|j�||_d|_|jD]}|j|��g|_y)z=I've connected to a publisher; I'll now send all my requests.zconnected to publisherrN)	r\rn�broker�notifyOnDisconnect�bootedrvrxrurm)rrvrbs   r�	connectedzResourceSubscription.connected�s_���	�	���/�0����+�+�D�K�K�8�"�������|�|�	!�G��K�K�� �	!���rc���|jjd|��d|_d|_|jD]#}|jd�|j
��%g|_y)zXI can't connect to a publisher; I'll now reply to all pending
        requests.
        z3could not connect to distributed web service: {msg})�msgrNz(Unable to connect to distributed server.)r\rnrxrvrur@r:)rr�rbs   r�notConnectedz!ResourceSubscription.notConnected�s[��	
�	�	���L�RU��V��������|�|�	�G��M�M�D�E��N�N��	���rc�&�|jd�y)Nzconnection dropped)r�rs rrzResourceSubscription.booted�s�����.�/rc��|js�|jj|�|js�d|_t	j
�}d}|jdk(r"tj|j||�n,tj|j|j||�|j�}|j|j|j�t&j(St|�}|jj!d|�j|j"|j$�t&j(S)a:Render this request, from my server.

        This will always be asynchronous, and therefore return NOT_DONE_YET.
        It spins off a request to the pb client, and either adds it to the list
        of pending issues or requests it immediately, depending on if the
        client is already connected.
        r1�
�unixrb)rvru�appendrxr	�PBClientFactoryr+r�connectUNIXrt�
connectTCP�
getRootObject�addCallbacksr�r�r`rSrhror
rd)rrb�bf�timeout�d�is      rrmzResourceSubscription.render�s����~�~��L�L����(��<�<� ����'�'�)�����9�9��&��'�'��	�	�2�w�?��&�&�t�y�y�$�)�)�R��I��$�$�&�����t�~�~�t�/@�/@�A��"�"�"�	�g��A��N�N�%�%�i��9�F�F��
�
�A�H�H�
��"�"�"rN)
r$r%r&�isLeafrxrr\rr{r�r�rrmr'rrrqrq�s1��
�F��G��8�D��
��
�0�#rrqc�:�eZdZdZe�Zd�ZdZd�Zd�Z	d�Z
y)�ResourcePublisherz�
    L{ResourcePublisher} exposes a remote API which can be used to respond
    to request.

    @ivar site: The site which will be used for resource lookup.
    @type site: L{twisted.web.server.Site}
    c��||_yr)�site)rr�s  rrzResourcePublisher.__init__�s	����	rr2c��|jjjd�|jj|j=|`|`|`y)N�web)�application�
authorizer�removeIdentity�services�serviceName�perspectiveNamers r�upgradeToVersion2z#ResourcePublisher.upgradeToVersion2�sH�����#�#�2�2�5�9����%�%�d�&6�&6�7������ rc��|Srr')r�names  r�getPerspectiveNamedz%ResourcePublisher.getPerspectiveNamed�s���rc��|jj|�}|jj|�|j	|�}|t
jur!|j|�|j�t
jS)zK
        Look up the resource for the given request and render it.
        )	r��getResourceForr\rnrmr
rdr@r:)rrb�resrgs    r�remote_requestz ResourcePublisher.remote_request�sf���i�i�&�&�w�/���	�	���w�����G�$����,�,�,��M�M�&�!��N�N���"�"�"rN)r$r%r&r^rr\r�persistenceVersionr�r�r�r'rrr�r��s,����8�D����!��
#rr�c�6�eZdZdZdZdZdZd
d�Zd�Zd�Z	d	�Z
y)�
UserDirectoryz�
    A resource which lists available user resources and serves them as
    children.

    @ivar _pwd: An object like L{pwd} which is used to enumerate users and
        their home directories.
    �public_htmlz.twistd-web-pba�
<html>
    <head>
    <title>twisted.web.distrib.UserDirectory</title>
    <style>

    a
    {
        font-family: Lucida, Verdana, Helvetica, Arial, sans-serif;
        color: #369;
        text-decoration: none;
    }

    th
    {
        font-family: Lucida, Verdana, Helvetica, Arial, sans-serif;
        font-weight: bold;
        text-decoration: none;
        text-align: left;
    }

    pre, code
    {
        font-family: "Courier New", Courier, monospace;
    }

    p, body, td, ol, ul, menu, blockquote, div
    {
        font-family: Lucida, Verdana, Helvetica, Arial, sans-serif;
        color: #000;
    }
    </style>
    </head>

    <body>
    <h1>twisted.web.distrib.UserDirectory</h1>

    %(users)s
</body>
</html>
Nc�`�tjj|�|�t}||_yr)rrsr�pwd�_pwd)r�userDatabases  rrzUserDirectory.__init__5s(�����"�"�4�(����L� ��	rc��g}|jj�D]�}|\}}}}}}}	|jd�d}
|
s|}
tjjtjj
||j��r|j||
dzf�tjj
||j�}tjj|�s��|dz}|j||
dzf���|S)z|
        Return a list of two-tuples giving links to user resources and text to
        associate with those links.
        �,rz (file)z.twistdz	 (twistd))
r��getpwall�split�os�path�exists�join�userDirNamer��userSocketName)
r�users�userr��passwd�uid�gid�gecos�dir�shell�realname�
twistdsock�linkNames
             r�_userszUserDirectory._users;s���
���I�I�&�&�(�
	A�D�8<�5�D�&�#�s�E�3���{�{�3�'��*�H�����w�w�~�~�b�g�g�l�l�3��0@�0@�A�B����d�H�y�$8�9�:������c�4�+>�+>�?�J��w�w�~�~�j�)��)�+�����h��;�(>�?�@�
	A��rc���t�}|jddd�}|j}|j�D]�\}}|j	d�}|jd|dz�|j
|�}|j|�|j	d�}	|	j|�|j|	���|jd|j�iz}
|
jd�S)	zm
        Render as HTML a listing of all known users with links to their
        personal resources.
        N�ul�a�href�/�lir�zutf-8)r�createDocument�documentElementr��
createElement�setAttribute�createTextNode�appendChild�template�toxml�encode)rrb�domImpl�newDoc�listing�link�text�linkElement�textNode�item�htmlDocs           r�
render_GETzUserDirectory.render_GETNs���'�(���'�'��d�D�9���(�(���+�+�-�	&�J�D�$� �.�.�s�3�K��$�$�V�T�C�Z�8��,�,�T�2�H��#�#�H�-��'�'��-�D����[�)�����%�	&��-�-�G�W�]�]�_�#=�>���~�~�g�&�&rc��|dk(r|Sd}|j|�r|dt|�}d}n|}d}	|jj|j	tj���\}}}}	}
}}|rJtjj||j�}
td|
�}|j||�|Stjj||j �}tjj#|�stj�St%j&|�S#t$rtj�cYSwxYw)Nrs.twistdr1rr�)�endswithrMr��getpwnam�decode�sys�getfilesystemencoding�KeyErrorr�_UnsafeNoResourcer�r�r�r�rq�putChildr�r�r�File)rr�rb�td�username�sub�pw_name�	pw_passwd�pw_uid�pw_gid�pw_gecos�pw_dir�pw_shellr��rsr�s                r�getChildzUserDirectory.getChildcs+���3�;��K�
���=�=����J�s�2�w�h�'�H��C��H��C�
	0��	�	�"�"�8�?�?�3�3L�3L�3N�#O�P�
��������������f�d�.A�.A�B�J�%�f�j�9�B��M�M�$��#��I��7�7�<�<���(8�(8�9�D��7�7�>�>�$�'��1�1�3�3��;�;�t�$�$���	0��-�-�/�/�	0�s�AD4�4E�Er)r$r%r&r^r�r�r�rr�r�r�r'rrr�r��s/��� �K�%�N�(�H�T!��&'�*#%rr�))r^ryr�r�r��ImportError�ior�xml.dom.minidomr�twisted.internetrr�twisted.loggerr�twisted.persistedr�twisted.spreadr	�twisted.spread.bananar
�twisted.webrrr
rr�twisted.web.http_headersr�
ReferenceablerrBr)�setUnjellyableForClassr`rsrq�Root�	Versionedr�r�r'rr�<module>rs���
��	�
����0�-�!�$��,�<�<�,�&�B�$4�$4�&�;/�b�m�m�V�^�^�;/�|����&�.�.�'�2� � �6K#�8�,�,�K#�\$#�����!1�!1�$#�NG%�H�%�%�G%��[��
�C��s�C;�;D�D