%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/spread/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/spread/__pycache__/flavors.cpython-312.pyc

�

Ϫ�f�[���dZddlZddlmZmZddlmZmZddlm	Z	m
Z
ddlmZm
Z
mZmZmZmZmZmZmZeZeZeZeZdZd	Zd
ZdZGd�d
e�ZGd�de�ZGd�de�Z Gd�de �Z!ee�Gd�de!��Z"Gd�de!�Z#Gd�de �Z$Gd�de �Z%Gd�de%�Z&Gd�de
�Z'Gd �d!e'e �Z(d"�Z)ed#e)�d$�Z*ed%e*�d&�Z+ed'e+�e
Gd(�d)��Z,e
Gd*�d+��Z-y),a�
This module represents flavors of remotely accessible objects.

Currently this is only objects accessible through Perspective Broker, but will
hopefully encompass all forms of remote access which can emulate subsets of PB
(such as XMLRPC or SOAP).

Future Plans: Optimization.  Exploitation of new-style object model.
Optimizations to this module should not affect external-use semantics at all,
but may have a small impact on users who subclass and override methods.

@author: Glyph Lefkowitz
�N)�	Interface�implementer)�log�reflect)�cmp�
comparable�)	�	Jellyable�Unjellyable�_createBlank�getInstanceState�setInstanceState�setUnjellyableFactoryForClass�setUnjellyableForClass�setUnjellyableForClassTree�unjellyableRegistryscopy�cachescached�remotec��eZdZdZy)�NoSuchMethodz(Raised if there is no such remote methodN)�__name__�
__module__�__qualname__�__doc__���8/usr/lib/python3/dist-packages/twisted/spread/flavors.pyrr7s��2rrc��eZdZdZd�Zy)�IPBRootz6Factory for root Referenceable objects for PB servers.c��y)z%Return root Referenceable for broker.Nr)�brokers r�
rootObjectzIPBRoot.rootObject>��rN�rrrrr"rrrrr;s
��@�4rrc��eZdZdZd�Zy)�SerializableaxAn object that can be passed remotely.

    I am a style of object which can be serialized by Perspective
    Broker.  Objects which wish to be referenceable or copied remotely
    have to subclass Serializable.  However, clients of Perspective
    Broker will probably not want to directly subclass Serializable; the
    Flavors of transferable objects are listed below.

    What it means to be "Serializable" is that an object can be
    passed to or returned from a remote method.  Certain basic types
    (dictionaries, lists, tuples, numbers, strings) are serializable by
    default; however, classes need to choose a specific serialization
    style: L{Referenceable}, L{Viewable}, L{Copyable} or L{Cacheable}.

    You may also pass C{[lists, dictionaries, tuples]} of L{Serializable}
    instances to or return them from remote methods, as many levels deep
    as you like.
    c��t|�S)z�Return an ID which uniquely represents this object for this process.

        By default, this uses the 'id' builtin, but can be overridden to
        indicate that two values are identity-equivalent (such as proxies
        for the same object).
        )�id��selfs r�processUniqueIDzSerializable.processUniqueIDVs
���$�x�rN)rrrrr+rrrr&r&Bs���&rr&c��eZdZdZ	d�Zd�Zy)�
ReferenceableNc�@�|j|�}|j|�}|j�D�cgc]}t|t�s�|��c}r2|j	�D��cic]\}}|jd�|��}}}t|t�s|jd�}t|d|zd�}|�td|����	||i|��}	|j|	|j�Scc}wcc}}w#t$rtj|�d|�d|����wxYw)z�A remote message has been received.  Dispatch it appropriately.

        The default implementation is to dispatch to a method called
        'remote_messagename' and call it with the same arguments.
        �utf8z	remote_%sNzNo such method: remote_� didn't accept � and )�unserialize�keys�
isinstance�bytes�items�decode�str�getattrr�	TypeErrorr�msg�	serialize�perspective)
r*r!�message�args�kw�key�k�v�method�states
          r�remoteMessageReceivedz#Referenceable.remoteMessageReceivedns���!�!�$�'��
�
�
��
#���7�7�9�?�C�
�3��(>�C�?�24�(�(�*�=�$�!�Q�!�(�(�6�"�A�%�=�B�=��'�3�'��n�n�V�,�G���{�W�4�d�;���>��!8��	�B�C�C�	��D�'�B�'�E�����t�'7�'7�8�8��@��=���	��G�G�v�h�o�d�V�5���=�>��	�s�C*�C*�%C/�C5�5(Dc�<�d|jj|�gS)zw(internal)

        Return a tuple which will be used as the s-expression to
        serialize this to a peer.
        r)�invoker�registerReference�r*�jelliers  r�jellyForzReferenceable.jellyFor�s���7�?�?�<�<�T�B�C�Cr)rrrr=rFrLrrrr-r-as���K�	�9�6Drr-c��eZdZdZd�Zy)�RootaI provide a root object to L{pb.Broker}s for a L{pb.PBClientFactory} or
    L{pb.PBServerFactory}.

    When a factory produces a L{pb.Broker}, it supplies that
    L{pb.Broker} with an object named "root".  That object is obtained
    by calling my rootObject method.
    c��|S)z�A factory is requesting to publish me as a root object.

        When a factory is sending me as the root object, this
        method will be invoked to allow per-broker versions of an
        object.  By default I return myself.
        r)r*r!s  rr"zRoot.rootObject�s	���rNr$rrrrNrN�s���rrNc�"�eZdZdZd�Zd�Zd�Zy)�	ViewPointaF
    I act as an indirect reference to an object accessed through a
    L{pb.IPerspective}.

    Simply put, I combine an object with a perspective so that when a
    peer calls methods on the object I refer to, the method will be
    invoked with that perspective as a first argument, so that it can
    know who is calling it.

    While L{Viewable} objects will be converted to ViewPoints by default
    when they are returned from or sent as arguments to a remote
    method, any object may be manually proxied as well. (XXX: Now that
    this class is no longer named C{Proxy}, this is the only occurrence
    of the term 'proxied' in this docstring, and may be unclear.)

    This can be useful when dealing with L{pb.IPerspective}s, L{Copyable}s,
    and L{Cacheable}s.  It is legal to implement a method as such on
    a perspective::

     | def perspective_getViewPointForOther(self, name):
     |     defr = self.service.getPerspectiveRequest(name)
     |     defr.addCallbacks(lambda x, self=self: ViewPoint(self, x), log.msg)
     |     return defr

    This will allow you to have references to Perspective objects in two
    different ways.  One is through the initial 'attach' call -- each
    peer will have a L{pb.RemoteReference} to their perspective directly.  The
    other is through this method; each peer can get a L{pb.RemoteReference} to
    all other perspectives in the service; but that L{pb.RemoteReference} will
    be to a L{ViewPoint}, not directly to the object.

    The practical offshoot of this is that you can implement 2 varieties
    of remotely callable methods on this Perspective; view_xxx and
    C{perspective_xxx}. C{view_xxx} methods will follow the rules for
    ViewPoint methods (see ViewPoint.L{remoteMessageReceived}), and
    C{perspective_xxx} methods will follow the rules for Perspective
    methods.
    c� �||_||_y)z/Initialize me with a Perspective and an Object.N)r=�object)r*r=rSs   r�__init__zViewPoint.__init__�s��&�����rc�V�t|j�t|j�fS)zGReturn an ID unique to a proxy for this perspective+object combination.)r(r=rSr)s rr+zViewPoint.processUniqueID�s ���4�#�#�$�b����o�6�6rc��|j||j�}|j||j�}t|t�s|j	d�}t|jd|z�}	||jf|zi|��}|j||j|||�}|S#t$rtj|�d|�d|����wxYw)a7A remote message has been received.  Dispatch it appropriately.

        The default implementation is to dispatch to a method called
        'C{view_messagename}' to my Object and call it on my object with
        the same arguments, modified by inserting my Perspective as
        the first argument.
        r/zview_%sr0r1)r2r=r4r8r7r9rSr:rr;r<)r*r!r>r?r@rDrE�rvs        rrFzViewPoint.remoteMessageReceived�s����!�!�$��(8�(8�9��
�
�
��D�$4�$4�
5���'�3�'��n�n�V�,�G�����i�'�&9�:��	��T�-�-�/�$�6�=�"�=�E��
�
�e�T�%5�%5�v�t�R�
H���	��	�	��G�G�v�h�o�d�V�5���=�>��	�s�4B+�+(CN)rrrrrTr+rFrrrrQrQ�s��%�N�
7�rrQc��eZdZdZd�Zy)�ViewableaBI will be converted to a L{ViewPoint} when passed to or returned from a remote method.

    The beginning of a peer's interaction with a PB Service is always
    through a perspective.  However, if a C{perspective_xxx} method returns
    a Viewable, it will be serialized to the peer as a response to that
    method.
    c�`�t|jj|�j|�S)zHSerialize a L{ViewPoint} for me and the perspective of the given broker.)rQrH�serializingPerspectiverLrJs  rrLzViewable.jellyFor�s%������?�?��F�O�O�PW�X�XrN)rrrrrLrrrrYrY�s
���YrrYc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�Copyablea�Subclass me to get copied each time you are returned from or passed to a remote method.

    When I am returned from or passed to a remote method call, I will be
    converted into data via a set of callbacks (see my methods for more
    info).  That data will then be serialized using Jelly, and sent to
    the peer.

    The peer will then look up the type to represent this with; see
    L{RemoteCopy} for details.
    c��|jS)z�Gather state to send when I am serialized for a peer.

        I will default to returning self.__dict__.  Override this to
        customize this behavior.
        )�__dict__r)s r�getStateToCopyzCopyable.getStateToCopy
s���}�}�rc�"�|j�S)z�
        Gather state to send when I am serialized for a particular
        perspective.

        I will default to calling L{getStateToCopy}.  Override this to
        customize this behavior.
        )r`�r*r=s  r�getStateToCopyForzCopyable.getStateToCopyFors���"�"�$�$rc�^�tj|j�jd�S)z�Determine what type tag to send for me.

        By default, send the string representation of my class
        (package.module.Class); normally this is adequate, but
        you may override this to change it.
        �utf-8)r�qual�	__class__�encoder)s r�
getTypeToCopyzCopyable.getTypeToCopys"���|�|�D�N�N�+�2�2�7�;�;rc�"�|j�S)z�Determine what type tag to send for me.

        By default, defer to self.L{getTypeToCopy}() normally this is
        adequate, but you may override this to change it.
        )rirbs  r�getTypeToCopyForzCopyable.getTypeToCopyFor(s���!�!�#�#rc�,�|j�t||�S|jj}|j|�}|j	|�}|j|�}|j
||j|�g�|j||�S)z�Assemble type tag and state to copy for this broker.

        This will call L{getTypeToCopyFor} and L{getStateToCopy}, and
        return an appropriate s-expression to represent me.
        )	rHr
r[rkrc�prepare�extend�jelly�preserve)r*rK�p�trE�sxps      rrLzCopyable.jellyFor1s����?�?�"�#�D�'�2�2��O�O�2�2���!�!�!�$���&�&�q�)���o�o�d�#���
�
�A�w�}�}�U�+�,�-�����c�*�*rN)	rrrrr`rcrirkrLrrrr]r]�s ��	��	%�<�$�+rr]c�"�eZdZdZd�Zd�Zd�Zy)�	Cacheablea�A cached instance.

    This means that it's copied; but there is some logic to make sure
    that it's only copied once.  Additionally, when state is retrieved,
    it is passed a "proto-reference" to the state as it will exist on
    the client.

    XXX: The documentation for this class needs work, but it's the most
    complex part of PB and it is inherently difficult to explain.
    c�$�|j|�S)a-
        Get state to cache on the client and client-cache reference
        to observe locally.

        This is similar to getStateToCopyFor, but it additionally
        passes in a reference to the client-side RemoteCache instance
        that will be created when it is unserialized.  This allows
        Cacheable instances to keep their RemoteCaches up to date when
        they change, such that no changes can occur between the point
        at which the state is initially copied and the client receives
        it that are not propagated.
        )rc�r*r=�observers   r�getStateToCacheAndObserveForz&Cacheable.getStateToCacheAndObserveForNs���%�%�k�2�2rc���|j�t||�S|jj|d�}|��|jj|�}|jj}|j|�}t
|j||�}|j||�}|j|�}|j|�}|j|||g�|j||�St|fS)z�Return an appropriate tuple to serialize me.

        Depending on whether this broker has cached me or not, this may
        return either a full state or a reference to an existing cache.
        r	)
rHr
�cachedRemotelyAs�
cacheRemotelyr[rk�RemoteCacheObserverryrmrornrp�cached_atom)	r*rK�luidrq�type_rxrE�l�jstates	         rrLzCacheable.jellyFor^s����?�?�"�#�D�'�2�2����/�/��a�8���<��?�?�0�0��6�D����6�6�A��)�)�!�,�E�*�7�?�?�D�!�D�H��5�5�a��B�E�����%�A��]�]�5�)�F�
�H�H�e�T�6�*�+��#�#�D�!�,�,���$�$rc��y)z�This method is called when a client has stopped observing me.

        The 'observer' argument is the same as that passed in to
        getStateToCacheAndObserveFor.
        Nrrws   r�stoppedObservingzCacheable.stoppedObservingtr#rN)rrrrryrLr�rrrruruBs��	�3� %�,rruc��eZdZdZd�Zd�Zy)�
RemoteCopyaI am a remote copy of a Copyable object.

    When the state from a L{Copyable} object is received, an instance will
    be created based on the copy tags table (see setUnjellyableForClass) and
    sent the L{setCopyableState} message.  I provide a reasonable default
    implementation of that message; subclass me if you wish to serve as
    a copier for remote data.

    NOTE: copiers are invoked with no arguments.  Do not implement a
    constructor which requires args in a subclass of L{RemoteCopy}!
    c��|si}|j�D��cic])\}}t|t�r|jd�n||��+}}}||_ycc}}w)a(I will be invoked with the state to copy locally.

        'state' is the data returned from the remote object's
        'getStateToCopyFor' method, which will often be the remote
        object's dictionary (or a filtered approximation of it depending
        on my peer's perspective).
        r/N)r6r4r5r7r_)r*rE�x�ys    r�setCopyableStatezRemoteCopy.setCopyableState�sW����E�KP�;�;�=�
�CG�1�a�
�1�e� 4�A�H�H�V��!�Q�>�
��
���
��
s�.Ac�~�|j�
t|||�S|j|j|d��|S�Nr	)rHrr��unjelly)r*�	unjellier�	jellyLists   r�
unjellyForzRemoteCopy.unjellyFor�s?�����$�#�D�)�Y�?�?����i�/�/�	�!��=�>��rN)rrrrr�r�rrrr�r�|s��
�
�rr�c�B�eZdZdZd�Zd�Zd�Zd�Zd�ZdZ	dZ
d�Zd	�Zy)
�RemoteCachea�A cache is a local representation of a remote L{Cacheable} object.

    This represents the last known state of this object.  It may
    also have methods invoked on it -- in order to update caches,
    the cached class generates a L{pb.RemoteReference} to this object as
    it is originally sent.

    Much like copy, I will be invoked with no arguments.  Do not
    implement a constructor that requires arguments in one of my
    subclasses.
    c�8�t|t�s|jd�}|j|�}|j|�}t	|d|z�}	||i|��}|j|d|||�S#t
$rt
j|�d|�d|����wxYw)z�A remote message has been received.  Dispatch it appropriately.

        The default implementation is to dispatch to a method called
        'C{observe_messagename}' and call it on my  with the same arguments.
        r/z
observe_%sr0r1N)	r4r8r7r2r9r:rr;r<)r*r!r>r?r@rDrEs       rrFz!RemoteCache.remoteMessageReceived�s����'�3�'��n�n�V�,�G��!�!�$�'��
�
�
��
#����|�g�5�6��	��D�'�B�'�E�����t�V�T�2�>�>���	��G�G�v�h�o�d�V�5���=�>��	�s�A1�1(Bc��|j�t||�S|j|jusJd��d|jfS)zKserialize me (only for the broker I'm for) as the original cached referencez3You cannot exchange cached proxies between brokers.slcache)rHr
r!rrJs  rrLzRemoteCache.jellyFor�sJ���?�?�"�#�D�'�2�2��O�O�t�{�{�*�	A�@�	A�*��$�)�)�#�#rc��|j�
t|||�S|j|_|d|_|j	�}t|dd�}|r|�|jj
|d|�|j|j|d��|j|_	|j|_|d|_|S)Nr	rT�)
rHrr!r�_borgifyr9�cacheLocallyr�r�r_)r*r�r��borgCopy�inits     rr�zRemoteCache.unjellyFor�s������$�#�D�)�Y�?�?��'�'����a�L��	��=�=�?���x��T�2����F����&�&�y��|�T�:��!�!�)�"3�"3�I�a�L�"A�B�!�)�)��
� �'�'����a�L��	��rc���t||j�r2tt|j�t|j��Stt|j�|�S)z#Compare me [to another RemoteCache.)r4rgrr(r_�r*�others  r�__cmp__zRemoteCache.__cmp__�sE���e�T�^�^�,��r�$�-�-�(�"�U�^�^�*<�=�=��r�$�-�-�(�%�0�0rc�`�tt|j�tjz�S)zHash me.)�intr(r_�sys�maxsizer)s r�__hash__zRemoteCache.__hash__�s���2�d�m�m�$�s�{�{�2�3�3rNc��	|jr&|jj|j�yy#t$rt	j
�YywxYw)z.Do distributed reference counting on finalize.N)r!�decCacheRefr�
BaseExceptionr�deferrr)s r�__del__zRemoteCache.__del__�sA��	��{�{����'�'��	�	�2����	��J�J�L�	�s�15�A�Ac�R�t|j�}|j|_|S)a�
        Create a new object that shares its state (i.e. its C{__dict__}) and
        type with this object, but does not share its identity.

        This is an instance of U{the Borg design pattern
        <https://code.activestate.com/recipes/66531/>} originally described by
        Alex Martelli, but unlike the example given there, this is not a
        replacement for a Singleton.  Instead, it is for lifecycle tracking
        (and distributed garbage collection).  The purpose of these separate
        objects is to have a separate object tracking each application-level
        reference to the root L{RemoteCache} object being tracked by the
        broker, and to have their C{__del__} methods be invoked.

        This may be achievable via a weak value dictionary to track the root
        L{RemoteCache} instances instead, but this implementation strategy
        predates the availability of weak references in Python.

        @return: The new instance.
        @rtype: C{self.__class__}
        )rrgr_)r*�blanks  rr�zRemoteCache._borgify�s"��*�T�^�^�,��������r)
