zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
84
85
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
U
£ý°dÀ-ã@sLdZdZGdd„deƒZGdd„deƒZGdd„deƒZGdd    „d    eƒZd
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@seZdZdZdZdd„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()
    # ...
  Ú
DESCRIPTORcCs4tj|krdS|tj}t|ƒ}| |¡||_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Ú_ServiceBuilderÚ BuildServicer)ÚclsÚnameÚbasesÚ
dictionaryÚ
descriptorZservice_builder©r úYd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\google/protobuf/service_reflection.pyÚ__init__@s
 
 
zGeneratedServiceType.__init__N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__rr r r r r r*srcs$eZdZdZdZ‡fdd„Z‡ZS)ÚGeneratedServiceStubTypezÁMetaclass for service stubs created at runtime from ServiceDescriptors.
 
  This class has similar responsibilities as GeneratedServiceType, except that
  it creates the service stub classes.
  rcsBtt|ƒ |||¡tj|kr"dS|tj}t|ƒ}| |¡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)Úsuperrr rÚ_ServiceStubBuilderÚBuildServiceStub)rrrr    r
Zservice_stub_builder©Ú    __class__r r r `s
 
 
z!GeneratedServiceStubType.__init__)rrrrrr Ú __classcell__r r rr rVsrc@sHeZdZdZdd„Zdd„Zdd„Zdd    „Zd
d „Zd d „Z    dd„Z
dS)raDThis 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.
  cCs
||_dS)z¥Initializes an instance of the service class builder.
 
    Args:
      service_descriptor: ServiceDescriptor to use when constructing the
        service class.
    N©r
©ÚselfZservice_descriptorr r r r sz_ServiceBuilder.__init__cs|‡fdd„}‡fdd„}‡fdd„}|ˆ_||_t‡fdd„ƒ|_d    |j_||_||_ˆjjD]}t    ||j
ˆ  |¡ƒq^d
S) z\Constructs the service class.
 
    Args:
      cls: The class that will be constructed.
    csˆ |||||¡S©N)Ú _CallMethod)rÚmethod_descriptorÚrpc_controllerÚrequestÚdone©Úbuilderr r Ú_WrapCallMethod”s
ÿz5_ServiceBuilder.BuildService.<locals>._WrapCallMethodcs
ˆ |¡Sr)Ú_GetRequestClass©rrr"r r Ú_WrapGetRequestClass˜sz:_ServiceBuilder.BuildService.<locals>._WrapGetRequestClasscs
ˆ |¡Sr)Ú_GetResponseClassr&r"r r Ú_WrapGetResponseClass›sz;_ServiceBuilder.BuildService.<locals>._WrapGetResponseClasscsˆjSrrr r"r r Ú<lambda> óz._ServiceBuilder.BuildService.<locals>.<lambda>zReturns the service descriptor.N) rÚ
CallMethodÚ staticmethodZ GetDescriptorrZGetRequestClassZGetResponseClassr
ÚmethodsÚsetattrrÚ_GenerateNonImplementedMethod)r#rr$r'r)Úmethodr r"r rˆs    z_ServiceBuilder.BuildServicecCs,|j|jkrtdƒ‚t||jƒ}||||ƒS)a‹Calls the method described by a given method descriptor.
 
    Args:
      srvc: Instance of the service for which this method is called.
      method_descriptor: Descriptor that represent the method to call.
      rpc_controller: RPC controller to use for this method's execution.
      request: Request protocol message.
      callback: A callback to invoke after the method has completed.
    z<CallMethod() given method descriptor for wrong service type.)Úcontaining_servicer
Ú RuntimeErrorÚgetattrr)rZsrvcrrr Úcallbackr1r r r r§s ÿ z_ServiceBuilder._CallMethodcCs|j|jkrtdƒ‚|jjS)aReturns the class of the request protocol message.
 
    Args:
      method_descriptor: Descriptor of the method for which to return the
        request protocol message class.
 
    Returns:
      A class that represents the input protocol message of the specified
      method.
    zAGetRequestClass() given method descriptor for wrong service type.)r2r
r3Z
input_typeÚ_concrete_classr&r r r r%¸s
ÿz _ServiceBuilder._GetRequestClasscCs|j|jkrtdƒ‚|jjS)aReturns the class of the response protocol message.
 
    Args:
      method_descriptor: Descriptor of the method for which to return the
        response protocol message class.
 
    Returns:
      A class that represents the output protocol message of the specified
      method.
    zBGetResponseClass() given method descriptor for wrong service type.)r2r
r3Ú output_typer6r&r r r r(Ès
ÿz!_ServiceBuilder._GetResponseClasscs‡‡fdd„S)zøGenerates and returns a method that can be set for a service methods.
 
    Args:
      method: Descriptor of the service method for which a method is to be
        generated.
 
    Returns:
      A method that can be added to the service class.
    csˆ ˆj||¡Sr)Ú_NonImplementedMethodr©Úinstrr r5©r1rr r r*âsz?_ServiceBuilder._GenerateNonImplementedMethod.<locals>.<lambda>r ©rr1r r;r r0Øs
z-_ServiceBuilder._GenerateNonImplementedMethodcCs| d|¡|dƒdS)a
The body of all methods in the generated service class.
 
    Args:
      method_name: Name of the method being executed.
      rpc_controller: RPC controller used to execute this method.
      callback: A callback which will be invoked when the method finishes.
    zMethod %s not implemented.N)Z    SetFailed)rÚ method_namerr5r r r r8åsz%_ServiceBuilder._NonImplementedMethodN) rrrrr rrr%r(r0r8r r r r rus     rc@s0eZdZdZdd„Zdd„Zdd„Zdd    „Zd
S) ra”Constructs a protocol service stub class using a service descriptor.
 
  Given a service descriptor, this class constructs a suitable stub class.
  A stub is just a type-safe wrapper around an RpcChannel which emulates a
  local implementation of the service.
 
  One service stub builder instance constructs exactly one class. It means all
  instances of that class share the same service stub builder.
  cCs
||_dS)z§Initializes an instance of the service stub class builder.
 
    Args:
      service_descriptor: ServiceDescriptor to use when constructing the
        stub class.
    Nrrr r r r ýsz_ServiceStubBuilder.__init__cCs:dd„}||_||_|jjD]}t||j| |¡ƒqdS)zYConstructs the stub class.
 
    Args:
      cls: The class that will be constructed.
    cSs
||_dSr)Ú rpc_channel)Ústubr>r r r Ú_ServiceStubInit sz>_ServiceStubBuilder.BuildServiceStub.<locals>._ServiceStubInitN)rr r
r.r/rÚ_GenerateStubMethod)rrr@r1r r r rs
 z$_ServiceStubBuilder.BuildServiceStubcsd‡‡fdd„    S)Ncsˆ |ˆ|||¡Sr)Ú _StubMethodr9r;r r r*sz9_ServiceStubBuilder._GenerateStubMethod.<locals>.<lambda>)Nr r<r r;r rAsz'_ServiceStubBuilder._GenerateStubMethodcCs|j ||||jj|¡S)a‡The body of all service methods in the generated stub class.
 
    Args:
      stub: Stub instance.
      method_descriptor: Descriptor of the invoked method.
      rpc_controller: Rpc controller to execute the method.
      request: Request protocol message.
      callback: A callback to execute when the method finishes.
    Returns:
      Response message (in case of blocking call).
    )r>r,r7r6)rr?rrr r5r r r rBs þz_ServiceStubBuilder._StubMethodN)rrrrr rrArBr r r r rñs
 
    rN)rÚ
__author__ÚtyperrÚobjectrrr r r r Ú<module>s
,|