protobuf 5.29.4__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.

Files changed (45) hide show
  1. google/protobuf/__init__.py +1 -1
  2. google/protobuf/any.py +15 -1
  3. google/protobuf/any_pb2.py +4 -4
  4. google/protobuf/api_pb2.py +14 -10
  5. google/protobuf/compiler/plugin_pb2.py +4 -4
  6. google/protobuf/descriptor.py +413 -248
  7. google/protobuf/descriptor_database.py +22 -4
  8. google/protobuf/descriptor_pb2.py +319 -119
  9. google/protobuf/descriptor_pool.py +31 -13
  10. google/protobuf/duration_pb2.py +4 -4
  11. google/protobuf/empty_pb2.py +4 -4
  12. google/protobuf/field_mask_pb2.py +4 -4
  13. google/protobuf/internal/api_implementation.py +0 -6
  14. google/protobuf/internal/builder.py +4 -3
  15. google/protobuf/internal/containers.py +13 -0
  16. google/protobuf/internal/decoder.py +163 -133
  17. google/protobuf/internal/extension_dict.py +3 -3
  18. google/protobuf/internal/field_mask.py +6 -4
  19. google/protobuf/internal/python_edition_defaults.py +1 -1
  20. google/protobuf/internal/python_message.py +86 -70
  21. google/protobuf/internal/testing_refleaks.py +11 -2
  22. google/protobuf/internal/type_checkers.py +52 -5
  23. google/protobuf/internal/well_known_types.py +63 -46
  24. google/protobuf/json_format.py +113 -71
  25. google/protobuf/message.py +26 -0
  26. google/protobuf/message_factory.py +16 -63
  27. google/protobuf/proto.py +38 -1
  28. google/protobuf/proto_text.py +129 -0
  29. google/protobuf/reflection.py +0 -49
  30. google/protobuf/runtime_version.py +8 -28
  31. google/protobuf/source_context_pb2.py +4 -4
  32. google/protobuf/struct_pb2.py +4 -4
  33. google/protobuf/symbol_database.py +0 -18
  34. google/protobuf/text_format.py +49 -29
  35. google/protobuf/timestamp_pb2.py +4 -4
  36. google/protobuf/type_pb2.py +4 -4
  37. google/protobuf/unknown_fields.py +3 -4
  38. google/protobuf/wrappers_pb2.py +4 -4
  39. {protobuf-5.29.4.dist-info → protobuf-6.33.3.dist-info}/METADATA +3 -3
  40. protobuf-6.33.3.dist-info/RECORD +58 -0
  41. google/protobuf/internal/_parameterized.py +0 -420
  42. google/protobuf/service.py +0 -213
  43. protobuf-5.29.4.dist-info/RECORD +0 -59
  44. {protobuf-5.29.4.dist-info → protobuf-6.33.3.dist-info}/LICENSE +0 -0
  45. {protobuf-5.29.4.dist-info → protobuf-6.33.3.dist-info}/WHEEL +0 -0
@@ -13,6 +13,9 @@
13
13
 
14
14
  __author__ = 'robinson@google.com (Will Robinson)'
15
15
 
16
+ _INCONSISTENT_MESSAGE_ATTRIBUTES = ('Extensions',)
17
+
18
+
16
19
  class Error(Exception):
17
20
  """Base error type for this module."""
18
21
  pass
@@ -56,6 +59,29 @@ class Message(object):
56
59
  clone.MergeFrom(self)
57
60
  return clone
58
61
 
