403Webshell
Server IP : 15.235.198.142  /  Your IP : 216.73.216.190
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux ballsack 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/landscape/lib/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/landscape/lib/__pycache__/amp.cpython-312.pyc
�

�~�e{W���dZddlmZddlmZddlmZddlmZddlmZddlm	Z	ddl
mZdd	l
mZdd
l
m
Z
ddl
mZddl
mZdd
l
mZddl
mZddlmZddlmZddlmZGd�de�ZGd�de�ZGd�de
�ZGd�de
�ZGd�de�ZGd�d�ZGd�de�ZGd �d!e�Z Gd"�d#�Z!Gd$�d%e	�Z"Gd&�d'e�Z#y())a<Expose the methods of a remote object over AMP.

This module implements an AMP-based protocol for performing remote procedure
calls in a convenient and easy way. It's conceptually similar to DBus in that
it supports exposing a Python object to a remote process, with communication
happening over any Twisted-supported transport, e.g. Unix domain sockets.

For example let's say we have a Python process "A" that creates an instance of
this class::

    class Greeter(object):

        def hello(self, name):
            return f"hi {name}!"

    greeter = Greeter()

Process A can "publish" the greeter object by defining which methods are
exposed remotely and opening a Unix socket for incoming connections::

    factory = MethodCallServerFactory(greeter, ["hello"])
    reactor.listenUNIX("/some/socket/path", factory)

Then a second Python process "B" can connect to that socket and build a
"remote" greeter object, i.e. a proxy that forwards method calls to the
real greeter object living in process A::

    factory = MethodCallClientFactory()
    reactor.connectUNIX("/some/socket/path", factory)

    def got_remote(remote_greeter):
        deferred = remote_greeter.hello("Ted")
        deferred.addCallback(lambda result: ... # result == "hi Ted!")

    factory.getRemoteObject().addCallback(got_remote)

Note that when invoking a method via the remote proxy, the parameters
are required to be serializable with bpickle, so they can be sent over
the wire.

See also::

    http://twistedmatrix.com/documents/current/core/howto/amp.html

for more details about the Twisted AMP protocol.
�)�uuid4)�Deferred)�
maybeDeferred)�succeed)�ReconnectingClientFactory)�
ServerFactory)�AMP)�Argument)�Command)�CommandLocator)�Integer)�MAX_VALUE_LENGTH)�String)�xrange)�Failure)�bpicklec�,�eZdZdZd�Zd�Zed��Zy)�MethodCallArgumentzA bpickle-compatible argument.c�,�tj|�S)zSerialize an argument.)r�dumps)�self�inobjects  �3/usr/lib/python3/dist-packages/landscape/lib/amp.py�toStringzMethodCallArgument.toStringF����}�}�X�&�&�c�,�tj|�S)zUnserialize an argument.)r�loads)r�instrings  r�
fromStringzMethodCallArgument.fromStringJrrc�8�t|�tjvS)z%Check if an argument is serializable.)�typer�dumps_table)�clsrs  r�checkzMethodCallArgument.checkNs���H�~��!4�!4�4�4rN)�__name__�
__module__�__qualname__�__doc__rr �classmethodr%�rrrrCs#��(�'�'��5��5rrc��eZdZdZy)�MethodCallErrorz*Raised when a L{MethodCall} command fails.N)r&r'r(r)r+rrr-r-Ts��4rr-c�`�eZdZdZde�fde�fde�fgZde�fgZe	diZ
y)�
MethodCalla�Call a method on the object exposed by a L{MethodCallServerFactory}.

    The command arguments have the following semantics:

    - C{sequence}: An integer uniquely indentifying a the L{MethodCall}
      being issued. The name 'sequence' is a bit misleading because it's
      really a uuid, since its values in practice are not in sequential
      order, they are just random values. The name is kept just for backward
      compatibility.

    - C{method}: The name of the method to invoke on the remote object.

    - C{arguments}: A BPickled binary tuple of the form C{(args, kwargs)},
      where C{args} are the positional arguments to be passed to the method
      and C{kwargs} the keyword ones.
    �sequencesmethods	arguments�result�METHOD_CALL_ERRORN)r&r'r(r)r
