HOME


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

Ϫ�f����dZddlmZddlmZmZddlmZddlm	Z	ddl
mZGd�d�ZGd	�d
�Z
Gd�d�ZGd
�d�ZGd�de�Zeej"�Gd�de��ZGd�dej&�Zd�Zy)z
Utility classes for spread.
�)�implementer)�defer�
interfaces)�basic)�Failure)�pbc��eZdZd�Zd�Zy)�LocalMethodc� �||_||_y�N)�local�name)�selfr
rs   �5/usr/lib/python3/dist-packages/twisted/spread/util.py�__init__zLocalMethod.__init__s����
���	�c�V�|jj|jg|��i|��Sr)r
�
callRemoter)r�args�kws   r�__call__zLocalMethod.__call__s'��$�t�z�z�$�$�T�Y�Y�<��<��<�<rN)�__name__�
__module__�__qualname__rr�rrr
r
s���=rr
c� �eZdZdZdZd�Zd�Zy)�
LocalAsRemotezN
    A class useful for emulating the effects of remote behavior locally.
    �c�4�t|d|z�rt|d|z�|i|��S	t|d|z�}tj||i|���S#t$r>t�}|jr|j�tj|�cYSwxYw)ax
        Call a specially-designated local method.

        self.callRemote('x') will first try to invoke a method named
        sync_x and return its result (which should probably be a
        Deferred).  Second, it will look for a method called async_x,
        which will be called and then have its result (or Failure)
        automatically wrapped in a Deferred.
        �sync_�async_)	�hasattr�getattrr�succeed�
BaseExceptionr�reportAllTracebacks�printTraceback�fail)rrrr�method�fs      rrzLocalAsRemote.callRemote#s����4��4��(�0�7�4��4��0�$�=�"�=�=�	!��T�8�d�?�3�F��=�=���!4��!4�5�5���	!��	�A��'�'�� � �"��:�:�a�=� �		!�s�)A�AB�Bc��t||�Sr)r
)rrs  r�remoteMethodzLocalAsRemote.remoteMethod8s���4��&�&rN)rrr�__doc__r&rr,rrrrrs�����!�*'rrc�$�eZdZdZdd�Zd�Zd�Zy)�LocalAsyncForwarderzD
    A class useful for forwarding a locally-defined interface.
    c�T�|j|�sJ�||_||_||_yr)�
providedBy�	forwarded�interfaceClass�failWhenNotImplemented)rr2r3r4s    rrzLocalAsyncForwarder.__init__As-���(�(��3�3�3�"���,���&<��#rc�:�t|j|�|i|��Sr)r#r2)rr)rrs    r�_callMethodzLocalAsyncForwarder._callMethodGs��.�w�t�~�~�v�.��;��;�;rc��|jj|�r&tj|j|g|��i|��}|S|j
r&tjttd|z��Stjd�S)NzNo Such Method in Interface: %s)
r3�queryDescriptionForr�
maybeDeferredr6r4r(r�NotImplementedErrorr$)rr)rr�results     rrzLocalAsyncForwarder.callRemoteJsz�����2�2�6�:��(�(��)9�)9�6�O�D�O�B�O�F��M�
�
(�
(��:�:��+�-N�QW�-W�X��
��=�=��&�&rN)r)rrrr-rr6rrrrr/r/<s���=�<�	'rr/c�0�eZdZdZdd�Zd�Zd�Zd�Zd�Zy)	�Pagerz5
    I am an object which pages out information.
    Nc��t|�r||_||_||_nd|_d|_||_|jj|�y)z�
        Create a pager with a Reference to a remote collector and
        an optional callable to invoke upon completion.
        Nr)�callable�callback�callbackArgs�callbackKeyword�_stillPaging�	collector�broker�registerPageProducer)rrDr@rrs     rrzPager.__init__[sM��
�H��$�D�M� $�D��#%�D� � �D�M����"������-�-�d�3rc���|jsO|jjdd��|j�&|j|ji|j
��|jS)�5
        (internal) Method called by Broker.
        �endedPagingF��pbanswer)rCrDrr@rArB�rs r�stillPagingzPager.stillPagingjsY��� � ��N�N�%�%�m�e�%�D��}�}�(���
�
�t�0�0�I�D�4H�4H�I�� � � rc�\�|jjd|j�d��y)rH�gotPageFrJN)rDr�nextPagerLs r�sendNextPagezPager.sendNextPagets#��	
���!�!�)�T�]�]�_�u�!�Mrc��t��)zO
        Override this to return an object to be sent to my collector.
        )r:rLs rrPzPager.nextPagezs