62
+ def __dir__(self):
63
+ """Provides the list of all accessible Message attributes."""
64
+ message_attributes = set(super().__dir__())
65
+
66
+ # TODO: Remove this once the UPB implementation is improved.
67
+ # The UPB proto implementation currently doesn't provide proto fields as
68
+ # attributes and they have to added.
69
+ if self.DESCRIPTOR is not None:
70
+ for field in self.DESCRIPTOR.fields:
71
+ message_attributes.add(field.name)
72
+
73
+ # The Fast C++ proto implementation provides inaccessible attributes that
74
+ # have to be removed.
75
+ for attribute in _INCONSISTENT_MESSAGE_ATTRIBUTES:
76
+ if attribute not in message_attributes:
77
+ continue
78
+ try:
79
+ getattr(self, attribute)
80
+ except AttributeError:
81
+ message_attributes.remove(attribute)
82
+
83
+ return sorted(message_attributes)
84
+
59
85
  def __eq__(self, other_msg):
60
86
  """Recursively compares two messages by value and structure."""
61
87
  raise NotImplementedError
@@ -56,6 +56,22 @@ def GetMessageClassesForFiles(files, pool):
56
56
  This will find and resolve dependencies, failing if the descriptor
57
57
  pool cannot satisfy them.
58
58
 
59
+ This will not return the classes for nested types within those classes, for
60
+ those, use GetMessageClass() on the nested types within their containing
61
+ messages.
62
+
63
+ For example, for the message:
64
+
65
+ message NestedTypeMessage {
66
+ message NestedType {
67
+ string data = 1;
68
+ }
69
+ NestedType nested = 1;
70
+ }
71
+
72
+ NestedTypeMessage will be in the result, but not
73
+ NestedTypeMessage.NestedType.
74
+
59
75
  Args:
60
76
  files: The file names to extract messages from.
61
77
  pool: The descriptor pool to find the files including the dependent files.
@@ -142,69 +158,6 @@ class MessageFactory(object):
142
158
  """Initializes a new factory."""
143
159
  self.pool = pool or descriptor_pool.DescriptorPool()
144
160
 
145
- def GetPrototype(self, descriptor):
146
- """Obtains a proto2 message class based on the passed in descriptor.
147
-
148
- Passing a descriptor with a fully qualified name matching a previous
149
- invocation will cause the same class to be returned.
150
-
151
- Args:
152
- descriptor: The descriptor to build from.
153
-
154
- Returns:
155
- A class describing the passed in descriptor.
156
- """
157
- warnings.warn(
158
- 'MessageFactory class is deprecated. Please use '
159
- 'GetMessageClass() instead of MessageFactory.GetPrototype. '
160
- 'MessageFactory class will be removed after 2024.',
161
- stacklevel=2,
162
- )
163
- return GetMessageClass(descriptor)
164
-
165
- def CreatePrototype(self, descriptor):
166
- """Builds a proto2 message class based on the passed in descriptor.
167
-
168
- Don't call this function directly, it always creates a new class. Call
169
- GetMessageClass() instead.
170
-
171
- Args:
172
- descriptor: The descriptor to build from.
173
-
174
- Returns:
175
- A class describing the passed in descriptor.
176
- """
177
- warnings.warn(
178
- 'Directly call CreatePrototype is wrong. Please use '
179
- 'GetMessageClass() method instead. Directly use '
180
- 'CreatePrototype will raise error after July 2023.',
181
- stacklevel=2,
182
- )
183
- return _InternalCreateMessageClass(descriptor)
184
-
185
- def GetMessages(self, files):
186
- """Gets all the messages from a specified file.
187
-
188
- This will find and resolve dependencies, failing if the descriptor
189
- pool cannot satisfy them.
190
-
191
- Args:
192
- files: The file names to extract messages from.
193
-
194
- Returns:
195
- A dictionary mapping proto names to the message classes. This will include
196
- any dependent messages as well as any messages defined in the same file as
197
- a specified message.
198
- """
199
- warnings.warn(
200
- 'MessageFactory class is deprecated. Please use '
201
- 'GetMessageClassesForFiles() instead of '
202
- 'MessageFactory.GetMessages(). MessageFactory class '
203
- 'will be removed after 2024.',
204
- stacklevel=2,
205
- )
206
- return GetMessageClassesForFiles(files, self.pool)
207
-
208
161
 