r�	argumentsr�responser-�errorsr+rrr/r/XsL���$
�g�i� �	�F�H��	�v�x� ��I��.�0�1�2�H��3�
4�Frr/c�P�eZdZdZde�fde�fgZde�fgZediZ	y)�MethodCallChunkaSend a chunk of L{MethodCall} containing a portion of the arguments.

    When a the arguments of a L{MethodCall} are bigger than 64k, they get split
    in several L{MethodCallChunk}s that are buffered on the receiver side.

    The command arguments have the following semantics:

    - C{sequence}: The unique integer associated with the L{MethodCall} that
      this L{MethodCallChunk} is part of.

    - C{chunk}: A portion of the big BPickle C{arguments} string which is
      being split and buffered.
    r0schunkr1r2N)
r&r'r(r)r
rr3r4r-r5r+rrr7r7us;����w�y�)�H�f�h�+?�@�I��G�I�&�'�H��3�
4�Frr7c�d�eZdZdZd�Zejd��Zejd��Z	d�Z
y)�MethodCallReceiverz�Expose methods of a local object over AMP.

    @param obj: The Python object to be exposed.
    @param methods: The list of the object's methods that can be called
         remotely.
    c�X�tj|�||_||_i|_y�N)r�__init__�_object�_methods�_pending_chunks�r�obj�methodss   rr<zMethodCallReceiver.__init__�s&������%������
�!��rc����jj|d�}|�"|j|�dj|�}t	j
|d��\}}|j
d�}|�jvrtd|�d���t�j|�}�fd�}d	�}	t|g|��i|��}
|
j|�|
j|	�|
S)
aCall an object's method with the given arguments.

        If a connected client sends a L{MethodCall} for method C{foo_bar}, then
        the actual method C{foo_bar} of the object associated with the protocol
        will be called with the given C{args} and C{kwargs} and its return
        value delivered back to the client as response to the command.

        @param sequence: The integer that uniquely identifies the L{MethodCall}
            being received.
        @param method: The name of the object's method to call.
        @param arguments: A bpickle'd binary tuple of (args, kwargs) to be
           passed to the method. In case this L{MethodCall} has been preceded
           by one or more L{MethodCallChunk}s, C{arguments} is the last chunk
           of data.
        NrT)�as_is�utf-8zForbidden method '�'c�*��d�j|�iS�N�result)�
_check_result)rIrs �r�
handle_resultz=MethodCallReceiver.receive_method_call.<locals>.handle_result�s����d�0�0��8�9�9rc�,�t|j��r;)r-�value)�failures r�handle_failurez>MethodCallReceiver.receive_method_call.<locals>.handle_failure�s��!�'�-�-�0�0r)r?�pop�append�joinrr�decoder>r-�getattrr=r�addCallback�
addErrback)r�sequence�methodr3�chunks�args�kwargs�method_funcrKrO�deferreds`          r�receive_method_callz&MethodCallReceiver.receive_method_call�s����"�%�%�)�)�(�D�9�����M�M�)�$�����(�I��}�}�Y�d�;���f����w�'������&�!�$6�v�h�a�"@�A�A��d�l�l�F�3��	:�	1�!��>�t�>�v�>�����]�+����N�+��rc�`�|jj|g�j|�d|iS)z�Receive a part of a multi-chunk L{MethodCall}.

        Add the received C{chunk} to the buffer of the L{MethodCall} identified
        by C{sequence}.
        rI)r?�
setdefaultrQ)rrW�chunks   r�receive_method_call_chunkz,MethodCallReceiver.receive_method_call_chunk�s0��	
���'�'��"�5�<�<�U�C��(�#�#rc�F�tj|�std��|S)z�Check that the C{result} we're about to return is serializable.

        @return: The C{result} itself if valid.
        @raises: L{MethodCallError} if C{result} is not serializable.
        zNon-serializable result)rr%r-)rrIs  rrJz MethodCallReceiver._check_result�s#��"�'�'��/�!�";�<�<��
rN)r&r'r(r)r<r/�	responderr^r7rbrJr+rrr9r9�sF���"����*��*�X���$��$�rr9c�0�eZdZdZdZeZd�Zd�Zgifd�Z	y)�MethodCallSenderaCall methods on a remote object over L{AMP} and return the result.

    @param protocol: A connected C{AMP} protocol.
    @param clock: An object implementing the C{IReactorTime} interface.

    @ivar timeout: A timeout for remote method class, see L{send_method_call}.
    �<c� �||_||_yr;)�	_protocol�_clock)r�protocol�clocks   rr<zMethodCallSender.__init__�s��!�����rc�����t����fd�}�fd�}|jj|j|��|jj
