Skip to content

service_reflection

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.

GeneratedServiceStubType

Bases: GeneratedServiceType

Metaclass for service stubs created at runtime from ServiceDescriptors.

This class has similar responsibilities as GeneratedServiceType, except that it creates the service stub classes.

Source code in client/ayon_nuke/vendor/google/protobuf/service_reflection.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
class GeneratedServiceStubType(GeneratedServiceType):

  """Metaclass for service stubs created at runtime from ServiceDescriptors.

  This class has similar responsibilities as GeneratedServiceType, except that
  it creates the service stub classes.
  """

  _DESCRIPTOR_KEY = 'DESCRIPTOR'

  def __init__(cls, name, bases, dictionary):
    """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.
    """
    super(GeneratedServiceStubType, cls).__init__(name, bases, dictionary)
    # Don't do anything if this class doesn't have a descriptor. This happens
    # when a service stub is subclassed.
    if GeneratedServiceStubType._DESCRIPTOR_KEY not in dictionary:
      return

    descriptor = dictionary[GeneratedServiceStubType._DESCRIPTOR_KEY]
    service_stub_builder = _ServiceStubBuilder(descriptor)
    service_stub_builder.BuildServiceStub(cls)

__init__(name, bases, dictionary)

Creates a message service stub class.

Parameters:

Name Type Description Default
name

Name of the class (ignored, here).

required
bases

Base classes of the class being constructed.

required
dictionary

The class dictionary of the class being constructed. dictionary[_DESCRIPTOR_KEY] must contain a ServiceDescriptor object describing this protocol service type.

required
Source code in client/ayon_nuke/vendor/google/protobuf/service_reflection.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def __init__(cls, name, bases, dictionary):
  """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.
  """
  super(GeneratedServiceStubType, cls).__init__(name, bases, dictionary)
  # Don't do anything if this class doesn't have a descriptor. This happens
  # when a service stub is subclassed.
  if GeneratedServiceStubType._DESCRIPTOR_KEY not in dictionary:
    return

  descriptor = dictionary[GeneratedServiceStubType._DESCRIPTOR_KEY]
  service_stub_builder = _ServiceStubBuilder(descriptor)
  service_stub_builder.BuildServiceStub(cls)

GeneratedServiceType

Bases: type

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() # ...

Source code in client/ayon_nuke/vendor/google/protobuf/service_reflection.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class GeneratedServiceType(type):

  """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()
    # ...
  """

  _DESCRIPTOR_KEY = 'DESCRIPTOR'

  def __init__(cls, name, bases, dictionary):
    """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.
    """
    # Don't do anything if this class doesn't have a descriptor. This happens
    # when a service class is subclassed.
    if GeneratedServiceType._DESCRIPTOR_KEY not in dictionary:
      return

    descriptor = dictionary[GeneratedServiceType._DESCRIPTOR_KEY]
    service_builder = _ServiceBuilder(descriptor)
    service_builder.BuildService(cls)
    cls.DESCRIPTOR = descriptor

__init__(name, bases, dictionary)

Creates a message service class.

Parameters:

Name Type Description Default
name

Name of the class (ignored, but required by the metaclass protocol).

required
bases

Base classes of the class being constructed.

required
dictionary

The class dictionary of the class being constructed. dictionary[_DESCRIPTOR_KEY] must contain a ServiceDescriptor object describing this protocol service type.

required
Source code in client/ayon_nuke/vendor/google/protobuf/service_reflection.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def __init__(cls, name, bases, dictionary):
  """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.
  """
  # Don't do anything if this class doesn't have a descriptor. This happens
  # when a service class is subclassed.
  if GeneratedServiceType._DESCRIPTOR_KEY not in dictionary:
    return

  descriptor = dictionary[GeneratedServiceType._DESCRIPTOR_KEY]
  service_builder = _ServiceBuilder(descriptor)
  service_builder.BuildService(cls)
  cls.DESCRIPTOR = descriptor