rrrrrFrLr�r�r�r!rr�r�rrrr�r��s6��
�?�&$��21�4��F��D��rr�c�^�|d}|jj|�j�Sr�)rH�cachedLocallyAsr�)r��unjellyListrs   r�
unjellyCachedr�s+���q�>�D����,�,�T�2�;�;�=�=r�cachedc�F�|d}|jj|�}|Sr�)rH�remotelyCachedForLUID)r�r�r�objs    r�
unjellyLCacher�s&���q�>�D�
�
�
�
1�
1�$�
7�C��Jr�lcachec�B�|jj|d�}|Sr�)rH�localObjectForID)r�r�r�s   r�unjellyLocalr�#s!��
�
�
�
,�
,�[��^�
<�C��Jr�localc�(�eZdZdZd�Zd�Zd�Zd�Zy)�RemoteCacheMethodz,A method on a reference to a L{RemoteCache}.c�<�||_||_||_||_y)z(internal) initialize.N)�namer!r=r�)r*r�r!r�r=s     rrTzRemoteCacheMethod.__init__/s����	����&�����rc�r�t|j|j|j|jf|�S�N)rr�r!r=r�r�s  rr�zRemoteCacheMethod.__cmp__6s*���D�I�I�t�{�{�D�,<�,<�d�k�k�J�E�R�Rrc�p�t|j|j|j|jf�Sr�)�hashr�r!r=r�r)s rr�zRemoteCacheMethod.__hash__9s(���T�Y�Y����T�-=�-=�t�{�{�K�L�Lrc���|jj|j�}|�ddlm}|d��|jjd|j||j||�S)�(internal) action method.r��
ProtocolError�QYou can't call a cached method when the object hasn't been given to the peer yet.r)r!r{r��twisted.spread.pbr��_sendMessager=r�)r*r?r@�cacheIDr�s     r�__call__zRemoteCacheMethod.__call__<sb���+�+�.�.�t�{�{�;���?�7��c��
��{�{�'�'��d�&�&�����D�"�
�	
rN)rrrrrTr�r�r�rrrr�r�+s��6��S�M�
rr�c�:�eZdZdZd�Zdefd�Zd�Zd�Zd�Z	d�Z
y	)
r}a6I am a reverse-reference to the peer's L{RemoteCache}.

    I am generated automatically when a cache is serialized.  I
    represent a reference to the client's L{RemoteCache} object that
    will represent a particular L{Cacheable}; I am the additional
    object passed to getStateToCacheAndObserveFor.
    c�.�||_||_||_y)a(internal) Initialize me.

        @param broker: a L{pb.Broker} instance.

        @param cached: a L{Cacheable} instance that this L{RemoteCacheObserver}
            corresponds to.

        @param perspective: a reference to the perspective who is observing this.
        N)r!r�r=)r*r!r�r=s    rrTzRemoteCacheObserver.__init__Ts��������&��r�returnc�x�dj|j|j|jt	|��S)Nz'<RemoteCacheObserver({}, {}, {}) at {}>)�formatr!r�r=r(r)s r�__repr__zRemoteCacheObserver.__repr__cs3��8�?�?��K�K��K�K�����t�H�	