209
162
  def GetMessages(file_protos, pool=None):
210
163
  """Builds a dictionary of all the messages available in a set of files.
google/protobuf/proto.py CHANGED
@@ -8,7 +8,7 @@
8
8
  """Contains the Nextgen Pythonic protobuf APIs."""
9
9
 
10
10
  import io
11
- from typing import Type, TypeVar
11
+ from typing import Text, Type, TypeVar
12
12
 
13
13
  from google.protobuf.internal import decoder
14
14
  from google.protobuf.internal import encoder
@@ -114,3 +114,40 @@ def parse_length_prefixed(
114
114
  '{2}.'.format(size, parsed_size, message.DESCRIPTOR.name)
115
115
  )
116
116
  return message
117
+
118
+
119
+ def byte_size(message: Message) -> int:
120
+ """Returns the serialized size of this message.
121
+
122
+ Args:
123
+ message: A proto message.
124
+
125
+ Returns:
126
+ int: The number of bytes required to serialize this message.
127
+ """
128
+ return message.ByteSize()
129
+
130
+
131
+ def clear_message(message: Message) -> None:
132
+ """Clears all data that was set in the message.
133
+
134
+ Args:
135
+ message: The proto message to be cleared.
136
+ """
137
+ message.Clear()
138
+
139
+
140
+ def clear_field(message: Message, field_name: Text) -> None:
141
+ """Clears the contents of a given field.
142
+
143
+ Inside a oneof group, clears the field set. If the name neither refers to a
144
+ defined field or oneof group, :exc:`ValueError` is raised.
145
+
146
+ Args:
147
+ message: The proto message.
148
+ field_name (str): The name of the field to be cleared.
149
+
150
+ Raises:
151
+ ValueError: if the `field_name` is not a member of this message.
152
+ """
153
+ message.ClearField(field_name)
@@ -0,0 +1,129 @@
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2025 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 the Nextgen Pythonic Protobuf Text Format APIs."""
9
+ from typing import AnyStr, Callable, Optional, Text, Type, Union
10
+
11
+ from google.protobuf import text_format
12
+ from google.protobuf.descriptor_pool import DescriptorPool
13
+ from google.protobuf.message import Message
14
+
15
+ _MsgFormatter = Callable[[Message, Union[int, bool], bool], Optional[Text]]
16
+
17
+
18
+ def serialize(
19
+ message: Message,
20
+ as_utf8: bool = True,
21
+ as_one_line: bool = False,
22
+ use_short_repeated_primitives: bool = False,
23
+ pointy_brackets: bool = False,
24
+ use_index_order: bool = False,
25
+ float_format: Optional[str] = None,
26
+ double_format: Optional[str] = None,
27
+ use_field_number: bool = False,
28
+ descriptor_pool: Optional[DescriptorPool] = None,
29
+ indent: int = 0,
30
+ message_formatter: Optional[_MsgFormatter] = None,
31
+ print_unknown_fields: bool = False,
32
+ force_colon: bool = False,
33
+ ) -> str:
34
+ """Convert protobuf message to text format.
35
+
36
+ Double values can be formatted compactly with 15 digits of
37
+ precision (which is the most that IEEE 754 "double" can guarantee)
38
+ using double_format='.15g'. To ensure that converting to text and back to a
39
+ proto will result in an identical value, double_format='.17g' should be used.
40
+
41
+ Args:
42
+ message: The protocol buffers message.
43
+ as_utf8: Return unescaped Unicode for non-ASCII characters.
44
+ as_one_line: Don't introduce newlines between fields.
45
+ use_short_repeated_primitives: Use short repeated format for primitives.
46
+ pointy_brackets: If True, use angle brackets instead of curly braces for
47
+ nesting.
48
+ use_index_order: If True, fields of a proto message will be printed using
49
+ the order defined in source code instead of the field number, extensions
50
+ will be printed at the end of the message and their relative order is
51
+ determined by the extension number. By default, use the field number
52
+ order.
53
+ float_format (str): If set, use this to specify float field formatting (per
54
+ the "Format Specification Mini-Language"); otherwise, shortest float that
55
+ has same value in wire will be printed. Also affect double field if
56
+ double_format is not set but float_format is set.
57
+ double_format (str): If set, use this to specify double field formatting
58
+ (per the "Format Specification Mini-Language"); if it is not set but
59
+ float_format is set, use float_format. Otherwise, use ``str()``
60
+ use_field_number: If True, print field numbers instead of names.
61
+ descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
62
+ indent (int): The initial indent level, in terms of spaces, for pretty
63
+ print.
64
+ message_formatter (function(message, indent, as_one_line) -> unicode|None):
65
+ Custom formatter for selected sub-messages (usually based on message
66
+ type). Use to pretty print parts of the protobuf for easier diffing.
67
+ print_unknown_fields: If True, unknown fields will be printed.
68
+ force_colon: If set, a colon will be added after the field name even if the
69
+ field is a proto message.
70
+
71
+ Returns:
72
+ str: A string of the text formatted protocol buffer message.
73
+ """
74
+ return text_format.MessageToString(
75
+ message=message,
76
+ as_utf8=as_utf8,
77
+ as_one_line=as_one_line,
78
+ use_short_repeated_primitives=use_short_repeated_primitives,
79
+ pointy_brackets=pointy_brackets,
80
+ use_index_order=use_index_order,
81
+ float_format=float_format,
82
+ double_format=double_format,
83
+ use_field_number=use_field_number,
84
+ descriptor_pool=descriptor_pool,
85
+ indent=indent,
86
+ message_formatter=message_formatter,
87
+ print_unknown_fields=print_unknown_fields,
88
+ force_colon=force_colon,
89
+ )
90
+
91
+
92
+ def parse(
93
+ message_class: Type[Message],
94
+ text: AnyStr,
95
+ allow_unknown_extension: bool = False,
96
+ allow_field_number: bool = False,
97
+ descriptor_pool: Optional[DescriptorPool] = None,
98
+ allow_unknown_field: bool = False,
99
+ ) -> Message:
100
+ """Parses a text representation of a protocol message into a message.
101
+
102
+ Args:
103
+ message_class: The message meta class.
104
+ text (str): Message text representation.
105
+ message (Message): A protocol buffer message to merge into.
106
+ allow_unknown_extension: if True, skip over missing extensions and keep
107
+ parsing
108
+ allow_field_number: if True, both field number and field name are allowed.
109
+ descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
110
+ allow_unknown_field: if True, skip over unknown field and keep parsing.
111
+ Avoid to use this option if possible. It may hide some errors (e.g.
112
+ spelling error on field name)
113
+
114
+ Returns:
115
+ Message: A new message passed from text.
116
+
117
+ Raises:
118
+ ParseError: On text parsing problems.
119
+ """
120
+ new_message = message_class()
121
+ text_format.Parse(
122
+ text=text,
123
+ message=new_message,
124
+ allow_unknown_extension=allow_unknown_extension,
125
+ allow_field_number=allow_field_number,
126
+ descriptor_pool=descriptor_pool,
127
+ allow_unknown_field=allow_unknown_field,
128
+ )
129
+ return new_message
@@ -34,52 +34,3 @@ from google.protobuf import symbol_database
34
34
  GeneratedProtocolMessageType = message_factory._GENERATED_PROTOCOL_MESSAGE_TYPE
