�
�~�e{W � � � d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z ddl
mZ dd l
mZ dd
l
m
Z
ddl
mZ ddl
mZ dd
l
mZ ddl
mZ ddlmZ ddlmZ ddlmZ G d� de� Z G d� de� Z G d� de
� Z G d� de
� Z G d� de� Z G d� d� Z G d� de� Z G d � d!e� Z G d"� d#� Z! G d$� d%e � Z" G d&� 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 �, � e Zd ZdZd� Zd� Zed� � Zy)�MethodCallArgumentzA bpickle-compatible argument.c �, � t j |� S )zSerialize an argument.)r �dumps)�self�inobjects �3/usr/lib/python3/dist-packages/landscape/lib/amp.py�toStringzMethodCallArgument.toStringF � � ��}�}�X�&�&� c �, � t j |� S )zUnserialize an argument.)r �loads)r �instrings r �
fromStringzMethodCallArgument.fromStringJ r r c �8 � t |� t j v S )z%Check if an argument is serializable.)�typer �dumps_table)�clsr s r �checkzMethodCallArgument.checkN s � � �H�~��!4�!4�4�4r N)�__name__�
__module__�__qualname__�__doc__r r �classmethodr% � r r r r C s# � �(�'�'� �5� �5r r c � � e Zd ZdZy)�MethodCallErrorz*Raised when a L{MethodCall} command fails.N)r& |