�	
rc��t|j�dzt|j�dzzt|j�dzzS)z`Generate a hash unique to all L{RemoteCacheObserver}s for this broker/perspective/cached tripleti)r�r!r=r�r)s rr�zRemoteCacheObserver.__hash__ksH���$�+�+�
��
&��D�$�$�%��-�
/��D�K�K� �5�(�
*�	
rc�\�t|j|j|jf|�S)z-Compare me to another L{RemoteCacheObserver}.)rr!r=r�r�s  rr�zRemoteCacheObserver.__cmp__ts&���D�K�K��!1�!1�4�;�;�?��G�Grc��|jj|j�}t|t�r|jd�}|�ddlm}|d��|jjd|j||||�S)r�rerr�r�r)
r!r{r�r4r8rhr�r�r�r=)r*�_namer?r@r�r�s      r�
callRemotezRemoteCacheObserver.callRemoteysx���+�+�.�.�t�{�{�;���e�S�!��L�L��)�E��?�7��<��
��{�{�'�'��d�&�&����b�
�	
rc�Z�t||j|j|j�S)z&Get a L{pb.RemoteMethod} for this key.)r�r!r�r=)r*rAs  r�remoteMethodz RemoteCacheObserver.remoteMethod�s!�� ��d�k�k�4�;�;��@P�@P�Q�QrN)rrrrrTr8r�r�r�r�r�rrrr}r}Js.���
'�
�#�
�
�H�

� Rrr}).rr��zope.interfacerr�twisted.pythonrr�twisted.python.compatrrror
rrr
rrrrr�setCopierForClass�setCopierForClassTree�setFactoryForClass�copyTags�	copy_atom�
cache_atomr~�remote_atom�AttributeErrorrrr&r-rNrQrYr]rur�r�r�r�r�r�r}rrr�<module>r�si��
�(�1�'�1�
�
�
�+��2��2�����	�
�
�����3�>�3�4�i�4��9��>/D�L�/D�d
�W���=����&F�
�F�RY�|�Y�A+�|�A+�H7��7�t �� �Fp�*�l�p�f>�
�x��/���x��/��
�w��-��
�
��
�<�@R�@R��@Rr

Zerion Mini Shell 1.0