35
35
 
36
36
  MESSAGE_CLASS_CACHE = {}
37
-
38
-
39
- # Deprecated. Please NEVER use reflection.ParseMessage().
40
- def ParseMessage(descriptor, byte_str):
41
- """Generate a new Message instance from this Descriptor and a byte string.
42
-
43
- DEPRECATED: ParseMessage is deprecated because it is using MakeClass().
44
- Please use MessageFactory.GetMessageClass() instead.
45
-
46
- Args:
47
- descriptor: Protobuf Descriptor object
48
- byte_str: Serialized protocol buffer byte string
49
-
50
- Returns:
51
- Newly created protobuf Message object.
52
- """
53
- warnings.warn(
54
- 'reflection.ParseMessage() is deprecated. Please use '
55
- 'MessageFactory.GetMessageClass() and message.ParseFromString() instead. '
56
- 'reflection.ParseMessage() will be removed in Jan 2025.',
57
- stacklevel=2,
58
- )
59
- result_class = MakeClass(descriptor)
60
- new_msg = result_class()
61
- new_msg.ParseFromString(byte_str)
62
- return new_msg
63
-
64
-
65
- # Deprecated. Please NEVER use reflection.MakeClass().
66
- def MakeClass(descriptor):
67
- """Construct a class object for a protobuf described by descriptor.
68
-
69
- DEPRECATED: use MessageFactory.GetMessageClass() instead.
70
-
71
- Args:
72
- descriptor: A descriptor.Descriptor object describing the protobuf.
73
- Returns:
74
- The Message class object described by the descriptor.
75
- """
76
- warnings.warn(
77
- 'reflection.MakeClass() is deprecated. Please use '
78
- 'MessageFactory.GetMessageClass() instead. '
79
- 'reflection.MakeClass() will be removed in Jan 2025.',
80
- stacklevel=2,
81
- )
82
- # Original implementation leads to duplicate message classes, which won't play
83
- # well with extensions. Message factory info is also missing.
84
- # Redirect to message_factory.
85
- return message_factory.GetMessageClass(descriptor)
@@ -27,9 +27,9 @@ class Domain(Enum):
27
27
  # the Protobuf release process. Do not edit them manually.
