3
SLj+ @ sL d Z dZG dd deZG dd deZG dd deZG dd d eZd
S )a* Contains metaclasses used to create protocol service and service stub
classes from ServiceDescriptor objects at runtime.
The GeneratedServiceType and GeneratedServiceStubType metaclasses are used to
inject all useful functionality into the classes output by the protocol
compiler at compile-time.
zpetar@google.com (Petar Petrov)c @ s e Zd ZdZdZdd ZdS )GeneratedServiceTypea Metaclass for service classes created at runtime from ServiceDescriptors.
Implementations for all methods described in the Service class are added here
by this class. We also create properties to allow getting/setting all fields
in the protocol message.
The protocol compiler currently uses this metaclass to create protocol service
classes at runtime. Clients can also manually create their own classes at
runtime, as in this example:
mydescriptor = ServiceDescriptor(.....)
class MyProtoService(service.Service):
__metaclass__ = GeneratedServiceType
DESCRIPTOR = mydescriptor
myservice_instance = MyProtoService()
...
DESCRIPTORc C s. t j|krdS |t j }t|}|j| dS )a Creates a message service class.
Args:
name: Name of the class (ignored, but required by the metaclass
protocol).
bases: Base classes of the class being constructed.
dictionary: The class dictionary of the class being constructed.
dictionary[_DESCRIPTOR_KEY] must contain a ServiceDescriptor object
describing this protocol service type.
N)r _DESCRIPTOR_KEY_ServiceBuilderBuildService)clsnamebases
dictionary
descriptorZservice_builder r (/usr/lib/python3.6/service_reflection.py__init__@ s
zGeneratedServiceType.__init__N)__name__
__module____qualname____doc__r r
r r r r r * s r c s$ e Zd ZdZdZ fddZ ZS )GeneratedServiceStubTypezMetaclass for service stubs created at runtime from ServiceDescriptors.
This class has similar responsibilities as GeneratedServiceType, except that
it creates the service stub classes.
r c sB t t| j||| tj|kr"dS |tj }t|}|j| dS )a` Creates a message service stub class.
Args:
name: Name of the class (ignored, here).
bases: Base classes of the class being constructed.
dictionary: The class dictionary of the class being constructed.
dictionary[_DESCRIPTOR_KEY] must contain a ServiceDescriptor object
describing this protocol service type.
N)superr r
r _ServiceStubBuilderBuildServiceStub)r r r r r
Zservice_stub_builder) __class__r r r
^ s
z!GeneratedServiceStubType.__init__)r r r r r r
__classcell__r r )r r r T s r c @ sH e Zd ZdZdd Zdd Zdd Zdd Zd
d Zdd
Z dd Z
dS )r aD This class constructs a protocol service class using a service descriptor.
Given a service descriptor, this class constructs a class that represents
the specified service descriptor. One service builder instance constructs
exactly one service class. That means all instances of that class share the
same builder.
c C s
|| _ dS )zInitializes an instance of the service class builder.
Args:
service_descriptor: ServiceDescriptor to use when constructing the
service class.
N)r
)selfservice_descriptorr r r r
| s z_ServiceBuilder.__init__c sl fdd}| _ ||_t fdd|_d|j_ j|_ j|_x$ j j
D ]}t||j j
| qLW dS )z\Constructs the service class.
Args:
cls: The class that will be constructed.
c s j | ||||S )N)_CallMethod)srvcmethod_descriptorrpc_controllerrequestcallback)r r r _WrapCallMethod s z5_ServiceBuilder.BuildService.