File manager - Edit - /usr/lib/python3/dist-packages/landscape/lib/__pycache__/amp.cpython-310.pyc
Back
o ���c�T � @ s0 d Z ddlmZ ddlmZmZmZ ddlmZm Z ddl mZ ddlm Z ddlmZmZmZmZmZmZmZ ddlmZ G d d � d e�ZG dd� de�ZG d d� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�Z G dd� de�Z!G dd� de�Z"G dd� de�Z#G dd� 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, e Zd ZdZdd� Zdd� Zedd� �ZdS ) �MethodCallArgumentzA bpickle-compatible argument.c C � t �|�S )zSerialize an argument.)r �dumps)�self�inObject� r �3/usr/lib/python3/dist-packages/landscape/lib/amp.py�toString? � zMethodCallArgument.toStringc C r )zUnserialize an argument.)r �loads)r �inStringr r r � fromStringC r zMethodCallArgument.fromStringc C s t |�tjv S )z%Check if an argument is serializable.)�typer �dumps_table)�clsr r r r �checkG s zMethodCallArgument.checkN)�__name__� __module__�__qualname__�__doc__r r �classmethodr! r r r r r <