��"�#�#rc��d|_y)z4
        Call this when you're done paging.
        rN)rCrLs r�
stopPagingzPager.stopPaging�s����rr)	rrrr-rrMrQrPrTrrrr=r=Vs!���
4�!�N�$�rr=c��eZdZdZdd�Zd�Zy)�StringPagerz:
    A simple pager that splits a string into chunks.
    Nc�d�||_d|_||_tj|||g|��i|��y)Nr)�string�pointer�	chunkSizer=r)rrD�strZr@rrs       rrzStringPager.__init__�s1��������"���
���t�Y��>�4�>�2�>rc��|j|j|j|jz}|xj|jz
c_|jt|j�k\r|j	�|Sr)rXrYrZ�lenrT�r�vals  rrPzStringPager.nextPage�sY���k�k�$�,�,�������)F�G��������&���<�<�3�t�{�{�+�+��O�O���
r)i N)rrrr-rrPrrrrVrV�s���?�rrVc�6�eZdZdZd	d�Zd�Zd�Zd�Zd�Zd�Z	y)
�	FilePagerzC
    Reads a file in chunks and sends the chunks as they come.
    Nc�j�g|_tj|||g|��i|��|j|�yr)�chunksr=r�startProducing)rrD�fdr@rrs      rrzFilePager.__init__�s1�����
���t�Y��>�4�>�2�>����B�rc���tj�j|���_�jj	�fd��y)Nc�$���j�Sr)rT)�xrs �r�<lambda>z*FilePager.startProducing.<locals>.<lambda>�s������(9�r)r�
FileSender�beginFileTransfer�deferred�addBoth)rres` rrdzFilePager.startProducing�s3����(�(�*�<�<�R��F��
��
�
���9�:rc�L�||_|s|jj�yyr)�producer�resumeProducing)rro�	streamings   r�registerProducerzFilePager.registerProducer�s!�� ��
���M�M�)�)�+�rc��d|_yr)rorLs r�unregisterProducerzFilePager.unregisterProducer�s	����
rc�:�|jj|�yr)rc�append)r�chunks  r�writezFilePager.write�s�������5�!rc���|jsy|jjd�}|jj�|jjd|d��y)zD
        Get the first chunk read and send it to collector.
        NrrOFrJ)rc�poprorprDrr^s  rrQzFilePager.sendNextPage�sI���{�{���k�k�o�o�a� ���
�
�%�%�'����!�!�)�S�5�!�Arr)
rrrr-rrdrrrtrxrQrrrrara�s&��� �
;�,�
�"�Brrac�"�eZdZdZd�Zd�Zd�Zy)�CallbackPageCollectorz�
    I receive pages from the peer. You may instantiate a Pager with a
    remote reference to me. I will call the callback with a list of pages
    once they are all received.
    c� �g|_||_yr)�pagesr@)rr@s  rrzCallbackPageCollector.__init__�s����
� ��
rc�:�|jj|�yr)r~rv)r�pages  r�remote_gotPagez$CallbackPageCollector.remote_gotPage�s���
�
���$�rc�:�|j|j�yr)r@r~rLs r�remote_endedPagingz(CallbackPageCollector.remote_endedPaging�s���
�
�d�j�j�!rN)rrrr-rr�r�rrrr|r|�s���!� �"rr|c��tj�}|j|t|j�g|��i|��|S)zr
    A utility method that will call a remote method which expects a
    PageCollector as the first argument.
    )r�Deferredrr|r@)�
referenceable�
methodNamerr�ds     r�getAllPagesr��s<��
	����A��M���Z�)>�q�z�z�)J�X�T�X�UW�X��HrN)r-�zope.interfacer�twisted.internetrr�twisted.protocolsr�twisted.python.failurer�twisted.spreadrr
rr/r=rV�	IConsumerra�
Referenceabler|r�rrr�<module>r�s����'�.�#�*��=�=�'�'�@'�'�4.�.�b�%��&
�Z�
!�
!�"�!B��!B�#�!B�J"�B�,�,�"�$
r