28
28
  # These OSS versions are not stripped to avoid merging conflicts.
29
29
  OSS_DOMAIN = Domain.PUBLIC
30
- OSS_MAJOR = 5
31
- OSS_MINOR = 29
32
- OSS_PATCH = 4
30
+ OSS_MAJOR = 6
31
+ OSS_MINOR = 33
32
+ OSS_PATCH = 3
33
33
  OSS_SUFFIX = ''
34
34
 
35
35
  DOMAIN = OSS_DOMAIN
@@ -92,33 +92,13 @@ def ValidateProtobufRuntimeVersion(
92
92
  ' Cross-domain usage of Protobuf is not supported.'
93
93
  )
94
94
 
95
- if gen_major != MAJOR:
96
- if gen_major == MAJOR - 1:
97
- if _warning_count < _MAX_WARNING_COUNT:
98
- warnings.warn(
99
- 'Protobuf gencode version %s is exactly one major version older'
100
- ' than the runtime version %s at %s. Please update the gencode to'
101
- ' avoid compatibility violations in the next runtime release.'
102
- % (gen_version, version, location)
103
- )
104
- _warning_count += 1
105
- else:
106
- _ReportVersionError(
107
- 'Detected mismatched Protobuf Gencode/Runtime major versions when'
108
- f' loading {location}: gencode {gen_version} runtime {version}.'
109
- f' Same major version is required. {error_prompt}'
110
- )
111
-
112
- if MINOR < gen_minor or (MINOR == gen_minor and PATCH < gen_patch):
95
+ if (
96
+ MAJOR < gen_major
97
+ or (MAJOR == gen_major and MINOR < gen_minor)
98
+ or (MAJOR == gen_major and MINOR == gen_minor and PATCH < gen_patch)
99
+ ):
113
100
  _ReportVersionError(
114
101
  'Detected incompatible Protobuf Gencode/Runtime versions when loading'
115
102
  f' {location}: gencode {gen_version} runtime {version}. Runtime version'
116
103
  f' cannot be older than the linked gencode version. {error_prompt}'
117
104
  )
