protobuf 5.29.0rc3__py3-none-any.whl → 6.33.3__py3-none-any.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/protobuf/__init__.py +1 -1
- google/protobuf/any.py +15 -1
- google/protobuf/any_pb2.py +5 -5
- google/protobuf/api_pb2.py +15 -11
- google/protobuf/compiler/plugin_pb2.py +5 -5
- google/protobuf/descriptor.py +413 -248
- google/protobuf/descriptor_database.py +22 -4
- google/protobuf/descriptor_pb2.py +320 -120
- google/protobuf/descriptor_pool.py +31 -13
- google/protobuf/duration_pb2.py +5 -5
- google/protobuf/empty_pb2.py +5 -5
- google/protobuf/field_mask_pb2.py +5 -5
- google/protobuf/internal/api_implementation.py +0 -6
- google/protobuf/internal/builder.py +4 -3
- google/protobuf/internal/containers.py +13 -0
- google/protobuf/internal/decoder.py +163 -133
- google/protobuf/internal/extension_dict.py +3 -3
- google/protobuf/internal/field_mask.py +6 -4
- google/protobuf/internal/python_edition_defaults.py +1 -1
- google/protobuf/internal/python_message.py +86 -70
- google/protobuf/internal/testing_refleaks.py +11 -2
- google/protobuf/internal/type_checkers.py +52 -5
- google/protobuf/internal/well_known_types.py +63 -46
- google/protobuf/json_format.py +113 -71
- google/protobuf/message.py +26 -0
- google/protobuf/message_factory.py +16 -63
- google/protobuf/proto.py +38 -1
- google/protobuf/proto_text.py +129 -0
- google/protobuf/reflection.py +0 -49
- google/protobuf/runtime_version.py +9 -29
- google/protobuf/source_context_pb2.py +5 -5
- google/protobuf/struct_pb2.py +5 -5
- google/protobuf/symbol_database.py +0 -18
- google/protobuf/text_format.py +49 -29
- google/protobuf/timestamp_pb2.py +5 -5
- google/protobuf/type_pb2.py +5 -5
- google/protobuf/unknown_fields.py +3 -4
- google/protobuf/wrappers_pb2.py +5 -5
- {protobuf-5.29.0rc3.dist-info → protobuf-6.33.3.dist-info}/METADATA +3 -3
- protobuf-6.33.3.dist-info/RECORD +58 -0
- google/protobuf/internal/_parameterized.py +0 -420
- google/protobuf/service.py +0 -213
- protobuf-5.29.0rc3.dist-info/RECORD +0 -59
- {protobuf-5.29.0rc3.dist-info → protobuf-6.33.3.dist-info}/LICENSE +0 -0
- {protobuf-5.29.0rc3.dist-info → protobuf-6.33.3.dist-info}/WHEEL +0 -0
google/protobuf/descriptor.py
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
# https://developers.google.com/open-source/licenses/bsd
|
|
7
7
|
|
|
8
8
|
"""Descriptors essentially contain exactly the information found in a .proto
|
|
9
|
+
|
|
9
10
|
file, in types that make this information accessible in Python.
|
|
10
11
|
"""
|
|
11
12
|
|
|
@@ -50,6 +51,7 @@ if _USE_C_DESCRIPTORS:
|
|
|
50
51
|
if isinstance(obj, cls._C_DESCRIPTOR_CLASS):
|
|
51
52
|
return True
|
|
52
53
|
return False
|
|
54
|
+
|
|
53
55
|
else:
|
|
54
56
|
# The standard metaclass; nothing changes.
|
|
55
57
|
DescriptorMetaclass = abc.ABCMeta
|
|
@@ -73,15 +75,18 @@ class _Lock(object):
|
|
|
73
75
|
_lock = threading.Lock()
|
|
74
76
|
|
|
75
77
|
|
|
76
|
-
def _Deprecated(
|
|
78
|
+
def _Deprecated(
|
|
79
|
+
name,
|
|
80
|
+
alternative='get/find descriptors from generated code or query the descriptor_pool',
|
|
81
|
+
):
|
|
77
82
|
if _Deprecated.count > 0:
|
|
78
83
|
_Deprecated.count -= 1
|
|
79
84
|
warnings.warn(
|
|
80
|
-
'Call to deprecated
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
'Call to deprecated %s, use %s instead.' % (name, alternative),
|
|
86
|
+
category=DeprecationWarning,
|
|
87
|
+
stacklevel=3,
|
|
88
|
+
)
|
|
89
|
+
|
|
85
90
|
|
|
86
91
|
# These must match the values in descriptor.proto, but we can't use them
|
|
87
92
|
# directly because we sometimes need to reference them in feature helpers
|
|
@@ -101,7 +106,6 @@ _internal_create_key = object()
|
|
|
101
106
|
|
|
102
107
|
|
|
103
108
|
class DescriptorBase(metaclass=DescriptorMetaclass):
|
|
104
|
-
|
|
105
109
|
"""Descriptors base class.
|
|
106
110
|
|
|
107
111
|
This class is the base of all descriptor classes. It provides common options
|
|
@@ -123,18 +127,22 @@ class DescriptorBase(metaclass=DescriptorMetaclass):
|
|
|
123
127
|
|
|
124
128
|
def __init__(self, file, options, serialized_options, options_class_name):
|
|
125
129
|
"""Initialize the descriptor given its options message and the name of the
|
|
130
|
+
|
|
126
131
|
class of the options message. The name of the class is required in case
|
|
127
132
|
the options message is None and has to be created.
|
|
128
133
|
"""
|
|
129
134
|
self._features = None
|
|
130
135
|
self.file = file
|
|
131
|
-
self.
|
|
132
|
-
|
|
136
|
+
self._original_options = options
|
|
137
|
+
# These two fields are duplicated as a compatibility shim for old gencode
|
|
138
|
+
# that resets them. In 26.x (cl/580304039) we renamed _options to,
|
|
139
|
+
# _loaded_options breaking backwards compatibility.
|
|
140
|
+
self._options = self._loaded_options = None
|
|
133
141
|
self._options_class_name = options_class_name
|
|
134
142
|
self._serialized_options = serialized_options
|
|
135
143
|
|
|
136
144
|
# Does this descriptor have non-default options?
|
|
137
|
-
self.has_options = (self.
|
|
145
|
+
self.has_options = (self._original_options is not None) or (
|
|
138
146
|
self._serialized_options is not None
|
|
139
147
|
)
|
|
140
148
|
|
|
@@ -186,7 +194,8 @@ class DescriptorBase(metaclass=DescriptorMetaclass):
|
|
|
186
194
|
|
|
187
195
|
def _LazyLoadOptions(self):
|
|
188
196
|
"""Lazily initializes descriptor options towards the end of the build."""
|
|
189
|
-
if self._loaded_options:
|
|
197
|
+
if self._options and self._loaded_options == self._options:
|
|
198
|
+
# If neither has been reset by gencode, use the cache.
|
|
190
199
|
return
|
|
191
200
|
|
|
192
201
|
# pylint: disable=g-import-not-at-top
|
|
@@ -206,12 +215,12 @@ class DescriptorBase(metaclass=DescriptorMetaclass):
|
|
|
206
215
|
descriptor_pb2.Edition.Value(edition), options_class()
|
|
207
216
|
)
|
|
208
217
|
with _lock:
|
|
209
|
-
self._loaded_options = options_class()
|
|
218
|
+
self._options = self._loaded_options = options_class()
|
|
210
219
|
if not self._features:
|
|
211
220
|
self._features = features
|
|
212
221
|
else:
|
|
213
222
|
if not self._serialized_options:
|
|
214
|
-
options = self.
|
|
223
|
+
options = self._original_options
|
|
215
224
|
else:
|
|
216
225
|
options = _ParseOptions(options_class(), self._serialized_options)
|
|
217
226
|
|
|
@@ -220,13 +229,13 @@ class DescriptorBase(metaclass=DescriptorMetaclass):
|
|
|
220
229
|
descriptor_pb2.Edition.Value(edition), options
|
|
221
230
|
)
|
|
222
231
|
with _lock:
|
|
223
|
-
self._loaded_options = options
|
|
232
|
+
self._options = self._loaded_options = options
|
|
224
233
|
if not self._features:
|
|
225
234
|
self._features = features
|
|
226
235
|
if options.HasField('features'):
|
|
227
236
|
options.ClearField('features')
|
|
228
237
|
if not options.SerializeToString():
|
|
229
|
-
self._loaded_options = options_class()
|
|
238
|
+
self._options = self._loaded_options = options_class()
|
|
230
239
|
self.has_options = False
|
|
231
240
|
|
|
232
241
|
def GetOptions(self):
|
|
@@ -235,17 +244,27 @@ class DescriptorBase(metaclass=DescriptorMetaclass):
|
|
|
235
244
|
Returns:
|
|
236
245
|
The options set on this descriptor.
|
|
237
246
|
"""
|
|
238
|
-
|
|
247
|
+
# If either has been reset by gencode, reload options.
|
|
248
|
+
if not self._options or not self._loaded_options:
|
|
239
249
|
self._LazyLoadOptions()
|
|
240
|
-
return self.
|
|
250
|
+
return self._options
|
|
241
251
|
|
|
242
252
|
|
|
243
253
|
class _NestedDescriptorBase(DescriptorBase):
|
|
244
254
|
"""Common class for descriptors that can be nested."""
|
|
245
255
|
|
|
246
|
-
def __init__(
|
|
247
|
-
|
|
248
|
-
|
|
256
|
+
def __init__(
|
|
257
|
+
self,
|
|
258
|
+
options,
|
|
259
|
+
options_class_name,
|
|
260
|
+
name,
|
|
261
|
+
full_name,
|
|
262
|
+
file,
|
|
263
|
+
containing_type,
|
|
264
|
+
serialized_start=None,
|
|
265
|
+
serialized_end=None,
|
|
266
|
+
serialized_options=None,
|
|
267
|
+
):
|
|
249
268
|
"""Constructor.
|
|
250
269
|
|
|
251
270
|
Args:
|
|
@@ -286,59 +305,60 @@ class _NestedDescriptorBase(DescriptorBase):
|
|
|
286
305
|
Error: If self couldn't be serialized, due to to few constructor
|
|
287
306
|
arguments.
|
|
288
307
|
"""
|
|
289
|
-
if (
|
|
290
|
-
self.
|
|
291
|
-
self.
|
|
292
|
-
|
|
293
|
-
|
|
308
|
+
if (
|
|
309
|
+
self.file is not None
|
|
310
|
+
and self._serialized_start is not None
|
|
311
|
+
and self._serialized_end is not None
|
|
312
|
+
):
|
|
313
|
+
proto.ParseFromString(
|
|
314
|
+
self.file.serialized_pb[self._serialized_start : self._serialized_end]
|
|
315
|
+
)
|
|
294
316
|
else:
|
|
295
317
|
raise Error('Descriptor does not contain serialization.')
|
|
296
318
|
|
|
297
319
|
|
|
298
320
|
class Descriptor(_NestedDescriptorBase):
|
|
299
|
-
|
|
300
321
|
"""Descriptor for a protocol message type.
|
|
301
322
|
|
|
302
323
|
Attributes:
|
|
303
324
|
name (str): Name of this protocol message type.
|
|
304
|
-
full_name (str): Fully-qualified name of this protocol message type,
|
|
305
|
-
|
|
306
|
-
|
|
325
|
+
full_name (str): Fully-qualified name of this protocol message type, which
|
|
326
|
+
will include protocol "package" name and the name of any enclosing
|
|
327
|
+
types.
|
|
307
328
|
containing_type (Descriptor): Reference to the descriptor of the type
|
|
308
|
-
|
|
309
|
-
fields (list[FieldDescriptor]): Field descriptors for all fields in
|
|
310
|
-
|
|
329
|
+
containing us, or None if this is top-level.
|
|
330
|
+
fields (list[FieldDescriptor]): Field descriptors for all fields in this
|
|
331
|
+
type.
|
|
311
332
|
fields_by_number (dict(int, FieldDescriptor)): Same
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
fields_by_name (dict(str, FieldDescriptor)): Same
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
nested_types (list[Descriptor]): Descriptor references
|
|
318
|
-
|
|
319
|
-
nested_types_by_name (dict(str, Descriptor)): Same Descriptor
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
enum_types (list[EnumDescriptor]): :class:`EnumDescriptor` references
|
|
323
|
-
|
|
333
|
+
:class:`FieldDescriptor` objects as in :attr:`fields`, but indexed by
|
|
334
|
+
"number" attribute in each FieldDescriptor.
|
|
335
|
+
fields_by_name (dict(str, FieldDescriptor)): Same :class:`FieldDescriptor`
|
|
336
|
+
objects as in :attr:`fields`, but indexed by "name" attribute in each
|
|
337
|
+
:class:`FieldDescriptor`.
|
|
338
|
+
nested_types (list[Descriptor]): Descriptor references for all protocol
|
|
339
|
+
message types nested within this one.
|
|
340
|
+
nested_types_by_name (dict(str, Descriptor)): Same Descriptor objects as
|
|
341
|
+
in :attr:`nested_types`, but indexed by "name" attribute in each
|
|
342
|
+
Descriptor.
|
|
343
|
+
enum_types (list[EnumDescriptor]): :class:`EnumDescriptor` references for
|
|
344
|
+
all enums contained within this type.
|
|
324
345
|
enum_types_by_name (dict(str, EnumDescriptor)): Same
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
enum_values_by_name (dict(str, EnumValueDescriptor)): Dict mapping
|
|
328
|
-
|
|
329
|
-
extensions (list[FieldDescriptor]): All extensions defined directly
|
|
330
|
-
|
|
346
|
+
:class:`EnumDescriptor` objects as in :attr:`enum_types`, but indexed by
|
|
347
|
+
"name" attribute in each EnumDescriptor.
|
|
348
|
+
enum_values_by_name (dict(str, EnumValueDescriptor)): Dict mapping from
|
|
349
|
+
enum value name to :class:`EnumValueDescriptor` for that value.
|
|
350
|
+
extensions (list[FieldDescriptor]): All extensions defined directly within
|
|
351
|
+
this message type (NOT within a nested type).
|
|
331
352
|
extensions_by_name (dict(str, FieldDescriptor)): Same FieldDescriptor
|
|
332
|
-
|
|
333
|
-
|
|
353
|
+
objects as :attr:`extensions`, but indexed by "name" attribute of each
|
|
354
|
+
FieldDescriptor.
|
|
334
355
|
is_extendable (bool): Does this type define any extension ranges?
|
|
335
356
|
oneofs (list[OneofDescriptor]): The list of descriptors for oneof fields
|
|
336
|
-
|
|
357
|
+
in this message.
|
|
337
358
|
oneofs_by_name (dict(str, OneofDescriptor)): Same objects as in
|
|
338
|
-
|
|
359
|
+
:attr:`oneofs`, but indexed by "name" attribute.
|
|
339
360
|
file (FileDescriptor): Reference to file descriptor.
|
|
340
361
|
is_map_entry: If the message type is a map entry.
|
|
341
|
-
|
|
342
362
|
"""
|
|
343
363
|
|
|
344
364
|
if _USE_C_DESCRIPTORS:
|
|
@@ -364,32 +384,57 @@ class Descriptor(_NestedDescriptorBase):
|
|
|
364
384
|
serialized_end=None,
|
|
365
385
|
syntax=None,
|
|
366
386
|
is_map_entry=False,
|
|
367
|
-
create_key=None
|
|
387
|
+
create_key=None,
|
|
388
|
+
):
|
|
368
389
|
_message.Message._CheckCalledFromGeneratedFile()
|
|
369
390
|
return _message.default_pool.FindMessageTypeByName(full_name)
|
|
370
391
|
|
|
371
392
|
# NOTE: The file argument redefining a builtin is nothing we can
|
|
372
393
|
# fix right now since we don't know how many clients already rely on the
|
|
373
394
|
# name of the argument.
|
|
374
|
-
def __init__(
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
395
|
+
def __init__(
|
|
396
|
+
self,
|
|
397
|
+
name,
|
|
398
|
+
full_name,
|
|
399
|
+
filename,
|
|
400
|
+
containing_type,
|
|
401
|
+
fields,
|
|
402
|
+
nested_types,
|
|
403
|
+
enum_types,
|
|
404
|
+
extensions,
|
|
405
|
+
options=None,
|
|
406
|
+
serialized_options=None,
|
|
407
|
+
is_extendable=True,
|
|
408
|
+
extension_ranges=None,
|
|
409
|
+
oneofs=None,
|
|
410
|
+
file=None,
|
|
411
|
+
serialized_start=None,
|
|
412
|
+
serialized_end=None, # pylint: disable=redefined-builtin
|
|
413
|
+
syntax=None,
|
|
414
|
+
is_map_entry=False,
|
|
415
|
+
create_key=None,
|
|
416
|
+
):
|
|
380
417
|
"""Arguments to __init__() are as described in the description
|
|
418
|
+
|
|
381
419
|
of Descriptor fields above.
|
|
382
420
|
|
|
383
421
|
Note that filename is an obsolete argument, that is not used anymore.
|
|
384
422
|
Please use file.name to access this as an attribute.
|
|
385
423
|
"""
|
|
386
424
|
if create_key is not _internal_create_key:
|
|
387
|
-
_Deprecated('Descriptor')
|
|
425
|
+
_Deprecated('create function Descriptor()')
|
|
388
426
|
|
|
389
427
|
super(Descriptor, self).__init__(
|
|
390
|
-
options,
|
|
391
|
-
|
|
392
|
-
|
|
428
|
+
options,
|
|
429
|
+
'MessageOptions',
|
|
430
|
+
name,
|
|
431
|
+
full_name,
|
|
432
|
+
file,
|
|
433
|
+
containing_type,
|
|
434
|
+
serialized_start=serialized_start,
|
|
435
|
+
serialized_end=serialized_end,
|
|
436
|
+
serialized_options=serialized_options,
|
|
437
|
+
)
|
|
393
438
|
|
|
394
439
|
# We have fields in addition to fields_by_name and fields_by_number,
|
|
395
440
|
# so that:
|
|
@@ -414,7 +459,8 @@ class Descriptor(_NestedDescriptorBase):
|
|
|
414
459
|
enum_type.containing_type = self
|
|
415
460
|
self.enum_types_by_name = dict((t.name, t) for t in enum_types)
|
|
416
461
|
self.enum_values_by_name = dict(
|
|
417
|
-
(v.name, v) for t in enum_types for v in t.values
|
|
462
|
+
(v.name, v) for t in enum_types for v in t.values
|
|
463
|
+
)
|
|
418
464
|
|
|
419
465
|
self.extensions = extensions
|
|
420
466
|
for extension in self.extensions:
|
|
@@ -436,11 +482,13 @@ class Descriptor(_NestedDescriptorBase):
|
|
|
436
482
|
@property
|
|
437
483
|
def fields_by_camelcase_name(self):
|
|
438
484
|
"""Same FieldDescriptor objects as in :attr:`fields`, but indexed by
|
|
485
|
+
|
|
439
486
|
:attr:`FieldDescriptor.camelcase_name`.
|
|
440
487
|
"""
|
|
441
488
|
if self._fields_by_camelcase_name is None:
|
|
442
489
|
self._fields_by_camelcase_name = dict(
|
|
443
|
-
(f.camelcase_name, f) for f in self.fields
|
|
490
|
+
(f.camelcase_name, f) for f in self.fields
|
|
491
|
+
)
|
|
444
492
|
return self._fields_by_camelcase_name
|
|
445
493
|
|
|
446
494
|
def EnumValueName(self, enum, value):
|
|
@@ -483,53 +531,42 @@ class Descriptor(_NestedDescriptorBase):
|
|
|
483
531
|
# stronger invariants here in general will reduce the number
|
|
484
532
|
# of runtime checks we must do in reflection.py...
|
|
485
533
|
class FieldDescriptor(DescriptorBase):
|
|
486
|
-
|
|
487
534
|
"""Descriptor for a single field in a .proto file.
|
|
488
535
|
|
|
489
536
|
Attributes:
|
|
490
537
|
name (str): Name of this field, exactly as it appears in .proto.
|
|
491
538
|
full_name (str): Name of this field, including containing scope. This is
|
|
492
539
|
particularly relevant for extensions.
|
|
493
|
-
index (int): Dense, 0-indexed index giving the order that this
|
|
494
|
-
|
|
540
|
+
index (int): Dense, 0-indexed index giving the order that this field
|
|
541
|
+
textually appears within its message in the .proto file.
|
|
495
542
|
number (int): Tag number declared for this field in the .proto file.
|
|
496
|
-
|
|
497
543
|
type (int): (One of the TYPE_* constants below) Declared type.
|
|
498
544
|
cpp_type (int): (One of the CPPTYPE_* constants below) C++ type used to
|
|
499
545
|
represent this field.
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
field is optional, required, or repeated.
|
|
546
|
+
label (int): (One of the LABEL_* constants below) Tells whether this field
|
|
547
|
+
is optional, required, or repeated.
|
|
503
548
|
has_default_value (bool): True if this field has a default value defined,
|
|
504
549
|
otherwise false.
|
|
505
|
-
default_value (Varies): Default value of this field. Only
|
|
506
|
-
|
|
507
|
-
should always set this to
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
message_type (Descriptor): If a composite field, a descriptor
|
|
518
|
-
of the message type contained in this field. Otherwise, this is None.
|
|
519
|
-
enum_type (EnumDescriptor): If this field contains an enum, a
|
|
520
|
-
descriptor of that enum. Otherwise, this is None.
|
|
521
|
-
|
|
550
|
+
default_value (Varies): Default value of this field. Only meaningful for
|
|
551
|
+
non-repeated scalar fields. Repeated fields should always set this to [],
|
|
552
|
+
and non-repeated composite fields should always set this to None.
|
|
553
|
+
containing_type (Descriptor): Descriptor of the protocol message type that
|
|
554
|
+
contains this field. Set by the Descriptor constructor if we're passed
|
|
555
|
+
into one. Somewhat confusingly, for extension fields, this is the
|
|
556
|
+
descriptor of the EXTENDED message, not the descriptor of the message
|
|
557
|
+
containing this field. (See is_extension and extension_scope below).
|
|
558
|
+
message_type (Descriptor): If a composite field, a descriptor of the message
|
|
559
|
+
type contained in this field. Otherwise, this is None.
|
|
560
|
+
enum_type (EnumDescriptor): If this field contains an enum, a descriptor of
|
|
561
|
+
that enum. Otherwise, this is None.
|
|
522
562
|
is_extension: True iff this describes an extension field.
|
|
523
|
-
extension_scope (Descriptor): Only meaningful if is_extension is True.
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
563
|
+
extension_scope (Descriptor): Only meaningful if is_extension is True. Gives
|
|
564
|
+
the message that immediately contains this extension field. Will be None
|
|
565
|
+
iff we're a top-level (file-level) extension field.
|
|
527
566
|
options (descriptor_pb2.FieldOptions): Protocol message field options or
|
|
528
567
|
None to use default field options.
|
|
529
|
-
|
|
530
568
|
containing_oneof (OneofDescriptor): If the field is a member of a oneof
|
|
531
569
|
union, contains its descriptor. Otherwise, None.
|
|
532
|
-
|
|
533
570
|
file (FileDescriptor): Reference to file descriptor.
|
|
534
571
|
"""
|
|
535
572
|
|
|
@@ -537,41 +574,41 @@ class FieldDescriptor(DescriptorBase):
|
|
|
537
574
|
# descriptor.h.
|
|
538
575
|
#
|
|
539
576
|
# TODO: Find a way to eliminate this repetition.
|
|
540
|
-
TYPE_DOUBLE
|
|
541
|
-
TYPE_FLOAT
|
|
542
|
-
TYPE_INT64
|
|
543
|
-
TYPE_UINT64
|
|
544
|
-
TYPE_INT32
|
|
545
|
-
TYPE_FIXED64
|
|
546
|
-
TYPE_FIXED32
|
|
547
|
-
TYPE_BOOL
|
|
548
|
-
TYPE_STRING
|
|
549
|
-
TYPE_GROUP
|
|
550
|
-
TYPE_MESSAGE
|
|
551
|
-
TYPE_BYTES
|
|
552
|
-
TYPE_UINT32
|
|
553
|
-
TYPE_ENUM
|
|
554
|
-
TYPE_SFIXED32
|
|
555
|
-
TYPE_SFIXED64
|
|
556
|
-
TYPE_SINT32
|
|
557
|
-
TYPE_SINT64
|
|
558
|
-
MAX_TYPE
|
|
577
|
+
TYPE_DOUBLE = 1
|
|
578
|
+
TYPE_FLOAT = 2
|
|
579
|
+
TYPE_INT64 = 3
|
|
580
|
+
TYPE_UINT64 = 4
|
|
581
|
+
TYPE_INT32 = 5
|
|
582
|
+
TYPE_FIXED64 = 6
|
|
583
|
+
TYPE_FIXED32 = 7
|
|
584
|
+
TYPE_BOOL = 8
|
|
585
|
+
TYPE_STRING = 9
|
|
586
|
+
TYPE_GROUP = 10
|
|
587
|
+
TYPE_MESSAGE = 11
|
|
588
|
+
TYPE_BYTES = 12
|
|
589
|
+
TYPE_UINT32 = 13
|
|
590
|
+
TYPE_ENUM = 14
|
|
591
|
+
TYPE_SFIXED32 = 15
|
|
592
|
+
TYPE_SFIXED64 = 16
|
|
593
|
+
TYPE_SINT32 = 17
|
|
594
|
+
TYPE_SINT64 = 18
|
|
595
|
+
MAX_TYPE = 18
|
|
559
596
|
|
|
560
597
|
# Must be consistent with C++ FieldDescriptor::CppType enum in
|
|
561
598
|
# descriptor.h.
|
|
562
599
|
#
|
|
563
600
|
# TODO: Find a way to eliminate this repetition.
|
|
564
|
-
CPPTYPE_INT32
|
|
565
|
-
CPPTYPE_INT64
|
|
566
|
-
CPPTYPE_UINT32
|
|
567
|
-
CPPTYPE_UINT64
|
|
568
|
-
CPPTYPE_DOUBLE
|
|
569
|
-
CPPTYPE_FLOAT
|
|
570
|
-
CPPTYPE_BOOL
|
|
571
|
-
CPPTYPE_ENUM
|
|
572
|
-
CPPTYPE_STRING
|
|
573
|
-
CPPTYPE_MESSAGE
|
|
574
|
-
MAX_CPPTYPE
|
|
601
|
+
CPPTYPE_INT32 = 1
|
|
602
|
+
CPPTYPE_INT64 = 2
|
|
603
|
+
CPPTYPE_UINT32 = 3
|
|
604
|
+
CPPTYPE_UINT64 = 4
|
|
605
|
+
CPPTYPE_DOUBLE = 5
|
|
606
|
+
CPPTYPE_FLOAT = 6
|
|
607
|
+
CPPTYPE_BOOL = 7
|
|
608
|
+
CPPTYPE_ENUM = 8
|
|
609
|
+
CPPTYPE_STRING = 9
|
|
610
|
+
CPPTYPE_MESSAGE = 10
|
|
611
|
+
MAX_CPPTYPE = 10
|
|
575
612
|
|
|
576
613
|
_PYTHON_TO_CPP_PROTO_TYPE_MAP = {
|
|
577
614
|
TYPE_DOUBLE: CPPTYPE_DOUBLE,
|
|
@@ -591,17 +628,17 @@ class FieldDescriptor(DescriptorBase):
|
|
|
591
628
|
TYPE_STRING: CPPTYPE_STRING,
|
|
592
629
|
TYPE_BOOL: CPPTYPE_BOOL,
|
|
593
630
|
TYPE_MESSAGE: CPPTYPE_MESSAGE,
|
|
594
|
-
TYPE_GROUP: CPPTYPE_MESSAGE
|
|
595
|
-
|
|
631
|
+
TYPE_GROUP: CPPTYPE_MESSAGE,
|
|
632
|
+
}
|
|
596
633
|
|
|
597
634
|
# Must be consistent with C++ FieldDescriptor::Label enum in
|
|
598
635
|
# descriptor.h.
|
|
599
636
|
#
|
|
600
637
|
# TODO: Find a way to eliminate this repetition.
|
|
601
|
-
LABEL_OPTIONAL
|
|
602
|
-
LABEL_REQUIRED
|
|
603
|
-
LABEL_REPEATED
|
|
604
|
-
MAX_LABEL
|
|
638
|
+
LABEL_OPTIONAL = 1
|
|
639
|
+
LABEL_REQUIRED = 2
|
|
640
|
+
LABEL_REPEATED = 3
|
|
641
|
+
MAX_LABEL = 3
|
|
605
642
|
|
|
606
643
|
# Must be consistent with C++ constants kMaxNumber, kFirstReservedNumber,
|
|
607
644
|
# and kLastReservedNumber in descriptor.h
|
|
@@ -612,25 +649,60 @@ class FieldDescriptor(DescriptorBase):
|
|
|
612
649
|
if _USE_C_DESCRIPTORS:
|
|
613
650
|
_C_DESCRIPTOR_CLASS = _message.FieldDescriptor
|
|
614
651
|
|
|
615
|
-
def __new__(
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
652
|
+
def __new__(
|
|
653
|
+
cls,
|
|
654
|
+
name,
|
|
655
|
+
full_name,
|
|
656
|
+
index,
|
|
657
|
+
number,
|
|
658
|
+
type,
|
|
659
|
+
cpp_type,
|
|
660
|
+
label,
|
|
661
|
+
default_value,
|
|
662
|
+
message_type,
|
|
663
|
+
enum_type,
|
|
664
|
+
containing_type,
|
|
665
|
+
is_extension,
|
|
666
|
+
extension_scope,
|
|
667
|
+
options=None,
|
|
668
|
+
serialized_options=None,
|
|
669
|
+
has_default_value=True,
|
|
670
|
+
containing_oneof=None,
|
|
671
|
+
json_name=None,
|
|
672
|
+
file=None,
|
|
673
|
+
create_key=None,
|
|
674
|
+
): # pylint: disable=redefined-builtin
|
|
621
675
|
_message.Message._CheckCalledFromGeneratedFile()
|
|
622
676
|
if is_extension:
|
|
623
677
|
return _message.default_pool.FindExtensionByName(full_name)
|
|
624
678
|
else:
|
|
625
679
|
return _message.default_pool.FindFieldByName(full_name)
|
|
626
680
|
|
|
627
|
-
def __init__(
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
681
|
+
def __init__(
|
|
682
|
+
self,
|
|
683
|
+
name,
|
|
684
|
+
full_name,
|
|
685
|
+
index,
|
|
686
|
+
number,
|
|
687
|
+
type,
|
|
688
|
+
cpp_type,
|
|
689
|
+
label,
|
|
690
|
+
default_value,
|
|
691
|
+
message_type,
|
|
692
|
+
enum_type,
|
|
693
|
+
containing_type,
|
|
694
|
+
is_extension,
|
|
695
|
+
extension_scope,
|
|
696
|
+
options=None,
|
|
697
|
+
serialized_options=None,
|
|
698
|
+
has_default_value=True,
|
|
699
|
+
containing_oneof=None,
|
|
700
|
+
json_name=None,
|
|
701
|
+
file=None,
|
|
702
|
+
create_key=None,
|
|
703
|
+
): # pylint: disable=redefined-builtin
|
|
633
704
|
"""The arguments are as described in the description of FieldDescriptor
|
|
705
|
+
|
|
634
706
|
attributes above.
|
|
635
707
|
|
|
636
708
|
Note that containing_type may be None, and may be set later if necessary
|
|
@@ -638,7 +710,7 @@ class FieldDescriptor(DescriptorBase):
|
|
|
638
710
|
Likewise for extension_scope.
|
|
639
711
|
"""
|
|
640
712
|
if create_key is not _internal_create_key:
|
|
641
|
-
_Deprecated('FieldDescriptor')
|
|
713
|
+
_Deprecated('create function FieldDescriptor()')
|
|
642
714
|
|
|
643
715
|
super(FieldDescriptor, self).__init__(
|
|
644
716
|
file, options, serialized_options, 'FieldOptions'
|
|
@@ -721,6 +793,8 @@ class FieldDescriptor(DescriptorBase):
|
|
|
721
793
|
|
|
722
794
|
@property
|
|
723
795
|
def label(self):
|
|
796
|
+
_Deprecated('label property', 'is_required or is_repeated properties')
|
|
797
|
+
|
|
724
798
|
if (
|
|
725
799
|
self._GetFeatures().field_presence
|
|
726
800
|
== _FEATURESET_FIELD_PRESENCE_LEGACY_REQUIRED
|
|
@@ -728,6 +802,19 @@ class FieldDescriptor(DescriptorBase):
|
|
|
728
802
|
return FieldDescriptor.LABEL_REQUIRED
|
|
729
803
|
return self._label
|
|
730
804
|
|
|
805
|
+
@property
|
|
806
|
+
def is_required(self):
|
|
807
|
+
"""Returns if the field is required."""
|
|
808
|
+
return (
|
|
809
|
+
self._GetFeatures().field_presence
|
|
810
|
+
== _FEATURESET_FIELD_PRESENCE_LEGACY_REQUIRED
|
|
811
|
+
)
|
|
812
|
+
|
|
813
|
+
@property
|
|
814
|
+
def is_repeated(self):
|
|
815
|
+
"""Returns if the field is repeated."""
|
|
816
|
+
return self._label == FieldDescriptor.LABEL_REPEATED
|
|
817
|
+
|
|
731
818
|
@property
|
|
732
819
|
def camelcase_name(self):
|
|
733
820
|
"""Camelcase name of this field.
|
|
@@ -746,7 +833,7 @@ class FieldDescriptor(DescriptorBase):
|
|
|
746
833
|
Raises:
|
|
747
834
|
RuntimeError: singular field that is not linked with message nor file.
|
|
748
835
|
"""
|
|
749
|
-
if self.
|
|
836
|
+
if self.is_repeated:
|
|
750
837
|
return False
|
|
751
838
|
if (
|
|
752
839
|
self.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE
|
|
@@ -763,13 +850,15 @@ class FieldDescriptor(DescriptorBase):
|
|
|
763
850
|
@property
|
|
764
851
|
def is_packed(self):
|
|
765
852
|
"""Returns if the field is packed."""
|
|
766
|
-
if self.
|
|
853
|
+
if not self.is_repeated:
|
|
767
854
|
return False
|
|
768
855
|
field_type = self.type
|
|
769
|
-
if (
|
|
770
|
-
field_type == FieldDescriptor.
|
|
771
|
-
field_type == FieldDescriptor.
|
|
772
|
-
field_type == FieldDescriptor.
|
|
856
|
+
if (
|
|
857
|
+
field_type == FieldDescriptor.TYPE_STRING
|
|
858
|
+
or field_type == FieldDescriptor.TYPE_GROUP
|
|
859
|
+
or field_type == FieldDescriptor.TYPE_MESSAGE
|
|
860
|
+
or field_type == FieldDescriptor.TYPE_BYTES
|
|
861
|
+
):
|
|
773
862
|
return False
|
|
774
863
|
|
|
775
864
|
return (
|
|
@@ -787,6 +876,7 @@ class FieldDescriptor(DescriptorBase):
|
|
|
787
876
|
|
|
788
877
|
Args:
|
|
789
878
|
proto_type: the Python proto type (descriptor.FieldDescriptor.TYPE_*)
|
|
879
|
+
|
|
790
880
|
Returns:
|
|
791
881
|
int: descriptor.FieldDescriptor.CPPTYPE_*, the C++ type.
|
|
792
882
|
Raises:
|
|
@@ -799,55 +889,78 @@ class FieldDescriptor(DescriptorBase):
|
|
|
799
889
|
|
|
800
890
|
|
|
801
891
|
class EnumDescriptor(_NestedDescriptorBase):
|
|
802
|
-
|
|
803
892
|
"""Descriptor for an enum defined in a .proto file.
|
|
804
893
|
|
|
805
894
|
Attributes:
|
|
806
895
|
name (str): Name of the enum type.
|
|
807
|
-
full_name (str): Full name of the type, including package name
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
values_by_name (dict(str, EnumValueDescriptor)): Same as :attr:`values`,
|
|
813
|
-
but indexed by the "name" field of each EnumValueDescriptor.
|
|
896
|
+
full_name (str): Full name of the type, including package name and any
|
|
897
|
+
enclosing type(s).
|
|
898
|
+
values (list[EnumValueDescriptor]): List of the values in this enum.
|
|
899
|
+
values_by_name (dict(str, EnumValueDescriptor)): Same as :attr:`values`, but
|
|
900
|
+
indexed by the "name" field of each EnumValueDescriptor.
|
|
814
901
|
values_by_number (dict(int, EnumValueDescriptor)): Same as :attr:`values`,
|
|
815
902
|
but indexed by the "number" field of each EnumValueDescriptor.
|
|
816
|
-
containing_type (Descriptor): Descriptor of the immediate containing
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
if we're passed into one.
|
|
903
|
+
containing_type (Descriptor): Descriptor of the immediate containing type of
|
|
904
|
+
this enum, or None if this is an enum defined at the top level in a .proto
|
|
905
|
+
file. Set by Descriptor's constructor if we're passed into one.
|
|
820
906
|
file (FileDescriptor): Reference to file descriptor.
|
|
821
|
-
options (descriptor_pb2.EnumOptions): Enum options message or
|
|
822
|
-
|
|
907
|
+
options (descriptor_pb2.EnumOptions): Enum options message or None to use
|
|
908
|
+
default enum options.
|
|
823
909
|
"""
|
|
824
910
|
|
|
825
911
|
if _USE_C_DESCRIPTORS:
|
|
826
912
|
_C_DESCRIPTOR_CLASS = _message.EnumDescriptor
|
|
827
913
|
|
|
828
|
-
def __new__(
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
914
|
+
def __new__(
|
|
915
|
+
cls,
|
|
916
|
+
name,
|
|
917
|
+
full_name,
|
|
918
|
+
filename,
|
|
919
|
+
values,
|
|
920
|
+
containing_type=None,
|
|
921
|
+
options=None,
|
|
922
|
+
serialized_options=None,
|
|
923
|
+
file=None, # pylint: disable=redefined-builtin
|
|
924
|
+
serialized_start=None,
|
|
925
|
+
serialized_end=None,
|
|
926
|
+
create_key=None,
|
|
927
|
+
):
|
|
832
928
|
_message.Message._CheckCalledFromGeneratedFile()
|
|
833
929
|
return _message.default_pool.FindEnumTypeByName(full_name)
|
|
834
930
|
|
|
835
|
-
def __init__(
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
931
|
+
def __init__(
|
|
932
|
+
self,
|
|
933
|
+
name,
|
|
934
|
+
full_name,
|
|
935
|
+
filename,
|
|
936
|
+
values,
|
|
937
|
+
containing_type=None,
|
|
938
|
+
options=None,
|
|
939
|
+
serialized_options=None,
|
|
940
|
+
file=None, # pylint: disable=redefined-builtin
|
|
941
|
+
serialized_start=None,
|
|
942
|
+
serialized_end=None,
|
|
943
|
+
create_key=None,
|
|
944
|
+
):
|
|
839
945
|
"""Arguments are as described in the attribute description above.
|
|
840
946
|
|
|
841
947
|
Note that filename is an obsolete argument, that is not used anymore.
|
|
842
948
|
Please use file.name to access this as an attribute.
|
|
843
949
|
"""
|
|
844
950
|
if create_key is not _internal_create_key:
|
|
845
|
-
_Deprecated('EnumDescriptor')
|
|
951
|
+
_Deprecated('create function EnumDescriptor()')
|
|
846
952
|
|
|
847
953
|
super(EnumDescriptor, self).__init__(
|
|
848
|
-
options,
|
|
849
|
-
|
|
850
|
-
|
|
954
|
+
options,
|
|
955
|
+
'EnumOptions',
|
|
956
|
+
name,
|
|
957
|
+
full_name,
|
|
958
|
+
file,
|
|
959
|
+
containing_type,
|
|
960
|
+
serialized_start=serialized_start,
|
|
961
|
+
serialized_end=serialized_end,
|
|
962
|
+
serialized_options=serialized_options,
|
|
963
|
+
)
|
|
851
964
|
|
|
852
965
|
self.values = values
|
|
853
966
|
for value in self.values:
|
|
@@ -896,17 +1009,15 @@ class EnumDescriptor(_NestedDescriptorBase):
|
|
|
896
1009
|
|
|
897
1010
|
|
|
898
1011
|
class EnumValueDescriptor(DescriptorBase):
|
|
899
|
-
|
|
900
1012
|
"""Descriptor for a single value within an enum.
|
|
901
1013
|
|
|
902
1014
|
Attributes:
|
|
903
1015
|
name (str): Name of this value.
|
|
904
|
-
index (int): Dense, 0-indexed index giving the order that this
|
|
905
|
-
|
|
1016
|
+
index (int): Dense, 0-indexed index giving the order that this value appears
|
|
1017
|
+
textually within its enum in the .proto file.
|
|
906
1018
|
number (int): Actual number assigned to this enum value.
|
|
907
|
-
type (EnumDescriptor): :class:`EnumDescriptor` to which this value
|
|
908
|
-
|
|
909
|
-
passed into one.
|
|
1019
|
+
type (EnumDescriptor): :class:`EnumDescriptor` to which this value belongs.
|
|
1020
|
+
Set by :class:`EnumDescriptor`'s constructor if we're passed into one.
|
|
910
1021
|
options (descriptor_pb2.EnumValueOptions): Enum value options message or
|
|
911
1022
|
None to use default enum value options options.
|
|
912
1023
|
"""
|
|
@@ -914,9 +1025,16 @@ class EnumValueDescriptor(DescriptorBase):
|
|
|
914
1025
|
if _USE_C_DESCRIPTORS:
|
|
915
1026
|
_C_DESCRIPTOR_CLASS = _message.EnumValueDescriptor
|
|
916
1027
|
|
|
917
|
-
def __new__(
|
|
918
|
-
|
|
919
|
-
|
|
1028
|
+
def __new__(
|
|
1029
|
+
cls,
|
|
1030
|
+
name,
|
|
1031
|
+
index,
|
|
1032
|
+
number,
|
|
1033
|
+
type=None, # pylint: disable=redefined-builtin
|
|
1034
|
+
options=None,
|
|
1035
|
+
serialized_options=None,
|
|
1036
|
+
create_key=None,
|
|
1037
|
+
):
|
|
920
1038
|
_message.Message._CheckCalledFromGeneratedFile()
|
|
921
1039
|
# There is no way we can build a complete EnumValueDescriptor with the
|
|
922
1040
|
# given parameters (the name of the Enum is not known, for example).
|
|
@@ -924,12 +1042,19 @@ class EnumValueDescriptor(DescriptorBase):
|
|
|
924
1042
|
# constructor, which will ignore it, so returning None is good enough.
|
|
925
1043
|
return None
|
|
926
1044
|
|
|
927
|
-
def __init__(
|
|
928
|
-
|
|
929
|
-
|
|
1045
|
+
def __init__(
|
|
1046
|
+
self,
|
|
1047
|
+
name,
|
|
1048
|
+
index,
|
|
1049
|
+
number,
|
|
1050
|
+
type=None, # pylint: disable=redefined-builtin
|
|
1051
|
+
options=None,
|
|
1052
|
+
serialized_options=None,
|
|
1053
|
+
create_key=None,
|
|
1054
|
+
):
|
|
930
1055
|
"""Arguments are as described in the attribute description above."""
|
|
931
1056
|
if create_key is not _internal_create_key:
|
|
932
|
-
_Deprecated('EnumValueDescriptor')
|
|
1057
|
+
_Deprecated('create function EnumValueDescriptor()')
|
|
933
1058
|
|
|
934
1059
|
super(EnumValueDescriptor, self).__init__(
|
|
935
1060
|
type.file if type else None,
|
|
@@ -953,30 +1078,46 @@ class OneofDescriptor(DescriptorBase):
|
|
|
953
1078
|
Attributes:
|
|
954
1079
|
name (str): Name of the oneof field.
|
|
955
1080
|
full_name (str): Full name of the oneof field, including package name.
|
|
956
|
-
index (int): 0-based index giving the order of the oneof field inside
|
|
957
|
-
|
|
1081
|
+
index (int): 0-based index giving the order of the oneof field inside its
|
|
1082
|
+
containing type.
|
|
958
1083
|
containing_type (Descriptor): :class:`Descriptor` of the protocol message
|
|
959
1084
|
type that contains this field. Set by the :class:`Descriptor` constructor
|
|
960
1085
|
if we're passed into one.
|
|
961
|
-
fields (list[FieldDescriptor]): The list of field descriptors this
|
|
962
|
-
|
|
1086
|
+
fields (list[FieldDescriptor]): The list of field descriptors this oneof can
|
|
1087
|
+
contain.
|
|
963
1088
|
"""
|
|
964
1089
|
|
|
965
1090
|
if _USE_C_DESCRIPTORS:
|
|
966
1091
|
_C_DESCRIPTOR_CLASS = _message.OneofDescriptor
|
|
967
1092
|
|
|
968
1093
|
def __new__(
|
|
969
|
-
cls,
|
|
970
|
-
|
|
1094
|
+
cls,
|
|
1095
|
+
name,
|
|
1096
|
+
full_name,
|
|
1097
|
+
index,
|
|
1098
|
+
containing_type,
|
|
1099
|
+
fields,
|
|
1100
|
+
options=None,
|
|
1101
|
+
serialized_options=None,
|
|
1102
|
+
create_key=None,
|
|
1103
|
+
):
|
|
971
1104
|
_message.Message._CheckCalledFromGeneratedFile()
|
|
972
1105
|
return _message.default_pool.FindOneofByName(full_name)
|
|
973
1106
|
|
|
974
1107
|
def __init__(
|
|
975
|
-
self,
|
|
976
|
-
|
|
1108
|
+
self,
|
|
1109
|
+
name,
|
|
1110
|
+
full_name,
|
|
1111
|
+
index,
|
|
1112
|
+
containing_type,
|
|
1113
|
+
fields,
|
|
1114
|
+
options=None,
|
|
1115
|
+
serialized_options=None,
|
|
1116
|
+
create_key=None,
|
|
1117
|
+
):
|
|
977
1118
|
"""Arguments are as described in the attribute description above."""
|
|
978
1119
|
if create_key is not _internal_create_key:
|
|
979
|
-
_Deprecated('OneofDescriptor')
|
|
1120
|
+
_Deprecated('create function OneofDescriptor()')
|
|
980
1121
|
|
|
981
1122
|
super(OneofDescriptor, self).__init__(
|
|
982
1123
|
containing_type.file if containing_type else None,
|
|
@@ -996,21 +1137,19 @@ class OneofDescriptor(DescriptorBase):
|
|
|
996
1137
|
|
|
997
1138
|
|
|
998
1139
|
class ServiceDescriptor(_NestedDescriptorBase):
|
|
999
|
-
|
|
1000
1140
|
"""Descriptor for a service.
|
|
1001
1141
|
|
|
1002
1142
|
Attributes:
|
|
1003
1143
|
name (str): Name of the service.
|
|
1004
1144
|
full_name (str): Full name of the service, including package name.
|
|
1005
|
-
index (int): 0-indexed index giving the order that this services
|
|
1006
|
-
|
|
1007
|
-
methods (list[MethodDescriptor]): List of methods provided by this
|
|
1008
|
-
service.
|
|
1145
|
+
index (int): 0-indexed index giving the order that this services definition
|
|
1146
|
+
appears within the .proto file.
|
|
1147
|
+
methods (list[MethodDescriptor]): List of methods provided by this service.
|
|
1009
1148
|
methods_by_name (dict(str, MethodDescriptor)): Same
|
|
1010
1149
|
:class:`MethodDescriptor` objects as in :attr:`methods_by_name`, but
|
|
1011
1150
|
indexed by "name" attribute in each :class:`MethodDescriptor`.
|
|
1012
|
-
options (descriptor_pb2.ServiceOptions): Service options message or
|
|
1013
|
-
|
|
1151
|
+
options (descriptor_pb2.ServiceOptions): Service options message or None to
|
|
1152
|
+
use default service options.
|
|
1014
1153
|
file (FileDescriptor): Reference to file info.
|
|
1015
1154
|
"""
|
|
1016
1155
|
|
|
@@ -1028,20 +1167,38 @@ class ServiceDescriptor(_NestedDescriptorBase):
|
|
|
1028
1167
|
file=None, # pylint: disable=redefined-builtin
|
|
1029
1168
|
serialized_start=None,
|
|
1030
1169
|
serialized_end=None,
|
|
1031
|
-
create_key=None
|
|
1170
|
+
create_key=None,
|
|
1171
|
+
):
|
|
1032
1172
|
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
|
|
1033
1173
|
return _message.default_pool.FindServiceByName(full_name)
|
|
1034
1174
|
|
|
1035
|
-
def __init__(
|
|
1036
|
-
|
|
1037
|
-
|
|
1175
|
+
def __init__(
|
|
1176
|
+
self,
|
|
1177
|
+
name,
|
|
1178
|
+
full_name,
|
|
1179
|
+
index,
|
|
1180
|
+
methods,
|
|
1181
|
+
options=None,
|
|
1182
|
+
serialized_options=None,
|
|
1183
|
+
file=None, # pylint: disable=redefined-builtin
|
|
1184
|
+
serialized_start=None,
|
|
1185
|
+
serialized_end=None,
|
|
1186
|
+
create_key=None,
|
|
1187
|
+
):
|
|
1038
1188
|
if create_key is not _internal_create_key:
|
|
1039
|
-
_Deprecated('ServiceDescriptor')
|
|
1189
|
+
_Deprecated('create function ServiceDescriptor()')
|
|
1040
1190
|
|
|
1041
1191
|
super(ServiceDescriptor, self).__init__(
|
|
1042
|
-
options,
|
|
1043
|
-
|
|
1044
|
-
|
|
1192
|
+
options,
|
|
1193
|
+
'ServiceOptions',
|
|
1194
|
+
name,
|
|
1195
|
+
full_name,
|
|
1196
|
+
file,
|
|
1197
|
+
None,
|
|
1198
|
+
serialized_start=serialized_start,
|
|
1199
|
+
serialized_end=serialized_end,
|
|
1200
|
+
serialized_options=serialized_options,
|
|
1201
|
+
)
|
|
1045
1202
|
self.index = index
|
|
1046
1203
|
self.methods = methods
|
|
1047
1204
|
self.methods_by_name = dict((m.name, m) for m in methods)
|
|
@@ -1079,7 +1236,6 @@ class ServiceDescriptor(_NestedDescriptorBase):
|
|
|
1079
1236
|
|
|
1080
1237
|
|
|
1081
1238
|
class MethodDescriptor(DescriptorBase):
|
|
1082
|
-
|
|
1083
1239
|
"""Descriptor for a method in a service.
|
|
1084
1240
|
|
|
1085
1241
|
Attributes:
|
|
@@ -1101,40 +1257,45 @@ class MethodDescriptor(DescriptorBase):
|
|
|
1101
1257
|
if _USE_C_DESCRIPTORS:
|
|
1102
1258
|
_C_DESCRIPTOR_CLASS = _message.MethodDescriptor
|
|
1103
1259
|
|
|
1104
|
-
def __new__(
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1260
|
+
def __new__(
|
|
1261
|
+
cls,
|
|
1262
|
+
name,
|
|
1263
|
+
full_name,
|
|
1264
|
+
index,
|
|
1265
|
+
containing_service,
|
|
1266
|
+
input_type,
|
|
1267
|
+
output_type,
|
|
1268
|
+
client_streaming=False,
|
|
1269
|
+
server_streaming=False,
|
|
1270
|
+
options=None,
|
|
1271
|
+
serialized_options=None,
|
|
1272
|
+
create_key=None,
|
|
1273
|
+
):
|
|
1116
1274
|
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
|
|
1117
1275
|
return _message.default_pool.FindMethodByName(full_name)
|
|
1118
1276
|
|
|
1119
|
-
def __init__(
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1277
|
+
def __init__(
|
|
1278
|
+
self,
|
|
1279
|
+
name,
|
|
1280
|
+
full_name,
|
|
1281
|
+
index,
|
|
1282
|
+
containing_service,
|
|
1283
|
+
input_type,
|
|
1284
|
+
output_type,
|
|
1285
|
+
client_streaming=False,
|
|
1286
|
+
server_streaming=False,
|
|
1287
|
+
options=None,
|
|
1288
|
+
serialized_options=None,
|
|
1289
|
+
create_key=None,
|
|
1290
|
+
):
|
|
1131
1291
|
"""The arguments are as described in the description of MethodDescriptor
|
|
1292
|
+
|
|
1132
1293
|
attributes above.
|
|
1133
1294
|
|
|
1134
1295
|
Note that containing_service may be None, and may be set later if necessary.
|
|
1135
1296
|
"""
|
|
1136
1297
|
if create_key is not _internal_create_key:
|
|
1137
|
-
_Deprecated('MethodDescriptor')
|
|
1298
|
+
_Deprecated('create function MethodDescriptor()')
|
|
1138
1299
|
|
|
1139
1300
|
super(MethodDescriptor, self).__init__(
|
|
1140
1301
|
containing_service.file if containing_service else None,
|
|
@@ -1167,6 +1328,7 @@ class MethodDescriptor(DescriptorBase):
|
|
|
1167
1328
|
"""
|
|
1168
1329
|
if self.containing_service is not None:
|
|
1169
1330
|
from google.protobuf import descriptor_pb2
|
|
1331
|
+
|
|
1170
1332
|
service_proto = descriptor_pb2.ServiceDescriptorProto()
|
|
1171
1333
|
self.containing_service.CopyToProto(service_proto)
|
|
1172
1334
|
proto.CopyFrom(service_proto.method[self.index])
|
|
@@ -1245,7 +1407,7 @@ class FileDescriptor(DescriptorBase):
|
|
|
1245
1407
|
):
|
|
1246
1408
|
"""Constructor."""
|
|
1247
1409
|
if create_key is not _internal_create_key:
|
|
1248
|
-
_Deprecated('FileDescriptor')
|
|
1410
|
+
_Deprecated('create function FileDescriptor()')
|
|
1249
1411
|
|
|
1250
1412
|
super(FileDescriptor, self).__init__(
|
|
1251
1413
|
self, options, serialized_options, 'FileOptions'
|
|
@@ -1260,6 +1422,7 @@ class FileDescriptor(DescriptorBase):
|
|
|
1260
1422
|
|
|
1261
1423
|
if pool is None:
|
|
1262
1424
|
from google.protobuf import descriptor_pool
|
|
1425
|
+
|
|
1263
1426
|
pool = descriptor_pool.Default()
|
|
1264
1427
|
self.pool = pool
|
|
1265
1428
|
self.message_types_by_name = {}
|
|
@@ -1270,8 +1433,8 @@ class FileDescriptor(DescriptorBase):
|
|
|
1270
1433
|
self.enum_types_by_name = {}
|
|
1271
1434
|
self.extensions_by_name = {}
|
|
1272
1435
|
self.services_by_name = {}
|
|
1273
|
-
self.dependencies =
|
|
1274
|
-
self.public_dependencies =
|
|
1436
|
+
self.dependencies = dependencies or []
|
|
1437
|
+
self.public_dependencies = public_dependencies or []
|
|
1275
1438
|
|
|
1276
1439
|
def CopyToProto(self, proto):
|
|
1277
1440
|
"""Copies this to a descriptor_pb2.FileDescriptorProto.
|
|
@@ -1415,7 +1578,8 @@ def MakeDescriptor(
|
|
|
1415
1578
|
create_key=_internal_create_key,
|
|
1416
1579
|
)
|
|
1417
1580
|
full_message_name = [desc_proto.name]
|
|
1418
|
-
if package:
|
|
1581
|
+
if package:
|
|
1582
|
+
full_message_name.insert(0, package)
|
|
1419
1583
|
|
|
1420
1584
|
# Create Descriptors for enum types
|
|
1421
1585
|
enum_types = {}
|
|
@@ -1466,8 +1630,9 @@ def MakeDescriptor(
|
|
|
1466
1630
|
json_name = None
|
|
1467
1631
|
if field_proto.HasField('type_name'):
|
|
1468
1632
|
type_name = field_proto.type_name
|
|
1469
|
-
full_type_name = '.'.join(
|
|
1470
|
-
|
|
1633
|
+
full_type_name = '.'.join(
|
|
1634
|
+
full_message_name + [type_name[type_name.rfind('.') + 1 :]]
|
|
1635
|
+
)
|
|
1471
1636
|
if full_type_name in nested_types:
|
|
1472
1637
|
nested_desc = nested_types[full_type_name]
|
|
1473
1638
|
elif full_type_name in enum_types:
|