AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /proc/thread-self/root/usr/lib/python3/dist-packages/landscape/lib/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /proc/thread-self/root/usr/lib/python3/dist-packages/landscape/lib/__pycache__/amp.cpython-310.pyc
o

���c�T�@s0dZddlmZddlmZmZmZddlmZm	Z	ddl
mZddlm
Z
ddlmZmZmZmZmZmZmZddlmZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"Gdd�de�Z#Gdd�de	�Z$dS) 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 "hi %s!" % 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)�
ServerFactory�ReconnectingClientFactory)�Failure)�xrange)�Argument�String�Integer�Command�AMP�MAX_VALUE_LENGTH�CommandLocator)�bpicklec@s,eZdZdZdd�Zdd�Zedd��ZdS)	�MethodCallArgumentzA bpickle-compatible argument.cC�
t�|�S)zSerialize an argument.)r�dumps)�self�inObject�r�3/usr/lib/python3/dist-packages/landscape/lib/amp.py�toString?�
zMethodCallArgument.toStringcCr)zUnserialize an argument.)r�loads)r�inStringrrr�
fromStringCrzMethodCallArgument.fromStringcCst|�tjvS)z%Check if an argument is serializable.)�typer�dumps_table)�clsrrrr�checkGszMethodCallArgument.checkN)�__name__�
__module__�__qualname__�__doc__rr�classmethodr!rrrrr<src@seZdZdZdS)�MethodCallErrorz*Raised when a L{MethodCall} command fails.N)r"r#r$r%rrrrr'Msr'c@s@eZdZdZde�fde�fde�fgZde�fgZe	diZ
dS)�
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'�errorsrrrrr(Qs�r(c@s8eZdZdZde�fde�fgZde�fgZediZ	dS)�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.
    r)schunkr*r+N)
r"r#r$r%rrr,r-r'r.rrrrr/ls�r/c@s<eZdZdZdd�Zejdd��Zejdd��Z	dd	�Z
d
S)�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.
    cCs t�|�||_||_i|_dS�N)r�__init__�_object�_methods�_pending_chunks�r�obj�methodsrrrr2�s

zMethodCallReceiver.__init__cs��j�|d�}|dur|�|�d�|�}tj|dd�\}}|�d�}|�jvr.td|��t	�j
|�}�fdd�}d	d
�}	t|g|�Ri|��}
|
�|�|
�
|	�|
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.
        N�T)�as_is�utf-8zForbidden method '%s'csd��|�iS�N�result)�
_check_result)r=�rrr�
handle_result�sz=MethodCallReceiver.receive_method_call.<locals>.handle_resultcSs
t|j��r1)r'�value)�failurerrr�handle_failure�s
z>MethodCallReceiver.receive_method_call.<locals>.handle_failure)r5�pop�append�joinrr�decoder4r'�getattrr3r�addCallback�
addErrback)r�sequence�methodr,�chunks�args�kwargs�method_funcr@rC�deferredrr?r�receive_method_call�s





z&MethodCallReceiver.receive_method_callcCs|j�|g��|�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}.
        r=)r5�
setdefaultrE)rrK�chunkrrr�receive_method_call_chunk�sz,MethodCallReceiver.receive_method_call_chunkcCst�|�s	td��|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')rr=rrrr>�s
z MethodCallReceiver._check_resultN)r"r#r$r%r2r(�	responderrRr/rUr>rrrrr0�s
,
	r0c@s6eZdZdZdZeZdd�Zdd�Zgifdd�Z	d	S)
�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}.
    �<cCs||_||_dSr1)�	_protocol�_clock)r�protocol�clockrrrr2�s
zMethodCallSender.__init__csRt����fdd�}�fdd�}|j�|j|��|jj|fi|��}|�|��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.
        cs"���sdS�����|�dSr1)�active�cancel�callback�r-��callrQrr�handle_response�szCMethodCallSender._call_remote_with_timeout.<locals>.handle_responsecs��td��dS)N�timeout)�errbackr'r�rQrr�handle_timeout�szBMethodCallSender._call_remote_with_timeout.<locals>.handle_timeout)rrZ�	callLaterrdrY�
callRemote�addBoth)r�commandrOrcrgr=rrar�_call_remote_with_timeout�s
z*MethodCallSender._call_remote_with_timeoutcs�t�||f��t�j���d����fdd�tdt���j�D��t�}t��dkrA�dd�D]}�fdd	�}|�	|�|��q0����fd
d�}|�	|�|�	dd
��|�
d�|S)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.
        r;csg|]}�||�j��qSr)�_chunk_size)�.0�i)r,rrr�
