protobuf 6.33.0__cp39-abi3-manylinux2014_s390x.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of protobuf might be problematic. Click here for more details.
- google/_upb/_message.abi3.so +0 -0
- google/protobuf/__init__.py +10 -0
- google/protobuf/any.py +53 -0
- google/protobuf/any_pb2.py +37 -0
- google/protobuf/api_pb2.py +47 -0
- google/protobuf/compiler/__init__.py +0 -0
- google/protobuf/compiler/plugin_pb2.py +46 -0
- google/protobuf/descriptor.py +1676 -0
- google/protobuf/descriptor_database.py +172 -0
- google/protobuf/descriptor_pb2.py +3363 -0
- google/protobuf/descriptor_pool.py +1370 -0
- google/protobuf/duration.py +100 -0
- google/protobuf/duration_pb2.py +37 -0
- google/protobuf/empty_pb2.py +37 -0
- google/protobuf/field_mask_pb2.py +37 -0
- google/protobuf/internal/__init__.py +7 -0
- google/protobuf/internal/api_implementation.py +136 -0
- google/protobuf/internal/builder.py +118 -0
- google/protobuf/internal/containers.py +690 -0
- google/protobuf/internal/decoder.py +1066 -0
- google/protobuf/internal/encoder.py +806 -0
- google/protobuf/internal/enum_type_wrapper.py +112 -0
- google/protobuf/internal/extension_dict.py +194 -0
- google/protobuf/internal/field_mask.py +312 -0
- google/protobuf/internal/message_listener.py +55 -0
- google/protobuf/internal/python_edition_defaults.py +5 -0
- google/protobuf/internal/python_message.py +1599 -0
- google/protobuf/internal/testing_refleaks.py +128 -0
- google/protobuf/internal/type_checkers.py +455 -0
- google/protobuf/internal/well_known_types.py +695 -0
- google/protobuf/internal/wire_format.py +245 -0
- google/protobuf/json_format.py +1111 -0
- google/protobuf/message.py +448 -0
- google/protobuf/message_factory.py +190 -0
- google/protobuf/proto.py +153 -0
- google/protobuf/proto_builder.py +111 -0
- google/protobuf/proto_json.py +83 -0
- google/protobuf/proto_text.py +129 -0
- google/protobuf/pyext/__init__.py +0 -0
- google/protobuf/pyext/cpp_message.py +49 -0
- google/protobuf/reflection.py +36 -0
- google/protobuf/runtime_version.py +104 -0
- google/protobuf/service_reflection.py +272 -0
- google/protobuf/source_context_pb2.py +37 -0
- google/protobuf/struct_pb2.py +47 -0
- google/protobuf/symbol_database.py +179 -0
- google/protobuf/testdata/__init__.py +0 -0
- google/protobuf/text_encoding.py +106 -0
- google/protobuf/text_format.py +1884 -0
- google/protobuf/timestamp.py +112 -0
- google/protobuf/timestamp_pb2.py +37 -0
- google/protobuf/type_pb2.py +53 -0
- google/protobuf/unknown_fields.py +96 -0
- google/protobuf/util/__init__.py +0 -0
- google/protobuf/wrappers_pb2.py +53 -0
- protobuf-6.33.0.dist-info/LICENSE +32 -0
- protobuf-6.33.0.dist-info/METADATA +17 -0
- protobuf-6.33.0.dist-info/RECORD +59 -0
- protobuf-6.33.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# Protocol Buffers - Google's data interchange format
|
|
2
|
+
# Copyright 2008 Google Inc. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Use of this source code is governed by a BSD-style
|
|
5
|
+
# license that can be found in the LICENSE file or at
|
|
6
|
+
# https://developers.google.com/open-source/licenses/bsd
|
|
7
|
+
|
|
8
|
+
"""Contains metaclasses used to create protocol service and service stub
|
|
9
|
+
classes from ServiceDescriptor objects at runtime.
|
|
10
|
+
|
|
11
|
+
The GeneratedServiceType and GeneratedServiceStubType metaclasses are used to
|
|
12
|
+
inject all useful functionality into the classes output by the protocol
|
|
13
|
+
compiler at compile-time.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
__author__ = 'petar@google.com (Petar Petrov)'
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class GeneratedServiceType(type):
|
|
20
|
+
|
|
21
|
+
"""Metaclass for service classes created at runtime from ServiceDescriptors.
|
|
22
|
+
|
|
23
|
+
Implementations for all methods described in the Service class are added here
|
|
24
|
+
by this class. We also create properties to allow getting/setting all fields
|
|
25
|
+
in the protocol message.
|
|
26
|
+
|
|
27
|
+
The protocol compiler currently uses this metaclass to create protocol service
|
|
28
|
+
classes at runtime. Clients can also manually create their own classes at
|
|
29
|
+
runtime, as in this example::
|
|
30
|
+
|
|
31
|
+
mydescriptor = ServiceDescriptor(.....)
|
|
32
|
+
class MyProtoService(service.Service):
|
|
33
|
+
__metaclass__ = GeneratedServiceType
|
|
34
|
+
DESCRIPTOR = mydescriptor
|
|
35
|
+
myservice_instance = MyProtoService()
|
|
36
|
+
# ...
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
_DESCRIPTOR_KEY = 'DESCRIPTOR'
|
|
40
|
+
|
|
41
|
+
def __init__(cls, name, bases, dictionary):
|
|
42
|
+
"""Creates a message service class.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
name: Name of the class (ignored, but required by the metaclass
|
|
46
|
+
protocol).
|
|
47
|
+
bases: Base classes of the class being constructed.
|
|
48
|
+
dictionary: The class dictionary of the class being constructed.
|
|
49
|
+
dictionary[_DESCRIPTOR_KEY] must contain a ServiceDescriptor object
|
|
50
|
+
describing this protocol service type.
|
|
51
|
+
"""
|
|
52
|
+
# Don't do anything if this class doesn't have a descriptor. This happens
|
|
53
|
+
# when a service class is subclassed.
|
|
54
|
+
if GeneratedServiceType._DESCRIPTOR_KEY not in dictionary:
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
descriptor = dictionary[GeneratedServiceType._DESCRIPTOR_KEY]
|
|
58
|
+
service_builder = _ServiceBuilder(descriptor)
|
|
59
|
+
service_builder.BuildService(cls)
|
|
60
|
+
cls.DESCRIPTOR = descriptor
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class GeneratedServiceStubType(GeneratedServiceType):
|
|
64
|
+
|
|
65
|
+
"""Metaclass for service stubs created at runtime from ServiceDescriptors.
|
|
66
|
+
|
|
67
|
+
This class has similar responsibilities as GeneratedServiceType, except that
|
|
68
|
+
it creates the service stub classes.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
_DESCRIPTOR_KEY = 'DESCRIPTOR'
|
|
72
|
+
|
|
73
|
+
def __init__(cls, name, bases, dictionary):
|
|
74
|
+
"""Creates a message service stub class.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
name: Name of the class (ignored, here).
|
|
78
|
+
bases: Base classes of the class being constructed.
|
|
79
|
+
dictionary: The class dictionary of the class being constructed.
|
|
80
|
+
dictionary[_DESCRIPTOR_KEY] must contain a ServiceDescriptor object
|
|
81
|
+
describing this protocol service type.
|
|
82
|
+
"""
|
|
83
|
+
super(GeneratedServiceStubType, cls).__init__(name, bases, dictionary)
|
|
84
|
+
# Don't do anything if this class doesn't have a descriptor. This happens
|
|
85
|
+
# when a service stub is subclassed.
|
|
86
|
+
if GeneratedServiceStubType._DESCRIPTOR_KEY not in dictionary:
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
descriptor = dictionary[GeneratedServiceStubType._DESCRIPTOR_KEY]
|
|
90
|
+
service_stub_builder = _ServiceStubBuilder(descriptor)
|
|
91
|
+
service_stub_builder.BuildServiceStub(cls)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class _ServiceBuilder(object):
|
|
95
|
+
|
|
96
|
+
"""This class constructs a protocol service class using a service descriptor.
|
|
97
|
+
|
|
98
|
+
Given a service descriptor, this class constructs a class that represents
|
|
99
|
+
the specified service descriptor. One service builder instance constructs
|
|
100
|
+
exactly one service class. That means all instances of that class share the
|
|
101
|
+
same builder.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
def __init__(self, service_descriptor):
|
|
105
|
+
"""Initializes an instance of the service class builder.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
service_descriptor: ServiceDescriptor to use when constructing the
|
|
109
|
+
service class.
|
|
110
|
+
"""
|
|
111
|
+
self.descriptor = service_descriptor
|
|
112
|
+
|
|
113
|
+
def BuildService(builder, cls):
|
|
114
|
+
"""Constructs the service class.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
cls: The class that will be constructed.
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
# CallMethod needs to operate with an instance of the Service class. This
|
|
121
|
+
# internal wrapper function exists only to be able to pass the service
|
|
122
|
+
# instance to the method that does the real CallMethod work.
|
|
123
|
+
# Making sure to use exact argument names from the abstract interface in
|
|
124
|
+
# service.py to match the type signature
|
|
125
|
+
def _WrapCallMethod(self, method_descriptor, rpc_controller, request, done):
|
|
126
|
+
return builder._CallMethod(self, method_descriptor, rpc_controller,
|
|
127
|
+
request, done)
|
|
128
|
+
|
|
129
|
+
def _WrapGetRequestClass(self, method_descriptor):
|
|
130
|
+
return builder._GetRequestClass(method_descriptor)
|
|
131
|
+
|
|
132
|
+
def _WrapGetResponseClass(self, method_descriptor):
|
|
133
|
+
return builder._GetResponseClass(method_descriptor)
|
|
134
|
+
|
|
135
|
+
builder.cls = cls
|
|
136
|
+
cls.CallMethod = _WrapCallMethod
|
|
137
|
+
cls.GetDescriptor = staticmethod(lambda: builder.descriptor)
|
|
138
|
+
cls.GetDescriptor.__doc__ = 'Returns the service descriptor.'
|
|
139
|
+
cls.GetRequestClass = _WrapGetRequestClass
|
|
140
|
+
cls.GetResponseClass = _WrapGetResponseClass
|
|
141
|
+
for method in builder.descriptor.methods:
|
|
142
|
+
setattr(cls, method.name, builder._GenerateNonImplementedMethod(method))
|
|
143
|
+
|
|
144
|
+
def _CallMethod(self, srvc, method_descriptor,
|
|
145
|
+
rpc_controller, request, callback):
|
|
146
|
+
"""Calls the method described by a given method descriptor.
|
|
147
|
+
|
|
148
|
+
Args:
|
|
149
|
+
srvc: Instance of the service for which this method is called.
|
|
150
|
+
method_descriptor: Descriptor that represent the method to call.
|
|
151
|
+
rpc_controller: RPC controller to use for this method's execution.
|
|
152
|
+
request: Request protocol message.
|
|
153
|
+
callback: A callback to invoke after the method has completed.
|
|
154
|
+
"""
|
|
155
|
+
if method_descriptor.containing_service != self.descriptor:
|
|
156
|
+
raise RuntimeError(
|
|
157
|
+
'CallMethod() given method descriptor for wrong service type.')
|
|
158
|
+
method = getattr(srvc, method_descriptor.name)
|
|
159
|
+
return method(rpc_controller, request, callback)
|
|
160
|
+
|
|
161
|
+
def _GetRequestClass(self, method_descriptor):
|
|
162
|
+
"""Returns the class of the request protocol message.
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
method_descriptor: Descriptor of the method for which to return the
|
|
166
|
+
request protocol message class.
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
A class that represents the input protocol message of the specified
|
|
170
|
+
method.
|
|
171
|
+
"""
|
|
172
|
+
if method_descriptor.containing_service != self.descriptor:
|
|
173
|
+
raise RuntimeError(
|
|
174
|
+
'GetRequestClass() given method descriptor for wrong service type.')
|
|
175
|
+
return method_descriptor.input_type._concrete_class
|
|
176
|
+
|
|
177
|
+
def _GetResponseClass(self, method_descriptor):
|
|
178
|
+
"""Returns the class of the response protocol message.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
method_descriptor: Descriptor of the method for which to return the
|
|
182
|
+
response protocol message class.
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
A class that represents the output protocol message of the specified
|
|
186
|
+
method.
|
|
187
|
+
"""
|
|
188
|
+
if method_descriptor.containing_service != self.descriptor:
|
|
189
|
+
raise RuntimeError(
|
|
190
|
+
'GetResponseClass() given method descriptor for wrong service type.')
|
|
191
|
+
return method_descriptor.output_type._concrete_class
|
|
192
|
+
|
|
193
|
+
def _GenerateNonImplementedMethod(self, method):
|
|
194
|
+
"""Generates and returns a method that can be set for a service methods.
|
|
195
|
+
|
|
196
|
+
Args:
|
|
197
|
+
method: Descriptor of the service method for which a method is to be
|
|
198
|
+
generated.
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
A method that can be added to the service class.
|
|
202
|
+
"""
|
|
203
|
+
return lambda inst, rpc_controller, request, callback: (
|
|
204
|
+
self._NonImplementedMethod(method.name, rpc_controller, callback))
|
|
205
|
+
|
|
206
|
+
def _NonImplementedMethod(self, method_name, rpc_controller, callback):
|
|
207
|
+
"""The body of all methods in the generated service class.
|
|
208
|
+
|
|
209
|
+
Args:
|
|
210
|
+
method_name: Name of the method being executed.
|
|
211
|
+
rpc_controller: RPC controller used to execute this method.
|
|
212
|
+
callback: A callback which will be invoked when the method finishes.
|
|
213
|
+
"""
|
|
214
|
+
rpc_controller.SetFailed('Method %s not implemented.' % method_name)
|
|
215
|
+
callback(None)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class _ServiceStubBuilder(object):
|
|
219
|
+
|
|
220
|
+
"""Constructs a protocol service stub class using a service descriptor.
|
|
221
|
+
|
|
222
|
+
Given a service descriptor, this class constructs a suitable stub class.
|
|
223
|
+
A stub is just a type-safe wrapper around an RpcChannel which emulates a
|
|
224
|
+
local implementation of the service.
|
|
225
|
+
|
|
226
|
+
One service stub builder instance constructs exactly one class. It means all
|
|
227
|
+
instances of that class share the same service stub builder.
|
|
228
|
+
"""
|
|
229
|
+
|
|
230
|
+
def __init__(self, service_descriptor):
|
|
231
|
+
"""Initializes an instance of the service stub class builder.
|
|
232
|
+
|
|
233
|
+
Args:
|
|
234
|
+
service_descriptor: ServiceDescriptor to use when constructing the
|
|
235
|
+
stub class.
|
|
236
|
+
"""
|
|
237
|
+
self.descriptor = service_descriptor
|
|
238
|
+
|
|
239
|
+
def BuildServiceStub(self, cls):
|
|
240
|
+
"""Constructs the stub class.
|
|
241
|
+
|
|
242
|
+
Args:
|
|
243
|
+
cls: The class that will be constructed.
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
def _ServiceStubInit(stub, rpc_channel):
|
|
247
|
+
stub.rpc_channel = rpc_channel
|
|
248
|
+
self.cls = cls
|
|
249
|
+
cls.__init__ = _ServiceStubInit
|
|
250
|
+
for method in self.descriptor.methods:
|
|
251
|
+
setattr(cls, method.name, self._GenerateStubMethod(method))
|
|
252
|
+
|
|
253
|
+
def _GenerateStubMethod(self, method):
|
|
254
|
+
return (lambda inst, rpc_controller, request, callback=None:
|
|
255
|
+
self._StubMethod(inst, method, rpc_controller, request, callback))
|
|
256
|
+
|
|
257
|
+
def _StubMethod(self, stub, method_descriptor,
|
|
258
|
+
rpc_controller, request, callback):
|
|
259
|
+
"""The body of all service methods in the generated stub class.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
stub: Stub instance.
|
|
263
|
+
method_descriptor: Descriptor of the invoked method.
|
|
264
|
+
rpc_controller: Rpc controller to execute the method.
|
|
265
|
+
request: Request protocol message.
|
|
266
|
+
callback: A callback to execute when the method finishes.
|
|
267
|
+
Returns:
|
|
268
|
+
Response message (in case of blocking call).
|
|
269
|
+
"""
|
|
270
|
+
return stub.rpc_channel.CallMethod(
|
|
271
|
+
method_descriptor, rpc_controller, request,
|
|
272
|
+
method_descriptor.output_type._concrete_class, callback)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# NO CHECKED-IN PROTOBUF GENCODE
|
|
4
|
+
# source: google/protobuf/source_context.proto
|
|
5
|
+
# Protobuf Python Version: 6.33.0
|
|
6
|
+
"""Generated protocol buffer code."""
|
|
7
|
+
from google.protobuf import descriptor as _descriptor
|
|
8
|
+
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
9
|
+
from google.protobuf import runtime_version as _runtime_version
|
|
10
|
+
from google.protobuf import symbol_database as _symbol_database
|
|
11
|
+
from google.protobuf.internal import builder as _builder
|
|
12
|
+
_runtime_version.ValidateProtobufRuntimeVersion(
|
|
13
|
+
_runtime_version.Domain.PUBLIC,
|
|
14
|
+
6,
|
|
15
|
+
33,
|
|
16
|
+
0,
|
|
17
|
+
'',
|
|
18
|
+
'google/protobuf/source_context.proto'
|
|
19
|
+
)
|
|
20
|
+
# @@protoc_insertion_point(imports)
|
|
21
|
+
|
|
22
|
+
_sym_db = _symbol_database.Default()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$google/protobuf/source_context.proto\x12\x0fgoogle.protobuf\",\n\rSourceContext\x12\x1b\n\tfile_name\x18\x01 \x01(\tR\x08\x66ileNameB\x8a\x01\n\x13\x63om.google.protobufB\x12SourceContextProtoP\x01Z6google.golang.org/protobuf/types/known/sourcecontextpb\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3')
|
|
28
|
+
|
|
29
|
+
_globals = globals()
|
|
30
|
+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
|
31
|
+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.source_context_pb2', _globals)
|
|
32
|
+
if not _descriptor._USE_C_DESCRIPTORS:
|
|
33
|
+
_globals['DESCRIPTOR']._loaded_options = None
|
|
34
|
+
_globals['DESCRIPTOR']._serialized_options = b'\n\023com.google.protobufB\022SourceContextProtoP\001Z6google.golang.org/protobuf/types/known/sourcecontextpb\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes'
|
|
35
|
+
_globals['_SOURCECONTEXT']._serialized_start=57
|
|
36
|
+
_globals['_SOURCECONTEXT']._serialized_end=101
|
|
37
|
+
# @@protoc_insertion_point(module_scope)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# NO CHECKED-IN PROTOBUF GENCODE
|
|
4
|
+
# source: google/protobuf/struct.proto
|
|
5
|
+
# Protobuf Python Version: 6.33.0
|
|
6
|
+
"""Generated protocol buffer code."""
|
|
7
|
+
from google.protobuf import descriptor as _descriptor
|
|
8
|
+
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
9
|
+
from google.protobuf import runtime_version as _runtime_version
|
|
10
|
+
from google.protobuf import symbol_database as _symbol_database
|
|
11
|
+
from google.protobuf.internal import builder as _builder
|
|
12
|
+
_runtime_version.ValidateProtobufRuntimeVersion(
|
|
13
|
+
_runtime_version.Domain.PUBLIC,
|
|
14
|
+
6,
|
|
15
|
+
33,
|
|
16
|
+
0,
|
|
17
|
+
'',
|
|
18
|
+
'google/protobuf/struct.proto'
|
|
19
|
+
)
|
|
20
|
+
# @@protoc_insertion_point(imports)
|
|
21
|
+
|
|
22
|
+
_sym_db = _symbol_database.Default()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1cgoogle/protobuf/struct.proto\x12\x0fgoogle.protobuf\"\x98\x01\n\x06Struct\x12;\n\x06\x66ields\x18\x01 \x03(\x0b\x32#.google.protobuf.Struct.FieldsEntryR\x06\x66ields\x1aQ\n\x0b\x46ieldsEntry\x12\x10\n\x03key\x18\x01 \x01(\tR\x03key\x12,\n\x05value\x18\x02 \x01(\x0b\x32\x16.google.protobuf.ValueR\x05value:\x02\x38\x01\"\xb2\x02\n\x05Value\x12;\n\nnull_value\x18\x01 \x01(\x0e\x32\x1a.google.protobuf.NullValueH\x00R\tnullValue\x12#\n\x0cnumber_value\x18\x02 \x01(\x01H\x00R\x0bnumberValue\x12#\n\x0cstring_value\x18\x03 \x01(\tH\x00R\x0bstringValue\x12\x1f\n\nbool_value\x18\x04 \x01(\x08H\x00R\tboolValue\x12<\n\x0cstruct_value\x18\x05 \x01(\x0b\x32\x17.google.protobuf.StructH\x00R\x0bstructValue\x12;\n\nlist_value\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.ListValueH\x00R\tlistValueB\x06\n\x04kind\";\n\tListValue\x12.\n\x06values\x18\x01 \x03(\x0b\x32\x16.google.protobuf.ValueR\x06values*\x1b\n\tNullValue\x12\x0e\n\nNULL_VALUE\x10\x00\x42\x7f\n\x13\x63om.google.protobufB\x0bStructProtoP\x01Z/google.golang.org/protobuf/types/known/structpb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3')
|
|
28
|
+
|
|
29
|
+
_globals = globals()
|
|
30
|
+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
|
31
|
+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.protobuf.struct_pb2', _globals)
|
|
32
|
+
if not _descriptor._USE_C_DESCRIPTORS:
|
|
33
|
+
_globals['DESCRIPTOR']._loaded_options = None
|
|
34
|
+
_globals['DESCRIPTOR']._serialized_options = b'\n\023com.google.protobufB\013StructProtoP\001Z/google.golang.org/protobuf/types/known/structpb\370\001\001\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes'
|
|
35
|
+
_globals['_STRUCT_FIELDSENTRY']._loaded_options = None
|
|
36
|
+
_globals['_STRUCT_FIELDSENTRY']._serialized_options = b'8\001'
|
|
37
|
+
_globals['_NULLVALUE']._serialized_start=574
|
|
38
|
+
_globals['_NULLVALUE']._serialized_end=601
|
|
39
|
+
_globals['_STRUCT']._serialized_start=50
|
|
40
|
+
_globals['_STRUCT']._serialized_end=202
|
|
41
|
+
_globals['_STRUCT_FIELDSENTRY']._serialized_start=121
|
|
42
|
+
_globals['_STRUCT_FIELDSENTRY']._serialized_end=202
|
|
43
|
+
_globals['_VALUE']._serialized_start=205
|
|
44
|
+
_globals['_VALUE']._serialized_end=511
|
|
45
|
+
_globals['_LISTVALUE']._serialized_start=513
|
|
46
|
+
_globals['_LISTVALUE']._serialized_end=572
|
|
47
|
+
# @@protoc_insertion_point(module_scope)
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# Protocol Buffers - Google's data interchange format
|
|
2
|
+
# Copyright 2008 Google Inc. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Use of this source code is governed by a BSD-style
|
|
5
|
+
# license that can be found in the LICENSE file or at
|
|
6
|
+
# https://developers.google.com/open-source/licenses/bsd
|
|
7
|
+
|
|
8
|
+
"""A database of Python protocol buffer generated symbols.
|
|
9
|
+
|
|
10
|
+
SymbolDatabase is the MessageFactory for messages generated at compile time,
|
|
11
|
+
and makes it easy to create new instances of a registered type, given only the
|
|
12
|
+
type's protocol buffer symbol name.
|
|
13
|
+
|
|
14
|
+
Example usage::
|
|
15
|
+
|
|
16
|
+
db = symbol_database.SymbolDatabase()
|
|
17
|
+
|
|
18
|
+
# Register symbols of interest, from one or multiple files.
|
|
19
|
+
db.RegisterFileDescriptor(my_proto_pb2.DESCRIPTOR)
|
|
20
|
+
db.RegisterMessage(my_proto_pb2.MyMessage)
|
|
21
|
+
db.RegisterEnumDescriptor(my_proto_pb2.MyEnum.DESCRIPTOR)
|
|
22
|
+
|
|
23
|
+
# The database can be used as a MessageFactory, to generate types based on
|
|
24
|
+
# their name:
|
|
25
|
+
types = db.GetMessages(['my_proto.proto'])
|
|
26
|
+
my_message_instance = types['MyMessage']()
|
|
27
|
+
|
|
28
|
+
# The database's underlying descriptor pool can be queried, so it's not
|
|
29
|
+
# necessary to know a type's filename to be able to generate it:
|
|
30
|
+
filename = db.pool.FindFileContainingSymbol('MyMessage')
|
|
31
|
+
my_message_instance = db.GetMessages([filename])['MyMessage']()
|
|
32
|
+
|
|
33
|
+
# This functionality is also provided directly via a convenience method:
|
|
34
|
+
my_message_instance = db.GetSymbol('MyMessage')()
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
import warnings
|
|
38
|
+
|
|
39
|
+
from google.protobuf.internal import api_implementation
|
|
40
|
+
from google.protobuf import descriptor_pool
|
|
41
|
+
from google.protobuf import message_factory
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class SymbolDatabase():
|
|
45
|
+
"""A database of Python generated symbols."""
|
|
46
|
+
|
|
47
|
+
# local cache of registered classes.
|
|
48
|
+
_classes = {}
|
|
49
|
+
|
|
50
|
+
def __init__(self, pool=None):
|
|
51
|
+
"""Initializes a new SymbolDatabase."""
|
|
52
|
+
self.pool = pool or descriptor_pool.DescriptorPool()
|
|
53
|
+
|
|
54
|
+
def RegisterMessage(self, message):
|
|
55
|
+
"""Registers the given message type in the local database.
|
|
56
|
+
|
|
57
|
+
Calls to GetSymbol() and GetMessages() will return messages registered here.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
message: A :class:`google.protobuf.message.Message` subclass (or
|
|
61
|
+
instance); its descriptor will be registered.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
The provided message.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
desc = message.DESCRIPTOR
|
|
68
|
+
self._classes[desc] = message
|
|
69
|
+
self.RegisterMessageDescriptor(desc)
|
|
70
|
+
return message
|
|
71
|
+
|
|
72
|
+
def RegisterMessageDescriptor(self, message_descriptor):
|
|
73
|
+
"""Registers the given message descriptor in the local database.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
message_descriptor (Descriptor): the message descriptor to add.
|
|
77
|
+
"""
|
|
78
|
+
if api_implementation.Type() == 'python':
|
|
79
|
+
# pylint: disable=protected-access
|
|
80
|
+
self.pool._AddDescriptor(message_descriptor)
|
|
81
|
+
|
|
82
|
+
def RegisterEnumDescriptor(self, enum_descriptor):
|
|
83
|
+
"""Registers the given enum descriptor in the local database.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
enum_descriptor (EnumDescriptor): The enum descriptor to register.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
EnumDescriptor: The provided descriptor.
|
|
90
|
+
"""
|
|
91
|
+
if api_implementation.Type() == 'python':
|
|
92
|
+
# pylint: disable=protected-access
|
|
93
|
+
self.pool._AddEnumDescriptor(enum_descriptor)
|
|
94
|
+
return enum_descriptor
|
|
95
|
+
|
|
96
|
+
def RegisterServiceDescriptor(self, service_descriptor):
|
|
97
|
+
"""Registers the given service descriptor in the local database.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
service_descriptor (ServiceDescriptor): the service descriptor to
|
|
101
|
+
register.
|
|
102
|
+
"""
|
|
103
|
+
if api_implementation.Type() == 'python':
|
|
104
|
+
# pylint: disable=protected-access
|
|
105
|
+
self.pool._AddServiceDescriptor(service_descriptor)
|
|
106
|
+
|
|
107
|
+
def RegisterFileDescriptor(self, file_descriptor):
|
|
108
|
+
"""Registers the given file descriptor in the local database.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
file_descriptor (FileDescriptor): The file descriptor to register.
|
|
112
|
+
"""
|
|
113
|
+
if api_implementation.Type() == 'python':
|
|
114
|
+
# pylint: disable=protected-access
|
|
115
|
+
self.pool._InternalAddFileDescriptor(file_descriptor)
|
|
116
|
+
|
|
117
|
+
def GetSymbol(self, symbol):
|
|
118
|
+
"""Tries to find a symbol in the local database.
|
|
119
|
+
|
|
120
|
+
Currently, this method only returns message.Message instances, however, if
|
|
121
|
+
may be extended in future to support other symbol types.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
symbol (str): a protocol buffer symbol.
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
A Python class corresponding to the symbol.
|
|
128
|
+
|
|
129
|
+
Raises:
|
|
130
|
+
KeyError: if the symbol could not be found.
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
return self._classes[self.pool.FindMessageTypeByName(symbol)]
|
|
134
|
+
|
|
135
|
+
def GetMessages(self, files):
|
|
136
|
+
# TODO: Fix the differences with MessageFactory.
|
|
137
|
+
"""Gets all registered messages from a specified file.
|
|
138
|
+
|
|
139
|
+
Only messages already created and registered will be returned; (this is the
|
|
140
|
+
case for imported _pb2 modules)
|
|
141
|
+
But unlike MessageFactory, this version also returns already defined nested
|
|
142
|
+
messages, but does not register any message extensions.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
files (list[str]): The file names to extract messages from.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
A dictionary mapping proto names to the message classes.
|
|
149
|
+
|
|
150
|
+
Raises:
|
|
151
|
+
KeyError: if a file could not be found.
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
def _GetAllMessages(desc):
|
|
155
|
+
"""Walk a message Descriptor and recursively yields all message names."""
|
|
156
|
+
yield desc
|
|
157
|
+
for msg_desc in desc.nested_types:
|
|
158
|
+
for nested_desc in _GetAllMessages(msg_desc):
|
|
159
|
+
yield nested_desc
|
|
160
|
+
|
|
161
|
+
result = {}
|
|
162
|
+
for file_name in files:
|
|
163
|
+
file_desc = self.pool.FindFileByName(file_name)
|
|
164
|
+
for msg_desc in file_desc.message_types_by_name.values():
|
|
165
|
+
for desc in _GetAllMessages(msg_desc):
|
|
166
|
+
try:
|
|
167
|
+
result[desc.full_name] = self._classes[desc]
|
|
168
|
+
except KeyError:
|
|
169
|
+
# This descriptor has no registered class, skip it.
|
|
170
|
+
pass
|
|
171
|
+
return result
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
_DEFAULT = SymbolDatabase(pool=descriptor_pool.Default())
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def Default():
|
|
178
|
+
"""Returns the default SymbolDatabase."""
|
|
179
|
+
return _DEFAULT
|
|
File without changes
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Protocol Buffers - Google's data interchange format
|
|
2
|
+
# Copyright 2008 Google Inc. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Use of this source code is governed by a BSD-style
|
|
5
|
+
# license that can be found in the LICENSE file or at
|
|
6
|
+
# https://developers.google.com/open-source/licenses/bsd
|
|
7
|
+
|
|
8
|
+
"""Encoding related utilities."""
|
|
9
|
+
import re
|
|
10
|
+
|
|
11
|
+
def _AsciiIsPrint(i):
|
|
12
|
+
return i >= 32 and i < 127
|
|
13
|
+
|
|
14
|
+
def _MakeStrEscapes():
|
|
15
|
+
ret = {}
|
|
16
|
+
for i in range(0, 128):
|
|
17
|
+
if not _AsciiIsPrint(i):
|
|
18
|
+
ret[i] = r'\%03o' % i
|
|
19
|
+
ret[ord('\t')] = r'\t' # optional escape
|
|
20
|
+
ret[ord('\n')] = r'\n' # optional escape
|
|
21
|
+
ret[ord('\r')] = r'\r' # optional escape
|
|
22
|
+
ret[ord('"')] = r'\"' # necessary escape
|
|
23
|
+
ret[ord('\'')] = r"\'" # optional escape
|
|
24
|
+
ret[ord('\\')] = r'\\' # necessary escape
|
|
25
|
+
return ret
|
|
26
|
+
|
|
27
|
+
# Maps int -> char, performing string escapes.
|
|
28
|
+
_str_escapes = _MakeStrEscapes()
|
|
29
|
+
|
|
30
|
+
# Maps int -> char, performing byte escaping and string escapes
|
|
31
|
+
_byte_escapes = {i: chr(i) for i in range(0, 256)}
|
|
32
|
+
_byte_escapes.update(_str_escapes)
|
|
33
|
+
_byte_escapes.update({i: r'\%03o' % i for i in range(128, 256)})
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _DecodeUtf8EscapeErrors(text_bytes):
|
|
37
|
+
ret = ''
|
|
38
|
+
while text_bytes:
|
|
39
|
+
try:
|
|
40
|
+
ret += text_bytes.decode('utf-8').translate(_str_escapes)
|
|
41
|
+
text_bytes = ''
|
|
42
|
+
except UnicodeDecodeError as e:
|
|
43
|
+
ret += text_bytes[:e.start].decode('utf-8').translate(_str_escapes)
|
|
44
|
+
ret += _byte_escapes[text_bytes[e.start]]
|
|
45
|
+
text_bytes = text_bytes[e.start+1:]
|
|
46
|
+
return ret
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def CEscape(text, as_utf8) -> str:
|
|
50
|
+
"""Escape a bytes string for use in an text protocol buffer.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
text: A byte string to be escaped.
|
|
54
|
+
as_utf8: Specifies if result may contain non-ASCII characters.
|
|
55
|
+
In Python 3 this allows unescaped non-ASCII Unicode characters.
|
|
56
|
+
In Python 2 the return value will be valid UTF-8 rather than only ASCII.
|
|
57
|
+
Returns:
|
|
58
|
+
Escaped string (str).
|
|
59
|
+
"""
|
|
60
|
+
# Python's text.encode() 'string_escape' or 'unicode_escape' codecs do not
|
|
61
|
+
# satisfy our needs; they encodes unprintable characters using two-digit hex
|
|
62
|
+
# escapes whereas our C++ unescaping function allows hex escapes to be any
|
|
63
|
+
# length. So, "\0011".encode('string_escape') ends up being "\\x011", which
|
|
64
|
+
# will be decoded in C++ as a single-character string with char code 0x11.
|
|
65
|
+
text_is_unicode = isinstance(text, str)
|
|
66
|
+
if as_utf8:
|
|
67
|
+
if text_is_unicode:
|
|
68
|
+
return text.translate(_str_escapes)
|
|
69
|
+
else:
|
|
70
|
+
return _DecodeUtf8EscapeErrors(text)
|
|
71
|
+
else:
|
|
72
|
+
if text_is_unicode:
|
|
73
|
+
text = text.encode('utf-8')
|
|
74
|
+
return ''.join([_byte_escapes[c] for c in text])
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
_CUNESCAPE_HEX = re.compile(r'(\\+)x([0-9a-fA-F])(?![0-9a-fA-F])')
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def CUnescape(text: str) -> bytes:
|
|
81
|
+
"""Unescape a text string with C-style escape sequences to UTF-8 bytes.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
text: The data to parse in a str.
|
|
85
|
+
Returns:
|
|
86
|
+
A byte string.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
def ReplaceHex(m):
|
|
90
|
+
# Only replace the match if the number of leading back slashes is odd. i.e.
|
|
91
|
+
# the slash itself is not escaped.
|
|
92
|
+
if len(m.group(1)) & 1:
|
|
93
|
+
return m.group(1) + 'x0' + m.group(2)
|
|
94
|
+
return m.group(0)
|
|
95
|
+
|
|
96
|
+
# This is required because the 'string_escape' encoding doesn't
|
|
97
|
+
# allow single-digit hex escapes (like '\xf').
|
|
98
|
+
result = _CUNESCAPE_HEX.sub(ReplaceHex, text)
|
|
99
|
+
|
|
100
|
+
# Replaces Unicode escape sequences with their character equivalents.
|
|
101
|
+
result = result.encode('raw_unicode_escape').decode('raw_unicode_escape')
|
|
102
|
+
# Encode Unicode characters as UTF-8, then decode to Latin-1 escaping
|
|
103
|
+
# unprintable characters.
|
|
104
|
+
result = result.encode('utf-8').decode('unicode_escape')
|
|
105
|
+
# Convert Latin-1 text back to a byte string (latin-1 codec also works here).
|
|
106
|
+
return result.encode('latin-1')
|