118
-
119
- if gen_suffix != SUFFIX:
120
- _ReportVersionError(
121
- 'Detected mismatched Protobuf Gencode/Runtime version suffixes when'
122
- f' loading {location}: gencode {gen_version} runtime {version}.'
123
- f' Version suffixes must be the same. {error_prompt}'
124
- )
@@ -2,7 +2,7 @@
2
2
  # Generated by the protocol buffer compiler. DO NOT EDIT!
3
3
  # NO CHECKED-IN PROTOBUF GENCODE
4
4
  # source: google/protobuf/source_context.proto
5
- # Protobuf Python Version: 5.29.4
5
+ # Protobuf Python Version: 6.33.3
6
6
  """Generated protocol buffer code."""
7
7
  from google.protobuf import descriptor as _descriptor
8
8
  from google.protobuf import descriptor_pool as _descriptor_pool
@@ -11,9 +11,9 @@ from google.protobuf import symbol_database as _symbol_database
11
11
  from google.protobuf.internal import builder as _builder
12
12
  _runtime_version.ValidateProtobufRuntimeVersion(
13
13
  _runtime_version.Domain.PUBLIC,
14
- 5,
15
- 29,
16
- 4,
14
+ 6,
15
+ 33,
16
+ 3,
17
17
  '',
18
18
  'google/protobuf/source_context.proto'
19
19
  )
@@ -2,7 +2,7 @@
2
2
  # Generated by the protocol buffer compiler. DO NOT EDIT!
3
3
  # NO CHECKED-IN PROTOBUF GENCODE
4
4
  # source: google/protobuf/struct.proto
5
- # Protobuf Python Version: 5.29.4
5
+ # Protobuf Python Version: 6.33.3
6
6
  """Generated protocol buffer code."""
7
7
  from google.protobuf import descriptor as _descriptor
8
8
  from google.protobuf import descriptor_pool as _descriptor_pool
@@ -11,9 +11,9 @@ from google.protobuf import symbol_database as _symbol_database
11
11
  from google.protobuf.internal import builder as _builder
12
12
  _runtime_version.ValidateProtobufRuntimeVersion(
13
13
  _runtime_version.Domain.PUBLIC,
14
- 5,
15
- 29,
16
- 4,
14
+ 6,
15
+ 33,
16
+ 3,
17
17
  '',
18
18
  'google/protobuf/struct.proto'
19
19
  )
@@ -51,24 +51,6 @@ class SymbolDatabase():
51
51
  """Initializes a new SymbolDatabase."""
52
52
  self.pool = pool or descriptor_pool.DescriptorPool()
53
53
 
54
- def GetPrototype(self, descriptor):
55
- warnings.warn('SymbolDatabase.GetPrototype() is deprecated. Please '
56
- 'use message_factory.GetMessageClass() instead. '
57
- 'SymbolDatabase.GetPrototype() will be removed soon.')
58
- return message_factory.GetMessageClass(descriptor)
59
-
60
- def CreatePrototype(self, descriptor):
61
- warnings.warn('Directly call CreatePrototype() is wrong. Please use '
62
- 'message_factory.GetMessageClass() instead. '
63
- 'SymbolDatabase.CreatePrototype() will be removed soon.')
64
- return message_factory._InternalCreateMessageClass(descriptor)
65
-
66
- def GetMessages(self, files):
67
- warnings.warn('SymbolDatabase.GetMessages() is deprecated. Please use '
68
- 'message_factory.GetMessageClassedForFiles() instead. '
69
- 'SymbolDatabase.GetMessages() will be removed soon.')
70
- return message_factory.GetMessageClassedForFiles(files, self.pool)
71
-
72
54
  def RegisterMessage(self, message):
73
55
  """Registers the given message type in the local database.
74
56