<listcomp>s�z5MethodCallSender.send_method_call.<locals>.<listcomp>r�N���cs���fdd�}|S)Ncs�jjt��d�S)N)rKrT)rYrir/)�x)rTrrKrr�<lambda>s�zNMethodCallSender.send_method_call.<locals>.create_send_chunk.<locals>.<lambda>r)rKrT�
send_chunkr?)rTrKr�create_send_chunksz<MethodCallSender.send_method_call.<locals>.create_send_chunkcs�d}�jt��|d�S)Nrr)rKrLr,)rlr()�ignoredrT)rMrLrrKrr�send_last_chunk!s�z:MethodCallSender.send_method_call.<locals>.send_last_chunkcSs|dSr<rr`rrrrt'sz3MethodCallSender.send_method_call.<locals>.<lambda>)rrr�int�encoder	�lenrmrrIr_)rrLrNrOr=rTrvrxr)r,rMrLrrKr�send_method_call�s 
�

z!MethodCallSender.send_method_callN)
r"r#r$r%rdrrmr2rlr|rrrrrW�srWc@seZdZdZdd�ZdS)�MethodCallServerProtocolzCReceive L{MethodCall} commands over the wire and send back results.cCstj|t||�d�dS)N)�locator)rr2r0r6rrrr2/sz!MethodCallServerProtocol.__init__N)r"r#r$r%r2rrrrr},sr}c@seZdZdZdZdd�ZdS)�MethodCallClientProtocolzASend L{MethodCall} commands over the wire using the AMP protocol.NcCs|jdur
|j�|�dSdS)z*Notify our factory that we're ready to go.N)�factory�clientConnectionMader?rrr�connectionMade8s
�z'MethodCallClientProtocol.connectionMade)r"r#r$r%r�r�rrrrr3src@sPeZdZdZdd�Zdd�Zddd�Zdd	d
�Z	ddd�Zd
d�Z	dd�Z
dS)�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.
    cCs$d|_i|_||_|j�|j�dS)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�rrrr2FszRemoteObject.__init__cs��fdd�}|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.
        cst�}���|||�|Sr1)r�_send_method_call)rNrOrQ�rLrrrr|Ysz2RemoteObject.__getattr__.<locals>.send_method_callr)rrLr|rr�r�__getattr__QszRemoteObject.__getattr__NcCs\|jj|||d�}|j|j||d�|j|j|||||d�|jjdur,|jj��dSdS)zASend a L{MethodCall} command, adding callbacks to handle retries.)rLrNrO�rbN)	r�r|rI�_handle_resultrJ�_handle_failurer��fake_connection�flush)rrLrNrOrQrbr=rrrr�`s���zRemoteObject._send_method_callcCs|dur|��|�|�dS)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)r^r_)rr=rQrbrrrr�pszRemoteObject._handle_resultc
	Cs�|jtu}|jjdu}|s|r'||jvr|j�|�|r |��|�|�dS|jjrF|durFt	td��}	|jj
j|jj|j|	||||d�}||||f|j|<dS)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.
        FNrdrf)
rr'r��retryOnReconnectr�rDr^re�retryTimeoutrr\rhr�)
rrBrLrNrOrQrb�is_method_call_error�
dont_retryrdrrrr�|s"


�zRemoteObject._handle_failurecCs(t||jj�|_|jjr|��dSdS)zaHandles a reconnection.

        @param protocol: The newly connected protocol instance.
        N)rWr�r\r�r��_retry)rr[rrrr��s�zRemoteObject._handle_connectcCsL|j��}|j��|r$|��\}\}}}}|j|||||d�|sdSdS)z*Try to perform again requests that failed.r�N)r��copy�clear�popitemr�)r�requestsrQrLrNrOrbrrrr��s

�zRemoteObject._retryr1)r"r#r$r%r2r�r�r�r�r�r�rrrrr�>s


�+	r�c@s$eZdZdZeZdd�Zdd�ZdS)�MethodCallServerFactoryz@Expose a Python object using L{MethodCall} commands over C{AMP}.cCs||_||_dS)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)�objectr8r6rrrr2�s
z MethodCallServerFactory.__init__cCs|�|j|j�}||_|Sr1)r[r�r8r��r�addrr[rrr�
buildProtocol�sz%MethodCallServerFactory.buildProtocolN)r"r#r$r%r}r[r2r�rrrrr��s

r�c@sleZdZdZdZdZeZeZ	dZ
dZdZdd�Z
dd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�ZdS)�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�?�FNcCs$||_|j|_g|_g|_d|_dS)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)r\�initialDelay�delay�	_connects�	_requests�_remote)rr\rrrr2�s

z MethodCallClientFactory.__init__cCs*|jdur
t|j�St�}|j�|�|S)z�Get a L{RemoteObject} as soon as the connection is ready.

        @return: A C{Deferred} firing with a connected L{RemoteObject}.
        N)r�rrr�rE)rrQrrr�getRemoteObjects


z'MethodCallClientFactory.getRemoteObjectcC�|j�|�dS)zAInvoke the given C{callback} when a connection is re-established.N)r�rE�rr_rrrr��z'MethodCallClientFactory.notifyOnConnectcCr�)z,Remove the given C{callback} from listeners.N)r��remover�rrr�dontNotifyOnConnectr�z+MethodCallClientFactory.dontNotifyOnConnectcCs:|jdur|�|�|_|jD]}||�q|�|j�dS)z2Called when a newly built protocol gets connected.N)r��remoter��_fire_requests)rr[r_rrrr�s



z,MethodCallClientFactory.clientConnectionMadecCs*t�|||�|jdur|�|�dSdS)z0Try to connect again or errback pending request.N)r�clientConnectionFailed�_callIDr�)r�	connector�reasonrrrr�$s�
�z.MethodCallClientFactory.clientConnectionFailedcCs|��t�||�}|Sr1)�
resetDelayrr�r�rrrr�,sz%MethodCallClientFactory.buildProtocolcCs,|jdd�}g|_|D]}|�|�qdS)zY
        Fire all pending L{getRemoteObject} deferreds with the given C{result}.
        N)r�r_)rr=r�rQrrrr�1s
�z&MethodCallClientFactory._fire_requests)r"r#r$r%�factor�maxDelayrr[r�r�r�r�r�r2r�r�r�r�r�r�r�rrrrr��s"
r�N)%r%�uuidr�twisted.internet.deferrrr�twisted.internet.protocolrr�twisted.python.failurer�twisted.python.compatr	�twisted.protocols.ampr
rrr
rrr�
landscape.librr�	Exceptionr'r(r/r0r�rWr}rr�r�r�rrrr�<module>s(.$PY

Anon7 - 2022
AnonSec Team