|fi|��}|j
|��S)aSend an L{AMP} command that will errback in case of a timeout.

        @return: A deferred resulting in the command's response (or failure) if
            the peer responds within C{self.timeout} seconds, or that errbacks
            with a L{MethodCallError} otherwise.
        c�j���j�sy�j��j|�yr;)�active�cancel�callback)r4�callr]s ��r�handle_responsezCMethodCallSender._call_remote_with_timeout.<locals>.handle_response�s(����;�;�=���K�K�M����h�'rc�:���jtd��y)N�timeout)�errbackr-�r]s�r�handle_timeoutzBMethodCallSender._call_remote_with_timeout.<locals>.handle_timeout�s������_�Y�7�8r)rrj�	callLaterruri�
callRemote�addBoth)r�commandr[rsrxrIrrr]s      @@r�_call_remote_with_timeoutz*MethodCallSender._call_remote_with_timeout�s^����:��	(�	9��{�{�$�$�T�\�\�>�B��*����*�*�7�=�f�=������'��rc����
��tj||f�}t�j��j	d��tdt
|��j�D�cgc]}|||�jz��c}�
t�}t
�
�dkDr'�
ddD]}�fd�}|j|�|���!�
���fd�}	|j|	�|jd��|jd�|Scc}w)	a�Send a L{MethodCall} command with the given arguments.

        If a response from the server is not received within C{self.timeout}
        seconds, the returned deferred will errback with a L{MethodCallError}.

        @param method: The name of the remote method to invoke.
        @param args: The positional arguments to pass to the remote method.
        @param kwargs: The keyword arguments to pass to the remote method.

        @return: A C{Deferred} firing with the return value of the method
            invoked on the remote object. If the remote method itself returns
            a deferred, we fire with the callback value of such deferred.
        rEr�N���c��������fd�}|S)Nc�H���jjt����S)N)rWra)rirzr7)�xrarrWs ���r�
send_chunkzPMethodCallSender.send_method_call.<locals>.create_send_chunk.<locals>.send_chunk&s(���#�~�~�8�8�+�%-�"'� 9� �rr+)rWrar�rs`` �r�create_send_chunkz<MethodCallSender.send_method_call.<locals>.create_send_chunk%s����&�%rc�@���d}�jt��|��S)Nr�)rWrXr3)r}r/)�ignoredrarYrXrrWs  ����r�send_last_chunkz:MethodCallSender.send_method_call.<locals>.send_last_chunk1s0����2�J�E��1�1��!���	2��
rc��|dSrHr+)r4s r�<lambda>z3MethodCallSender.send_method_call.<locals>.<lambda>;s��H�X�,>�r)rrr�int�encoder�len�_chunk_sizerrUrq)rrXrZr[r3�irIrar�r�rYrWs``        @@r�send_method_callz!MethodCallSender.send_method_calls�����M�M�4��.�1�	��7�;�;�����w�'��
�A�s�9�~�t�/?�/?�@�
��
�a�!�d�.�.�.�/�
��
����v�;��?�����
G��&��"�"�#4�X�u�#E�F�
G�	�	���?�+����>�?�������
��E
s�#C<N)
r&r'r(r)rurr�r<r}r�r+rrrfrf�s)����G�"�K���6-/�r�6rrfc��eZdZdZd�Zy)�MethodCallServerProtocolzCReceive L{MethodCall} commands over the wire and send back results.c�F�tj|t||���y)N)�locator)r	r<r9r@s   rr<z!MethodCallServerProtocol.__init__Cs�����T�#5�c�7�#C�DrN)r&r'r(r)r<r+rrr�r�@s��M�Err�c��eZdZdZdZd�Zy)�MethodCallClientProtocolzASend L{MethodCall} commands over the wire using the AMP protocol.Nc�T�|j�|jj|�yy)z*Notify our factory that we're ready to go.N)�factory�clientConnectionMade)rs r�connectionMadez'MethodCallClientProtocol.connectionMadeLs#���<�<�#��L�L�-�-�d�3�$r)r&r'r(r)r�r�r+rrr�r�Gs��K��G�4rr�c�B�eZdZdZd�Zd�Zd
d�Zd
d�Z	d
d�Zd�Z	d	�Z
y)�RemoteObjectaAn object able to transparently call methods on a remote object.

    Any method call on a L{RemoteObject} instance will return a L{Deferred}
    resulting in the return value of the same method call performed on
    the remote object exposed by the peer.
    c�x�d|_i|_||_|jj|j�y)z�
        @param factory: The L{MethodCallClientFactory} used for connecting to
            the other peer. Look there if you need to tweak the behavior of
            this L{RemoteObject}.
        N)�_sender�_pending_requests�_factory�notifyOnConnect�_handle_connect)rr�s  rr<zRemoteObject.__init__Zs2�����!#�����
��
�
�%�%�d�&:�&:�;rc������fd�}|S)a^Return a function sending a L{MethodCall} for the given C{method}.

        When the created function is called, it sends the an appropriate
        L{MethodCall} to the remote peer passing it the arguments and
        keyword arguments it was called with, and returning a L{Deferred}
        resulting in the L{MethodCall}'s response value.
        c�D��t�}�j�|||�|Sr;)r�_send_method_call)rZr[r]rXrs   ��rr�z2RemoteObject.__getattr__.<locals>.send_method_callns#����z�H��"�"�6�4���B��Orr+)rrXr�s`` r�__getattr__zRemoteObject.__getattr__es���	�
 �rNc�4�|jj|||��}|j|j||��|j	|j
|||||��|jj�%|jjj�yy)zASend a L{MethodCall} command, adding callbacks to handle retries.)rXrZr[�rrN)	r�r�rU�_handle_resultrV�_handle_failurer��fake_connection�flush)rrXrZr[r]rrrIs       rr�zRemoteObject._send_method_callus������.�.����/�
��
	���4�.�.��t��D����� � ������
	�	
��=�=�(�(�4�

�M�M�)�)�/�/�1�5rc�J�|�|j�|j|�y)a&Handles a successful C{send_method_call} result.

        @param response: The L{MethodCall} response.
        @param deferred: The deferred that was returned to the caller.
        @param call: If not C{None}, the scheduled timeout call associated with
            the given deferred.
        N)rprq)rrIr]rrs    rr�zRemoteObject._handle_result�s!�����K�K�M����&�!rc	��|jtu}|jjdu}|s|rM||jvr|jj|�|r|j
�|j|�y|jjr`|�^ttd��}	|jjj|jj|j|	||||��}||||f|j|<y)a+Called when a L{MethodCall} command fails.

        If a failure is due to a connection error and if C{retry_on_reconnect}
        is C{True}, we will try to perform the requested L{MethodCall} again
        as soon as a new connection becomes available, giving up after the
        specified C{timeout}, if any.

        @param failure: The L{Failure} raised by the requested L{MethodCall}.
        @param name: The method name associated with the failed L{MethodCall}.
        @param args: The positional arguments of the failed L{MethodCall}.
        @param kwargs: The keyword arguments of the failed L{MethodCall}.
        @param deferred: The deferred that was returned to the caller.
        @param call: If not C{None}, the scheduled timeout call associated with
            the given deferred.
        FNrurw)
r"r-r��retryOnReconnectr�rPrprv�retryTimeoutrrlryr�)
rrNrXrZr[r]rr�is_method_call_error�
dont_retryrus
          rr�zRemoteObject._handle_failure�s���0 '�|�|��>���]�]�3�3�u�<�
��:�
�4�1�1�1��&�&�*�*�8�4�����
����W�%���=�=�%�%�$�,��o�i�8�9�G��=�=�&�&�0�0��
�
�*�*��$�$�����!�1��D�-3�D�&�$�+G����x�(rc��t||jj�|_|jjr|j�yy)zaHandles a reconnection.

        @param protocol: The newly connected protocol instance.
        N)rfr�rlr�r��_retry)rrks  rr�zRemoteObject._handle_connect�s7��
(��$�-�-�2E�2E�F����=�=�)�)��K�K�M�*rc���|jj�}|jj�|r2|j�\}\}}}}|j	|||||��|r�1yy)z*Try to perform again requests that failed.r�N)r��copy�clear�popitemr�)r�requestsr]rXrZr[rrs       rr�zRemoteObject._retry�sg���)�)�.�.�0�����$�$�&��5=�5E�5E�5G�2�H�2�v�t�V�T��"�"�6�4����"�M�rr;)r&r'r(r)r<r�r�r�r�r�r�r+rrr�r�Rs2���	<� � 2�0
"�&�5H�n�Nrr�c� �eZdZdZeZd�Zd�Zy)�MethodCallServerFactoryz@Expose a Python object using L{MethodCall} commands over C{AMP}.c� �||_||_y)a
        @param object: The object exposed by the L{MethodCallProtocol}s
            instances created by this factory.
        @param methods: A list of the names of the methods that remote peers
            are allowed to call on the C{object} that we publish.
        N)�objectrBr@s   rr<z MethodCallServerFactory.__init__�s�������rc�`�|j|j|j�}||_|Sr;)rkr�rBr��r�addrrks   r�
buildProtocolz%MethodCallServerFactory.buildProtocol�s'���=�=����d�l�l�;������rN)r&r'r(r)r�rkr<r�r+rrr�r��s��J�'�H��rr�c�\�eZdZdZdZdZeZeZ	dZ
dZdZd�Z
d�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zy)�MethodCallClientFactorya�
    Factory for L{MethodCallClientProtocol}s exposing an object or connecting
    to L{MethodCall} servers.

    When used to connect, if the connection fails or is lost the factory
    will keep retrying to establish it.

    @ivar factor: The time factor by which the delay between two subsequent
        connection retries will increase.
    @ivar maxDelay: Maximum number of seconds between connection attempts.
    @ivar protocol: The factory used to build protocol instances.
    @ivar remote: The factory used to build remote object instances.
    @ivar retryOnReconnect: If C{True}, the remote object returned by the
        C{getRemoteObject} method will retry requests that failed, as a
        result of a lost connection, as soon as a new connection is available.
    @param retryTimeout: A timeout for retrying requests, if the remote object
        can't perform them again successfully within this number of seconds,
        they will errback with a L{MethodCallError}.
    g��w�?�FNc�^�||_|j|_g|_g|_d|_y)z�
        @param object: The object exposed by the L{MethodCallProtocol}s
            instances created by this factory.
        @param reactor: The reactor used by the created protocols
            to schedule notifications and timeouts.
        N)rl�initialDelay�delay�	_connects�	_requests�_remote)rrls  rr<z MethodCallClientFactory.__init__!s-����
��&�&��
���������rc��|j�t|j�St�}|jj	|�|S)z�Get a L{RemoteObject} as soon as the connection is ready.

        @return: A C{Deferred} firing with a connected L{RemoteObject}.
        )r�rrr�rQ)rr]s  r�getRemoteObjectz'MethodCallClientFactory.getRemoteObject.s;��
�<�<�#��4�<�<�(�(��:�������h�'��rc�:�|jj|�y)zAInvoke the given C{callback} when a connection is re-established.N)r�rQ�rrqs  rr�z'MethodCallClientFactory.notifyOnConnect9��������h�'rc�:�|jj|�y)z,Remove the given C{callback} from listeners.N)r��remover�s  r�dontNotifyOnConnectz+MethodCallClientFactory.dontNotifyOnConnect=r�rc��|j�|j|�|_|jD]
}||��|j|j�y)z2Called when a newly built protocol gets connected.N)r��remoter��_fire_requests)rrkrqs   rr�z,MethodCallClientFactory.clientConnectionMadeAsK���<�<���;�;�t�,�D�L����	�H��X��	�	
���D�L�L�)rc�n�tj|||�|j�|j|�yy)z0Try to connect again or errback pending request.N)r�clientConnectionFailed�_callIDr�)r�	connector�reasons   rr�z.MethodCallClientFactory.clientConnectionFailedMs8��!�8�8����	
�
�<�<������'� rc�R�|j�tj||�}|Sr;)�
resetDelayrr�r�s   rr�z%MethodCallClientFactory.buildProtocolXs#������,�:�:�4��F���rc�`�|jdd}g|_|D]}|j|��y)zY
        Fire all pending L{getRemoteObject} deferreds with the given C{result}.
        N)r�rq)rrIr�r]s    rr�z&MethodCallClientFactory._fire_requests]s6���>�>�!�$����� �	&�H����f�%�	&r)r&r'r(r)�factor�maxDelayr�rkr�r�r�r�r�r<r�r�r�r�r�r�r�r+rrr�r��sW���( �F��H�'�H�
�F����L��O��	�(�(�
*�	(��
&rr�N)$r)�uuidr�twisted.internet.deferrrr�twisted.internet.protocolrr�twisted.protocols.ampr	r
rrr
rr�twisted.python.compatr�twisted.python.failurer�
landscape.librr�	Exceptionr-r/r7r9rfr�r�r�r�r�r+rr�<module>r�s���-�\�+�0�*�?�3�%�*�)�0�)�2�(�(�*�!�5��5�"5�i�5�5��5�:5�g�5�,M��M�`b�b�JE�s�E�4�s�4�SN�SN�l�m��*h&�7�h&r

Youez - 2016 - github.com/yon3zu
LinuXploit