aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.ru>2022-02-10 16:45:08 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:08 +0300
commit4e839db24a3bbc9f1c610c43d6faaaa99824dcca (patch)
tree506dac10f5df94fab310584ee51b24fc5a081c22 /contrib/python
parent2d37894b1b037cf24231090eda8589bbb44fb6fc (diff)
downloadydb-4e839db24a3bbc9f1c610c43d6faaaa99824dcca.tar.gz
Restoring authorship annotation for <thegeorg@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/python')
-rw-r--r--contrib/python/Jinja2/ya.make2
-rw-r--r--contrib/python/MarkupSafe/ya.make2
-rw-r--r--contrib/python/Pygments/ya.make2
-rw-r--r--contrib/python/certifi/ya.make2
-rw-r--r--contrib/python/future/ya.make2
-rw-r--r--contrib/python/ipython/ya.make2
-rw-r--r--contrib/python/mypy-protobuf/ya.make2
-rw-r--r--contrib/python/packaging/ya.make2
-rw-r--r--contrib/python/parso/ya.make2
-rw-r--r--contrib/python/pluggy/ya.make2
-rw-r--r--contrib/python/prompt-toolkit/ya.make2
-rw-r--r--contrib/python/protobuf/py2/.yandex_meta/devtools.copyrights.report216
-rw-r--r--contrib/python/protobuf/py2/.yandex_meta/devtools.licenses.report214
-rw-r--r--contrib/python/protobuf/py2/.yandex_meta/licenses.list.txt124
-rw-r--r--contrib/python/protobuf/py2/google/__init__.py8
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/__init__.py2
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/descriptor.py706
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/descriptor_database.py94
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/descriptor_pool.py662
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/internal/__init__.py60
-rwxr-xr-xcontrib/python/protobuf/py2/google/protobuf/internal/_parameterized.py54
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/internal/api_implementation.cc66
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/internal/api_implementation.py50
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/internal/containers.py340
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/internal/decoder.py456
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/internal/encoder.py34
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/internal/enum_type_wrapper.py78
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/internal/extension_dict.py426
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/internal/python_message.py410
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/internal/type_checkers.py158
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/internal/well_known_types.py262
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/json_format.py302
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/message.py340
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/message_factory.py130
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/proto_api.h246
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/proto_builder.py18
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/descriptor.cc478
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/descriptor.h10
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_containers.cc586
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_containers.h2
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_database.cc98
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_database.h24
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_pool.cc514
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_pool.h16
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/extension_dict.cc568
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/extension_dict.h10
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/field.cc284
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/field.h118
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/map_container.cc496
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/map_container.h18
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/message.cc2036
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/message.h318
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/message_factory.cc162
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/message_factory.h16
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/message_module.cc162
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/repeated_composite_container.cc762
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/repeated_composite_container.h16
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/repeated_scalar_container.cc610
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/repeated_scalar_container.h10
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/safe_numerics.h16
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/scoped_pyobject_ptr.h4
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/unknown_fields.cc716
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/pyext/unknown_fields.h180
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/reflection.py26
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/service.py4
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/service_reflection.py22
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/symbol_database.py48
-rw-r--r--contrib/python/protobuf/py2/google/protobuf/text_format.py880
-rw-r--r--contrib/python/protobuf/py2/ya.make186
-rw-r--r--contrib/python/protobuf/py3/.yandex_meta/devtools.copyrights.report216
-rw-r--r--contrib/python/protobuf/py3/.yandex_meta/devtools.licenses.report214
-rw-r--r--contrib/python/protobuf/py3/.yandex_meta/licenses.list.txt124
-rw-r--r--contrib/python/protobuf/py3/README.md264
-rw-r--r--contrib/python/protobuf/py3/google/__init__.py8
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/__init__.py2
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/descriptor.py706
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/descriptor_database.py94
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/descriptor_pool.py662
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/internal/__init__.py60
-rwxr-xr-xcontrib/python/protobuf/py3/google/protobuf/internal/_parameterized.py54
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.cc66
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.py50
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/internal/containers.py340
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/internal/decoder.py456
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/internal/encoder.py34
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/internal/enum_type_wrapper.py78
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/internal/extension_dict.py426
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/internal/python_message.py410
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/internal/type_checkers.py158
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/internal/well_known_types.py262
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/json_format.py302
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/message.py340
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/message_factory.py130
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/proto_api.h246
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/proto_builder.py18
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.cc478
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.h10
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.cc586
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.h2
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_database.cc98
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_database.h24
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.cc514
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.h16
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.cc568
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.h10
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/field.cc284
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/field.h118
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/map_container.cc496
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/map_container.h18
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/message.cc2036
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/message.h318
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.cc162
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.h16
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/message_module.cc162
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/repeated_composite_container.cc762
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/repeated_composite_container.h16
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/repeated_scalar_container.cc610
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/repeated_scalar_container.h10
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/safe_numerics.h16
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/scoped_pyobject_ptr.h4
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.cc716
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.h180
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/reflection.py26
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/service.py4
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/service_reflection.py22
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/symbol_database.py48
-rw-r--r--contrib/python/protobuf/py3/google/protobuf/text_format.py880
-rw-r--r--contrib/python/protobuf/py3/ya.make190
-rw-r--r--contrib/python/protobuf/ya.make36
-rw-r--r--contrib/python/s3transfer/ya.make2
-rw-r--r--contrib/python/setuptools/ya.make2
-rw-r--r--contrib/python/tornado/ya.make2
-rw-r--r--contrib/python/traitlets/ya.make2
-rw-r--r--contrib/python/ya.make24
134 files changed, 15031 insertions, 15031 deletions
diff --git a/contrib/python/Jinja2/ya.make b/contrib/python/Jinja2/ya.make
index 40f6572401..34890c8170 100644
--- a/contrib/python/Jinja2/ya.make
+++ b/contrib/python/Jinja2/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/MarkupSafe/ya.make b/contrib/python/MarkupSafe/ya.make
index 764b5915ff..fefb8cdc47 100644
--- a/contrib/python/MarkupSafe/ya.make
+++ b/contrib/python/MarkupSafe/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/Pygments/ya.make b/contrib/python/Pygments/ya.make
index 9aec5a65a8..65ab9c912e 100644
--- a/contrib/python/Pygments/ya.make
+++ b/contrib/python/Pygments/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/certifi/ya.make b/contrib/python/certifi/ya.make
index d13fe73acc..926e9d4549 100644
--- a/contrib/python/certifi/ya.make
+++ b/contrib/python/certifi/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(orivej g:python-contrib)
diff --git a/contrib/python/future/ya.make b/contrib/python/future/ya.make
index ba24f13341..541ee3bb44 100644
--- a/contrib/python/future/ya.make
+++ b/contrib/python/future/ya.make
@@ -137,7 +137,7 @@ PY_SRCS(
past/utils/__init__.py
)
-IF (MODULE_TAG == "PY2")
+IF (MODULE_TAG == "PY2")
PY_SRCS(
TOP_LEVEL
_dummy_thread/__init__.py
diff --git a/contrib/python/ipython/ya.make b/contrib/python/ipython/ya.make
index b1dd8c5e23..e4ed9bd733 100644
--- a/contrib/python/ipython/ya.make
+++ b/contrib/python/ipython/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/mypy-protobuf/ya.make b/contrib/python/mypy-protobuf/ya.make
index 4f86fe6bf9..70c420e2c6 100644
--- a/contrib/python/mypy-protobuf/ya.make
+++ b/contrib/python/mypy-protobuf/ya.make
@@ -7,7 +7,7 @@ VERSION(2.10)
LICENSE(Apache-2.0)
PEERDIR(
- contrib/python/protobuf
+ contrib/python/protobuf
)
NO_LINT()
diff --git a/contrib/python/packaging/ya.make b/contrib/python/packaging/ya.make
index 45549cf137..20409bac48 100644
--- a/contrib/python/packaging/ya.make
+++ b/contrib/python/packaging/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/parso/ya.make b/contrib/python/parso/ya.make
index 05de6d3bbd..b9bf8e51d0 100644
--- a/contrib/python/parso/ya.make
+++ b/contrib/python/parso/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/pluggy/ya.make b/contrib/python/pluggy/ya.make
index 43e4c7b2ab..85968936c4 100644
--- a/contrib/python/pluggy/ya.make
+++ b/contrib/python/pluggy/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/prompt-toolkit/ya.make b/contrib/python/prompt-toolkit/ya.make
index f1f936eb3f..52142c3115 100644
--- a/contrib/python/prompt-toolkit/ya.make
+++ b/contrib/python/prompt-toolkit/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/protobuf/py2/.yandex_meta/devtools.copyrights.report b/contrib/python/protobuf/py2/.yandex_meta/devtools.copyrights.report
index 295c793dec..9450a6cbed 100644
--- a/contrib/python/protobuf/py2/.yandex_meta/devtools.copyrights.report
+++ b/contrib/python/protobuf/py2/.yandex_meta/devtools.copyrights.report
@@ -1,108 +1,108 @@
-# File format ($ symbol means the beginning of a line):
-#
-# $ # this message
-# $ # =======================
-# $ # comments (all commentaries should starts with some number of spaces and # symbol)
-# ${action} {license id} {license text hash}
-# $BELONGS ./ya/make/file/relative/path/1/ya.make ./ya/make/2/ya.make
-# ${all_file_action} filename
-# $ # user commentaries (many lines)
-# $ generated description - files with this license, license text... (some number of lines that starts with some number of spaces, do not modify)
-# ${action} {license spdx} {license text hash}
-# $BELONGS ./ya/make/file/relative/path/3/ya.make
-# ${all_file_action} filename
-# $ # user commentaries
-# $ generated description
-# $ ...
-#
-# You can modify action, all_file_action and add commentaries
-# Available actions:
-# keep - keep license in contrib and use in credits
-# skip - skip license
-# remove - remove all files with this license
-# rename - save license text/links into licenses texts file, but not store SPDX into LINCENSE macro. You should store correct license id into devtools.license.spdx.txt file
-#
-# {all file action} records will be generated when license text contains filename that exists on filesystem (in contrib directory)
-# We suppose that that files can contain some license info
-# Available all file actions:
-# FILE_IGNORE - ignore file (do nothing)
-# FILE_INCLUDE - include all file data into licenses text file
-# =======================
-
-KEEP COPYRIGHT_SERVICE_LABEL 29be00457f74dcf5f2b494d41d6a6c10
-BELONGS ya.make
- License text:
- \# Copyright 2007 Google Inc. All Rights Reserved.
- Scancode info:
- Original SPDX id: COPYRIGHT_SERVICE_LABEL
- Score : 100.00
- Match type : COPYRIGHT
- Files with this license:
- google/protobuf/__init__.py [31:31]
-
-KEEP COPYRIGHT_SERVICE_LABEL 7ddb2995f48012001146c0eb94d23367
-BELONGS ya.make
- License text:
- \# Copyright 2008 Google Inc. All rights reserved.
- Scancode info:
- Original SPDX id: COPYRIGHT_SERVICE_LABEL
- Score : 100.00
- Match type : COPYRIGHT
- Files with this license:
- google/protobuf/__init__.py [2:2]
- google/protobuf/descriptor.py [2:2]
- google/protobuf/descriptor_database.py [2:2]
- google/protobuf/descriptor_pool.py [2:2]
- google/protobuf/internal/__init__.py [2:2]
- google/protobuf/internal/_parameterized.py [4:4]
- google/protobuf/internal/api_implementation.cc [2:2]
- google/protobuf/internal/api_implementation.py [2:2]
- google/protobuf/internal/containers.py [2:2]
- google/protobuf/internal/decoder.py [2:2]
- google/protobuf/internal/encoder.py [2:2]
- google/protobuf/internal/enum_type_wrapper.py [2:2]
- google/protobuf/internal/extension_dict.py [2:2]
- google/protobuf/internal/message_listener.py [2:2]
- google/protobuf/internal/python_message.py [2:2]
- google/protobuf/internal/type_checkers.py [2:2]
- google/protobuf/internal/well_known_types.py [2:2]
- google/protobuf/internal/wire_format.py [2:2]
- google/protobuf/json_format.py [2:2]
- google/protobuf/message.py [2:2]
- google/protobuf/message_factory.py [2:2]
- google/protobuf/proto_api.h [2:2]
- google/protobuf/proto_builder.py [2:2]
- google/protobuf/pyext/cpp_message.py [2:2]
- google/protobuf/pyext/descriptor.cc [2:2]
- google/protobuf/pyext/descriptor.h [2:2]
- google/protobuf/pyext/descriptor_containers.cc [2:2]
- google/protobuf/pyext/descriptor_containers.h [2:2]
- google/protobuf/pyext/descriptor_database.cc [2:2]
- google/protobuf/pyext/descriptor_database.h [2:2]
- google/protobuf/pyext/descriptor_pool.cc [2:2]
- google/protobuf/pyext/descriptor_pool.h [2:2]
- google/protobuf/pyext/extension_dict.cc [2:2]
- google/protobuf/pyext/extension_dict.h [2:2]
- google/protobuf/pyext/field.cc [2:2]
- google/protobuf/pyext/field.h [2:2]
- google/protobuf/pyext/map_container.cc [2:2]
- google/protobuf/pyext/map_container.h [2:2]
- google/protobuf/pyext/message.cc [2:2]
- google/protobuf/pyext/message.h [2:2]
- google/protobuf/pyext/message_factory.cc [2:2]
- google/protobuf/pyext/message_factory.h [2:2]
- google/protobuf/pyext/message_module.cc [2:2]
- google/protobuf/pyext/repeated_composite_container.cc [2:2]
- google/protobuf/pyext/repeated_composite_container.h [2:2]
- google/protobuf/pyext/repeated_scalar_container.cc [2:2]
- google/protobuf/pyext/repeated_scalar_container.h [2:2]
- google/protobuf/pyext/safe_numerics.h [2:2]
- google/protobuf/pyext/scoped_pyobject_ptr.h [2:2]
- google/protobuf/pyext/unknown_fields.cc [2:2]
- google/protobuf/pyext/unknown_fields.h [2:2]
- google/protobuf/reflection.py [2:2]
- google/protobuf/service.py [2:2]
- google/protobuf/service_reflection.py [2:2]
- google/protobuf/symbol_database.py [2:2]
- google/protobuf/text_encoding.py [2:2]
- google/protobuf/text_format.py [2:2]
+# File format ($ symbol means the beginning of a line):
+#
+# $ # this message
+# $ # =======================
+# $ # comments (all commentaries should starts with some number of spaces and # symbol)
+# ${action} {license id} {license text hash}
+# $BELONGS ./ya/make/file/relative/path/1/ya.make ./ya/make/2/ya.make
+# ${all_file_action} filename
+# $ # user commentaries (many lines)
+# $ generated description - files with this license, license text... (some number of lines that starts with some number of spaces, do not modify)
+# ${action} {license spdx} {license text hash}
+# $BELONGS ./ya/make/file/relative/path/3/ya.make
+# ${all_file_action} filename
+# $ # user commentaries
+# $ generated description
+# $ ...
+#
+# You can modify action, all_file_action and add commentaries
+# Available actions:
+# keep - keep license in contrib and use in credits
+# skip - skip license
+# remove - remove all files with this license
+# rename - save license text/links into licenses texts file, but not store SPDX into LINCENSE macro. You should store correct license id into devtools.license.spdx.txt file
+#
+# {all file action} records will be generated when license text contains filename that exists on filesystem (in contrib directory)
+# We suppose that that files can contain some license info
+# Available all file actions:
+# FILE_IGNORE - ignore file (do nothing)
+# FILE_INCLUDE - include all file data into licenses text file
+# =======================
+
+KEEP COPYRIGHT_SERVICE_LABEL 29be00457f74dcf5f2b494d41d6a6c10
+BELONGS ya.make
+ License text:
+ \# Copyright 2007 Google Inc. All Rights Reserved.
+ Scancode info:
+ Original SPDX id: COPYRIGHT_SERVICE_LABEL
+ Score : 100.00
+ Match type : COPYRIGHT
+ Files with this license:
+ google/protobuf/__init__.py [31:31]
+
+KEEP COPYRIGHT_SERVICE_LABEL 7ddb2995f48012001146c0eb94d23367
+BELONGS ya.make
+ License text:
+ \# Copyright 2008 Google Inc. All rights reserved.
+ Scancode info:
+ Original SPDX id: COPYRIGHT_SERVICE_LABEL
+ Score : 100.00
+ Match type : COPYRIGHT
+ Files with this license:
+ google/protobuf/__init__.py [2:2]
+ google/protobuf/descriptor.py [2:2]
+ google/protobuf/descriptor_database.py [2:2]
+ google/protobuf/descriptor_pool.py [2:2]
+ google/protobuf/internal/__init__.py [2:2]
+ google/protobuf/internal/_parameterized.py [4:4]
+ google/protobuf/internal/api_implementation.cc [2:2]
+ google/protobuf/internal/api_implementation.py [2:2]
+ google/protobuf/internal/containers.py [2:2]
+ google/protobuf/internal/decoder.py [2:2]
+ google/protobuf/internal/encoder.py [2:2]
+ google/protobuf/internal/enum_type_wrapper.py [2:2]
+ google/protobuf/internal/extension_dict.py [2:2]
+ google/protobuf/internal/message_listener.py [2:2]
+ google/protobuf/internal/python_message.py [2:2]
+ google/protobuf/internal/type_checkers.py [2:2]
+ google/protobuf/internal/well_known_types.py [2:2]
+ google/protobuf/internal/wire_format.py [2:2]
+ google/protobuf/json_format.py [2:2]
+ google/protobuf/message.py [2:2]
+ google/protobuf/message_factory.py [2:2]
+ google/protobuf/proto_api.h [2:2]
+ google/protobuf/proto_builder.py [2:2]
+ google/protobuf/pyext/cpp_message.py [2:2]
+ google/protobuf/pyext/descriptor.cc [2:2]
+ google/protobuf/pyext/descriptor.h [2:2]
+ google/protobuf/pyext/descriptor_containers.cc [2:2]
+ google/protobuf/pyext/descriptor_containers.h [2:2]
+ google/protobuf/pyext/descriptor_database.cc [2:2]
+ google/protobuf/pyext/descriptor_database.h [2:2]
+ google/protobuf/pyext/descriptor_pool.cc [2:2]
+ google/protobuf/pyext/descriptor_pool.h [2:2]
+ google/protobuf/pyext/extension_dict.cc [2:2]
+ google/protobuf/pyext/extension_dict.h [2:2]
+ google/protobuf/pyext/field.cc [2:2]
+ google/protobuf/pyext/field.h [2:2]
+ google/protobuf/pyext/map_container.cc [2:2]
+ google/protobuf/pyext/map_container.h [2:2]
+ google/protobuf/pyext/message.cc [2:2]
+ google/protobuf/pyext/message.h [2:2]
+ google/protobuf/pyext/message_factory.cc [2:2]
+ google/protobuf/pyext/message_factory.h [2:2]
+ google/protobuf/pyext/message_module.cc [2:2]
+ google/protobuf/pyext/repeated_composite_container.cc [2:2]
+ google/protobuf/pyext/repeated_composite_container.h [2:2]
+ google/protobuf/pyext/repeated_scalar_container.cc [2:2]
+ google/protobuf/pyext/repeated_scalar_container.h [2:2]
+ google/protobuf/pyext/safe_numerics.h [2:2]
+ google/protobuf/pyext/scoped_pyobject_ptr.h [2:2]
+ google/protobuf/pyext/unknown_fields.cc [2:2]
+ google/protobuf/pyext/unknown_fields.h [2:2]
+ google/protobuf/reflection.py [2:2]
+ google/protobuf/service.py [2:2]
+ google/protobuf/service_reflection.py [2:2]
+ google/protobuf/symbol_database.py [2:2]
+ google/protobuf/text_encoding.py [2:2]
+ google/protobuf/text_format.py [2:2]
diff --git a/contrib/python/protobuf/py2/.yandex_meta/devtools.licenses.report b/contrib/python/protobuf/py2/.yandex_meta/devtools.licenses.report
index 3da6c693e5..e174828acb 100644
--- a/contrib/python/protobuf/py2/.yandex_meta/devtools.licenses.report
+++ b/contrib/python/protobuf/py2/.yandex_meta/devtools.licenses.report
@@ -1,107 +1,107 @@
-# File format ($ symbol means the beginning of a line):
-#
-# $ # this message
-# $ # =======================
-# $ # comments (all commentaries should starts with some number of spaces and # symbol)
-# ${action} {license id} {license text hash}
-# $BELONGS ./ya/make/file/relative/path/1/ya.make ./ya/make/2/ya.make
-# ${all_file_action} filename
-# $ # user commentaries (many lines)
-# $ generated description - files with this license, license text... (some number of lines that starts with some number of spaces, do not modify)
-# ${action} {license spdx} {license text hash}
-# $BELONGS ./ya/make/file/relative/path/3/ya.make
-# ${all_file_action} filename
-# $ # user commentaries
-# $ generated description
-# $ ...
-#
-# You can modify action, all_file_action and add commentaries
-# Available actions:
-# keep - keep license in contrib and use in credits
-# skip - skip license
-# remove - remove all files with this license
-# rename - save license text/links into licenses texts file, but not store SPDX into LINCENSE macro. You should store correct license id into devtools.license.spdx.txt file
-#
-# {all file action} records will be generated when license text contains filename that exists on filesystem (in contrib directory)
-# We suppose that that files can contain some license info
-# Available all file actions:
-# FILE_IGNORE - ignore file (do nothing)
-# FILE_INCLUDE - include all file data into licenses text file
-# =======================
-
-KEEP BSD-3-Clause 6aa235708ac9f5dd8e5c6ac415fc5837
-BELONGS ya.make
- Note: matched license text is too long. Read it in the source files.
- Scancode info:
- Original SPDX id: BSD-3-Clause
- Score : 100.00
- Match type : TEXT
- Links : http://www.opensource.org/licenses/BSD-3-Clause, https://spdx.org/licenses/BSD-3-Clause
- Files with this license:
- google/protobuf/internal/api_implementation.cc [5:29]
- google/protobuf/proto_api.h [5:29]
- google/protobuf/pyext/descriptor.cc [5:29]
- google/protobuf/pyext/descriptor.h [5:29]
- google/protobuf/pyext/descriptor_containers.cc [5:29]
- google/protobuf/pyext/descriptor_containers.h [5:29]
- google/protobuf/pyext/descriptor_database.cc [5:29]
- google/protobuf/pyext/descriptor_database.h [5:29]
- google/protobuf/pyext/descriptor_pool.cc [5:29]
- google/protobuf/pyext/descriptor_pool.h [5:29]
- google/protobuf/pyext/extension_dict.cc [5:29]
- google/protobuf/pyext/extension_dict.h [5:29]
- google/protobuf/pyext/field.cc [5:29]
- google/protobuf/pyext/field.h [5:29]
- google/protobuf/pyext/map_container.cc [5:29]
- google/protobuf/pyext/map_container.h [5:29]
- google/protobuf/pyext/message.cc [5:29]
- google/protobuf/pyext/message.h [5:29]
- google/protobuf/pyext/message_factory.cc [5:29]
- google/protobuf/pyext/message_factory.h [5:29]
- google/protobuf/pyext/message_module.cc [5:29]
- google/protobuf/pyext/repeated_composite_container.cc [5:29]
- google/protobuf/pyext/repeated_composite_container.h [5:29]
- google/protobuf/pyext/repeated_scalar_container.cc [5:29]
- google/protobuf/pyext/repeated_scalar_container.h [5:29]
- google/protobuf/pyext/safe_numerics.h [5:29]
- google/protobuf/pyext/scoped_pyobject_ptr.h [5:29]
- google/protobuf/pyext/unknown_fields.cc [5:29]
- google/protobuf/pyext/unknown_fields.h [5:29]
-
-KEEP BSD-3-Clause 8aaace038fd54f3a52b1f041f9504709
-BELONGS ya.make
- Note: matched license text is too long. Read it in the source files.
- Scancode info:
- Original SPDX id: BSD-3-Clause
- Score : 100.00
- Match type : TEXT
- Links : http://www.opensource.org/licenses/BSD-3-Clause, https://spdx.org/licenses/BSD-3-Clause
- Files with this license:
- google/protobuf/__init__.py [5:29]
- google/protobuf/descriptor.py [5:29]
- google/protobuf/descriptor_database.py [5:29]
- google/protobuf/descriptor_pool.py [5:29]
- google/protobuf/internal/__init__.py [5:29]
- google/protobuf/internal/_parameterized.py [7:31]
- google/protobuf/internal/api_implementation.py [5:29]
- google/protobuf/internal/containers.py [5:29]
- google/protobuf/internal/decoder.py [5:29]
- google/protobuf/internal/encoder.py [5:29]
- google/protobuf/internal/enum_type_wrapper.py [5:29]
- google/protobuf/internal/extension_dict.py [5:29]
- google/protobuf/internal/message_listener.py [5:29]
- google/protobuf/internal/python_message.py [5:29]
- google/protobuf/internal/type_checkers.py [5:29]
- google/protobuf/internal/well_known_types.py [5:29]
- google/protobuf/internal/wire_format.py [5:29]
- google/protobuf/json_format.py [5:29]
- google/protobuf/message.py [5:29]
- google/protobuf/message_factory.py [5:29]
- google/protobuf/proto_builder.py [5:29]
- google/protobuf/pyext/cpp_message.py [5:29]
- google/protobuf/reflection.py [5:29]
- google/protobuf/service.py [5:29]
- google/protobuf/service_reflection.py [5:29]
- google/protobuf/symbol_database.py [5:29]
- google/protobuf/text_encoding.py [5:29]
- google/protobuf/text_format.py [5:29]
+# File format ($ symbol means the beginning of a line):
+#
+# $ # this message
+# $ # =======================
+# $ # comments (all commentaries should starts with some number of spaces and # symbol)
+# ${action} {license id} {license text hash}
+# $BELONGS ./ya/make/file/relative/path/1/ya.make ./ya/make/2/ya.make
+# ${all_file_action} filename
+# $ # user commentaries (many lines)
+# $ generated description - files with this license, license text... (some number of lines that starts with some number of spaces, do not modify)
+# ${action} {license spdx} {license text hash}
+# $BELONGS ./ya/make/file/relative/path/3/ya.make
+# ${all_file_action} filename
+# $ # user commentaries
+# $ generated description
+# $ ...
+#
+# You can modify action, all_file_action and add commentaries
+# Available actions:
+# keep - keep license in contrib and use in credits
+# skip - skip license
+# remove - remove all files with this license
+# rename - save license text/links into licenses texts file, but not store SPDX into LINCENSE macro. You should store correct license id into devtools.license.spdx.txt file
+#
+# {all file action} records will be generated when license text contains filename that exists on filesystem (in contrib directory)
+# We suppose that that files can contain some license info
+# Available all file actions:
+# FILE_IGNORE - ignore file (do nothing)
+# FILE_INCLUDE - include all file data into licenses text file
+# =======================
+
+KEEP BSD-3-Clause 6aa235708ac9f5dd8e5c6ac415fc5837
+BELONGS ya.make
+ Note: matched license text is too long. Read it in the source files.
+ Scancode info:
+ Original SPDX id: BSD-3-Clause
+ Score : 100.00
+ Match type : TEXT
+ Links : http://www.opensource.org/licenses/BSD-3-Clause, https://spdx.org/licenses/BSD-3-Clause
+ Files with this license:
+ google/protobuf/internal/api_implementation.cc [5:29]
+ google/protobuf/proto_api.h [5:29]
+ google/protobuf/pyext/descriptor.cc [5:29]
+ google/protobuf/pyext/descriptor.h [5:29]
+ google/protobuf/pyext/descriptor_containers.cc [5:29]
+ google/protobuf/pyext/descriptor_containers.h [5:29]
+ google/protobuf/pyext/descriptor_database.cc [5:29]
+ google/protobuf/pyext/descriptor_database.h [5:29]
+ google/protobuf/pyext/descriptor_pool.cc [5:29]
+ google/protobuf/pyext/descriptor_pool.h [5:29]
+ google/protobuf/pyext/extension_dict.cc [5:29]
+ google/protobuf/pyext/extension_dict.h [5:29]
+ google/protobuf/pyext/field.cc [5:29]
+ google/protobuf/pyext/field.h [5:29]
+ google/protobuf/pyext/map_container.cc [5:29]
+ google/protobuf/pyext/map_container.h [5:29]
+ google/protobuf/pyext/message.cc [5:29]
+ google/protobuf/pyext/message.h [5:29]
+ google/protobuf/pyext/message_factory.cc [5:29]
+ google/protobuf/pyext/message_factory.h [5:29]
+ google/protobuf/pyext/message_module.cc [5:29]
+ google/protobuf/pyext/repeated_composite_container.cc [5:29]
+ google/protobuf/pyext/repeated_composite_container.h [5:29]
+ google/protobuf/pyext/repeated_scalar_container.cc [5:29]
+ google/protobuf/pyext/repeated_scalar_container.h [5:29]
+ google/protobuf/pyext/safe_numerics.h [5:29]
+ google/protobuf/pyext/scoped_pyobject_ptr.h [5:29]
+ google/protobuf/pyext/unknown_fields.cc [5:29]
+ google/protobuf/pyext/unknown_fields.h [5:29]
+
+KEEP BSD-3-Clause 8aaace038fd54f3a52b1f041f9504709
+BELONGS ya.make
+ Note: matched license text is too long. Read it in the source files.
+ Scancode info:
+ Original SPDX id: BSD-3-Clause
+ Score : 100.00
+ Match type : TEXT
+ Links : http://www.opensource.org/licenses/BSD-3-Clause, https://spdx.org/licenses/BSD-3-Clause
+ Files with this license:
+ google/protobuf/__init__.py [5:29]
+ google/protobuf/descriptor.py [5:29]
+ google/protobuf/descriptor_database.py [5:29]
+ google/protobuf/descriptor_pool.py [5:29]
+ google/protobuf/internal/__init__.py [5:29]
+ google/protobuf/internal/_parameterized.py [7:31]
+ google/protobuf/internal/api_implementation.py [5:29]
+ google/protobuf/internal/containers.py [5:29]
+ google/protobuf/internal/decoder.py [5:29]
+ google/protobuf/internal/encoder.py [5:29]
+ google/protobuf/internal/enum_type_wrapper.py [5:29]
+ google/protobuf/internal/extension_dict.py [5:29]
+ google/protobuf/internal/message_listener.py [5:29]
+ google/protobuf/internal/python_message.py [5:29]
+ google/protobuf/internal/type_checkers.py [5:29]
+ google/protobuf/internal/well_known_types.py [5:29]
+ google/protobuf/internal/wire_format.py [5:29]
+ google/protobuf/json_format.py [5:29]
+ google/protobuf/message.py [5:29]
+ google/protobuf/message_factory.py [5:29]
+ google/protobuf/proto_builder.py [5:29]
+ google/protobuf/pyext/cpp_message.py [5:29]
+ google/protobuf/reflection.py [5:29]
+ google/protobuf/service.py [5:29]
+ google/protobuf/service_reflection.py [5:29]
+ google/protobuf/symbol_database.py [5:29]
+ google/protobuf/text_encoding.py [5:29]
+ google/protobuf/text_format.py [5:29]
diff --git a/contrib/python/protobuf/py2/.yandex_meta/licenses.list.txt b/contrib/python/protobuf/py2/.yandex_meta/licenses.list.txt
index 81364a2ff7..c8ea6f050b 100644
--- a/contrib/python/protobuf/py2/.yandex_meta/licenses.list.txt
+++ b/contrib/python/protobuf/py2/.yandex_meta/licenses.list.txt
@@ -1,62 +1,62 @@
-====================BSD-3-Clause====================
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-# * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-====================BSD-3-Clause====================
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-====================COPYRIGHT====================
-# Copyright 2007 Google Inc. All Rights Reserved.
-
-
-====================COPYRIGHT====================
-# Copyright 2008 Google Inc. All rights reserved.
+====================BSD-3-Clause====================
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+====================BSD-3-Clause====================
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+====================COPYRIGHT====================
+# Copyright 2007 Google Inc. All Rights Reserved.
+
+
+====================COPYRIGHT====================
+# Copyright 2008 Google Inc. All rights reserved.
diff --git a/contrib/python/protobuf/py2/google/__init__.py b/contrib/python/protobuf/py2/google/__init__.py
index 5585614122..79f9960a79 100644
--- a/contrib/python/protobuf/py2/google/__init__.py
+++ b/contrib/python/protobuf/py2/google/__init__.py
@@ -1,4 +1,4 @@
-try:
- __import__('pkg_resources').declare_namespace(__name__)
-except ImportError:
- __path__ = __import__('pkgutil').extend_path(__path__, __name__)
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ __path__ = __import__('pkgutil').extend_path(__path__, __name__)
diff --git a/contrib/python/protobuf/py2/google/protobuf/__init__.py b/contrib/python/protobuf/py2/google/protobuf/__init__.py
index 496df6adaf..fade4d257a 100644
--- a/contrib/python/protobuf/py2/google/protobuf/__init__.py
+++ b/contrib/python/protobuf/py2/google/protobuf/__init__.py
@@ -30,4 +30,4 @@
# Copyright 2007 Google Inc. All Rights Reserved.
-__version__ = '3.17.3'
+__version__ = '3.17.3'
diff --git a/contrib/python/protobuf/py2/google/protobuf/descriptor.py b/contrib/python/protobuf/py2/google/protobuf/descriptor.py
index 70fdae16ff..a3a40b740d 100644
--- a/contrib/python/protobuf/py2/google/protobuf/descriptor.py
+++ b/contrib/python/protobuf/py2/google/protobuf/descriptor.py
@@ -34,8 +34,8 @@ file, in types that make this information accessible in Python.
__author__ = 'robinson@google.com (Will Robinson)'
-import threading
-import warnings
+import threading
+import warnings
import six
from google.protobuf.internal import api_implementation
@@ -43,10 +43,10 @@ from google.protobuf.internal import api_implementation
_USE_C_DESCRIPTORS = False
if api_implementation.Type() == 'cpp':
# Used by MakeDescriptor in cpp mode
- import binascii
+ import binascii
import os
from google.protobuf.pyext import _message
- _USE_C_DESCRIPTORS = True
+ _USE_C_DESCRIPTORS = True
class Error(Exception):
@@ -74,43 +74,43 @@ else:
DescriptorMetaclass = type
-class _Lock(object):
- """Wrapper class of threading.Lock(), which is allowed by 'with'."""
-
- def __new__(cls):
- self = object.__new__(cls)
- self._lock = threading.Lock() # pylint: disable=protected-access
- return self
-
- def __enter__(self):
- self._lock.acquire()
-
- def __exit__(self, exc_type, exc_value, exc_tb):
- self._lock.release()
-
-
-_lock = threading.Lock()
-
-
-def _Deprecated(name):
- if _Deprecated.count > 0:
- _Deprecated.count -= 1
- warnings.warn(
- 'Call to deprecated create function %s(). Note: Create unlinked '
- 'descriptors is going to go away. Please use get/find descriptors from '
- 'generated code or query the descriptor_pool.'
- % name,
- category=DeprecationWarning, stacklevel=3)
-
-
-# Deprecated warnings will print 100 times at most which should be enough for
-# users to notice and do not cause timeout.
-_Deprecated.count = 100
-
-
-_internal_create_key = object()
-
-
+class _Lock(object):
+ """Wrapper class of threading.Lock(), which is allowed by 'with'."""
+
+ def __new__(cls):
+ self = object.__new__(cls)
+ self._lock = threading.Lock() # pylint: disable=protected-access
+ return self
+
+ def __enter__(self):
+ self._lock.acquire()
+
+ def __exit__(self, exc_type, exc_value, exc_tb):
+ self._lock.release()
+
+
+_lock = threading.Lock()
+
+
+def _Deprecated(name):
+ if _Deprecated.count > 0:
+ _Deprecated.count -= 1
+ warnings.warn(
+ 'Call to deprecated create function %s(). Note: Create unlinked '
+ 'descriptors is going to go away. Please use get/find descriptors from '
+ 'generated code or query the descriptor_pool.'
+ % name,
+ category=DeprecationWarning, stacklevel=3)
+
+
+# Deprecated warnings will print 100 times at most which should be enough for
+# users to notice and do not cause timeout.
+_Deprecated.count = 100
+
+
+_internal_create_key = object()
+
+
class DescriptorBase(six.with_metaclass(DescriptorMetaclass)):
"""Descriptors base class.
@@ -131,17 +131,17 @@ class DescriptorBase(six.with_metaclass(DescriptorMetaclass)):
# subclasses" of this descriptor class.
_C_DESCRIPTOR_CLASS = ()
- def __init__(self, options, serialized_options, options_class_name):
+ def __init__(self, options, serialized_options, options_class_name):
"""Initialize the descriptor given its options message and the name of the
class of the options message. The name of the class is required in case
the options message is None and has to be created.
"""
self._options = options
self._options_class_name = options_class_name
- self._serialized_options = serialized_options
+ self._serialized_options = serialized_options
# Does this descriptor have non-default options?
- self.has_options = (options is not None) or (serialized_options is not None)
+ self.has_options = (options is not None) or (serialized_options is not None)
def _SetOptions(self, options, options_class_name):
"""Sets the descriptor's options
@@ -163,52 +163,52 @@ class DescriptorBase(six.with_metaclass(DescriptorMetaclass)):
"""
if self._options:
return self._options
-
+
from google.protobuf import descriptor_pb2
try:
- options_class = getattr(descriptor_pb2,
- self._options_class_name)
+ options_class = getattr(descriptor_pb2,
+ self._options_class_name)
except AttributeError:
raise RuntimeError('Unknown options class name %s!' %
(self._options_class_name))
- with _lock:
- if self._serialized_options is None:
- self._options = options_class()
- else:
- self._options = _ParseOptions(options_class(),
- self._serialized_options)
-
- return self._options
-
+ with _lock:
+ if self._serialized_options is None:
+ self._options = options_class()
+ else:
+ self._options = _ParseOptions(options_class(),
+ self._serialized_options)
+ return self._options
+
+
class _NestedDescriptorBase(DescriptorBase):
"""Common class for descriptors that can be nested."""
def __init__(self, options, options_class_name, name, full_name,
file, containing_type, serialized_start=None,
- serialized_end=None, serialized_options=None):
+ serialized_end=None, serialized_options=None):
"""Constructor.
Args:
options: Protocol message options or None
to use default message options.
- options_class_name (str): The class name of the above options.
- name (str): Name of this protocol message type.
- full_name (str): Fully-qualified name of this protocol message type,
+ options_class_name (str): The class name of the above options.
+ name (str): Name of this protocol message type.
+ full_name (str): Fully-qualified name of this protocol message type,
which will include protocol "package" name and the name of any
enclosing types.
- file (FileDescriptor): Reference to file info.
+ file (FileDescriptor): Reference to file info.
containing_type: if provided, this is a nested descriptor, with this
descriptor as parent, otherwise None.
serialized_start: The start index (inclusive) in block in the
file.serialized_pb that describes this descriptor.
serialized_end: The end index (exclusive) in block in the
file.serialized_pb that describes this descriptor.
- serialized_options: Protocol message serialized options or None.
+ serialized_options: Protocol message serialized options or None.
"""
super(_NestedDescriptorBase, self).__init__(
- options, serialized_options, options_class_name)
+ options, serialized_options, options_class_name)
self.name = name
# TODO(falk): Add function to calculate full_name instead of having it in
@@ -227,8 +227,8 @@ class _NestedDescriptorBase(DescriptorBase):
proto: An empty proto instance from descriptor_pb2.
Raises:
- Error: If self couldn't be serialized, due to to few constructor
- arguments.
+ Error: If self couldn't be serialized, due to to few constructor
+ arguments.
"""
if (self.file is not None and
self._serialized_start is not None and
@@ -243,70 +243,70 @@ class Descriptor(_NestedDescriptorBase):
"""Descriptor for a protocol message type.
- Attributes:
- name (str): Name of this protocol message type.
- full_name (str): Fully-qualified name of this protocol message type,
- which will include protocol "package" name and the name of any
- enclosing types.
- containing_type (Descriptor): Reference to the descriptor of the type
- containing us, or None if this is top-level.
- fields (list[FieldDescriptor]): Field descriptors for all fields in
- this type.
- fields_by_number (dict(int, FieldDescriptor)): Same
- :class:`FieldDescriptor` objects as in :attr:`fields`, but indexed
- by "number" attribute in each FieldDescriptor.
- fields_by_name (dict(str, FieldDescriptor)): Same
- :class:`FieldDescriptor` objects as in :attr:`fields`, but indexed by
- "name" attribute in each :class:`FieldDescriptor`.
- nested_types (list[Descriptor]): Descriptor references
- for all protocol message types nested within this one.
- nested_types_by_name (dict(str, Descriptor)): Same Descriptor
- objects as in :attr:`nested_types`, but indexed by "name" attribute
- in each Descriptor.
- enum_types (list[EnumDescriptor]): :class:`EnumDescriptor` references
- for all enums contained within this type.
- enum_types_by_name (dict(str, EnumDescriptor)): Same
- :class:`EnumDescriptor` objects as in :attr:`enum_types`, but
- indexed by "name" attribute in each EnumDescriptor.
- enum_values_by_name (dict(str, EnumValueDescriptor)): Dict mapping
- from enum value name to :class:`EnumValueDescriptor` for that value.
- extensions (list[FieldDescriptor]): All extensions defined directly
- within this message type (NOT within a nested type).
- extensions_by_name (dict(str, FieldDescriptor)): Same FieldDescriptor
- objects as :attr:`extensions`, but indexed by "name" attribute of each
- FieldDescriptor.
- is_extendable (bool): Does this type define any extension ranges?
- oneofs (list[OneofDescriptor]): The list of descriptors for oneof fields
- in this message.
- oneofs_by_name (dict(str, OneofDescriptor)): Same objects as in
- :attr:`oneofs`, but indexed by "name" attribute.
- file (FileDescriptor): Reference to file descriptor.
+ Attributes:
+ name (str): Name of this protocol message type.
+ full_name (str): Fully-qualified name of this protocol message type,
+ which will include protocol "package" name and the name of any
+ enclosing types.
+ containing_type (Descriptor): Reference to the descriptor of the type
+ containing us, or None if this is top-level.
+ fields (list[FieldDescriptor]): Field descriptors for all fields in
+ this type.
+ fields_by_number (dict(int, FieldDescriptor)): Same
+ :class:`FieldDescriptor` objects as in :attr:`fields`, but indexed
+ by "number" attribute in each FieldDescriptor.
+ fields_by_name (dict(str, FieldDescriptor)): Same
+ :class:`FieldDescriptor` objects as in :attr:`fields`, but indexed by
+ "name" attribute in each :class:`FieldDescriptor`.
+ nested_types (list[Descriptor]): Descriptor references
+ for all protocol message types nested within this one.
+ nested_types_by_name (dict(str, Descriptor)): Same Descriptor
+ objects as in :attr:`nested_types`, but indexed by "name" attribute
+ in each Descriptor.
+ enum_types (list[EnumDescriptor]): :class:`EnumDescriptor` references
+ for all enums contained within this type.
+ enum_types_by_name (dict(str, EnumDescriptor)): Same
+ :class:`EnumDescriptor` objects as in :attr:`enum_types`, but
+ indexed by "name" attribute in each EnumDescriptor.
+ enum_values_by_name (dict(str, EnumValueDescriptor)): Dict mapping
+ from enum value name to :class:`EnumValueDescriptor` for that value.
+ extensions (list[FieldDescriptor]): All extensions defined directly
+ within this message type (NOT within a nested type).
+ extensions_by_name (dict(str, FieldDescriptor)): Same FieldDescriptor
+ objects as :attr:`extensions`, but indexed by "name" attribute of each
+ FieldDescriptor.
+ is_extendable (bool): Does this type define any extension ranges?
+ oneofs (list[OneofDescriptor]): The list of descriptors for oneof fields
+ in this message.
+ oneofs_by_name (dict(str, OneofDescriptor)): Same objects as in
+ :attr:`oneofs`, but indexed by "name" attribute.
+ file (FileDescriptor): Reference to file descriptor.
"""
if _USE_C_DESCRIPTORS:
_C_DESCRIPTOR_CLASS = _message.Descriptor
- def __new__(
- cls,
- name=None,
- full_name=None,
- filename=None,
- containing_type=None,
- fields=None,
- nested_types=None,
- enum_types=None,
- extensions=None,
- options=None,
- serialized_options=None,
- is_extendable=True,
- extension_ranges=None,
- oneofs=None,
- file=None, # pylint: disable=redefined-builtin
- serialized_start=None,
- serialized_end=None,
- syntax=None,
- create_key=None):
+ def __new__(
+ cls,
+ name=None,
+ full_name=None,
+ filename=None,
+ containing_type=None,
+ fields=None,
+ nested_types=None,
+ enum_types=None,
+ extensions=None,
+ options=None,
+ serialized_options=None,
+ is_extendable=True,
+ extension_ranges=None,
+ oneofs=None,
+ file=None, # pylint: disable=redefined-builtin
+ serialized_start=None,
+ serialized_end=None,
+ syntax=None,
+ create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindMessageTypeByName(full_name)
@@ -315,23 +315,23 @@ class Descriptor(_NestedDescriptorBase):
# name of the argument.
def __init__(self, name, full_name, filename, containing_type, fields,
nested_types, enum_types, extensions, options=None,
- serialized_options=None,
+ serialized_options=None,
is_extendable=True, extension_ranges=None, oneofs=None,
file=None, serialized_start=None, serialized_end=None, # pylint: disable=redefined-builtin
- syntax=None, create_key=None):
+ syntax=None, create_key=None):
"""Arguments to __init__() are as described in the description
of Descriptor fields above.
Note that filename is an obsolete argument, that is not used anymore.
Please use file.name to access this as an attribute.
"""
- if create_key is not _internal_create_key:
- _Deprecated('Descriptor')
-
+ if create_key is not _internal_create_key:
+ _Deprecated('Descriptor')
+
super(Descriptor, self).__init__(
options, 'MessageOptions', name, full_name, file,
containing_type, serialized_start=serialized_start,
- serialized_end=serialized_end, serialized_options=serialized_options)
+ serialized_end=serialized_end, serialized_options=serialized_options)
# We have fields in addition to fields_by_name and fields_by_number,
# so that:
@@ -371,9 +371,9 @@ class Descriptor(_NestedDescriptorBase):
@property
def fields_by_camelcase_name(self):
- """Same FieldDescriptor objects as in :attr:`fields`, but indexed by
- :attr:`FieldDescriptor.camelcase_name`.
- """
+ """Same FieldDescriptor objects as in :attr:`fields`, but indexed by
+ :attr:`FieldDescriptor.camelcase_name`.
+ """
if self._fields_by_camelcase_name is None:
self._fields_by_camelcase_name = dict(
(f.camelcase_name, f) for f in self.fields)
@@ -422,51 +422,51 @@ class FieldDescriptor(DescriptorBase):
"""Descriptor for a single field in a .proto file.
- Attributes:
- name (str): Name of this field, exactly as it appears in .proto.
- full_name (str): Name of this field, including containing scope. This is
+ Attributes:
+ name (str): Name of this field, exactly as it appears in .proto.
+ full_name (str): Name of this field, including containing scope. This is
particularly relevant for extensions.
- index (int): Dense, 0-indexed index giving the order that this
+ index (int): Dense, 0-indexed index giving the order that this
field textually appears within its message in the .proto file.
- number (int): Tag number declared for this field in the .proto file.
+ number (int): Tag number declared for this field in the .proto file.
- type (int): (One of the TYPE_* constants below) Declared type.
- cpp_type (int): (One of the CPPTYPE_* constants below) C++ type used to
+ type (int): (One of the TYPE_* constants below) Declared type.
+ cpp_type (int): (One of the CPPTYPE_* constants below) C++ type used to
represent this field.
- label (int): (One of the LABEL_* constants below) Tells whether this
+ label (int): (One of the LABEL_* constants below) Tells whether this
field is optional, required, or repeated.
- has_default_value (bool): True if this field has a default value defined,
+ has_default_value (bool): True if this field has a default value defined,
otherwise false.
- default_value (Varies): Default value of this field. Only
+ default_value (Varies): Default value of this field. Only
meaningful for non-repeated scalar fields. Repeated fields
should always set this to [], and non-repeated composite
fields should always set this to None.
- containing_type (Descriptor): Descriptor of the protocol message
+ containing_type (Descriptor): Descriptor of the protocol message
type that contains this field. Set by the Descriptor constructor
if we're passed into one.
Somewhat confusingly, for extension fields, this is the
descriptor of the EXTENDED message, not the descriptor
of the message containing this field. (See is_extension and
extension_scope below).
- message_type (Descriptor): If a composite field, a descriptor
+ message_type (Descriptor): If a composite field, a descriptor
of the message type contained in this field. Otherwise, this is None.
- enum_type (EnumDescriptor): If this field contains an enum, a
+ enum_type (EnumDescriptor): If this field contains an enum, a
descriptor of that enum. Otherwise, this is None.
is_extension: True iff this describes an extension field.
- extension_scope (Descriptor): Only meaningful if is_extension is True.
+ extension_scope (Descriptor): Only meaningful if is_extension is True.
Gives the message that immediately contains this extension field.
Will be None iff we're a top-level (file-level) extension field.
- options (descriptor_pb2.FieldOptions): Protocol message field options or
+ options (descriptor_pb2.FieldOptions): Protocol message field options or
None to use default field options.
- containing_oneof (OneofDescriptor): If the field is a member of a oneof
+ containing_oneof (OneofDescriptor): If the field is a member of a oneof
union, contains its descriptor. Otherwise, None.
- file (FileDescriptor): Reference to file descriptor.
+ file (FileDescriptor): Reference to file descriptor.
"""
# Must be consistent with C++ FieldDescriptor::Type enum in
@@ -551,9 +551,9 @@ class FieldDescriptor(DescriptorBase):
def __new__(cls, name, full_name, index, number, type, cpp_type, label,
default_value, message_type, enum_type, containing_type,
is_extension, extension_scope, options=None,
- serialized_options=None,
+ serialized_options=None,
has_default_value=True, containing_oneof=None, json_name=None,
- file=None, create_key=None): # pylint: disable=redefined-builtin
+ file=None, create_key=None): # pylint: disable=redefined-builtin
_message.Message._CheckCalledFromGeneratedFile()
if is_extension:
return _message.default_pool.FindExtensionByName(full_name)
@@ -563,9 +563,9 @@ class FieldDescriptor(DescriptorBase):
def __init__(self, name, full_name, index, number, type, cpp_type, label,
default_value, message_type, enum_type, containing_type,
is_extension, extension_scope, options=None,
- serialized_options=None,
+ serialized_options=None,
has_default_value=True, containing_oneof=None, json_name=None,
- file=None, create_key=None): # pylint: disable=redefined-builtin
+ file=None, create_key=None): # pylint: disable=redefined-builtin
"""The arguments are as described in the description of FieldDescriptor
attributes above.
@@ -573,11 +573,11 @@ class FieldDescriptor(DescriptorBase):
(to deal with circular references between message types, for example).
Likewise for extension_scope.
"""
- if create_key is not _internal_create_key:
- _Deprecated('FieldDescriptor')
-
- super(FieldDescriptor, self).__init__(
- options, serialized_options, 'FieldOptions')
+ if create_key is not _internal_create_key:
+ _Deprecated('FieldDescriptor')
+
+ super(FieldDescriptor, self).__init__(
+ options, serialized_options, 'FieldOptions')
self.name = name
self.full_name = full_name
self.file = file
@@ -609,11 +609,11 @@ class FieldDescriptor(DescriptorBase):
@property
def camelcase_name(self):
- """Camelcase name of this field.
-
- Returns:
- str: the name in CamelCase.
- """
+ """Camelcase name of this field.
+
+ Returns:
+ str: the name in CamelCase.
+ """
if self._camelcase_name is None:
self._camelcase_name = _ToCamelCase(self.name)
return self._camelcase_name
@@ -629,7 +629,7 @@ class FieldDescriptor(DescriptorBase):
Args:
proto_type: the Python proto type (descriptor.FieldDescriptor.TYPE_*)
Returns:
- int: descriptor.FieldDescriptor.CPPTYPE_*, the C++ type.
+ int: descriptor.FieldDescriptor.CPPTYPE_*, the C++ type.
Raises:
TypeTransformationError: when the Python proto type isn't known.
"""
@@ -643,23 +643,23 @@ class EnumDescriptor(_NestedDescriptorBase):
"""Descriptor for an enum defined in a .proto file.
- Attributes:
- name (str): Name of the enum type.
- full_name (str): Full name of the type, including package name
+ Attributes:
+ name (str): Name of the enum type.
+ full_name (str): Full name of the type, including package name
and any enclosing type(s).
- values (list[EnumValueDescriptors]): List of the values
+ values (list[EnumValueDescriptors]): List of the values
in this enum.
- values_by_name (dict(str, EnumValueDescriptor)): Same as :attr:`values`,
+ values_by_name (dict(str, EnumValueDescriptor)): Same as :attr:`values`,
but indexed by the "name" field of each EnumValueDescriptor.
- values_by_number (dict(int, EnumValueDescriptor)): Same as :attr:`values`,
+ values_by_number (dict(int, EnumValueDescriptor)): Same as :attr:`values`,
but indexed by the "number" field of each EnumValueDescriptor.
- containing_type (Descriptor): Descriptor of the immediate containing
+ containing_type (Descriptor): Descriptor of the immediate containing
type of this enum, or None if this is an enum defined at the
top level in a .proto file. Set by Descriptor's constructor
if we're passed into one.
- file (FileDescriptor): Reference to file descriptor.
- options (descriptor_pb2.EnumOptions): Enum options message or
+ file (FileDescriptor): Reference to file descriptor.
+ options (descriptor_pb2.EnumOptions): Enum options message or
None to use default enum options.
"""
@@ -667,41 +667,41 @@ class EnumDescriptor(_NestedDescriptorBase):
_C_DESCRIPTOR_CLASS = _message.EnumDescriptor
def __new__(cls, name, full_name, filename, values,
- containing_type=None, options=None,
- serialized_options=None, file=None, # pylint: disable=redefined-builtin
- serialized_start=None, serialized_end=None, create_key=None):
+ containing_type=None, options=None,
+ serialized_options=None, file=None, # pylint: disable=redefined-builtin
+ serialized_start=None, serialized_end=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindEnumTypeByName(full_name)
def __init__(self, name, full_name, filename, values,
- containing_type=None, options=None,
- serialized_options=None, file=None, # pylint: disable=redefined-builtin
- serialized_start=None, serialized_end=None, create_key=None):
+ containing_type=None, options=None,
+ serialized_options=None, file=None, # pylint: disable=redefined-builtin
+ serialized_start=None, serialized_end=None, create_key=None):
"""Arguments are as described in the attribute description above.
Note that filename is an obsolete argument, that is not used anymore.
Please use file.name to access this as an attribute.
"""
- if create_key is not _internal_create_key:
- _Deprecated('EnumDescriptor')
-
+ if create_key is not _internal_create_key:
+ _Deprecated('EnumDescriptor')
+
super(EnumDescriptor, self).__init__(
options, 'EnumOptions', name, full_name, file,
containing_type, serialized_start=serialized_start,
- serialized_end=serialized_end, serialized_options=serialized_options)
+ serialized_end=serialized_end, serialized_options=serialized_options)
self.values = values
for value in self.values:
value.type = self
self.values_by_name = dict((v.name, v) for v in values)
- # Values are reversed to ensure that the first alias is retained.
- self.values_by_number = dict((v.number, v) for v in reversed(values))
+ # Values are reversed to ensure that the first alias is retained.
+ self.values_by_number = dict((v.number, v) for v in reversed(values))
def CopyToProto(self, proto):
"""Copies this to a descriptor_pb2.EnumDescriptorProto.
Args:
- proto (descriptor_pb2.EnumDescriptorProto): An empty descriptor proto.
+ proto (descriptor_pb2.EnumDescriptorProto): An empty descriptor proto.
"""
# This function is overridden to give a better doc comment.
super(EnumDescriptor, self).CopyToProto(proto)
@@ -711,24 +711,24 @@ class EnumValueDescriptor(DescriptorBase):
"""Descriptor for a single value within an enum.
- Attributes:
- name (str): Name of this value.
- index (int): Dense, 0-indexed index giving the order that this
+ Attributes:
+ name (str): Name of this value.
+ index (int): Dense, 0-indexed index giving the order that this
value appears textually within its enum in the .proto file.
- number (int): Actual number assigned to this enum value.
- type (EnumDescriptor): :class:`EnumDescriptor` to which this value
- belongs. Set by :class:`EnumDescriptor`'s constructor if we're
+ number (int): Actual number assigned to this enum value.
+ type (EnumDescriptor): :class:`EnumDescriptor` to which this value
+ belongs. Set by :class:`EnumDescriptor`'s constructor if we're
passed into one.
- options (descriptor_pb2.EnumValueOptions): Enum value options message or
+ options (descriptor_pb2.EnumValueOptions): Enum value options message or
None to use default enum value options options.
"""
if _USE_C_DESCRIPTORS:
_C_DESCRIPTOR_CLASS = _message.EnumValueDescriptor
- def __new__(cls, name, index, number,
- type=None, # pylint: disable=redefined-builtin
- options=None, serialized_options=None, create_key=None):
+ def __new__(cls, name, index, number,
+ type=None, # pylint: disable=redefined-builtin
+ options=None, serialized_options=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
# There is no way we can build a complete EnumValueDescriptor with the
# given parameters (the name of the Enum is not known, for example).
@@ -736,15 +736,15 @@ class EnumValueDescriptor(DescriptorBase):
# constructor, which will ignore it, so returning None is good enough.
return None
- def __init__(self, name, index, number,
- type=None, # pylint: disable=redefined-builtin
- options=None, serialized_options=None, create_key=None):
+ def __init__(self, name, index, number,
+ type=None, # pylint: disable=redefined-builtin
+ options=None, serialized_options=None, create_key=None):
"""Arguments are as described in the attribute description above."""
- if create_key is not _internal_create_key:
- _Deprecated('EnumValueDescriptor')
-
- super(EnumValueDescriptor, self).__init__(
- options, serialized_options, 'EnumValueOptions')
+ if create_key is not _internal_create_key:
+ _Deprecated('EnumValueDescriptor')
+
+ super(EnumValueDescriptor, self).__init__(
+ options, serialized_options, 'EnumValueOptions')
self.name = name
self.index = index
self.number = number
@@ -754,15 +754,15 @@ class EnumValueDescriptor(DescriptorBase):
class OneofDescriptor(DescriptorBase):
"""Descriptor for a oneof field.
- Attributes:
- name (str): Name of the oneof field.
- full_name (str): Full name of the oneof field, including package name.
- index (int): 0-based index giving the order of the oneof field inside
+ Attributes:
+ name (str): Name of the oneof field.
+ full_name (str): Full name of the oneof field, including package name.
+ index (int): 0-based index giving the order of the oneof field inside
its containing type.
- containing_type (Descriptor): :class:`Descriptor` of the protocol message
- type that contains this field. Set by the :class:`Descriptor` constructor
+ containing_type (Descriptor): :class:`Descriptor` of the protocol message
+ type that contains this field. Set by the :class:`Descriptor` constructor
if we're passed into one.
- fields (list[FieldDescriptor]): The list of field descriptors this
+ fields (list[FieldDescriptor]): The list of field descriptors this
oneof can contain.
"""
@@ -770,20 +770,20 @@ class OneofDescriptor(DescriptorBase):
_C_DESCRIPTOR_CLASS = _message.OneofDescriptor
def __new__(
- cls, name, full_name, index, containing_type, fields, options=None,
- serialized_options=None, create_key=None):
+ cls, name, full_name, index, containing_type, fields, options=None,
+ serialized_options=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindOneofByName(full_name)
def __init__(
- self, name, full_name, index, containing_type, fields, options=None,
- serialized_options=None, create_key=None):
+ self, name, full_name, index, containing_type, fields, options=None,
+ serialized_options=None, create_key=None):
"""Arguments are as described in the attribute description above."""
- if create_key is not _internal_create_key:
- _Deprecated('OneofDescriptor')
-
- super(OneofDescriptor, self).__init__(
- options, serialized_options, 'OneofOptions')
+ if create_key is not _internal_create_key:
+ _Deprecated('OneofDescriptor')
+
+ super(OneofDescriptor, self).__init__(
+ options, serialized_options, 'OneofOptions')
self.name = name
self.full_name = full_name
self.index = index
@@ -795,49 +795,49 @@ class ServiceDescriptor(_NestedDescriptorBase):
"""Descriptor for a service.
- Attributes:
- name (str): Name of the service.
- full_name (str): Full name of the service, including package name.
- index (int): 0-indexed index giving the order that this services
- definition appears within the .proto file.
- methods (list[MethodDescriptor]): List of methods provided by this
+ Attributes:
+ name (str): Name of the service.
+ full_name (str): Full name of the service, including package name.
+ index (int): 0-indexed index giving the order that this services
+ definition appears within the .proto file.
+ methods (list[MethodDescriptor]): List of methods provided by this
service.
- methods_by_name (dict(str, MethodDescriptor)): Same
- :class:`MethodDescriptor` objects as in :attr:`methods_by_name`, but
- indexed by "name" attribute in each :class:`MethodDescriptor`.
- options (descriptor_pb2.ServiceOptions): Service options message or
+ methods_by_name (dict(str, MethodDescriptor)): Same
+ :class:`MethodDescriptor` objects as in :attr:`methods_by_name`, but
+ indexed by "name" attribute in each :class:`MethodDescriptor`.
+ options (descriptor_pb2.ServiceOptions): Service options message or
None to use default service options.
- file (FileDescriptor): Reference to file info.
+ file (FileDescriptor): Reference to file info.
"""
if _USE_C_DESCRIPTORS:
_C_DESCRIPTOR_CLASS = _message.ServiceDescriptor
- def __new__(
- cls,
- name=None,
- full_name=None,
- index=None,
- methods=None,
- options=None,
- serialized_options=None,
- file=None, # pylint: disable=redefined-builtin
- serialized_start=None,
- serialized_end=None,
- create_key=None):
+ def __new__(
+ cls,
+ name=None,
+ full_name=None,
+ index=None,
+ methods=None,
+ options=None,
+ serialized_options=None,
+ file=None, # pylint: disable=redefined-builtin
+ serialized_start=None,
+ serialized_end=None,
+ create_key=None):
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
return _message.default_pool.FindServiceByName(full_name)
- def __init__(self, name, full_name, index, methods, options=None,
- serialized_options=None, file=None, # pylint: disable=redefined-builtin
- serialized_start=None, serialized_end=None, create_key=None):
- if create_key is not _internal_create_key:
- _Deprecated('ServiceDescriptor')
-
+ def __init__(self, name, full_name, index, methods, options=None,
+ serialized_options=None, file=None, # pylint: disable=redefined-builtin
+ serialized_start=None, serialized_end=None, create_key=None):
+ if create_key is not _internal_create_key:
+ _Deprecated('ServiceDescriptor')
+
super(ServiceDescriptor, self).__init__(
options, 'ServiceOptions', name, full_name, file,
None, serialized_start=serialized_start,
- serialized_end=serialized_end, serialized_options=serialized_options)
+ serialized_end=serialized_end, serialized_options=serialized_options)
self.index = index
self.methods = methods
self.methods_by_name = dict((m.name, m) for m in methods)
@@ -846,21 +846,21 @@ class ServiceDescriptor(_NestedDescriptorBase):
method.containing_service = self
def FindMethodByName(self, name):
- """Searches for the specified method, and returns its descriptor.
-
- Args:
- name (str): Name of the method.
- Returns:
- MethodDescriptor or None: the descriptor for the requested method, if
- found.
- """
+ """Searches for the specified method, and returns its descriptor.
+
+ Args:
+ name (str): Name of the method.
+ Returns:
+ MethodDescriptor or None: the descriptor for the requested method, if
+ found.
+ """
return self.methods_by_name.get(name, None)
def CopyToProto(self, proto):
"""Copies this to a descriptor_pb2.ServiceDescriptorProto.
Args:
- proto (descriptor_pb2.ServiceDescriptorProto): An empty descriptor proto.
+ proto (descriptor_pb2.ServiceDescriptorProto): An empty descriptor proto.
"""
# This function is overridden to give a better doc comment.
super(ServiceDescriptor, self).CopyToProto(proto)
@@ -870,42 +870,42 @@ class MethodDescriptor(DescriptorBase):
"""Descriptor for a method in a service.
- Attributes:
- name (str): Name of the method within the service.
- full_name (str): Full name of method.
- index (int): 0-indexed index of the method inside the service.
- containing_service (ServiceDescriptor): The service that contains this
- method.
- input_type (Descriptor): The descriptor of the message that this method
- accepts.
- output_type (Descriptor): The descriptor of the message that this method
- returns.
- options (descriptor_pb2.MethodOptions or None): Method options message, or
- None to use default method options.
+ Attributes:
+ name (str): Name of the method within the service.
+ full_name (str): Full name of method.
+ index (int): 0-indexed index of the method inside the service.
+ containing_service (ServiceDescriptor): The service that contains this
+ method.
+ input_type (Descriptor): The descriptor of the message that this method
+ accepts.
+ output_type (Descriptor): The descriptor of the message that this method
+ returns.
+ options (descriptor_pb2.MethodOptions or None): Method options message, or
+ None to use default method options.
"""
if _USE_C_DESCRIPTORS:
_C_DESCRIPTOR_CLASS = _message.MethodDescriptor
def __new__(cls, name, full_name, index, containing_service,
- input_type, output_type, options=None, serialized_options=None,
- create_key=None):
+ input_type, output_type, options=None, serialized_options=None,
+ create_key=None):
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
return _message.default_pool.FindMethodByName(full_name)
def __init__(self, name, full_name, index, containing_service,
- input_type, output_type, options=None, serialized_options=None,
- create_key=None):
+ input_type, output_type, options=None, serialized_options=None,
+ create_key=None):
"""The arguments are as described in the description of MethodDescriptor
attributes above.
Note that containing_service may be None, and may be set later if necessary.
"""
- if create_key is not _internal_create_key:
- _Deprecated('MethodDescriptor')
-
- super(MethodDescriptor, self).__init__(
- options, serialized_options, 'MethodOptions')
+ if create_key is not _internal_create_key:
+ _Deprecated('MethodDescriptor')
+
+ super(MethodDescriptor, self).__init__(
+ options, serialized_options, 'MethodOptions')
self.name = name
self.full_name = full_name
self.index = index
@@ -913,88 +913,88 @@ class MethodDescriptor(DescriptorBase):
self.input_type = input_type
self.output_type = output_type
- def CopyToProto(self, proto):
- """Copies this to a descriptor_pb2.MethodDescriptorProto.
-
- Args:
- proto (descriptor_pb2.MethodDescriptorProto): An empty descriptor proto.
-
- Raises:
- Error: If self couldn't be serialized, due to too few constructor
- arguments.
- """
- if self.containing_service is not None:
- from google.protobuf import descriptor_pb2
- service_proto = descriptor_pb2.ServiceDescriptorProto()
- self.containing_service.CopyToProto(service_proto)
- proto.CopyFrom(service_proto.method[self.index])
- else:
- raise Error('Descriptor does not contain a service.')
-
-
+ def CopyToProto(self, proto):
+ """Copies this to a descriptor_pb2.MethodDescriptorProto.
+
+ Args:
+ proto (descriptor_pb2.MethodDescriptorProto): An empty descriptor proto.
+
+ Raises:
+ Error: If self couldn't be serialized, due to too few constructor
+ arguments.
+ """
+ if self.containing_service is not None:
+ from google.protobuf import descriptor_pb2
+ service_proto = descriptor_pb2.ServiceDescriptorProto()
+ self.containing_service.CopyToProto(service_proto)
+ proto.CopyFrom(service_proto.method[self.index])
+ else:
+ raise Error('Descriptor does not contain a service.')
+
+
class FileDescriptor(DescriptorBase):
"""Descriptor for a file. Mimics the descriptor_pb2.FileDescriptorProto.
- Note that :attr:`enum_types_by_name`, :attr:`extensions_by_name`, and
- :attr:`dependencies` fields are only set by the
- :py:mod:`google.protobuf.message_factory` module, and not by the generated
- proto code.
-
- Attributes:
- name (str): Name of file, relative to root of source tree.
- package (str): Name of the package
- syntax (str): string indicating syntax of the file (can be "proto2" or
- "proto3")
- serialized_pb (bytes): Byte string of serialized
- :class:`descriptor_pb2.FileDescriptorProto`.
- dependencies (list[FileDescriptor]): List of other :class:`FileDescriptor`
- objects this :class:`FileDescriptor` depends on.
- public_dependencies (list[FileDescriptor]): A subset of
- :attr:`dependencies`, which were declared as "public".
- message_types_by_name (dict(str, Descriptor)): Mapping from message names
- to their :class:`Desctiptor`.
- enum_types_by_name (dict(str, EnumDescriptor)): Mapping from enum names to
- their :class:`EnumDescriptor`.
- extensions_by_name (dict(str, FieldDescriptor)): Mapping from extension
- names declared at file scope to their :class:`FieldDescriptor`.
- services_by_name (dict(str, ServiceDescriptor)): Mapping from services'
- names to their :class:`ServiceDescriptor`.
- pool (DescriptorPool): The pool this descriptor belongs to. When not
- passed to the constructor, the global default pool is used.
+ Note that :attr:`enum_types_by_name`, :attr:`extensions_by_name`, and
+ :attr:`dependencies` fields are only set by the
+ :py:mod:`google.protobuf.message_factory` module, and not by the generated
+ proto code.
+
+ Attributes:
+ name (str): Name of file, relative to root of source tree.
+ package (str): Name of the package
+ syntax (str): string indicating syntax of the file (can be "proto2" or
+ "proto3")
+ serialized_pb (bytes): Byte string of serialized
+ :class:`descriptor_pb2.FileDescriptorProto`.
+ dependencies (list[FileDescriptor]): List of other :class:`FileDescriptor`
+ objects this :class:`FileDescriptor` depends on.
+ public_dependencies (list[FileDescriptor]): A subset of
+ :attr:`dependencies`, which were declared as "public".
+ message_types_by_name (dict(str, Descriptor)): Mapping from message names
+ to their :class:`Desctiptor`.
+ enum_types_by_name (dict(str, EnumDescriptor)): Mapping from enum names to
+ their :class:`EnumDescriptor`.
+ extensions_by_name (dict(str, FieldDescriptor)): Mapping from extension
+ names declared at file scope to their :class:`FieldDescriptor`.
+ services_by_name (dict(str, ServiceDescriptor)): Mapping from services'
+ names to their :class:`ServiceDescriptor`.
+ pool (DescriptorPool): The pool this descriptor belongs to. When not
+ passed to the constructor, the global default pool is used.
"""
if _USE_C_DESCRIPTORS:
_C_DESCRIPTOR_CLASS = _message.FileDescriptor
- def __new__(cls, name, package, options=None,
- serialized_options=None, serialized_pb=None,
+ def __new__(cls, name, package, options=None,
+ serialized_options=None, serialized_pb=None,
dependencies=None, public_dependencies=None,
- syntax=None, pool=None, create_key=None):
+ syntax=None, pool=None, create_key=None):
# FileDescriptor() is called from various places, not only from generated
# files, to register dynamic proto files and messages.
- # pylint: disable=g-explicit-bool-comparison
- if serialized_pb == b'':
- # Cpp generated code must be linked in if serialized_pb is ''
- try:
- return _message.default_pool.FindFileByName(name)
- except KeyError:
- raise RuntimeError('Please link in cpp generated lib for %s' % (name))
- elif serialized_pb:
+ # pylint: disable=g-explicit-bool-comparison
+ if serialized_pb == b'':
+ # Cpp generated code must be linked in if serialized_pb is ''
+ try:
+ return _message.default_pool.FindFileByName(name)
+ except KeyError:
+ raise RuntimeError('Please link in cpp generated lib for %s' % (name))
+ elif serialized_pb:
return _message.default_pool.AddSerializedFile(serialized_pb)
else:
return super(FileDescriptor, cls).__new__(cls)
- def __init__(self, name, package, options=None,
- serialized_options=None, serialized_pb=None,
+ def __init__(self, name, package, options=None,
+ serialized_options=None, serialized_pb=None,
dependencies=None, public_dependencies=None,
- syntax=None, pool=None, create_key=None):
+ syntax=None, pool=None, create_key=None):
"""Constructor."""
- if create_key is not _internal_create_key:
- _Deprecated('FileDescriptor')
-
- super(FileDescriptor, self).__init__(
- options, serialized_options, 'FileOptions')
+ if create_key is not _internal_create_key:
+ _Deprecated('FileDescriptor')
+ super(FileDescriptor, self).__init__(
+ options, serialized_options, 'FileOptions')
+
if pool is None:
from google.protobuf import descriptor_pool
pool = descriptor_pool.Default()
@@ -1107,7 +1107,7 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
# imported ones. We need to specify a file name so the descriptor pool
# accepts our FileDescriptorProto, but it is not important what that file
# name is actually set to.
- proto_name = binascii.hexlify(os.urandom(16)).decode('ascii')
+ proto_name = binascii.hexlify(os.urandom(16)).decode('ascii')
if package:
file_descriptor_proto.name = os.path.join(package.replace('.', '/'),
@@ -1130,11 +1130,11 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
for enum_proto in desc_proto.enum_type:
full_name = '.'.join(full_message_name + [enum_proto.name])
enum_desc = EnumDescriptor(
- enum_proto.name, full_name, None, [
- EnumValueDescriptor(enum_val.name, ii, enum_val.number,
- create_key=_internal_create_key)
- for ii, enum_val in enumerate(enum_proto.value)],
- create_key=_internal_create_key)
+ enum_proto.name, full_name, None, [
+ EnumValueDescriptor(enum_val.name, ii, enum_val.number,
+ create_key=_internal_create_key)
+ for ii, enum_val in enumerate(enum_proto.value)],
+ create_key=_internal_create_key)
enum_types[full_name] = enum_desc
# Create Descriptors for nested types
@@ -1173,11 +1173,11 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type),
field_proto.label, None, nested_desc, enum_desc, None, False, None,
options=_OptionsOrNone(field_proto), has_default_value=False,
- json_name=json_name, create_key=_internal_create_key)
+ json_name=json_name, create_key=_internal_create_key)
fields.append(field)
desc_name = '.'.join(full_message_name)
return Descriptor(desc_proto.name, desc_name, None, None, fields,
list(nested_types.values()), list(enum_types.values()), [],
- options=_OptionsOrNone(desc_proto),
- create_key=_internal_create_key)
+ options=_OptionsOrNone(desc_proto),
+ create_key=_internal_create_key)
diff --git a/contrib/python/protobuf/py2/google/protobuf/descriptor_database.py b/contrib/python/protobuf/py2/google/protobuf/descriptor_database.py
index 073eddc711..bd3fee2f05 100644
--- a/contrib/python/protobuf/py2/google/protobuf/descriptor_database.py
+++ b/contrib/python/protobuf/py2/google/protobuf/descriptor_database.py
@@ -32,9 +32,9 @@
__author__ = 'matthewtoia@google.com (Matt Toia)'
-import warnings
-
+import warnings
+
class Error(Exception):
pass
@@ -58,7 +58,7 @@ class DescriptorDatabase(object):
Raises:
DescriptorDatabaseConflictingDefinitionError: if an attempt is made to
add a proto with the same name but different definition than an
- existing proto in the database.
+ existing proto in the database.
"""
proto_name = file_desc_proto.name
if proto_name not in self._file_desc_protos_by_file:
@@ -66,23 +66,23 @@ class DescriptorDatabase(object):
elif self._file_desc_protos_by_file[proto_name] != file_desc_proto:
raise DescriptorDatabaseConflictingDefinitionError(
'%s already added, but with different descriptor.' % proto_name)
- else:
- return
+ else:
+ return
# Add all the top-level descriptors to the index.
package = file_desc_proto.package
for message in file_desc_proto.message_type:
- for name in _ExtractSymbols(message, package):
- self._AddSymbol(name, file_desc_proto)
+ for name in _ExtractSymbols(message, package):
+ self._AddSymbol(name, file_desc_proto)
for enum in file_desc_proto.enum_type:
- self._AddSymbol(('.'.join((package, enum.name))), file_desc_proto)
- for enum_value in enum.value:
- self._file_desc_protos_by_symbol[
- '.'.join((package, enum_value.name))] = file_desc_proto
+ self._AddSymbol(('.'.join((package, enum.name))), file_desc_proto)
+ for enum_value in enum.value:
+ self._file_desc_protos_by_symbol[
+ '.'.join((package, enum_value.name))] = file_desc_proto
for extension in file_desc_proto.extension:
- self._AddSymbol(('.'.join((package, extension.name))), file_desc_proto)
+ self._AddSymbol(('.'.join((package, extension.name))), file_desc_proto)
for service in file_desc_proto.service:
- self._AddSymbol(('.'.join((package, service.name))), file_desc_proto)
+ self._AddSymbol(('.'.join((package, service.name))), file_desc_proto)
def FindFileByName(self, name):
"""Finds the file descriptor proto by file name.
@@ -111,7 +111,7 @@ class DescriptorDatabase(object):
'some.package.name.Message'
'some.package.name.Message.NestedEnum'
- 'some.package.name.Message.some_field'
+ 'some.package.name.Message.some_field'
The file descriptor proto containing the specified symbol must be added to
this database using the Add method or else an error will be raised.
@@ -125,39 +125,39 @@ class DescriptorDatabase(object):
Raises:
KeyError if no file contains the specified symbol.
"""
- try:
- return self._file_desc_protos_by_symbol[symbol]
- except KeyError:
- # Fields, enum values, and nested extensions are not in
- # _file_desc_protos_by_symbol. Try to find the top level
- # descriptor. Non-existent nested symbol under a valid top level
- # descriptor can also be found. The behavior is the same with
- # protobuf C++.
- top_level, _, _ = symbol.rpartition('.')
- try:
- return self._file_desc_protos_by_symbol[top_level]
- except KeyError:
- # Raise the original symbol as a KeyError for better diagnostics.
- raise KeyError(symbol)
-
- def FindFileContainingExtension(self, extendee_name, extension_number):
- # TODO(jieluo): implement this API.
- return None
-
- def FindAllExtensionNumbers(self, extendee_name):
- # TODO(jieluo): implement this API.
- return []
-
- def _AddSymbol(self, name, file_desc_proto):
- if name in self._file_desc_protos_by_symbol:
- warn_msg = ('Conflict register for file "' + file_desc_proto.name +
- '": ' + name +
- ' is already defined in file "' +
- self._file_desc_protos_by_symbol[name].name + '"')
- warnings.warn(warn_msg, RuntimeWarning)
- self._file_desc_protos_by_symbol[name] = file_desc_proto
-
-
+ try:
+ return self._file_desc_protos_by_symbol[symbol]
+ except KeyError:
+ # Fields, enum values, and nested extensions are not in
+ # _file_desc_protos_by_symbol. Try to find the top level
+ # descriptor. Non-existent nested symbol under a valid top level
+ # descriptor can also be found. The behavior is the same with
+ # protobuf C++.
+ top_level, _, _ = symbol.rpartition('.')
+ try:
+ return self._file_desc_protos_by_symbol[top_level]
+ except KeyError:
+ # Raise the original symbol as a KeyError for better diagnostics.
+ raise KeyError(symbol)
+
+ def FindFileContainingExtension(self, extendee_name, extension_number):
+ # TODO(jieluo): implement this API.
+ return None
+
+ def FindAllExtensionNumbers(self, extendee_name):
+ # TODO(jieluo): implement this API.
+ return []
+
+ def _AddSymbol(self, name, file_desc_proto):
+ if name in self._file_desc_protos_by_symbol:
+ warn_msg = ('Conflict register for file "' + file_desc_proto.name +
+ '": ' + name +
+ ' is already defined in file "' +
+ self._file_desc_protos_by_symbol[name].name + '"')
+ warnings.warn(warn_msg, RuntimeWarning)
+ self._file_desc_protos_by_symbol[name] = file_desc_proto
+
+
def _ExtractSymbols(desc_proto, package):
"""Pulls out all the symbols from a descriptor proto.
diff --git a/contrib/python/protobuf/py2/google/protobuf/descriptor_pool.py b/contrib/python/protobuf/py2/google/protobuf/descriptor_pool.py
index de9100b09c..37df6e7562 100644
--- a/contrib/python/protobuf/py2/google/protobuf/descriptor_pool.py
+++ b/contrib/python/protobuf/py2/google/protobuf/descriptor_pool.py
@@ -38,7 +38,7 @@ For most applications protocol buffers should be used via modules generated by
the protocol buffer compiler tool. This should only be used when the type of
protocol buffers used in an application or library cannot be predetermined.
-Below is a straightforward example on how to use this class::
+Below is a straightforward example on how to use this class::
pool = DescriptorPool()
file_descriptor_protos = [ ... ]
@@ -58,7 +58,7 @@ directly instead of this class.
__author__ = 'matthewtoia@google.com (Matt Toia)'
import collections
-import warnings
+import warnings
from google.protobuf import descriptor
from google.protobuf import descriptor_database
@@ -68,22 +68,22 @@ from google.protobuf import text_encoding
_USE_C_DESCRIPTORS = descriptor._USE_C_DESCRIPTORS # pylint: disable=protected-access
-def _Deprecated(func):
- """Mark functions as deprecated."""
-
- def NewFunc(*args, **kwargs):
- warnings.warn(
- 'Call to deprecated function %s(). Note: Do add unlinked descriptors '
- 'to descriptor_pool is wrong. Use Add() or AddSerializedFile() '
- 'instead.' % func.__name__,
- category=DeprecationWarning)
- return func(*args, **kwargs)
- NewFunc.__name__ = func.__name__
- NewFunc.__doc__ = func.__doc__
- NewFunc.__dict__.update(func.__dict__)
- return NewFunc
-
-
+def _Deprecated(func):
+ """Mark functions as deprecated."""
+
+ def NewFunc(*args, **kwargs):
+ warnings.warn(
+ 'Call to deprecated function %s(). Note: Do add unlinked descriptors '
+ 'to descriptor_pool is wrong. Use Add() or AddSerializedFile() '
+ 'instead.' % func.__name__,
+ category=DeprecationWarning)
+ return func(*args, **kwargs)
+ NewFunc.__name__ = func.__name__
+ NewFunc.__doc__ = func.__doc__
+ NewFunc.__dict__.update(func.__dict__)
+ return NewFunc
+
+
def _NormalizeFullyQualifiedName(name):
"""Remove leading period from fully-qualified type name.
@@ -91,10 +91,10 @@ def _NormalizeFullyQualifiedName(name):
generated with a leading period. This function removes that prefix.
Args:
- name (str): The fully-qualified symbol name.
+ name (str): The fully-qualified symbol name.
Returns:
- str: The normalized fully-qualified symbol name.
+ str: The normalized fully-qualified symbol name.
"""
return name.lstrip('.')
@@ -144,59 +144,59 @@ class DescriptorPool(object):
self._service_descriptors = {}
self._file_descriptors = {}
self._toplevel_extensions = {}
- # TODO(jieluo): Remove _file_desc_by_toplevel_extension after
- # maybe year 2020 for compatibility issue (with 3.4.1 only).
+ # TODO(jieluo): Remove _file_desc_by_toplevel_extension after
+ # maybe year 2020 for compatibility issue (with 3.4.1 only).
self._file_desc_by_toplevel_extension = {}
- self._top_enum_values = {}
+ self._top_enum_values = {}
# We store extensions in two two-level mappings: The first key is the
# descriptor of the message being extended, the second key is the extension
# full name or its tag number.
self._extensions_by_name = collections.defaultdict(dict)
self._extensions_by_number = collections.defaultdict(dict)
- def _CheckConflictRegister(self, desc, desc_name, file_name):
- """Check if the descriptor name conflicts with another of the same name.
-
- Args:
- desc: Descriptor of a message, enum, service, extension or enum value.
- desc_name (str): the full name of desc.
- file_name (str): The file name of descriptor.
- """
- for register, descriptor_type in [
- (self._descriptors, descriptor.Descriptor),
- (self._enum_descriptors, descriptor.EnumDescriptor),
- (self._service_descriptors, descriptor.ServiceDescriptor),
- (self._toplevel_extensions, descriptor.FieldDescriptor),
- (self._top_enum_values, descriptor.EnumValueDescriptor)]:
- if desc_name in register:
- old_desc = register[desc_name]
- if isinstance(old_desc, descriptor.EnumValueDescriptor):
- old_file = old_desc.type.file.name
- else:
- old_file = old_desc.file.name
-
- if not isinstance(desc, descriptor_type) or (
- old_file != file_name):
- error_msg = ('Conflict register for file "' + file_name +
- '": ' + desc_name +
- ' is already defined in file "' +
- old_file + '". Please fix the conflict by adding '
- 'package name on the proto file, or use different '
- 'name for the duplication.')
- if isinstance(desc, descriptor.EnumValueDescriptor):
- error_msg += ('\nNote: enum values appear as '
- 'siblings of the enum type instead of '
- 'children of it.')
-
- raise TypeError(error_msg)
-
- return
-
+ def _CheckConflictRegister(self, desc, desc_name, file_name):
+ """Check if the descriptor name conflicts with another of the same name.
+
+ Args:
+ desc: Descriptor of a message, enum, service, extension or enum value.
+ desc_name (str): the full name of desc.
+ file_name (str): The file name of descriptor.
+ """
+ for register, descriptor_type in [
+ (self._descriptors, descriptor.Descriptor),
+ (self._enum_descriptors, descriptor.EnumDescriptor),
+ (self._service_descriptors, descriptor.ServiceDescriptor),
+ (self._toplevel_extensions, descriptor.FieldDescriptor),
+ (self._top_enum_values, descriptor.EnumValueDescriptor)]:
+ if desc_name in register:
+ old_desc = register[desc_name]
+ if isinstance(old_desc, descriptor.EnumValueDescriptor):
+ old_file = old_desc.type.file.name
+ else:
+ old_file = old_desc.file.name
+
+ if not isinstance(desc, descriptor_type) or (
+ old_file != file_name):
+ error_msg = ('Conflict register for file "' + file_name +
+ '": ' + desc_name +
+ ' is already defined in file "' +
+ old_file + '". Please fix the conflict by adding '
+ 'package name on the proto file, or use different '
+ 'name for the duplication.')
+ if isinstance(desc, descriptor.EnumValueDescriptor):
+ error_msg += ('\nNote: enum values appear as '
+ 'siblings of the enum type instead of '
+ 'children of it.')
+
+ raise TypeError(error_msg)
+
+ return
+
def Add(self, file_desc_proto):
"""Adds the FileDescriptorProto and its types to this pool.
Args:
- file_desc_proto (FileDescriptorProto): The file descriptor to add.
+ file_desc_proto (FileDescriptorProto): The file descriptor to add.
"""
self._internal_db.Add(file_desc_proto)
@@ -205,8 +205,8 @@ class DescriptorPool(object):
"""Adds the FileDescriptorProto and its types to this pool.
Args:
- serialized_file_desc_proto (bytes): A bytes string, serialization of the
- :class:`FileDescriptorProto` to add.
+ serialized_file_desc_proto (bytes): A bytes string, serialization of the
+ :class:`FileDescriptorProto` to add.
"""
# pylint: disable=g-import-not-at-top
@@ -215,14 +215,14 @@ class DescriptorPool(object):
serialized_file_desc_proto)
self.Add(file_desc_proto)
- # Add Descriptor to descriptor pool is dreprecated. Please use Add()
- # or AddSerializedFile() to add a FileDescriptorProto instead.
- @_Deprecated
+ # Add Descriptor to descriptor pool is dreprecated. Please use Add()
+ # or AddSerializedFile() to add a FileDescriptorProto instead.
+ @_Deprecated
def AddDescriptor(self, desc):
- self._AddDescriptor(desc)
-
- # Never call this method. It is for internal usage only.
- def _AddDescriptor(self, desc):
+ self._AddDescriptor(desc)
+
+ # Never call this method. It is for internal usage only.
+ def _AddDescriptor(self, desc):
"""Adds a Descriptor to the pool, non-recursively.
If the Descriptor contains nested messages or enums, the caller must
@@ -235,19 +235,19 @@ class DescriptorPool(object):
if not isinstance(desc, descriptor.Descriptor):
raise TypeError('Expected instance of descriptor.Descriptor.')
- self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
-
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
+
self._descriptors[desc.full_name] = desc
self._AddFileDescriptor(desc.file)
- # Add EnumDescriptor to descriptor pool is dreprecated. Please use Add()
- # or AddSerializedFile() to add a FileDescriptorProto instead.
- @_Deprecated
+ # Add EnumDescriptor to descriptor pool is dreprecated. Please use Add()
+ # or AddSerializedFile() to add a FileDescriptorProto instead.
+ @_Deprecated
def AddEnumDescriptor(self, enum_desc):
- self._AddEnumDescriptor(enum_desc)
-
- # Never call this method. It is for internal usage only.
- def _AddEnumDescriptor(self, enum_desc):
+ self._AddEnumDescriptor(enum_desc)
+
+ # Never call this method. It is for internal usage only.
+ def _AddEnumDescriptor(self, enum_desc):
"""Adds an EnumDescriptor to the pool.
This method also registers the FileDescriptor associated with the enum.
@@ -259,36 +259,36 @@ class DescriptorPool(object):
if not isinstance(enum_desc, descriptor.EnumDescriptor):
raise TypeError('Expected instance of descriptor.EnumDescriptor.')
- file_name = enum_desc.file.name
- self._CheckConflictRegister(enum_desc, enum_desc.full_name, file_name)
+ file_name = enum_desc.file.name
+ self._CheckConflictRegister(enum_desc, enum_desc.full_name, file_name)
self._enum_descriptors[enum_desc.full_name] = enum_desc
-
- # Top enum values need to be indexed.
- # Count the number of dots to see whether the enum is toplevel or nested
- # in a message. We cannot use enum_desc.containing_type at this stage.
- if enum_desc.file.package:
- top_level = (enum_desc.full_name.count('.')
- - enum_desc.file.package.count('.') == 1)
- else:
- top_level = enum_desc.full_name.count('.') == 0
- if top_level:
- file_name = enum_desc.file.name
- package = enum_desc.file.package
- for enum_value in enum_desc.values:
- full_name = _NormalizeFullyQualifiedName(
- '.'.join((package, enum_value.name)))
- self._CheckConflictRegister(enum_value, full_name, file_name)
- self._top_enum_values[full_name] = enum_value
+
+ # Top enum values need to be indexed.
+ # Count the number of dots to see whether the enum is toplevel or nested
+ # in a message. We cannot use enum_desc.containing_type at this stage.
+ if enum_desc.file.package:
+ top_level = (enum_desc.full_name.count('.')
+ - enum_desc.file.package.count('.') == 1)
+ else:
+ top_level = enum_desc.full_name.count('.') == 0
+ if top_level:
+ file_name = enum_desc.file.name
+ package = enum_desc.file.package
+ for enum_value in enum_desc.values:
+ full_name = _NormalizeFullyQualifiedName(
+ '.'.join((package, enum_value.name)))
+ self._CheckConflictRegister(enum_value, full_name, file_name)
+ self._top_enum_values[full_name] = enum_value
self._AddFileDescriptor(enum_desc.file)
- # Add ServiceDescriptor to descriptor pool is dreprecated. Please use Add()
- # or AddSerializedFile() to add a FileDescriptorProto instead.
- @_Deprecated
+ # Add ServiceDescriptor to descriptor pool is dreprecated. Please use Add()
+ # or AddSerializedFile() to add a FileDescriptorProto instead.
+ @_Deprecated
def AddServiceDescriptor(self, service_desc):
- self._AddServiceDescriptor(service_desc)
-
- # Never call this method. It is for internal usage only.
- def _AddServiceDescriptor(self, service_desc):
+ self._AddServiceDescriptor(service_desc)
+
+ # Never call this method. It is for internal usage only.
+ def _AddServiceDescriptor(self, service_desc):
"""Adds a ServiceDescriptor to the pool.
Args:
@@ -298,18 +298,18 @@ class DescriptorPool(object):
if not isinstance(service_desc, descriptor.ServiceDescriptor):
raise TypeError('Expected instance of descriptor.ServiceDescriptor.')
- self._CheckConflictRegister(service_desc, service_desc.full_name,
- service_desc.file.name)
+ self._CheckConflictRegister(service_desc, service_desc.full_name,
+ service_desc.file.name)
self._service_descriptors[service_desc.full_name] = service_desc
- # Add ExtensionDescriptor to descriptor pool is dreprecated. Please use Add()
- # or AddSerializedFile() to add a FileDescriptorProto instead.
- @_Deprecated
+ # Add ExtensionDescriptor to descriptor pool is dreprecated. Please use Add()
+ # or AddSerializedFile() to add a FileDescriptorProto instead.
+ @_Deprecated
def AddExtensionDescriptor(self, extension):
- self._AddExtensionDescriptor(extension)
-
- # Never call this method. It is for internal usage only.
- def _AddExtensionDescriptor(self, extension):
+ self._AddExtensionDescriptor(extension)
+
+ # Never call this method. It is for internal usage only.
+ def _AddExtensionDescriptor(self, extension):
"""Adds a FieldDescriptor describing an extension to the pool.
Args:
@@ -351,12 +351,12 @@ class DescriptorPool(object):
self._extensions_by_name[extension.containing_type][
extension.message_type.full_name] = extension
- @_Deprecated
+ @_Deprecated
def AddFileDescriptor(self, file_desc):
- self._InternalAddFileDescriptor(file_desc)
-
- # Never call this method. It is for internal usage only.
- def _InternalAddFileDescriptor(self, file_desc):
+ self._InternalAddFileDescriptor(file_desc)
+
+ # Never call this method. It is for internal usage only.
+ def _InternalAddFileDescriptor(self, file_desc):
"""Adds a FileDescriptor to the pool, non-recursively.
If the FileDescriptor contains messages or enums, the caller must explicitly
@@ -368,8 +368,8 @@ class DescriptorPool(object):
self._AddFileDescriptor(file_desc)
# TODO(jieluo): This is a temporary solution for FieldDescriptor.file.
- # FieldDescriptor.file is added in code gen. Remove this solution after
- # maybe 2020 for compatibility reason (with 3.4.1 only).
+ # FieldDescriptor.file is added in code gen. Remove this solution after
+ # maybe 2020 for compatibility reason (with 3.4.1 only).
for extension in file_desc.extensions_by_name.values():
self._file_desc_by_toplevel_extension[
extension.full_name] = file_desc
@@ -392,10 +392,10 @@ class DescriptorPool(object):
"""Gets a FileDescriptor by file name.
Args:
- file_name (str): The path to the file to get a descriptor for.
+ file_name (str): The path to the file to get a descriptor for.
Returns:
- FileDescriptor: The descriptor for the named file.
+ FileDescriptor: The descriptor for the named file.
Raises:
KeyError: if the file cannot be found in the pool.
@@ -421,11 +421,11 @@ class DescriptorPool(object):
"""Gets the FileDescriptor for the file containing the specified symbol.
Args:
- symbol (str): The name of the symbol to search for.
+ symbol (str): The name of the symbol to search for.
Returns:
- FileDescriptor: Descriptor for the file that contains the specified
- symbol.
+ FileDescriptor: Descriptor for the file that contains the specified
+ symbol.
Raises:
KeyError: if the file cannot be found in the pool.
@@ -433,31 +433,31 @@ class DescriptorPool(object):
symbol = _NormalizeFullyQualifiedName(symbol)
try:
- return self._InternalFindFileContainingSymbol(symbol)
- except KeyError:
- pass
-
- try:
- # Try fallback database. Build and find again if possible.
- self._FindFileContainingSymbolInDb(symbol)
- return self._InternalFindFileContainingSymbol(symbol)
- except KeyError:
- raise KeyError('Cannot find a file containing %s' % symbol)
-
- def _InternalFindFileContainingSymbol(self, symbol):
- """Gets the already built FileDescriptor containing the specified symbol.
-
- Args:
- symbol (str): The name of the symbol to search for.
-
- Returns:
- FileDescriptor: Descriptor for the file that contains the specified
- symbol.
-
- Raises:
- KeyError: if the file cannot be found in the pool.
- """
- try:
+ return self._InternalFindFileContainingSymbol(symbol)
+ except KeyError:
+ pass
+
+ try:
+ # Try fallback database. Build and find again if possible.
+ self._FindFileContainingSymbolInDb(symbol)
+ return self._InternalFindFileContainingSymbol(symbol)
+ except KeyError:
+ raise KeyError('Cannot find a file containing %s' % symbol)
+
+ def _InternalFindFileContainingSymbol(self, symbol):
+ """Gets the already built FileDescriptor containing the specified symbol.
+
+ Args:
+ symbol (str): The name of the symbol to search for.
+
+ Returns:
+ FileDescriptor: Descriptor for the file that contains the specified
+ symbol.
+
+ Raises:
+ KeyError: if the file cannot be found in the pool.
+ """
+ try:
return self._descriptors[symbol].file
except KeyError:
pass
@@ -473,7 +473,7 @@ class DescriptorPool(object):
pass
try:
- return self._top_enum_values[symbol].type.file
+ return self._top_enum_values[symbol].type.file
except KeyError:
pass
@@ -482,25 +482,25 @@ class DescriptorPool(object):
except KeyError:
pass
- # Try fields, enum values and nested extensions inside a message.
- top_name, _, sub_name = symbol.rpartition('.')
+ # Try fields, enum values and nested extensions inside a message.
+ top_name, _, sub_name = symbol.rpartition('.')
try:
- message = self.FindMessageTypeByName(top_name)
- assert (sub_name in message.extensions_by_name or
- sub_name in message.fields_by_name or
- sub_name in message.enum_values_by_name)
+ message = self.FindMessageTypeByName(top_name)
+ assert (sub_name in message.extensions_by_name or
+ sub_name in message.fields_by_name or
+ sub_name in message.enum_values_by_name)
return message.file
- except (KeyError, AssertionError):
+ except (KeyError, AssertionError):
raise KeyError('Cannot find a file containing %s' % symbol)
def FindMessageTypeByName(self, full_name):
"""Loads the named descriptor from the pool.
Args:
- full_name (str): The full name of the descriptor to load.
+ full_name (str): The full name of the descriptor to load.
Returns:
- Descriptor: The descriptor for the named type.
+ Descriptor: The descriptor for the named type.
Raises:
KeyError: if the message cannot be found in the pool.
@@ -515,10 +515,10 @@ class DescriptorPool(object):
"""Loads the named enum descriptor from the pool.
Args:
- full_name (str): The full name of the enum descriptor to load.
+ full_name (str): The full name of the enum descriptor to load.
Returns:
- EnumDescriptor: The enum descriptor for the named type.
+ EnumDescriptor: The enum descriptor for the named type.
Raises:
KeyError: if the enum cannot be found in the pool.
@@ -533,10 +533,10 @@ class DescriptorPool(object):
"""Loads the named field descriptor from the pool.
Args:
- full_name (str): The full name of the field descriptor to load.
+ full_name (str): The full name of the field descriptor to load.
Returns:
- FieldDescriptor: The field descriptor for the named field.
+ FieldDescriptor: The field descriptor for the named field.
Raises:
KeyError: if the field cannot be found in the pool.
@@ -546,31 +546,31 @@ class DescriptorPool(object):
message_descriptor = self.FindMessageTypeByName(message_name)
return message_descriptor.fields_by_name[field_name]
- def FindOneofByName(self, full_name):
- """Loads the named oneof descriptor from the pool.
-
- Args:
- full_name (str): The full name of the oneof descriptor to load.
-
- Returns:
- OneofDescriptor: The oneof descriptor for the named oneof.
-
- Raises:
- KeyError: if the oneof cannot be found in the pool.
- """
- full_name = _NormalizeFullyQualifiedName(full_name)
- message_name, _, oneof_name = full_name.rpartition('.')
- message_descriptor = self.FindMessageTypeByName(message_name)
- return message_descriptor.oneofs_by_name[oneof_name]
-
+ def FindOneofByName(self, full_name):
+ """Loads the named oneof descriptor from the pool.
+
+ Args:
+ full_name (str): The full name of the oneof descriptor to load.
+
+ Returns:
+ OneofDescriptor: The oneof descriptor for the named oneof.
+
+ Raises:
+ KeyError: if the oneof cannot be found in the pool.
+ """
+ full_name = _NormalizeFullyQualifiedName(full_name)
+ message_name, _, oneof_name = full_name.rpartition('.')
+ message_descriptor = self.FindMessageTypeByName(message_name)
+ return message_descriptor.oneofs_by_name[oneof_name]
+
def FindExtensionByName(self, full_name):
"""Loads the named extension descriptor from the pool.
Args:
- full_name (str): The full name of the extension descriptor to load.
+ full_name (str): The full name of the extension descriptor to load.
Returns:
- FieldDescriptor: The field descriptor for the named extension.
+ FieldDescriptor: The field descriptor for the named extension.
Raises:
KeyError: if the extension cannot be found in the pool.
@@ -596,86 +596,86 @@ class DescriptorPool(object):
def FindExtensionByNumber(self, message_descriptor, number):
"""Gets the extension of the specified message with the specified number.
- Extensions have to be registered to this pool by calling :func:`Add` or
- :func:`AddExtensionDescriptor`.
+ Extensions have to be registered to this pool by calling :func:`Add` or
+ :func:`AddExtensionDescriptor`.
Args:
- message_descriptor (Descriptor): descriptor of the extended message.
- number (int): Number of the extension field.
+ message_descriptor (Descriptor): descriptor of the extended message.
+ number (int): Number of the extension field.
Returns:
- FieldDescriptor: The descriptor for the extension.
+ FieldDescriptor: The descriptor for the extension.
Raises:
KeyError: when no extension with the given number is known for the
specified message.
"""
- try:
- return self._extensions_by_number[message_descriptor][number]
- except KeyError:
- self._TryLoadExtensionFromDB(message_descriptor, number)
- return self._extensions_by_number[message_descriptor][number]
+ try:
+ return self._extensions_by_number[message_descriptor][number]
+ except KeyError:
+ self._TryLoadExtensionFromDB(message_descriptor, number)
+ return self._extensions_by_number[message_descriptor][number]
def FindAllExtensions(self, message_descriptor):
- """Gets all the known extensions of a given message.
+ """Gets all the known extensions of a given message.
- Extensions have to be registered to this pool by build related
- :func:`Add` or :func:`AddExtensionDescriptor`.
+ Extensions have to be registered to this pool by build related
+ :func:`Add` or :func:`AddExtensionDescriptor`.
Args:
- message_descriptor (Descriptor): Descriptor of the extended message.
+ message_descriptor (Descriptor): Descriptor of the extended message.
Returns:
- list[FieldDescriptor]: Field descriptors describing the extensions.
+ list[FieldDescriptor]: Field descriptors describing the extensions.
"""
- # Fallback to descriptor db if FindAllExtensionNumbers is provided.
- if self._descriptor_db and hasattr(
- self._descriptor_db, 'FindAllExtensionNumbers'):
- full_name = message_descriptor.full_name
- all_numbers = self._descriptor_db.FindAllExtensionNumbers(full_name)
- for number in all_numbers:
- if number in self._extensions_by_number[message_descriptor]:
- continue
- self._TryLoadExtensionFromDB(message_descriptor, number)
-
+ # Fallback to descriptor db if FindAllExtensionNumbers is provided.
+ if self._descriptor_db and hasattr(
+ self._descriptor_db, 'FindAllExtensionNumbers'):
+ full_name = message_descriptor.full_name
+ all_numbers = self._descriptor_db.FindAllExtensionNumbers(full_name)
+ for number in all_numbers:
+ if number in self._extensions_by_number[message_descriptor]:
+ continue
+ self._TryLoadExtensionFromDB(message_descriptor, number)
+
return list(self._extensions_by_number[message_descriptor].values())
- def _TryLoadExtensionFromDB(self, message_descriptor, number):
- """Try to Load extensions from descriptor db.
-
- Args:
- message_descriptor: descriptor of the extended message.
- number: the extension number that needs to be loaded.
- """
- if not self._descriptor_db:
- return
- # Only supported when FindFileContainingExtension is provided.
- if not hasattr(
- self._descriptor_db, 'FindFileContainingExtension'):
- return
-
- full_name = message_descriptor.full_name
- file_proto = self._descriptor_db.FindFileContainingExtension(
- full_name, number)
-
- if file_proto is None:
- return
-
- try:
- self._ConvertFileProtoToFileDescriptor(file_proto)
- except:
- warn_msg = ('Unable to load proto file %s for extension number %d.' %
- (file_proto.name, number))
- warnings.warn(warn_msg, RuntimeWarning)
-
+ def _TryLoadExtensionFromDB(self, message_descriptor, number):
+ """Try to Load extensions from descriptor db.
+
+ Args:
+ message_descriptor: descriptor of the extended message.
+ number: the extension number that needs to be loaded.
+ """
+ if not self._descriptor_db:
+ return
+ # Only supported when FindFileContainingExtension is provided.
+ if not hasattr(
+ self._descriptor_db, 'FindFileContainingExtension'):
+ return
+
+ full_name = message_descriptor.full_name
+ file_proto = self._descriptor_db.FindFileContainingExtension(
+ full_name, number)
+
+ if file_proto is None:
+ return
+
+ try:
+ self._ConvertFileProtoToFileDescriptor(file_proto)
+ except:
+ warn_msg = ('Unable to load proto file %s for extension number %d.' %
+ (file_proto.name, number))
+ warnings.warn(warn_msg, RuntimeWarning)
+
def FindServiceByName(self, full_name):
"""Loads the named service descriptor from the pool.
Args:
- full_name (str): The full name of the service descriptor to load.
+ full_name (str): The full name of the service descriptor to load.
Returns:
- ServiceDescriptor: The service descriptor for the named service.
+ ServiceDescriptor: The service descriptor for the named service.
Raises:
KeyError: if the service cannot be found in the pool.
@@ -685,31 +685,31 @@ class DescriptorPool(object):
self._FindFileContainingSymbolInDb(full_name)
return self._service_descriptors[full_name]
- def FindMethodByName(self, full_name):
- """Loads the named service method descriptor from the pool.
-
- Args:
- full_name (str): The full name of the method descriptor to load.
-
- Returns:
- MethodDescriptor: The method descriptor for the service method.
-
- Raises:
- KeyError: if the method cannot be found in the pool.
- """
- full_name = _NormalizeFullyQualifiedName(full_name)
- service_name, _, method_name = full_name.rpartition('.')
- service_descriptor = self.FindServiceByName(service_name)
- return service_descriptor.methods_by_name[method_name]
-
+ def FindMethodByName(self, full_name):
+ """Loads the named service method descriptor from the pool.
+
+ Args:
+ full_name (str): The full name of the method descriptor to load.
+
+ Returns:
+ MethodDescriptor: The method descriptor for the service method.
+
+ Raises:
+ KeyError: if the method cannot be found in the pool.
+ """
+ full_name = _NormalizeFullyQualifiedName(full_name)
+ service_name, _, method_name = full_name.rpartition('.')
+ service_descriptor = self.FindServiceByName(service_name)
+ return service_descriptor.methods_by_name[method_name]
+
def _FindFileContainingSymbolInDb(self, symbol):
"""Finds the file in descriptor DB containing the specified symbol.
Args:
- symbol (str): The name of the symbol to search for.
+ symbol (str): The name of the symbol to search for.
Returns:
- FileDescriptor: The file that contains the specified symbol.
+ FileDescriptor: The file that contains the specified symbol.
Raises:
KeyError: if the file cannot be found in the descriptor database.
@@ -750,9 +750,9 @@ class DescriptorPool(object):
options=_OptionsOrNone(file_proto),
serialized_pb=file_proto.SerializeToString(),
dependencies=direct_deps,
- public_dependencies=public_deps,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ public_dependencies=public_deps,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
scope = {}
# This loop extracts all the message and enum types from all the
@@ -775,7 +775,7 @@ class DescriptorPool(object):
for enum_type in file_proto.enum_type:
file_descriptor.enum_types_by_name[enum_type.name] = (
self._ConvertEnumDescriptor(enum_type, file_proto.package,
- file_descriptor, None, scope, True))
+ file_descriptor, None, scope, True))
for index, extension_proto in enumerate(file_proto.extension):
extension_desc = self._MakeFieldDescriptor(
@@ -787,8 +787,8 @@ class DescriptorPool(object):
file_descriptor.package, scope)
file_descriptor.extensions_by_name[extension_desc.name] = (
extension_desc)
- self._file_desc_by_toplevel_extension[extension_desc.full_name] = (
- file_descriptor)
+ self._file_desc_by_toplevel_extension[extension_desc.full_name] = (
+ file_descriptor)
for desc_proto in file_proto.message_type:
self._SetAllFieldTypes(file_proto.package, desc_proto, scope)
@@ -811,16 +811,16 @@ class DescriptorPool(object):
self.Add(file_proto)
self._file_descriptors[file_proto.name] = file_descriptor
- # Add extensions to the pool
- file_desc = self._file_descriptors[file_proto.name]
- for extension in file_desc.extensions_by_name.values():
- self._AddExtensionDescriptor(extension)
- for message_type in file_desc.message_types_by_name.values():
- for extension in message_type.extensions:
- self._AddExtensionDescriptor(extension)
-
- return file_desc
+ # Add extensions to the pool
+ file_desc = self._file_descriptors[file_proto.name]
+ for extension in file_desc.extensions_by_name.values():
+ self._AddExtensionDescriptor(extension)
+ for message_type in file_desc.message_types_by_name.values():
+ for extension in message_type.extensions:
+ self._AddExtensionDescriptor(extension)
+ return file_desc
+
def _ConvertMessageDescriptor(self, desc_proto, package=None, file_desc=None,
scope=None, syntax=None):
"""Adds the proto to the pool in the specified package.
@@ -854,8 +854,8 @@ class DescriptorPool(object):
nested, desc_name, file_desc, scope, syntax)
for nested in desc_proto.nested_type]
enums = [
- self._ConvertEnumDescriptor(enum, desc_name, file_desc, None,
- scope, False)
+ self._ConvertEnumDescriptor(enum, desc_name, file_desc, None,
+ scope, False)
for enum in desc_proto.enum_type]
fields = [self._MakeFieldDescriptor(field, desc_name, index, file_desc)
for index, field in enumerate(desc_proto.field)]
@@ -864,11 +864,11 @@ class DescriptorPool(object):
is_extension=True)
for index, extension in enumerate(desc_proto.extension)]
oneofs = [
- # pylint: disable=g-complex-comprehension
+ # pylint: disable=g-complex-comprehension
descriptor.OneofDescriptor(desc.name, '.'.join((desc_name, desc.name)),
- index, None, [], desc.options,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ index, None, [], desc.options,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
for index, desc in enumerate(desc_proto.oneof_decl)]
extension_ranges = [(r.start, r.end) for r in desc_proto.extension_range]
if extension_ranges:
@@ -891,9 +891,9 @@ class DescriptorPool(object):
file=file_desc,
serialized_start=None,
serialized_end=None,
- syntax=syntax,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ syntax=syntax,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
for nested in desc.nested_types:
nested.containing_type = desc
for enum in desc.enum_types:
@@ -905,12 +905,12 @@ class DescriptorPool(object):
fields[field_index].containing_oneof = oneofs[oneof_index]
scope[_PrefixWithDot(desc_name)] = desc
- self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
self._descriptors[desc_name] = desc
return desc
def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None,
- containing_type=None, scope=None, top_level=False):
+ containing_type=None, scope=None, top_level=False):
"""Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf.
Args:
@@ -919,8 +919,8 @@ class DescriptorPool(object):
file_desc: The file containing the enum descriptor.
containing_type: The type containing this enum.
scope: Scope containing available types.
- top_level: If True, the enum is a top level symbol. If False, the enum
- is defined inside a message.
+ top_level: If True, the enum is a top level symbol. If False, the enum
+ is defined inside a message.
Returns:
The added descriptor
@@ -944,21 +944,21 @@ class DescriptorPool(object):
file=file_desc,
values=values,
containing_type=containing_type,
- options=_OptionsOrNone(enum_proto),
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ options=_OptionsOrNone(enum_proto),
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
scope['.%s' % enum_name] = desc
- self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
self._enum_descriptors[enum_name] = desc
-
- # Add top level enum values.
- if top_level:
- for value in values:
- full_name = _NormalizeFullyQualifiedName(
- '.'.join((package, value.name)))
- self._CheckConflictRegister(value, full_name, file_name)
- self._top_enum_values[full_name] = value
-
+
+ # Add top level enum values.
+ if top_level:
+ for value in values:
+ full_name = _NormalizeFullyQualifiedName(
+ '.'.join((package, value.name)))
+ self._CheckConflictRegister(value, full_name, file_name)
+ self._top_enum_values[full_name] = value
+
return desc
def _MakeFieldDescriptor(self, field_proto, message_name, index,
@@ -1003,9 +1003,9 @@ class DescriptorPool(object):
is_extension=is_extension,
extension_scope=None,
options=_OptionsOrNone(field_proto),
- file=file_desc,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ file=file_desc,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
def _SetAllFieldTypes(self, package, desc_proto, scope):
"""Sets all the descriptor's fields's types.
@@ -1044,7 +1044,7 @@ class DescriptorPool(object):
Args:
field_proto: Data about the field in proto format.
- field_desc: The descriptor to modify.
+ field_desc: The descriptor to modify.
package: The package the field's container is in.
scope: Enclosing scope of available types.
"""
@@ -1087,8 +1087,8 @@ class DescriptorPool(object):
elif field_proto.type == descriptor.FieldDescriptor.TYPE_BYTES:
field_desc.default_value = text_encoding.CUnescape(
field_proto.default_value)
- elif field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE:
- field_desc.default_value = None
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE:
+ field_desc.default_value = None
else:
# All other types are of the "int" type.
field_desc.default_value = int(field_proto.default_value)
@@ -1105,8 +1105,8 @@ class DescriptorPool(object):
field_desc.default_value = field_desc.enum_type.values[0].number
elif field_proto.type == descriptor.FieldDescriptor.TYPE_BYTES:
field_desc.default_value = b''
- elif field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE:
- field_desc.default_value = None
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE:
+ field_desc.default_value = None
else:
# All other types are of the "int" type.
field_desc.default_value = 0
@@ -1129,9 +1129,9 @@ class DescriptorPool(object):
index=index,
number=value_proto.number,
options=_OptionsOrNone(value_proto),
- type=None,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ type=None,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
def _MakeServiceDescriptor(self, service_proto, service_index, scope,
package, file_desc):
@@ -1156,16 +1156,16 @@ class DescriptorPool(object):
methods = [self._MakeMethodDescriptor(method_proto, service_name, package,
scope, index)
for index, method_proto in enumerate(service_proto.method)]
- desc = descriptor.ServiceDescriptor(
- name=service_proto.name,
- full_name=service_name,
- index=service_index,
- methods=methods,
- options=_OptionsOrNone(service_proto),
- file=file_desc,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
- self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
+ desc = descriptor.ServiceDescriptor(
+ name=service_proto.name,
+ full_name=service_name,
+ index=service_index,
+ methods=methods,
+ options=_OptionsOrNone(service_proto),
+ file=file_desc,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
self._service_descriptors[service_name] = desc
return desc
@@ -1188,16 +1188,16 @@ class DescriptorPool(object):
package, method_proto.input_type, scope)
output_type = self._GetTypeFromScope(
package, method_proto.output_type, scope)
- return descriptor.MethodDescriptor(
- name=method_proto.name,
- full_name=full_name,
- index=index,
- containing_service=None,
- input_type=input_type,
- output_type=output_type,
- options=_OptionsOrNone(method_proto),
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ return descriptor.MethodDescriptor(
+ name=method_proto.name,
+ full_name=full_name,
+ index=index,
+ containing_service=None,
+ input_type=input_type,
+ output_type=output_type,
+ options=_OptionsOrNone(method_proto),
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
def _ExtractSymbols(self, descriptors):
"""Pulls out all the symbols from descriptor protos.
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/__init__.py b/contrib/python/protobuf/py2/google/protobuf/internal/__init__.py
index 7d2e571a14..70cba29297 100644
--- a/contrib/python/protobuf/py2/google/protobuf/internal/__init__.py
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/__init__.py
@@ -1,30 +1,30 @@
-# Protocol Buffers - Google's data interchange format
-# Copyright 2008 Google Inc. All rights reserved.
-# https://developers.google.com/protocol-buffers/
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-# * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+# Protocol Buffers - Google's data interchange format
+# Copyright 2008 Google Inc. All rights reserved.
+# https://developers.google.com/protocol-buffers/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/_parameterized.py b/contrib/python/protobuf/py2/google/protobuf/internal/_parameterized.py
index 4cba1d479d..784af0856f 100755
--- a/contrib/python/protobuf/py2/google/protobuf/internal/_parameterized.py
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/_parameterized.py
@@ -37,8 +37,8 @@ argument tuples.
A simple example:
- class AdditionExample(parameterized.TestCase):
- @parameterized.parameters(
+ class AdditionExample(parameterized.TestCase):
+ @parameterized.parameters(
(1, 2, 3),
(4, 5, 9),
(1, 1, 3))
@@ -51,11 +51,11 @@ like a normal test method, with its own setUp/tearDown cycle. In the
example above, there are three separate testcases, one of which will
fail due to an assertion error (1 + 1 != 3).
-Parameters for individual test cases can be tuples (with positional parameters)
+Parameters for individual test cases can be tuples (with positional parameters)
or dictionaries (with named parameters):
- class AdditionExample(parameterized.TestCase):
- @parameterized.parameters(
+ class AdditionExample(parameterized.TestCase):
+ @parameterized.parameters(
{'op1': 1, 'op2': 2, 'result': 3},
{'op1': 4, 'op2': 5, 'result': 9},
)
@@ -77,13 +77,13 @@ stay the same across several invocations, object representations like
'<__main__.Foo object at 0x23d8610>'
are turned into '<__main__.Foo>'. For even more descriptive names,
-especially in test logs, you can use the named_parameters decorator. In
+especially in test logs, you can use the named_parameters decorator. In
this case, only tuples are supported, and the first parameters has to
be a string (or an object that returns an apt name when converted via
str()):
- class NamedExample(parameterized.TestCase):
- @parameterized.named_parameters(
+ class NamedExample(parameterized.TestCase):
+ @parameterized.named_parameters(
('Normal', 'aa', 'aaa', True),
('EmptyPrefix', '', 'abc', True),
('BothEmpty', '', '', True))
@@ -103,13 +103,13 @@ from the command line:
Parameterized Classes
=====================
If invocation arguments are shared across test methods in a single
-TestCase class, instead of decorating all test methods
+TestCase class, instead of decorating all test methods
individually, the class itself can be decorated:
- @parameterized.parameters(
+ @parameterized.parameters(
(1, 2, 3)
(4, 5, 9))
- class ArithmeticTest(parameterized.TestCase):
+ class ArithmeticTest(parameterized.TestCase):
def testAdd(self, arg1, arg2, result):
self.assertEqual(arg1 + arg2, result)
@@ -122,8 +122,8 @@ If parameters should be shared across several test cases, or are dynamically
created from other sources, a single non-tuple iterable can be passed into
the decorator. This iterable will be used to obtain the test cases:
- class AdditionExample(parameterized.TestCase):
- @parameterized.parameters(
+ class AdditionExample(parameterized.TestCase):
+ @parameterized.parameters(
c.op1, c.op2, c.result for c in testcases
)
def testAddition(self, op1, op2, result):
@@ -135,8 +135,8 @@ Single-Argument Test Methods
If a test method takes only one argument, the single argument does not need to
be wrapped into a tuple:
- class NegativeNumberExample(parameterized.TestCase):
- @parameterized.parameters(
+ class NegativeNumberExample(parameterized.TestCase):
+ @parameterized.parameters(
-1, -3, -4, -5
)
def testIsNegative(self, arg):
@@ -218,7 +218,7 @@ class _ParameterizedTestIter(object):
def __call__(self, *args, **kwargs):
raise RuntimeError('You appear to be running a parameterized test case '
'without having inherited from parameterized.'
- 'TestCase. This is bad because none of '
+ 'TestCase. This is bad because none of '
'your test cases are actually being run.')
def __iter__(self):
@@ -269,7 +269,7 @@ def _ModifyClass(class_object, testcases, naming_type):
'Cannot add parameters to %s,'
' which already has parameterized methods.' % (class_object,))
class_object._id_suffix = id_suffix = {}
- # We change the size of __dict__ while we iterate over it,
+ # We change the size of __dict__ while we iterate over it,
# which Python 3.x will complain about, so use copy().
for name, obj in class_object.__dict__.copy().items():
if (name.startswith(unittest.TestLoader.testMethodPrefix)
@@ -312,7 +312,7 @@ def _ParameterDecorator(naming_type, testcases):
return _Apply
-def parameters(*testcases): # pylint: disable=invalid-name
+def parameters(*testcases): # pylint: disable=invalid-name
"""A decorator for creating parameterized tests.
See the module docstring for a usage example.
@@ -327,7 +327,7 @@ def parameters(*testcases): # pylint: disable=invalid-name
return _ParameterDecorator(_ARGUMENT_REPR, testcases)
-def named_parameters(*testcases): # pylint: disable=invalid-name
+def named_parameters(*testcases): # pylint: disable=invalid-name
"""A decorator for creating parameterized tests.
See the module docstring for a usage example. The first element of
@@ -354,7 +354,7 @@ class TestGeneratorMetaclass(type):
up as tests by the unittest framework.
In general, it is supposed to be used in conjunction with the
- parameters decorator.
+ parameters decorator.
"""
def __new__(mcs, class_name, bases, dct):
@@ -391,8 +391,8 @@ def _UpdateClassDictForParamTestCase(dct, id_suffix, name, iterator):
id_suffix[new_name] = getattr(func, '__x_extra_id__', '')
-class TestCase(unittest.TestCase):
- """Base class for test cases using the parameters decorator."""
+class TestCase(unittest.TestCase):
+ """Base class for test cases using the parameters decorator."""
__metaclass__ = TestGeneratorMetaclass
def _OriginalName(self):
@@ -415,10 +415,10 @@ class TestCase(unittest.TestCase):
self._id_suffix.get(self._testMethodName, ''))
-def CoopTestCase(other_base_class):
+def CoopTestCase(other_base_class):
"""Returns a new base class with a cooperative metaclass base.
- This enables the TestCase to be used in combination
+ This enables the TestCase to be used in combination
with other base classes that have custom metaclasses, such as
mox.MoxTestBase.
@@ -431,7 +431,7 @@ def CoopTestCase(other_base_class):
from google3.testing.pybase import parameterized
- class ExampleTest(parameterized.CoopTestCase(mox.MoxTestBase)):
+ class ExampleTest(parameterized.CoopTestCase(mox.MoxTestBase)):
...
Args:
@@ -445,5 +445,5 @@ def CoopTestCase(other_base_class):
(other_base_class.__metaclass__,
TestGeneratorMetaclass), {})
return metaclass(
- 'CoopTestCase',
- (other_base_class, TestCase), {})
+ 'CoopTestCase',
+ (other_base_class, TestCase), {})
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/api_implementation.cc b/contrib/python/protobuf/py2/google/protobuf/internal/api_implementation.cc
index 2a7f41d2d6..f99ba09602 100644
--- a/contrib/python/protobuf/py2/google/protobuf/internal/api_implementation.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/api_implementation.cc
@@ -69,24 +69,24 @@ static const char* kImplVersionName = "api_version";
static const char* kModuleName = "_api_implementation";
static const char kModuleDocstring[] =
- "_api_implementation is a module that exposes compile-time constants that\n"
- "determine the default API implementation to use for Python proto2.\n"
- "\n"
- "It complements api_implementation.py by setting defaults using "
- "compile-time\n"
- "constants defined in C, such that one can set defaults at compilation\n"
- "(e.g. with blaze flag --copt=-DPYTHON_PROTO2_CPP_IMPL_V2).";
+ "_api_implementation is a module that exposes compile-time constants that\n"
+ "determine the default API implementation to use for Python proto2.\n"
+ "\n"
+ "It complements api_implementation.py by setting defaults using "
+ "compile-time\n"
+ "constants defined in C, such that one can set defaults at compilation\n"
+ "(e.g. with blaze flag --copt=-DPYTHON_PROTO2_CPP_IMPL_V2).";
#if PY_MAJOR_VERSION >= 3
-static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
- kModuleName,
- kModuleDocstring,
- -1,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL};
+static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
+ kModuleName,
+ kModuleDocstring,
+ -1,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL};
#define INITFUNC PyInit__api_implementation
#define INITFUNC_ERRORVAL NULL
#else
@@ -95,32 +95,32 @@ static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
#endif
extern "C" {
-PyMODINIT_FUNC INITFUNC() {
+PyMODINIT_FUNC INITFUNC() {
#if PY_MAJOR_VERSION >= 3
- PyObject* module = PyModule_Create(&_module);
+ PyObject* module = PyModule_Create(&_module);
#else
- PyObject* module = Py_InitModule3(const_cast<char*>(kModuleName), NULL,
- const_cast<char*>(kModuleDocstring));
+ PyObject* module = Py_InitModule3(const_cast<char*>(kModuleName), NULL,
+ const_cast<char*>(kModuleDocstring));
#endif
- if (module == NULL) {
- return INITFUNC_ERRORVAL;
- }
+ if (module == NULL) {
+ return INITFUNC_ERRORVAL;
+ }
- // Adds the module variable "api_version".
- if (PyModule_AddIntConstant(module, const_cast<char*>(kImplVersionName),
- kImplVersion))
+ // Adds the module variable "api_version".
+ if (PyModule_AddIntConstant(module, const_cast<char*>(kImplVersionName),
+ kImplVersion))
#if PY_MAJOR_VERSION < 3
- return;
+ return;
#else
- {
- Py_DECREF(module);
- return NULL;
- }
+ {
+ Py_DECREF(module);
+ return NULL;
+ }
- return module;
+ return module;
#endif
}
-}
+}
} // namespace python
} // namespace protobuf
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/api_implementation.py b/contrib/python/protobuf/py2/google/protobuf/internal/api_implementation.py
index be1af7df6b..a9d37acdd3 100644
--- a/contrib/python/protobuf/py2/google/protobuf/internal/api_implementation.py
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/api_implementation.py
@@ -32,7 +32,7 @@
"""
import os
-import sys
+import sys
import warnings
try:
@@ -60,25 +60,25 @@ if _api_version < 0: # Still unspecified?
raise ImportError('_use_fast_cpp_protos import succeeded but was None')
del _use_fast_cpp_protos
_api_version = 2
- from google.protobuf import use_pure_python
- raise RuntimeError(
- 'Conflicting deps on both :use_fast_cpp_protos and :use_pure_python.\n'
- ' go/build_deps_on_BOTH_use_fast_cpp_protos_AND_use_pure_python\n'
- 'This should be impossible via a link error at build time...')
+ from google.protobuf import use_pure_python
+ raise RuntimeError(
+ 'Conflicting deps on both :use_fast_cpp_protos and :use_pure_python.\n'
+ ' go/build_deps_on_BOTH_use_fast_cpp_protos_AND_use_pure_python\n'
+ 'This should be impossible via a link error at build time...')
except ImportError:
- try:
- # pylint: disable=g-import-not-at-top
- from google.protobuf import use_pure_python
- del use_pure_python # Avoids a pylint error and namespace pollution.
- _api_version = 0
- except ImportError:
- # TODO(b/74017912): It's unsafe to enable :use_fast_cpp_protos by default;
- # it can cause data loss if you have any Python-only extensions to any
- # message passed back and forth with C++ code.
- #
- # TODO(b/17427486): Once that bug is fixed, we want to make both Python 2
- # and Python 3 default to `_api_version = 2` (C++ implementation V2).
- pass
+ try:
+ # pylint: disable=g-import-not-at-top
+ from google.protobuf import use_pure_python
+ del use_pure_python # Avoids a pylint error and namespace pollution.
+ _api_version = 0
+ except ImportError:
+ # TODO(b/74017912): It's unsafe to enable :use_fast_cpp_protos by default;
+ # it can cause data loss if you have any Python-only extensions to any
+ # message passed back and forth with C++ code.
+ #
+ # TODO(b/17427486): Once that bug is fixed, we want to make both Python 2
+ # and Python 3 default to `_api_version = 2` (C++ implementation V2).
+ pass
_default_implementation_type = (
'python' if _api_version <= 0 else 'cpp')
@@ -143,12 +143,12 @@ def Type():
return _implementation_type
-def _SetType(implementation_type):
- """Never use! Only for protobuf benchmark."""
- global _implementation_type
- _implementation_type = implementation_type
-
-
+def _SetType(implementation_type):
+ """Never use! Only for protobuf benchmark."""
+ global _implementation_type
+ _implementation_type = implementation_type
+
+
# See comment on 'Type' above.
def Version():
return _implementation_version
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/containers.py b/contrib/python/protobuf/py2/google/protobuf/internal/containers.py
index 92793490bb..2653a235c3 100644
--- a/contrib/python/protobuf/py2/google/protobuf/internal/containers.py
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/containers.py
@@ -33,21 +33,21 @@
This file defines container classes which represent categories of protocol
buffer field types which need extra maintenance. Currently these categories
are:
-
-- Repeated scalar fields - These are all repeated fields which aren't
+
+- Repeated scalar fields - These are all repeated fields which aren't
composite (e.g. they are of simple types like int32, string, etc).
-- Repeated composite fields - Repeated fields which are composite. This
+- Repeated composite fields - Repeated fields which are composite. This
includes groups and nested messages.
"""
__author__ = 'petar@google.com (Petar Petrov)'
-import sys
+import sys
try:
- # This fallback applies for all versions of Python before 3.3
- import collections.abc as collections_abc
+ # This fallback applies for all versions of Python before 3.3
+ import collections.abc as collections_abc
except ImportError:
- import collections as collections_abc
+ import collections as collections_abc
if sys.version_info[0] < 3:
# We would use collections_abc.MutableMapping all the time, but in Python 2
@@ -231,13 +231,13 @@ class BaseContainer(object):
kwargs['cmp'] = kwargs.pop('sort_function')
self._values.sort(*args, **kwargs)
- def reverse(self):
- self._values.reverse()
-
-
-collections_abc.MutableSequence.register(BaseContainer)
-
+ def reverse(self):
+ self._values.reverse()
+
+collections_abc.MutableSequence.register(BaseContainer)
+
+
class RepeatedScalarFieldContainer(BaseContainer):
"""Simple, type-checked, list-like container for holding repeated scalars."""
@@ -245,13 +245,13 @@ class RepeatedScalarFieldContainer(BaseContainer):
__slots__ = ['_type_checker']
def __init__(self, message_listener, type_checker):
- """Args:
-
- message_listener: A MessageListener implementation. The
- RepeatedScalarFieldContainer will call this object's Modified() method
- when it is modified.
+ """Args:
+
+ message_listener: A MessageListener implementation. The
+ RepeatedScalarFieldContainer will call this object's Modified() method
+ when it is modified.
type_checker: A type_checkers.ValueChecker instance to run on elements
- inserted into this container.
+ inserted into this container.
"""
super(RepeatedScalarFieldContainer, self).__init__(message_listener)
self._type_checker = type_checker
@@ -384,27 +384,27 @@ class RepeatedCompositeFieldContainer(BaseContainer):
self._message_listener.Modified()
return new_element
- def append(self, value):
- """Appends one element by copying the message."""
- new_element = self._message_descriptor._concrete_class()
- new_element._SetListener(self._message_listener)
- new_element.CopyFrom(value)
- self._values.append(new_element)
- if not self._message_listener.dirty:
- self._message_listener.Modified()
-
- def insert(self, key, value):
- """Inserts the item at the specified position by copying."""
- new_element = self._message_descriptor._concrete_class()
- new_element._SetListener(self._message_listener)
- new_element.CopyFrom(value)
- self._values.insert(key, new_element)
- if not self._message_listener.dirty:
- self._message_listener.Modified()
-
+ def append(self, value):
+ """Appends one element by copying the message."""
+ new_element = self._message_descriptor._concrete_class()
+ new_element._SetListener(self._message_listener)
+ new_element.CopyFrom(value)
+ self._values.append(new_element)
+ if not self._message_listener.dirty:
+ self._message_listener.Modified()
+
+ def insert(self, key, value):
+ """Inserts the item at the specified position by copying."""
+ new_element = self._message_descriptor._concrete_class()
+ new_element._SetListener(self._message_listener)
+ new_element.CopyFrom(value)
+ self._values.insert(key, new_element)
+ if not self._message_listener.dirty:
+ self._message_listener.Modified()
+
def extend(self, elem_seq):
"""Extends by appending the given sequence of elements of the same type
-
+
as this one, copying each individual message.
"""
message_class = self._message_descriptor._concrete_class
@@ -576,7 +576,7 @@ class MessageMap(MutableMapping):
self._values = {}
def __getitem__(self, key):
- key = self._key_checker.CheckValue(key)
+ key = self._key_checker.CheckValue(key)
try:
return self._values[key]
except KeyError:
@@ -611,14 +611,14 @@ class MessageMap(MutableMapping):
return default
def __contains__(self, item):
- item = self._key_checker.CheckValue(item)
+ item = self._key_checker.CheckValue(item)
return item in self._values
def __setitem__(self, key, value):
raise ValueError('May not set values directly, call my_map[key].foo = 5')
def __delitem__(self, key):
- key = self._key_checker.CheckValue(key)
+ key = self._key_checker.CheckValue(key)
del self._values[key]
self._message_listener.Modified()
@@ -632,8 +632,8 @@ class MessageMap(MutableMapping):
return repr(self._values)
def MergeFrom(self, other):
- # pylint: disable=protected-access
- for key in other._values:
+ # pylint: disable=protected-access
+ for key in other._values:
# According to documentation: "When parsing from the wire or when merging,
# if there are duplicate map keys the last key seen is used".
if key in self:
@@ -656,130 +656,130 @@ class MessageMap(MutableMapping):
def GetEntryClass(self):
return self._entry_descriptor._concrete_class
-
-
-class _UnknownField(object):
-
- """A parsed unknown field."""
-
- # Disallows assignment to other attributes.
- __slots__ = ['_field_number', '_wire_type', '_data']
-
- def __init__(self, field_number, wire_type, data):
- self._field_number = field_number
- self._wire_type = wire_type
- self._data = data
- return
-
- def __lt__(self, other):
- # pylint: disable=protected-access
- return self._field_number < other._field_number
-
- def __eq__(self, other):
- if self is other:
- return True
- # pylint: disable=protected-access
- return (self._field_number == other._field_number and
- self._wire_type == other._wire_type and
- self._data == other._data)
-
-
-class UnknownFieldRef(object):
-
- def __init__(self, parent, index):
- self._parent = parent
- self._index = index
- return
-
- def _check_valid(self):
- if not self._parent:
- raise ValueError('UnknownField does not exist. '
- 'The parent message might be cleared.')
- if self._index >= len(self._parent):
- raise ValueError('UnknownField does not exist. '
- 'The parent message might be cleared.')
-
- @property
- def field_number(self):
- self._check_valid()
- # pylint: disable=protected-access
- return self._parent._internal_get(self._index)._field_number
-
- @property
- def wire_type(self):
- self._check_valid()
- # pylint: disable=protected-access
- return self._parent._internal_get(self._index)._wire_type
-
- @property
- def data(self):
- self._check_valid()
- # pylint: disable=protected-access
- return self._parent._internal_get(self._index)._data
-
-
-class UnknownFieldSet(object):
-
- """UnknownField container"""
-
- # Disallows assignment to other attributes.
- __slots__ = ['_values']
-
- def __init__(self):
- self._values = []
-
- def __getitem__(self, index):
- if self._values is None:
- raise ValueError('UnknownFields does not exist. '
- 'The parent message might be cleared.')
- size = len(self._values)
- if index < 0:
- index += size
- if index < 0 or index >= size:
- raise IndexError('index %d out of range'.index)
-
- return UnknownFieldRef(self, index)
-
- def _internal_get(self, index):
- return self._values[index]
-
- def __len__(self):
- if self._values is None:
- raise ValueError('UnknownFields does not exist. '
- 'The parent message might be cleared.')
- return len(self._values)
-
- def _add(self, field_number, wire_type, data):
- unknown_field = _UnknownField(field_number, wire_type, data)
- self._values.append(unknown_field)
- return unknown_field
-
- def __iter__(self):
- for i in range(len(self)):
- yield UnknownFieldRef(self, i)
-
- def _extend(self, other):
- if other is None:
- return
- # pylint: disable=protected-access
- self._values.extend(other._values)
-
- def __eq__(self, other):
- if self is other:
- return True
- # Sort unknown fields because their order shouldn't
- # affect equality test.
- values = list(self._values)
- if other is None:
- return not values
- values.sort()
- # pylint: disable=protected-access
- other_values = sorted(other._values)
- return values == other_values
-
- def _clear(self):
- for value in self._values:
- # pylint: disable=protected-access
- if isinstance(value._data, UnknownFieldSet):
- value._data._clear() # pylint: disable=protected-access
- self._values = None
+
+
+class _UnknownField(object):
+
+ """A parsed unknown field."""
+
+ # Disallows assignment to other attributes.
+ __slots__ = ['_field_number', '_wire_type', '_data']
+
+ def __init__(self, field_number, wire_type, data):
+ self._field_number = field_number
+ self._wire_type = wire_type
+ self._data = data
+ return
+
+ def __lt__(self, other):
+ # pylint: disable=protected-access
+ return self._field_number < other._field_number
+
+ def __eq__(self, other):
+ if self is other:
+ return True
+ # pylint: disable=protected-access
+ return (self._field_number == other._field_number and
+ self._wire_type == other._wire_type and
+ self._data == other._data)
+
+
+class UnknownFieldRef(object):
+
+ def __init__(self, parent, index):
+ self._parent = parent
+ self._index = index
+ return
+
+ def _check_valid(self):
+ if not self._parent:
+ raise ValueError('UnknownField does not exist. '
+ 'The parent message might be cleared.')
+ if self._index >= len(self._parent):
+ raise ValueError('UnknownField does not exist. '
+ 'The parent message might be cleared.')
+
+ @property
+ def field_number(self):
+ self._check_valid()
+ # pylint: disable=protected-access
+ return self._parent._internal_get(self._index)._field_number
+
+ @property
+ def wire_type(self):
+ self._check_valid()
+ # pylint: disable=protected-access
+ return self._parent._internal_get(self._index)._wire_type
+
+ @property
+ def data(self):
+ self._check_valid()
+ # pylint: disable=protected-access
+ return self._parent._internal_get(self._index)._data
+
+
+class UnknownFieldSet(object):
+
+ """UnknownField container"""
+
+ # Disallows assignment to other attributes.
+ __slots__ = ['_values']
+
+ def __init__(self):
+ self._values = []
+
+ def __getitem__(self, index):
+ if self._values is None:
+ raise ValueError('UnknownFields does not exist. '
+ 'The parent message might be cleared.')
+ size = len(self._values)
+ if index < 0:
+ index += size
+ if index < 0 or index >= size:
+ raise IndexError('index %d out of range'.index)
+
+ return UnknownFieldRef(self, index)
+
+ def _internal_get(self, index):
+ return self._values[index]
+
+ def __len__(self):
+ if self._values is None:
+ raise ValueError('UnknownFields does not exist. '
+ 'The parent message might be cleared.')
+ return len(self._values)
+
+ def _add(self, field_number, wire_type, data):
+ unknown_field = _UnknownField(field_number, wire_type, data)
+ self._values.append(unknown_field)
+ return unknown_field
+
+ def __iter__(self):
+ for i in range(len(self)):
+ yield UnknownFieldRef(self, i)
+
+ def _extend(self, other):
+ if other is None:
+ return
+ # pylint: disable=protected-access
+ self._values.extend(other._values)
+
+ def __eq__(self, other):
+ if self is other:
+ return True
+ # Sort unknown fields because their order shouldn't
+ # affect equality test.
+ values = list(self._values)
+ if other is None:
+ return not values
+ values.sort()
+ # pylint: disable=protected-access
+ other_values = sorted(other._values)
+ return values == other_values
+
+ def _clear(self):
+ for value in self._values:
+ # pylint: disable=protected-access
+ if isinstance(value._data, UnknownFieldSet):
+ value._data._clear() # pylint: disable=protected-access
+ self._values = None
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/decoder.py b/contrib/python/protobuf/py2/google/protobuf/internal/decoder.py
index 6804986b6e..050f845cce 100644
--- a/contrib/python/protobuf/py2/google/protobuf/internal/decoder.py
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/decoder.py
@@ -81,17 +81,17 @@ we repeatedly read a tag, look up the corresponding decoder, and invoke it.
__author__ = 'kenton@google.com (Kenton Varda)'
import struct
-import sys
+import sys
import six
-_UCS2_MAXUNICODE = 65535
+_UCS2_MAXUNICODE = 65535
if six.PY3:
long = int
-else:
- import re # pylint: disable=g-import-not-at-top
- _SURROGATE_PATTERN = re.compile(six.u(r'[\ud800-\udfff]'))
+else:
+ import re # pylint: disable=g-import-not-at-top
+ _SURROGATE_PATTERN = re.compile(six.u(r'[\ud800-\udfff]'))
-from google.protobuf.internal import containers
+from google.protobuf.internal import containers
from google.protobuf.internal import encoder
from google.protobuf.internal import wire_format
from google.protobuf import message
@@ -172,7 +172,7 @@ _DecodeSignedVarint32 = _SignedVarintDecoder(32, int)
def ReadTag(buffer, pos):
- """Read a tag from the memoryview, and return a (tag_bytes, new_pos) tuple.
+ """Read a tag from the memoryview, and return a (tag_bytes, new_pos) tuple.
We return the raw bytes of the tag rather than decoding them. The raw
bytes can then be used to look up the proper decoder. This effectively allows
@@ -180,23 +180,23 @@ def ReadTag(buffer, pos):
for work that is done in C (searching for a byte string in a hash table).
In a low-level language it would be much cheaper to decode the varint and
use that, but not in Python.
-
- Args:
- buffer: memoryview object of the encoded bytes
- pos: int of the current position to start from
-
- Returns:
- Tuple[bytes, int] of the tag data and new position.
+
+ Args:
+ buffer: memoryview object of the encoded bytes
+ pos: int of the current position to start from
+
+ Returns:
+ Tuple[bytes, int] of the tag data and new position.
"""
start = pos
while six.indexbytes(buffer, pos) & 0x80:
pos += 1
pos += 1
- tag_bytes = buffer[start:pos].tobytes()
- return tag_bytes, pos
-
+ tag_bytes = buffer[start:pos].tobytes()
+ return tag_bytes, pos
+
# --------------------------------------------------------------------
@@ -209,8 +209,8 @@ def _SimpleDecoder(wire_type, decode_value):
_DecodeVarint()
"""
- def SpecificDecoder(field_number, is_repeated, is_packed, key, new_default,
- clear_if_default=False):
+ def SpecificDecoder(field_number, is_repeated, is_packed, key, new_default,
+ clear_if_default=False):
if is_packed:
local_DecodeVarint = _DecodeVarint
def DecodePackedField(buffer, pos, end, message, field_dict):
@@ -250,13 +250,13 @@ def _SimpleDecoder(wire_type, decode_value):
return DecodeRepeatedField
else:
def DecodeField(buffer, pos, end, message, field_dict):
- (new_value, pos) = decode_value(buffer, pos)
+ (new_value, pos) = decode_value(buffer, pos)
if pos > end:
raise _DecodeError('Truncated message.')
- if clear_if_default and not new_value:
- field_dict.pop(key, None)
- else:
- field_dict[key] = new_value
+ if clear_if_default and not new_value:
+ field_dict.pop(key, None)
+ else:
+ field_dict[key] = new_value
return pos
return DecodeField
@@ -312,20 +312,20 @@ def _FloatDecoder():
local_unpack = struct.unpack
def InnerDecode(buffer, pos):
- """Decode serialized float to a float and new position.
-
- Args:
- buffer: memoryview of the serialized bytes
- pos: int, position in the memory view to start at.
-
- Returns:
- Tuple[float, int] of the deserialized float value and new position
- in the serialized data.
- """
+ """Decode serialized float to a float and new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes
+ pos: int, position in the memory view to start at.
+
+ Returns:
+ Tuple[float, int] of the deserialized float value and new position
+ in the serialized data.
+ """
# We expect a 32-bit value in little-endian byte order. Bit 1 is the sign
# bit, bits 2-9 represent the exponent, and bits 10-32 are the significand.
new_pos = pos + 4
- float_bytes = buffer[pos:new_pos].tobytes()
+ float_bytes = buffer[pos:new_pos].tobytes()
# If this value has all its exponent bits set, then it's non-finite.
# In Python 2.4, struct.unpack will convert it to a finite 64-bit value.
@@ -356,20 +356,20 @@ def _DoubleDecoder():
local_unpack = struct.unpack
def InnerDecode(buffer, pos):
- """Decode serialized double to a double and new position.
-
- Args:
- buffer: memoryview of the serialized bytes.
- pos: int, position in the memory view to start at.
-
- Returns:
- Tuple[float, int] of the decoded double value and new position
- in the serialized data.
- """
+ """Decode serialized double to a double and new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes.
+ pos: int, position in the memory view to start at.
+
+ Returns:
+ Tuple[float, int] of the decoded double value and new position
+ in the serialized data.
+ """
# We expect a 64-bit value in little-endian byte order. Bit 1 is the sign
# bit, bits 2-12 represent the exponent, and bits 13-64 are the significand.
new_pos = pos + 8
- double_bytes = buffer[pos:new_pos].tobytes()
+ double_bytes = buffer[pos:new_pos].tobytes()
# If this value has all its exponent bits set and at least one significand
# bit set, it's not a number. In Python 2.4, struct.unpack will treat it
@@ -387,25 +387,25 @@ def _DoubleDecoder():
return _SimpleDecoder(wire_format.WIRETYPE_FIXED64, InnerDecode)
-def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
- clear_if_default=False):
- """Returns a decoder for enum field."""
+def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
+ clear_if_default=False):
+ """Returns a decoder for enum field."""
enum_type = key.enum_type
if is_packed:
local_DecodeVarint = _DecodeVarint
def DecodePackedField(buffer, pos, end, message, field_dict):
- """Decode serialized packed enum to its value and a new position.
-
- Args:
- buffer: memoryview of the serialized bytes.
- pos: int, position in the memory view to start at.
- end: int, end position of serialized data
- message: Message object to store unknown fields in
- field_dict: Map[Descriptor, Any] to store decoded values in.
-
- Returns:
- int, new position in serialized data.
- """
+ """Decode serialized packed enum to its value and a new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes.
+ pos: int, position in the memory view to start at.
+ end: int, end position of serialized data
+ message: Message object to store unknown fields in
+ field_dict: Map[Descriptor, Any] to store decoded values in.
+
+ Returns:
+ int, new position in serialized data.
+ """
value = field_dict.get(key)
if value is None:
value = field_dict.setdefault(key, new_default(message))
@@ -416,7 +416,7 @@ def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
while pos < endpoint:
value_start_pos = pos
(element, pos) = _DecodeSignedVarint32(buffer, pos)
- # pylint: disable=protected-access
+ # pylint: disable=protected-access
if element in enum_type.values_by_number:
value.append(element)
else:
@@ -424,22 +424,22 @@ def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
message._unknown_fields = []
tag_bytes = encoder.TagBytes(field_number,
wire_format.WIRETYPE_VARINT)
-
+
message._unknown_fields.append(
- (tag_bytes, buffer[value_start_pos:pos].tobytes()))
- if message._unknown_field_set is None:
- message._unknown_field_set = containers.UnknownFieldSet()
- message._unknown_field_set._add(
- field_number, wire_format.WIRETYPE_VARINT, element)
- # pylint: enable=protected-access
+ (tag_bytes, buffer[value_start_pos:pos].tobytes()))
+ if message._unknown_field_set is None:
+ message._unknown_field_set = containers.UnknownFieldSet()
+ message._unknown_field_set._add(
+ field_number, wire_format.WIRETYPE_VARINT, element)
+ # pylint: enable=protected-access
if pos > endpoint:
if element in enum_type.values_by_number:
del value[-1] # Discard corrupt value.
else:
del message._unknown_fields[-1]
- # pylint: disable=protected-access
- del message._unknown_field_set._values[-1]
- # pylint: enable=protected-access
+ # pylint: disable=protected-access
+ del message._unknown_field_set._values[-1]
+ # pylint: enable=protected-access
raise _DecodeError('Packed element was truncated.')
return pos
return DecodePackedField
@@ -447,36 +447,36 @@ def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
tag_bytes = encoder.TagBytes(field_number, wire_format.WIRETYPE_VARINT)
tag_len = len(tag_bytes)
def DecodeRepeatedField(buffer, pos, end, message, field_dict):
- """Decode serialized repeated enum to its value and a new position.
-
- Args:
- buffer: memoryview of the serialized bytes.
- pos: int, position in the memory view to start at.
- end: int, end position of serialized data
- message: Message object to store unknown fields in
- field_dict: Map[Descriptor, Any] to store decoded values in.
-
- Returns:
- int, new position in serialized data.
- """
+ """Decode serialized repeated enum to its value and a new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes.
+ pos: int, position in the memory view to start at.
+ end: int, end position of serialized data
+ message: Message object to store unknown fields in
+ field_dict: Map[Descriptor, Any] to store decoded values in.
+
+ Returns:
+ int, new position in serialized data.
+ """
value = field_dict.get(key)
if value is None:
value = field_dict.setdefault(key, new_default(message))
while 1:
(element, new_pos) = _DecodeSignedVarint32(buffer, pos)
- # pylint: disable=protected-access
+ # pylint: disable=protected-access
if element in enum_type.values_by_number:
value.append(element)
else:
if not message._unknown_fields:
message._unknown_fields = []
message._unknown_fields.append(
- (tag_bytes, buffer[pos:new_pos].tobytes()))
- if message._unknown_field_set is None:
- message._unknown_field_set = containers.UnknownFieldSet()
- message._unknown_field_set._add(
- field_number, wire_format.WIRETYPE_VARINT, element)
- # pylint: enable=protected-access
+ (tag_bytes, buffer[pos:new_pos].tobytes()))
+ if message._unknown_field_set is None:
+ message._unknown_field_set = containers.UnknownFieldSet()
+ message._unknown_field_set._add(
+ field_number, wire_format.WIRETYPE_VARINT, element)
+ # pylint: enable=protected-access
# Predict that the next tag is another copy of the same repeated
# field.
pos = new_pos + tag_len
@@ -488,26 +488,26 @@ def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
return DecodeRepeatedField
else:
def DecodeField(buffer, pos, end, message, field_dict):
- """Decode serialized repeated enum to its value and a new position.
-
- Args:
- buffer: memoryview of the serialized bytes.
- pos: int, position in the memory view to start at.
- end: int, end position of serialized data
- message: Message object to store unknown fields in
- field_dict: Map[Descriptor, Any] to store decoded values in.
-
- Returns:
- int, new position in serialized data.
- """
+ """Decode serialized repeated enum to its value and a new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes.
+ pos: int, position in the memory view to start at.
+ end: int, end position of serialized data
+ message: Message object to store unknown fields in
+ field_dict: Map[Descriptor, Any] to store decoded values in.
+
+ Returns:
+ int, new position in serialized data.
+ """
value_start_pos = pos
(enum_value, pos) = _DecodeSignedVarint32(buffer, pos)
if pos > end:
raise _DecodeError('Truncated message.')
- if clear_if_default and not enum_value:
- field_dict.pop(key, None)
- return pos
- # pylint: disable=protected-access
+ if clear_if_default and not enum_value:
+ field_dict.pop(key, None)
+ return pos
+ # pylint: disable=protected-access
if enum_value in enum_type.values_by_number:
field_dict[key] = enum_value
else:
@@ -516,12 +516,12 @@ def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
tag_bytes = encoder.TagBytes(field_number,
wire_format.WIRETYPE_VARINT)
message._unknown_fields.append(
- (tag_bytes, buffer[value_start_pos:pos].tobytes()))
- if message._unknown_field_set is None:
- message._unknown_field_set = containers.UnknownFieldSet()
- message._unknown_field_set._add(
- field_number, wire_format.WIRETYPE_VARINT, enum_value)
- # pylint: enable=protected-access
+ (tag_bytes, buffer[value_start_pos:pos].tobytes()))
+ if message._unknown_field_set is None:
+ message._unknown_field_set = containers.UnknownFieldSet()
+ message._unknown_field_set._add(
+ field_number, wire_format.WIRETYPE_VARINT, enum_value)
+ # pylint: enable=protected-access
return pos
return DecodeField
@@ -558,34 +558,34 @@ BoolDecoder = _ModifiedDecoder(
wire_format.WIRETYPE_VARINT, _DecodeVarint, bool)
-def StringDecoder(field_number, is_repeated, is_packed, key, new_default,
- is_strict_utf8=False, clear_if_default=False):
+def StringDecoder(field_number, is_repeated, is_packed, key, new_default,
+ is_strict_utf8=False, clear_if_default=False):
"""Returns a decoder for a string field."""
local_DecodeVarint = _DecodeVarint
local_unicode = six.text_type
- def _ConvertToUnicode(memview):
- """Convert byte to unicode."""
- byte_str = memview.tobytes()
+ def _ConvertToUnicode(memview):
+ """Convert byte to unicode."""
+ byte_str = memview.tobytes()
try:
- value = local_unicode(byte_str, 'utf-8')
+ value = local_unicode(byte_str, 'utf-8')
except UnicodeDecodeError as e:
# add more information to the error message and re-raise it.
e.reason = '%s in field: %s' % (e, key.full_name)
raise
- if is_strict_utf8 and six.PY2 and sys.maxunicode > _UCS2_MAXUNICODE:
- # Only do the check for python2 ucs4 when is_strict_utf8 enabled
- if _SURROGATE_PATTERN.search(value):
- reason = ('String field %s contains invalid UTF-8 data when parsing'
- 'a protocol buffer: surrogates not allowed. Use'
- 'the bytes type if you intend to send raw bytes.') % (
- key.full_name)
- raise message.DecodeError(reason)
-
- return value
-
+ if is_strict_utf8 and six.PY2 and sys.maxunicode > _UCS2_MAXUNICODE:
+ # Only do the check for python2 ucs4 when is_strict_utf8 enabled
+ if _SURROGATE_PATTERN.search(value):
+ reason = ('String field %s contains invalid UTF-8 data when parsing'
+ 'a protocol buffer: surrogates not allowed. Use'
+ 'the bytes type if you intend to send raw bytes.') % (
+ key.full_name)
+ raise message.DecodeError(reason)
+
+ return value
+
assert not is_packed
if is_repeated:
tag_bytes = encoder.TagBytes(field_number,
@@ -613,16 +613,16 @@ def StringDecoder(field_number, is_repeated, is_packed, key, new_default,
new_pos = pos + size
if new_pos > end:
raise _DecodeError('Truncated string.')
- if clear_if_default and not size:
- field_dict.pop(key, None)
- else:
- field_dict[key] = _ConvertToUnicode(buffer[pos:new_pos])
+ if clear_if_default and not size:
+ field_dict.pop(key, None)
+ else:
+ field_dict[key] = _ConvertToUnicode(buffer[pos:new_pos])
return new_pos
return DecodeField
-def BytesDecoder(field_number, is_repeated, is_packed, key, new_default,
- clear_if_default=False):
+def BytesDecoder(field_number, is_repeated, is_packed, key, new_default,
+ clear_if_default=False):
"""Returns a decoder for a bytes field."""
local_DecodeVarint = _DecodeVarint
@@ -641,7 +641,7 @@ def BytesDecoder(field_number, is_repeated, is_packed, key, new_default,
new_pos = pos + size
if new_pos > end:
raise _DecodeError('Truncated string.')
- value.append(buffer[pos:new_pos].tobytes())
+ value.append(buffer[pos:new_pos].tobytes())
# Predict that the next tag is another copy of the same repeated field.
pos = new_pos + tag_len
if buffer[new_pos:pos] != tag_bytes or new_pos == end:
@@ -654,10 +654,10 @@ def BytesDecoder(field_number, is_repeated, is_packed, key, new_default,
new_pos = pos + size
if new_pos > end:
raise _DecodeError('Truncated string.')
- if clear_if_default and not size:
- field_dict.pop(key, None)
- else:
- field_dict[key] = buffer[pos:new_pos].tobytes()
+ if clear_if_default and not size:
+ field_dict.pop(key, None)
+ else:
+ field_dict[key] = buffer[pos:new_pos].tobytes()
return new_pos
return DecodeField
@@ -786,18 +786,18 @@ def MessageSetItemDecoder(descriptor):
local_SkipField = SkipField
def DecodeItem(buffer, pos, end, message, field_dict):
- """Decode serialized message set to its value and new position.
-
- Args:
- buffer: memoryview of the serialized bytes.
- pos: int, position in the memory view to start at.
- end: int, end position of serialized data
- message: Message object to store unknown fields in
- field_dict: Map[Descriptor, Any] to store decoded values in.
-
- Returns:
- int, new position in serialized data.
- """
+ """Decode serialized message set to its value and new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes.
+ pos: int, position in the memory view to start at.
+ end: int, end position of serialized data
+ message: Message object to store unknown fields in
+ field_dict: Map[Descriptor, Any] to store decoded values in.
+
+ Returns:
+ int, new position in serialized data.
+ """
message_set_item_start = pos
type_id = -1
message_start = -1
@@ -828,16 +828,16 @@ def MessageSetItemDecoder(descriptor):
raise _DecodeError('MessageSet item missing message.')
extension = message.Extensions._FindExtensionByNumber(type_id)
- # pylint: disable=protected-access
+ # pylint: disable=protected-access
if extension is not None:
value = field_dict.get(extension)
if value is None:
- message_type = extension.message_type
- if not hasattr(message_type, '_concrete_class'):
- # pylint: disable=protected-access
- message._FACTORY.GetPrototype(message_type)
+ message_type = extension.message_type
+ if not hasattr(message_type, '_concrete_class'):
+ # pylint: disable=protected-access
+ message._FACTORY.GetPrototype(message_type)
value = field_dict.setdefault(
- extension, message_type._concrete_class())
+ extension, message_type._concrete_class())
if value._InternalParse(buffer, message_start,message_end) != message_end:
# The only reason _InternalParse would return early is if it encountered
# an end-group tag.
@@ -845,15 +845,15 @@ def MessageSetItemDecoder(descriptor):
else:
if not message._unknown_fields:
message._unknown_fields = []
- message._unknown_fields.append(
- (MESSAGE_SET_ITEM_TAG, buffer[message_set_item_start:pos].tobytes()))
- if message._unknown_field_set is None:
- message._unknown_field_set = containers.UnknownFieldSet()
- message._unknown_field_set._add(
- type_id,
- wire_format.WIRETYPE_LENGTH_DELIMITED,
- buffer[message_start:message_end].tobytes())
- # pylint: enable=protected-access
+ message._unknown_fields.append(
+ (MESSAGE_SET_ITEM_TAG, buffer[message_set_item_start:pos].tobytes()))
+ if message._unknown_field_set is None:
+ message._unknown_field_set = containers.UnknownFieldSet()
+ message._unknown_field_set._add(
+ type_id,
+ wire_format.WIRETYPE_LENGTH_DELIMITED,
+ buffer[message_start:message_end].tobytes())
+ # pylint: enable=protected-access
return pos
@@ -891,7 +891,7 @@ def MapDecoder(field_descriptor, new_default, is_message_map):
raise _DecodeError('Unexpected end-group tag.')
if is_message_map:
- value[submsg.key].CopyFrom(submsg.value)
+ value[submsg.key].CopyFrom(submsg.value)
else:
value[submsg.key] = submsg.value
@@ -912,7 +912,7 @@ def _SkipVarint(buffer, pos, end):
# Previously ord(buffer[pos]) raised IndexError when pos is out of range.
# With this code, ord(b'') raises TypeError. Both are handled in
# python_message.py to generate a 'Truncated message' error.
- while ord(buffer[pos:pos+1].tobytes()) & 0x80:
+ while ord(buffer[pos:pos+1].tobytes()) & 0x80:
pos += 1
pos += 1
if pos > end:
@@ -927,13 +927,13 @@ def _SkipFixed64(buffer, pos, end):
raise _DecodeError('Truncated message.')
return pos
-
-def _DecodeFixed64(buffer, pos):
- """Decode a fixed64."""
- new_pos = pos + 8
- return (struct.unpack('<Q', buffer[pos:new_pos])[0], new_pos)
-
-
+
+def _DecodeFixed64(buffer, pos):
+ """Decode a fixed64."""
+ new_pos = pos + 8
+ return (struct.unpack('<Q', buffer[pos:new_pos])[0], new_pos)
+
+
def _SkipLengthDelimited(buffer, pos, end):
"""Skip a length-delimited value. Returns the new position."""
@@ -943,7 +943,7 @@ def _SkipLengthDelimited(buffer, pos, end):
raise _DecodeError('Truncated message.')
return pos
-
+
def _SkipGroup(buffer, pos, end):
"""Skip sub-group. Returns the new position."""
@@ -954,53 +954,53 @@ def _SkipGroup(buffer, pos, end):
return pos
pos = new_pos
-
-def _DecodeUnknownFieldSet(buffer, pos, end_pos=None):
- """Decode UnknownFieldSet. Returns the UnknownFieldSet and new position."""
-
- unknown_field_set = containers.UnknownFieldSet()
- while end_pos is None or pos < end_pos:
- (tag_bytes, pos) = ReadTag(buffer, pos)
- (tag, _) = _DecodeVarint(tag_bytes, 0)
- field_number, wire_type = wire_format.UnpackTag(tag)
- if wire_type == wire_format.WIRETYPE_END_GROUP:
- break
- (data, pos) = _DecodeUnknownField(buffer, pos, wire_type)
- # pylint: disable=protected-access
- unknown_field_set._add(field_number, wire_type, data)
-
- return (unknown_field_set, pos)
-
-
-def _DecodeUnknownField(buffer, pos, wire_type):
- """Decode a unknown field. Returns the UnknownField and new position."""
-
- if wire_type == wire_format.WIRETYPE_VARINT:
- (data, pos) = _DecodeVarint(buffer, pos)
- elif wire_type == wire_format.WIRETYPE_FIXED64:
- (data, pos) = _DecodeFixed64(buffer, pos)
- elif wire_type == wire_format.WIRETYPE_FIXED32:
- (data, pos) = _DecodeFixed32(buffer, pos)
- elif wire_type == wire_format.WIRETYPE_LENGTH_DELIMITED:
- (size, pos) = _DecodeVarint(buffer, pos)
- data = buffer[pos:pos+size].tobytes()
- pos += size
- elif wire_type == wire_format.WIRETYPE_START_GROUP:
- (data, pos) = _DecodeUnknownFieldSet(buffer, pos)
- elif wire_type == wire_format.WIRETYPE_END_GROUP:
- return (0, -1)
- else:
- raise _DecodeError('Wrong wire type in tag.')
-
- return (data, pos)
-
-
+
+def _DecodeUnknownFieldSet(buffer, pos, end_pos=None):
+ """Decode UnknownFieldSet. Returns the UnknownFieldSet and new position."""
+
+ unknown_field_set = containers.UnknownFieldSet()
+ while end_pos is None or pos < end_pos:
+ (tag_bytes, pos) = ReadTag(buffer, pos)
+ (tag, _) = _DecodeVarint(tag_bytes, 0)
+ field_number, wire_type = wire_format.UnpackTag(tag)
+ if wire_type == wire_format.WIRETYPE_END_GROUP:
+ break
+ (data, pos) = _DecodeUnknownField(buffer, pos, wire_type)
+ # pylint: disable=protected-access
+ unknown_field_set._add(field_number, wire_type, data)
+
+ return (unknown_field_set, pos)
+
+
+def _DecodeUnknownField(buffer, pos, wire_type):
+ """Decode a unknown field. Returns the UnknownField and new position."""
+
+ if wire_type == wire_format.WIRETYPE_VARINT:
+ (data, pos) = _DecodeVarint(buffer, pos)
+ elif wire_type == wire_format.WIRETYPE_FIXED64:
+ (data, pos) = _DecodeFixed64(buffer, pos)
+ elif wire_type == wire_format.WIRETYPE_FIXED32:
+ (data, pos) = _DecodeFixed32(buffer, pos)
+ elif wire_type == wire_format.WIRETYPE_LENGTH_DELIMITED:
+ (size, pos) = _DecodeVarint(buffer, pos)
+ data = buffer[pos:pos+size].tobytes()
+ pos += size
+ elif wire_type == wire_format.WIRETYPE_START_GROUP:
+ (data, pos) = _DecodeUnknownFieldSet(buffer, pos)
+ elif wire_type == wire_format.WIRETYPE_END_GROUP:
+ return (0, -1)
+ else:
+ raise _DecodeError('Wrong wire type in tag.')
+
+ return (data, pos)
+
+
def _EndGroup(buffer, pos, end):
"""Skipping an END_GROUP tag returns -1 to tell the parent loop to break."""
return -1
-
+
def _SkipFixed32(buffer, pos, end):
"""Skip a fixed32 value. Returns the new position."""
@@ -1009,14 +1009,14 @@ def _SkipFixed32(buffer, pos, end):
raise _DecodeError('Truncated message.')
return pos
-
-def _DecodeFixed32(buffer, pos):
- """Decode a fixed32."""
-
- new_pos = pos + 4
- return (struct.unpack('<I', buffer[pos:new_pos])[0], new_pos)
-
-
+
+def _DecodeFixed32(buffer, pos):
+ """Decode a fixed32."""
+
+ new_pos = pos + 4
+ return (struct.unpack('<I', buffer[pos:new_pos])[0], new_pos)
+
+
def _RaiseInvalidWireType(buffer, pos, end):
"""Skip function for unknown wire types. Raises an exception."""
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/encoder.py b/contrib/python/protobuf/py2/google/protobuf/internal/encoder.py
index 0c016f3cfa..5392199155 100644
--- a/contrib/python/protobuf/py2/google/protobuf/internal/encoder.py
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/encoder.py
@@ -372,15 +372,15 @@ def MapSizer(field_descriptor, is_message_map):
def _VarintEncoder():
"""Return an encoder for a basic varint value (does not include tag)."""
- local_int2byte = six.int2byte
- def EncodeVarint(write, value, unused_deterministic=None):
+ local_int2byte = six.int2byte
+ def EncodeVarint(write, value, unused_deterministic=None):
bits = value & 0x7f
value >>= 7
while value:
- write(local_int2byte(0x80|bits))
+ write(local_int2byte(0x80|bits))
bits = value & 0x7f
value >>= 7
- return write(local_int2byte(bits))
+ return write(local_int2byte(bits))
return EncodeVarint
@@ -389,17 +389,17 @@ def _SignedVarintEncoder():
"""Return an encoder for a basic signed varint value (does not include
tag)."""
- local_int2byte = six.int2byte
- def EncodeSignedVarint(write, value, unused_deterministic=None):
+ local_int2byte = six.int2byte
+ def EncodeSignedVarint(write, value, unused_deterministic=None):
if value < 0:
value += (1 << 64)
bits = value & 0x7f
value >>= 7
while value:
- write(local_int2byte(0x80|bits))
+ write(local_int2byte(0x80|bits))
bits = value & 0x7f
value >>= 7
- return write(local_int2byte(bits))
+ return write(local_int2byte(bits))
return EncodeSignedVarint
@@ -420,8 +420,8 @@ def _VarintBytes(value):
def TagBytes(field_number, wire_type):
"""Encode the given tag and return the bytes. Only called at startup."""
- return six.binary_type(
- _VarintBytes(wire_format.PackTag(field_number, wire_type)))
+ return six.binary_type(
+ _VarintBytes(wire_format.PackTag(field_number, wire_type)))
# --------------------------------------------------------------------
# As with sizers (see above), we have a number of common encoder
@@ -526,14 +526,14 @@ def _StructPackEncoder(wire_type, format):
return EncodePackedField
elif is_repeated:
tag_bytes = TagBytes(field_number, wire_type)
- def EncodeRepeatedField(write, value, unused_deterministic=None):
+ def EncodeRepeatedField(write, value, unused_deterministic=None):
for element in value:
write(tag_bytes)
write(local_struct_pack(format, element))
return EncodeRepeatedField
else:
tag_bytes = TagBytes(field_number, wire_type)
- def EncodeField(write, value, unused_deterministic=None):
+ def EncodeField(write, value, unused_deterministic=None):
write(tag_bytes)
return write(local_struct_pack(format, value))
return EncodeField
@@ -597,7 +597,7 @@ def _FloatingPointEncoder(wire_type, format):
return EncodePackedField
elif is_repeated:
tag_bytes = TagBytes(field_number, wire_type)
- def EncodeRepeatedField(write, value, unused_deterministic=None):
+ def EncodeRepeatedField(write, value, unused_deterministic=None):
for element in value:
write(tag_bytes)
try:
@@ -607,7 +607,7 @@ def _FloatingPointEncoder(wire_type, format):
return EncodeRepeatedField
else:
tag_bytes = TagBytes(field_number, wire_type)
- def EncodeField(write, value, unused_deterministic=None):
+ def EncodeField(write, value, unused_deterministic=None):
write(tag_bytes)
try:
write(local_struct_pack(format, value))
@@ -664,7 +664,7 @@ def BoolEncoder(field_number, is_repeated, is_packed):
return EncodePackedField
elif is_repeated:
tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
- def EncodeRepeatedField(write, value, unused_deterministic=None):
+ def EncodeRepeatedField(write, value, unused_deterministic=None):
for element in value:
write(tag_bytes)
if element:
@@ -674,7 +674,7 @@ def BoolEncoder(field_number, is_repeated, is_packed):
return EncodeRepeatedField
else:
tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
- def EncodeField(write, value, unused_deterministic=None):
+ def EncodeField(write, value, unused_deterministic=None):
write(tag_bytes)
if value:
return write(true_byte)
@@ -822,7 +822,7 @@ def MapEncoder(field_descriptor):
encode_message = MessageEncoder(field_descriptor.number, False, False)
def EncodeField(write, value, deterministic):
- value_keys = sorted(value.keys()) if deterministic else value
+ value_keys = sorted(value.keys()) if deterministic else value
for key in value_keys:
entry_msg = message_type._concrete_class(key=key, value=value[key])
encode_message(write, entry_msg, deterministic)
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/enum_type_wrapper.py b/contrib/python/protobuf/py2/google/protobuf/internal/enum_type_wrapper.py
index 9ae0066584..d5cbf56bab 100644
--- a/contrib/python/protobuf/py2/google/protobuf/internal/enum_type_wrapper.py
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/enum_type_wrapper.py
@@ -37,9 +37,9 @@ on proto classes. For usage, see:
__author__ = 'rabsatt@google.com (Kevin Rabsatt)'
-import six
-
+import six
+
class EnumTypeWrapper(object):
"""A utility for finding the names of enum values."""
@@ -48,38 +48,38 @@ class EnumTypeWrapper(object):
def __init__(self, enum_type):
"""Inits EnumTypeWrapper with an EnumDescriptor."""
self._enum_type = enum_type
- self.DESCRIPTOR = enum_type # pylint: disable=invalid-name
+ self.DESCRIPTOR = enum_type # pylint: disable=invalid-name
- def Name(self, number): # pylint: disable=invalid-name
+ def Name(self, number): # pylint: disable=invalid-name
"""Returns a string containing the name of an enum value."""
- try:
+ try:
return self._enum_type.values_by_number[number].name
- except KeyError:
- pass # fall out to break exception chaining
-
- if not isinstance(number, six.integer_types):
- raise TypeError(
- 'Enum value for {} must be an int, but got {} {!r}.'.format(
- self._enum_type.name, type(number), number))
- else:
- # repr here to handle the odd case when you pass in a boolean.
- raise ValueError('Enum {} has no name defined for value {!r}'.format(
- self._enum_type.name, number))
-
- def Value(self, name): # pylint: disable=invalid-name
- """Returns the value corresponding to the given enum name."""
- try:
+ except KeyError:
+ pass # fall out to break exception chaining
+
+ if not isinstance(number, six.integer_types):
+ raise TypeError(
+ 'Enum value for {} must be an int, but got {} {!r}.'.format(
+ self._enum_type.name, type(number), number))
+ else:
+ # repr here to handle the odd case when you pass in a boolean.
+ raise ValueError('Enum {} has no name defined for value {!r}'.format(
+ self._enum_type.name, number))
+
+ def Value(self, name): # pylint: disable=invalid-name
+ """Returns the value corresponding to the given enum name."""
+ try:
return self._enum_type.values_by_name[name].number
- except KeyError:
- pass # fall out to break exception chaining
- raise ValueError('Enum {} has no value defined for name {!r}'.format(
+ except KeyError:
+ pass # fall out to break exception chaining
+ raise ValueError('Enum {} has no value defined for name {!r}'.format(
self._enum_type.name, name))
def keys(self):
"""Return a list of the string names in the enum.
- Returns:
- A list of strs, in the order they were defined in the .proto file.
+ Returns:
+ A list of strs, in the order they were defined in the .proto file.
"""
return [value_descriptor.name
@@ -88,8 +88,8 @@ class EnumTypeWrapper(object):
def values(self):
"""Return a list of the integer values in the enum.
- Returns:
- A list of ints, in the order they were defined in the .proto file.
+ Returns:
+ A list of ints, in the order they were defined in the .proto file.
"""
return [value_descriptor.number
@@ -98,20 +98,20 @@ class EnumTypeWrapper(object):
def items(self):
"""Return a list of the (name, value) pairs of the enum.
- Returns:
- A list of (str, int) pairs, in the order they were defined
- in the .proto file.
+ Returns:
+ A list of (str, int) pairs, in the order they were defined
+ in the .proto file.
"""
return [(value_descriptor.name, value_descriptor.number)
for value_descriptor in self._enum_type.values]
def __getattr__(self, name):
- """Returns the value corresponding to the given enum name."""
- try:
- return super(
- EnumTypeWrapper,
- self).__getattribute__('_enum_type').values_by_name[name].number
- except KeyError:
- pass # fall out to break exception chaining
- raise AttributeError('Enum {} has no value defined for name {!r}'.format(
- self._enum_type.name, name))
+ """Returns the value corresponding to the given enum name."""
+ try:
+ return super(
+ EnumTypeWrapper,
+ self).__getattribute__('_enum_type').values_by_name[name].number
+ except KeyError:
+ pass # fall out to break exception chaining
+ raise AttributeError('Enum {} has no value defined for name {!r}'.format(
+ self._enum_type.name, name))
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/extension_dict.py b/contrib/python/protobuf/py2/google/protobuf/internal/extension_dict.py
index b346cf283e..799e15600e 100644
--- a/contrib/python/protobuf/py2/google/protobuf/internal/extension_dict.py
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/extension_dict.py
@@ -1,213 +1,213 @@
-# Protocol Buffers - Google's data interchange format
-# Copyright 2008 Google Inc. All rights reserved.
-# https://developers.google.com/protocol-buffers/
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-# * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-"""Contains _ExtensionDict class to represent extensions.
-"""
-
-from google.protobuf.internal import type_checkers
-from google.protobuf.descriptor import FieldDescriptor
-
-
-def _VerifyExtensionHandle(message, extension_handle):
- """Verify that the given extension handle is valid."""
-
- if not isinstance(extension_handle, FieldDescriptor):
- raise KeyError('HasExtension() expects an extension handle, got: %s' %
- extension_handle)
-
- if not extension_handle.is_extension:
- raise KeyError('"%s" is not an extension.' % extension_handle.full_name)
-
- if not extension_handle.containing_type:
- raise KeyError('"%s" is missing a containing_type.'
- % extension_handle.full_name)
-
- if extension_handle.containing_type is not message.DESCRIPTOR:
- raise KeyError('Extension "%s" extends message type "%s", but this '
- 'message is of type "%s".' %
- (extension_handle.full_name,
- extension_handle.containing_type.full_name,
- message.DESCRIPTOR.full_name))
-
-
-# TODO(robinson): Unify error handling of "unknown extension" crap.
-# TODO(robinson): Support iteritems()-style iteration over all
-# extensions with the "has" bits turned on?
-class _ExtensionDict(object):
-
- """Dict-like container for Extension fields on proto instances.
-
- Note that in all cases we expect extension handles to be
- FieldDescriptors.
- """
-
- def __init__(self, extended_message):
- """
- Args:
- extended_message: Message instance for which we are the Extensions dict.
- """
- self._extended_message = extended_message
-
- def __getitem__(self, extension_handle):
- """Returns the current value of the given extension handle."""
-
- _VerifyExtensionHandle(self._extended_message, extension_handle)
-
- result = self._extended_message._fields.get(extension_handle)
- if result is not None:
- return result
-
- if extension_handle.label == FieldDescriptor.LABEL_REPEATED:
- result = extension_handle._default_constructor(self._extended_message)
- elif extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
- message_type = extension_handle.message_type
- if not hasattr(message_type, '_concrete_class'):
- # pylint: disable=protected-access
- self._extended_message._FACTORY.GetPrototype(message_type)
- assert getattr(extension_handle.message_type, '_concrete_class', None), (
- 'Uninitialized concrete class found for field %r (message type %r)'
- % (extension_handle.full_name,
- extension_handle.message_type.full_name))
- result = extension_handle.message_type._concrete_class()
- try:
- result._SetListener(self._extended_message._listener_for_children)
- except ReferenceError:
- pass
- else:
- # Singular scalar -- just return the default without inserting into the
- # dict.
- return extension_handle.default_value
-
- # Atomically check if another thread has preempted us and, if not, swap
- # in the new object we just created. If someone has preempted us, we
- # take that object and discard ours.
- # WARNING: We are relying on setdefault() being atomic. This is true
- # in CPython but we haven't investigated others. This warning appears
- # in several other locations in this file.
- result = self._extended_message._fields.setdefault(
- extension_handle, result)
-
- return result
-
- def __eq__(self, other):
- if not isinstance(other, self.__class__):
- return False
-
- my_fields = self._extended_message.ListFields()
- other_fields = other._extended_message.ListFields()
-
- # Get rid of non-extension fields.
- my_fields = [field for field in my_fields if field.is_extension]
- other_fields = [field for field in other_fields if field.is_extension]
-
- return my_fields == other_fields
-
- def __ne__(self, other):
- return not self == other
-
- def __len__(self):
- fields = self._extended_message.ListFields()
- # Get rid of non-extension fields.
- extension_fields = [field for field in fields if field[0].is_extension]
- return len(extension_fields)
-
- def __hash__(self):
- raise TypeError('unhashable object')
-
- # Note that this is only meaningful for non-repeated, scalar extension
- # fields. Note also that we may have to call _Modified() when we do
- # successfully set a field this way, to set any necessary "has" bits in the
- # ancestors of the extended message.
- def __setitem__(self, extension_handle, value):
- """If extension_handle specifies a non-repeated, scalar extension
- field, sets the value of that field.
- """
-
- _VerifyExtensionHandle(self._extended_message, extension_handle)
-
- if (extension_handle.label == FieldDescriptor.LABEL_REPEATED or
- extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE):
- raise TypeError(
- 'Cannot assign to extension "%s" because it is a repeated or '
- 'composite type.' % extension_handle.full_name)
-
- # It's slightly wasteful to lookup the type checker each time,
- # but we expect this to be a vanishingly uncommon case anyway.
- type_checker = type_checkers.GetTypeChecker(extension_handle)
- # pylint: disable=protected-access
- self._extended_message._fields[extension_handle] = (
- type_checker.CheckValue(value))
- self._extended_message._Modified()
-
- def __delitem__(self, extension_handle):
- self._extended_message.ClearExtension(extension_handle)
-
- def _FindExtensionByName(self, name):
- """Tries to find a known extension with the specified name.
-
- Args:
- name: Extension full name.
-
- Returns:
- Extension field descriptor.
- """
- return self._extended_message._extensions_by_name.get(name, None)
-
- def _FindExtensionByNumber(self, number):
- """Tries to find a known extension with the field number.
-
- Args:
- number: Extension field number.
-
- Returns:
- Extension field descriptor.
- """
- return self._extended_message._extensions_by_number.get(number, None)
-
- def __iter__(self):
- # Return a generator over the populated extension fields
- return (f[0] for f in self._extended_message.ListFields()
- if f[0].is_extension)
-
- def __contains__(self, extension_handle):
- _VerifyExtensionHandle(self._extended_message, extension_handle)
-
- if extension_handle not in self._extended_message._fields:
- return False
-
- if extension_handle.label == FieldDescriptor.LABEL_REPEATED:
- return bool(self._extended_message._fields.get(extension_handle))
-
- if extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
- value = self._extended_message._fields.get(extension_handle)
- # pylint: disable=protected-access
- return value is not None and value._is_present_in_parent
-
- return True
+# Protocol Buffers - Google's data interchange format
+# Copyright 2008 Google Inc. All rights reserved.
+# https://developers.google.com/protocol-buffers/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Contains _ExtensionDict class to represent extensions.
+"""
+
+from google.protobuf.internal import type_checkers
+from google.protobuf.descriptor import FieldDescriptor
+
+
+def _VerifyExtensionHandle(message, extension_handle):
+ """Verify that the given extension handle is valid."""
+
+ if not isinstance(extension_handle, FieldDescriptor):
+ raise KeyError('HasExtension() expects an extension handle, got: %s' %
+ extension_handle)
+
+ if not extension_handle.is_extension:
+ raise KeyError('"%s" is not an extension.' % extension_handle.full_name)
+
+ if not extension_handle.containing_type:
+ raise KeyError('"%s" is missing a containing_type.'
+ % extension_handle.full_name)
+
+ if extension_handle.containing_type is not message.DESCRIPTOR:
+ raise KeyError('Extension "%s" extends message type "%s", but this '
+ 'message is of type "%s".' %
+ (extension_handle.full_name,
+ extension_handle.containing_type.full_name,
+ message.DESCRIPTOR.full_name))
+
+
+# TODO(robinson): Unify error handling of "unknown extension" crap.
+# TODO(robinson): Support iteritems()-style iteration over all
+# extensions with the "has" bits turned on?
+class _ExtensionDict(object):
+
+ """Dict-like container for Extension fields on proto instances.
+
+ Note that in all cases we expect extension handles to be
+ FieldDescriptors.
+ """
+
+ def __init__(self, extended_message):
+ """
+ Args:
+ extended_message: Message instance for which we are the Extensions dict.
+ """
+ self._extended_message = extended_message
+
+ def __getitem__(self, extension_handle):
+ """Returns the current value of the given extension handle."""
+
+ _VerifyExtensionHandle(self._extended_message, extension_handle)
+
+ result = self._extended_message._fields.get(extension_handle)
+ if result is not None:
+ return result
+
+ if extension_handle.label == FieldDescriptor.LABEL_REPEATED:
+ result = extension_handle._default_constructor(self._extended_message)
+ elif extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
+ message_type = extension_handle.message_type
+ if not hasattr(message_type, '_concrete_class'):
+ # pylint: disable=protected-access
+ self._extended_message._FACTORY.GetPrototype(message_type)
+ assert getattr(extension_handle.message_type, '_concrete_class', None), (
+ 'Uninitialized concrete class found for field %r (message type %r)'
+ % (extension_handle.full_name,
+ extension_handle.message_type.full_name))
+ result = extension_handle.message_type._concrete_class()
+ try:
+ result._SetListener(self._extended_message._listener_for_children)
+ except ReferenceError:
+ pass
+ else:
+ # Singular scalar -- just return the default without inserting into the
+ # dict.
+ return extension_handle.default_value
+
+ # Atomically check if another thread has preempted us and, if not, swap
+ # in the new object we just created. If someone has preempted us, we
+ # take that object and discard ours.
+ # WARNING: We are relying on setdefault() being atomic. This is true
+ # in CPython but we haven't investigated others. This warning appears
+ # in several other locations in this file.
+ result = self._extended_message._fields.setdefault(
+ extension_handle, result)
+
+ return result
+
+ def __eq__(self, other):
+ if not isinstance(other, self.__class__):
+ return False
+
+ my_fields = self._extended_message.ListFields()
+ other_fields = other._extended_message.ListFields()
+
+ # Get rid of non-extension fields.
+ my_fields = [field for field in my_fields if field.is_extension]
+ other_fields = [field for field in other_fields if field.is_extension]
+
+ return my_fields == other_fields
+
+ def __ne__(self, other):
+ return not self == other
+
+ def __len__(self):
+ fields = self._extended_message.ListFields()
+ # Get rid of non-extension fields.
+ extension_fields = [field for field in fields if field[0].is_extension]
+ return len(extension_fields)
+
+ def __hash__(self):
+ raise TypeError('unhashable object')
+
+ # Note that this is only meaningful for non-repeated, scalar extension
+ # fields. Note also that we may have to call _Modified() when we do
+ # successfully set a field this way, to set any necessary "has" bits in the
+ # ancestors of the extended message.
+ def __setitem__(self, extension_handle, value):
+ """If extension_handle specifies a non-repeated, scalar extension
+ field, sets the value of that field.
+ """
+
+ _VerifyExtensionHandle(self._extended_message, extension_handle)
+
+ if (extension_handle.label == FieldDescriptor.LABEL_REPEATED or
+ extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE):
+ raise TypeError(
+ 'Cannot assign to extension "%s" because it is a repeated or '
+ 'composite type.' % extension_handle.full_name)
+
+ # It's slightly wasteful to lookup the type checker each time,
+ # but we expect this to be a vanishingly uncommon case anyway.
+ type_checker = type_checkers.GetTypeChecker(extension_handle)
+ # pylint: disable=protected-access
+ self._extended_message._fields[extension_handle] = (
+ type_checker.CheckValue(value))
+ self._extended_message._Modified()
+
+ def __delitem__(self, extension_handle):
+ self._extended_message.ClearExtension(extension_handle)
+
+ def _FindExtensionByName(self, name):
+ """Tries to find a known extension with the specified name.
+
+ Args:
+ name: Extension full name.
+
+ Returns:
+ Extension field descriptor.
+ """
+ return self._extended_message._extensions_by_name.get(name, None)
+
+ def _FindExtensionByNumber(self, number):
+ """Tries to find a known extension with the field number.
+
+ Args:
+ number: Extension field number.
+
+ Returns:
+ Extension field descriptor.
+ """
+ return self._extended_message._extensions_by_number.get(number, None)
+
+ def __iter__(self):
+ # Return a generator over the populated extension fields
+ return (f[0] for f in self._extended_message.ListFields()
+ if f[0].is_extension)
+
+ def __contains__(self, extension_handle):
+ _VerifyExtensionHandle(self._extended_message, extension_handle)
+
+ if extension_handle not in self._extended_message._fields:
+ return False
+
+ if extension_handle.label == FieldDescriptor.LABEL_REPEATED:
+ return bool(self._extended_message._fields.get(extension_handle))
+
+ if extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
+ value = self._extended_message._fields.get(extension_handle)
+ # pylint: disable=protected-access
+ return value is not None and value._is_present_in_parent
+
+ return True
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/python_message.py b/contrib/python/protobuf/py2/google/protobuf/internal/python_message.py
index 99d2f078de..0107202581 100644
--- a/contrib/python/protobuf/py2/google/protobuf/internal/python_message.py
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/python_message.py
@@ -56,7 +56,7 @@ import sys
import weakref
import six
-from six.moves import range
+from six.moves import range
# We use "as" to avoid name collisions with variables.
from google.protobuf.internal import api_implementation
@@ -64,7 +64,7 @@ from google.protobuf.internal import containers
from google.protobuf.internal import decoder
from google.protobuf.internal import encoder
from google.protobuf.internal import enum_type_wrapper
-from google.protobuf.internal import extension_dict
+from google.protobuf.internal import extension_dict
from google.protobuf.internal import message_listener as message_listener_mod
from google.protobuf.internal import type_checkers
from google.protobuf.internal import well_known_types
@@ -75,7 +75,7 @@ from google.protobuf import text_format
_FieldDescriptor = descriptor_mod.FieldDescriptor
_AnyFullTypeName = 'google.protobuf.Any'
-_ExtensionDict = extension_dict._ExtensionDict
+_ExtensionDict = extension_dict._ExtensionDict
class GeneratedProtocolMessageType(type):
@@ -124,30 +124,30 @@ class GeneratedProtocolMessageType(type):
Returns:
Newly-allocated class.
-
- Raises:
- RuntimeError: Generated code only work with python cpp extension.
+
+ Raises:
+ RuntimeError: Generated code only work with python cpp extension.
"""
descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY]
-
- if isinstance(descriptor, str):
- raise RuntimeError('The generated code only work with python cpp '
- 'extension, but it is using pure python runtime.')
-
- # If a concrete class already exists for this descriptor, don't try to
- # create another. Doing so will break any messages that already exist with
- # the existing class.
- #
- # The C++ implementation appears to have its own internal `PyMessageFactory`
- # to achieve similar results.
- #
- # This most commonly happens in `text_format.py` when using descriptors from
- # a custom pool; it calls symbol_database.Global().getPrototype() on a
- # descriptor which already has an existing concrete class.
- new_class = getattr(descriptor, '_concrete_class', None)
- if new_class:
- return new_class
-
+
+ if isinstance(descriptor, str):
+ raise RuntimeError('The generated code only work with python cpp '
+ 'extension, but it is using pure python runtime.')
+
+ # If a concrete class already exists for this descriptor, don't try to
+ # create another. Doing so will break any messages that already exist with
+ # the existing class.
+ #
+ # The C++ implementation appears to have its own internal `PyMessageFactory`
+ # to achieve similar results.
+ #
+ # This most commonly happens in `text_format.py` when using descriptors from
+ # a custom pool; it calls symbol_database.Global().getPrototype() on a
+ # descriptor which already has an existing concrete class.
+ new_class = getattr(descriptor, '_concrete_class', None)
+ if new_class:
+ return new_class
+
if descriptor.full_name in well_known_types.WKTBASES:
bases += (well_known_types.WKTBASES[descriptor.full_name],)
_AddClassAttributesForNestedExtensions(descriptor, dictionary)
@@ -175,16 +175,16 @@ class GeneratedProtocolMessageType(type):
type.
"""
descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY]
-
- # If this is an _existing_ class looked up via `_concrete_class` in the
- # __new__ method above, then we don't need to re-initialize anything.
- existing_class = getattr(descriptor, '_concrete_class', None)
- if existing_class:
- assert existing_class is cls, (
- 'Duplicate `GeneratedProtocolMessageType` created for descriptor %r'
- % (descriptor.full_name))
- return
-
+
+ # If this is an _existing_ class looked up via `_concrete_class` in the
+ # __new__ method above, then we don't need to re-initialize anything.
+ existing_class = getattr(descriptor, '_concrete_class', None)
+ if existing_class:
+ assert existing_class is cls, (
+ 'Duplicate `GeneratedProtocolMessageType` created for descriptor %r'
+ % (descriptor.full_name))
+ return
+
cls._decoders_by_tag = {}
if (descriptor.has_options and
descriptor.GetOptions().message_set_wire_format):
@@ -257,7 +257,7 @@ def _AddSlots(message_descriptor, dictionary):
'_cached_byte_size_dirty',
'_fields',
'_unknown_fields',
- '_unknown_field_set',
+ '_unknown_field_set',
'_is_present_in_parent',
'_listener',
'_listener_for_children',
@@ -280,30 +280,30 @@ def _IsMapField(field):
def _IsMessageMapField(field):
- value_type = field.message_type.fields_by_name['value']
+ value_type = field.message_type.fields_by_name['value']
return value_type.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE
-def _IsStrictUtf8Check(field):
- if field.containing_type.syntax != 'proto3':
- return False
- enforce_utf8 = True
- return enforce_utf8
-
-
+def _IsStrictUtf8Check(field):
+ if field.containing_type.syntax != 'proto3':
+ return False
+ enforce_utf8 = True
+ return enforce_utf8
+
+
def _AttachFieldHelpers(cls, field_descriptor):
is_repeated = (field_descriptor.label == _FieldDescriptor.LABEL_REPEATED)
is_packable = (is_repeated and
wire_format.IsTypePackable(field_descriptor.type))
- is_proto3 = field_descriptor.containing_type.syntax == 'proto3'
+ is_proto3 = field_descriptor.containing_type.syntax == 'proto3'
if not is_packable:
is_packed = False
- elif field_descriptor.containing_type.syntax == 'proto2':
+ elif field_descriptor.containing_type.syntax == 'proto2':
is_packed = (field_descriptor.has_options and
field_descriptor.GetOptions().packed)
else:
has_packed_false = (field_descriptor.has_options and
- field_descriptor.GetOptions().HasField('packed') and
+ field_descriptor.GetOptions().HasField('packed') and
field_descriptor.GetOptions().packed == False)
is_packed = not has_packed_false
is_map_entry = _IsMapField(field_descriptor)
@@ -334,12 +334,12 @@ def _AttachFieldHelpers(cls, field_descriptor):
decode_type = _FieldDescriptor.TYPE_INT32
oneof_descriptor = None
- clear_if_default = False
+ clear_if_default = False
if field_descriptor.containing_oneof is not None:
oneof_descriptor = field_descriptor
- elif (is_proto3 and not is_repeated and
- field_descriptor.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE):
- clear_if_default = True
+ elif (is_proto3 and not is_repeated and
+ field_descriptor.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE):
+ clear_if_default = True
if is_map_entry:
is_message_map = _IsMessageMapField(field_descriptor)
@@ -347,22 +347,22 @@ def _AttachFieldHelpers(cls, field_descriptor):
field_decoder = decoder.MapDecoder(
field_descriptor, _GetInitializeDefaultForMap(field_descriptor),
is_message_map)
- elif decode_type == _FieldDescriptor.TYPE_STRING:
- is_strict_utf8_check = _IsStrictUtf8Check(field_descriptor)
- field_decoder = decoder.StringDecoder(
- field_descriptor.number, is_repeated, is_packed,
- field_descriptor, field_descriptor._default_constructor,
- is_strict_utf8_check, clear_if_default)
- elif field_descriptor.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
- field_decoder = type_checkers.TYPE_TO_DECODER[decode_type](
- field_descriptor.number, is_repeated, is_packed,
- field_descriptor, field_descriptor._default_constructor)
+ elif decode_type == _FieldDescriptor.TYPE_STRING:
+ is_strict_utf8_check = _IsStrictUtf8Check(field_descriptor)
+ field_decoder = decoder.StringDecoder(
+ field_descriptor.number, is_repeated, is_packed,
+ field_descriptor, field_descriptor._default_constructor,
+ is_strict_utf8_check, clear_if_default)
+ elif field_descriptor.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+ field_decoder = type_checkers.TYPE_TO_DECODER[decode_type](
+ field_descriptor.number, is_repeated, is_packed,
+ field_descriptor, field_descriptor._default_constructor)
else:
field_decoder = type_checkers.TYPE_TO_DECODER[decode_type](
- field_descriptor.number, is_repeated, is_packed,
- # pylint: disable=protected-access
- field_descriptor, field_descriptor._default_constructor,
- clear_if_default)
+ field_descriptor.number, is_repeated, is_packed,
+ # pylint: disable=protected-access
+ field_descriptor, field_descriptor._default_constructor,
+ clear_if_default)
cls._decoders_by_tag[tag_bytes] = (field_decoder, oneof_descriptor)
@@ -376,8 +376,8 @@ def _AttachFieldHelpers(cls, field_descriptor):
def _AddClassAttributesForNestedExtensions(descriptor, dictionary):
- extensions = descriptor.extensions_by_name
- for extension_name, extension_field in extensions.items():
+ extensions = descriptor.extensions_by_name
+ for extension_name, extension_field in extensions.items():
assert extension_name not in dictionary
dictionary[extension_name] = extension_field
@@ -459,9 +459,9 @@ def _DefaultValueConstructorForField(field):
# _concrete_class may not yet be initialized.
message_type = field.message_type
def MakeSubMessageDefault(message):
- assert getattr(message_type, '_concrete_class', None), (
- 'Uninitialized concrete class found for field %r (message type %r)'
- % (field.full_name, message_type.full_name))
+ assert getattr(message_type, '_concrete_class', None), (
+ 'Uninitialized concrete class found for field %r (message type %r)'
+ % (field.full_name, message_type.full_name))
result = message_type._concrete_class()
result._SetListener(
_OneofListener(message, field)
@@ -517,16 +517,16 @@ def _AddInitMethod(message_descriptor, cls):
# _unknown_fields is () when empty for efficiency, and will be turned into
# a list if fields are added.
self._unknown_fields = ()
- # _unknown_field_set is None when empty for efficiency, and will be
- # turned into UnknownFieldSet struct if fields are added.
- self._unknown_field_set = None # pylint: disable=protected-access
+ # _unknown_field_set is None when empty for efficiency, and will be
+ # turned into UnknownFieldSet struct if fields are added.
+ self._unknown_field_set = None # pylint: disable=protected-access
self._is_present_in_parent = False
self._listener = message_listener_mod.NullMessageListener()
self._listener_for_children = _Listener(self)
for field_name, field_value in kwargs.items():
field = _GetFieldByName(message_descriptor, field_name)
if field is None:
- raise TypeError('%s() got an unexpected keyword argument "%s"' %
+ raise TypeError('%s() got an unexpected keyword argument "%s"' %
(message_descriptor.name, field_name))
if field_value is None:
# field=None is the same as no field at all.
@@ -616,7 +616,7 @@ def _AddPropertiesForField(field, cls):
# handle specially here.
assert _FieldDescriptor.MAX_CPPTYPE == 10
- constant_name = field.name.upper() + '_FIELD_NUMBER'
+ constant_name = field.name.upper() + '_FIELD_NUMBER'
setattr(cls, constant_name, field.number)
if field.label == _FieldDescriptor.LABEL_REPEATED:
@@ -627,18 +627,18 @@ def _AddPropertiesForField(field, cls):
_AddPropertiesForNonRepeatedScalarField(field, cls)
-class _FieldProperty(property):
- __slots__ = ('DESCRIPTOR',)
-
- def __init__(self, descriptor, getter, setter, doc):
- property.__init__(self, getter, setter, doc=doc)
- self.DESCRIPTOR = descriptor
-
-
+class _FieldProperty(property):
+ __slots__ = ('DESCRIPTOR',)
+
+ def __init__(self, descriptor, getter, setter, doc):
+ property.__init__(self, getter, setter, doc=doc)
+ self.DESCRIPTOR = descriptor
+
+
def _AddPropertiesForRepeatedField(field, cls):
"""Adds a public property for a "repeated" protocol message field. Clients
can use this property to get the value of the field, which will be either a
- RepeatedScalarFieldContainer or RepeatedCompositeFieldContainer (see
+ RepeatedScalarFieldContainer or RepeatedCompositeFieldContainer (see
below).
Note that when clients add values to these containers, we perform
@@ -676,7 +676,7 @@ def _AddPropertiesForRepeatedField(field, cls):
'"%s" in protocol message object.' % proto_field_name)
doc = 'Magic attribute generated for "%s" proto field.' % proto_field_name
- setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
+ setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
def _AddPropertiesForNonRepeatedScalarField(field, cls):
@@ -694,7 +694,7 @@ def _AddPropertiesForNonRepeatedScalarField(field, cls):
property_name = _PropertyName(proto_field_name)
type_checker = type_checkers.GetTypeChecker(field)
default_value = field.default_value
- is_proto3 = field.containing_type.syntax == 'proto3'
+ is_proto3 = field.containing_type.syntax == 'proto3'
def getter(self):
# TODO(protobuf-team): This may be broken since there may not be
@@ -709,11 +709,11 @@ def _AddPropertiesForNonRepeatedScalarField(field, cls):
# pylint: disable=protected-access
# Testing the value for truthiness captures all of the proto3 defaults
# (0, 0.0, enum 0, and False).
- try:
- new_value = type_checker.CheckValue(new_value)
- except TypeError as e:
- raise TypeError(
- 'Cannot set %s to %.1024r: %s' % (field.full_name, new_value, e))
+ try:
+ new_value = type_checker.CheckValue(new_value)
+ except TypeError as e:
+ raise TypeError(
+ 'Cannot set %s to %.1024r: %s' % (field.full_name, new_value, e))
if clear_when_set_to_default and not new_value:
self._fields.pop(field, None)
else:
@@ -735,7 +735,7 @@ def _AddPropertiesForNonRepeatedScalarField(field, cls):
# Add a property to encapsulate the getter/setter.
doc = 'Magic attribute generated for "%s" proto field.' % proto_field_name
- setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
+ setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
def _AddPropertiesForNonRepeatedCompositeField(field, cls):
@@ -779,14 +779,14 @@ def _AddPropertiesForNonRepeatedCompositeField(field, cls):
# Add a property to encapsulate the getter.
doc = 'Magic attribute generated for "%s" proto field.' % proto_field_name
- setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
+ setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
def _AddPropertiesForExtensions(descriptor, cls):
"""Adds properties for all fields in this protocol message type."""
- extensions = descriptor.extensions_by_name
- for extension_name, extension_field in extensions.items():
- constant_name = extension_name.upper() + '_FIELD_NUMBER'
+ extensions = descriptor.extensions_by_name
+ for extension_name, extension_field in extensions.items():
+ constant_name = extension_name.upper() + '_FIELD_NUMBER'
setattr(cls, constant_name, extension_field.number)
# TODO(amauryfa): Migrate all users of these attributes to functions like
@@ -802,8 +802,8 @@ def _AddStaticMethods(cls):
def RegisterExtension(extension_handle):
extension_handle.containing_type = cls.DESCRIPTOR
# TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
- # pylint: disable=protected-access
- cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+ # pylint: disable=protected-access
+ cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
_AttachFieldHelpers(cls, extension_handle)
cls.RegisterExtension = staticmethod(RegisterExtension)
@@ -836,16 +836,16 @@ def _AddListFieldsMethod(message_descriptor, cls):
cls.ListFields = ListFields
-_PROTO3_ERROR_TEMPLATE = \
- ('Protocol message %s has no non-repeated submessage field "%s" '
- 'nor marked as optional')
-_PROTO2_ERROR_TEMPLATE = 'Protocol message %s has no non-repeated field "%s"'
+_PROTO3_ERROR_TEMPLATE = \
+ ('Protocol message %s has no non-repeated submessage field "%s" '
+ 'nor marked as optional')
+_PROTO2_ERROR_TEMPLATE = 'Protocol message %s has no non-repeated field "%s"'
def _AddHasFieldMethod(message_descriptor, cls):
"""Helper for _AddMessageMethods()."""
is_proto3 = (message_descriptor.syntax == "proto3")
- error_msg = _PROTO3_ERROR_TEMPLATE if is_proto3 else _PROTO2_ERROR_TEMPLATE
+ error_msg = _PROTO3_ERROR_TEMPLATE if is_proto3 else _PROTO2_ERROR_TEMPLATE
hassable_fields = {}
for field in message_descriptor.fields:
@@ -857,15 +857,15 @@ def _AddHasFieldMethod(message_descriptor, cls):
continue
hassable_fields[field.name] = field
- # Has methods are supported for oneof descriptors.
- for oneof in message_descriptor.oneofs:
- hassable_fields[oneof.name] = oneof
+ # Has methods are supported for oneof descriptors.
+ for oneof in message_descriptor.oneofs:
+ hassable_fields[oneof.name] = oneof
def HasField(self, field_name):
try:
field = hassable_fields[field_name]
except KeyError:
- raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+ raise ValueError(error_msg % (message_descriptor.full_name, field_name))
if isinstance(field, descriptor_mod.OneofDescriptor):
try:
@@ -895,7 +895,7 @@ def _AddClearFieldMethod(message_descriptor, cls):
else:
return
except KeyError:
- raise ValueError('Protocol message %s has no "%s" field.' %
+ raise ValueError('Protocol message %s has no "%s" field.' %
(message_descriptor.name, field_name))
if field in self._fields:
@@ -923,7 +923,7 @@ def _AddClearFieldMethod(message_descriptor, cls):
def _AddClearExtensionMethod(cls):
"""Helper for _AddMessageMethods()."""
def ClearExtension(self, extension_handle):
- extension_dict._VerifyExtensionHandle(self, extension_handle)
+ extension_dict._VerifyExtensionHandle(self, extension_handle)
# Similar to ClearField(), above.
if extension_handle in self._fields:
@@ -935,7 +935,7 @@ def _AddClearExtensionMethod(cls):
def _AddHasExtensionMethod(cls):
"""Helper for _AddMessageMethods()."""
def HasExtension(self, extension_handle):
- extension_dict._VerifyExtensionHandle(self, extension_handle)
+ extension_dict._VerifyExtensionHandle(self, extension_handle)
if extension_handle.label == _FieldDescriptor.LABEL_REPEATED:
raise KeyError('"%s" is repeated.' % extension_handle.full_name)
@@ -1005,8 +1005,8 @@ def _AddEqualsMethod(message_descriptor, cls):
if not self.ListFields() == other.ListFields():
return False
- # TODO(jieluo): Fix UnknownFieldSet to consider MessageSet extensions,
- # then use it for the comparison.
+ # TODO(jieluo): Fix UnknownFieldSet to consider MessageSet extensions,
+ # then use it for the comparison.
unknown_fields = list(self._unknown_fields)
unknown_fields.sort()
other_unknown_fields = list(other._unknown_fields)
@@ -1066,16 +1066,16 @@ def _AddByteSizeMethod(message_descriptor, cls):
return self._cached_byte_size
size = 0
- descriptor = self.DESCRIPTOR
- if descriptor.GetOptions().map_entry:
- # Fields of map entry should always be serialized.
- size = descriptor.fields_by_name['key']._sizer(self.key)
- size += descriptor.fields_by_name['value']._sizer(self.value)
- else:
- for field_descriptor, field_value in self.ListFields():
- size += field_descriptor._sizer(field_value)
- for tag_bytes, value_bytes in self._unknown_fields:
- size += len(tag_bytes) + len(value_bytes)
+ descriptor = self.DESCRIPTOR
+ if descriptor.GetOptions().map_entry:
+ # Fields of map entry should always be serialized.
+ size = descriptor.fields_by_name['key']._sizer(self.key)
+ size += descriptor.fields_by_name['value']._sizer(self.value)
+ else:
+ for field_descriptor, field_value in self.ListFields():
+ size += field_descriptor._sizer(field_value)
+ for tag_bytes, value_bytes in self._unknown_fields:
+ size += len(tag_bytes) + len(value_bytes)
self._cached_byte_size = size
self._cached_byte_size_dirty = False
@@ -1113,27 +1113,27 @@ def _AddSerializePartialToStringMethod(message_descriptor, cls):
api_implementation.IsPythonDefaultSerializationDeterministic())
else:
deterministic = bool(deterministic)
-
- descriptor = self.DESCRIPTOR
- if descriptor.GetOptions().map_entry:
- # Fields of map entry should always be serialized.
- descriptor.fields_by_name['key']._encoder(
- write_bytes, self.key, deterministic)
- descriptor.fields_by_name['value']._encoder(
- write_bytes, self.value, deterministic)
- else:
- for field_descriptor, field_value in self.ListFields():
- field_descriptor._encoder(write_bytes, field_value, deterministic)
- for tag_bytes, value_bytes in self._unknown_fields:
- write_bytes(tag_bytes)
- write_bytes(value_bytes)
+
+ descriptor = self.DESCRIPTOR
+ if descriptor.GetOptions().map_entry:
+ # Fields of map entry should always be serialized.
+ descriptor.fields_by_name['key']._encoder(
+ write_bytes, self.key, deterministic)
+ descriptor.fields_by_name['value']._encoder(
+ write_bytes, self.value, deterministic)
+ else:
+ for field_descriptor, field_value in self.ListFields():
+ field_descriptor._encoder(write_bytes, field_value, deterministic)
+ for tag_bytes, value_bytes in self._unknown_fields:
+ write_bytes(tag_bytes)
+ write_bytes(value_bytes)
cls._InternalSerialize = InternalSerialize
def _AddMergeFromStringMethod(message_descriptor, cls):
"""Helper for _AddMessageMethods()."""
def MergeFromString(self, serialized):
- serialized = memoryview(serialized)
+ serialized = memoryview(serialized)
length = len(serialized)
try:
if self._InternalParse(serialized, 0, length) != length:
@@ -1153,54 +1153,54 @@ def _AddMergeFromStringMethod(message_descriptor, cls):
decoders_by_tag = cls._decoders_by_tag
def InternalParse(self, buffer, pos, end):
- """Create a message from serialized bytes.
-
- Args:
- self: Message, instance of the proto message object.
- buffer: memoryview of the serialized data.
- pos: int, position to start in the serialized data.
- end: int, end position of the serialized data.
-
- Returns:
- Message object.
- """
- # Guard against internal misuse, since this function is called internally
- # quite extensively, and its easy to accidentally pass bytes.
- assert isinstance(buffer, memoryview)
+ """Create a message from serialized bytes.
+
+ Args:
+ self: Message, instance of the proto message object.
+ buffer: memoryview of the serialized data.
+ pos: int, position to start in the serialized data.
+ end: int, end position of the serialized data.
+
+ Returns:
+ Message object.
+ """
+ # Guard against internal misuse, since this function is called internally
+ # quite extensively, and its easy to accidentally pass bytes.
+ assert isinstance(buffer, memoryview)
self._Modified()
field_dict = self._fields
- # pylint: disable=protected-access
- unknown_field_set = self._unknown_field_set
+ # pylint: disable=protected-access
+ unknown_field_set = self._unknown_field_set
while pos != end:
(tag_bytes, new_pos) = local_ReadTag(buffer, pos)
field_decoder, field_desc = decoders_by_tag.get(tag_bytes, (None, None))
if field_decoder is None:
- if not self._unknown_fields: # pylint: disable=protected-access
- self._unknown_fields = [] # pylint: disable=protected-access
- if unknown_field_set is None:
- # pylint: disable=protected-access
- self._unknown_field_set = containers.UnknownFieldSet()
- # pylint: disable=protected-access
- unknown_field_set = self._unknown_field_set
- # pylint: disable=protected-access
- (tag, _) = decoder._DecodeVarint(tag_bytes, 0)
- field_number, wire_type = wire_format.UnpackTag(tag)
- if field_number == 0:
- raise message_mod.DecodeError('Field number 0 is illegal.')
- # TODO(jieluo): remove old_pos.
- old_pos = new_pos
- (data, new_pos) = decoder._DecodeUnknownField(
- buffer, new_pos, wire_type) # pylint: disable=protected-access
- if new_pos == -1:
- return pos
- # pylint: disable=protected-access
- unknown_field_set._add(field_number, wire_type, data)
- # TODO(jieluo): remove _unknown_fields.
- new_pos = local_SkipField(buffer, old_pos, end, tag_bytes)
+ if not self._unknown_fields: # pylint: disable=protected-access
+ self._unknown_fields = [] # pylint: disable=protected-access
+ if unknown_field_set is None:
+ # pylint: disable=protected-access
+ self._unknown_field_set = containers.UnknownFieldSet()
+ # pylint: disable=protected-access
+ unknown_field_set = self._unknown_field_set
+ # pylint: disable=protected-access
+ (tag, _) = decoder._DecodeVarint(tag_bytes, 0)
+ field_number, wire_type = wire_format.UnpackTag(tag)
+ if field_number == 0:
+ raise message_mod.DecodeError('Field number 0 is illegal.')
+ # TODO(jieluo): remove old_pos.
+ old_pos = new_pos
+ (data, new_pos) = decoder._DecodeUnknownField(
+ buffer, new_pos, wire_type) # pylint: disable=protected-access
if new_pos == -1:
return pos
- self._unknown_fields.append(
- (tag_bytes, buffer[old_pos:new_pos].tobytes()))
+ # pylint: disable=protected-access
+ unknown_field_set._add(field_number, wire_type, data)
+ # TODO(jieluo): remove _unknown_fields.
+ new_pos = local_SkipField(buffer, old_pos, end, tag_bytes)
+ if new_pos == -1:
+ return pos
+ self._unknown_fields.append(
+ (tag_bytes, buffer[old_pos:new_pos].tobytes()))
pos = new_pos
else:
pos = field_decoder(buffer, new_pos, end, self, field_dict)
@@ -1275,7 +1275,7 @@ def _AddIsInitializedMethod(message_descriptor, cls):
for field, value in self.ListFields():
if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
if field.is_extension:
- name = '(%s)' % field.full_name
+ name = '(%s)' % field.full_name
else:
name = field.name
@@ -1283,7 +1283,7 @@ def _AddIsInitializedMethod(message_descriptor, cls):
if _IsMessageMapField(field):
for key in value:
element = value[key]
- prefix = '%s[%s].' % (name, key)
+ prefix = '%s[%s].' % (name, key)
sub_errors = element.FindInitializationErrors()
errors += [prefix + error for error in sub_errors]
else:
@@ -1292,11 +1292,11 @@ def _AddIsInitializedMethod(message_descriptor, cls):
elif field.label == _FieldDescriptor.LABEL_REPEATED:
for i in range(len(value)):
element = value[i]
- prefix = '%s[%d].' % (name, i)
+ prefix = '%s[%d].' % (name, i)
sub_errors = element.FindInitializationErrors()
errors += [prefix + error for error in sub_errors]
else:
- prefix = name + '.'
+ prefix = name + '.'
sub_errors = value.FindInitializationErrors()
errors += [prefix + error for error in sub_errors]
@@ -1312,7 +1312,7 @@ def _AddMergeFromMethod(cls):
def MergeFrom(self, msg):
if not isinstance(msg, cls):
raise TypeError(
- 'Parameter to MergeFrom() must be instance of same class: '
+ 'Parameter to MergeFrom() must be instance of same class: '
'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
assert msg is not self
@@ -1345,10 +1345,10 @@ def _AddMergeFromMethod(cls):
if not self._unknown_fields:
self._unknown_fields = []
self._unknown_fields.extend(msg._unknown_fields)
- # pylint: disable=protected-access
- if self._unknown_field_set is None:
- self._unknown_field_set = containers.UnknownFieldSet()
- self._unknown_field_set._extend(msg._unknown_field_set)
+ # pylint: disable=protected-access
+ if self._unknown_field_set is None:
+ self._unknown_field_set = containers.UnknownFieldSet()
+ self._unknown_field_set._extend(msg._unknown_field_set)
cls.MergeFrom = MergeFrom
@@ -1375,32 +1375,32 @@ def _Clear(self):
# Clear fields.
self._fields = {}
self._unknown_fields = ()
- # pylint: disable=protected-access
- if self._unknown_field_set is not None:
- self._unknown_field_set._clear()
- self._unknown_field_set = None
-
+ # pylint: disable=protected-access
+ if self._unknown_field_set is not None:
+ self._unknown_field_set._clear()
+ self._unknown_field_set = None
+
self._oneofs = {}
self._Modified()
-def _UnknownFields(self):
- if self._unknown_field_set is None: # pylint: disable=protected-access
- # pylint: disable=protected-access
- self._unknown_field_set = containers.UnknownFieldSet()
- return self._unknown_field_set # pylint: disable=protected-access
-
-
+def _UnknownFields(self):
+ if self._unknown_field_set is None: # pylint: disable=protected-access
+ # pylint: disable=protected-access
+ self._unknown_field_set = containers.UnknownFieldSet()
+ return self._unknown_field_set # pylint: disable=protected-access
+
+
def _DiscardUnknownFields(self):
self._unknown_fields = []
- self._unknown_field_set = None # pylint: disable=protected-access
+ self._unknown_field_set = None # pylint: disable=protected-access
for field, value in self.ListFields():
if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
- if _IsMapField(field):
- if _IsMessageMapField(field):
- for key in value:
- value[key].DiscardUnknownFields()
- elif field.label == _FieldDescriptor.LABEL_REPEATED:
+ if _IsMapField(field):
+ if _IsMessageMapField(field):
+ for key in value:
+ value[key].DiscardUnknownFields()
+ elif field.label == _FieldDescriptor.LABEL_REPEATED:
for sub_message in value:
sub_message.DiscardUnknownFields()
else:
@@ -1435,7 +1435,7 @@ def _AddMessageMethods(message_descriptor, cls):
_AddWhichOneofMethod(message_descriptor, cls)
# Adds methods which do not depend on cls.
cls.Clear = _Clear
- cls.UnknownFields = _UnknownFields
+ cls.UnknownFields = _UnknownFields
cls.DiscardUnknownFields = _DiscardUnknownFields
cls._SetListener = _SetListener
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/type_checkers.py b/contrib/python/protobuf/py2/google/protobuf/internal/type_checkers.py
index eb66f9f6fb..3e3bd9aa0a 100644
--- a/contrib/python/protobuf/py2/google/protobuf/internal/type_checkers.py
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/type_checkers.py
@@ -38,18 +38,18 @@ TYPE_TO_BYTE_SIZE_FN: A dictionary with field types and a size computing
TYPE_TO_SERIALIZE_METHOD: A dictionary with field types and serialization
function.
FIELD_TYPE_TO_WIRE_TYPE: A dictionary with field typed and their
- corresponding wire types.
+ corresponding wire types.
TYPE_TO_DESERIALIZE_METHOD: A dictionary with field types and deserialization
function.
"""
__author__ = 'robinson@google.com (Will Robinson)'
-try:
- import ctypes
-except Exception: # pylint: disable=broad-except
- ctypes = None
- import struct
+try:
+ import ctypes
+except Exception: # pylint: disable=broad-except
+ ctypes = None
+ import struct
import numbers
import six
@@ -64,29 +64,29 @@ from google.protobuf import descriptor
_FieldDescriptor = descriptor.FieldDescriptor
-
-def TruncateToFourByteFloat(original):
- if ctypes:
- return ctypes.c_float(original).value
- else:
- return struct.unpack('<f', struct.pack('<f', original))[0]
-
-
-def ToShortestFloat(original):
- """Returns the shortest float that has same value in wire."""
- # All 4 byte floats have between 6 and 9 significant digits, so we
- # start with 6 as the lower bound.
- # It has to be iterative because use '.9g' directly can not get rid
- # of the noises for most values. For example if set a float_field=0.9
- # use '.9g' will print 0.899999976.
- precision = 6
- rounded = float('{0:.{1}g}'.format(original, precision))
- while TruncateToFourByteFloat(rounded) != original:
- precision += 1
- rounded = float('{0:.{1}g}'.format(original, precision))
- return rounded
-
-
+
+def TruncateToFourByteFloat(original):
+ if ctypes:
+ return ctypes.c_float(original).value
+ else:
+ return struct.unpack('<f', struct.pack('<f', original))[0]
+
+
+def ToShortestFloat(original):
+ """Returns the shortest float that has same value in wire."""
+ # All 4 byte floats have between 6 and 9 significant digits, so we
+ # start with 6 as the lower bound.
+ # It has to be iterative because use '.9g' directly can not get rid
+ # of the noises for most values. For example if set a float_field=0.9
+ # use '.9g' will print 0.899999976.
+ precision = 6
+ rounded = float('{0:.{1}g}'.format(original, precision))
+ while TruncateToFourByteFloat(rounded) != original:
+ precision += 1
+ rounded = float('{0:.{1}g}'.format(original, precision))
+ return rounded
+
+
def SupportsOpenEnums(field_descriptor):
return field_descriptor.containing_type.syntax == "proto3"
@@ -101,7 +101,7 @@ def GetTypeChecker(field):
of values assigned to a field of the specified type.
"""
if (field.cpp_type == _FieldDescriptor.CPPTYPE_STRING and
- field.type == _FieldDescriptor.TYPE_STRING):
+ field.type == _FieldDescriptor.TYPE_STRING):
return UnicodeValueChecker()
if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM:
if SupportsOpenEnums(field):
@@ -135,18 +135,18 @@ class TypeChecker(object):
message = ('%.1024r has type %s, but expected one of: %s' %
(proposed_value, type(proposed_value), self._acceptable_types))
raise TypeError(message)
- # Some field types(float, double and bool) accept other types, must
- # convert to the correct type in such cases.
- if self._acceptable_types:
- if self._acceptable_types[0] in (bool, float):
- return self._acceptable_types[0](proposed_value)
+ # Some field types(float, double and bool) accept other types, must
+ # convert to the correct type in such cases.
+ if self._acceptable_types:
+ if self._acceptable_types[0] in (bool, float):
+ return self._acceptable_types[0](proposed_value)
return proposed_value
class TypeCheckerWithDefault(TypeChecker):
def __init__(self, default_value, *acceptable_types):
- TypeChecker.__init__(self, *acceptable_types)
+ TypeChecker.__init__(self, *acceptable_types)
self._default_value = default_value
def DefaultValue(self):
@@ -218,14 +218,14 @@ class UnicodeValueChecker(object):
'encoding. Non-UTF-8 strings must be converted to '
'unicode objects before being added.' %
(proposed_value))
- else:
- try:
- proposed_value.encode('utf8')
- except UnicodeEncodeError:
- raise ValueError('%.1024r isn\'t a valid unicode string and '
- 'can\'t be encoded in UTF-8.'%
- (proposed_value))
-
+ else:
+ try:
+ proposed_value.encode('utf8')
+ except UnicodeEncodeError:
+ raise ValueError('%.1024r isn\'t a valid unicode string and '
+ 'can\'t be encoded in UTF-8.'%
+ (proposed_value))
+
return proposed_value
def DefaultValue(self):
@@ -258,39 +258,39 @@ class Uint64ValueChecker(IntValueChecker):
_TYPE = long
-# The max 4 bytes float is about 3.4028234663852886e+38
-_FLOAT_MAX = float.fromhex('0x1.fffffep+127')
-_FLOAT_MIN = -_FLOAT_MAX
-_INF = float('inf')
-_NEG_INF = float('-inf')
-
-
-class FloatValueChecker(object):
-
- """Checker used for float fields. Performs type-check and range check.
-
- Values exceeding a 32-bit float will be converted to inf/-inf.
- """
-
- def CheckValue(self, proposed_value):
- """Check and convert proposed_value to float."""
- if not isinstance(proposed_value, numbers.Real):
- message = ('%.1024r has type %s, but expected one of: numbers.Real' %
- (proposed_value, type(proposed_value)))
- raise TypeError(message)
- converted_value = float(proposed_value)
- # This inf rounding matches the C++ proto SafeDoubleToFloat logic.
- if converted_value > _FLOAT_MAX:
- return _INF
- if converted_value < _FLOAT_MIN:
- return _NEG_INF
-
- return TruncateToFourByteFloat(converted_value)
-
- def DefaultValue(self):
- return 0.0
-
-
+# The max 4 bytes float is about 3.4028234663852886e+38
+_FLOAT_MAX = float.fromhex('0x1.fffffep+127')
+_FLOAT_MIN = -_FLOAT_MAX
+_INF = float('inf')
+_NEG_INF = float('-inf')
+
+
+class FloatValueChecker(object):
+
+ """Checker used for float fields. Performs type-check and range check.
+
+ Values exceeding a 32-bit float will be converted to inf/-inf.
+ """
+
+ def CheckValue(self, proposed_value):
+ """Check and convert proposed_value to float."""
+ if not isinstance(proposed_value, numbers.Real):
+ message = ('%.1024r has type %s, but expected one of: numbers.Real' %
+ (proposed_value, type(proposed_value)))
+ raise TypeError(message)
+ converted_value = float(proposed_value)
+ # This inf rounding matches the C++ proto SafeDoubleToFloat logic.
+ if converted_value > _FLOAT_MAX:
+ return _INF
+ if converted_value < _FLOAT_MIN:
+ return _NEG_INF
+
+ return TruncateToFourByteFloat(converted_value)
+
+ def DefaultValue(self):
+ return 0.0
+
+
# Type-checkers for all scalar CPPTYPEs.
_VALUE_CHECKERS = {
_FieldDescriptor.CPPTYPE_INT32: Int32ValueChecker(),
@@ -298,8 +298,8 @@ _VALUE_CHECKERS = {
_FieldDescriptor.CPPTYPE_UINT32: Uint32ValueChecker(),
_FieldDescriptor.CPPTYPE_UINT64: Uint64ValueChecker(),
_FieldDescriptor.CPPTYPE_DOUBLE: TypeCheckerWithDefault(
- 0.0, float, numbers.Real),
- _FieldDescriptor.CPPTYPE_FLOAT: FloatValueChecker(),
+ 0.0, float, numbers.Real),
+ _FieldDescriptor.CPPTYPE_FLOAT: FloatValueChecker(),
_FieldDescriptor.CPPTYPE_BOOL: TypeCheckerWithDefault(
False, bool, numbers.Integral),
_FieldDescriptor.CPPTYPE_STRING: TypeCheckerWithDefault(b'', bytes),
diff --git a/contrib/python/protobuf/py2/google/protobuf/internal/well_known_types.py b/contrib/python/protobuf/py2/google/protobuf/internal/well_known_types.py
index 6f55d6b17b..df45c027f7 100644
--- a/contrib/python/protobuf/py2/google/protobuf/internal/well_known_types.py
+++ b/contrib/python/protobuf/py2/google/protobuf/internal/well_known_types.py
@@ -40,18 +40,18 @@ This files defines well known classes which need extra maintenance including:
__author__ = 'jieluo@google.com (Jie Luo)'
-import calendar
+import calendar
from datetime import datetime
from datetime import timedelta
import six
-try:
- # Since python 3
- import collections.abc as collections_abc
-except ImportError:
- # Won't work after python 3.8
- import collections as collections_abc
-
+try:
+ # Since python 3
+ import collections.abc as collections_abc
+except ImportError:
+ # Won't work after python 3.8
+ import collections as collections_abc
+
from google.protobuf.descriptor import FieldDescriptor
_TIMESTAMPFOMAT = '%Y-%m-%dT%H:%M:%S'
@@ -67,16 +67,16 @@ _DURATION_SECONDS_MAX = 315576000000
class Any(object):
"""Class for Any Message type."""
- __slots__ = ()
-
- def Pack(self, msg, type_url_prefix='type.googleapis.com/',
- deterministic=None):
+ __slots__ = ()
+
+ def Pack(self, msg, type_url_prefix='type.googleapis.com/',
+ deterministic=None):
"""Packs the specified message into current Any message."""
if len(type_url_prefix) < 1 or type_url_prefix[-1] != '/':
self.type_url = '%s/%s' % (type_url_prefix, msg.DESCRIPTOR.full_name)
else:
self.type_url = '%s%s' % (type_url_prefix, msg.DESCRIPTOR.full_name)
- self.value = msg.SerializeToString(deterministic=deterministic)
+ self.value = msg.SerializeToString(deterministic=deterministic)
def Unpack(self, msg):
"""Unpacks the current Any message into specified message."""
@@ -93,17 +93,17 @@ class Any(object):
def Is(self, descriptor):
"""Checks if this Any represents the given protobuf type."""
- return '/' in self.type_url and self.TypeName() == descriptor.full_name
-
-
-_EPOCH_DATETIME = datetime.utcfromtimestamp(0)
+ return '/' in self.type_url and self.TypeName() == descriptor.full_name
+_EPOCH_DATETIME = datetime.utcfromtimestamp(0)
+
+
class Timestamp(object):
"""Class for Timestamp message type."""
- __slots__ = ()
-
+ __slots__ = ()
+
def ToJsonString(self):
"""Converts Timestamp to RFC 3339 date string format.
@@ -141,7 +141,7 @@ class Timestamp(object):
Example of accepted format: '1972-01-01T10:00:20.021-05:00'
Raises:
- ValueError: On parsing problems.
+ ValueError: On parsing problems.
"""
timezone_offset = value.find('Z')
if timezone_offset == -1:
@@ -149,7 +149,7 @@ class Timestamp(object):
if timezone_offset == -1:
timezone_offset = value.rfind('-')
if timezone_offset == -1:
- raise ValueError(
+ raise ValueError(
'Failed to parse timestamp: missing valid timezone offset.')
time_value = value[0:timezone_offset]
# Parse datetime and nanos.
@@ -160,15 +160,15 @@ class Timestamp(object):
else:
second_value = time_value[:point_position]
nano_value = time_value[point_position + 1:]
- if 't' in second_value:
- raise ValueError(
- 'time data \'{0}\' does not match format \'%Y-%m-%dT%H:%M:%S\', '
- 'lowercase \'t\' is not accepted'.format(second_value))
+ if 't' in second_value:
+ raise ValueError(
+ 'time data \'{0}\' does not match format \'%Y-%m-%dT%H:%M:%S\', '
+ 'lowercase \'t\' is not accepted'.format(second_value))
date_object = datetime.strptime(second_value, _TIMESTAMPFOMAT)
td = date_object - datetime(1970, 1, 1)
seconds = td.seconds + td.days * _SECONDS_PER_DAY
if len(nano_value) > 9:
- raise ValueError(
+ raise ValueError(
'Failed to parse Timestamp: nanos {0} more than '
'9 fractional digits.'.format(nano_value))
if nano_value:
@@ -178,13 +178,13 @@ class Timestamp(object):
# Parse timezone offsets.
if value[timezone_offset] == 'Z':
if len(value) != timezone_offset + 1:
- raise ValueError('Failed to parse timestamp: invalid trailing'
+ raise ValueError('Failed to parse timestamp: invalid trailing'
' data {0}.'.format(value))
else:
timezone = value[timezone_offset:]
pos = timezone.find(':')
if pos == -1:
- raise ValueError(
+ raise ValueError(
'Invalid timezone offset value: {0}.'.format(timezone))
if timezone[0] == '+':
seconds -= (int(timezone[1:pos])*60+int(timezone[pos+1:]))*60
@@ -238,28 +238,28 @@ class Timestamp(object):
def ToDatetime(self):
"""Converts Timestamp to datetime."""
- return _EPOCH_DATETIME + timedelta(
- seconds=self.seconds, microseconds=_RoundTowardZero(
- self.nanos, _NANOS_PER_MICROSECOND))
+ return _EPOCH_DATETIME + timedelta(
+ seconds=self.seconds, microseconds=_RoundTowardZero(
+ self.nanos, _NANOS_PER_MICROSECOND))
def FromDatetime(self, dt):
"""Converts datetime to Timestamp."""
- # Using this guide: http://wiki.python.org/moin/WorkingWithTime
- # And this conversion guide: http://docs.python.org/library/time.html
-
- # Turn the date parameter into a tuple (struct_time) that can then be
- # manipulated into a long value of seconds. During the conversion from
- # struct_time to long, the source date in UTC, and so it follows that the
- # correct transformation is calendar.timegm()
- self.seconds = calendar.timegm(dt.utctimetuple())
- self.nanos = dt.microsecond * _NANOS_PER_MICROSECOND
+ # Using this guide: http://wiki.python.org/moin/WorkingWithTime
+ # And this conversion guide: http://docs.python.org/library/time.html
+ # Turn the date parameter into a tuple (struct_time) that can then be
+ # manipulated into a long value of seconds. During the conversion from
+ # struct_time to long, the source date in UTC, and so it follows that the
+ # correct transformation is calendar.timegm()
+ self.seconds = calendar.timegm(dt.utctimetuple())
+ self.nanos = dt.microsecond * _NANOS_PER_MICROSECOND
+
class Duration(object):
"""Class for Duration message type."""
- __slots__ = ()
-
+ __slots__ = ()
+
def ToJsonString(self):
"""Converts Duration to string format.
@@ -301,10 +301,10 @@ class Duration(object):
precision. For example: "1s", "1.01s", "1.0000001s", "-3.100s
Raises:
- ValueError: On parsing problems.
+ ValueError: On parsing problems.
"""
if len(value) < 1 or value[-1] != 's':
- raise ValueError(
+ raise ValueError(
'Duration must end with letter "s": {0}.'.format(value))
try:
pos = value.find('.')
@@ -320,9 +320,9 @@ class Duration(object):
_CheckDurationValid(seconds, nanos)
self.seconds = seconds
self.nanos = nanos
- except ValueError as e:
- raise ValueError(
- 'Couldn\'t parse duration: {0} : {1}.'.format(value, e))
+ except ValueError as e:
+ raise ValueError(
+ 'Couldn\'t parse duration: {0} : {1}.'.format(value, e))
def ToNanoseconds(self):
"""Converts a Duration to nanoseconds."""
@@ -387,21 +387,21 @@ class Duration(object):
def _CheckDurationValid(seconds, nanos):
if seconds < -_DURATION_SECONDS_MAX or seconds > _DURATION_SECONDS_MAX:
- raise ValueError(
+ raise ValueError(
'Duration is not valid: Seconds {0} must be in range '
'[-315576000000, 315576000000].'.format(seconds))
if nanos <= -_NANOS_PER_SECOND or nanos >= _NANOS_PER_SECOND:
- raise ValueError(
+ raise ValueError(
'Duration is not valid: Nanos {0} must be in range '
'[-999999999, 999999999].'.format(nanos))
- if (nanos < 0 and seconds > 0) or (nanos > 0 and seconds < 0):
- raise ValueError(
- 'Duration is not valid: Sign mismatch.')
+ if (nanos < 0 and seconds > 0) or (nanos > 0 and seconds < 0):
+ raise ValueError(
+ 'Duration is not valid: Sign mismatch.')
def _RoundTowardZero(value, divider):
"""Truncates the remainder part after division."""
- # For some languages, the sign of the remainder is implementation
+ # For some languages, the sign of the remainder is implementation
# dependent if any of the operands is negative. Here we enforce
# "rounded toward zero" semantics. For example, for (-5) / 2 an
# implementation may give -3 as the result with the remainder being
@@ -417,8 +417,8 @@ def _RoundTowardZero(value, divider):
class FieldMask(object):
"""Class for FieldMask message type."""
- __slots__ = ()
-
+ __slots__ = ()
+
def ToJsonString(self):
"""Converts FieldMask to string according to proto3 JSON spec."""
camelcase_paths = []
@@ -429,9 +429,9 @@ class FieldMask(object):
def FromJsonString(self, value):
"""Converts string to FieldMask according to proto3 JSON spec."""
self.Clear()
- if value:
- for path in value.split(','):
- self.paths.append(_CamelCaseToSnakeCase(path))
+ if value:
+ for path in value.split(','):
+ self.paths.append(_CamelCaseToSnakeCase(path))
def IsValidForDescriptor(self, message_descriptor):
"""Checks whether the FieldMask is valid for Message Descriptor."""
@@ -500,7 +500,7 @@ def _IsValidPath(message_descriptor, path):
parts = path.split('.')
last = parts.pop()
for name in parts:
- field = message_descriptor.fields_by_name.get(name)
+ field = message_descriptor.fields_by_name.get(name)
if (field is None or
field.label == FieldDescriptor.LABEL_REPEATED or
field.type != FieldDescriptor.TYPE_MESSAGE):
@@ -524,26 +524,26 @@ def _SnakeCaseToCamelCase(path_name):
after_underscore = False
for c in path_name:
if c.isupper():
- raise ValueError(
- 'Fail to print FieldMask to Json string: Path name '
- '{0} must not contain uppercase letters.'.format(path_name))
+ raise ValueError(
+ 'Fail to print FieldMask to Json string: Path name '
+ '{0} must not contain uppercase letters.'.format(path_name))
if after_underscore:
if c.islower():
result.append(c.upper())
after_underscore = False
else:
- raise ValueError(
- 'Fail to print FieldMask to Json string: The '
- 'character after a "_" must be a lowercase letter '
- 'in path name {0}.'.format(path_name))
+ raise ValueError(
+ 'Fail to print FieldMask to Json string: The '
+ 'character after a "_" must be a lowercase letter '
+ 'in path name {0}.'.format(path_name))
elif c == '_':
after_underscore = True
else:
result += c
if after_underscore:
- raise ValueError('Fail to print FieldMask to Json string: Trailing "_" '
- 'in path name {0}.'.format(path_name))
+ raise ValueError('Fail to print FieldMask to Json string: Trailing "_" '
+ 'in path name {0}.'.format(path_name))
return ''.join(result)
@@ -552,7 +552,7 @@ def _CamelCaseToSnakeCase(path_name):
result = []
for c in path_name:
if c == '_':
- raise ValueError('Fail to parse FieldMask: Path name '
+ raise ValueError('Fail to parse FieldMask: Path name '
'{0} must not contain "_"s.'.format(path_name))
if c.isupper():
result += '_'
@@ -575,8 +575,8 @@ class _FieldMaskTree(object):
In the tree, each leaf node represents a field path.
"""
- __slots__ = ('_root',)
-
+ __slots__ = ('_root',)
+
def __init__(self, field_mask=None):
"""Initializes the tree by FieldMask."""
self._root = {}
@@ -678,17 +678,17 @@ def _MergeMessage(
raise ValueError('Error: Field {0} in message {1} is not a singular '
'message field and cannot have sub-fields.'.format(
name, source_descriptor.full_name))
- if source.HasField(name):
- _MergeMessage(
- child, getattr(source, name), getattr(destination, name),
- replace_message, replace_repeated)
+ if source.HasField(name):
+ _MergeMessage(
+ child, getattr(source, name), getattr(destination, name),
+ replace_message, replace_repeated)
continue
if field.label == FieldDescriptor.LABEL_REPEATED:
if replace_repeated:
destination.ClearField(_StrConvert(name))
repeated_source = getattr(source, name)
repeated_destination = getattr(destination, name)
- repeated_destination.MergeFrom(repeated_source)
+ repeated_destination.MergeFrom(repeated_source)
else:
if field.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
if replace_message:
@@ -701,7 +701,7 @@ def _MergeMessage(
def _AddFieldPaths(node, prefix, field_mask):
"""Adds the field paths descended from node to field_mask."""
- if not node and prefix:
+ if not node and prefix:
field_mask.paths.append(prefix)
return
for name in sorted(node):
@@ -726,12 +726,12 @@ def _SetStructValue(struct_value, value):
struct_value.string_value = value
elif isinstance(value, _INT_OR_FLOAT):
struct_value.number_value = value
- elif isinstance(value, (dict, Struct)):
- struct_value.struct_value.Clear()
- struct_value.struct_value.update(value)
- elif isinstance(value, (list, ListValue)):
- struct_value.list_value.Clear()
- struct_value.list_value.extend(value)
+ elif isinstance(value, (dict, Struct)):
+ struct_value.struct_value.Clear()
+ struct_value.struct_value.update(value)
+ elif isinstance(value, (list, ListValue)):
+ struct_value.list_value.Clear()
+ struct_value.list_value.extend(value)
else:
raise ValueError('Unexpected type')
@@ -757,61 +757,61 @@ def _GetStructValue(struct_value):
class Struct(object):
"""Class for Struct message type."""
- __slots__ = ()
+ __slots__ = ()
def __getitem__(self, key):
return _GetStructValue(self.fields[key])
- def __contains__(self, item):
- return item in self.fields
-
+ def __contains__(self, item):
+ return item in self.fields
+
def __setitem__(self, key, value):
_SetStructValue(self.fields[key], value)
- def __delitem__(self, key):
- del self.fields[key]
-
- def __len__(self):
- return len(self.fields)
-
- def __iter__(self):
- return iter(self.fields)
-
- def keys(self): # pylint: disable=invalid-name
- return self.fields.keys()
-
- def values(self): # pylint: disable=invalid-name
- return [self[key] for key in self]
-
- def items(self): # pylint: disable=invalid-name
- return [(key, self[key]) for key in self]
-
+ def __delitem__(self, key):
+ del self.fields[key]
+
+ def __len__(self):
+ return len(self.fields)
+
+ def __iter__(self):
+ return iter(self.fields)
+
+ def keys(self): # pylint: disable=invalid-name
+ return self.fields.keys()
+
+ def values(self): # pylint: disable=invalid-name
+ return [self[key] for key in self]
+
+ def items(self): # pylint: disable=invalid-name
+ return [(key, self[key]) for key in self]
+
def get_or_create_list(self, key):
"""Returns a list for this key, creating if it didn't exist already."""
- if not self.fields[key].HasField('list_value'):
- # Clear will mark list_value modified which will indeed create a list.
- self.fields[key].list_value.Clear()
+ if not self.fields[key].HasField('list_value'):
+ # Clear will mark list_value modified which will indeed create a list.
+ self.fields[key].list_value.Clear()
return self.fields[key].list_value
def get_or_create_struct(self, key):
"""Returns a struct for this key, creating if it didn't exist already."""
- if not self.fields[key].HasField('struct_value'):
- # Clear will mark struct_value modified which will indeed create a struct.
- self.fields[key].struct_value.Clear()
+ if not self.fields[key].HasField('struct_value'):
+ # Clear will mark struct_value modified which will indeed create a struct.
+ self.fields[key].struct_value.Clear()
return self.fields[key].struct_value
- def update(self, dictionary): # pylint: disable=invalid-name
- for key, value in dictionary.items():
- _SetStructValue(self.fields[key], value)
-
-collections_abc.MutableMapping.register(Struct)
+ def update(self, dictionary): # pylint: disable=invalid-name
+ for key, value in dictionary.items():
+ _SetStructValue(self.fields[key], value)
+collections_abc.MutableMapping.register(Struct)
+
class ListValue(object):
"""Class for ListValue message type."""
- __slots__ = ()
-
+ __slots__ = ()
+
def __len__(self):
return len(self.values)
@@ -829,30 +829,30 @@ class ListValue(object):
def __setitem__(self, index, value):
_SetStructValue(self.values.__getitem__(index), value)
- def __delitem__(self, key):
- del self.values[key]
-
+ def __delitem__(self, key):
+ del self.values[key]
+
def items(self):
for i in range(len(self)):
yield self[i]
def add_struct(self):
"""Appends and returns a struct value as the next value in the list."""
- struct_value = self.values.add().struct_value
- # Clear will mark struct_value modified which will indeed create a struct.
- struct_value.Clear()
- return struct_value
+ struct_value = self.values.add().struct_value
+ # Clear will mark struct_value modified which will indeed create a struct.
+ struct_value.Clear()
+ return struct_value
def add_list(self):
"""Appends and returns a list value as the next value in the list."""
- list_value = self.values.add().list_value
- # Clear will mark list_value modified which will indeed create a list.
- list_value.Clear()
- return list_value
-
-collections_abc.MutableSequence.register(ListValue)
+ list_value = self.values.add().list_value
+ # Clear will mark list_value modified which will indeed create a list.
+ list_value.Clear()
+ return list_value
+collections_abc.MutableSequence.register(ListValue)
+
WKTBASES = {
'google.protobuf.Any': Any,
'google.protobuf.Duration': Duration,
diff --git a/contrib/python/protobuf/py2/google/protobuf/json_format.py b/contrib/python/protobuf/py2/google/protobuf/json_format.py
index 965614d803..7e88d33a26 100644
--- a/contrib/python/protobuf/py2/google/protobuf/json_format.py
+++ b/contrib/python/protobuf/py2/google/protobuf/json_format.py
@@ -42,29 +42,29 @@ Simple usage example:
__author__ = 'jieluo@google.com (Jie Luo)'
-# pylint: disable=g-statement-before-imports,g-import-not-at-top
+# pylint: disable=g-statement-before-imports,g-import-not-at-top
try:
from collections import OrderedDict
except ImportError:
- from ordereddict import OrderedDict # PY26
-# pylint: enable=g-statement-before-imports,g-import-not-at-top
-
+ from ordereddict import OrderedDict # PY26
+# pylint: enable=g-statement-before-imports,g-import-not-at-top
+
import base64
import json
import math
-
-from operator import methodcaller
-
+
+from operator import methodcaller
+
import re
import sys
-import six
-
-from google.protobuf.internal import type_checkers
+import six
+
+from google.protobuf.internal import type_checkers
from google.protobuf import descriptor
from google.protobuf import symbol_database
-
+
_TIMESTAMPFOMAT = '%Y-%m-%dT%H:%M:%S'
_INT_TYPES = frozenset([descriptor.FieldDescriptor.CPPTYPE_INT32,
descriptor.FieldDescriptor.CPPTYPE_UINT32,
@@ -97,15 +97,15 @@ class ParseError(Error):
"""Thrown in case of parsing error."""
-def MessageToJson(
- message,
- including_default_value_fields=False,
- preserving_proto_field_name=False,
- indent=2,
- sort_keys=False,
- use_integers_for_enums=False,
- descriptor_pool=None,
- float_precision=None):
+def MessageToJson(
+ message,
+ including_default_value_fields=False,
+ preserving_proto_field_name=False,
+ indent=2,
+ sort_keys=False,
+ use_integers_for_enums=False,
+ descriptor_pool=None,
+ float_precision=None):
"""Converts protobuf message to JSON format.
Args:
@@ -121,29 +121,29 @@ def MessageToJson(
An indent level of 0 or negative will only insert newlines.
sort_keys: If True, then the output will be sorted by field names.
use_integers_for_enums: If true, print integers instead of enum names.
- descriptor_pool: A Descriptor Pool for resolving types. If None use the
- default.
- float_precision: If set, use this to specify float field valid digits.
+ descriptor_pool: A Descriptor Pool for resolving types. If None use the
+ default.
+ float_precision: If set, use this to specify float field valid digits.
Returns:
A string containing the JSON formatted protocol buffer message.
"""
- printer = _Printer(
- including_default_value_fields,
- preserving_proto_field_name,
- use_integers_for_enums,
- descriptor_pool,
- float_precision=float_precision)
+ printer = _Printer(
+ including_default_value_fields,
+ preserving_proto_field_name,
+ use_integers_for_enums,
+ descriptor_pool,
+ float_precision=float_precision)
return printer.ToJsonString(message, indent, sort_keys)
-def MessageToDict(
- message,
- including_default_value_fields=False,
- preserving_proto_field_name=False,
- use_integers_for_enums=False,
- descriptor_pool=None,
- float_precision=None):
+def MessageToDict(
+ message,
+ including_default_value_fields=False,
+ preserving_proto_field_name=False,
+ use_integers_for_enums=False,
+ descriptor_pool=None,
+ float_precision=None):
"""Converts protobuf message to a dictionary.
When the dictionary is encoded to JSON, it conforms to proto3 JSON spec.
@@ -158,19 +158,19 @@ def MessageToDict(
names as defined in the .proto file. If False, convert the field
names to lowerCamelCase.
use_integers_for_enums: If true, print integers instead of enum names.
- descriptor_pool: A Descriptor Pool for resolving types. If None use the
- default.
- float_precision: If set, use this to specify float field valid digits.
+ descriptor_pool: A Descriptor Pool for resolving types. If None use the
+ default.
+ float_precision: If set, use this to specify float field valid digits.
Returns:
A dict representation of the protocol buffer message.
"""
- printer = _Printer(
- including_default_value_fields,
- preserving_proto_field_name,
- use_integers_for_enums,
- descriptor_pool,
- float_precision=float_precision)
+ printer = _Printer(
+ including_default_value_fields,
+ preserving_proto_field_name,
+ use_integers_for_enums,
+ descriptor_pool,
+ float_precision=float_precision)
# pylint: disable=protected-access
return printer._MessageToJsonObject(message)
@@ -184,25 +184,25 @@ def _IsMapEntry(field):
class _Printer(object):
"""JSON format printer for protocol message."""
- def __init__(
- self,
- including_default_value_fields=False,
- preserving_proto_field_name=False,
- use_integers_for_enums=False,
- descriptor_pool=None,
- float_precision=None):
+ def __init__(
+ self,
+ including_default_value_fields=False,
+ preserving_proto_field_name=False,
+ use_integers_for_enums=False,
+ descriptor_pool=None,
+ float_precision=None):
self.including_default_value_fields = including_default_value_fields
self.preserving_proto_field_name = preserving_proto_field_name
self.use_integers_for_enums = use_integers_for_enums
- self.descriptor_pool = descriptor_pool
- if float_precision:
- self.float_format = '.{}g'.format(float_precision)
- else:
- self.float_format = None
+ self.descriptor_pool = descriptor_pool
+ if float_precision:
+ self.float_format = '.{}g'.format(float_precision)
+ else:
+ self.float_format = None
def ToJsonString(self, message, indent, sort_keys):
js = self._MessageToJsonObject(message)
- return json.dumps(js, indent=indent, sort_keys=sort_keys)
+ return json.dumps(js, indent=indent, sort_keys=sort_keys)
def _MessageToJsonObject(self, message):
"""Converts message to an object according to Proto3 JSON Specification."""
@@ -245,7 +245,7 @@ class _Printer(object):
js[name] = [self._FieldToJsonObject(field, k)
for k in value]
elif field.is_extension:
- name = '[%s]' % field.full_name
+ name = '[%s]' % field.full_name
js[name] = self._FieldToJsonObject(field, value)
else:
js[name] = self._FieldToJsonObject(field, value)
@@ -264,7 +264,7 @@ class _Printer(object):
else:
name = field.json_name
if name in js:
- # Skip the field which has been serialized already.
+ # Skip the field which has been serialized already.
continue
if _IsMapEntry(field):
js[name] = {}
@@ -286,14 +286,14 @@ class _Printer(object):
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_ENUM:
if self.use_integers_for_enums:
return value
- if field.enum_type.full_name == 'google.protobuf.NullValue':
- return None
+ if field.enum_type.full_name == 'google.protobuf.NullValue':
+ return None
enum_value = field.enum_type.values_by_number.get(value, None)
if enum_value is not None:
return enum_value.name
else:
- if field.file.syntax == 'proto3':
- return value
+ if field.file.syntax == 'proto3':
+ return value
raise SerializeToJsonError('Enum field contains an integer value '
'which can not mapped to an enum value.')
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_STRING:
@@ -314,12 +314,12 @@ class _Printer(object):
return _INFINITY
if math.isnan(value):
return _NAN
- if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
- if self.float_format:
- return float(format(value, self.float_format))
- else:
- return type_checkers.ToShortestFloat(value)
-
+ if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
+ if self.float_format:
+ return float(format(value, self.float_format))
+ else:
+ return type_checkers.ToShortestFloat(value)
+
return value
def _AnyMessageToJsonObject(self, message):
@@ -330,7 +330,7 @@ class _Printer(object):
js = OrderedDict()
type_url = message.type_url
js['@type'] = type_url
- sub_message = _CreateMessageFromTypeUrl(type_url, self.descriptor_pool)
+ sub_message = _CreateMessageFromTypeUrl(type_url, self.descriptor_pool)
sub_message.ParseFromString(message.value)
message_descriptor = sub_message.DESCRIPTOR
full_name = message_descriptor.full_name
@@ -396,13 +396,13 @@ def _DuplicateChecker(js):
return result
-def _CreateMessageFromTypeUrl(type_url, descriptor_pool):
- """Creates a message from a type URL."""
+def _CreateMessageFromTypeUrl(type_url, descriptor_pool):
+ """Creates a message from a type URL."""
db = symbol_database.Default()
- pool = db.pool if descriptor_pool is None else descriptor_pool
+ pool = db.pool if descriptor_pool is None else descriptor_pool
type_name = type_url.split('/')[-1]
try:
- message_descriptor = pool.FindMessageTypeByName(type_name)
+ message_descriptor = pool.FindMessageTypeByName(type_name)
except KeyError:
raise TypeError(
'Can not find message descriptor by type_url: {0}.'.format(type_url))
@@ -410,15 +410,15 @@ def _CreateMessageFromTypeUrl(type_url, descriptor_pool):
return message_class()
-def Parse(text, message, ignore_unknown_fields=False, descriptor_pool=None):
+def Parse(text, message, ignore_unknown_fields=False, descriptor_pool=None):
"""Parses a JSON representation of a protocol message into a message.
Args:
text: Message JSON representation.
message: A protocol buffer message to merge into.
ignore_unknown_fields: If True, do not raise errors for unknown fields.
- descriptor_pool: A Descriptor Pool for resolving types. If None use the
- default.
+ descriptor_pool: A Descriptor Pool for resolving types. If None use the
+ default.
Returns:
The same message passed as argument.
@@ -428,29 +428,29 @@ def Parse(text, message, ignore_unknown_fields=False, descriptor_pool=None):
"""
if not isinstance(text, six.text_type): text = text.decode('utf-8')
try:
- js = json.loads(text, object_pairs_hook=_DuplicateChecker)
+ js = json.loads(text, object_pairs_hook=_DuplicateChecker)
except ValueError as e:
raise ParseError('Failed to load JSON: {0}.'.format(str(e)))
- return ParseDict(js, message, ignore_unknown_fields, descriptor_pool)
+ return ParseDict(js, message, ignore_unknown_fields, descriptor_pool)
-def ParseDict(js_dict,
- message,
- ignore_unknown_fields=False,
- descriptor_pool=None):
+def ParseDict(js_dict,
+ message,
+ ignore_unknown_fields=False,
+ descriptor_pool=None):
"""Parses a JSON dictionary representation into a message.
Args:
js_dict: Dict representation of a JSON message.
message: A protocol buffer message to merge into.
ignore_unknown_fields: If True, do not raise errors for unknown fields.
- descriptor_pool: A Descriptor Pool for resolving types. If None use the
- default.
+ descriptor_pool: A Descriptor Pool for resolving types. If None use the
+ default.
Returns:
The same message passed as argument.
"""
- parser = _Parser(ignore_unknown_fields, descriptor_pool)
+ parser = _Parser(ignore_unknown_fields, descriptor_pool)
parser.ConvertMessage(js_dict, message)
return message
@@ -461,9 +461,9 @@ _INT_OR_FLOAT = six.integer_types + (float,)
class _Parser(object):
"""JSON format parser for protocol message."""
- def __init__(self, ignore_unknown_fields, descriptor_pool):
+ def __init__(self, ignore_unknown_fields, descriptor_pool):
self.ignore_unknown_fields = ignore_unknown_fields
- self.descriptor_pool = descriptor_pool
+ self.descriptor_pool = descriptor_pool
def ConvertMessage(self, value, message):
"""Convert a JSON object into a message.
@@ -511,13 +511,13 @@ class _Parser(object):
# pylint: disable=protected-access
field = message.Extensions._FindExtensionByName(identifier)
# pylint: enable=protected-access
- if not field:
- # Try looking for extension by the message type name, dropping the
- # field name following the final . separator in full_name.
- identifier = '.'.join(identifier.split('.')[:-1])
- # pylint: disable=protected-access
- field = message.Extensions._FindExtensionByName(identifier)
- # pylint: enable=protected-access
+ if not field:
+ # Try looking for extension by the message type name, dropping the
+ # field name following the final . separator in full_name.
+ identifier = '.'.join(identifier.split('.')[:-1])
+ # pylint: disable=protected-access
+ field = message.Extensions._FindExtensionByName(identifier)
+ # pylint: enable=protected-access
if not field:
if self.ignore_unknown_fields:
continue
@@ -525,15 +525,15 @@ class _Parser(object):
('Message type "{0}" has no field named "{1}".\n'
' Available Fields(except extensions): {2}').format(
message_descriptor.full_name, name,
- [f.json_name for f in message_descriptor.fields]))
+ [f.json_name for f in message_descriptor.fields]))
if name in names:
raise ParseError('Message type "{0}" should not have multiple '
'"{1}" fields.'.format(
message.DESCRIPTOR.full_name, name))
names.append(name)
- value = js[name]
+ value = js[name]
# Check no other oneof field is parsed.
- if field.containing_oneof is not None and value is not None:
+ if field.containing_oneof is not None and value is not None:
oneof_name = field.containing_oneof.name
if oneof_name in names:
raise ParseError('Message type "{0}" should not have multiple '
@@ -546,9 +546,9 @@ class _Parser(object):
and field.message_type.full_name == 'google.protobuf.Value'):
sub_message = getattr(message, field.name)
sub_message.null_value = 0
- elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_ENUM
- and field.enum_type.full_name == 'google.protobuf.NullValue'):
- setattr(message, field.name, 0)
+ elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_ENUM
+ and field.enum_type.full_name == 'google.protobuf.NullValue'):
+ setattr(message, field.name, 0)
else:
message.ClearField(field.name)
continue
@@ -588,13 +588,13 @@ class _Parser(object):
sub_message.SetInParent()
self.ConvertMessage(value, sub_message)
else:
- if field.is_extension:
- message.Extensions[field] = _ConvertScalarFieldValue(value, field)
- else:
- setattr(message, field.name, _ConvertScalarFieldValue(value, field))
+ if field.is_extension:
+ message.Extensions[field] = _ConvertScalarFieldValue(value, field)
+ else:
+ setattr(message, field.name, _ConvertScalarFieldValue(value, field))
except ParseError as e:
if field and field.containing_oneof is None:
- raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
+ raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
else:
raise ParseError(str(e))
except ValueError as e:
@@ -611,7 +611,7 @@ class _Parser(object):
except KeyError:
raise ParseError('@type is missing when parsing any message.')
- sub_message = _CreateMessageFromTypeUrl(type_url, self.descriptor_pool)
+ sub_message = _CreateMessageFromTypeUrl(type_url, self.descriptor_pool)
message_descriptor = sub_message.DESCRIPTOR
full_name = message_descriptor.full_name
if _IsWrapperMessage(message_descriptor):
@@ -622,7 +622,7 @@ class _Parser(object):
else:
del value['@type']
self._ConvertFieldValuePair(value, sub_message)
- value['@type'] = type_url
+ value['@type'] = type_url
# Sets Any message
message.value = sub_message.SerializeToString()
message.type_url = type_url
@@ -631,10 +631,10 @@ class _Parser(object):
"""Convert a JSON representation into message with FromJsonString."""
# Duration, Timestamp, FieldMask have a FromJsonString method to do the
# conversion. Users can also call the method directly.
- try:
- message.FromJsonString(value)
- except ValueError as e:
- raise ParseError(e)
+ try:
+ message.FromJsonString(value)
+ except ValueError as e:
+ raise ParseError(e)
def _ConvertValueMessage(self, value, message):
"""Convert a JSON representation into Value message."""
@@ -651,8 +651,8 @@ class _Parser(object):
elif isinstance(value, _INT_OR_FLOAT):
message.number_value = value
else:
- raise ParseError('Value {0} has unexpected type {1}.'.format(
- value, type(value)))
+ raise ParseError('Value {0} has unexpected type {1}.'.format(
+ value, type(value)))
def _ConvertListValueMessage(self, value, message):
"""Convert a JSON representation into ListValue message."""
@@ -668,9 +668,9 @@ class _Parser(object):
if not isinstance(value, dict):
raise ParseError(
'Struct must be in a dict which is {0}.'.format(value))
- # Clear will mark the struct as modified so it will be created even if
- # there are no values.
- message.Clear()
+ # Clear will mark the struct as modified so it will be created even if
+ # there are no values.
+ message.Clear()
for key in value:
self._ConvertValueMessage(value[key], message.fields[key])
return
@@ -724,18 +724,18 @@ def _ConvertScalarFieldValue(value, field, require_str=False):
if field.cpp_type in _INT_TYPES:
return _ConvertInteger(value)
elif field.cpp_type in _FLOAT_TYPES:
- return _ConvertFloat(value, field)
+ return _ConvertFloat(value, field)
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_BOOL:
return _ConvertBool(value, require_str)
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_STRING:
if field.type == descriptor.FieldDescriptor.TYPE_BYTES:
- if isinstance(value, six.text_type):
- encoded = value.encode('utf-8')
- else:
- encoded = value
- # Add extra padding '='
- padded_value = encoded + b'=' * (4 - len(encoded) % 4)
- return base64.urlsafe_b64decode(padded_value)
+ if isinstance(value, six.text_type):
+ encoded = value.encode('utf-8')
+ else:
+ encoded = value
+ # Add extra padding '='
+ padded_value = encoded + b'=' * (4 - len(encoded) % 4)
+ return base64.urlsafe_b64decode(padded_value)
else:
# Checking for unpaired surrogates appears to be unreliable,
# depending on the specific Python version, so we check manually.
@@ -753,9 +753,9 @@ def _ConvertScalarFieldValue(value, field, require_str=False):
raise ParseError('Invalid enum value {0} for enum type {1}.'.format(
value, field.enum_type.full_name))
if enum_value is None:
- if field.file.syntax == 'proto3':
- # Proto3 accepts unknown enums.
- return number
+ if field.file.syntax == 'proto3':
+ # Proto3 accepts unknown enums.
+ return number
raise ParseError('Invalid enum value {0} for enum type {1}.'.format(
value, field.enum_type.full_name))
return enum_value.number
@@ -779,32 +779,32 @@ def _ConvertInteger(value):
if isinstance(value, six.text_type) and value.find(' ') != -1:
raise ParseError('Couldn\'t parse integer: "{0}".'.format(value))
- if isinstance(value, bool):
- raise ParseError('Bool value {0} is not acceptable for '
- 'integer field.'.format(value))
-
+ if isinstance(value, bool):
+ raise ParseError('Bool value {0} is not acceptable for '
+ 'integer field.'.format(value))
+
return int(value)
-def _ConvertFloat(value, field):
+def _ConvertFloat(value, field):
"""Convert an floating point number."""
- if isinstance(value, float):
- if math.isnan(value):
- raise ParseError('Couldn\'t parse NaN, use quoted "NaN" instead.')
- if math.isinf(value):
- if value > 0:
- raise ParseError('Couldn\'t parse Infinity or value too large, '
- 'use quoted "Infinity" instead.')
- else:
- raise ParseError('Couldn\'t parse -Infinity or value too small, '
- 'use quoted "-Infinity" instead.')
- if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
- # pylint: disable=protected-access
- if value > type_checkers._FLOAT_MAX:
- raise ParseError('Float value too large')
- # pylint: disable=protected-access
- if value < type_checkers._FLOAT_MIN:
- raise ParseError('Float value too small')
+ if isinstance(value, float):
+ if math.isnan(value):
+ raise ParseError('Couldn\'t parse NaN, use quoted "NaN" instead.')
+ if math.isinf(value):
+ if value > 0:
+ raise ParseError('Couldn\'t parse Infinity or value too large, '
+ 'use quoted "Infinity" instead.')
+ else:
+ raise ParseError('Couldn\'t parse -Infinity or value too small, '
+ 'use quoted "-Infinity" instead.')
+ if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
+ # pylint: disable=protected-access
+ if value > type_checkers._FLOAT_MAX:
+ raise ParseError('Float value too large')
+ # pylint: disable=protected-access
+ if value < type_checkers._FLOAT_MIN:
+ raise ParseError('Float value too small')
if value == 'nan':
raise ParseError('Couldn\'t parse float "nan", use "NaN" instead.')
try:
diff --git a/contrib/python/protobuf/py2/google/protobuf/message.py b/contrib/python/protobuf/py2/google/protobuf/message.py
index 224d2fc491..7355745855 100644
--- a/contrib/python/protobuf/py2/google/protobuf/message.py
+++ b/contrib/python/protobuf/py2/google/protobuf/message.py
@@ -36,21 +36,21 @@
__author__ = 'robinson@google.com (Will Robinson)'
-class Error(Exception):
- """Base error type for this module."""
- pass
-
-
-class DecodeError(Error):
- """Exception raised when deserializing messages."""
- pass
-
-
-class EncodeError(Error):
- """Exception raised when serializing messages."""
- pass
-
-
+class Error(Exception):
+ """Base error type for this module."""
+ pass
+
+
+class DecodeError(Error):
+ """Exception raised when deserializing messages."""
+ pass
+
+
+class EncodeError(Error):
+ """Exception raised when serializing messages."""
+ pass
+
+
class Message(object):
"""Abstract base class for protocol messages.
@@ -58,23 +58,23 @@ class Message(object):
Protocol message classes are almost always generated by the protocol
compiler. These generated types subclass Message and implement the methods
shown below.
- """
+ """
- # TODO(robinson): Link to an HTML document here.
+ # TODO(robinson): Link to an HTML document here.
- # TODO(robinson): Document that instances of this class will also
- # have an Extensions attribute with __getitem__ and __setitem__.
- # Again, not sure how to best convey this.
+ # TODO(robinson): Document that instances of this class will also
+ # have an Extensions attribute with __getitem__ and __setitem__.
+ # Again, not sure how to best convey this.
- # TODO(robinson): Document that the class must also have a static
- # RegisterExtension(extension_field) method.
- # Not sure how to best express at this point.
+ # TODO(robinson): Document that the class must also have a static
+ # RegisterExtension(extension_field) method.
+ # Not sure how to best express at this point.
# TODO(robinson): Document these fields and methods.
__slots__ = []
- #: The :class:`google.protobuf.descriptor.Descriptor` for this message type.
+ #: The :class:`google.protobuf.descriptor.Descriptor` for this message type.
DESCRIPTOR = None
def __deepcopy__(self, memo=None):
@@ -110,7 +110,7 @@ class Message(object):
appended. Singular sub-messages and groups are recursively merged.
Args:
- other_msg (Message): A message to merge into the current message.
+ other_msg (Message): A message to merge into the current message.
"""
raise NotImplementedError
@@ -121,7 +121,7 @@ class Message(object):
message using MergeFrom.
Args:
- other_msg (Message): A message to copy into the current one.
+ other_msg (Message): A message to copy into the current one.
"""
if self is other_msg:
return
@@ -138,16 +138,16 @@ class Message(object):
This normally happens automatically when you assign a field of a
sub-message, but sometimes you want to make the sub-message
present while keeping it empty. If you find yourself using this,
- you may want to reconsider your design.
- """
+ you may want to reconsider your design.
+ """
raise NotImplementedError
def IsInitialized(self):
"""Checks if the message is initialized.
Returns:
- bool: The method returns True if the message is initialized (i.e. all of
- its required fields are set).
+ bool: The method returns True if the message is initialized (i.e. all of
+ its required fields are set).
"""
raise NotImplementedError
@@ -160,57 +160,57 @@ class Message(object):
def MergeFromString(self, serialized):
"""Merges serialized protocol buffer data into this message.
- When we find a field in `serialized` that is already present
+ When we find a field in `serialized` that is already present
in this message:
-
- - If it's a "repeated" field, we append to the end of our list.
- - Else, if it's a scalar, we overwrite our field.
- - Else, (it's a nonrepeated composite), we recursively merge
+
+ - If it's a "repeated" field, we append to the end of our list.
+ - Else, if it's a scalar, we overwrite our field.
+ - Else, (it's a nonrepeated composite), we recursively merge
into the existing composite.
Args:
- serialized (bytes): Any object that allows us to call
- ``memoryview(serialized)`` to access a string of bytes using the
- buffer interface.
+ serialized (bytes): Any object that allows us to call
+ ``memoryview(serialized)`` to access a string of bytes using the
+ buffer interface.
Returns:
- int: The number of bytes read from `serialized`.
- For non-group messages, this will always be `len(serialized)`,
+ int: The number of bytes read from `serialized`.
+ For non-group messages, this will always be `len(serialized)`,
but for messages which are actually groups, this will
- generally be less than `len(serialized)`, since we must
- stop when we reach an ``END_GROUP`` tag. Note that if
- we *do* stop because of an ``END_GROUP`` tag, the number
+ generally be less than `len(serialized)`, since we must
+ stop when we reach an ``END_GROUP`` tag. Note that if
+ we *do* stop because of an ``END_GROUP`` tag, the number
of bytes returned does not include the bytes
- for the ``END_GROUP`` tag information.
-
- Raises:
- DecodeError: if the input cannot be parsed.
+ for the ``END_GROUP`` tag information.
+
+ Raises:
+ DecodeError: if the input cannot be parsed.
"""
- # TODO(robinson): Document handling of unknown fields.
- # TODO(robinson): When we switch to a helper, this will return None.
+ # TODO(robinson): Document handling of unknown fields.
+ # TODO(robinson): When we switch to a helper, this will return None.
raise NotImplementedError
def ParseFromString(self, serialized):
"""Parse serialized protocol buffer data into this message.
- Like :func:`MergeFromString()`, except we clear the object first.
+ Like :func:`MergeFromString()`, except we clear the object first.
"""
self.Clear()
- return self.MergeFromString(serialized)
+ return self.MergeFromString(serialized)
def SerializeToString(self, **kwargs):
"""Serializes the protocol message to a binary string.
- Keyword Args:
- deterministic (bool): If true, requests deterministic serialization
- of the protobuf, with predictable ordering of map keys.
+ Keyword Args:
+ deterministic (bool): If true, requests deterministic serialization
+ of the protobuf, with predictable ordering of map keys.
Returns:
A binary string representation of the message if all of the required
fields in the message are set (i.e. the message is initialized).
Raises:
- EncodeError: if the message isn't initialized (see :func:`IsInitialized`).
+ EncodeError: if the message isn't initialized (see :func:`IsInitialized`).
"""
raise NotImplementedError
@@ -220,12 +220,12 @@ class Message(object):
This method is similar to SerializeToString but doesn't check if the
message is initialized.
- Keyword Args:
- deterministic (bool): If true, requests deterministic serialization
- of the protobuf, with predictable ordering of map keys.
+ Keyword Args:
+ deterministic (bool): If true, requests deterministic serialization
+ of the protobuf, with predictable ordering of map keys.
Returns:
- bytes: A serialized representation of the partial message.
+ bytes: A serialized representation of the partial message.
"""
raise NotImplementedError
@@ -246,116 +246,116 @@ class Message(object):
# keywords. So they would become lambda_ or yield_.
# """
def ListFields(self):
- """Returns a list of (FieldDescriptor, value) tuples for present fields.
-
- A message field is non-empty if HasField() would return true. A singular
- primitive field is non-empty if HasField() would return true in proto2 or it
- is non zero in proto3. A repeated field is non-empty if it contains at least
- one element. The fields are ordered by field number.
-
- Returns:
- list[tuple(FieldDescriptor, value)]: field descriptors and values
- for all fields in the message which are not empty. The values vary by
- field type.
- """
+ """Returns a list of (FieldDescriptor, value) tuples for present fields.
+
+ A message field is non-empty if HasField() would return true. A singular
+ primitive field is non-empty if HasField() would return true in proto2 or it
+ is non zero in proto3. A repeated field is non-empty if it contains at least
+ one element. The fields are ordered by field number.
+
+ Returns:
+ list[tuple(FieldDescriptor, value)]: field descriptors and values
+ for all fields in the message which are not empty. The values vary by
+ field type.
+ """
raise NotImplementedError
def HasField(self, field_name):
- """Checks if a certain field is set for the message.
-
- For a oneof group, checks if any field inside is set. Note that if the
- field_name is not defined in the message descriptor, :exc:`ValueError` will
- be raised.
-
- Args:
- field_name (str): The name of the field to check for presence.
-
- Returns:
- bool: Whether a value has been set for the named field.
-
- Raises:
- ValueError: if the `field_name` is not a member of this message.
- """
+ """Checks if a certain field is set for the message.
+
+ For a oneof group, checks if any field inside is set. Note that if the
+ field_name is not defined in the message descriptor, :exc:`ValueError` will
+ be raised.
+
+ Args:
+ field_name (str): The name of the field to check for presence.
+
+ Returns:
+ bool: Whether a value has been set for the named field.
+
+ Raises:
+ ValueError: if the `field_name` is not a member of this message.
+ """
raise NotImplementedError
def ClearField(self, field_name):
- """Clears the contents of a given field.
-
- Inside a oneof group, clears the field set. If the name neither refers to a
- defined field or oneof group, :exc:`ValueError` is raised.
-
- Args:
- field_name (str): The name of the field to check for presence.
-
- Raises:
- ValueError: if the `field_name` is not a member of this message.
- """
+ """Clears the contents of a given field.
+
+ Inside a oneof group, clears the field set. If the name neither refers to a
+ defined field or oneof group, :exc:`ValueError` is raised.
+
+ Args:
+ field_name (str): The name of the field to check for presence.
+
+ Raises:
+ ValueError: if the `field_name` is not a member of this message.
+ """
raise NotImplementedError
def WhichOneof(self, oneof_group):
- """Returns the name of the field that is set inside a oneof group.
-
- If no field is set, returns None.
-
- Args:
- oneof_group (str): the name of the oneof group to check.
-
- Returns:
- str or None: The name of the group that is set, or None.
-
- Raises:
- ValueError: no group with the given name exists
- """
+ """Returns the name of the field that is set inside a oneof group.
+
+ If no field is set, returns None.
+
+ Args:
+ oneof_group (str): the name of the oneof group to check.
+
+ Returns:
+ str or None: The name of the group that is set, or None.
+
+ Raises:
+ ValueError: no group with the given name exists
+ """
raise NotImplementedError
def HasExtension(self, extension_handle):
- """Checks if a certain extension is present for this message.
-
- Extensions are retrieved using the :attr:`Extensions` mapping (if present).
-
- Args:
- extension_handle: The handle for the extension to check.
-
- Returns:
- bool: Whether the extension is present for this message.
-
- Raises:
- KeyError: if the extension is repeated. Similar to repeated fields,
- there is no separate notion of presence: a "not present" repeated
- extension is an empty list.
- """
+ """Checks if a certain extension is present for this message.
+
+ Extensions are retrieved using the :attr:`Extensions` mapping (if present).
+
+ Args:
+ extension_handle: The handle for the extension to check.
+
+ Returns:
+ bool: Whether the extension is present for this message.
+
+ Raises:
+ KeyError: if the extension is repeated. Similar to repeated fields,
+ there is no separate notion of presence: a "not present" repeated
+ extension is an empty list.
+ """
raise NotImplementedError
def ClearExtension(self, extension_handle):
- """Clears the contents of a given extension.
-
- Args:
- extension_handle: The handle for the extension to clear.
- """
- raise NotImplementedError
-
- def UnknownFields(self):
- """Returns the UnknownFieldSet.
-
- Returns:
- UnknownFieldSet: The unknown fields stored in this message.
- """
+ """Clears the contents of a given extension.
+
+ Args:
+ extension_handle: The handle for the extension to clear.
+ """
raise NotImplementedError
+ def UnknownFields(self):
+ """Returns the UnknownFieldSet.
+
+ Returns:
+ UnknownFieldSet: The unknown fields stored in this message.
+ """
+ raise NotImplementedError
+
def DiscardUnknownFields(self):
- """Clears all fields in the :class:`UnknownFieldSet`.
-
- This operation is recursive for nested message.
- """
+ """Clears all fields in the :class:`UnknownFieldSet`.
+
+ This operation is recursive for nested message.
+ """
raise NotImplementedError
def ByteSize(self):
"""Returns the serialized size of this message.
-
+
Recursively calls ByteSize() on all contained messages.
-
- Returns:
- int: The number of bytes required to serialize this message.
+
+ Returns:
+ int: The number of bytes required to serialize this message.
"""
raise NotImplementedError
@@ -387,27 +387,27 @@ class Message(object):
def __setstate__(self, state):
"""Support the pickle protocol."""
self.__init__()
- serialized = state['serialized']
- # On Python 3, using encoding='latin1' is required for unpickling
- # protos pickled by Python 2.
- if not isinstance(serialized, bytes):
- serialized = serialized.encode('latin1')
- self.ParseFromString(serialized)
-
- def __reduce__(self):
- message_descriptor = self.DESCRIPTOR
- if message_descriptor.containing_type is None:
- return type(self), (), self.__getstate__()
- # the message type must be nested.
- # Python does not pickle nested classes; use the symbol_database on the
- # receiving end.
- container = message_descriptor
- return (_InternalConstructMessage, (container.full_name,),
- self.__getstate__())
-
-
-def _InternalConstructMessage(full_name):
- """Constructs a nested message."""
- from google.protobuf import symbol_database # pylint:disable=g-import-not-at-top
-
- return symbol_database.Default().GetSymbol(full_name)()
+ serialized = state['serialized']
+ # On Python 3, using encoding='latin1' is required for unpickling
+ # protos pickled by Python 2.
+ if not isinstance(serialized, bytes):
+ serialized = serialized.encode('latin1')
+ self.ParseFromString(serialized)
+
+ def __reduce__(self):
+ message_descriptor = self.DESCRIPTOR
+ if message_descriptor.containing_type is None:
+ return type(self), (), self.__getstate__()
+ # the message type must be nested.
+ # Python does not pickle nested classes; use the symbol_database on the
+ # receiving end.
+ container = message_descriptor
+ return (_InternalConstructMessage, (container.full_name,),
+ self.__getstate__())
+
+
+def _InternalConstructMessage(full_name):
+ """Constructs a nested message."""
+ from google.protobuf import symbol_database # pylint:disable=g-import-not-at-top
+
+ return symbol_database.Default().GetSymbol(full_name)()
diff --git a/contrib/python/protobuf/py2/google/protobuf/message_factory.py b/contrib/python/protobuf/py2/google/protobuf/message_factory.py
index 7dfaec88e1..8ff16c6023 100644
--- a/contrib/python/protobuf/py2/google/protobuf/message_factory.py
+++ b/contrib/python/protobuf/py2/google/protobuf/message_factory.py
@@ -39,20 +39,20 @@ my_proto_instance = message_classes['some.proto.package.MessageName']()
__author__ = 'matthewtoia@google.com (Matt Toia)'
-from google.protobuf.internal import api_implementation
+from google.protobuf.internal import api_implementation
from google.protobuf import descriptor_pool
from google.protobuf import message
-if api_implementation.Type() == 'cpp':
- from google.protobuf.pyext import cpp_message as message_impl
-else:
- from google.protobuf.internal import python_message as message_impl
-
-
-# The type of all Message classes.
-_GENERATED_PROTOCOL_MESSAGE_TYPE = message_impl.GeneratedProtocolMessageType
-
+if api_implementation.Type() == 'cpp':
+ from google.protobuf.pyext import cpp_message as message_impl
+else:
+ from google.protobuf.internal import python_message as message_impl
+
+# The type of all Message classes.
+_GENERATED_PROTOCOL_MESSAGE_TYPE = message_impl.GeneratedProtocolMessageType
+
+
class MessageFactory(object):
"""Factory for creating Proto2 messages from descriptors in a pool."""
@@ -64,7 +64,7 @@ class MessageFactory(object):
self._classes = {}
def GetPrototype(self, descriptor):
- """Obtains a proto2 message class based on the passed in descriptor.
+ """Obtains a proto2 message class based on the passed in descriptor.
Passing a descriptor with a fully qualified name matching a previous
invocation will cause the same class to be returned.
@@ -76,52 +76,52 @@ class MessageFactory(object):
A class describing the passed in descriptor.
"""
if descriptor not in self._classes:
- result_class = self.CreatePrototype(descriptor)
- # The assignment to _classes is redundant for the base implementation, but
- # might avoid confusion in cases where CreatePrototype gets overridden and
- # does not call the base implementation.
+ result_class = self.CreatePrototype(descriptor)
+ # The assignment to _classes is redundant for the base implementation, but
+ # might avoid confusion in cases where CreatePrototype gets overridden and
+ # does not call the base implementation.
self._classes[descriptor] = result_class
- return result_class
+ return result_class
return self._classes[descriptor]
- def CreatePrototype(self, descriptor):
- """Builds a proto2 message class based on the passed in descriptor.
-
- Don't call this function directly, it always creates a new class. Call
- GetPrototype() instead. This method is meant to be overridden in subblasses
- to perform additional operations on the newly constructed class.
-
- Args:
- descriptor: The descriptor to build from.
-
- Returns:
- A class describing the passed in descriptor.
- """
- descriptor_name = descriptor.name
- if str is bytes: # PY2
- descriptor_name = descriptor.name.encode('ascii', 'ignore')
- result_class = _GENERATED_PROTOCOL_MESSAGE_TYPE(
- descriptor_name,
- (message.Message,),
- {
- 'DESCRIPTOR': descriptor,
- # If module not set, it wrongly points to message_factory module.
- '__module__': None,
- })
- result_class._FACTORY = self # pylint: disable=protected-access
- # Assign in _classes before doing recursive calls to avoid infinite
- # recursion.
- self._classes[descriptor] = result_class
- for field in descriptor.fields:
- if field.message_type:
- self.GetPrototype(field.message_type)
- for extension in result_class.DESCRIPTOR.extensions:
- if extension.containing_type not in self._classes:
- self.GetPrototype(extension.containing_type)
- extended_class = self._classes[extension.containing_type]
- extended_class.RegisterExtension(extension)
- return result_class
-
+ def CreatePrototype(self, descriptor):
+ """Builds a proto2 message class based on the passed in descriptor.
+
+ Don't call this function directly, it always creates a new class. Call
+ GetPrototype() instead. This method is meant to be overridden in subblasses
+ to perform additional operations on the newly constructed class.
+
+ Args:
+ descriptor: The descriptor to build from.
+
+ Returns:
+ A class describing the passed in descriptor.
+ """
+ descriptor_name = descriptor.name
+ if str is bytes: # PY2
+ descriptor_name = descriptor.name.encode('ascii', 'ignore')
+ result_class = _GENERATED_PROTOCOL_MESSAGE_TYPE(
+ descriptor_name,
+ (message.Message,),
+ {
+ 'DESCRIPTOR': descriptor,
+ # If module not set, it wrongly points to message_factory module.
+ '__module__': None,
+ })
+ result_class._FACTORY = self # pylint: disable=protected-access
+ # Assign in _classes before doing recursive calls to avoid infinite
+ # recursion.
+ self._classes[descriptor] = result_class
+ for field in descriptor.fields:
+ if field.message_type:
+ self.GetPrototype(field.message_type)
+ for extension in result_class.DESCRIPTOR.extensions:
+ if extension.containing_type not in self._classes:
+ self.GetPrototype(extension.containing_type)
+ extended_class = self._classes[extension.containing_type]
+ extended_class.RegisterExtension(extension)
+ return result_class
+
def GetMessages(self, files):
"""Gets all the messages from a specified file.
@@ -166,22 +166,22 @@ def GetMessages(file_protos):
"""Builds a dictionary of all the messages available in a set of files.
Args:
- file_protos: Iterable of FileDescriptorProto to build messages out of.
+ file_protos: Iterable of FileDescriptorProto to build messages out of.
Returns:
A dictionary mapping proto names to the message classes. This will include
any dependent messages as well as any messages defined in the same file as
a specified message.
"""
- # The cpp implementation of the protocol buffer library requires to add the
- # message in topological order of the dependency graph.
- file_by_name = {file_proto.name: file_proto for file_proto in file_protos}
- def _AddFile(file_proto):
- for dependency in file_proto.dependency:
- if dependency in file_by_name:
- # Remove from elements to be visited, in order to cut cycles.
- _AddFile(file_by_name.pop(dependency))
+ # The cpp implementation of the protocol buffer library requires to add the
+ # message in topological order of the dependency graph.
+ file_by_name = {file_proto.name: file_proto for file_proto in file_protos}
+ def _AddFile(file_proto):
+ for dependency in file_proto.dependency:
+ if dependency in file_by_name:
+ # Remove from elements to be visited, in order to cut cycles.
+ _AddFile(file_by_name.pop(dependency))
_FACTORY.pool.Add(file_proto)
- while file_by_name:
- _AddFile(file_by_name.popitem()[1])
+ while file_by_name:
+ _AddFile(file_by_name.popitem()[1])
return _FACTORY.GetMessages([file_proto.name for file_proto in file_protos])
diff --git a/contrib/python/protobuf/py2/google/protobuf/proto_api.h b/contrib/python/protobuf/py2/google/protobuf/proto_api.h
index c869bce058..420c54a723 100644
--- a/contrib/python/protobuf/py2/google/protobuf/proto_api.h
+++ b/contrib/python/protobuf/py2/google/protobuf/proto_api.h
@@ -1,123 +1,123 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// This file can be included by other C++ libraries, typically extension modules
-// which want to interact with the Python Messages coming from the "cpp"
-// implementation of protocol buffers.
-//
-// Usage:
-// Declare a (probably static) variable to hold the API:
-// const PyProto_API* py_proto_api;
-// In some initialization function, write:
-// py_proto_api = static_cast<const PyProto_API*>(PyCapsule_Import(
-// PyProtoAPICapsuleName(), 0));
-// if (!py_proto_api) { ...handle ImportError... }
-// Then use the methods of the returned class:
-// py_proto_api->GetMessagePointer(...);
-
-#ifndef GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
-#define GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
-
-#include <Python.h>
-
-#include <google/protobuf/descriptor_database.h>
-#include <google/protobuf/message.h>
-
-namespace google {
-namespace protobuf {
-namespace python {
-
-// Note on the implementation:
-// This API is designed after
-// https://docs.python.org/3/extending/extending.html#providing-a-c-api-for-an-extension-module
-// The class below contains no mutable state, and all methods are "const";
-// we use a C++ class instead of a C struct with functions pointers just because
-// the code looks more readable.
-struct PyProto_API {
- // The API object is created at initialization time and never freed.
- // This destructor is never called.
- virtual ~PyProto_API() {}
-
- // Operations on Messages.
-
- // If the passed object is a Python Message, returns its internal pointer.
- // Otherwise, returns NULL with an exception set.
- virtual const Message* GetMessagePointer(PyObject* msg) const = 0;
-
- // If the passed object is a Python Message, returns a mutable pointer.
- // Otherwise, returns NULL with an exception set.
- // This function will succeed only if there are no other Python objects
- // pointing to the message, like submessages or repeated containers.
- // With the current implementation, only empty messages are in this case.
- virtual Message* GetMutableMessagePointer(PyObject* msg) const = 0;
-
- // Expose the underlying DescriptorPool and MessageFactory to enable C++ code
- // to create Python-compatible message.
- virtual const DescriptorPool* GetDefaultDescriptorPool() const = 0;
- virtual MessageFactory* GetDefaultMessageFactory() const = 0;
-
- // Allocate a new protocol buffer as a python object for the provided
- // descriptor. This function works even if no Python module has been imported
- // for the corresponding protocol buffer class.
- // The factory is usually null; when provided, it is the MessageFactory which
- // owns the Python class, and will be used to find and create Extensions for
- // this message.
- // When null is returned, a python error has already been set.
- virtual PyObject* NewMessage(const Descriptor* descriptor,
- PyObject* py_message_factory) const = 0;
-
- // Allocate a new protocol buffer where the underlying object is owned by C++.
- // The factory must currently be null. This function works even if no Python
- // module has been imported for the corresponding protocol buffer class.
- // When null is returned, a python error has already been set.
- //
- // Since this call returns a python object owned by C++, some operations
- // are risky, and it must be used carefully. In particular:
- // * Avoid modifying the returned object from the C++ side while there are
- // existing python references to it or it's subobjects.
- // * Avoid using python references to this object or any subobjects after the
- // C++ object has been freed.
- // * Calling this with the same C++ pointer will result in multiple distinct
- // python objects referencing the same C++ object.
- virtual PyObject* NewMessageOwnedExternally(
- Message* msg, PyObject* py_message_factory) const = 0;
-};
-
-inline const char* PyProtoAPICapsuleName() {
- static const char kCapsuleName[] =
- "google.protobuf.pyext._message.proto_API";
- return kCapsuleName;
-}
-
-} // namespace python
-} // namespace protobuf
-} // namespace google
-
-#endif // GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// This file can be included by other C++ libraries, typically extension modules
+// which want to interact with the Python Messages coming from the "cpp"
+// implementation of protocol buffers.
+//
+// Usage:
+// Declare a (probably static) variable to hold the API:
+// const PyProto_API* py_proto_api;
+// In some initialization function, write:
+// py_proto_api = static_cast<const PyProto_API*>(PyCapsule_Import(
+// PyProtoAPICapsuleName(), 0));
+// if (!py_proto_api) { ...handle ImportError... }
+// Then use the methods of the returned class:
+// py_proto_api->GetMessagePointer(...);
+
+#ifndef GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
+#define GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
+
+#include <Python.h>
+
+#include <google/protobuf/descriptor_database.h>
+#include <google/protobuf/message.h>
+
+namespace google {
+namespace protobuf {
+namespace python {
+
+// Note on the implementation:
+// This API is designed after
+// https://docs.python.org/3/extending/extending.html#providing-a-c-api-for-an-extension-module
+// The class below contains no mutable state, and all methods are "const";
+// we use a C++ class instead of a C struct with functions pointers just because
+// the code looks more readable.
+struct PyProto_API {
+ // The API object is created at initialization time and never freed.
+ // This destructor is never called.
+ virtual ~PyProto_API() {}
+
+ // Operations on Messages.
+
+ // If the passed object is a Python Message, returns its internal pointer.
+ // Otherwise, returns NULL with an exception set.
+ virtual const Message* GetMessagePointer(PyObject* msg) const = 0;
+
+ // If the passed object is a Python Message, returns a mutable pointer.
+ // Otherwise, returns NULL with an exception set.
+ // This function will succeed only if there are no other Python objects
+ // pointing to the message, like submessages or repeated containers.
+ // With the current implementation, only empty messages are in this case.
+ virtual Message* GetMutableMessagePointer(PyObject* msg) const = 0;
+
+ // Expose the underlying DescriptorPool and MessageFactory to enable C++ code
+ // to create Python-compatible message.
+ virtual const DescriptorPool* GetDefaultDescriptorPool() const = 0;
+ virtual MessageFactory* GetDefaultMessageFactory() const = 0;
+
+ // Allocate a new protocol buffer as a python object for the provided
+ // descriptor. This function works even if no Python module has been imported
+ // for the corresponding protocol buffer class.
+ // The factory is usually null; when provided, it is the MessageFactory which
+ // owns the Python class, and will be used to find and create Extensions for
+ // this message.
+ // When null is returned, a python error has already been set.
+ virtual PyObject* NewMessage(const Descriptor* descriptor,
+ PyObject* py_message_factory) const = 0;
+
+ // Allocate a new protocol buffer where the underlying object is owned by C++.
+ // The factory must currently be null. This function works even if no Python
+ // module has been imported for the corresponding protocol buffer class.
+ // When null is returned, a python error has already been set.
+ //
+ // Since this call returns a python object owned by C++, some operations
+ // are risky, and it must be used carefully. In particular:
+ // * Avoid modifying the returned object from the C++ side while there are
+ // existing python references to it or it's subobjects.
+ // * Avoid using python references to this object or any subobjects after the
+ // C++ object has been freed.
+ // * Calling this with the same C++ pointer will result in multiple distinct
+ // python objects referencing the same C++ object.
+ virtual PyObject* NewMessageOwnedExternally(
+ Message* msg, PyObject* py_message_factory) const = 0;
+};
+
+inline const char* PyProtoAPICapsuleName() {
+ static const char kCapsuleName[] =
+ "google.protobuf.pyext._message.proto_API";
+ return kCapsuleName;
+}
+
+} // namespace python
+} // namespace protobuf
+} // namespace google
+
+#endif // GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/proto_builder.py b/contrib/python/protobuf/py2/google/protobuf/proto_builder.py
index 2b7dddcbd3..115e50319e 100644
--- a/contrib/python/protobuf/py2/google/protobuf/proto_builder.py
+++ b/contrib/python/protobuf/py2/google/protobuf/proto_builder.py
@@ -31,14 +31,14 @@
"""Dynamic Protobuf class creator."""
try:
- from collections import OrderedDict
+ from collections import OrderedDict
except ImportError:
- from ordereddict import OrderedDict #PY26
+ from ordereddict import OrderedDict #PY26
import hashlib
import os
from google.protobuf import descriptor_pb2
-from google.protobuf import descriptor
+from google.protobuf import descriptor
from google.protobuf import message_factory
@@ -125,12 +125,12 @@ def _MakeFileDescriptorProto(proto_file_name, full_name, field_items):
for f_number, (f_name, f_type) in enumerate(field_items, 1):
field_proto = desc_proto.field.add()
field_proto.name = f_name
- # # If the number falls in the reserved range, reassign it to the correct
- # # number after the range.
- if f_number >= descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER:
- f_number += (
- descriptor.FieldDescriptor.LAST_RESERVED_FIELD_NUMBER -
- descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER + 1)
+ # # If the number falls in the reserved range, reassign it to the correct
+ # # number after the range.
+ if f_number >= descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER:
+ f_number += (
+ descriptor.FieldDescriptor.LAST_RESERVED_FIELD_NUMBER -
+ descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER + 1)
field_proto.number = f_number
field_proto.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
field_proto.type = f_type
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor.cc
index de788afa2f..b6a495e5b6 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor.cc
@@ -30,24 +30,24 @@
// Author: petar@google.com (Petar Petrov)
-#include <google/protobuf/pyext/descriptor.h>
-
+#include <google/protobuf/pyext/descriptor.h>
+
#include <Python.h>
#include <frameobject.h>
-
-#include <cstdint>
-#include <string>
-#include <unordered_map>
-
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/dynamic_message.h>
-#include <google/protobuf/pyext/descriptor_containers.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/stubs/hash.h>
+
+#include <cstdint>
+#include <string>
+#include <unordered_map>
+
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/pyext/descriptor_containers.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/stubs/hash.h>
#if PY_MAJOR_VERSION >= 3
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
@@ -58,12 +58,12 @@
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#endif
-#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
+#define PyString_AsStringAndSize(ob, charpp, sizep) \
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
namespace google {
@@ -76,9 +76,9 @@ namespace python {
// released.
// This is enough to support the "is" operator on live objects.
// All descriptors are stored here.
-std::unordered_map<const void*, PyObject*>* interned_descriptors;
+std::unordered_map<const void*, PyObject*>* interned_descriptors;
-PyObject* PyString_FromCppString(const TProtoStringType& str) {
+PyObject* PyString_FromCppString(const TProtoStringType& str) {
return PyString_FromStringAndSize(str.c_str(), str.size());
}
@@ -125,12 +125,12 @@ bool _CalledFromGeneratedFile(int stacklevel) {
PyErr_Clear();
return false;
}
- if ((filename_size < 3) ||
- (strcmp(&filename[filename_size - 3], ".py") != 0)) {
- // Cython's stack does not have .py file name and is not at global module
- // scope.
- return true;
- }
+ if ((filename_size < 3) ||
+ (strcmp(&filename[filename_size - 3], ".py") != 0)) {
+ // Cython's stack does not have .py file name and is not at global module
+ // scope.
+ return true;
+ }
if (filename_size < 7) {
// filename is too short.
return false;
@@ -139,11 +139,11 @@ bool _CalledFromGeneratedFile(int stacklevel) {
// Filename is not ending with _pb2.
return false;
}
-
- if (frame->f_globals != frame->f_locals) {
- // Not at global module scope
- return false;
- }
+
+ if (frame->f_globals != frame->f_locals) {
+ // Not at global module scope
+ return false;
+ }
#endif
return true;
}
@@ -192,21 +192,21 @@ const FileDescriptor* GetFileDescriptor(const MethodDescriptor* descriptor) {
return descriptor->service()->file();
}
-bool Reparse(
- PyMessageFactory* message_factory, const Message& from, Message* to) {
- // Reparse message.
- TProtoStringType serialized;
- from.SerializeToString(&serialized);
- io::CodedInputStream input(
- reinterpret_cast<const uint8_t*>(serialized.c_str()), serialized.size());
- input.SetExtensionRegistry(message_factory->pool->pool,
- message_factory->message_factory);
- bool success = to->ParseFromCodedStream(&input);
- if (!success) {
- return false;
- }
- return true;
-}
+bool Reparse(
+ PyMessageFactory* message_factory, const Message& from, Message* to) {
+ // Reparse message.
+ TProtoStringType serialized;
+ from.SerializeToString(&serialized);
+ io::CodedInputStream input(
+ reinterpret_cast<const uint8_t*>(serialized.c_str()), serialized.size());
+ input.SetExtensionRegistry(message_factory->pool->pool,
+ message_factory->message_factory);
+ bool success = to->ParseFromCodedStream(&input);
+ if (!success) {
+ return false;
+ }
+ return true;
+}
// Converts options into a Python protobuf, and cache the result.
//
// This is a bit tricky because options can contain extension fields defined in
@@ -216,48 +216,48 @@ bool Reparse(
// Always returns a new reference.
template<class DescriptorClass>
static PyObject* GetOrBuildOptions(const DescriptorClass *descriptor) {
- // Options are cached in the pool that owns the descriptor.
- // First search in the cache.
- PyDescriptorPool* caching_pool = GetDescriptorPool_FromPool(
+ // Options are cached in the pool that owns the descriptor.
+ // First search in the cache.
+ PyDescriptorPool* caching_pool = GetDescriptorPool_FromPool(
GetFileDescriptor(descriptor)->pool());
- std::unordered_map<const void*, PyObject*>* descriptor_options =
- caching_pool->descriptor_options;
+ std::unordered_map<const void*, PyObject*>* descriptor_options =
+ caching_pool->descriptor_options;
if (descriptor_options->find(descriptor) != descriptor_options->end()) {
PyObject *value = (*descriptor_options)[descriptor];
Py_INCREF(value);
return value;
}
- // Similar to the C++ implementation, we return an Options object from the
- // default (generated) factory, so that client code know that they can use
- // extensions from generated files:
- // d.GetOptions().Extensions[some_pb2.extension]
- //
- // The consequence is that extensions not defined in the default pool won't
- // be available. If needed, we could add an optional 'message_factory'
- // parameter to the GetOptions() function.
- PyMessageFactory* message_factory =
- GetDefaultDescriptorPool()->py_message_factory;
-
+ // Similar to the C++ implementation, we return an Options object from the
+ // default (generated) factory, so that client code know that they can use
+ // extensions from generated files:
+ // d.GetOptions().Extensions[some_pb2.extension]
+ //
+ // The consequence is that extensions not defined in the default pool won't
+ // be available. If needed, we could add an optional 'message_factory'
+ // parameter to the GetOptions() function.
+ PyMessageFactory* message_factory =
+ GetDefaultDescriptorPool()->py_message_factory;
+
// Build the Options object: get its Python class, and make a copy of the C++
// read-only instance.
const Message& options(descriptor->options());
const Descriptor *message_type = options.GetDescriptor();
- CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
+ CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
message_factory, message_type);
if (message_class == NULL) {
PyErr_Format(PyExc_TypeError, "Could not retrieve class for Options: %s",
message_type->full_name().c_str());
return NULL;
}
- ScopedPyObjectPtr args(PyTuple_New(0));
+ ScopedPyObjectPtr args(PyTuple_New(0));
ScopedPyObjectPtr value(
- PyObject_Call(message_class->AsPyObject(), args.get(), NULL));
- Py_DECREF(message_class);
+ PyObject_Call(message_class->AsPyObject(), args.get(), NULL));
+ Py_DECREF(message_class);
if (value == NULL) {
return NULL;
}
- if (!PyObject_TypeCheck(value.get(), CMessage_Type)) {
+ if (!PyObject_TypeCheck(value.get(), CMessage_Type)) {
PyErr_Format(PyExc_TypeError, "Invalid class for %s: %s",
message_type->full_name().c_str(),
Py_TYPE(value.get())->tp_name);
@@ -271,8 +271,8 @@ static PyObject* GetOrBuildOptions(const DescriptorClass *descriptor) {
cmsg->message->CopyFrom(options);
} else {
// Reparse options string! XXX call cmessage::MergeFromString
- if (!Reparse(message_factory, options, cmsg->message)) {
- PyErr_Format(PyExc_ValueError, "Error reparsing Options message");
+ if (!Reparse(message_factory, options, cmsg->message)) {
+ PyErr_Format(PyExc_ValueError, "Error reparsing Options message");
return NULL;
}
}
@@ -293,7 +293,7 @@ static PyObject* CopyToPythonProto(const DescriptorClass *descriptor,
const Descriptor* self_descriptor =
DescriptorProtoClass::default_instance().GetDescriptor();
CMessage* message = reinterpret_cast<CMessage*>(target);
- if (!PyObject_TypeCheck(target, CMessage_Type) ||
+ if (!PyObject_TypeCheck(target, CMessage_Type) ||
message->message->GetDescriptor() != self_descriptor) {
PyErr_Format(PyExc_TypeError, "Not a %s message",
self_descriptor->full_name().c_str());
@@ -303,16 +303,16 @@ static PyObject* CopyToPythonProto(const DescriptorClass *descriptor,
DescriptorProtoClass* descriptor_message =
static_cast<DescriptorProtoClass*>(message->message);
descriptor->CopyTo(descriptor_message);
- // Custom options might in unknown extensions. Reparse
- // the descriptor_message. Can't skip reparse when options unknown
- // fields is empty, because they might in sub descriptors' options.
- PyMessageFactory* message_factory =
- GetDefaultDescriptorPool()->py_message_factory;
- if (!Reparse(message_factory, *descriptor_message, descriptor_message)) {
- PyErr_Format(PyExc_ValueError, "Error reparsing descriptor message");
- return nullptr;
- }
-
+ // Custom options might in unknown extensions. Reparse
+ // the descriptor_message. Can't skip reparse when options unknown
+ // fields is empty, because they might in sub descriptors' options.
+ PyMessageFactory* message_factory =
+ GetDefaultDescriptorPool()->py_message_factory;
+ if (!Reparse(message_factory, *descriptor_message, descriptor_message)) {
+ PyErr_Format(PyExc_ValueError, "Error reparsing descriptor message");
+ return nullptr;
+ }
+
Py_RETURN_NONE;
}
@@ -360,15 +360,15 @@ PyObject* NewInternedDescriptor(PyTypeObject* type,
}
// See if the object is in the map of interned descriptors
- std::unordered_map<const void*, PyObject*>::iterator it =
- interned_descriptors->find(descriptor);
- if (it != interned_descriptors->end()) {
+ std::unordered_map<const void*, PyObject*>::iterator it =
+ interned_descriptors->find(descriptor);
+ if (it != interned_descriptors->end()) {
GOOGLE_DCHECK(Py_TYPE(it->second) == type);
Py_INCREF(it->second);
return it->second;
}
// Create a new descriptor object
- PyBaseDescriptor* py_descriptor = PyObject_GC_New(
+ PyBaseDescriptor* py_descriptor = PyObject_GC_New(
PyBaseDescriptor, type);
if (py_descriptor == NULL) {
return NULL;
@@ -376,7 +376,7 @@ PyObject* NewInternedDescriptor(PyTypeObject* type,
py_descriptor->descriptor = descriptor;
// and cache it.
- interned_descriptors->insert(
+ interned_descriptors->insert(
std::make_pair(descriptor, reinterpret_cast<PyObject*>(py_descriptor)));
// Ensures that the DescriptorPool stays alive.
@@ -390,69 +390,69 @@ PyObject* NewInternedDescriptor(PyTypeObject* type,
Py_INCREF(pool);
py_descriptor->pool = pool;
- PyObject_GC_Track(py_descriptor);
-
+ PyObject_GC_Track(py_descriptor);
+
if (was_created) {
*was_created = true;
}
return reinterpret_cast<PyObject*>(py_descriptor);
}
-static void Dealloc(PyObject* pself) {
- PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
+static void Dealloc(PyObject* pself) {
+ PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
// Remove from interned dictionary
- interned_descriptors->erase(self->descriptor);
- Py_CLEAR(self->pool);
- Py_TYPE(self)->tp_free(pself);
-}
-
-static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
- PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
- Py_VISIT(self->pool);
- return 0;
-}
-
-static int GcClear(PyObject* pself) {
- PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
+ interned_descriptors->erase(self->descriptor);
Py_CLEAR(self->pool);
- return 0;
-}
-
+ Py_TYPE(self)->tp_free(pself);
+}
+
+static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
+ PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
+ Py_VISIT(self->pool);
+ return 0;
+}
+
+static int GcClear(PyObject* pself) {
+ PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
+ Py_CLEAR(self->pool);
+ return 0;
+}
+
static PyGetSetDef Getters[] = {
{NULL}
};
PyTypeObject PyBaseDescriptor_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".DescriptorBase", // tp_name
- sizeof(PyBaseDescriptor), // tp_basicsize
- 0, // tp_itemsize
- (destructor)Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
- "Descriptors base class", // tp_doc
- GcTraverse, // tp_traverse
- GcClear, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- Getters, // tp_getset
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".DescriptorBase", // tp_name
+ sizeof(PyBaseDescriptor), // tp_basicsize
+ 0, // tp_itemsize
+ (destructor)Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
+ "Descriptors base class", // tp_doc
+ GcTraverse, // tp_traverse
+ GcClear, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ Getters, // tp_getset
};
} // namespace descriptor
@@ -485,7 +485,7 @@ static PyObject* GetFile(PyBaseDescriptor *self, void *closure) {
}
static PyObject* GetConcreteClass(PyBaseDescriptor* self, void *closure) {
- // Returns the canonical class for the given descriptor.
+ // Returns the canonical class for the given descriptor.
// This is the class that was registered with the primary descriptor pool
// which contains this descriptor.
// This might not be the one you expect! For example the returned object does
@@ -610,11 +610,11 @@ static int SetOptions(PyBaseDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
-
+static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
+
static PyObject* CopyToProto(PyBaseDescriptor *self, PyObject *target) {
return CopyToPythonProto<DescriptorProto>(_GetDescriptor(self), target);
}
@@ -674,8 +674,8 @@ static PyGetSetDef Getters[] = {
{ "is_extendable", (getter)IsExtendable, (setter)NULL},
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{ "syntax", (getter)GetSyntax, (setter)NULL, "Syntax"},
{NULL}
};
@@ -801,29 +801,29 @@ static PyObject* HasDefaultValue(PyBaseDescriptor *self, void *closure) {
static PyObject* GetDefaultValue(PyBaseDescriptor *self, void *closure) {
PyObject *result;
- if (_GetDescriptor(self)->is_repeated()) {
- return PyList_New(0);
- }
-
-
+ if (_GetDescriptor(self)->is_repeated()) {
+ return PyList_New(0);
+ }
+
+
switch (_GetDescriptor(self)->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
- int32_t value = _GetDescriptor(self)->default_value_int32();
+ int32_t value = _GetDescriptor(self)->default_value_int32();
result = PyInt_FromLong(value);
break;
}
case FieldDescriptor::CPPTYPE_INT64: {
- int64_t value = _GetDescriptor(self)->default_value_int64();
+ int64_t value = _GetDescriptor(self)->default_value_int64();
result = PyLong_FromLongLong(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT32: {
- uint32_t value = _GetDescriptor(self)->default_value_uint32();
+ uint32_t value = _GetDescriptor(self)->default_value_uint32();
result = PyInt_FromSize_t(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT64: {
- uint64_t value = _GetDescriptor(self)->default_value_uint64();
+ uint64_t value = _GetDescriptor(self)->default_value_uint64();
result = PyLong_FromUnsignedLongLong(value);
break;
}
@@ -843,7 +843,7 @@ static PyObject* GetDefaultValue(PyBaseDescriptor *self, void *closure) {
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- const TProtoStringType& value = _GetDescriptor(self)->default_value_string();
+ const TProtoStringType& value = _GetDescriptor(self)->default_value_string();
result = ToStringObject(_GetDescriptor(self), value);
break;
}
@@ -853,10 +853,10 @@ static PyObject* GetDefaultValue(PyBaseDescriptor *self, void *closure) {
result = PyInt_FromLong(value->number());
break;
}
- case FieldDescriptor::CPPTYPE_MESSAGE: {
- Py_RETURN_NONE;
- break;
- }
+ case FieldDescriptor::CPPTYPE_MESSAGE: {
+ Py_RETURN_NONE;
+ break;
+ }
default:
PyErr_Format(PyExc_NotImplementedError, "default value for %s",
_GetDescriptor(self)->full_name().c_str());
@@ -959,10 +959,10 @@ static int SetOptions(PyBaseDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
+static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
static PyGetSetDef Getters[] = {
{ "full_name", (getter)GetFullName, NULL, "Full name"},
@@ -992,8 +992,8 @@ static PyGetSetDef Getters[] = {
"Containing oneof"},
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{NULL}
};
@@ -1123,11 +1123,11 @@ static int SetOptions(PyBaseDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
-
+static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
+
static PyObject* CopyToProto(PyBaseDescriptor *self, PyObject *target) {
return CopyToPythonProto<EnumDescriptorProto>(_GetDescriptor(self), target);
}
@@ -1152,8 +1152,8 @@ static PyGetSetDef Getters[] = {
"Containing type"},
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{NULL}
};
@@ -1254,10 +1254,10 @@ static int SetOptions(PyBaseDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
+static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
static PyGetSetDef Getters[] = {
{ "name", (getter)GetName, NULL, "name"},
@@ -1267,8 +1267,8 @@ static PyGetSetDef Getters[] = {
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{NULL}
};
@@ -1328,7 +1328,7 @@ static const FileDescriptor* _GetDescriptor(PyFileDescriptor *self) {
static void Dealloc(PyFileDescriptor* self) {
Py_XDECREF(self->serialized_pb);
- descriptor::Dealloc(reinterpret_cast<PyObject*>(self));
+ descriptor::Dealloc(reinterpret_cast<PyObject*>(self));
}
static PyObject* GetPool(PyFileDescriptor *self, void *closure) {
@@ -1354,7 +1354,7 @@ static PyObject* GetSerializedPb(PyFileDescriptor *self, void *closure) {
}
FileDescriptorProto file_proto;
_GetDescriptor(self)->CopyTo(&file_proto);
- TProtoStringType contents;
+ TProtoStringType contents;
file_proto.SerializePartialToString(&contents);
self->serialized_pb = PyBytes_FromStringAndSize(
contents.c_str(), contents.size());
@@ -1411,11 +1411,11 @@ static int SetOptions(PyFileDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyFileDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
-
+static int SetSerializedOptions(PyFileDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
+
static PyObject* GetSyntax(PyFileDescriptor *self, void *closure) {
return PyString_InternFromString(
FileDescriptor::SyntaxName(_GetDescriptor(self)->syntax()));
@@ -1441,8 +1441,8 @@ static PyGetSetDef Getters[] = {
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{ "syntax", (getter)GetSyntax, (setter)NULL, "Syntax"},
{NULL}
};
@@ -1456,45 +1456,45 @@ static PyMethodDef Methods[] = {
} // namespace file_descriptor
PyTypeObject PyFileDescriptor_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".FileDescriptor", // tp_name
- sizeof(PyFileDescriptor), // tp_basicsize
- 0, // tp_itemsize
- (destructor)file_descriptor::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "A File Descriptor", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- file_descriptor::Methods, // tp_methods
- 0, // tp_members
- file_descriptor::Getters, // tp_getset
- &descriptor::PyBaseDescriptor_Type, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
- 0, // tp_alloc
- 0, // tp_new
- PyObject_GC_Del, // tp_free
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".FileDescriptor", // tp_name
+ sizeof(PyFileDescriptor), // tp_basicsize
+ 0, // tp_itemsize
+ (destructor)file_descriptor::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "A File Descriptor", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ file_descriptor::Methods, // tp_methods
+ 0, // tp_members
+ file_descriptor::Getters, // tp_getset
+ &descriptor::PyBaseDescriptor_Type, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ 0, // tp_new
+ PyObject_GC_Del, // tp_free
};
PyObject* PyFileDescriptor_FromDescriptor(
@@ -1588,11 +1588,11 @@ static int SetOptions(PyBaseDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
-
+static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
+
static PyGetSetDef Getters[] = {
{ "name", (getter)GetName, NULL, "Name"},
{ "full_name", (getter)GetFullName, NULL, "Full name"},
@@ -1601,8 +1601,8 @@ static PyGetSetDef Getters[] = {
{ "containing_type", (getter)GetContainingType, NULL, "Containing type"},
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{ "fields", (getter)GetFields, NULL, "Fields"},
{NULL}
};
@@ -1694,7 +1694,7 @@ static PyObject* FindMethodByName(PyBaseDescriptor *self, PyObject* arg) {
}
const MethodDescriptor* method_descriptor =
- _GetDescriptor(self)->FindMethodByName(StringParam(name, name_size));
+ _GetDescriptor(self)->FindMethodByName(StringParam(name, name_size));
if (method_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find method %.200s", name);
return NULL;
@@ -1962,9 +1962,9 @@ bool InitDescriptor() {
if (!InitDescriptorMappingTypes())
return false;
- // Initialize globals defined in this file.
- interned_descriptors = new std::unordered_map<const void*, PyObject*>;
-
+ // Initialize globals defined in this file.
+ interned_descriptors = new std::unordered_map<const void*, PyObject*>;
+
return true;
}
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor.h b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor.h
index 47efbe35d7..fda7d0ca43 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor.h
@@ -35,15 +35,15 @@
#include <Python.h>
-#include <google/protobuf/descriptor.h>
+#include <google/protobuf/descriptor.h>
namespace google {
namespace protobuf {
namespace python {
-// Should match the type of ConstStringParam.
-using StringParam = TProtoStringType;
-
+// Should match the type of ConstStringParam.
+using StringParam = TProtoStringType;
+
extern PyTypeObject PyMessageDescriptor_Type;
extern PyTypeObject PyFieldDescriptor_Type;
extern PyTypeObject PyEnumDescriptor_Type;
@@ -102,6 +102,6 @@ bool InitDescriptor();
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_containers.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_containers.cc
index 7990604ff0..64969fe426 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_containers.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_containers.cc
@@ -33,7 +33,7 @@
//
// They avoid the allocation of a full dictionary or a full list: they simply
// store a pointer to the parent descriptor, use the C++ Descriptor methods (see
-// net/proto2/public/descriptor.h) to retrieve other descriptors, and create
+// net/proto2/public/descriptor.h) to retrieve other descriptors, and create
// Python objects on the fly.
//
// The containers fully conform to abc.Mapping and abc.Sequence, and behave just
@@ -51,11 +51,11 @@
#include <Python.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/pyext/descriptor_containers.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/pyext/descriptor_containers.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#if PY_MAJOR_VERSION >= 3
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
@@ -64,12 +64,12 @@
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#endif
-#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
+#define PyString_AsStringAndSize(ob, charpp, sizep) \
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
namespace google {
@@ -80,15 +80,15 @@ struct PyContainer;
typedef int (*CountMethod)(PyContainer* self);
typedef const void* (*GetByIndexMethod)(PyContainer* self, int index);
-typedef const void* (*GetByNameMethod)(PyContainer* self,
- ConstStringParam name);
+typedef const void* (*GetByNameMethod)(PyContainer* self,
+ ConstStringParam name);
typedef const void* (*GetByCamelcaseNameMethod)(PyContainer* self,
- ConstStringParam name);
+ ConstStringParam name);
typedef const void* (*GetByNumberMethod)(PyContainer* self, int index);
typedef PyObject* (*NewObjectFromItemMethod)(const void* descriptor);
-typedef const TProtoStringType& (*GetItemNameMethod)(const void* descriptor);
-typedef const TProtoStringType& (*GetItemCamelcaseNameMethod)(
- const void* descriptor);
+typedef const TProtoStringType& (*GetItemNameMethod)(const void* descriptor);
+typedef const TProtoStringType& (*GetItemCamelcaseNameMethod)(
+ const void* descriptor);
typedef int (*GetItemNumberMethod)(const void* descriptor);
typedef int (*GetItemIndexMethod)(const void* descriptor);
@@ -183,7 +183,7 @@ static bool _GetItemByKey(PyContainer* self, PyObject* key, const void** item) {
return false;
}
*item = self->container_def->get_by_name_fn(
- self, StringParam(name, name_size));
+ self, StringParam(name, name_size));
return true;
}
case PyContainer::KIND_BYCAMELCASENAME:
@@ -200,7 +200,7 @@ static bool _GetItemByKey(PyContainer* self, PyObject* key, const void** item) {
return false;
}
*item = self->container_def->get_by_camelcase_name_fn(
- self, StringParam(camelcase_name, name_size));
+ self, StringParam(camelcase_name, name_size));
return true;
}
case PyContainer::KIND_BYNUMBER:
@@ -231,14 +231,14 @@ static PyObject* _NewKey_ByIndex(PyContainer* self, Py_ssize_t index) {
switch (self->kind) {
case PyContainer::KIND_BYNAME:
{
- const TProtoStringType& name(self->container_def->get_item_name_fn(item));
- return PyString_FromStringAndSize(name.c_str(), name.size());
+ const TProtoStringType& name(self->container_def->get_item_name_fn(item));
+ return PyString_FromStringAndSize(name.c_str(), name.size());
}
case PyContainer::KIND_BYCAMELCASENAME:
{
- const TProtoStringType& name(
- self->container_def->get_item_camelcase_name_fn(item));
- return PyString_FromStringAndSize(name.c_str(), name.size());
+ const TProtoStringType& name(
+ self->container_def->get_item_camelcase_name_fn(item));
+ return PyString_FromStringAndSize(name.c_str(), name.size());
}
case PyContainer::KIND_BYNUMBER:
{
@@ -641,7 +641,7 @@ int Find(PyContainer* self, PyObject* item) {
// the .proto file definition.
const void* descriptor_ptr = PyDescriptor_AsVoidPtr(item);
if (descriptor_ptr == NULL) {
- PyErr_Clear();
+ PyErr_Clear();
// Not a descriptor, it cannot be in the list.
return -1;
}
@@ -962,55 +962,55 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->field_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindFieldByName(name);
}
-static const void* GetByCamelcaseName(PyContainer* self,
- ConstStringParam name) {
+static const void* GetByCamelcaseName(PyContainer* self,
+ ConstStringParam name) {
return GetDescriptor(self)->FindFieldByCamelcaseName(name);
}
-static const void* GetByNumber(PyContainer* self, int number) {
+static const void* GetByNumber(PyContainer* self, int number) {
return GetDescriptor(self)->FindFieldByNumber(number);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->field(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static const TProtoStringType& GetItemCamelcaseName(const void* item) {
- return static_cast<ItemDescriptor>(item)->camelcase_name();
+static const TProtoStringType& GetItemCamelcaseName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->camelcase_name();
}
-static int GetItemNumber(const void* item) {
- return static_cast<ItemDescriptor>(item)->number();
+static int GetItemNumber(const void* item) {
+ return static_cast<ItemDescriptor>(item)->number();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"MessageFields",
- Count,
- GetByIndex,
- GetByName,
- GetByCamelcaseName,
- GetByNumber,
- NewObjectFromItem,
- GetItemName,
- GetItemCamelcaseName,
- GetItemNumber,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ GetByCamelcaseName,
+ GetByNumber,
+ NewObjectFromItem,
+ GetItemName,
+ GetItemCamelcaseName,
+ GetItemNumber,
+ GetItemIndex,
};
} // namespace fields
@@ -1040,38 +1040,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->nested_type_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindNestedTypeByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->nested_type(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyMessageDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyMessageDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"MessageNestedTypes",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace nested_types
@@ -1092,38 +1092,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->enum_type_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindEnumTypeByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->enum_type(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyEnumDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyEnumDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"MessageNestedEnums",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace enums
@@ -1155,11 +1155,11 @@ static int Count(PyContainer* self) {
return count;
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindEnumValueByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
// This is not optimal, but the number of enums *types* in a given message
// is small. This function is only used when iterating over the mapping.
const EnumDescriptor* enum_type = NULL;
@@ -1178,27 +1178,27 @@ static const void* GetByIndex(PyContainer* self, int index) {
return enum_type->value(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyEnumValueDescriptor_FromDescriptor(
- static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyEnumValueDescriptor_FromDescriptor(
+ static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
static DescriptorContainerDef ContainerDef = {
"MessageEnumValues",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- NULL,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ NULL,
};
} // namespace enumvalues
@@ -1215,38 +1215,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->extension_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindExtensionByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->extension(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"MessageExtensions",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace extensions
@@ -1267,38 +1267,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->oneof_decl_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindOneofByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->oneof_decl(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyOneofDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyOneofDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"MessageOneofs",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace oneofs
@@ -1329,47 +1329,47 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->value_count();
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->value(index);
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindValueByName(name);
}
-static const void* GetByNumber(PyContainer* self, int number) {
+static const void* GetByNumber(PyContainer* self, int number) {
return GetDescriptor(self)->FindValueByNumber(number);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyEnumValueDescriptor_FromDescriptor(
- static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyEnumValueDescriptor_FromDescriptor(
+ static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemNumber(const void* item) {
- return static_cast<ItemDescriptor>(item)->number();
+static int GetItemNumber(const void* item) {
+ return static_cast<ItemDescriptor>(item)->number();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"EnumValues",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- GetByNumber,
- NewObjectFromItem,
- GetItemName,
- NULL,
- GetItemNumber,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ GetByNumber,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ GetItemNumber,
+ GetItemIndex,
};
} // namespace enumvalues
@@ -1404,30 +1404,30 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->field_count();
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->field(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index_in_oneof();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index_in_oneof();
}
static DescriptorContainerDef ContainerDef = {
"OneofFields",
- Count,
- GetByIndex,
- NULL,
- NULL,
- NULL,
- NewObjectFromItem,
- NULL,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ NULL,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ NULL,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace fields
@@ -1454,38 +1454,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->method_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindMethodByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->method(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyMethodDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyMethodDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"ServiceMethods",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace methods
@@ -1516,38 +1516,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->message_type_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindMessageTypeByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->message_type(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyMessageDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyMessageDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"FileMessages",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace messages
@@ -1564,38 +1564,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->enum_type_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindEnumTypeByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->enum_type(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyEnumDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyEnumDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"FileEnums",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace enums
@@ -1612,38 +1612,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->extension_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindExtensionByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->extension(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"FileExtensions",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace extensions
@@ -1660,38 +1660,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->service_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindServiceByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->service(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyServiceDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyServiceDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"FileServices",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace services
@@ -1708,26 +1708,26 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->dependency_count();
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->dependency(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFileDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFileDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
static DescriptorContainerDef ContainerDef = {
"FileDependencies",
- Count,
- GetByIndex,
- NULL,
- NULL,
- NULL,
- NewObjectFromItem,
- NULL,
- NULL,
- NULL,
- NULL,
+ Count,
+ GetByIndex,
+ NULL,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
};
} // namespace dependencies
@@ -1744,26 +1744,26 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->public_dependency_count();
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->public_dependency(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFileDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFileDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
static DescriptorContainerDef ContainerDef = {
"FilePublicDependencies",
- Count,
- GetByIndex,
- NULL,
- NULL,
- NULL,
- NewObjectFromItem,
- NULL,
- NULL,
- NULL,
- NULL,
+ Count,
+ GetByIndex,
+ NULL,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
};
} // namespace public_dependencies
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_containers.h b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_containers.h
index 4e05c58e2b..2e7960f227 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_containers.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_containers.h
@@ -104,6 +104,6 @@ PyObject* NewServiceMethodsByName(const ServiceDescriptor* descriptor);
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_CONTAINERS_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_database.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_database.cc
index be8089841c..fdf53cab1d 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_database.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_database.cc
@@ -31,15 +31,15 @@
// This file defines a C++ DescriptorDatabase, which wraps a Python Database
// and delegate all its operations to Python methods.
-#include <google/protobuf/pyext/descriptor_database.h>
+#include <google/protobuf/pyext/descriptor_database.h>
-#include <cstdint>
-
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <cstdint>
+
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
namespace google {
namespace protobuf {
@@ -72,7 +72,7 @@ static bool GetFileDescriptorProto(PyObject* py_descriptor,
const Descriptor* filedescriptor_descriptor =
FileDescriptorProto::default_instance().GetDescriptor();
CMessage* message = reinterpret_cast<CMessage*>(py_descriptor);
- if (PyObject_TypeCheck(py_descriptor, CMessage_Type) &&
+ if (PyObject_TypeCheck(py_descriptor, CMessage_Type) &&
message->message->GetDescriptor() == filedescriptor_descriptor) {
// Fast path: Just use the pointer.
FileDescriptorProto* file_proto =
@@ -110,7 +110,7 @@ static bool GetFileDescriptorProto(PyObject* py_descriptor,
}
// Find a file by file name.
-bool PyDescriptorDatabase::FindFileByName(const TProtoStringType& filename,
+bool PyDescriptorDatabase::FindFileByName(const TProtoStringType& filename,
FileDescriptorProto* output) {
ScopedPyObjectPtr py_descriptor(PyObject_CallMethod(
py_database_, "FindFileByName", "s#", filename.c_str(), filename.size()));
@@ -119,7 +119,7 @@ bool PyDescriptorDatabase::FindFileByName(const TProtoStringType& filename,
// Find the file that declares the given fully-qualified symbol name.
bool PyDescriptorDatabase::FindFileContainingSymbol(
- const TProtoStringType& symbol_name, FileDescriptorProto* output) {
+ const TProtoStringType& symbol_name, FileDescriptorProto* output) {
ScopedPyObjectPtr py_descriptor(
PyObject_CallMethod(py_database_, "FindFileContainingSymbol", "s#",
symbol_name.c_str(), symbol_name.size()));
@@ -130,7 +130,7 @@ bool PyDescriptorDatabase::FindFileContainingSymbol(
// with the given field number.
// Python DescriptorDatabases are not required to implement this method.
bool PyDescriptorDatabase::FindFileContainingExtension(
- const TProtoStringType& containing_type, int field_number,
+ const TProtoStringType& containing_type, int field_number,
FileDescriptorProto* output) {
ScopedPyObjectPtr py_method(
PyObject_GetAttrString(py_database_, "FindFileContainingExtension"));
@@ -145,43 +145,43 @@ bool PyDescriptorDatabase::FindFileContainingExtension(
return GetFileDescriptorProto(py_descriptor.get(), output);
}
-// Finds the tag numbers used by all known extensions of
-// containing_type, and appends them to output in an undefined
-// order.
-// Python DescriptorDatabases are not required to implement this method.
-bool PyDescriptorDatabase::FindAllExtensionNumbers(
- const TProtoStringType& containing_type, std::vector<int>* output) {
- ScopedPyObjectPtr py_method(
- PyObject_GetAttrString(py_database_, "FindAllExtensionNumbers"));
- if (py_method == NULL) {
- // This method is not implemented, returns without error.
- PyErr_Clear();
- return false;
- }
- ScopedPyObjectPtr py_list(
- PyObject_CallFunction(py_method.get(), "s#", containing_type.c_str(),
- containing_type.size()));
- if (py_list == NULL) {
- PyErr_Print();
- return false;
- }
- Py_ssize_t size = PyList_Size(py_list.get());
- int64_t item_value;
- for (Py_ssize_t i = 0 ; i < size; ++i) {
- ScopedPyObjectPtr item(PySequence_GetItem(py_list.get(), i));
- item_value = PyLong_AsLong(item.get());
- if (item_value < 0) {
- GOOGLE_LOG(ERROR)
- << "FindAllExtensionNumbers method did not return "
- << "valid extension numbers.";
- PyErr_Print();
- return false;
- }
- output->push_back(item_value);
- }
- return true;
-}
-
+// Finds the tag numbers used by all known extensions of
+// containing_type, and appends them to output in an undefined
+// order.
+// Python DescriptorDatabases are not required to implement this method.
+bool PyDescriptorDatabase::FindAllExtensionNumbers(
+ const TProtoStringType& containing_type, std::vector<int>* output) {
+ ScopedPyObjectPtr py_method(
+ PyObject_GetAttrString(py_database_, "FindAllExtensionNumbers"));
+ if (py_method == NULL) {
+ // This method is not implemented, returns without error.
+ PyErr_Clear();
+ return false;
+ }
+ ScopedPyObjectPtr py_list(
+ PyObject_CallFunction(py_method.get(), "s#", containing_type.c_str(),
+ containing_type.size()));
+ if (py_list == NULL) {
+ PyErr_Print();
+ return false;
+ }
+ Py_ssize_t size = PyList_Size(py_list.get());
+ int64_t item_value;
+ for (Py_ssize_t i = 0 ; i < size; ++i) {
+ ScopedPyObjectPtr item(PySequence_GetItem(py_list.get(), i));
+ item_value = PyLong_AsLong(item.get());
+ if (item_value < 0) {
+ GOOGLE_LOG(ERROR)
+ << "FindAllExtensionNumbers method did not return "
+ << "valid extension numbers.";
+ PyErr_Print();
+ return false;
+ }
+ output->push_back(item_value);
+ }
+ return true;
+}
+
} // namespace python
} // namespace protobuf
} // namespace google
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_database.h b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_database.h
index 59918a6d92..3c7dc88c37 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_database.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_database.h
@@ -33,7 +33,7 @@
#include <Python.h>
-#include <google/protobuf/descriptor_database.h>
+#include <google/protobuf/descriptor_database.h>
namespace google {
namespace protobuf {
@@ -48,27 +48,27 @@ class PyDescriptorDatabase : public DescriptorDatabase {
// with a copy of FileDescriptorProto.
// Find a file by file name.
- bool FindFileByName(const TProtoStringType& filename, FileDescriptorProto* output);
+ bool FindFileByName(const TProtoStringType& filename, FileDescriptorProto* output);
// Find the file that declares the given fully-qualified symbol name.
- bool FindFileContainingSymbol(const TProtoStringType& symbol_name,
+ bool FindFileContainingSymbol(const TProtoStringType& symbol_name,
FileDescriptorProto* output);
// Find the file which defines an extension extending the given message type
// with the given field number.
// Containing_type must be a fully-qualified type name.
// Python objects are not required to implement this method.
- bool FindFileContainingExtension(const TProtoStringType& containing_type,
+ bool FindFileContainingExtension(const TProtoStringType& containing_type,
int field_number,
FileDescriptorProto* output);
- // Finds the tag numbers used by all known extensions of
- // containing_type, and appends them to output in an undefined
- // order.
- // Python objects are not required to implement this method.
- bool FindAllExtensionNumbers(const TProtoStringType& containing_type,
- std::vector<int>* output);
-
+ // Finds the tag numbers used by all known extensions of
+ // containing_type, and appends them to output in an undefined
+ // order.
+ // Python objects are not required to implement this method.
+ bool FindAllExtensionNumbers(const TProtoStringType& containing_type,
+ std::vector<int>* output);
+
private:
// The python object that implements the database. The reference is owned.
PyObject* py_database_;
@@ -76,6 +76,6 @@ class PyDescriptorDatabase : public DescriptorDatabase {
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_DATABASE_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_pool.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_pool.cc
index a53411e797..1e6fe82cbf 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_pool.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_pool.cc
@@ -30,30 +30,30 @@
// Implements the DescriptorPool, which collects all descriptors.
-#include <unordered_map>
-
+#include <unordered_map>
+
#include <Python.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/descriptor_database.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/stubs/hash.h>
+#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/descriptor_database.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/stubs/hash.h>
#if PY_MAJOR_VERSION >= 3
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#endif
-#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
+#define PyString_AsStringAndSize(ob, charpp, sizep) \
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
namespace google {
@@ -62,57 +62,57 @@ namespace python {
// A map to cache Python Pools per C++ pointer.
// Pointers are not owned here, and belong to the PyDescriptorPool.
-static std::unordered_map<const DescriptorPool*, PyDescriptorPool*>*
- descriptor_pool_map;
+static std::unordered_map<const DescriptorPool*, PyDescriptorPool*>*
+ descriptor_pool_map;
namespace cdescriptor_pool {
-// Collects errors that occur during proto file building to allow them to be
-// propagated in the python exception instead of only living in ERROR logs.
-class BuildFileErrorCollector : public DescriptorPool::ErrorCollector {
- public:
- BuildFileErrorCollector() : error_message(""), had_errors_(false) {}
-
- void AddError(const TProtoStringType& filename, const TProtoStringType& element_name,
- const Message* descriptor, ErrorLocation location,
- const TProtoStringType& message) override {
- // Replicates the logging behavior that happens in the C++ implementation
- // when an error collector is not passed in.
- if (!had_errors_) {
- error_message +=
- ("Invalid proto descriptor for file \"" + filename + "\":\n");
- had_errors_ = true;
- }
- // As this only happens on failure and will result in the program not
- // running at all, no effort is made to optimize this string manipulation.
- error_message += (" " + element_name + ": " + message + "\n");
- }
-
- void Clear() {
- had_errors_ = false;
- error_message = "";
- }
-
- TProtoStringType error_message;
-
- private:
- bool had_errors_;
-};
-
+// Collects errors that occur during proto file building to allow them to be
+// propagated in the python exception instead of only living in ERROR logs.
+class BuildFileErrorCollector : public DescriptorPool::ErrorCollector {
+ public:
+ BuildFileErrorCollector() : error_message(""), had_errors_(false) {}
+
+ void AddError(const TProtoStringType& filename, const TProtoStringType& element_name,
+ const Message* descriptor, ErrorLocation location,
+ const TProtoStringType& message) override {
+ // Replicates the logging behavior that happens in the C++ implementation
+ // when an error collector is not passed in.
+ if (!had_errors_) {
+ error_message +=
+ ("Invalid proto descriptor for file \"" + filename + "\":\n");
+ had_errors_ = true;
+ }
+ // As this only happens on failure and will result in the program not
+ // running at all, no effort is made to optimize this string manipulation.
+ error_message += (" " + element_name + ": " + message + "\n");
+ }
+
+ void Clear() {
+ had_errors_ = false;
+ error_message = "";
+ }
+
+ TProtoStringType error_message;
+
+ private:
+ bool had_errors_;
+};
+
// Create a Python DescriptorPool object, but does not fill the "pool"
// attribute.
static PyDescriptorPool* _CreateDescriptorPool() {
- PyDescriptorPool* cpool = PyObject_GC_New(
+ PyDescriptorPool* cpool = PyObject_GC_New(
PyDescriptorPool, &PyDescriptorPool_Type);
if (cpool == NULL) {
return NULL;
}
- cpool->error_collector = nullptr;
+ cpool->error_collector = nullptr;
cpool->underlay = NULL;
cpool->database = NULL;
- cpool->descriptor_options = new std::unordered_map<const void*, PyObject*>();
+ cpool->descriptor_options = new std::unordered_map<const void*, PyObject*>();
cpool->py_message_factory = message_factory::NewMessageFactory(
&PyMessageFactory_Type, cpool);
@@ -121,8 +121,8 @@ static PyDescriptorPool* _CreateDescriptorPool() {
return NULL;
}
- PyObject_GC_Track(cpool);
-
+ PyObject_GC_Track(cpool);
+
return cpool;
}
@@ -140,7 +140,7 @@ static PyDescriptorPool* PyDescriptorPool_NewWithUnderlay(
cpool->pool = new DescriptorPool(underlay);
cpool->underlay = underlay;
- if (!descriptor_pool_map->insert(
+ if (!descriptor_pool_map->insert(
std::make_pair(cpool->pool, cpool)).second) {
// Should never happen -- would indicate an internal error / bug.
PyErr_SetString(PyExc_ValueError, "DescriptorPool already registered");
@@ -157,14 +157,14 @@ static PyDescriptorPool* PyDescriptorPool_NewWithDatabase(
return NULL;
}
if (database != NULL) {
- cpool->error_collector = new BuildFileErrorCollector();
- cpool->pool = new DescriptorPool(database, cpool->error_collector);
+ cpool->error_collector = new BuildFileErrorCollector();
+ cpool->pool = new DescriptorPool(database, cpool->error_collector);
cpool->database = database;
} else {
cpool->pool = new DescriptorPool();
}
- if (!descriptor_pool_map->insert(std::make_pair(cpool->pool, cpool)).second) {
+ if (!descriptor_pool_map->insert(std::make_pair(cpool->pool, cpool)).second) {
// Should never happen -- would indicate an internal error / bug.
PyErr_SetString(PyExc_ValueError, "DescriptorPool already registered");
return NULL;
@@ -178,8 +178,8 @@ static PyObject* New(PyTypeObject* type,
PyObject* args, PyObject* kwargs) {
static const char* kwlist[] = {"descriptor_db", 0};
PyObject* py_database = NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O",
- const_cast<char**>(kwlist), &py_database)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O",
+ const_cast<char**>(kwlist), &py_database)) {
return NULL;
}
DescriptorDatabase* database = NULL;
@@ -190,11 +190,11 @@ static PyObject* New(PyTypeObject* type,
PyDescriptorPool_NewWithDatabase(database));
}
-static void Dealloc(PyObject* pself) {
- PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
- descriptor_pool_map->erase(self->pool);
+static void Dealloc(PyObject* pself) {
+ PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
+ descriptor_pool_map->erase(self->pool);
Py_CLEAR(self->py_message_factory);
- for (std::unordered_map<const void*, PyObject*>::iterator it =
+ for (std::unordered_map<const void*, PyObject*>::iterator it =
self->descriptor_options->begin();
it != self->descriptor_options->end(); ++it) {
Py_DECREF(it->second);
@@ -202,37 +202,37 @@ static void Dealloc(PyObject* pself) {
delete self->descriptor_options;
delete self->database;
delete self->pool;
- delete self->error_collector;
- Py_TYPE(self)->tp_free(pself);
-}
-
-static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
- PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
- Py_VISIT(self->py_message_factory);
- return 0;
-}
-
-static int GcClear(PyObject* pself) {
- PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
- Py_CLEAR(self->py_message_factory);
- return 0;
-}
-
-PyObject* SetErrorFromCollector(DescriptorPool::ErrorCollector* self,
- const char* name, const char* error_type) {
- BuildFileErrorCollector* error_collector =
- reinterpret_cast<BuildFileErrorCollector*>(self);
- if (error_collector && !error_collector->error_message.empty()) {
- PyErr_Format(PyExc_KeyError, "Couldn't build file for %s %.200s\n%s",
- error_type, name, error_collector->error_message.c_str());
- error_collector->Clear();
- return NULL;
- }
- PyErr_Format(PyExc_KeyError, "Couldn't find %s %.200s", error_type, name);
- return NULL;
-}
-
-static PyObject* FindMessageByName(PyObject* self, PyObject* arg) {
+ delete self->error_collector;
+ Py_TYPE(self)->tp_free(pself);
+}
+
+static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
+ PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
+ Py_VISIT(self->py_message_factory);
+ return 0;
+}
+
+static int GcClear(PyObject* pself) {
+ PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
+ Py_CLEAR(self->py_message_factory);
+ return 0;
+}
+
+PyObject* SetErrorFromCollector(DescriptorPool::ErrorCollector* self,
+ const char* name, const char* error_type) {
+ BuildFileErrorCollector* error_collector =
+ reinterpret_cast<BuildFileErrorCollector*>(self);
+ if (error_collector && !error_collector->error_message.empty()) {
+ PyErr_Format(PyExc_KeyError, "Couldn't build file for %s %.200s\n%s",
+ error_type, name, error_collector->error_message.c_str());
+ error_collector->Clear();
+ return NULL;
+ }
+ PyErr_Format(PyExc_KeyError, "Couldn't find %s %.200s", error_type, name);
+ return NULL;
+}
+
+static PyObject* FindMessageByName(PyObject* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
@@ -240,35 +240,35 @@ static PyObject* FindMessageByName(PyObject* self, PyObject* arg) {
}
const Descriptor* message_descriptor =
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMessageTypeByName(
- StringParam(name, name_size));
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMessageTypeByName(
+ StringParam(name, name_size));
if (message_descriptor == NULL) {
- return SetErrorFromCollector(
- reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
- "message");
+ return SetErrorFromCollector(
+ reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
+ "message");
}
-
+
return PyMessageDescriptor_FromDescriptor(message_descriptor);
}
-static PyObject* FindFileByName(PyObject* self, PyObject* arg) {
+static PyObject* FindFileByName(PyObject* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
return NULL;
}
- PyDescriptorPool* py_pool = reinterpret_cast<PyDescriptorPool*>(self);
+ PyDescriptorPool* py_pool = reinterpret_cast<PyDescriptorPool*>(self);
const FileDescriptor* file_descriptor =
- py_pool->pool->FindFileByName(StringParam(name, name_size));
-
+ py_pool->pool->FindFileByName(StringParam(name, name_size));
+
if (file_descriptor == NULL) {
- return SetErrorFromCollector(py_pool->error_collector, name, "file");
+ return SetErrorFromCollector(py_pool->error_collector, name, "file");
}
return PyFileDescriptor_FromDescriptor(file_descriptor);
}
@@ -281,19 +281,19 @@ PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* arg) {
}
const FieldDescriptor* field_descriptor =
- self->pool->FindFieldByName(StringParam(name, name_size));
+ self->pool->FindFieldByName(StringParam(name, name_size));
if (field_descriptor == NULL) {
- return SetErrorFromCollector(self->error_collector, name, "field");
+ return SetErrorFromCollector(self->error_collector, name, "field");
}
-
+
return PyFieldDescriptor_FromDescriptor(field_descriptor);
}
-static PyObject* FindFieldByNameMethod(PyObject* self, PyObject* arg) {
- return FindFieldByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
-}
-
+static PyObject* FindFieldByNameMethod(PyObject* self, PyObject* arg) {
+ return FindFieldByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
+}
+
PyObject* FindExtensionByName(PyDescriptorPool* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
@@ -302,20 +302,20 @@ PyObject* FindExtensionByName(PyDescriptorPool* self, PyObject* arg) {
}
const FieldDescriptor* field_descriptor =
- self->pool->FindExtensionByName(StringParam(name, name_size));
+ self->pool->FindExtensionByName(StringParam(name, name_size));
if (field_descriptor == NULL) {
- return SetErrorFromCollector(self->error_collector, name,
- "extension field");
+ return SetErrorFromCollector(self->error_collector, name,
+ "extension field");
}
-
+
return PyFieldDescriptor_FromDescriptor(field_descriptor);
}
-static PyObject* FindExtensionByNameMethod(PyObject* self, PyObject* arg) {
- return FindExtensionByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
-}
-
+static PyObject* FindExtensionByNameMethod(PyObject* self, PyObject* arg) {
+ return FindExtensionByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
+}
+
PyObject* FindEnumTypeByName(PyDescriptorPool* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
@@ -324,19 +324,19 @@ PyObject* FindEnumTypeByName(PyDescriptorPool* self, PyObject* arg) {
}
const EnumDescriptor* enum_descriptor =
- self->pool->FindEnumTypeByName(StringParam(name, name_size));
+ self->pool->FindEnumTypeByName(StringParam(name, name_size));
if (enum_descriptor == NULL) {
- return SetErrorFromCollector(self->error_collector, name, "enum");
+ return SetErrorFromCollector(self->error_collector, name, "enum");
}
-
+
return PyEnumDescriptor_FromDescriptor(enum_descriptor);
}
-static PyObject* FindEnumTypeByNameMethod(PyObject* self, PyObject* arg) {
- return FindEnumTypeByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
-}
-
+static PyObject* FindEnumTypeByNameMethod(PyObject* self, PyObject* arg) {
+ return FindEnumTypeByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
+}
+
PyObject* FindOneofByName(PyDescriptorPool* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
@@ -345,20 +345,20 @@ PyObject* FindOneofByName(PyDescriptorPool* self, PyObject* arg) {
}
const OneofDescriptor* oneof_descriptor =
- self->pool->FindOneofByName(StringParam(name, name_size));
+ self->pool->FindOneofByName(StringParam(name, name_size));
if (oneof_descriptor == NULL) {
- return SetErrorFromCollector(self->error_collector, name, "oneof");
+ return SetErrorFromCollector(self->error_collector, name, "oneof");
}
-
+
return PyOneofDescriptor_FromDescriptor(oneof_descriptor);
}
-static PyObject* FindOneofByNameMethod(PyObject* self, PyObject* arg) {
- return FindOneofByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
-}
-
-static PyObject* FindServiceByName(PyObject* self, PyObject* arg) {
+static PyObject* FindOneofByNameMethod(PyObject* self, PyObject* arg) {
+ return FindOneofByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
+}
+
+static PyObject* FindServiceByName(PyObject* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
@@ -366,19 +366,19 @@ static PyObject* FindServiceByName(PyObject* self, PyObject* arg) {
}
const ServiceDescriptor* service_descriptor =
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindServiceByName(
- StringParam(name, name_size));
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindServiceByName(
+ StringParam(name, name_size));
if (service_descriptor == NULL) {
- return SetErrorFromCollector(
- reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
- "service");
+ return SetErrorFromCollector(
+ reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
+ "service");
}
-
+
return PyServiceDescriptor_FromDescriptor(service_descriptor);
}
-static PyObject* FindMethodByName(PyObject* self, PyObject* arg) {
+static PyObject* FindMethodByName(PyObject* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
@@ -386,19 +386,19 @@ static PyObject* FindMethodByName(PyObject* self, PyObject* arg) {
}
const MethodDescriptor* method_descriptor =
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMethodByName(
- StringParam(name, name_size));
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMethodByName(
+ StringParam(name, name_size));
if (method_descriptor == NULL) {
- return SetErrorFromCollector(
- reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
- "method");
+ return SetErrorFromCollector(
+ reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
+ "method");
}
-
+
return PyMethodDescriptor_FromDescriptor(method_descriptor);
}
-static PyObject* FindFileContainingSymbol(PyObject* self, PyObject* arg) {
+static PyObject* FindFileContainingSymbol(PyObject* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
@@ -406,19 +406,19 @@ static PyObject* FindFileContainingSymbol(PyObject* self, PyObject* arg) {
}
const FileDescriptor* file_descriptor =
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileContainingSymbol(
- StringParam(name, name_size));
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileContainingSymbol(
+ StringParam(name, name_size));
if (file_descriptor == NULL) {
- return SetErrorFromCollector(
- reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
- "symbol");
+ return SetErrorFromCollector(
+ reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
+ "symbol");
}
-
+
return PyFileDescriptor_FromDescriptor(file_descriptor);
}
-static PyObject* FindExtensionByNumber(PyObject* self, PyObject* args) {
+static PyObject* FindExtensionByNumber(PyObject* self, PyObject* args) {
PyObject* message_descriptor;
int number;
if (!PyArg_ParseTuple(args, "Oi", &message_descriptor, &number)) {
@@ -431,35 +431,35 @@ static PyObject* FindExtensionByNumber(PyObject* self, PyObject* args) {
}
const FieldDescriptor* extension_descriptor =
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindExtensionByNumber(
- descriptor, number);
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindExtensionByNumber(
+ descriptor, number);
if (extension_descriptor == NULL) {
- BuildFileErrorCollector* error_collector =
- reinterpret_cast<BuildFileErrorCollector*>(
- reinterpret_cast<PyDescriptorPool*>(self)->error_collector);
- if (error_collector && !error_collector->error_message.empty()) {
- PyErr_Format(PyExc_KeyError, "Couldn't build file for Extension %.d\n%s",
- number, error_collector->error_message.c_str());
- error_collector->Clear();
- return NULL;
- }
- PyErr_Format(PyExc_KeyError, "Couldn't find Extension %d", number);
+ BuildFileErrorCollector* error_collector =
+ reinterpret_cast<BuildFileErrorCollector*>(
+ reinterpret_cast<PyDescriptorPool*>(self)->error_collector);
+ if (error_collector && !error_collector->error_message.empty()) {
+ PyErr_Format(PyExc_KeyError, "Couldn't build file for Extension %.d\n%s",
+ number, error_collector->error_message.c_str());
+ error_collector->Clear();
+ return NULL;
+ }
+ PyErr_Format(PyExc_KeyError, "Couldn't find Extension %d", number);
return NULL;
}
-
+
return PyFieldDescriptor_FromDescriptor(extension_descriptor);
}
-static PyObject* FindAllExtensions(PyObject* self, PyObject* arg) {
+static PyObject* FindAllExtensions(PyObject* self, PyObject* arg) {
const Descriptor* descriptor = PyMessageDescriptor_AsDescriptor(arg);
if (descriptor == NULL) {
return NULL;
}
std::vector<const FieldDescriptor*> extensions;
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindAllExtensions(
- descriptor, &extensions);
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindAllExtensions(
+ descriptor, &extensions);
ScopedPyObjectPtr result(PyList_New(extensions.size()));
if (result == NULL) {
@@ -484,15 +484,15 @@ static PyObject* FindAllExtensions(PyObject* self, PyObject* arg) {
// call a function that will just be a no-op?
// TODO(amauryfa): Need to investigate further.
-static PyObject* AddFileDescriptor(PyObject* self, PyObject* descriptor) {
+static PyObject* AddFileDescriptor(PyObject* self, PyObject* descriptor) {
const FileDescriptor* file_descriptor =
PyFileDescriptor_AsDescriptor(descriptor);
if (!file_descriptor) {
return NULL;
}
if (file_descriptor !=
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileByName(
- file_descriptor->name())) {
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileByName(
+ file_descriptor->name())) {
PyErr_Format(PyExc_ValueError,
"The file descriptor %s does not belong to this pool",
file_descriptor->name().c_str());
@@ -501,15 +501,15 @@ static PyObject* AddFileDescriptor(PyObject* self, PyObject* descriptor) {
Py_RETURN_NONE;
}
-static PyObject* AddDescriptor(PyObject* self, PyObject* descriptor) {
+static PyObject* AddDescriptor(PyObject* self, PyObject* descriptor) {
const Descriptor* message_descriptor =
PyMessageDescriptor_AsDescriptor(descriptor);
if (!message_descriptor) {
return NULL;
}
if (message_descriptor !=
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMessageTypeByName(
- message_descriptor->full_name())) {
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMessageTypeByName(
+ message_descriptor->full_name())) {
PyErr_Format(PyExc_ValueError,
"The message descriptor %s does not belong to this pool",
message_descriptor->full_name().c_str());
@@ -518,15 +518,15 @@ static PyObject* AddDescriptor(PyObject* self, PyObject* descriptor) {
Py_RETURN_NONE;
}
-static PyObject* AddEnumDescriptor(PyObject* self, PyObject* descriptor) {
+static PyObject* AddEnumDescriptor(PyObject* self, PyObject* descriptor) {
const EnumDescriptor* enum_descriptor =
PyEnumDescriptor_AsDescriptor(descriptor);
if (!enum_descriptor) {
return NULL;
}
if (enum_descriptor !=
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindEnumTypeByName(
- enum_descriptor->full_name())) {
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindEnumTypeByName(
+ enum_descriptor->full_name())) {
PyErr_Format(PyExc_ValueError,
"The enum descriptor %s does not belong to this pool",
enum_descriptor->full_name().c_str());
@@ -535,15 +535,15 @@ static PyObject* AddEnumDescriptor(PyObject* self, PyObject* descriptor) {
Py_RETURN_NONE;
}
-static PyObject* AddExtensionDescriptor(PyObject* self, PyObject* descriptor) {
+static PyObject* AddExtensionDescriptor(PyObject* self, PyObject* descriptor) {
const FieldDescriptor* extension_descriptor =
PyFieldDescriptor_AsDescriptor(descriptor);
if (!extension_descriptor) {
return NULL;
}
if (extension_descriptor !=
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindExtensionByName(
- extension_descriptor->full_name())) {
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindExtensionByName(
+ extension_descriptor->full_name())) {
PyErr_Format(PyExc_ValueError,
"The extension descriptor %s does not belong to this pool",
extension_descriptor->full_name().c_str());
@@ -552,15 +552,15 @@ static PyObject* AddExtensionDescriptor(PyObject* self, PyObject* descriptor) {
Py_RETURN_NONE;
}
-static PyObject* AddServiceDescriptor(PyObject* self, PyObject* descriptor) {
+static PyObject* AddServiceDescriptor(PyObject* self, PyObject* descriptor) {
const ServiceDescriptor* service_descriptor =
PyServiceDescriptor_AsDescriptor(descriptor);
if (!service_descriptor) {
return NULL;
}
if (service_descriptor !=
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindServiceByName(
- service_descriptor->full_name())) {
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindServiceByName(
+ service_descriptor->full_name())) {
PyErr_Format(PyExc_ValueError,
"The service descriptor %s does not belong to this pool",
service_descriptor->full_name().c_str());
@@ -570,8 +570,8 @@ static PyObject* AddServiceDescriptor(PyObject* self, PyObject* descriptor) {
}
// The code below loads new Descriptors from a serialized FileDescriptorProto.
-static PyObject* AddSerializedFile(PyObject* pself, PyObject* serialized_pb) {
- PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
+static PyObject* AddSerializedFile(PyObject* pself, PyObject* serialized_pb) {
+ PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
char* message_type;
Py_ssize_t message_len;
@@ -619,7 +619,7 @@ static PyObject* AddSerializedFile(PyObject* pself, PyObject* serialized_pb) {
descriptor, serialized_pb);
}
-static PyObject* Add(PyObject* self, PyObject* file_descriptor_proto) {
+static PyObject* Add(PyObject* self, PyObject* file_descriptor_proto) {
ScopedPyObjectPtr serialized_pb(
PyObject_CallMethod(file_descriptor_proto, "SerializeToString", NULL));
if (serialized_pb == NULL) {
@@ -629,46 +629,46 @@ static PyObject* Add(PyObject* self, PyObject* file_descriptor_proto) {
}
static PyMethodDef Methods[] = {
- { "Add", Add, METH_O,
+ { "Add", Add, METH_O,
"Adds the FileDescriptorProto and its types to this pool." },
- { "AddSerializedFile", AddSerializedFile, METH_O,
+ { "AddSerializedFile", AddSerializedFile, METH_O,
"Adds a serialized FileDescriptorProto to this pool." },
// TODO(amauryfa): Understand why the Python implementation differs from
// this one, ask users to use another API and deprecate these functions.
- { "AddFileDescriptor", AddFileDescriptor, METH_O,
+ { "AddFileDescriptor", AddFileDescriptor, METH_O,
"No-op. Add() must have been called before." },
- { "AddDescriptor", AddDescriptor, METH_O,
+ { "AddDescriptor", AddDescriptor, METH_O,
"No-op. Add() must have been called before." },
- { "AddEnumDescriptor", AddEnumDescriptor, METH_O,
+ { "AddEnumDescriptor", AddEnumDescriptor, METH_O,
"No-op. Add() must have been called before." },
- { "AddExtensionDescriptor", AddExtensionDescriptor, METH_O,
+ { "AddExtensionDescriptor", AddExtensionDescriptor, METH_O,
"No-op. Add() must have been called before." },
- { "AddServiceDescriptor", AddServiceDescriptor, METH_O,
+ { "AddServiceDescriptor", AddServiceDescriptor, METH_O,
"No-op. Add() must have been called before." },
- { "FindFileByName", FindFileByName, METH_O,
+ { "FindFileByName", FindFileByName, METH_O,
"Searches for a file descriptor by its .proto name." },
- { "FindMessageTypeByName", FindMessageByName, METH_O,
+ { "FindMessageTypeByName", FindMessageByName, METH_O,
"Searches for a message descriptor by full name." },
- { "FindFieldByName", FindFieldByNameMethod, METH_O,
+ { "FindFieldByName", FindFieldByNameMethod, METH_O,
"Searches for a field descriptor by full name." },
- { "FindExtensionByName", FindExtensionByNameMethod, METH_O,
+ { "FindExtensionByName", FindExtensionByNameMethod, METH_O,
"Searches for extension descriptor by full name." },
- { "FindEnumTypeByName", FindEnumTypeByNameMethod, METH_O,
+ { "FindEnumTypeByName", FindEnumTypeByNameMethod, METH_O,
"Searches for enum type descriptor by full name." },
- { "FindOneofByName", FindOneofByNameMethod, METH_O,
+ { "FindOneofByName", FindOneofByNameMethod, METH_O,
"Searches for oneof descriptor by full name." },
- { "FindServiceByName", FindServiceByName, METH_O,
+ { "FindServiceByName", FindServiceByName, METH_O,
"Searches for service descriptor by full name." },
- { "FindMethodByName", FindMethodByName, METH_O,
+ { "FindMethodByName", FindMethodByName, METH_O,
"Searches for method descriptor by full name." },
- { "FindFileContainingSymbol", FindFileContainingSymbol, METH_O,
+ { "FindFileContainingSymbol", FindFileContainingSymbol, METH_O,
"Gets the FileDescriptor containing the specified symbol." },
- { "FindExtensionByNumber", FindExtensionByNumber, METH_VARARGS,
+ { "FindExtensionByNumber", FindExtensionByNumber, METH_VARARGS,
"Gets the extension descriptor for the given number." },
- { "FindAllExtensions", FindAllExtensions, METH_O,
+ { "FindAllExtensions", FindAllExtensions, METH_O,
"Gets all known extensions of the given message descriptor." },
{NULL}
};
@@ -676,45 +676,45 @@ static PyMethodDef Methods[] = {
} // namespace cdescriptor_pool
PyTypeObject PyDescriptorPool_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".DescriptorPool", // tp_name
- sizeof(PyDescriptorPool), // tp_basicsize
- 0, // tp_itemsize
- cdescriptor_pool::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
- "A Descriptor Pool", // tp_doc
- cdescriptor_pool::GcTraverse, // tp_traverse
- cdescriptor_pool::GcClear, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- cdescriptor_pool::Methods, // tp_methods
- 0, // tp_members
- 0, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
- 0, // tp_alloc
- cdescriptor_pool::New, // tp_new
- PyObject_GC_Del, // tp_free
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".DescriptorPool", // tp_name
+ sizeof(PyDescriptorPool), // tp_basicsize
+ 0, // tp_itemsize
+ cdescriptor_pool::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
+ "A Descriptor Pool", // tp_doc
+ cdescriptor_pool::GcTraverse, // tp_traverse
+ cdescriptor_pool::GcClear, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ cdescriptor_pool::Methods, // tp_methods
+ 0, // tp_members
+ 0, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ cdescriptor_pool::New, // tp_new
+ PyObject_GC_Del, // tp_free
};
// This is the DescriptorPool which contains all the definitions from the
@@ -728,17 +728,17 @@ bool InitDescriptorPool() {
// The Pool of messages declared in Python libraries.
// generated_pool() contains all messages already linked in C++ libraries, and
// is used as underlay.
- descriptor_pool_map =
- new std::unordered_map<const DescriptorPool*, PyDescriptorPool*>;
+ descriptor_pool_map =
+ new std::unordered_map<const DescriptorPool*, PyDescriptorPool*>;
python_generated_pool = cdescriptor_pool::PyDescriptorPool_NewWithUnderlay(
DescriptorPool::generated_pool());
if (python_generated_pool == NULL) {
- delete descriptor_pool_map;
+ delete descriptor_pool_map;
return false;
}
-
+
// Register this pool to be found for C++-generated descriptors.
- descriptor_pool_map->insert(
+ descriptor_pool_map->insert(
std::make_pair(DescriptorPool::generated_pool(),
python_generated_pool));
@@ -759,9 +759,9 @@ PyDescriptorPool* GetDescriptorPool_FromPool(const DescriptorPool* pool) {
pool == DescriptorPool::generated_pool()) {
return python_generated_pool;
}
- std::unordered_map<const DescriptorPool*, PyDescriptorPool*>::iterator it =
- descriptor_pool_map->find(pool);
- if (it == descriptor_pool_map->end()) {
+ std::unordered_map<const DescriptorPool*, PyDescriptorPool*>::iterator it =
+ descriptor_pool_map->find(pool);
+ if (it == descriptor_pool_map->end()) {
PyErr_SetString(PyExc_KeyError, "Unknown descriptor pool");
return NULL;
}
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_pool.h b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_pool.h
index 2d456f9088..fe8c87ced7 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_pool.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/descriptor_pool.h
@@ -33,8 +33,8 @@
#include <Python.h>
-#include <unordered_map>
-#include <google/protobuf/descriptor.h>
+#include <unordered_map>
+#include <google/protobuf/descriptor.h>
namespace google {
namespace protobuf {
@@ -59,10 +59,10 @@ typedef struct PyDescriptorPool {
// The C++ pool containing Descriptors.
DescriptorPool* pool;
- // The error collector to store error info. Can be NULL. This pointer is
- // owned.
- DescriptorPool::ErrorCollector* error_collector;
-
+ // The error collector to store error info. Can be NULL. This pointer is
+ // owned.
+ DescriptorPool::ErrorCollector* error_collector;
+
// The C++ pool acting as an underlay. Can be NULL.
// This pointer is not owned and must stay alive.
const DescriptorPool* underlay;
@@ -79,7 +79,7 @@ typedef struct PyDescriptorPool {
// Cache the options for any kind of descriptor.
// Descriptor pointers are owned by the DescriptorPool above.
// Python objects are owned by the map.
- std::unordered_map<const void*, PyObject*>* descriptor_options;
+ std::unordered_map<const void*, PyObject*>* descriptor_options;
} PyDescriptorPool;
@@ -131,6 +131,6 @@ bool InitDescriptorPool();
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/extension_dict.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/extension_dict.cc
index 37b414c375..2fdd9b2cf2 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/extension_dict.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/extension_dict.cc
@@ -31,34 +31,34 @@
// Author: anuraag@google.com (Anuraag Agrawal)
// Author: tibell@google.com (Johan Tibell)
-#include <google/protobuf/pyext/extension_dict.h>
-
-#include <cstdint>
-#include <memory>
-
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/dynamic_message.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/repeated_composite_container.h>
-#include <google/protobuf/pyext/repeated_scalar_container.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/pyext/extension_dict.h>
+
+#include <cstdint>
+#include <memory>
+
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/repeated_composite_container.h>
+#include <google/protobuf/pyext/repeated_scalar_container.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#if PY_MAJOR_VERSION >= 3
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#endif
-#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
+#define PyString_AsStringAndSize(ob, charpp, sizep) \
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
namespace google {
@@ -67,103 +67,103 @@ namespace python {
namespace extension_dict {
-static Py_ssize_t len(ExtensionDict* self) {
- Py_ssize_t size = 0;
- std::vector<const FieldDescriptor*> fields;
- self->parent->message->GetReflection()->ListFields(*self->parent->message,
- &fields);
-
- for (size_t i = 0; i < fields.size(); ++i) {
- if (fields[i]->is_extension()) {
- // With C++ descriptors, the field can always be retrieved, but for
- // unknown extensions which have not been imported in Python code, there
- // is no message class and we cannot retrieve the value.
- // ListFields() has the same behavior.
- if (fields[i]->message_type() != nullptr &&
- message_factory::GetMessageClass(
- cmessage::GetFactoryForMessage(self->parent),
- fields[i]->message_type()) == nullptr) {
- PyErr_Clear();
- continue;
- }
- ++size;
- }
- }
- return size;
-}
-
-struct ExtensionIterator {
- PyObject_HEAD;
- Py_ssize_t index;
- std::vector<const FieldDescriptor*> fields;
-
- // Owned reference, to keep the FieldDescriptors alive.
- ExtensionDict* extension_dict;
-};
-
-PyObject* GetIter(PyObject* _self) {
- ExtensionDict* self = reinterpret_cast<ExtensionDict*>(_self);
-
- ScopedPyObjectPtr obj(PyType_GenericAlloc(&ExtensionIterator_Type, 0));
- if (obj == nullptr) {
- return PyErr_Format(PyExc_MemoryError,
- "Could not allocate extension iterator");
- }
-
- ExtensionIterator* iter = reinterpret_cast<ExtensionIterator*>(obj.get());
-
- // Call "placement new" to initialize. So the constructor of
- // std::vector<...> fields will be called.
- new (iter) ExtensionIterator;
-
- self->parent->message->GetReflection()->ListFields(*self->parent->message,
- &iter->fields);
- iter->index = 0;
- Py_INCREF(self);
- iter->extension_dict = self;
-
- return obj.release();
-}
-
-static void DeallocExtensionIterator(PyObject* _self) {
- ExtensionIterator* self = reinterpret_cast<ExtensionIterator*>(_self);
- self->fields.clear();
- Py_XDECREF(self->extension_dict);
- self->~ExtensionIterator();
- Py_TYPE(_self)->tp_free(_self);
+static Py_ssize_t len(ExtensionDict* self) {
+ Py_ssize_t size = 0;
+ std::vector<const FieldDescriptor*> fields;
+ self->parent->message->GetReflection()->ListFields(*self->parent->message,
+ &fields);
+
+ for (size_t i = 0; i < fields.size(); ++i) {
+ if (fields[i]->is_extension()) {
+ // With C++ descriptors, the field can always be retrieved, but for
+ // unknown extensions which have not been imported in Python code, there
+ // is no message class and we cannot retrieve the value.
+ // ListFields() has the same behavior.
+ if (fields[i]->message_type() != nullptr &&
+ message_factory::GetMessageClass(
+ cmessage::GetFactoryForMessage(self->parent),
+ fields[i]->message_type()) == nullptr) {
+ PyErr_Clear();
+ continue;
+ }
+ ++size;
+ }
+ }
+ return size;
}
+struct ExtensionIterator {
+ PyObject_HEAD;
+ Py_ssize_t index;
+ std::vector<const FieldDescriptor*> fields;
+
+ // Owned reference, to keep the FieldDescriptors alive.
+ ExtensionDict* extension_dict;
+};
+
+PyObject* GetIter(PyObject* _self) {
+ ExtensionDict* self = reinterpret_cast<ExtensionDict*>(_self);
+
+ ScopedPyObjectPtr obj(PyType_GenericAlloc(&ExtensionIterator_Type, 0));
+ if (obj == nullptr) {
+ return PyErr_Format(PyExc_MemoryError,
+ "Could not allocate extension iterator");
+ }
+
+ ExtensionIterator* iter = reinterpret_cast<ExtensionIterator*>(obj.get());
+
+ // Call "placement new" to initialize. So the constructor of
+ // std::vector<...> fields will be called.
+ new (iter) ExtensionIterator;
+
+ self->parent->message->GetReflection()->ListFields(*self->parent->message,
+ &iter->fields);
+ iter->index = 0;
+ Py_INCREF(self);
+ iter->extension_dict = self;
+
+ return obj.release();
+}
+
+static void DeallocExtensionIterator(PyObject* _self) {
+ ExtensionIterator* self = reinterpret_cast<ExtensionIterator*>(_self);
+ self->fields.clear();
+ Py_XDECREF(self->extension_dict);
+ self->~ExtensionIterator();
+ Py_TYPE(_self)->tp_free(_self);
+}
+
PyObject* subscript(ExtensionDict* self, PyObject* key) {
const FieldDescriptor* descriptor = cmessage::GetExtensionDescriptor(key);
if (descriptor == NULL) {
return NULL;
}
- if (!CheckFieldBelongsToMessage(descriptor, self->parent->message)) {
+ if (!CheckFieldBelongsToMessage(descriptor, self->parent->message)) {
return NULL;
}
if (descriptor->label() != FieldDescriptor::LABEL_REPEATED &&
descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
- return cmessage::InternalGetScalar(self->parent->message, descriptor);
+ return cmessage::InternalGetScalar(self->parent->message, descriptor);
}
- CMessage::CompositeFieldsMap::iterator iterator =
- self->parent->composite_fields->find(descriptor);
- if (iterator != self->parent->composite_fields->end()) {
- Py_INCREF(iterator->second);
- return iterator->second->AsPyObject();
+ CMessage::CompositeFieldsMap::iterator iterator =
+ self->parent->composite_fields->find(descriptor);
+ if (iterator != self->parent->composite_fields->end()) {
+ Py_INCREF(iterator->second);
+ return iterator->second->AsPyObject();
}
if (descriptor->label() != FieldDescriptor::LABEL_REPEATED &&
descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
// TODO(plabatut): consider building the class on the fly!
- ContainerBase* sub_message = cmessage::InternalGetSubMessage(
+ ContainerBase* sub_message = cmessage::InternalGetSubMessage(
self->parent, descriptor);
if (sub_message == NULL) {
return NULL;
}
- (*self->parent->composite_fields)[descriptor] = sub_message;
- return sub_message->AsPyObject();
+ (*self->parent->composite_fields)[descriptor] = sub_message;
+ return sub_message->AsPyObject();
}
if (descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
@@ -186,21 +186,21 @@ PyObject* subscript(ExtensionDict* self, PyObject* key) {
if (message_class == NULL) {
return NULL;
}
- ContainerBase* py_container = repeated_composite_container::NewContainer(
+ ContainerBase* py_container = repeated_composite_container::NewContainer(
self->parent, descriptor, message_class);
if (py_container == NULL) {
return NULL;
}
- (*self->parent->composite_fields)[descriptor] = py_container;
- return py_container->AsPyObject();
+ (*self->parent->composite_fields)[descriptor] = py_container;
+ return py_container->AsPyObject();
} else {
- ContainerBase* py_container = repeated_scalar_container::NewContainer(
+ ContainerBase* py_container = repeated_scalar_container::NewContainer(
self->parent, descriptor);
if (py_container == NULL) {
return NULL;
}
- (*self->parent->composite_fields)[descriptor] = py_container;
- return py_container->AsPyObject();
+ (*self->parent->composite_fields)[descriptor] = py_container;
+ return py_container->AsPyObject();
}
}
PyErr_SetString(PyExc_ValueError, "control reached unexpected line");
@@ -212,23 +212,23 @@ int ass_subscript(ExtensionDict* self, PyObject* key, PyObject* value) {
if (descriptor == NULL) {
return -1;
}
- if (!CheckFieldBelongsToMessage(descriptor, self->parent->message)) {
+ if (!CheckFieldBelongsToMessage(descriptor, self->parent->message)) {
return -1;
}
- if (value == nullptr) {
- return cmessage::ClearFieldByDescriptor(self->parent, descriptor);
- }
-
+ if (value == nullptr) {
+ return cmessage::ClearFieldByDescriptor(self->parent, descriptor);
+ }
+
if (descriptor->label() != FieldDescriptor::LABEL_OPTIONAL ||
descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
PyErr_SetString(PyExc_TypeError, "Extension is repeated and/or composite "
"type");
return -1;
}
- cmessage::AssureWritable(self->parent);
- if (cmessage::InternalSetScalar(self->parent, descriptor, value) < 0) {
- return -1;
+ cmessage::AssureWritable(self->parent);
+ if (cmessage::InternalSetScalar(self->parent, descriptor, value) < 0) {
+ return -1;
}
return 0;
}
@@ -242,11 +242,11 @@ PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* arg) {
PyDescriptorPool* pool = cmessage::GetFactoryForMessage(self->parent)->pool;
const FieldDescriptor* message_extension =
- pool->pool->FindExtensionByName(StringParam(name, name_size));
+ pool->pool->FindExtensionByName(StringParam(name, name_size));
if (message_extension == NULL) {
// Is is the name of a message set extension?
- const Descriptor* message_descriptor =
- pool->pool->FindMessageTypeByName(StringParam(name, name_size));
+ const Descriptor* message_descriptor =
+ pool->pool->FindMessageTypeByName(StringParam(name, name_size));
if (message_descriptor && message_descriptor->extension_count() > 0) {
const FieldDescriptor* extension = message_descriptor->extension(0);
if (extension->is_extension() &&
@@ -265,7 +265,7 @@ PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* arg) {
}
PyObject* _FindExtensionByNumber(ExtensionDict* self, PyObject* arg) {
- int64_t number = PyLong_AsLong(arg);
+ int64_t number = PyLong_AsLong(arg);
if (number == -1 && PyErr_Occurred()) {
return NULL;
}
@@ -280,35 +280,35 @@ PyObject* _FindExtensionByNumber(ExtensionDict* self, PyObject* arg) {
return PyFieldDescriptor_FromDescriptor(message_extension);
}
-static int Contains(PyObject* _self, PyObject* key) {
- ExtensionDict* self = reinterpret_cast<ExtensionDict*>(_self);
- const FieldDescriptor* field_descriptor =
- cmessage::GetExtensionDescriptor(key);
- if (field_descriptor == nullptr) {
- return -1;
- }
-
- if (!field_descriptor->is_extension()) {
- PyErr_Format(PyExc_KeyError, "%s is not an extension",
- field_descriptor->full_name().c_str());
- return -1;
- }
-
- const Message* message = self->parent->message;
- const Reflection* reflection = message->GetReflection();
- if (field_descriptor->is_repeated()) {
- if (reflection->FieldSize(*message, field_descriptor) > 0) {
- return 1;
- }
- } else {
- if (reflection->HasField(*message, field_descriptor)) {
- return 1;
- }
- }
-
- return 0;
-}
-
+static int Contains(PyObject* _self, PyObject* key) {
+ ExtensionDict* self = reinterpret_cast<ExtensionDict*>(_self);
+ const FieldDescriptor* field_descriptor =
+ cmessage::GetExtensionDescriptor(key);
+ if (field_descriptor == nullptr) {
+ return -1;
+ }
+
+ if (!field_descriptor->is_extension()) {
+ PyErr_Format(PyExc_KeyError, "%s is not an extension",
+ field_descriptor->full_name().c_str());
+ return -1;
+ }
+
+ const Message* message = self->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ if (field_descriptor->is_repeated()) {
+ if (reflection->FieldSize(*message, field_descriptor) > 0) {
+ return 1;
+ }
+ } else {
+ if (reflection->HasField(*message, field_descriptor)) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
ExtensionDict* NewExtensionDict(CMessage *parent) {
ExtensionDict* self = reinterpret_cast<ExtensionDict*>(
PyType_GenericAlloc(&ExtensionDict_Type, 0));
@@ -316,165 +316,165 @@ ExtensionDict* NewExtensionDict(CMessage *parent) {
return NULL;
}
- Py_INCREF(parent);
- self->parent = parent;
+ Py_INCREF(parent);
+ self->parent = parent;
return self;
}
-void dealloc(PyObject* pself) {
- ExtensionDict* self = reinterpret_cast<ExtensionDict*>(pself);
- Py_CLEAR(self->parent);
+void dealloc(PyObject* pself) {
+ ExtensionDict* self = reinterpret_cast<ExtensionDict*>(pself);
+ Py_CLEAR(self->parent);
Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self));
}
-static PyObject* RichCompare(ExtensionDict* self, PyObject* other, int opid) {
- // Only equality comparisons are implemented.
- if (opid != Py_EQ && opid != Py_NE) {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
- }
- bool equals = false;
- if (PyObject_TypeCheck(other, &ExtensionDict_Type)) {
- equals = self->parent == reinterpret_cast<ExtensionDict*>(other)->parent;;
- }
- if (equals ^ (opid == Py_EQ)) {
- Py_RETURN_FALSE;
- } else {
- Py_RETURN_TRUE;
- }
-}
-static PySequenceMethods SeqMethods = {
- (lenfunc)len, // sq_length
- 0, // sq_concat
- 0, // sq_repeat
- 0, // sq_item
- 0, // sq_slice
- 0, // sq_ass_item
- 0, // sq_ass_slice
- (objobjproc)Contains, // sq_contains
-};
-
+static PyObject* RichCompare(ExtensionDict* self, PyObject* other, int opid) {
+ // Only equality comparisons are implemented.
+ if (opid != Py_EQ && opid != Py_NE) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+ bool equals = false;
+ if (PyObject_TypeCheck(other, &ExtensionDict_Type)) {
+ equals = self->parent == reinterpret_cast<ExtensionDict*>(other)->parent;;
+ }
+ if (equals ^ (opid == Py_EQ)) {
+ Py_RETURN_FALSE;
+ } else {
+ Py_RETURN_TRUE;
+ }
+}
+static PySequenceMethods SeqMethods = {
+ (lenfunc)len, // sq_length
+ 0, // sq_concat
+ 0, // sq_repeat
+ 0, // sq_item
+ 0, // sq_slice
+ 0, // sq_ass_item
+ 0, // sq_ass_slice
+ (objobjproc)Contains, // sq_contains
+};
+
static PyMappingMethods MpMethods = {
- (lenfunc)len, /* mp_length */
- (binaryfunc)subscript, /* mp_subscript */
+ (lenfunc)len, /* mp_length */
+ (binaryfunc)subscript, /* mp_subscript */
(objobjargproc)ass_subscript,/* mp_ass_subscript */
};
#define EDMETHOD(name, args, doc) { #name, (PyCFunction)name, args, doc }
static PyMethodDef Methods[] = {
- EDMETHOD(_FindExtensionByName, METH_O, "Finds an extension by name."),
- EDMETHOD(_FindExtensionByNumber, METH_O,
- "Finds an extension by field number."),
- {NULL, NULL},
+ EDMETHOD(_FindExtensionByName, METH_O, "Finds an extension by name."),
+ EDMETHOD(_FindExtensionByNumber, METH_O,
+ "Finds an extension by field number."),
+ {NULL, NULL},
};
} // namespace extension_dict
PyTypeObject ExtensionDict_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) //
- FULL_MODULE_NAME ".ExtensionDict", // tp_name
- sizeof(ExtensionDict), // tp_basicsize
- 0, // tp_itemsize
- (destructor)extension_dict::dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- &extension_dict::SeqMethods, // tp_as_sequence
- &extension_dict::MpMethods, // tp_as_mapping
- PyObject_HashNotImplemented, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "An extension dict", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- (richcmpfunc)extension_dict::RichCompare, // tp_richcompare
- 0, // tp_weaklistoffset
- extension_dict::GetIter, // tp_iter
- 0, // tp_iternext
- extension_dict::Methods, // tp_methods
- 0, // tp_members
- 0, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) //
+ FULL_MODULE_NAME ".ExtensionDict", // tp_name
+ sizeof(ExtensionDict), // tp_basicsize
+ 0, // tp_itemsize
+ (destructor)extension_dict::dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ &extension_dict::SeqMethods, // tp_as_sequence
+ &extension_dict::MpMethods, // tp_as_mapping
+ PyObject_HashNotImplemented, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "An extension dict", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ (richcmpfunc)extension_dict::RichCompare, // tp_richcompare
+ 0, // tp_weaklistoffset
+ extension_dict::GetIter, // tp_iter
+ 0, // tp_iternext
+ extension_dict::Methods, // tp_methods
+ 0, // tp_members
+ 0, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
};
-PyObject* IterNext(PyObject* _self) {
- extension_dict::ExtensionIterator* self =
- reinterpret_cast<extension_dict::ExtensionIterator*>(_self);
- Py_ssize_t total_size = self->fields.size();
- Py_ssize_t index = self->index;
- while (self->index < total_size) {
- index = self->index;
- ++self->index;
- if (self->fields[index]->is_extension()) {
- // With C++ descriptors, the field can always be retrieved, but for
- // unknown extensions which have not been imported in Python code, there
- // is no message class and we cannot retrieve the value.
- // ListFields() has the same behavior.
- if (self->fields[index]->message_type() != nullptr &&
- message_factory::GetMessageClass(
- cmessage::GetFactoryForMessage(self->extension_dict->parent),
- self->fields[index]->message_type()) == nullptr) {
- PyErr_Clear();
- continue;
- }
-
- return PyFieldDescriptor_FromDescriptor(self->fields[index]);
- }
- }
-
- return nullptr;
-}
-
-PyTypeObject ExtensionIterator_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) //
- FULL_MODULE_NAME ".ExtensionIterator", // tp_name
- sizeof(extension_dict::ExtensionIterator), // tp_basicsize
- 0, // tp_itemsize
- extension_dict::DeallocExtensionIterator, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "A scalar map iterator", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- PyObject_SelfIter, // tp_iter
- IterNext, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- 0, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
-};
+PyObject* IterNext(PyObject* _self) {
+ extension_dict::ExtensionIterator* self =
+ reinterpret_cast<extension_dict::ExtensionIterator*>(_self);
+ Py_ssize_t total_size = self->fields.size();
+ Py_ssize_t index = self->index;
+ while (self->index < total_size) {
+ index = self->index;
+ ++self->index;
+ if (self->fields[index]->is_extension()) {
+ // With C++ descriptors, the field can always be retrieved, but for
+ // unknown extensions which have not been imported in Python code, there
+ // is no message class and we cannot retrieve the value.
+ // ListFields() has the same behavior.
+ if (self->fields[index]->message_type() != nullptr &&
+ message_factory::GetMessageClass(
+ cmessage::GetFactoryForMessage(self->extension_dict->parent),
+ self->fields[index]->message_type()) == nullptr) {
+ PyErr_Clear();
+ continue;
+ }
+
+ return PyFieldDescriptor_FromDescriptor(self->fields[index]);
+ }
+ }
+
+ return nullptr;
+}
+
+PyTypeObject ExtensionIterator_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) //
+ FULL_MODULE_NAME ".ExtensionIterator", // tp_name
+ sizeof(extension_dict::ExtensionIterator), // tp_basicsize
+ 0, // tp_itemsize
+ extension_dict::DeallocExtensionIterator, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "A scalar map iterator", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ PyObject_SelfIter, // tp_iter
+ IterNext, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ 0, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+};
} // namespace python
} // namespace protobuf
} // namespace google
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/extension_dict.h b/contrib/python/protobuf/py2/google/protobuf/pyext/extension_dict.h
index c9da443161..52f11729f5 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/extension_dict.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/extension_dict.h
@@ -38,8 +38,8 @@
#include <memory>
-#include <google/protobuf/pyext/message.h>
-
+#include <google/protobuf/pyext/message.h>
+
namespace google {
namespace protobuf {
@@ -51,12 +51,12 @@ namespace python {
typedef struct ExtensionDict {
PyObject_HEAD;
- // Strong, owned reference to the parent message. Never NULL.
+ // Strong, owned reference to the parent message. Never NULL.
CMessage* parent;
} ExtensionDict;
extern PyTypeObject ExtensionDict_Type;
-extern PyTypeObject ExtensionIterator_Type;
+extern PyTypeObject ExtensionIterator_Type;
namespace extension_dict {
@@ -66,6 +66,6 @@ ExtensionDict* NewExtensionDict(CMessage *parent);
} // namespace extension_dict
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/field.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/field.cc
index 1afd4583b3..e3328998e6 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/field.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/field.cc
@@ -1,142 +1,142 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <google/protobuf/pyext/field.h>
-
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/message.h>
-
-#if PY_MAJOR_VERSION >= 3
- #define PyString_FromFormat PyUnicode_FromFormat
-#endif
-
-namespace google {
-namespace protobuf {
-namespace python {
-
-namespace field {
-
-static PyObject* Repr(PyMessageFieldProperty* self) {
- return PyString_FromFormat("<field property '%s'>",
- self->field_descriptor->full_name().c_str());
-}
-
-static PyObject* DescrGet(PyMessageFieldProperty* self, PyObject* obj,
- PyObject* type) {
- if (obj == NULL) {
- Py_INCREF(self);
- return reinterpret_cast<PyObject*>(self);
- }
- return cmessage::GetFieldValue(reinterpret_cast<CMessage*>(obj),
- self->field_descriptor);
-}
-
-static int DescrSet(PyMessageFieldProperty* self, PyObject* obj,
- PyObject* value) {
- if (value == NULL) {
- PyErr_SetString(PyExc_AttributeError, "Cannot delete field attribute");
- return -1;
- }
- return cmessage::SetFieldValue(reinterpret_cast<CMessage*>(obj),
- self->field_descriptor, value);
-}
-
-static PyObject* GetDescriptor(PyMessageFieldProperty* self, void* closure) {
- return PyFieldDescriptor_FromDescriptor(self->field_descriptor);
-}
-
-static PyObject* GetDoc(PyMessageFieldProperty* self, void* closure) {
- return PyString_FromFormat("Field %s",
- self->field_descriptor->full_name().c_str());
-}
-
-static PyGetSetDef Getters[] = {
- {"DESCRIPTOR", (getter)GetDescriptor, NULL, "Field descriptor"},
- {"__doc__", (getter)GetDoc, NULL, NULL},
- {NULL}};
-} // namespace field
-
-static PyTypeObject _CFieldProperty_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) // head
- FULL_MODULE_NAME ".FieldProperty", // tp_name
- sizeof(PyMessageFieldProperty), // tp_basicsize
- 0, // tp_itemsize
- 0, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- (reprfunc)field::Repr, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "Field property of a Message", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- field::Getters, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- (descrgetfunc)field::DescrGet, // tp_descr_get
- (descrsetfunc)field::DescrSet, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
- 0, // tp_alloc
- 0, // tp_new
-};
-PyTypeObject* CFieldProperty_Type = &_CFieldProperty_Type;
-
-PyObject* NewFieldProperty(const FieldDescriptor* field_descriptor) {
- // Create a new descriptor object
- PyMessageFieldProperty* property =
- PyObject_New(PyMessageFieldProperty, CFieldProperty_Type);
- if (property == NULL) {
- return NULL;
- }
- property->field_descriptor = field_descriptor;
- return reinterpret_cast<PyObject*>(property);
-}
-
-} // namespace python
-} // namespace protobuf
-} // namespace google
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <google/protobuf/pyext/field.h>
+
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/message.h>
+
+#if PY_MAJOR_VERSION >= 3
+ #define PyString_FromFormat PyUnicode_FromFormat
+#endif
+
+namespace google {
+namespace protobuf {
+namespace python {
+
+namespace field {
+
+static PyObject* Repr(PyMessageFieldProperty* self) {
+ return PyString_FromFormat("<field property '%s'>",
+ self->field_descriptor->full_name().c_str());
+}
+
+static PyObject* DescrGet(PyMessageFieldProperty* self, PyObject* obj,
+ PyObject* type) {
+ if (obj == NULL) {
+ Py_INCREF(self);
+ return reinterpret_cast<PyObject*>(self);
+ }
+ return cmessage::GetFieldValue(reinterpret_cast<CMessage*>(obj),
+ self->field_descriptor);
+}
+
+static int DescrSet(PyMessageFieldProperty* self, PyObject* obj,
+ PyObject* value) {
+ if (value == NULL) {
+ PyErr_SetString(PyExc_AttributeError, "Cannot delete field attribute");
+ return -1;
+ }
+ return cmessage::SetFieldValue(reinterpret_cast<CMessage*>(obj),
+ self->field_descriptor, value);
+}
+
+static PyObject* GetDescriptor(PyMessageFieldProperty* self, void* closure) {
+ return PyFieldDescriptor_FromDescriptor(self->field_descriptor);
+}
+
+static PyObject* GetDoc(PyMessageFieldProperty* self, void* closure) {
+ return PyString_FromFormat("Field %s",
+ self->field_descriptor->full_name().c_str());
+}
+
+static PyGetSetDef Getters[] = {
+ {"DESCRIPTOR", (getter)GetDescriptor, NULL, "Field descriptor"},
+ {"__doc__", (getter)GetDoc, NULL, NULL},
+ {NULL}};
+} // namespace field
+
+static PyTypeObject _CFieldProperty_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) // head
+ FULL_MODULE_NAME ".FieldProperty", // tp_name
+ sizeof(PyMessageFieldProperty), // tp_basicsize
+ 0, // tp_itemsize
+ 0, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ (reprfunc)field::Repr, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "Field property of a Message", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ field::Getters, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ (descrgetfunc)field::DescrGet, // tp_descr_get
+ (descrsetfunc)field::DescrSet, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ 0, // tp_new
+};
+PyTypeObject* CFieldProperty_Type = &_CFieldProperty_Type;
+
+PyObject* NewFieldProperty(const FieldDescriptor* field_descriptor) {
+ // Create a new descriptor object
+ PyMessageFieldProperty* property =
+ PyObject_New(PyMessageFieldProperty, CFieldProperty_Type);
+ if (property == NULL) {
+ return NULL;
+ }
+ property->field_descriptor = field_descriptor;
+ return reinterpret_cast<PyObject*>(property);
+}
+
+} // namespace python
+} // namespace protobuf
+} // namespace google
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/field.h b/contrib/python/protobuf/py2/google/protobuf/pyext/field.h
index 7b4660cab5..349e1a9615 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/field.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/field.h
@@ -1,59 +1,59 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
-#define GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
-
-#include <Python.h>
-
-namespace google {
-namespace protobuf {
-
-class FieldDescriptor;
-
-namespace python {
-
-// A data descriptor that represents a field in a Message class.
-struct PyMessageFieldProperty {
- PyObject_HEAD;
-
- // This pointer is owned by the same pool as the Message class it belongs to.
- const FieldDescriptor* field_descriptor;
-};
-
-extern PyTypeObject* CFieldProperty_Type;
-
-PyObject* NewFieldProperty(const FieldDescriptor* field_descriptor);
-
-} // namespace python
-} // namespace protobuf
-} // namespace google
-
-#endif // GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
+#define GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
+
+#include <Python.h>
+
+namespace google {
+namespace protobuf {
+
+class FieldDescriptor;
+
+namespace python {
+
+// A data descriptor that represents a field in a Message class.
+struct PyMessageFieldProperty {
+ PyObject_HEAD;
+
+ // This pointer is owned by the same pool as the Message class it belongs to.
+ const FieldDescriptor* field_descriptor;
+};
+
+extern PyTypeObject* CFieldProperty_Type;
+
+PyObject* NewFieldProperty(const FieldDescriptor* field_descriptor);
+
+} // namespace python
+} // namespace protobuf
+} // namespace google
+
+#endif // GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/map_container.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/map_container.cc
index e7a9cca23b..11da49cb3b 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/map_container.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/map_container.cc
@@ -30,21 +30,21 @@
// Author: haberman@google.com (Josh Haberman)
-#include <google/protobuf/pyext/map_container.h>
+#include <google/protobuf/pyext/map_container.h>
-#include <cstdint>
+#include <cstdint>
#include <memory>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/map.h>
-#include <google/protobuf/map_field.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/repeated_composite_container.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/stubs/map_util.h>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/map.h>
+#include <google/protobuf/map_field.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/repeated_composite_container.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/stubs/map_util.h>
#if PY_MAJOR_VERSION >= 3
#define PyInt_FromLong PyLong_FromLong
@@ -64,52 +64,52 @@ class MapReflectionFriend {
static Py_ssize_t Length(PyObject* _self);
static PyObject* GetIterator(PyObject *_self);
static PyObject* IterNext(PyObject* _self);
- static PyObject* MergeFrom(PyObject* _self, PyObject* arg);
+ static PyObject* MergeFrom(PyObject* _self, PyObject* arg);
// Methods that differ between the map types.
static PyObject* ScalarMapGetItem(PyObject* _self, PyObject* key);
static PyObject* MessageMapGetItem(PyObject* _self, PyObject* key);
static int ScalarMapSetItem(PyObject* _self, PyObject* key, PyObject* v);
static int MessageMapSetItem(PyObject* _self, PyObject* key, PyObject* v);
- static PyObject* ScalarMapToStr(PyObject* _self);
- static PyObject* MessageMapToStr(PyObject* _self);
+ static PyObject* ScalarMapToStr(PyObject* _self);
+ static PyObject* MessageMapToStr(PyObject* _self);
};
struct MapIterator {
PyObject_HEAD;
- std::unique_ptr<::google::protobuf::MapIterator> iter;
+ std::unique_ptr<::google::protobuf::MapIterator> iter;
// A pointer back to the container, so we can notice changes to the version.
// We own a ref on this.
MapContainer* container;
- // We need to keep a ref on the parent Message too, because
+ // We need to keep a ref on the parent Message too, because
// MapIterator::~MapIterator() accesses it. Normally this would be ok because
// the ref on container (above) would guarantee outlive semantics. However in
- // the case of ClearField(), the MapContainer points to a different message,
- // a copy of the original. But our iterator still points to the original,
- // which could now get deleted before us.
+ // the case of ClearField(), the MapContainer points to a different message,
+ // a copy of the original. But our iterator still points to the original,
+ // which could now get deleted before us.
//
// To prevent this, we ensure that the Message will always stay alive as long
// as this iterator does. This is solely for the benefit of the MapIterator
// destructor -- we should never actually access the iterator in this state
// except to delete it.
- CMessage* parent;
+ CMessage* parent;
// The version of the map when we took the iterator to it.
//
// We store this so that if the map is modified during iteration we can throw
// an error.
- uint64_t version;
+ uint64_t version;
};
Message* MapContainer::GetMutableMessage() {
cmessage::AssureWritable(parent);
- return parent->message;
+ return parent->message;
}
// Consumes a reference on the Python string object.
-static bool PyStringToSTL(PyObject* py_string, TProtoStringType* stl_string) {
+static bool PyStringToSTL(PyObject* py_string, TProtoStringType* stl_string) {
char *value;
Py_ssize_t value_len;
@@ -126,9 +126,9 @@ static bool PyStringToSTL(PyObject* py_string, TProtoStringType* stl_string) {
}
}
-static bool PythonToMapKey(MapContainer* self, PyObject* obj, MapKey* key) {
- const FieldDescriptor* field_descriptor =
- self->parent_field_descriptor->message_type()->map_key();
+static bool PythonToMapKey(MapContainer* self, PyObject* obj, MapKey* key) {
+ const FieldDescriptor* field_descriptor =
+ self->parent_field_descriptor->message_type()->map_key();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
GOOGLE_CHECK_GET_INT32(obj, value, false);
@@ -156,7 +156,7 @@ static bool PythonToMapKey(MapContainer* self, PyObject* obj, MapKey* key) {
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- TProtoStringType str;
+ TProtoStringType str;
if (!PyStringToSTL(CheckString(obj, field_descriptor), &str)) {
return false;
}
@@ -172,9 +172,9 @@ static bool PythonToMapKey(MapContainer* self, PyObject* obj, MapKey* key) {
return true;
}
-static PyObject* MapKeyToPython(MapContainer* self, const MapKey& key) {
- const FieldDescriptor* field_descriptor =
- self->parent_field_descriptor->message_type()->map_key();
+static PyObject* MapKeyToPython(MapContainer* self, const MapKey& key) {
+ const FieldDescriptor* field_descriptor =
+ self->parent_field_descriptor->message_type()->map_key();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
return PyInt_FromLong(key.GetInt32Value());
@@ -198,28 +198,28 @@ static PyObject* MapKeyToPython(MapContainer* self, const MapKey& key) {
// This is only used for ScalarMap, so we don't need to handle the
// CPPTYPE_MESSAGE case.
-PyObject* MapValueRefToPython(MapContainer* self, const MapValueRef& value) {
- const FieldDescriptor* field_descriptor =
- self->parent_field_descriptor->message_type()->map_value();
+PyObject* MapValueRefToPython(MapContainer* self, const MapValueRef& value) {
+ const FieldDescriptor* field_descriptor =
+ self->parent_field_descriptor->message_type()->map_value();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
- return PyInt_FromLong(value.GetInt32Value());
+ return PyInt_FromLong(value.GetInt32Value());
case FieldDescriptor::CPPTYPE_INT64:
- return PyLong_FromLongLong(value.GetInt64Value());
+ return PyLong_FromLongLong(value.GetInt64Value());
case FieldDescriptor::CPPTYPE_UINT32:
- return PyInt_FromSize_t(value.GetUInt32Value());
+ return PyInt_FromSize_t(value.GetUInt32Value());
case FieldDescriptor::CPPTYPE_UINT64:
- return PyLong_FromUnsignedLongLong(value.GetUInt64Value());
+ return PyLong_FromUnsignedLongLong(value.GetUInt64Value());
case FieldDescriptor::CPPTYPE_FLOAT:
- return PyFloat_FromDouble(value.GetFloatValue());
+ return PyFloat_FromDouble(value.GetFloatValue());
case FieldDescriptor::CPPTYPE_DOUBLE:
- return PyFloat_FromDouble(value.GetDoubleValue());
+ return PyFloat_FromDouble(value.GetDoubleValue());
case FieldDescriptor::CPPTYPE_BOOL:
- return PyBool_FromLong(value.GetBoolValue());
+ return PyBool_FromLong(value.GetBoolValue());
case FieldDescriptor::CPPTYPE_STRING:
- return ToStringObject(field_descriptor, value.GetStringValue());
+ return ToStringObject(field_descriptor, value.GetStringValue());
case FieldDescriptor::CPPTYPE_ENUM:
- return PyInt_FromLong(value.GetEnumValue());
+ return PyInt_FromLong(value.GetEnumValue());
default:
PyErr_Format(
PyExc_SystemError, "Couldn't convert type %d to value",
@@ -230,11 +230,11 @@ PyObject* MapValueRefToPython(MapContainer* self, const MapValueRef& value) {
// This is only used for ScalarMap, so we don't need to handle the
// CPPTYPE_MESSAGE case.
-static bool PythonToMapValueRef(MapContainer* self, PyObject* obj,
+static bool PythonToMapValueRef(MapContainer* self, PyObject* obj,
bool allow_unknown_enum_values,
MapValueRef* value_ref) {
- const FieldDescriptor* field_descriptor =
- self->parent_field_descriptor->message_type()->map_value();
+ const FieldDescriptor* field_descriptor =
+ self->parent_field_descriptor->message_type()->map_value();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
GOOGLE_CHECK_GET_INT32(obj, value, false);
@@ -272,7 +272,7 @@ static bool PythonToMapValueRef(MapContainer* self, PyObject* obj,
return true;;
}
case FieldDescriptor::CPPTYPE_STRING: {
- TProtoStringType str;
+ TProtoStringType str;
if (!PyStringToSTL(CheckString(obj, field_descriptor), &str)) {
return false;
}
@@ -314,7 +314,7 @@ static MapContainer* GetMap(PyObject* obj) {
Py_ssize_t MapReflectionFriend::Length(PyObject* _self) {
MapContainer* self = GetMap(_self);
- const google::protobuf::Message* message = self->parent->message;
+ const google::protobuf::Message* message = self->parent->message;
return message->GetReflection()->MapSize(*message,
self->parent_field_descriptor);
}
@@ -338,35 +338,35 @@ PyObject* GetEntryClass(PyObject* _self) {
return reinterpret_cast<PyObject*>(message_class);
}
-PyObject* MapReflectionFriend::MergeFrom(PyObject* _self, PyObject* arg) {
- MapContainer* self = GetMap(_self);
- if (!PyObject_TypeCheck(arg, ScalarMapContainer_Type) &&
- !PyObject_TypeCheck(arg, MessageMapContainer_Type)) {
- PyErr_SetString(PyExc_AttributeError, "Not a map field");
- return nullptr;
- }
- MapContainer* other_map = GetMap(arg);
- Message* message = self->GetMutableMessage();
- const Message* other_message = other_map->parent->message;
- const Reflection* reflection = message->GetReflection();
- const Reflection* other_reflection = other_message->GetReflection();
- internal::MapFieldBase* field = reflection->MutableMapData(
- message, self->parent_field_descriptor);
- const internal::MapFieldBase* other_field = other_reflection->GetMapData(
- *other_message, other_map->parent_field_descriptor);
- field->MergeFrom(*other_field);
- self->version++;
- Py_RETURN_NONE;
-}
-
+PyObject* MapReflectionFriend::MergeFrom(PyObject* _self, PyObject* arg) {
+ MapContainer* self = GetMap(_self);
+ if (!PyObject_TypeCheck(arg, ScalarMapContainer_Type) &&
+ !PyObject_TypeCheck(arg, MessageMapContainer_Type)) {
+ PyErr_SetString(PyExc_AttributeError, "Not a map field");
+ return nullptr;
+ }
+ MapContainer* other_map = GetMap(arg);
+ Message* message = self->GetMutableMessage();
+ const Message* other_message = other_map->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ const Reflection* other_reflection = other_message->GetReflection();
+ internal::MapFieldBase* field = reflection->MutableMapData(
+ message, self->parent_field_descriptor);
+ const internal::MapFieldBase* other_field = other_reflection->GetMapData(
+ *other_message, other_map->parent_field_descriptor);
+ field->MergeFrom(*other_field);
+ self->version++;
+ Py_RETURN_NONE;
+}
+
PyObject* MapReflectionFriend::Contains(PyObject* _self, PyObject* key) {
MapContainer* self = GetMap(_self);
- const Message* message = self->parent->message;
+ const Message* message = self->parent->message;
const Reflection* reflection = message->GetReflection();
MapKey map_key;
- if (!PythonToMapKey(self, key, &map_key)) {
+ if (!PythonToMapKey(self, key, &map_key)) {
return NULL;
}
@@ -380,27 +380,27 @@ PyObject* MapReflectionFriend::Contains(PyObject* _self, PyObject* key) {
// ScalarMap ///////////////////////////////////////////////////////////////////
-MapContainer* NewScalarMapContainer(
+MapContainer* NewScalarMapContainer(
CMessage* parent, const google::protobuf::FieldDescriptor* parent_field_descriptor) {
if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
return NULL;
}
- PyObject* obj(PyType_GenericAlloc(ScalarMapContainer_Type, 0));
- if (obj == NULL) {
- PyErr_Format(PyExc_RuntimeError,
- "Could not allocate new container.");
- return NULL;
+ PyObject* obj(PyType_GenericAlloc(ScalarMapContainer_Type, 0));
+ if (obj == NULL) {
+ PyErr_Format(PyExc_RuntimeError,
+ "Could not allocate new container.");
+ return NULL;
}
- MapContainer* self = GetMap(obj);
+ MapContainer* self = GetMap(obj);
- Py_INCREF(parent);
+ Py_INCREF(parent);
self->parent = parent;
self->parent_field_descriptor = parent_field_descriptor;
self->version = 0;
- return self;
+ return self;
}
PyObject* MapReflectionFriend::ScalarMapGetItem(PyObject* _self,
@@ -412,7 +412,7 @@ PyObject* MapReflectionFriend::ScalarMapGetItem(PyObject* _self,
MapKey map_key;
MapValueRef value;
- if (!PythonToMapKey(self, key, &map_key)) {
+ if (!PythonToMapKey(self, key, &map_key)) {
return NULL;
}
@@ -421,7 +421,7 @@ PyObject* MapReflectionFriend::ScalarMapGetItem(PyObject* _self,
self->version++;
}
- return MapValueRefToPython(self, value);
+ return MapValueRefToPython(self, value);
}
int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,
@@ -433,7 +433,7 @@ int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,
MapKey map_key;
MapValueRef value;
- if (!PythonToMapKey(self, key, &map_key)) {
+ if (!PythonToMapKey(self, key, &map_key)) {
return -1;
}
@@ -444,11 +444,11 @@ int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,
reflection->InsertOrLookupMapValue(message, self->parent_field_descriptor,
map_key, &value);
- if (!PythonToMapValueRef(self, v, reflection->SupportsUnknownEnumValues(),
- &value)) {
- return -1;
- }
- return 0;
+ if (!PythonToMapValueRef(self, v, reflection->SupportsUnknownEnumValues(),
+ &value)) {
+ return -1;
+ }
+ return 0;
} else {
// Delete key from map.
if (reflection->DeleteMapValue(message, self->parent_field_descriptor,
@@ -461,14 +461,14 @@ int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,
}
}
-static PyObject* ScalarMapGet(PyObject* self, PyObject* args,
- PyObject* kwargs) {
- static const char* kwlist[] = {"key", "default", nullptr};
+static PyObject* ScalarMapGet(PyObject* self, PyObject* args,
+ PyObject* kwargs) {
+ static const char* kwlist[] = {"key", "default", nullptr};
PyObject* key;
PyObject* default_value = NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
- const_cast<char**>(kwlist), &key,
- &default_value)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
+ const_cast<char**>(kwlist), &key,
+ &default_value)) {
return NULL;
}
@@ -489,65 +489,65 @@ static PyObject* ScalarMapGet(PyObject* self, PyObject* args,
}
}
-PyObject* MapReflectionFriend::ScalarMapToStr(PyObject* _self) {
- ScopedPyObjectPtr dict(PyDict_New());
- if (dict == NULL) {
- return NULL;
- }
- ScopedPyObjectPtr key;
- ScopedPyObjectPtr value;
-
- MapContainer* self = GetMap(_self);
- Message* message = self->GetMutableMessage();
- const Reflection* reflection = message->GetReflection();
- for (google::protobuf::MapIterator it = reflection->MapBegin(
- message, self->parent_field_descriptor);
- it != reflection->MapEnd(message, self->parent_field_descriptor);
- ++it) {
- key.reset(MapKeyToPython(self, it.GetKey()));
- if (key == NULL) {
- return NULL;
- }
- value.reset(MapValueRefToPython(self, it.GetValueRef()));
- if (value == NULL) {
- return NULL;
- }
- if (PyDict_SetItem(dict.get(), key.get(), value.get()) < 0) {
- return NULL;
- }
- }
- return PyObject_Repr(dict.get());
-}
-
+PyObject* MapReflectionFriend::ScalarMapToStr(PyObject* _self) {
+ ScopedPyObjectPtr dict(PyDict_New());
+ if (dict == NULL) {
+ return NULL;
+ }
+ ScopedPyObjectPtr key;
+ ScopedPyObjectPtr value;
+
+ MapContainer* self = GetMap(_self);
+ Message* message = self->GetMutableMessage();
+ const Reflection* reflection = message->GetReflection();
+ for (google::protobuf::MapIterator it = reflection->MapBegin(
+ message, self->parent_field_descriptor);
+ it != reflection->MapEnd(message, self->parent_field_descriptor);
+ ++it) {
+ key.reset(MapKeyToPython(self, it.GetKey()));
+ if (key == NULL) {
+ return NULL;
+ }
+ value.reset(MapValueRefToPython(self, it.GetValueRef()));
+ if (value == NULL) {
+ return NULL;
+ }
+ if (PyDict_SetItem(dict.get(), key.get(), value.get()) < 0) {
+ return NULL;
+ }
+ }
+ return PyObject_Repr(dict.get());
+}
+
static void ScalarMapDealloc(PyObject* _self) {
MapContainer* self = GetMap(_self);
- self->RemoveFromParentCache();
- PyTypeObject *type = Py_TYPE(_self);
- type->tp_free(_self);
- if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
- // With Python3, the Map class is not static, and must be managed.
- Py_DECREF(type);
- }
+ self->RemoveFromParentCache();
+ PyTypeObject *type = Py_TYPE(_self);
+ type->tp_free(_self);
+ if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
+ // With Python3, the Map class is not static, and must be managed.
+ Py_DECREF(type);
+ }
}
static PyMethodDef ScalarMapMethods[] = {
- {"__contains__", MapReflectionFriend::Contains, METH_O,
- "Tests whether a key is a member of the map."},
- {"clear", (PyCFunction)Clear, METH_NOARGS,
- "Removes all elements from the map."},
- {"get", (PyCFunction)ScalarMapGet, METH_VARARGS | METH_KEYWORDS,
- "Gets the value for the given key if present, or otherwise a default"},
- {"GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS,
- "Return the class used to build Entries of (key, value) pairs."},
- {"MergeFrom", (PyCFunction)MapReflectionFriend::MergeFrom, METH_O,
- "Merges a map into the current map."},
- /*
- { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
- "Makes a deep copy of the class." },
- { "__reduce__", (PyCFunction)Reduce, METH_NOARGS,
- "Outputs picklable representation of the repeated field." },
- */
- {NULL, NULL},
+ {"__contains__", MapReflectionFriend::Contains, METH_O,
+ "Tests whether a key is a member of the map."},
+ {"clear", (PyCFunction)Clear, METH_NOARGS,
+ "Removes all elements from the map."},
+ {"get", (PyCFunction)ScalarMapGet, METH_VARARGS | METH_KEYWORDS,
+ "Gets the value for the given key if present, or otherwise a default"},
+ {"GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS,
+ "Return the class used to build Entries of (key, value) pairs."},
+ {"MergeFrom", (PyCFunction)MapReflectionFriend::MergeFrom, METH_O,
+ "Merges a map into the current map."},
+ /*
+ { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
+ "Makes a deep copy of the class." },
+ { "__reduce__", (PyCFunction)Reduce, METH_NOARGS,
+ "Outputs picklable representation of the repeated field." },
+ */
+ {NULL, NULL},
};
PyTypeObject *ScalarMapContainer_Type;
@@ -559,7 +559,7 @@ PyTypeObject *ScalarMapContainer_Type;
{Py_mp_ass_subscript, (void *)MapReflectionFriend::ScalarMapSetItem},
{Py_tp_methods, (void *)ScalarMapMethods},
{Py_tp_iter, (void *)MapReflectionFriend::GetIterator},
- {Py_tp_repr, (void *)MapReflectionFriend::ScalarMapToStr},
+ {Py_tp_repr, (void *)MapReflectionFriend::ScalarMapToStr},
{0, 0},
};
@@ -587,7 +587,7 @@ PyTypeObject *ScalarMapContainer_Type;
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
- MapReflectionFriend::ScalarMapToStr, // tp_repr
+ MapReflectionFriend::ScalarMapToStr, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
&ScalarMapMappingMethods, // tp_as_mapping
@@ -626,13 +626,13 @@ static MessageMapContainer* GetMessageMap(PyObject* obj) {
static PyObject* GetCMessage(MessageMapContainer* self, Message* message) {
// Get or create the CMessage object corresponding to this message.
- return self->parent
- ->BuildSubMessageFromPointer(self->parent_field_descriptor, message,
- self->message_class)
- ->AsPyObject();
+ return self->parent
+ ->BuildSubMessageFromPointer(self->parent_field_descriptor, message,
+ self->message_class)
+ ->AsPyObject();
}
-MessageMapContainer* NewMessageMapContainer(
+MessageMapContainer* NewMessageMapContainer(
CMessage* parent, const google::protobuf::FieldDescriptor* parent_field_descriptor,
CMessageClass* message_class) {
if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
@@ -641,13 +641,13 @@ MessageMapContainer* NewMessageMapContainer(
PyObject* obj = PyType_GenericAlloc(MessageMapContainer_Type, 0);
if (obj == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "Could not allocate new container.");
- return NULL;
+ PyErr_SetString(PyExc_RuntimeError, "Could not allocate new container.");
+ return NULL;
}
MessageMapContainer* self = GetMessageMap(obj);
- Py_INCREF(parent);
+ Py_INCREF(parent);
self->parent = parent;
self->parent_field_descriptor = parent_field_descriptor;
self->version = 0;
@@ -655,7 +655,7 @@ MessageMapContainer* NewMessageMapContainer(
Py_INCREF(message_class);
self->message_class = message_class;
- return self;
+ return self;
}
int MapReflectionFriend::MessageMapSetItem(PyObject* _self, PyObject* key,
@@ -676,7 +676,7 @@ int MapReflectionFriend::MessageMapSetItem(PyObject* _self, PyObject* key,
self->version++;
- if (!PythonToMapKey(self, key, &map_key)) {
+ if (!PythonToMapKey(self, key, &map_key)) {
return -1;
}
@@ -687,15 +687,15 @@ int MapReflectionFriend::MessageMapSetItem(PyObject* _self, PyObject* key,
MapValueRef value;
reflection->InsertOrLookupMapValue(message, self->parent_field_descriptor,
map_key, &value);
- Message* sub_message = value.MutableMessageValue();
- // If there is a living weak reference to an item, we "Release" it,
- // otherwise we just discard the C++ value.
- if (CMessage* released =
- self->parent->MaybeReleaseSubMessage(sub_message)) {
- Message* msg = released->message;
- released->message = msg->New();
- msg->GetReflection()->Swap(msg, released->message);
- }
+ Message* sub_message = value.MutableMessageValue();
+ // If there is a living weak reference to an item, we "Release" it,
+ // otherwise we just discard the C++ value.
+ if (CMessage* released =
+ self->parent->MaybeReleaseSubMessage(sub_message)) {
+ Message* msg = released->message;
+ released->message = msg->New();
+ msg->GetReflection()->Swap(msg, released->message);
+ }
// Delete key from map.
reflection->DeleteMapValue(message, self->parent_field_descriptor,
@@ -716,7 +716,7 @@ PyObject* MapReflectionFriend::MessageMapGetItem(PyObject* _self,
MapKey map_key;
MapValueRef value;
- if (!PythonToMapKey(self, key, &map_key)) {
+ if (!PythonToMapKey(self, key, &map_key)) {
return NULL;
}
@@ -728,43 +728,43 @@ PyObject* MapReflectionFriend::MessageMapGetItem(PyObject* _self,
return GetCMessage(self, value.MutableMessageValue());
}
-PyObject* MapReflectionFriend::MessageMapToStr(PyObject* _self) {
- ScopedPyObjectPtr dict(PyDict_New());
- if (dict == NULL) {
- return NULL;
- }
- ScopedPyObjectPtr key;
- ScopedPyObjectPtr value;
-
- MessageMapContainer* self = GetMessageMap(_self);
- Message* message = self->GetMutableMessage();
- const Reflection* reflection = message->GetReflection();
- for (google::protobuf::MapIterator it = reflection->MapBegin(
- message, self->parent_field_descriptor);
- it != reflection->MapEnd(message, self->parent_field_descriptor);
- ++it) {
- key.reset(MapKeyToPython(self, it.GetKey()));
- if (key == NULL) {
- return NULL;
- }
- value.reset(GetCMessage(self, it.MutableValueRef()->MutableMessageValue()));
- if (value == NULL) {
- return NULL;
- }
- if (PyDict_SetItem(dict.get(), key.get(), value.get()) < 0) {
- return NULL;
- }
- }
- return PyObject_Repr(dict.get());
-}
-
-PyObject* MessageMapGet(PyObject* self, PyObject* args, PyObject* kwargs) {
- static const char* kwlist[] = {"key", "default", nullptr};
+PyObject* MapReflectionFriend::MessageMapToStr(PyObject* _self) {
+ ScopedPyObjectPtr dict(PyDict_New());
+ if (dict == NULL) {
+ return NULL;
+ }
+ ScopedPyObjectPtr key;
+ ScopedPyObjectPtr value;
+
+ MessageMapContainer* self = GetMessageMap(_self);
+ Message* message = self->GetMutableMessage();
+ const Reflection* reflection = message->GetReflection();
+ for (google::protobuf::MapIterator it = reflection->MapBegin(
+ message, self->parent_field_descriptor);
+ it != reflection->MapEnd(message, self->parent_field_descriptor);
+ ++it) {
+ key.reset(MapKeyToPython(self, it.GetKey()));
+ if (key == NULL) {
+ return NULL;
+ }
+ value.reset(GetCMessage(self, it.MutableValueRef()->MutableMessageValue()));
+ if (value == NULL) {
+ return NULL;
+ }
+ if (PyDict_SetItem(dict.get(), key.get(), value.get()) < 0) {
+ return NULL;
+ }
+ }
+ return PyObject_Repr(dict.get());
+}
+
+PyObject* MessageMapGet(PyObject* self, PyObject* args, PyObject* kwargs) {
+ static const char* kwlist[] = {"key", "default", nullptr};
PyObject* key;
PyObject* default_value = NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
- const_cast<char**>(kwlist), &key,
- &default_value)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
+ const_cast<char**>(kwlist), &key,
+ &default_value)) {
return NULL;
}
@@ -787,36 +787,36 @@ PyObject* MessageMapGet(PyObject* self, PyObject* args, PyObject* kwargs) {
static void MessageMapDealloc(PyObject* _self) {
MessageMapContainer* self = GetMessageMap(_self);
- self->RemoveFromParentCache();
+ self->RemoveFromParentCache();
Py_DECREF(self->message_class);
- PyTypeObject *type = Py_TYPE(_self);
- type->tp_free(_self);
- if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
- // With Python3, the Map class is not static, and must be managed.
- Py_DECREF(type);
- }
+ PyTypeObject *type = Py_TYPE(_self);
+ type->tp_free(_self);
+ if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
+ // With Python3, the Map class is not static, and must be managed.
+ Py_DECREF(type);
+ }
}
static PyMethodDef MessageMapMethods[] = {
- {"__contains__", (PyCFunction)MapReflectionFriend::Contains, METH_O,
- "Tests whether the map contains this element."},
- {"clear", (PyCFunction)Clear, METH_NOARGS,
- "Removes all elements from the map."},
- {"get", (PyCFunction)MessageMapGet, METH_VARARGS | METH_KEYWORDS,
- "Gets the value for the given key if present, or otherwise a default"},
- {"get_or_create", MapReflectionFriend::MessageMapGetItem, METH_O,
- "Alias for getitem, useful to make explicit that the map is mutated."},
- {"GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS,
- "Return the class used to build Entries of (key, value) pairs."},
- {"MergeFrom", (PyCFunction)MapReflectionFriend::MergeFrom, METH_O,
- "Merges a map into the current map."},
- /*
- { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
- "Makes a deep copy of the class." },
- { "__reduce__", (PyCFunction)Reduce, METH_NOARGS,
- "Outputs picklable representation of the repeated field." },
- */
- {NULL, NULL},
+ {"__contains__", (PyCFunction)MapReflectionFriend::Contains, METH_O,
+ "Tests whether the map contains this element."},
+ {"clear", (PyCFunction)Clear, METH_NOARGS,
+ "Removes all elements from the map."},
+ {"get", (PyCFunction)MessageMapGet, METH_VARARGS | METH_KEYWORDS,
+ "Gets the value for the given key if present, or otherwise a default"},
+ {"get_or_create", MapReflectionFriend::MessageMapGetItem, METH_O,
+ "Alias for getitem, useful to make explicit that the map is mutated."},
+ {"GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS,
+ "Return the class used to build Entries of (key, value) pairs."},
+ {"MergeFrom", (PyCFunction)MapReflectionFriend::MergeFrom, METH_O,
+ "Merges a map into the current map."},
+ /*
+ { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
+ "Makes a deep copy of the class." },
+ { "__reduce__", (PyCFunction)Reduce, METH_NOARGS,
+ "Outputs picklable representation of the repeated field." },
+ */
+ {NULL, NULL},
};
PyTypeObject *MessageMapContainer_Type;
@@ -828,7 +828,7 @@ PyTypeObject *MessageMapContainer_Type;
{Py_mp_ass_subscript, (void *)MapReflectionFriend::MessageMapSetItem},
{Py_tp_methods, (void *)MessageMapMethods},
{Py_tp_iter, (void *)MapReflectionFriend::GetIterator},
- {Py_tp_repr, (void *)MapReflectionFriend::MessageMapToStr},
+ {Py_tp_repr, (void *)MapReflectionFriend::MessageMapToStr},
{0, 0}
};
@@ -856,7 +856,7 @@ PyTypeObject *MessageMapContainer_Type;
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
- MapReflectionFriend::MessageMapToStr, // tp_repr
+ MapReflectionFriend::MessageMapToStr, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
&MessageMapMappingMethods, // tp_as_mapping
@@ -905,8 +905,8 @@ PyObject* MapReflectionFriend::GetIterator(PyObject *_self) {
Py_INCREF(self);
iter->container = self;
iter->version = self->version;
- Py_INCREF(self->parent);
- iter->parent = self->parent;
+ Py_INCREF(self->parent);
+ iter->parent = self->parent;
if (MapReflectionFriend::Length(_self) > 0) {
Message* message = self->GetMutableMessage();
@@ -928,10 +928,10 @@ PyObject* MapReflectionFriend::IterNext(PyObject* _self) {
return PyErr_Format(PyExc_RuntimeError,
"Map modified during iteration.");
}
- if (self->parent != self->container->parent) {
- return PyErr_Format(PyExc_RuntimeError,
- "Map cleared during iteration.");
- }
+ if (self->parent != self->container->parent) {
+ return PyErr_Format(PyExc_RuntimeError,
+ "Map cleared during iteration.");
+ }
if (self->iter.get() == NULL) {
return NULL;
@@ -945,7 +945,7 @@ PyObject* MapReflectionFriend::IterNext(PyObject* _self) {
return NULL;
}
- PyObject* ret = MapKeyToPython(self->container, self->iter->GetKey());
+ PyObject* ret = MapKeyToPython(self->container, self->iter->GetKey());
++(*self->iter);
@@ -955,8 +955,8 @@ PyObject* MapReflectionFriend::IterNext(PyObject* _self) {
static void DeallocMapIterator(PyObject* _self) {
MapIterator* self = GetIter(_self);
self->iter.reset();
- Py_CLEAR(self->container);
- Py_CLEAR(self->parent);
+ Py_CLEAR(self->container);
+ Py_CLEAR(self->parent);
Py_TYPE(_self)->tp_free(_self);
}
@@ -1013,15 +1013,15 @@ bool InitMapContainers() {
return false;
}
- Py_INCREF(mutable_mapping.get());
-#if PY_MAJOR_VERSION >= 3
- ScopedPyObjectPtr bases(PyTuple_Pack(1, mutable_mapping.get()));
- if (bases == NULL) {
+ Py_INCREF(mutable_mapping.get());
+#if PY_MAJOR_VERSION >= 3
+ ScopedPyObjectPtr bases(PyTuple_Pack(1, mutable_mapping.get()));
+ if (bases == NULL) {
return false;
}
ScalarMapContainer_Type = reinterpret_cast<PyTypeObject*>(
- PyType_FromSpecWithBases(&ScalarMapContainer_Type_spec, bases.get()));
+ PyType_FromSpecWithBases(&ScalarMapContainer_Type_spec, bases.get()));
#else
_ScalarMapContainer_Type.tp_base =
reinterpret_cast<PyTypeObject*>(mutable_mapping.get());
@@ -1039,7 +1039,7 @@ bool InitMapContainers() {
#if PY_MAJOR_VERSION >= 3
MessageMapContainer_Type = reinterpret_cast<PyTypeObject*>(
- PyType_FromSpecWithBases(&MessageMapContainer_Type_spec, bases.get()));
+ PyType_FromSpecWithBases(&MessageMapContainer_Type_spec, bases.get()));
#else
Py_INCREF(mutable_mapping.get());
_MessageMapContainer_Type.tp_base =
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/map_container.h b/contrib/python/protobuf/py2/google/protobuf/pyext/map_container.h
index 842602e79f..7a5bfed193 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/map_container.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/map_container.h
@@ -33,12 +33,12 @@
#include <Python.h>
-#include <cstdint>
+#include <cstdint>
#include <memory>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/message.h>
namespace google {
namespace protobuf {
@@ -51,13 +51,13 @@ struct CMessageClass;
// This struct is used directly for ScalarMap, and is the base class of
// MessageMapContainer, which is used for MessageMap.
-struct MapContainer : public ContainerBase {
+struct MapContainer : public ContainerBase {
// Use to get a mutable message when necessary.
Message* GetMutableMessage();
// We bump this whenever we perform a mutation, to invalidate existing
// iterators.
- uint64_t version;
+ uint64_t version;
};
struct MessageMapContainer : public MapContainer {
@@ -73,17 +73,17 @@ extern PyTypeObject MapIterator_Type; // Both map types use the same iterator.
// Builds a MapContainer object, from a parent message and a
// field descriptor.
-extern MapContainer* NewScalarMapContainer(
+extern MapContainer* NewScalarMapContainer(
CMessage* parent, const FieldDescriptor* parent_field_descriptor);
// Builds a MessageMap object, from a parent message and a
// field descriptor.
-extern MessageMapContainer* NewMessageMapContainer(
+extern MessageMapContainer* NewMessageMapContainer(
CMessage* parent, const FieldDescriptor* parent_field_descriptor,
CMessageClass* message_class);
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/message.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/message.cc
index 8b41ca47dd..bdc4bfd612 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/message.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/message.cc
@@ -31,52 +31,52 @@
// Author: anuraag@google.com (Anuraag Agrawal)
// Author: tibell@google.com (Johan Tibell)
-#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message.h>
-#include <structmember.h> // A Python header file.
-
-#include <cstdint>
+#include <structmember.h> // A Python header file.
+
+#include <cstdint>
#include <map>
#include <memory>
-#include <string>
+#include <string>
#include <vector>
-#include <google/protobuf/stubs/strutil.h>
-
+#include <google/protobuf/stubs/strutil.h>
+
#ifndef PyVarObject_HEAD_INIT
#define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
#endif
#ifndef Py_TYPE
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#endif
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/text_format.h>
-#include <google/protobuf/unknown_field_set.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/extension_dict.h>
-#include <google/protobuf/pyext/field.h>
-#include <google/protobuf/pyext/map_container.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/repeated_composite_container.h>
-#include <google/protobuf/pyext/repeated_scalar_container.h>
-#include <google/protobuf/pyext/safe_numerics.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/pyext/unknown_fields.h>
-#include <google/protobuf/util/message_differencer.h>
-#include <google/protobuf/io/strtod.h>
-#include <google/protobuf/stubs/map_util.h>
-
-// clang-format off
-#include <google/protobuf/port_def.inc>
-// clang-format on
-
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
+#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/text_format.h>
+#include <google/protobuf/unknown_field_set.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/extension_dict.h>
+#include <google/protobuf/pyext/field.h>
+#include <google/protobuf/pyext/map_container.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/repeated_composite_container.h>
+#include <google/protobuf/pyext/repeated_scalar_container.h>
+#include <google/protobuf/pyext/safe_numerics.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/pyext/unknown_fields.h>
+#include <google/protobuf/util/message_differencer.h>
+#include <google/protobuf/io/strtod.h>
+#include <google/protobuf/stubs/map_util.h>
+
+// clang-format off
+#include <google/protobuf/port_def.inc>
+// clang-format on
+
#if PY_MAJOR_VERSION >= 3
#define PyInt_AsLong PyLong_AsLong
#define PyInt_FromLong PyLong_FromLong
@@ -84,34 +84,34 @@
#define PyString_Check PyUnicode_Check
#define PyString_FromString PyUnicode_FromString
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
- #define PyString_FromFormat PyUnicode_FromFormat
+ #define PyString_FromFormat PyUnicode_FromFormat
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#else
#define PyString_AsString(ob) \
(PyUnicode_Check(ob)? PyUnicode_AsUTF8(ob): PyBytes_AsString(ob))
-#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
-#endif
+#define PyString_AsStringAndSize(ob, charpp, sizep) \
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
+#endif
namespace google {
namespace protobuf {
namespace python {
-class MessageReflectionFriend {
- public:
- static void UnsafeShallowSwapFields(
- Message* lhs, Message* rhs,
- const std::vector<const FieldDescriptor*>& fields) {
- lhs->GetReflection()->UnsafeShallowSwapFields(lhs, rhs, fields);
- }
-};
-
+class MessageReflectionFriend {
+ public:
+ static void UnsafeShallowSwapFields(
+ Message* lhs, Message* rhs,
+ const std::vector<const FieldDescriptor*>& fields) {
+ lhs->GetReflection()->UnsafeShallowSwapFields(lhs, rhs, fields);
+ }
+};
+
static PyObject* kDESCRIPTOR;
PyObject* EnumTypeWrapper_class;
static PyObject* PythonMessage_class;
@@ -122,26 +122,26 @@ namespace message_meta {
static int InsertEmptyWeakref(PyTypeObject* base);
-namespace {
-// Copied over from internal 'google/protobuf/stubs/strutil.h'.
-inline void LowerString(TProtoStringType* s) {
- s->to_lower();
+namespace {
+// Copied over from internal 'google/protobuf/stubs/strutil.h'.
+inline void LowerString(TProtoStringType* s) {
+ s->to_lower();
}
-} // namespace
+} // namespace
// Finalize the creation of the Message class.
static int AddDescriptors(PyObject* cls, const Descriptor* descriptor) {
// For each field set: cls.<field>_FIELD_NUMBER = <number>
for (int i = 0; i < descriptor->field_count(); ++i) {
- const FieldDescriptor* field_descriptor = descriptor->field(i);
- ScopedPyObjectPtr property(NewFieldProperty(field_descriptor));
- if (property == NULL) {
- return -1;
- }
- if (PyObject_SetAttrString(cls, field_descriptor->name().c_str(),
- property.get()) < 0) {
+ const FieldDescriptor* field_descriptor = descriptor->field(i);
+ ScopedPyObjectPtr property(NewFieldProperty(field_descriptor));
+ if (property == NULL) {
return -1;
}
+ if (PyObject_SetAttrString(cls, field_descriptor->name().c_str(),
+ property.get()) < 0) {
+ return -1;
+ }
}
// For each enum set cls.<enum name> = EnumTypeWrapper(<enum descriptor>).
@@ -151,7 +151,7 @@ static int AddDescriptors(PyObject* cls, const Descriptor* descriptor) {
PyEnumDescriptor_FromDescriptor(enum_descriptor));
if (enum_type == NULL) {
return -1;
- }
+ }
// Add wrapped enum type to message class.
ScopedPyObjectPtr wrapped(PyObject_CallFunctionObjArgs(
EnumTypeWrapper_class, enum_type.get(), NULL));
@@ -201,15 +201,15 @@ static int AddDescriptors(PyObject* cls, const Descriptor* descriptor) {
return 0;
}
-static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
- static const char* kwlist[] = {"name", "bases", "dict", 0};
+static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
+ static const char* kwlist[] = {"name", "bases", "dict", 0};
PyObject *bases, *dict;
const char* name;
// Check arguments: (name, bases, dict)
- if (!PyArg_ParseTupleAndKeywords(
- args, kwargs, "sO!O!:type", const_cast<char**>(kwlist), &name,
- &PyTuple_Type, &bases, &PyDict_Type, &dict)) {
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kwargs, "sO!O!:type", const_cast<char**>(kwlist), &name,
+ &PyTuple_Type, &bases, &PyDict_Type, &dict)) {
return NULL;
}
@@ -224,20 +224,20 @@ static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
// Check dict['DESCRIPTOR']
PyObject* py_descriptor = PyDict_GetItem(dict, kDESCRIPTOR);
- if (py_descriptor == nullptr) {
+ if (py_descriptor == nullptr) {
PyErr_SetString(PyExc_TypeError, "Message class has no DESCRIPTOR");
- return nullptr;
+ return nullptr;
}
if (!PyObject_TypeCheck(py_descriptor, &PyMessageDescriptor_Type)) {
PyErr_Format(PyExc_TypeError, "Expected a message Descriptor, got %s",
py_descriptor->ob_type->tp_name);
- return nullptr;
- }
- const Descriptor* message_descriptor =
- PyMessageDescriptor_AsDescriptor(py_descriptor);
- if (message_descriptor == nullptr) {
- return nullptr;
+ return nullptr;
}
+ const Descriptor* message_descriptor =
+ PyMessageDescriptor_AsDescriptor(py_descriptor);
+ if (message_descriptor == nullptr) {
+ return nullptr;
+ }
// Messages have no __dict__
ScopedPyObjectPtr slots(PyTuple_New(0));
@@ -261,10 +261,10 @@ static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
PyObject* well_known_class = PyDict_GetItemString(
WKT_classes, message_descriptor->full_name().c_str());
if (well_known_class == NULL) {
- new_args.reset(Py_BuildValue("s(OO)O", name, CMessage_Type,
+ new_args.reset(Py_BuildValue("s(OO)O", name, CMessage_Type,
PythonMessage_class, dict));
} else {
- new_args.reset(Py_BuildValue("s(OOO)O", name, CMessage_Type,
+ new_args.reset(Py_BuildValue("s(OOO)O", name, CMessage_Type,
PythonMessage_class, well_known_class, dict));
}
@@ -281,7 +281,7 @@ static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
// Insert the empty weakref into the base classes.
if (InsertEmptyWeakref(
reinterpret_cast<PyTypeObject*>(PythonMessage_class)) < 0 ||
- InsertEmptyWeakref(CMessage_Type) < 0) {
+ InsertEmptyWeakref(CMessage_Type) < 0) {
return NULL;
}
@@ -319,26 +319,26 @@ static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
return result.release();
}
-static void Dealloc(PyObject* pself) {
- CMessageClass* self = reinterpret_cast<CMessageClass*>(pself);
+static void Dealloc(PyObject* pself) {
+ CMessageClass* self = reinterpret_cast<CMessageClass*>(pself);
Py_XDECREF(self->py_message_descriptor);
Py_XDECREF(self->py_message_factory);
- return PyType_Type.tp_dealloc(pself);
-}
-
-static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
- CMessageClass* self = reinterpret_cast<CMessageClass*>(pself);
- Py_VISIT(self->py_message_descriptor);
- Py_VISIT(self->py_message_factory);
- return PyType_Type.tp_traverse(pself, visit, arg);
-}
-
-static int GcClear(PyObject* pself) {
- // It's important to keep the descriptor and factory alive, until the
- // C++ message is fully destructed.
- return PyType_Type.tp_clear(pself);
-}
-
+ return PyType_Type.tp_dealloc(pself);
+}
+
+static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
+ CMessageClass* self = reinterpret_cast<CMessageClass*>(pself);
+ Py_VISIT(self->py_message_descriptor);
+ Py_VISIT(self->py_message_factory);
+ return PyType_Type.tp_traverse(pself, visit, arg);
+}
+
+static int GcClear(PyObject* pself) {
+ // It's important to keep the descriptor and factory alive, until the
+ // C++ message is fully destructed.
+ return PyType_Type.tp_clear(pself);
+}
+
// This function inserts and empty weakref at the end of the list of
// subclasses for the main protocol buffer Message class.
//
@@ -351,16 +351,16 @@ static int InsertEmptyWeakref(PyTypeObject *base_type) {
// https://bugs.python.org/issue17936.
return 0;
#else
-#ifdef Py_DEBUG
- // The code below causes all new subclasses to append an entry, which is never
- // cleared. This is a small memory leak, which we disable in Py_DEBUG mode
- // to have stable refcounting checks.
-#else
+#ifdef Py_DEBUG
+ // The code below causes all new subclasses to append an entry, which is never
+ // cleared. This is a small memory leak, which we disable in Py_DEBUG mode
+ // to have stable refcounting checks.
+#else
PyObject *subclasses = base_type->tp_subclasses;
if (subclasses && PyList_CheckExact(subclasses)) {
return PyList_Append(subclasses, kEmptyWeakref);
}
-#endif // !Py_DEBUG
+#endif // !Py_DEBUG
return 0;
#endif // PY_MAJOR_VERSION >= 3
}
@@ -368,13 +368,13 @@ static int InsertEmptyWeakref(PyTypeObject *base_type) {
// The _extensions_by_name dictionary is built on every access.
// TODO(amauryfa): Migrate all users to pool.FindAllExtensions()
static PyObject* GetExtensionsByName(CMessageClass *self, void *closure) {
- if (self->message_descriptor == NULL) {
- // This is the base Message object, simply raise AttributeError.
- PyErr_SetString(PyExc_AttributeError,
- "Base Message class has no DESCRIPTOR");
- return NULL;
- }
-
+ if (self->message_descriptor == NULL) {
+ // This is the base Message object, simply raise AttributeError.
+ PyErr_SetString(PyExc_AttributeError,
+ "Base Message class has no DESCRIPTOR");
+ return NULL;
+ }
+
const PyDescriptorPool* pool = self->py_message_factory->pool;
std::vector<const FieldDescriptor*> extensions;
@@ -398,13 +398,13 @@ static PyObject* GetExtensionsByName(CMessageClass *self, void *closure) {
// The _extensions_by_number dictionary is built on every access.
// TODO(amauryfa): Migrate all users to pool.FindExtensionByNumber()
static PyObject* GetExtensionsByNumber(CMessageClass *self, void *closure) {
- if (self->message_descriptor == NULL) {
- // This is the base Message object, simply raise AttributeError.
- PyErr_SetString(PyExc_AttributeError,
- "Base Message class has no DESCRIPTOR");
- return NULL;
- }
-
+ if (self->message_descriptor == NULL) {
+ // This is the base Message object, simply raise AttributeError.
+ PyErr_SetString(PyExc_AttributeError,
+ "Base Message class has no DESCRIPTOR");
+ return NULL;
+ }
+
const PyDescriptorPool* pool = self->py_message_factory->pool;
std::vector<const FieldDescriptor*> extensions;
@@ -434,94 +434,94 @@ static PyGetSetDef Getters[] = {
{NULL}
};
-// Compute some class attributes on the fly:
-// - All the _FIELD_NUMBER attributes, for all fields and nested extensions.
-// Returns a new reference, or NULL with an exception set.
-static PyObject* GetClassAttribute(CMessageClass *self, PyObject* name) {
- char* attr;
- Py_ssize_t attr_size;
- static const char kSuffix[] = "_FIELD_NUMBER";
- if (PyString_AsStringAndSize(name, &attr, &attr_size) >= 0 &&
- HasSuffixString(StringPiece(attr, attr_size), kSuffix)) {
- TProtoStringType field_name(attr, attr_size - sizeof(kSuffix) + 1);
- LowerString(&field_name);
-
- // Try to find a field with the given name, without the suffix.
- const FieldDescriptor* field =
- self->message_descriptor->FindFieldByLowercaseName(field_name);
- if (!field) {
- // Search nested extensions as well.
- field =
- self->message_descriptor->FindExtensionByLowercaseName(field_name);
- }
- if (field) {
- return PyInt_FromLong(field->number());
- }
- }
- PyErr_SetObject(PyExc_AttributeError, name);
- return NULL;
-}
-
-static PyObject* GetAttr(CMessageClass* self, PyObject* name) {
- PyObject* result = CMessageClass_Type->tp_base->tp_getattro(
- reinterpret_cast<PyObject*>(self), name);
- if (result != NULL) {
- return result;
- }
- if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
- return NULL;
- }
-
- PyErr_Clear();
- return GetClassAttribute(self, name);
-}
-
+// Compute some class attributes on the fly:
+// - All the _FIELD_NUMBER attributes, for all fields and nested extensions.
+// Returns a new reference, or NULL with an exception set.
+static PyObject* GetClassAttribute(CMessageClass *self, PyObject* name) {
+ char* attr;
+ Py_ssize_t attr_size;
+ static const char kSuffix[] = "_FIELD_NUMBER";
+ if (PyString_AsStringAndSize(name, &attr, &attr_size) >= 0 &&
+ HasSuffixString(StringPiece(attr, attr_size), kSuffix)) {
+ TProtoStringType field_name(attr, attr_size - sizeof(kSuffix) + 1);
+ LowerString(&field_name);
+
+ // Try to find a field with the given name, without the suffix.
+ const FieldDescriptor* field =
+ self->message_descriptor->FindFieldByLowercaseName(field_name);
+ if (!field) {
+ // Search nested extensions as well.
+ field =
+ self->message_descriptor->FindExtensionByLowercaseName(field_name);
+ }
+ if (field) {
+ return PyInt_FromLong(field->number());
+ }
+ }
+ PyErr_SetObject(PyExc_AttributeError, name);
+ return NULL;
+}
+
+static PyObject* GetAttr(CMessageClass* self, PyObject* name) {
+ PyObject* result = CMessageClass_Type->tp_base->tp_getattro(
+ reinterpret_cast<PyObject*>(self), name);
+ if (result != NULL) {
+ return result;
+ }
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ return NULL;
+ }
+
+ PyErr_Clear();
+ return GetClassAttribute(self, name);
+}
+
} // namespace message_meta
-static PyTypeObject _CMessageClass_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".MessageMeta", // tp_name
- sizeof(CMessageClass), // tp_basicsize
- 0, // tp_itemsize
- message_meta::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- (getattrofunc)message_meta::GetAttr, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, // tp_flags
- "The metaclass of ProtocolMessages", // tp_doc
- message_meta::GcTraverse, // tp_traverse
- message_meta::GcClear, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- message_meta::Getters, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
- 0, // tp_alloc
- message_meta::New, // tp_new
+static PyTypeObject _CMessageClass_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".MessageMeta", // tp_name
+ sizeof(CMessageClass), // tp_basicsize
+ 0, // tp_itemsize
+ message_meta::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ (getattrofunc)message_meta::GetAttr, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, // tp_flags
+ "The metaclass of ProtocolMessages", // tp_doc
+ message_meta::GcTraverse, // tp_traverse
+ message_meta::GcClear, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ message_meta::Getters, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ message_meta::New, // tp_new
};
-PyTypeObject* CMessageClass_Type = &_CMessageClass_Type;
+PyTypeObject* CMessageClass_Type = &_CMessageClass_Type;
static CMessageClass* CheckMessageClass(PyTypeObject* cls) {
- if (!PyObject_TypeCheck(cls, CMessageClass_Type)) {
+ if (!PyObject_TypeCheck(cls, CMessageClass_Type)) {
PyErr_Format(PyExc_TypeError, "Class %s is not a Message", cls->tp_name);
return NULL;
}
@@ -540,7 +540,7 @@ static const Descriptor* GetMessageDescriptor(PyTypeObject* cls) {
namespace cmessage {
int InternalReleaseFieldByDescriptor(
CMessage* self,
- const FieldDescriptor* field_descriptor);
+ const FieldDescriptor* field_descriptor);
} // namespace cmessage
// ---------------------------------------------------------------------
@@ -549,12 +549,12 @@ PyObject* EncodeError_class;
PyObject* DecodeError_class;
PyObject* PickleError_class;
-// Format an error message for unexpected types.
-// Always return with an exception set.
+// Format an error message for unexpected types.
+// Always return with an exception set.
void FormatTypeError(PyObject* arg, const char* expected_types) {
- // This function is often called with an exception set.
- // Clear it to call PyObject_Repr() in good conditions.
- PyErr_Clear();
+ // This function is often called with an exception set.
+ // Clear it to call PyObject_Repr() in good conditions.
+ PyErr_Clear();
PyObject* repr = PyObject_Repr(arg);
if (repr) {
PyErr_Format(PyExc_TypeError,
@@ -578,7 +578,7 @@ void OutOfRangeError(PyObject* arg) {
template<class RangeType, class ValueType>
bool VerifyIntegerCastAndRange(PyObject* arg, ValueType value) {
- if (PROTOBUF_PREDICT_FALSE(value == -1 && PyErr_Occurred())) {
+ if (PROTOBUF_PREDICT_FALSE(value == -1 && PyErr_Occurred())) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
// Replace it with the same ValueError as pure python protos instead of
// the default one.
@@ -587,21 +587,21 @@ bool VerifyIntegerCastAndRange(PyObject* arg, ValueType value) {
} // Otherwise propagate existing error.
return false;
}
- if (PROTOBUF_PREDICT_FALSE(!IsValidNumericCast<RangeType>(value))) {
+ if (PROTOBUF_PREDICT_FALSE(!IsValidNumericCast<RangeType>(value))) {
OutOfRangeError(arg);
return false;
}
return true;
}
-template <class T>
+template <class T>
bool CheckAndGetInteger(PyObject* arg, T* value) {
// The fast path.
#if PY_MAJOR_VERSION < 3
// For the typical case, offer a fast path.
- if (PROTOBUF_PREDICT_TRUE(PyInt_Check(arg))) {
- long int_result = PyInt_AsLong(arg);
- if (PROTOBUF_PREDICT_TRUE(IsValidNumericCast<T>(int_result))) {
+ if (PROTOBUF_PREDICT_TRUE(PyInt_Check(arg))) {
+ long int_result = PyInt_AsLong(arg);
+ if (PROTOBUF_PREDICT_TRUE(IsValidNumericCast<T>(int_result))) {
*value = static_cast<T>(int_result);
return true;
} else {
@@ -614,7 +614,7 @@ bool CheckAndGetInteger(PyObject* arg, T* value) {
// an integer and can be used as an ordinal number".
// This definition includes everything that implements numbers.Integral
// and shouldn't cast the net too wide.
- if (PROTOBUF_PREDICT_FALSE(!PyIndex_Check(arg))) {
+ if (PROTOBUF_PREDICT_FALSE(!PyIndex_Check(arg))) {
FormatTypeError(arg, "int, long");
return false;
}
@@ -631,7 +631,7 @@ bool CheckAndGetInteger(PyObject* arg, T* value) {
// Unlike PyLong_AsLongLong, PyLong_AsUnsignedLongLong is very
// picky about the exact type.
PyObject* casted = PyNumber_Long(arg);
- if (PROTOBUF_PREDICT_FALSE(casted == nullptr)) {
+ if (PROTOBUF_PREDICT_FALSE(casted == nullptr)) {
// Propagate existing error.
return false;
}
@@ -656,7 +656,7 @@ bool CheckAndGetInteger(PyObject* arg, T* value) {
// Valid subclasses of numbers.Integral should have a __long__() method
// so fall back to that.
PyObject* casted = PyNumber_Long(arg);
- if (PROTOBUF_PREDICT_FALSE(casted == nullptr)) {
+ if (PROTOBUF_PREDICT_FALSE(casted == nullptr)) {
// Propagate existing error.
return false;
}
@@ -682,7 +682,7 @@ template bool CheckAndGetInteger<uint64>(PyObject*, uint64*);
bool CheckAndGetDouble(PyObject* arg, double* value) {
*value = PyFloat_AsDouble(arg);
- if (PROTOBUF_PREDICT_FALSE(*value == -1 && PyErr_Occurred())) {
+ if (PROTOBUF_PREDICT_FALSE(*value == -1 && PyErr_Occurred())) {
FormatTypeError(arg, "int, long, float");
return false;
}
@@ -694,7 +694,7 @@ bool CheckAndGetFloat(PyObject* arg, float* value) {
if (!CheckAndGetDouble(arg, &double_value)) {
return false;
}
- *value = io::SafeDoubleToFloat(double_value);
+ *value = io::SafeDoubleToFloat(double_value);
return true;
}
@@ -792,20 +792,20 @@ bool CheckAndSetString(
return false;
}
- TProtoStringType value_string(value, value_len);
+ TProtoStringType value_string(value, value_len);
if (append) {
- reflection->AddString(message, descriptor, std::move(value_string));
+ reflection->AddString(message, descriptor, std::move(value_string));
} else if (index < 0) {
- reflection->SetString(message, descriptor, std::move(value_string));
+ reflection->SetString(message, descriptor, std::move(value_string));
} else {
- reflection->SetRepeatedString(message, descriptor, index,
- std::move(value_string));
+ reflection->SetRepeatedString(message, descriptor, index,
+ std::move(value_string));
}
return true;
}
-PyObject* ToStringObject(const FieldDescriptor* descriptor,
- const TProtoStringType& value) {
+PyObject* ToStringObject(const FieldDescriptor* descriptor,
+ const TProtoStringType& value) {
#if PY_MAJOR_VERSION >= 3
if (descriptor->type() != FieldDescriptor::TYPE_STRING) {
return PyBytes_FromStringAndSize(value.c_str(), value.length());
@@ -840,7 +840,7 @@ bool CheckFieldBelongsToMessage(const FieldDescriptor* field_descriptor,
namespace cmessage {
PyMessageFactory* GetFactoryForMessage(CMessage* message) {
- GOOGLE_DCHECK(PyObject_TypeCheck(message, CMessage_Type));
+ GOOGLE_DCHECK(PyObject_TypeCheck(message, CMessage_Type));
return reinterpret_cast<CMessageClass*>(Py_TYPE(message))->py_message_factory;
}
@@ -864,78 +864,78 @@ static int MaybeReleaseOverlappingOneofField(
// Non-message fields don't need to be released.
return 0;
}
- if (InternalReleaseFieldByDescriptor(cmessage, existing_field) < 0) {
+ if (InternalReleaseFieldByDescriptor(cmessage, existing_field) < 0) {
return -1;
}
-#endif
+#endif
return 0;
}
-// After a Merge, visit every sub-message that was read-only, and
-// eventually update their pointer if the Merge operation modified them.
-int FixupMessageAfterMerge(CMessage* self) {
- if (!self->composite_fields) {
+// After a Merge, visit every sub-message that was read-only, and
+// eventually update their pointer if the Merge operation modified them.
+int FixupMessageAfterMerge(CMessage* self) {
+ if (!self->composite_fields) {
return 0;
}
- for (const auto& item : *self->composite_fields) {
- const FieldDescriptor* descriptor = item.first;
- if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
- !descriptor->is_repeated()) {
- CMessage* cmsg = reinterpret_cast<CMessage*>(item.second);
- if (cmsg->read_only == false) {
- return 0;
- }
- Message* message = self->message;
- const Reflection* reflection = message->GetReflection();
- if (reflection->HasField(*message, descriptor)) {
- // Message used to be read_only, but is no longer. Get the new pointer
- // and record it.
- Message* mutable_message =
- reflection->MutableMessage(message, descriptor, nullptr);
- cmsg->message = mutable_message;
- cmsg->read_only = false;
- if (FixupMessageAfterMerge(cmsg) < 0) {
- return -1;
- }
- }
- }
- }
-
- return 0;
-}
-
-// ---------------------------------------------------------------------
-// Making a message writable
+ for (const auto& item : *self->composite_fields) {
+ const FieldDescriptor* descriptor = item.first;
+ if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
+ !descriptor->is_repeated()) {
+ CMessage* cmsg = reinterpret_cast<CMessage*>(item.second);
+ if (cmsg->read_only == false) {
+ return 0;
+ }
+ Message* message = self->message;
+ const Reflection* reflection = message->GetReflection();
+ if (reflection->HasField(*message, descriptor)) {
+ // Message used to be read_only, but is no longer. Get the new pointer
+ // and record it.
+ Message* mutable_message =
+ reflection->MutableMessage(message, descriptor, nullptr);
+ cmsg->message = mutable_message;
+ cmsg->read_only = false;
+ if (FixupMessageAfterMerge(cmsg) < 0) {
+ return -1;
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+// ---------------------------------------------------------------------
+// Making a message writable
int AssureWritable(CMessage* self) {
if (self == NULL || !self->read_only) {
return 0;
}
- // Toplevel messages are always mutable.
- GOOGLE_DCHECK(self->parent);
+ // Toplevel messages are always mutable.
+ GOOGLE_DCHECK(self->parent);
- if (AssureWritable(self->parent) == -1) {
- return -1;
- }
- // If this message is part of a oneof, there might be a field to release in
- // the parent.
- if (MaybeReleaseOverlappingOneofField(self->parent,
- self->parent_field_descriptor) < 0) {
- return -1;
+ if (AssureWritable(self->parent) == -1) {
+ return -1;
}
+ // If this message is part of a oneof, there might be a field to release in
+ // the parent.
+ if (MaybeReleaseOverlappingOneofField(self->parent,
+ self->parent_field_descriptor) < 0) {
+ return -1;
+ }
- // Make self->message writable.
- Message* parent_message = self->parent->message;
- const Reflection* reflection = parent_message->GetReflection();
- Message* mutable_message = reflection->MutableMessage(
- parent_message, self->parent_field_descriptor,
- GetFactoryForMessage(self->parent)->message_factory);
- if (mutable_message == NULL) {
+ // Make self->message writable.
+ Message* parent_message = self->parent->message;
+ const Reflection* reflection = parent_message->GetReflection();
+ Message* mutable_message = reflection->MutableMessage(
+ parent_message, self->parent_field_descriptor,
+ GetFactoryForMessage(self->parent)->message_factory);
+ if (mutable_message == NULL) {
return -1;
- }
- self->message = mutable_message;
- self->read_only = false;
+ }
+ self->message = mutable_message;
+ self->read_only = false;
return 0;
}
@@ -971,9 +971,9 @@ static PyObject* GetIntegerEnumValue(const FieldDescriptor& descriptor,
return NULL;
}
const EnumValueDescriptor* enum_value_descriptor =
- enum_descriptor->FindValueByName(StringParam(enum_label, size));
+ enum_descriptor->FindValueByName(StringParam(enum_label, size));
if (enum_value_descriptor == NULL) {
- PyErr_Format(PyExc_ValueError, "unknown enum label \"%s\"", enum_label);
+ PyErr_Format(PyExc_ValueError, "unknown enum label \"%s\"", enum_label);
return NULL;
}
return PyInt_FromLong(enum_value_descriptor->number());
@@ -982,15 +982,15 @@ static PyObject* GetIntegerEnumValue(const FieldDescriptor& descriptor,
return value;
}
-// Delete a slice from a repeated field.
-// The only way to remove items in C++ protos is to delete the last one,
-// so we swap items to move the deleted ones at the end, and then strip the
-// sequence.
-int DeleteRepeatedField(
+// Delete a slice from a repeated field.
+// The only way to remove items in C++ protos is to delete the last one,
+// so we swap items to move the deleted ones at the end, and then strip the
+// sequence.
+int DeleteRepeatedField(
CMessage* self,
const FieldDescriptor* field_descriptor,
- PyObject* slice) {
- Py_ssize_t length, from, to, step, slice_length;
+ PyObject* slice) {
+ Py_ssize_t length, from, to, step, slice_length;
Message* message = self->message;
const Reflection* reflection = message->GetReflection();
int min, max;
@@ -1041,7 +1041,7 @@ int DeleteRepeatedField(
i += step;
}
- // Swap elements so that items to delete are at the end.
+ // Swap elements so that items to delete are at the end.
to = 0;
for (i = 0; i < length; ++i) {
if (!to_delete[i]) {
@@ -1052,22 +1052,22 @@ int DeleteRepeatedField(
}
}
- // Remove items, starting from the end.
- for (; length > to; length--) {
- if (field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
+ // Remove items, starting from the end.
+ for (; length > to; length--) {
+ if (field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
reflection->RemoveLast(message, field_descriptor);
- continue;
- }
- // It seems that RemoveLast() is less efficient for sub-messages, and
- // the memory is not completely released. Prefer ReleaseLast().
- Message* sub_message = reflection->ReleaseLast(message, field_descriptor);
- // If there is a live weak reference to an item being removed, we "Release"
- // it, and it takes ownership of the message.
- if (CMessage* released = self->MaybeReleaseSubMessage(sub_message)) {
- released->message = sub_message;
+ continue;
+ }
+ // It seems that RemoveLast() is less efficient for sub-messages, and
+ // the memory is not completely released. Prefer ReleaseLast().
+ Message* sub_message = reflection->ReleaseLast(message, field_descriptor);
+ // If there is a live weak reference to an item being removed, we "Release"
+ // it, and it takes ownership of the message.
+ if (CMessage* released = self->MaybeReleaseSubMessage(sub_message)) {
+ released->message = sub_message;
} else {
- // sub_message was not transferred, delete it.
- delete sub_message;
+ // sub_message was not transferred, delete it.
+ delete sub_message;
}
}
@@ -1089,45 +1089,45 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
PyObject* name;
PyObject* value;
while (PyDict_Next(kwargs, &pos, &name, &value)) {
- if (!(PyString_Check(name) || PyUnicode_Check(name))) {
+ if (!(PyString_Check(name) || PyUnicode_Check(name))) {
PyErr_SetString(PyExc_ValueError, "Field name must be a string");
return -1;
}
- ScopedPyObjectPtr property(
- PyObject_GetAttr(reinterpret_cast<PyObject*>(Py_TYPE(self)), name));
- if (property == NULL ||
- !PyObject_TypeCheck(property.get(), CFieldProperty_Type)) {
+ ScopedPyObjectPtr property(
+ PyObject_GetAttr(reinterpret_cast<PyObject*>(Py_TYPE(self)), name));
+ if (property == NULL ||
+ !PyObject_TypeCheck(property.get(), CFieldProperty_Type)) {
PyErr_Format(PyExc_ValueError, "Protocol message %s has no \"%s\" field.",
self->message->GetDescriptor()->name().c_str(),
PyString_AsString(name));
return -1;
}
- const FieldDescriptor* descriptor =
- reinterpret_cast<PyMessageFieldProperty*>(property.get())
- ->field_descriptor;
+ const FieldDescriptor* descriptor =
+ reinterpret_cast<PyMessageFieldProperty*>(property.get())
+ ->field_descriptor;
if (value == Py_None) {
// field=None is the same as no field at all.
continue;
}
if (descriptor->is_map()) {
- ScopedPyObjectPtr map(GetFieldValue(self, descriptor));
+ ScopedPyObjectPtr map(GetFieldValue(self, descriptor));
const FieldDescriptor* value_descriptor =
descriptor->message_type()->FindFieldByName("value");
if (value_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- ScopedPyObjectPtr iter(PyObject_GetIter(value));
- if (iter == NULL) {
- PyErr_Format(PyExc_TypeError, "Argument %s is not iterable", PyString_AsString(name));
- return -1;
- }
- ScopedPyObjectPtr next;
- while ((next.reset(PyIter_Next(iter.get()))) != NULL) {
- ScopedPyObjectPtr source_value(PyObject_GetItem(value, next.get()));
- ScopedPyObjectPtr dest_value(PyObject_GetItem(map.get(), next.get()));
- if (source_value.get() == NULL || dest_value.get() == NULL) {
+ ScopedPyObjectPtr iter(PyObject_GetIter(value));
+ if (iter == NULL) {
+ PyErr_Format(PyExc_TypeError, "Argument %s is not iterable", PyString_AsString(name));
+ return -1;
+ }
+ ScopedPyObjectPtr next;
+ while ((next.reset(PyIter_Next(iter.get()))) != NULL) {
+ ScopedPyObjectPtr source_value(PyObject_GetItem(value, next.get()));
+ ScopedPyObjectPtr dest_value(PyObject_GetItem(map.get(), next.get()));
+ if (source_value.get() == NULL || dest_value.get() == NULL) {
return -1;
}
ScopedPyObjectPtr ok(PyObject_CallMethod(
- dest_value.get(), "MergeFrom", "O", source_value.get()));
+ dest_value.get(), "MergeFrom", "O", source_value.get()));
if (ok.get() == NULL) {
return -1;
}
@@ -1141,7 +1141,7 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
}
}
} else if (descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
- ScopedPyObjectPtr container(GetFieldValue(self, descriptor));
+ ScopedPyObjectPtr container(GetFieldValue(self, descriptor));
if (container == NULL) {
return -1;
}
@@ -1208,7 +1208,7 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
}
}
} else if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- ScopedPyObjectPtr message(GetFieldValue(self, descriptor));
+ ScopedPyObjectPtr message(GetFieldValue(self, descriptor));
if (message == NULL) {
return -1;
}
@@ -1232,9 +1232,9 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
if (new_val == NULL) {
return -1;
}
- value = new_val.get();
+ value = new_val.get();
}
- if (SetFieldValue(self, descriptor, value) < 0) {
+ if (SetFieldValue(self, descriptor, value) < 0) {
return -1;
}
}
@@ -1242,8 +1242,8 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
return 0;
}
-// Allocates an incomplete Python Message: the caller must fill self->message
-// and eventually self->parent.
+// Allocates an incomplete Python Message: the caller must fill self->message
+// and eventually self->parent.
CMessage* NewEmptyMessage(CMessageClass* type) {
CMessage* self = reinterpret_cast<CMessage*>(
PyType_GenericAlloc(&type->super.ht_type, 0));
@@ -1257,52 +1257,52 @@ CMessage* NewEmptyMessage(CMessageClass* type) {
self->read_only = false;
self->composite_fields = NULL;
- self->child_submessages = NULL;
-
- self->unknown_field_set = NULL;
+ self->child_submessages = NULL;
+ self->unknown_field_set = NULL;
+
return self;
}
// The __new__ method of Message classes.
// Creates a new C++ message and takes ownership.
-static CMessage* NewCMessage(CMessageClass* type) {
+static CMessage* NewCMessage(CMessageClass* type) {
// Retrieve the message descriptor and the default instance (=prototype).
const Descriptor* message_descriptor = type->message_descriptor;
- if (message_descriptor == nullptr) {
- // This would be very unexpected since the CMessageClass has already
- // been checked.
- PyErr_Format(PyExc_TypeError,
- "CMessageClass object '%s' has no descriptor.",
- Py_TYPE(type)->tp_name);
- return nullptr;
- }
- const Message* prototype =
- type->py_message_factory->message_factory->GetPrototype(
- message_descriptor);
- if (prototype == nullptr) {
+ if (message_descriptor == nullptr) {
+ // This would be very unexpected since the CMessageClass has already
+ // been checked.
+ PyErr_Format(PyExc_TypeError,
+ "CMessageClass object '%s' has no descriptor.",
+ Py_TYPE(type)->tp_name);
+ return nullptr;
+ }
+ const Message* prototype =
+ type->py_message_factory->message_factory->GetPrototype(
+ message_descriptor);
+ if (prototype == nullptr) {
PyErr_SetString(PyExc_TypeError, message_descriptor->full_name().c_str());
- return nullptr;
+ return nullptr;
}
CMessage* self = NewEmptyMessage(type);
- if (self == nullptr) {
- return nullptr;
- }
- self->message = prototype->New(nullptr); // Ensures no arena is used.
- self->parent = nullptr; // This message owns its data.
- return self;
-}
-
-static PyObject* New(PyTypeObject* cls, PyObject* unused_args,
- PyObject* unused_kwargs) {
- CMessageClass* type = CheckMessageClass(cls);
- if (type == nullptr) {
- return nullptr;
- }
- return reinterpret_cast<PyObject*>(NewCMessage(type));
-}
-
+ if (self == nullptr) {
+ return nullptr;
+ }
+ self->message = prototype->New(nullptr); // Ensures no arena is used.
+ self->parent = nullptr; // This message owns its data.
+ return self;
+}
+
+static PyObject* New(PyTypeObject* cls, PyObject* unused_args,
+ PyObject* unused_kwargs) {
+ CMessageClass* type = CheckMessageClass(cls);
+ if (type == nullptr) {
+ return nullptr;
+ }
+ return reinterpret_cast<PyObject*>(NewCMessage(type));
+}
+
// The __init__ method of Message classes.
// It initializes fields from keywords passed to the constructor.
static int Init(CMessage* self, PyObject* args, PyObject* kwargs) {
@@ -1316,34 +1316,34 @@ static void Dealloc(CMessage* self) {
if (self->weakreflist) {
PyObject_ClearWeakRefs(reinterpret_cast<PyObject*>(self));
}
- // At this point all dependent objects have been removed.
- GOOGLE_DCHECK(!self->child_submessages || self->child_submessages->empty());
- GOOGLE_DCHECK(!self->composite_fields || self->composite_fields->empty());
- delete self->child_submessages;
- delete self->composite_fields;
- if (self->unknown_field_set) {
- unknown_fields::Clear(
- reinterpret_cast<PyUnknownFields*>(self->unknown_field_set));
- }
-
- CMessage* parent = self->parent;
- if (!parent) {
- // No parent, we own the message.
- delete self->message;
- } else if (parent->AsPyObject() == Py_None) {
- // Message owned externally: Nothing to dealloc
- Py_CLEAR(self->parent);
- } else {
- // Clear this message from its parent's map.
- if (self->parent_field_descriptor->is_repeated()) {
- if (parent->child_submessages)
- parent->child_submessages->erase(self->message);
- } else {
- if (parent->composite_fields)
- parent->composite_fields->erase(self->parent_field_descriptor);
- }
- Py_CLEAR(self->parent);
- }
+ // At this point all dependent objects have been removed.
+ GOOGLE_DCHECK(!self->child_submessages || self->child_submessages->empty());
+ GOOGLE_DCHECK(!self->composite_fields || self->composite_fields->empty());
+ delete self->child_submessages;
+ delete self->composite_fields;
+ if (self->unknown_field_set) {
+ unknown_fields::Clear(
+ reinterpret_cast<PyUnknownFields*>(self->unknown_field_set));
+ }
+
+ CMessage* parent = self->parent;
+ if (!parent) {
+ // No parent, we own the message.
+ delete self->message;
+ } else if (parent->AsPyObject() == Py_None) {
+ // Message owned externally: Nothing to dealloc
+ Py_CLEAR(self->parent);
+ } else {
+ // Clear this message from its parent's map.
+ if (self->parent_field_descriptor->is_repeated()) {
+ if (parent->child_submessages)
+ parent->child_submessages->erase(self->message);
+ } else {
+ if (parent->composite_fields)
+ parent->composite_fields->erase(self->parent_field_descriptor);
+ }
+ Py_CLEAR(self->parent);
+ }
Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self));
}
@@ -1352,7 +1352,7 @@ static void Dealloc(CMessage* self) {
PyObject* IsInitialized(CMessage* self, PyObject* args) {
PyObject* errors = NULL;
- if (!PyArg_ParseTuple(args, "|O", &errors)) {
+ if (!PyArg_ParseTuple(args, "|O", &errors)) {
return NULL;
}
if (self->message->IsInitialized()) {
@@ -1380,23 +1380,23 @@ PyObject* IsInitialized(CMessage* self, PyObject* args) {
Py_RETURN_FALSE;
}
-int HasFieldByDescriptor(CMessage* self,
- const FieldDescriptor* field_descriptor) {
+int HasFieldByDescriptor(CMessage* self,
+ const FieldDescriptor* field_descriptor) {
Message* message = self->message;
if (!CheckFieldBelongsToMessage(field_descriptor, message)) {
- return -1;
+ return -1;
}
if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
PyErr_SetString(PyExc_KeyError,
"Field is repeated. A singular method is required.");
- return -1;
+ return -1;
}
- return message->GetReflection()->HasField(*message, field_descriptor);
+ return message->GetReflection()->HasField(*message, field_descriptor);
}
-const FieldDescriptor* FindFieldWithOneofs(const Message* message,
- ConstStringParam field_name,
- bool* in_oneof) {
+const FieldDescriptor* FindFieldWithOneofs(const Message* message,
+ ConstStringParam field_name,
+ bool* in_oneof) {
*in_oneof = false;
const Descriptor* descriptor = message->GetDescriptor();
const FieldDescriptor* field_descriptor =
@@ -1415,20 +1415,20 @@ const FieldDescriptor* FindFieldWithOneofs(const Message* message,
}
bool CheckHasPresence(const FieldDescriptor* field_descriptor, bool in_oneof) {
- auto message_name = field_descriptor->containing_type()->name();
+ auto message_name = field_descriptor->containing_type()->name();
if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
PyErr_Format(PyExc_ValueError,
- "Protocol message %s has no singular \"%s\" field.",
- message_name.c_str(), field_descriptor->name().c_str());
+ "Protocol message %s has no singular \"%s\" field.",
+ message_name.c_str(), field_descriptor->name().c_str());
return false;
}
- if (!field_descriptor->has_presence()) {
- PyErr_Format(PyExc_ValueError,
- "Can't test non-optional, non-submessage field \"%s.%s\" for "
- "presence in proto3.",
- message_name.c_str(), field_descriptor->name().c_str());
- return false;
+ if (!field_descriptor->has_presence()) {
+ PyErr_Format(PyExc_ValueError,
+ "Can't test non-optional, non-submessage field \"%s.%s\" for "
+ "presence in proto3.",
+ message_name.c_str(), field_descriptor->name().c_str());
+ return false;
}
return true;
@@ -1451,11 +1451,11 @@ PyObject* HasField(CMessage* self, PyObject* arg) {
Message* message = self->message;
bool is_in_oneof;
const FieldDescriptor* field_descriptor =
- FindFieldWithOneofs(message, StringParam(field_name, size), &is_in_oneof);
+ FindFieldWithOneofs(message, StringParam(field_name, size), &is_in_oneof);
if (field_descriptor == NULL) {
if (!is_in_oneof) {
- PyErr_Format(PyExc_ValueError, "Protocol message %s has no field %s.",
- message->GetDescriptor()->name().c_str(), field_name);
+ PyErr_Format(PyExc_ValueError, "Protocol message %s has no field %s.",
+ message->GetDescriptor()->name().c_str(), field_name);
return NULL;
} else {
Py_RETURN_FALSE;
@@ -1469,7 +1469,7 @@ PyObject* HasField(CMessage* self, PyObject* arg) {
if (message->GetReflection()->HasField(*message, field_descriptor)) {
Py_RETURN_TRUE;
}
-
+
Py_RETURN_FALSE;
}
@@ -1478,10 +1478,10 @@ PyObject* ClearExtension(CMessage* self, PyObject* extension) {
if (descriptor == NULL) {
return NULL;
}
- if (ClearFieldByDescriptor(self, descriptor) < 0) {
- return nullptr;
+ if (ClearFieldByDescriptor(self, descriptor) < 0) {
+ return nullptr;
}
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
PyObject* HasExtension(CMessage* self, PyObject* extension) {
@@ -1489,12 +1489,12 @@ PyObject* HasExtension(CMessage* self, PyObject* extension) {
if (descriptor == NULL) {
return NULL;
}
- int has_field = HasFieldByDescriptor(self, descriptor);
- if (has_field < 0) {
- return nullptr;
- } else {
- return PyBool_FromLong(has_field);
- }
+ int has_field = HasFieldByDescriptor(self, descriptor);
+ if (has_field < 0) {
+ return nullptr;
+ } else {
+ return PyBool_FromLong(has_field);
+ }
}
// ---------------------------------------------------------------------
@@ -1502,188 +1502,188 @@ PyObject* HasExtension(CMessage* self, PyObject* extension) {
//
// The Python API's ClearField() and Clear() methods behave
// differently than their C++ counterparts. While the C++ versions
-// clears the children, the Python versions detaches the children,
+// clears the children, the Python versions detaches the children,
// without touching their content. This impedance mismatch causes
// some complexity in the implementation, which is captured in this
// section.
//
-// When one or multiple fields are cleared we need to:
+// When one or multiple fields are cleared we need to:
//
-// * Gather all child objects that need to be detached from the message.
-// In composite_fields and child_submessages.
+// * Gather all child objects that need to be detached from the message.
+// In composite_fields and child_submessages.
//
-// * Create a new Python message of the same kind. Use SwapFields() to move
-// data from the original message.
+// * Create a new Python message of the same kind. Use SwapFields() to move
+// data from the original message.
//
-// * Change the parent of all child objects: update their strong reference
-// to their parent, and move their presence in composite_fields and
-// child_submessages.
+// * Change the parent of all child objects: update their strong reference
+// to their parent, and move their presence in composite_fields and
+// child_submessages.
-// ---------------------------------------------------------------------
-// Release a composite child of a CMessage
+// ---------------------------------------------------------------------
+// Release a composite child of a CMessage
-static int InternalReparentFields(
- CMessage* self, const std::vector<CMessage*>& messages_to_release,
- const std::vector<ContainerBase*>& containers_to_release) {
- if (messages_to_release.empty() && containers_to_release.empty()) {
+static int InternalReparentFields(
+ CMessage* self, const std::vector<CMessage*>& messages_to_release,
+ const std::vector<ContainerBase*>& containers_to_release) {
+ if (messages_to_release.empty() && containers_to_release.empty()) {
return 0;
}
- // Move all the passed sub_messages to another message.
- CMessage* new_message = cmessage::NewEmptyMessage(self->GetMessageClass());
- if (new_message == nullptr) {
- return -1;
- }
- new_message->message = self->message->New(nullptr);
- ScopedPyObjectPtr holder(reinterpret_cast<PyObject*>(new_message));
- new_message->child_submessages = new CMessage::SubMessagesMap();
- new_message->composite_fields = new CMessage::CompositeFieldsMap();
- std::set<const FieldDescriptor*> fields_to_swap;
-
- // In case this the removed fields are the last reference to a message, keep
- // a reference.
- Py_INCREF(self);
-
- for (const auto& to_release : messages_to_release) {
- fields_to_swap.insert(to_release->parent_field_descriptor);
- // Reparent
- Py_INCREF(new_message);
- Py_DECREF(to_release->parent);
- to_release->parent = new_message;
- self->child_submessages->erase(to_release->message);
- new_message->child_submessages->emplace(to_release->message, to_release);
- }
-
- for (const auto& to_release : containers_to_release) {
- fields_to_swap.insert(to_release->parent_field_descriptor);
- Py_INCREF(new_message);
- Py_DECREF(to_release->parent);
- to_release->parent = new_message;
- self->composite_fields->erase(to_release->parent_field_descriptor);
- new_message->composite_fields->emplace(to_release->parent_field_descriptor,
- to_release);
- }
-
- if (self->message->GetArena() == new_message->message->GetArena()) {
- MessageReflectionFriend::UnsafeShallowSwapFields(
- self->message, new_message->message,
- std::vector<const FieldDescriptor*>(fields_to_swap.begin(),
- fields_to_swap.end()));
- } else {
- self->message->GetReflection()->SwapFields(
- self->message, new_message->message,
- std::vector<const FieldDescriptor*>(fields_to_swap.begin(),
- fields_to_swap.end()));
- }
-
- // This might delete the Python message completely if all children were moved.
- Py_DECREF(self);
-
+ // Move all the passed sub_messages to another message.
+ CMessage* new_message = cmessage::NewEmptyMessage(self->GetMessageClass());
+ if (new_message == nullptr) {
+ return -1;
+ }
+ new_message->message = self->message->New(nullptr);
+ ScopedPyObjectPtr holder(reinterpret_cast<PyObject*>(new_message));
+ new_message->child_submessages = new CMessage::SubMessagesMap();
+ new_message->composite_fields = new CMessage::CompositeFieldsMap();
+ std::set<const FieldDescriptor*> fields_to_swap;
+
+ // In case this the removed fields are the last reference to a message, keep
+ // a reference.
+ Py_INCREF(self);
+
+ for (const auto& to_release : messages_to_release) {
+ fields_to_swap.insert(to_release->parent_field_descriptor);
+ // Reparent
+ Py_INCREF(new_message);
+ Py_DECREF(to_release->parent);
+ to_release->parent = new_message;
+ self->child_submessages->erase(to_release->message);
+ new_message->child_submessages->emplace(to_release->message, to_release);
+ }
+
+ for (const auto& to_release : containers_to_release) {
+ fields_to_swap.insert(to_release->parent_field_descriptor);
+ Py_INCREF(new_message);
+ Py_DECREF(to_release->parent);
+ to_release->parent = new_message;
+ self->composite_fields->erase(to_release->parent_field_descriptor);
+ new_message->composite_fields->emplace(to_release->parent_field_descriptor,
+ to_release);
+ }
+
+ if (self->message->GetArena() == new_message->message->GetArena()) {
+ MessageReflectionFriend::UnsafeShallowSwapFields(
+ self->message, new_message->message,
+ std::vector<const FieldDescriptor*>(fields_to_swap.begin(),
+ fields_to_swap.end()));
+ } else {
+ self->message->GetReflection()->SwapFields(
+ self->message, new_message->message,
+ std::vector<const FieldDescriptor*>(fields_to_swap.begin(),
+ fields_to_swap.end()));
+ }
+
+ // This might delete the Python message completely if all children were moved.
+ Py_DECREF(self);
+
return 0;
}
-int InternalReleaseFieldByDescriptor(
- CMessage* self,
- const FieldDescriptor* field_descriptor) {
- if (!field_descriptor->is_repeated() &&
- field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
- // Single scalars are not in any cache.
- return 0;
+int InternalReleaseFieldByDescriptor(
+ CMessage* self,
+ const FieldDescriptor* field_descriptor) {
+ if (!field_descriptor->is_repeated() &&
+ field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
+ // Single scalars are not in any cache.
+ return 0;
}
- std::vector<CMessage*> messages_to_release;
- std::vector<ContainerBase*> containers_to_release;
- if (self->child_submessages && field_descriptor->is_repeated() &&
- field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- for (const auto& child_item : *self->child_submessages) {
- if (child_item.second->parent_field_descriptor == field_descriptor) {
- messages_to_release.push_back(child_item.second);
- }
- }
+ std::vector<CMessage*> messages_to_release;
+ std::vector<ContainerBase*> containers_to_release;
+ if (self->child_submessages && field_descriptor->is_repeated() &&
+ field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ for (const auto& child_item : *self->child_submessages) {
+ if (child_item.second->parent_field_descriptor == field_descriptor) {
+ messages_to_release.push_back(child_item.second);
+ }
+ }
}
- if (self->composite_fields) {
- CMessage::CompositeFieldsMap::iterator it =
- self->composite_fields->find(field_descriptor);
- if (it != self->composite_fields->end()) {
- containers_to_release.push_back(it->second);
- }
+ if (self->composite_fields) {
+ CMessage::CompositeFieldsMap::iterator it =
+ self->composite_fields->find(field_descriptor);
+ if (it != self->composite_fields->end()) {
+ containers_to_release.push_back(it->second);
+ }
}
- return InternalReparentFields(self, messages_to_release,
- containers_to_release);
+ return InternalReparentFields(self, messages_to_release,
+ containers_to_release);
}
-int ClearFieldByDescriptor(CMessage* self,
- const FieldDescriptor* field_descriptor) {
+int ClearFieldByDescriptor(CMessage* self,
+ const FieldDescriptor* field_descriptor) {
if (!CheckFieldBelongsToMessage(field_descriptor, self->message)) {
- return -1;
- }
- if (InternalReleaseFieldByDescriptor(self, field_descriptor) < 0) {
- return -1;
+ return -1;
}
+ if (InternalReleaseFieldByDescriptor(self, field_descriptor) < 0) {
+ return -1;
+ }
AssureWritable(self);
Message* message = self->message;
message->GetReflection()->ClearField(message, field_descriptor);
- return 0;
+ return 0;
}
PyObject* ClearField(CMessage* self, PyObject* arg) {
- char* field_name;
- Py_ssize_t field_size;
- if (PyString_AsStringAndSize(arg, &field_name, &field_size) < 0) {
+ char* field_name;
+ Py_ssize_t field_size;
+ if (PyString_AsStringAndSize(arg, &field_name, &field_size) < 0) {
return NULL;
}
AssureWritable(self);
bool is_in_oneof;
- const FieldDescriptor* field_descriptor = FindFieldWithOneofs(
- self->message, StringParam(field_name, field_size), &is_in_oneof);
+ const FieldDescriptor* field_descriptor = FindFieldWithOneofs(
+ self->message, StringParam(field_name, field_size), &is_in_oneof);
if (field_descriptor == NULL) {
- if (is_in_oneof) {
- // We gave the name of a oneof, and none of its fields are set.
- Py_RETURN_NONE;
- } else {
+ if (is_in_oneof) {
+ // We gave the name of a oneof, and none of its fields are set.
+ Py_RETURN_NONE;
+ } else {
PyErr_Format(PyExc_ValueError,
"Protocol message has no \"%s\" field.", field_name);
return NULL;
}
}
- if (ClearFieldByDescriptor(self, field_descriptor) < 0) {
- return nullptr;
+ if (ClearFieldByDescriptor(self, field_descriptor) < 0) {
+ return nullptr;
}
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
PyObject* Clear(CMessage* self) {
AssureWritable(self);
- // Detach all current fields of this message
- std::vector<CMessage*> messages_to_release;
- std::vector<ContainerBase*> containers_to_release;
- if (self->child_submessages) {
- for (const auto& item : *self->child_submessages) {
- messages_to_release.push_back(item.second);
- }
- }
+ // Detach all current fields of this message
+ std::vector<CMessage*> messages_to_release;
+ std::vector<ContainerBase*> containers_to_release;
+ if (self->child_submessages) {
+ for (const auto& item : *self->child_submessages) {
+ messages_to_release.push_back(item.second);
+ }
+ }
if (self->composite_fields) {
- for (const auto& item : *self->composite_fields) {
- containers_to_release.push_back(item.second);
- }
- }
- if (InternalReparentFields(self, messages_to_release, containers_to_release) <
- 0) {
- return NULL;
- }
- if (self->unknown_field_set) {
- unknown_fields::Clear(
- reinterpret_cast<PyUnknownFields*>(self->unknown_field_set));
- self->unknown_field_set = nullptr;
- }
+ for (const auto& item : *self->composite_fields) {
+ containers_to_release.push_back(item.second);
+ }
+ }
+ if (InternalReparentFields(self, messages_to_release, containers_to_release) <
+ 0) {
+ return NULL;
+ }
+ if (self->unknown_field_set) {
+ unknown_fields::Clear(
+ reinterpret_cast<PyUnknownFields*>(self->unknown_field_set));
+ self->unknown_field_set = nullptr;
+ }
self->message->Clear();
Py_RETURN_NONE;
}
// ---------------------------------------------------------------------
-static TProtoStringType GetMessageName(CMessage* self) {
+static TProtoStringType GetMessageName(CMessage* self) {
if (self->parent_field_descriptor != NULL) {
return self->parent_field_descriptor->full_name();
} else {
@@ -1695,10 +1695,10 @@ static PyObject* InternalSerializeToString(
CMessage* self, PyObject* args, PyObject* kwargs,
bool require_initialized) {
// Parse the "deterministic" kwarg; defaults to False.
- static const char* kwlist[] = {"deterministic", 0};
+ static const char* kwlist[] = {"deterministic", 0};
PyObject* deterministic_obj = Py_None;
- if (!PyArg_ParseTupleAndKeywords(
- args, kwargs, "|O", const_cast<char**>(kwlist), &deterministic_obj)) {
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kwargs, "|O", const_cast<char**>(kwlist), &deterministic_obj)) {
return NULL;
}
// Preemptively convert to a bool first, so we don't need to back out of
@@ -1753,15 +1753,15 @@ static PyObject* InternalSerializeToString(
if (size == 0) {
return PyBytes_FromString("");
}
-
- if (size > INT_MAX) {
- PyErr_Format(PyExc_ValueError,
- "Message %s exceeds maximum protobuf "
- "size of 2GB: %zu",
- GetMessageName(self).c_str(), size);
- return nullptr;
- }
-
+
+ if (size > INT_MAX) {
+ PyErr_Format(PyExc_ValueError,
+ "Message %s exceeds maximum protobuf "
+ "size of 2GB: %zu",
+ GetMessageName(self).c_str(), size);
+ return nullptr;
+ }
+
PyObject* result = PyBytes_FromStringAndSize(NULL, size);
if (result == NULL) {
return NULL;
@@ -1790,7 +1790,7 @@ static PyObject* SerializePartialToString(
// Formats proto fields for ascii dumps using python formatting functions where
// appropriate.
-class PythonFieldValuePrinter : public TextFormat::FastFieldValuePrinter {
+class PythonFieldValuePrinter : public TextFormat::FastFieldValuePrinter {
public:
// Python has some differences from C++ when printing floating point numbers.
//
@@ -1802,12 +1802,12 @@ class PythonFieldValuePrinter : public TextFormat::FastFieldValuePrinter {
//
// We override floating point printing with the C-API function for printing
// Python floats to ensure consistency.
- void PrintFloat(float val,
- TextFormat::BaseTextGenerator* generator) const override {
- PrintDouble(val, generator);
- }
- void PrintDouble(double val,
- TextFormat::BaseTextGenerator* generator) const override {
+ void PrintFloat(float val,
+ TextFormat::BaseTextGenerator* generator) const override {
+ PrintDouble(val, generator);
+ }
+ void PrintDouble(double val,
+ TextFormat::BaseTextGenerator* generator) const override {
// This implementation is not highly optimized (it allocates two temporary
// Python objects) but it is simple and portable. If this is shown to be a
// performance bottleneck, we can optimize it, but the results will likely
@@ -1816,17 +1816,17 @@ class PythonFieldValuePrinter : public TextFormat::FastFieldValuePrinter {
//
// (Though a valid question is: do we really want to make out output
// dependent on the Python version?)
- ScopedPyObjectPtr py_value(PyFloat_FromDouble(val));
+ ScopedPyObjectPtr py_value(PyFloat_FromDouble(val));
if (!py_value.get()) {
- return;
+ return;
}
ScopedPyObjectPtr py_str(PyObject_Str(py_value.get()));
if (!py_str.get()) {
- return;
+ return;
}
- generator->PrintString(PyString_AsString(py_str.get()));
+ generator->PrintString(PyString_AsString(py_str.get()));
}
};
@@ -1835,7 +1835,7 @@ static PyObject* ToStr(CMessage* self) {
// Passes ownership
printer.SetDefaultFieldValuePrinter(new PythonFieldValuePrinter());
printer.SetHideUnknownFields(true);
- TProtoStringType output;
+ TProtoStringType output;
if (!printer.PrintToString(*self->message, &output)) {
PyErr_SetString(PyExc_ValueError, "Unable to convert message to str");
return NULL;
@@ -1845,7 +1845,7 @@ static PyObject* ToStr(CMessage* self) {
PyObject* MergeFrom(CMessage* self, PyObject* arg) {
CMessage* other_message;
- if (!PyObject_TypeCheck(arg, CMessage_Type)) {
+ if (!PyObject_TypeCheck(arg, CMessage_Type)) {
PyErr_Format(PyExc_TypeError,
"Parameter to MergeFrom() must be instance of same class: "
"expected %s got %s.",
@@ -1866,19 +1866,19 @@ PyObject* MergeFrom(CMessage* self, PyObject* arg) {
}
AssureWritable(self);
- self->message->MergeFrom(*other_message->message);
- // Child message might be lazily created before MergeFrom. Make sure they
- // are mutable at this point if child messages are really created.
- if (FixupMessageAfterMerge(self) < 0) {
- return NULL;
- }
+ self->message->MergeFrom(*other_message->message);
+ // Child message might be lazily created before MergeFrom. Make sure they
+ // are mutable at this point if child messages are really created.
+ if (FixupMessageAfterMerge(self) < 0) {
+ return NULL;
+ }
Py_RETURN_NONE;
}
static PyObject* CopyFrom(CMessage* self, PyObject* arg) {
CMessage* other_message;
- if (!PyObject_TypeCheck(arg, CMessage_Type)) {
+ if (!PyObject_TypeCheck(arg, CMessage_Type)) {
PyErr_Format(PyExc_TypeError,
"Parameter to CopyFrom() must be instance of same class: "
"expected %s got %s.",
@@ -1943,48 +1943,48 @@ PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg) {
}
static PyObject* MergeFromString(CMessage* self, PyObject* arg) {
- Py_buffer data;
- if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) < 0) {
+ Py_buffer data;
+ if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) < 0) {
return NULL;
}
AssureWritable(self);
-
+
PyMessageFactory* factory = GetFactoryForMessage(self);
- int depth = allow_oversize_protos
- ? INT_MAX
- : io::CodedInputStream::GetDefaultRecursionLimit();
- const char* ptr;
- internal::ParseContext ctx(
- depth, false, &ptr,
- StringPiece(static_cast<const char*>(data.buf), data.len));
- PyBuffer_Release(&data);
- ctx.data().pool = factory->pool->pool;
- ctx.data().factory = factory->message_factory;
-
- ptr = self->message->_InternalParse(ptr, &ctx);
-
- // Child message might be lazily created before MergeFrom. Make sure they
- // are mutable at this point if child messages are really created.
- if (FixupMessageAfterMerge(self) < 0) {
- return NULL;
- }
-
- // Python makes distinction in error message, between a general parse failure
- // and in-correct ending on a terminating tag. Hence we need to be a bit more
- // explicit in our correctness checks.
- if (ptr == nullptr || ctx.BytesUntilLimit(ptr) < 0) {
- // Parse error or the parser overshoot the limit.
- PyErr_Format(DecodeError_class, "Error parsing message");
- return NULL;
- }
- // ctx has an explicit limit set (length of string_view), so we have to
- // check we ended at that limit.
- if (!ctx.EndedAtLimit()) {
- PyErr_Format(DecodeError_class, "Unexpected end-group tag: Not all data was converted");
- return nullptr;
- }
- return PyInt_FromLong(data.len);
+ int depth = allow_oversize_protos
+ ? INT_MAX
+ : io::CodedInputStream::GetDefaultRecursionLimit();
+ const char* ptr;
+ internal::ParseContext ctx(
+ depth, false, &ptr,
+ StringPiece(static_cast<const char*>(data.buf), data.len));
+ PyBuffer_Release(&data);
+ ctx.data().pool = factory->pool->pool;
+ ctx.data().factory = factory->message_factory;
+
+ ptr = self->message->_InternalParse(ptr, &ctx);
+
+ // Child message might be lazily created before MergeFrom. Make sure they
+ // are mutable at this point if child messages are really created.
+ if (FixupMessageAfterMerge(self) < 0) {
+ return NULL;
+ }
+
+ // Python makes distinction in error message, between a general parse failure
+ // and in-correct ending on a terminating tag. Hence we need to be a bit more
+ // explicit in our correctness checks.
+ if (ptr == nullptr || ctx.BytesUntilLimit(ptr) < 0) {
+ // Parse error or the parser overshoot the limit.
+ PyErr_Format(DecodeError_class, "Error parsing message");
+ return NULL;
+ }
+ // ctx has an explicit limit set (length of string_view), so we have to
+ // check we ended at that limit.
+ if (!ctx.EndedAtLimit()) {
+ PyErr_Format(DecodeError_class, "Unexpected end-group tag: Not all data was converted");
+ return nullptr;
+ }
+ return PyInt_FromLong(data.len);
}
static PyObject* ParseFromString(CMessage* self, PyObject* arg) {
@@ -1995,7 +1995,7 @@ static PyObject* ParseFromString(CMessage* self, PyObject* arg) {
}
static PyObject* ByteSize(CMessage* self, PyObject* args) {
- return PyLong_FromLong(self->message->ByteSizeLong());
+ return PyLong_FromLong(self->message->ByteSizeLong());
}
PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle) {
@@ -2004,7 +2004,7 @@ PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle) {
if (descriptor == NULL) {
return NULL;
}
- if (!PyObject_TypeCheck(cls, CMessageClass_Type)) {
+ if (!PyObject_TypeCheck(cls, CMessageClass_Type)) {
PyErr_Format(PyExc_TypeError, "Expected a message class, got %s",
cls->ob_type->tp_name);
return NULL;
@@ -2035,11 +2035,11 @@ static PyObject* WhichOneof(CMessage* self, PyObject* arg) {
if (PyString_AsStringAndSize(arg, &name_data, &name_size) < 0)
return NULL;
const OneofDescriptor* oneof_desc =
- self->message->GetDescriptor()->FindOneofByName(
- StringParam(name_data, name_size));
+ self->message->GetDescriptor()->FindOneofByName(
+ StringParam(name_data, name_size));
if (oneof_desc == NULL) {
PyErr_Format(PyExc_ValueError,
- "Protocol message has no oneof \"%s\" field.", name_data);
+ "Protocol message has no oneof \"%s\" field.", name_data);
return NULL;
}
const FieldDescriptor* field_in_oneof =
@@ -2048,7 +2048,7 @@ static PyObject* WhichOneof(CMessage* self, PyObject* arg) {
if (field_in_oneof == NULL) {
Py_RETURN_NONE;
} else {
- const TProtoStringType& name = field_in_oneof->name();
+ const TProtoStringType& name = field_in_oneof->name();
return PyString_FromStringAndSize(name.c_str(), name.size());
}
}
@@ -2113,9 +2113,9 @@ static PyObject* ListFields(CMessage* self) {
return NULL;
}
- PyObject* field_value = GetFieldValue(self, fields[i]);
+ PyObject* field_value = GetFieldValue(self, fields[i]);
if (field_value == NULL) {
- PyErr_SetString(PyExc_ValueError, fields[i]->name().c_str());
+ PyErr_SetString(PyExc_ValueError, fields[i]->name().c_str());
return NULL;
}
PyTuple_SET_ITEM(t.get(), 0, field_descriptor.release());
@@ -2140,7 +2140,7 @@ static PyObject* DiscardUnknownFields(CMessage* self) {
PyObject* FindInitializationErrors(CMessage* self) {
Message* message = self->message;
- std::vector<TProtoStringType> errors;
+ std::vector<TProtoStringType> errors;
message->FindInitializationErrors(&errors);
PyObject* error_list = PyList_New(errors.size());
@@ -2148,7 +2148,7 @@ PyObject* FindInitializationErrors(CMessage* self) {
return NULL;
}
for (size_t i = 0; i < errors.size(); ++i) {
- const TProtoStringType& error = errors[i];
+ const TProtoStringType& error = errors[i];
PyObject* error_string = PyString_FromStringAndSize(
error.c_str(), error.length());
if (error_string == NULL) {
@@ -2168,25 +2168,25 @@ static PyObject* RichCompare(CMessage* self, PyObject* other, int opid) {
}
bool equals = true;
// If other is not a message, it cannot be equal.
- if (!PyObject_TypeCheck(other, CMessage_Type)) {
+ if (!PyObject_TypeCheck(other, CMessage_Type)) {
equals = false;
- } else {
- // Otherwise, we have a CMessage whose message we can inspect.
- const google::protobuf::Message* other_message =
- reinterpret_cast<CMessage*>(other)->message;
- // If messages don't have the same descriptors, they are not equal.
- if (equals &&
- self->message->GetDescriptor() != other_message->GetDescriptor()) {
- equals = false;
- }
- // Check the message contents.
- if (equals &&
- !google::protobuf::util::MessageDifferencer::Equals(
- *self->message, *reinterpret_cast<CMessage*>(other)->message)) {
- equals = false;
- }
- }
-
+ } else {
+ // Otherwise, we have a CMessage whose message we can inspect.
+ const google::protobuf::Message* other_message =
+ reinterpret_cast<CMessage*>(other)->message;
+ // If messages don't have the same descriptors, they are not equal.
+ if (equals &&
+ self->message->GetDescriptor() != other_message->GetDescriptor()) {
+ equals = false;
+ }
+ // Check the message contents.
+ if (equals &&
+ !google::protobuf::util::MessageDifferencer::Equals(
+ *self->message, *reinterpret_cast<CMessage*>(other)->message)) {
+ equals = false;
+ }
+ }
+
if (equals ^ (opid == Py_EQ)) {
Py_RETURN_FALSE;
} else {
@@ -2205,22 +2205,22 @@ PyObject* InternalGetScalar(const Message* message,
PyObject* result = NULL;
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
- int32_t value = reflection->GetInt32(*message, field_descriptor);
+ int32_t value = reflection->GetInt32(*message, field_descriptor);
result = PyInt_FromLong(value);
break;
}
case FieldDescriptor::CPPTYPE_INT64: {
- int64_t value = reflection->GetInt64(*message, field_descriptor);
+ int64_t value = reflection->GetInt64(*message, field_descriptor);
result = PyLong_FromLongLong(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT32: {
- uint32_t value = reflection->GetUInt32(*message, field_descriptor);
+ uint32_t value = reflection->GetUInt32(*message, field_descriptor);
result = PyInt_FromSize_t(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT64: {
- uint64_t value = reflection->GetUInt64(*message, field_descriptor);
+ uint64_t value = reflection->GetUInt64(*message, field_descriptor);
result = PyLong_FromUnsignedLongLong(value);
break;
}
@@ -2240,16 +2240,16 @@ PyObject* InternalGetScalar(const Message* message,
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- TProtoStringType scratch;
- const TProtoStringType& value =
- reflection->GetStringReference(*message, field_descriptor, &scratch);
+ TProtoStringType scratch;
+ const TProtoStringType& value =
+ reflection->GetStringReference(*message, field_descriptor, &scratch);
result = ToStringObject(field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_ENUM: {
- const EnumValueDescriptor* enum_value =
- message->GetReflection()->GetEnum(*message, field_descriptor);
- result = PyInt_FromLong(enum_value->number());
+ const EnumValueDescriptor* enum_value =
+ message->GetReflection()->GetEnum(*message, field_descriptor);
+ result = PyInt_FromLong(enum_value->number());
break;
}
default:
@@ -2261,7 +2261,7 @@ PyObject* InternalGetScalar(const Message* message,
return result;
}
-CMessage* InternalGetSubMessage(
+CMessage* InternalGetSubMessage(
CMessage* self, const FieldDescriptor* field_descriptor) {
const Reflection* reflection = self->message->GetReflection();
PyMessageFactory* factory = GetFactoryForMessage(self);
@@ -2270,7 +2270,7 @@ CMessage* InternalGetSubMessage(
CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
factory, field_descriptor->message_type());
- ScopedPyObjectPtr message_class_owner(
+ ScopedPyObjectPtr message_class_owner(
reinterpret_cast<PyObject*>(message_class));
if (message_class == NULL) {
return NULL;
@@ -2281,12 +2281,12 @@ CMessage* InternalGetSubMessage(
return NULL;
}
- Py_INCREF(self);
+ Py_INCREF(self);
cmsg->parent = self;
cmsg->parent_field_descriptor = field_descriptor;
cmsg->read_only = !reflection->HasField(*self->message, field_descriptor);
cmsg->message = const_cast<Message*>(&sub_message);
- return cmsg;
+ return cmsg;
}
int InternalSetNonOneofScalar(
@@ -2407,7 +2407,7 @@ PyObject* DeepCopy(CMessage* self, PyObject* arg) {
if (clone == NULL) {
return NULL;
}
- if (!PyObject_TypeCheck(clone, CMessage_Type)) {
+ if (!PyObject_TypeCheck(clone, CMessage_Type)) {
Py_DECREF(clone);
return NULL;
}
@@ -2465,27 +2465,27 @@ static PyObject* GetExtensionDict(CMessage* self, void *closure) {
// If there are extension_ranges, the message is "extendable". Allocate a
// dictionary to store the extension fields.
const Descriptor* descriptor = GetMessageDescriptor(Py_TYPE(self));
- if (!descriptor->extension_range_count()) {
- PyErr_SetNone(PyExc_AttributeError);
- return NULL;
- }
- if (!self->composite_fields) {
- self->composite_fields = new CMessage::CompositeFieldsMap();
- }
- if (!self->composite_fields) {
- return NULL;
- }
- ExtensionDict* extension_dict = extension_dict::NewExtensionDict(self);
- return reinterpret_cast<PyObject*>(extension_dict);
-}
-
-static PyObject* UnknownFieldSet(CMessage* self) {
- if (self->unknown_field_set == NULL) {
- self->unknown_field_set = unknown_fields::NewPyUnknownFields(self);
- } else {
- Py_INCREF(self->unknown_field_set);
- }
- return self->unknown_field_set;
+ if (!descriptor->extension_range_count()) {
+ PyErr_SetNone(PyExc_AttributeError);
+ return NULL;
+ }
+ if (!self->composite_fields) {
+ self->composite_fields = new CMessage::CompositeFieldsMap();
+ }
+ if (!self->composite_fields) {
+ return NULL;
+ }
+ ExtensionDict* extension_dict = extension_dict::NewExtensionDict(self);
+ return reinterpret_cast<PyObject*>(extension_dict);
+}
+
+static PyObject* UnknownFieldSet(CMessage* self) {
+ if (self->unknown_field_set == NULL) {
+ self->unknown_field_set = unknown_fields::NewPyUnknownFields(self);
+ } else {
+ Py_INCREF(self->unknown_field_set);
+ }
+ return self->unknown_field_set;
}
static PyObject* GetExtensionsByName(CMessage *self, void *closure) {
@@ -2552,8 +2552,8 @@ static PyMethodDef Methods[] = {
"Serializes the message to a string, only for initialized messages." },
{ "SetInParent", (PyCFunction)SetInParent, METH_NOARGS,
"Sets the has bit of the given field in its parent message." },
- { "UnknownFields", (PyCFunction)UnknownFieldSet, METH_NOARGS,
- "Parse unknown field set"},
+ { "UnknownFields", (PyCFunction)UnknownFieldSet, METH_NOARGS,
+ "Parse unknown field set"},
{ "WhichOneof", (PyCFunction)WhichOneof, METH_O,
"Returns the name of the field set inside a oneof, "
"or None if no field is set." },
@@ -2565,65 +2565,65 @@ static PyMethodDef Methods[] = {
{ NULL, NULL}
};
-bool SetCompositeField(CMessage* self, const FieldDescriptor* field,
- ContainerBase* value) {
+bool SetCompositeField(CMessage* self, const FieldDescriptor* field,
+ ContainerBase* value) {
if (self->composite_fields == NULL) {
- self->composite_fields = new CMessage::CompositeFieldsMap();
- }
- (*self->composite_fields)[field] = value;
- return true;
-}
-
-bool SetSubmessage(CMessage* self, CMessage* submessage) {
- if (self->child_submessages == NULL) {
- self->child_submessages = new CMessage::SubMessagesMap();
- }
- (*self->child_submessages)[submessage->message] = submessage;
- return true;
-}
-
-PyObject* GetAttr(PyObject* pself, PyObject* name) {
- CMessage* self = reinterpret_cast<CMessage*>(pself);
- PyObject* result = PyObject_GenericGetAttr(
- reinterpret_cast<PyObject*>(self), name);
- if (result != NULL) {
- return result;
- }
- if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
- return NULL;
- }
-
- PyErr_Clear();
- return message_meta::GetClassAttribute(
- CheckMessageClass(Py_TYPE(self)), name);
-}
-
-PyObject* GetFieldValue(CMessage* self,
- const FieldDescriptor* field_descriptor) {
- if (self->composite_fields) {
- CMessage::CompositeFieldsMap::iterator it =
- self->composite_fields->find(field_descriptor);
- if (it != self->composite_fields->end()) {
- ContainerBase* value = it->second;
- Py_INCREF(value);
- return value->AsPyObject();
- }
- }
-
- if (self->message->GetDescriptor() != field_descriptor->containing_type()) {
- PyErr_Format(PyExc_TypeError,
- "descriptor to field '%s' doesn't apply to '%s' object",
- field_descriptor->full_name().c_str(),
- Py_TYPE(self)->tp_name);
- return NULL;
- }
-
- if (!field_descriptor->is_repeated() &&
- field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
- return InternalGetScalar(self->message, field_descriptor);
- }
-
- ContainerBase* py_container = nullptr;
+ self->composite_fields = new CMessage::CompositeFieldsMap();
+ }
+ (*self->composite_fields)[field] = value;
+ return true;
+}
+
+bool SetSubmessage(CMessage* self, CMessage* submessage) {
+ if (self->child_submessages == NULL) {
+ self->child_submessages = new CMessage::SubMessagesMap();
+ }
+ (*self->child_submessages)[submessage->message] = submessage;
+ return true;
+}
+
+PyObject* GetAttr(PyObject* pself, PyObject* name) {
+ CMessage* self = reinterpret_cast<CMessage*>(pself);
+ PyObject* result = PyObject_GenericGetAttr(
+ reinterpret_cast<PyObject*>(self), name);
+ if (result != NULL) {
+ return result;
+ }
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ return NULL;
+ }
+
+ PyErr_Clear();
+ return message_meta::GetClassAttribute(
+ CheckMessageClass(Py_TYPE(self)), name);
+}
+
+PyObject* GetFieldValue(CMessage* self,
+ const FieldDescriptor* field_descriptor) {
+ if (self->composite_fields) {
+ CMessage::CompositeFieldsMap::iterator it =
+ self->composite_fields->find(field_descriptor);
+ if (it != self->composite_fields->end()) {
+ ContainerBase* value = it->second;
+ Py_INCREF(value);
+ return value->AsPyObject();
+ }
+ }
+
+ if (self->message->GetDescriptor() != field_descriptor->containing_type()) {
+ PyErr_Format(PyExc_TypeError,
+ "descriptor to field '%s' doesn't apply to '%s' object",
+ field_descriptor->full_name().c_str(),
+ Py_TYPE(self)->tp_name);
+ return NULL;
+ }
+
+ if (!field_descriptor->is_repeated() &&
+ field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
+ return InternalGetScalar(self->message, field_descriptor);
+ }
+
+ ContainerBase* py_container = nullptr;
if (field_descriptor->is_map()) {
const Descriptor* entry_type = field_descriptor->message_type();
const FieldDescriptor* value_type = entry_type->FindFieldByName("value");
@@ -2638,7 +2638,7 @@ PyObject* GetFieldValue(CMessage* self,
} else {
py_container = NewScalarMapContainer(self, field_descriptor);
}
- } else if (field_descriptor->is_repeated()) {
+ } else if (field_descriptor->is_repeated()) {
if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
CMessageClass* message_class = message_factory::GetMessageClass(
GetFactoryForMessage(self), field_descriptor->message_type());
@@ -2648,129 +2648,129 @@ PyObject* GetFieldValue(CMessage* self,
py_container = repeated_composite_container::NewContainer(
self, field_descriptor, message_class);
} else {
- py_container =
- repeated_scalar_container::NewContainer(self, field_descriptor);
+ py_container =
+ repeated_scalar_container::NewContainer(self, field_descriptor);
}
- } else if (field_descriptor->cpp_type() ==
- FieldDescriptor::CPPTYPE_MESSAGE) {
- py_container = InternalGetSubMessage(self, field_descriptor);
- } else {
- PyErr_SetString(PyExc_SystemError, "Should never happen");
+ } else if (field_descriptor->cpp_type() ==
+ FieldDescriptor::CPPTYPE_MESSAGE) {
+ py_container = InternalGetSubMessage(self, field_descriptor);
+ } else {
+ PyErr_SetString(PyExc_SystemError, "Should never happen");
}
- if (py_container == NULL) {
- return NULL;
- }
- if (!SetCompositeField(self, field_descriptor, py_container)) {
- Py_DECREF(py_container);
- return NULL;
+ if (py_container == NULL) {
+ return NULL;
}
- return py_container->AsPyObject();
+ if (!SetCompositeField(self, field_descriptor, py_container)) {
+ Py_DECREF(py_container);
+ return NULL;
+ }
+ return py_container->AsPyObject();
}
-int SetFieldValue(CMessage* self, const FieldDescriptor* field_descriptor,
- PyObject* value) {
- if (self->message->GetDescriptor() != field_descriptor->containing_type()) {
- PyErr_Format(PyExc_TypeError,
- "descriptor to field '%s' doesn't apply to '%s' object",
- field_descriptor->full_name().c_str(),
- Py_TYPE(self)->tp_name);
+int SetFieldValue(CMessage* self, const FieldDescriptor* field_descriptor,
+ PyObject* value) {
+ if (self->message->GetDescriptor() != field_descriptor->containing_type()) {
+ PyErr_Format(PyExc_TypeError,
+ "descriptor to field '%s' doesn't apply to '%s' object",
+ field_descriptor->full_name().c_str(),
+ Py_TYPE(self)->tp_name);
return -1;
- } else if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
- PyErr_Format(PyExc_AttributeError,
- "Assignment not allowed to repeated "
- "field \"%s\" in protocol message object.",
- field_descriptor->name().c_str());
- return -1;
- } else if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- PyErr_Format(PyExc_AttributeError,
- "Assignment not allowed to "
- "field \"%s\" in protocol message object.",
- field_descriptor->name().c_str());
- return -1;
- } else {
- AssureWritable(self);
- return InternalSetScalar(self, field_descriptor, value);
- }
-}
-
-} // namespace cmessage
-
-// All containers which are not messages:
-// - Make a new parent message
-// - Copy the field
-// - return the field.
-PyObject* ContainerBase::DeepCopy() {
- CMessage* new_parent =
- cmessage::NewEmptyMessage(this->parent->GetMessageClass());
- new_parent->message = this->parent->message->New(nullptr);
-
- // Copy the map field into the new message.
- this->parent->message->GetReflection()->SwapFields(
- this->parent->message, new_parent->message,
- {this->parent_field_descriptor});
- this->parent->message->MergeFrom(*new_parent->message);
-
- PyObject* result =
- cmessage::GetFieldValue(new_parent, this->parent_field_descriptor);
- Py_DECREF(new_parent);
- return result;
-}
-
-void ContainerBase::RemoveFromParentCache() {
- CMessage* parent = this->parent;
- if (parent) {
- if (parent->composite_fields)
- parent->composite_fields->erase(this->parent_field_descriptor);
- Py_CLEAR(parent);
- }
-}
-
-CMessage* CMessage::BuildSubMessageFromPointer(
- const FieldDescriptor* field_descriptor, Message* sub_message,
- CMessageClass* message_class) {
- if (!this->child_submessages) {
- this->child_submessages = new CMessage::SubMessagesMap();
- }
- CMessage* cmsg = FindPtrOrNull(
- *this->child_submessages, sub_message);
- if (cmsg) {
- Py_INCREF(cmsg);
- } else {
- cmsg = cmessage::NewEmptyMessage(message_class);
-
- if (cmsg == NULL) {
- return NULL;
- }
- cmsg->message = sub_message;
- Py_INCREF(this);
- cmsg->parent = this;
- cmsg->parent_field_descriptor = field_descriptor;
- cmessage::SetSubmessage(this, cmsg);
- }
- return cmsg;
-}
-
-CMessage* CMessage::MaybeReleaseSubMessage(Message* sub_message) {
- if (!this->child_submessages) {
- return nullptr;
- }
- CMessage* released = FindPtrOrNull(
- *this->child_submessages, sub_message);
- if (!released) {
- return nullptr;
- }
- // The target message will now own its content.
- Py_CLEAR(released->parent);
- released->parent_field_descriptor = nullptr;
- released->read_only = false;
- // Delete it from the cache.
- this->child_submessages->erase(sub_message);
- return released;
-}
-
-static CMessageClass _CMessage_Type = { { {
- PyVarObject_HEAD_INIT(&_CMessageClass_Type, 0)
+ } else if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
+ PyErr_Format(PyExc_AttributeError,
+ "Assignment not allowed to repeated "
+ "field \"%s\" in protocol message object.",
+ field_descriptor->name().c_str());
+ return -1;
+ } else if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ PyErr_Format(PyExc_AttributeError,
+ "Assignment not allowed to "
+ "field \"%s\" in protocol message object.",
+ field_descriptor->name().c_str());
+ return -1;
+ } else {
+ AssureWritable(self);
+ return InternalSetScalar(self, field_descriptor, value);
+ }
+}
+
+} // namespace cmessage
+
+// All containers which are not messages:
+// - Make a new parent message
+// - Copy the field
+// - return the field.
+PyObject* ContainerBase::DeepCopy() {
+ CMessage* new_parent =
+ cmessage::NewEmptyMessage(this->parent->GetMessageClass());
+ new_parent->message = this->parent->message->New(nullptr);
+
+ // Copy the map field into the new message.
+ this->parent->message->GetReflection()->SwapFields(
+ this->parent->message, new_parent->message,
+ {this->parent_field_descriptor});
+ this->parent->message->MergeFrom(*new_parent->message);
+
+ PyObject* result =
+ cmessage::GetFieldValue(new_parent, this->parent_field_descriptor);
+ Py_DECREF(new_parent);
+ return result;
+}
+
+void ContainerBase::RemoveFromParentCache() {
+ CMessage* parent = this->parent;
+ if (parent) {
+ if (parent->composite_fields)
+ parent->composite_fields->erase(this->parent_field_descriptor);
+ Py_CLEAR(parent);
+ }
+}
+
+CMessage* CMessage::BuildSubMessageFromPointer(
+ const FieldDescriptor* field_descriptor, Message* sub_message,
+ CMessageClass* message_class) {
+ if (!this->child_submessages) {
+ this->child_submessages = new CMessage::SubMessagesMap();
+ }
+ CMessage* cmsg = FindPtrOrNull(
+ *this->child_submessages, sub_message);
+ if (cmsg) {
+ Py_INCREF(cmsg);
+ } else {
+ cmsg = cmessage::NewEmptyMessage(message_class);
+
+ if (cmsg == NULL) {
+ return NULL;
+ }
+ cmsg->message = sub_message;
+ Py_INCREF(this);
+ cmsg->parent = this;
+ cmsg->parent_field_descriptor = field_descriptor;
+ cmessage::SetSubmessage(this, cmsg);
+ }
+ return cmsg;
+}
+
+CMessage* CMessage::MaybeReleaseSubMessage(Message* sub_message) {
+ if (!this->child_submessages) {
+ return nullptr;
+ }
+ CMessage* released = FindPtrOrNull(
+ *this->child_submessages, sub_message);
+ if (!released) {
+ return nullptr;
+ }
+ // The target message will now own its content.
+ Py_CLEAR(released->parent);
+ released->parent_field_descriptor = nullptr;
+ released->read_only = false;
+ // Delete it from the cache.
+ this->child_submessages->erase(sub_message);
+ return released;
+}
+
+static CMessageClass _CMessage_Type = { { {
+ PyVarObject_HEAD_INIT(&_CMessageClass_Type, 0)
FULL_MODULE_NAME ".CMessage", // tp_name
sizeof(CMessage), // tp_basicsize
0, // tp_itemsize
@@ -2786,11 +2786,11 @@ static CMessageClass _CMessage_Type = { { {
PyObject_HashNotImplemented, // tp_hash
0, // tp_call
(reprfunc)cmessage::ToStr, // tp_str
- cmessage::GetAttr, // tp_getattro
- 0, // tp_setattro
+ cmessage::GetAttr, // tp_getattro
+ 0, // tp_setattro
0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
- | Py_TPFLAGS_HAVE_VERSION_TAG, // tp_flags
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
+ | Py_TPFLAGS_HAVE_VERSION_TAG, // tp_flags
"A ProtocolMessage", // tp_doc
0, // tp_traverse
0, // tp_clear
@@ -2809,121 +2809,121 @@ static CMessageClass _CMessage_Type = { { {
(initproc)cmessage::Init, // tp_init
0, // tp_alloc
cmessage::New, // tp_new
-} } };
-PyTypeObject* CMessage_Type = &_CMessage_Type.super.ht_type;
+} } };
+PyTypeObject* CMessage_Type = &_CMessage_Type.super.ht_type;
// --- Exposing the C proto living inside Python proto to C code:
-const Message* (*GetCProtoInsidePyProtoPtr)(PyObject* msg);
-Message* (*MutableCProtoInsidePyProtoPtr)(PyObject* msg);
+const Message* (*GetCProtoInsidePyProtoPtr)(PyObject* msg);
+Message* (*MutableCProtoInsidePyProtoPtr)(PyObject* msg);
static const Message* GetCProtoInsidePyProtoImpl(PyObject* msg) {
- const Message* message = PyMessage_GetMessagePointer(msg);
- if (message == NULL) {
- PyErr_Clear();
- return NULL;
- }
- return message;
-}
-
-static Message* MutableCProtoInsidePyProtoImpl(PyObject* msg) {
- Message* message = PyMessage_GetMutableMessagePointer(msg);
- if (message == NULL) {
- PyErr_Clear();
- return NULL;
- }
- return message;
-}
-
-const Message* PyMessage_GetMessagePointer(PyObject* msg) {
- if (!PyObject_TypeCheck(msg, CMessage_Type)) {
- PyErr_SetString(PyExc_TypeError, "Not a Message instance");
- return NULL;
- }
+ const Message* message = PyMessage_GetMessagePointer(msg);
+ if (message == NULL) {
+ PyErr_Clear();
+ return NULL;
+ }
+ return message;
+}
+
+static Message* MutableCProtoInsidePyProtoImpl(PyObject* msg) {
+ Message* message = PyMessage_GetMutableMessagePointer(msg);
+ if (message == NULL) {
+ PyErr_Clear();
+ return NULL;
+ }
+ return message;
+}
+
+const Message* PyMessage_GetMessagePointer(PyObject* msg) {
+ if (!PyObject_TypeCheck(msg, CMessage_Type)) {
+ PyErr_SetString(PyExc_TypeError, "Not a Message instance");
+ return NULL;
+ }
CMessage* cmsg = reinterpret_cast<CMessage*>(msg);
return cmsg->message;
}
-Message* PyMessage_GetMutableMessagePointer(PyObject* msg) {
- if (!PyObject_TypeCheck(msg, CMessage_Type)) {
- PyErr_SetString(PyExc_TypeError, "Not a Message instance");
+Message* PyMessage_GetMutableMessagePointer(PyObject* msg) {
+ if (!PyObject_TypeCheck(msg, CMessage_Type)) {
+ PyErr_SetString(PyExc_TypeError, "Not a Message instance");
return NULL;
}
CMessage* cmsg = reinterpret_cast<CMessage*>(msg);
-
-
- if ((cmsg->composite_fields && !cmsg->composite_fields->empty()) ||
- (cmsg->child_submessages && !cmsg->child_submessages->empty())) {
+
+
+ if ((cmsg->composite_fields && !cmsg->composite_fields->empty()) ||
+ (cmsg->child_submessages && !cmsg->child_submessages->empty())) {
// There is currently no way of accurately syncing arbitrary changes to
// the underlying C++ message back to the CMessage (e.g. removed repeated
// composite containers). We only allow direct mutation of the underlying
// C++ message if there is no child data in the CMessage.
- PyErr_SetString(PyExc_ValueError,
- "Cannot reliably get a mutable pointer "
- "to a message with extra references");
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot reliably get a mutable pointer "
+ "to a message with extra references");
return NULL;
}
cmessage::AssureWritable(cmsg);
return cmsg->message;
}
-PyObject* PyMessage_New(const Descriptor* descriptor,
- PyObject* py_message_factory) {
- PyMessageFactory* factory = nullptr;
- if (py_message_factory == nullptr) {
- factory = GetDescriptorPool_FromPool(descriptor->file()->pool())
- ->py_message_factory;
- } else if (PyObject_TypeCheck(py_message_factory, &PyMessageFactory_Type)) {
- factory = reinterpret_cast<PyMessageFactory*>(py_message_factory);
- } else {
- PyErr_SetString(PyExc_TypeError, "Expected a MessageFactory");
- return nullptr;
- }
- auto* message_class =
- message_factory::GetOrCreateMessageClass(factory, descriptor);
- if (message_class == nullptr) {
- return nullptr;
- }
-
- CMessage* self = cmessage::NewCMessage(message_class);
- Py_DECREF(message_class);
- if (self == nullptr) {
- return nullptr;
- }
- return self->AsPyObject();
-}
-
-PyObject* PyMessage_NewMessageOwnedExternally(Message* message,
- PyObject* py_message_factory) {
- if (py_message_factory) {
- PyErr_SetString(PyExc_NotImplementedError,
- "Default message_factory=NULL is the only supported value");
- return nullptr;
- }
- if (message->GetReflection()->GetMessageFactory() !=
- MessageFactory::generated_factory()) {
- PyErr_SetString(PyExc_TypeError,
- "Message pointer was not created from the default factory");
- return nullptr;
- }
-
- CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
- GetDefaultDescriptorPool()->py_message_factory, message->GetDescriptor());
- if (message_class == nullptr) {
- return nullptr;
- }
-
- CMessage* self = cmessage::NewEmptyMessage(message_class);
- Py_DECREF(message_class);
- if (self == nullptr) {
- return nullptr;
- }
- self->message = message;
- Py_INCREF(Py_None);
- self->parent = reinterpret_cast<CMessage*>(Py_None);
- return self->AsPyObject();
-}
-
+PyObject* PyMessage_New(const Descriptor* descriptor,
+ PyObject* py_message_factory) {
+ PyMessageFactory* factory = nullptr;
+ if (py_message_factory == nullptr) {
+ factory = GetDescriptorPool_FromPool(descriptor->file()->pool())
+ ->py_message_factory;
+ } else if (PyObject_TypeCheck(py_message_factory, &PyMessageFactory_Type)) {
+ factory = reinterpret_cast<PyMessageFactory*>(py_message_factory);
+ } else {
+ PyErr_SetString(PyExc_TypeError, "Expected a MessageFactory");
+ return nullptr;
+ }
+ auto* message_class =
+ message_factory::GetOrCreateMessageClass(factory, descriptor);
+ if (message_class == nullptr) {
+ return nullptr;
+ }
+
+ CMessage* self = cmessage::NewCMessage(message_class);
+ Py_DECREF(message_class);
+ if (self == nullptr) {
+ return nullptr;
+ }
+ return self->AsPyObject();
+}
+
+PyObject* PyMessage_NewMessageOwnedExternally(Message* message,
+ PyObject* py_message_factory) {
+ if (py_message_factory) {
+ PyErr_SetString(PyExc_NotImplementedError,
+ "Default message_factory=NULL is the only supported value");
+ return nullptr;
+ }
+ if (message->GetReflection()->GetMessageFactory() !=
+ MessageFactory::generated_factory()) {
+ PyErr_SetString(PyExc_TypeError,
+ "Message pointer was not created from the default factory");
+ return nullptr;
+ }
+
+ CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
+ GetDefaultDescriptorPool()->py_message_factory, message->GetDescriptor());
+ if (message_class == nullptr) {
+ return nullptr;
+ }
+
+ CMessage* self = cmessage::NewEmptyMessage(message_class);
+ Py_DECREF(message_class);
+ if (self == nullptr) {
+ return nullptr;
+ }
+ self->message = message;
+ Py_INCREF(Py_None);
+ self->parent = reinterpret_cast<CMessage*>(Py_None);
+ return self->AsPyObject();
+}
+
void InitGlobals() {
// TODO(gps): Check all return values in this function for NULL and propagate
// the error (MemoryError) on up to result in an import failure. These should
@@ -2954,29 +2954,29 @@ bool InitProto2MessageModule(PyObject *m) {
// Initialize constants defined in this file.
InitGlobals();
- CMessageClass_Type->tp_base = &PyType_Type;
- if (PyType_Ready(CMessageClass_Type) < 0) {
+ CMessageClass_Type->tp_base = &PyType_Type;
+ if (PyType_Ready(CMessageClass_Type) < 0) {
return false;
}
PyModule_AddObject(m, "MessageMeta",
- reinterpret_cast<PyObject*>(CMessageClass_Type));
+ reinterpret_cast<PyObject*>(CMessageClass_Type));
- if (PyType_Ready(CMessage_Type) < 0) {
- return false;
- }
- if (PyType_Ready(CFieldProperty_Type) < 0) {
+ if (PyType_Ready(CMessage_Type) < 0) {
return false;
}
+ if (PyType_Ready(CFieldProperty_Type) < 0) {
+ return false;
+ }
// DESCRIPTOR is set on each protocol buffer message class elsewhere, but set
// it here as well to document that subclasses need to set it.
- PyDict_SetItem(CMessage_Type->tp_dict, kDESCRIPTOR, Py_None);
- // Invalidate any cached data for the CMessage type.
- // This call is necessary to correctly support Py_TPFLAGS_HAVE_VERSION_TAG,
- // after we have modified CMessage_Type.tp_dict.
- PyType_Modified(CMessage_Type);
+ PyDict_SetItem(CMessage_Type->tp_dict, kDESCRIPTOR, Py_None);
+ // Invalidate any cached data for the CMessage type.
+ // This call is necessary to correctly support Py_TPFLAGS_HAVE_VERSION_TAG,
+ // after we have modified CMessage_Type.tp_dict.
+ PyType_Modified(CMessage_Type);
- PyModule_AddObject(m, "Message", reinterpret_cast<PyObject*>(CMessage_Type));
+ PyModule_AddObject(m, "Message", reinterpret_cast<PyObject*>(CMessage_Type));
// Initialize Repeated container types.
{
@@ -2984,9 +2984,9 @@ bool InitProto2MessageModule(PyObject *m) {
return false;
}
- PyModule_AddObject(
- m, "RepeatedScalarContainer",
- reinterpret_cast<PyObject*>(&RepeatedScalarContainer_Type));
+ PyModule_AddObject(
+ m, "RepeatedScalarContainer",
+ reinterpret_cast<PyObject*>(&RepeatedScalarContainer_Type));
if (PyType_Ready(&RepeatedCompositeContainer_Type) < 0) {
return false;
@@ -2994,7 +2994,7 @@ bool InitProto2MessageModule(PyObject *m) {
PyModule_AddObject(
m, "RepeatedCompositeContainer",
- reinterpret_cast<PyObject*>(&RepeatedCompositeContainer_Type));
+ reinterpret_cast<PyObject*>(&RepeatedCompositeContainer_Type));
// Register them as MutableSequence.
#if PY_MAJOR_VERSION >= 3
@@ -3022,20 +3022,20 @@ bool InitProto2MessageModule(PyObject *m) {
}
}
- if (PyType_Ready(&PyUnknownFields_Type) < 0) {
- return false;
- }
-
- PyModule_AddObject(m, "UnknownFieldSet",
- reinterpret_cast<PyObject*>(&PyUnknownFields_Type));
-
- if (PyType_Ready(&PyUnknownFieldRef_Type) < 0) {
- return false;
- }
-
- PyModule_AddObject(m, "UnknownField",
- reinterpret_cast<PyObject*>(&PyUnknownFieldRef_Type));
-
+ if (PyType_Ready(&PyUnknownFields_Type) < 0) {
+ return false;
+ }
+
+ PyModule_AddObject(m, "UnknownFieldSet",
+ reinterpret_cast<PyObject*>(&PyUnknownFields_Type));
+
+ if (PyType_Ready(&PyUnknownFieldRef_Type) < 0) {
+ return false;
+ }
+
+ PyModule_AddObject(m, "UnknownField",
+ reinterpret_cast<PyObject*>(&PyUnknownFieldRef_Type));
+
// Initialize Map container types.
if (!InitMapContainers()) {
return false;
@@ -3050,13 +3050,13 @@ bool InitProto2MessageModule(PyObject *m) {
if (PyType_Ready(&ExtensionDict_Type) < 0) {
return false;
}
- PyModule_AddObject(m, "ExtensionDict",
- reinterpret_cast<PyObject*>(&ExtensionDict_Type));
- if (PyType_Ready(&ExtensionIterator_Type) < 0) {
- return false;
- }
- PyModule_AddObject(m, "ExtensionIterator",
- reinterpret_cast<PyObject*>(&ExtensionIterator_Type));
+ PyModule_AddObject(m, "ExtensionDict",
+ reinterpret_cast<PyObject*>(&ExtensionDict_Type));
+ if (PyType_Ready(&ExtensionIterator_Type) < 0) {
+ return false;
+ }
+ PyModule_AddObject(m, "ExtensionIterator",
+ reinterpret_cast<PyObject*>(&ExtensionIterator_Type));
// Expose the DescriptorPool used to hold all descriptors added from generated
// pb2.py files.
@@ -3065,24 +3065,24 @@ bool InitProto2MessageModule(PyObject *m) {
PyModule_AddObject(m, "default_pool",
reinterpret_cast<PyObject*>(GetDefaultDescriptorPool()));
- PyModule_AddObject(m, "DescriptorPool",
- reinterpret_cast<PyObject*>(&PyDescriptorPool_Type));
- PyModule_AddObject(m, "Descriptor",
- reinterpret_cast<PyObject*>(&PyMessageDescriptor_Type));
- PyModule_AddObject(m, "FieldDescriptor",
- reinterpret_cast<PyObject*>(&PyFieldDescriptor_Type));
- PyModule_AddObject(m, "EnumDescriptor",
- reinterpret_cast<PyObject*>(&PyEnumDescriptor_Type));
- PyModule_AddObject(m, "EnumValueDescriptor",
- reinterpret_cast<PyObject*>(&PyEnumValueDescriptor_Type));
- PyModule_AddObject(m, "FileDescriptor",
- reinterpret_cast<PyObject*>(&PyFileDescriptor_Type));
- PyModule_AddObject(m, "OneofDescriptor",
- reinterpret_cast<PyObject*>(&PyOneofDescriptor_Type));
- PyModule_AddObject(m, "ServiceDescriptor",
- reinterpret_cast<PyObject*>(&PyServiceDescriptor_Type));
- PyModule_AddObject(m, "MethodDescriptor",
- reinterpret_cast<PyObject*>(&PyMethodDescriptor_Type));
+ PyModule_AddObject(m, "DescriptorPool",
+ reinterpret_cast<PyObject*>(&PyDescriptorPool_Type));
+ PyModule_AddObject(m, "Descriptor",
+ reinterpret_cast<PyObject*>(&PyMessageDescriptor_Type));
+ PyModule_AddObject(m, "FieldDescriptor",
+ reinterpret_cast<PyObject*>(&PyFieldDescriptor_Type));
+ PyModule_AddObject(m, "EnumDescriptor",
+ reinterpret_cast<PyObject*>(&PyEnumDescriptor_Type));
+ PyModule_AddObject(m, "EnumValueDescriptor",
+ reinterpret_cast<PyObject*>(&PyEnumValueDescriptor_Type));
+ PyModule_AddObject(m, "FileDescriptor",
+ reinterpret_cast<PyObject*>(&PyFileDescriptor_Type));
+ PyModule_AddObject(m, "OneofDescriptor",
+ reinterpret_cast<PyObject*>(&PyOneofDescriptor_Type));
+ PyModule_AddObject(m, "ServiceDescriptor",
+ reinterpret_cast<PyObject*>(&PyServiceDescriptor_Type));
+ PyModule_AddObject(m, "MethodDescriptor",
+ reinterpret_cast<PyObject*>(&PyMethodDescriptor_Type));
PyObject* enum_type_wrapper = PyImport_ImportModule(
"google.protobuf.internal.enum_type_wrapper");
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/message.h b/contrib/python/protobuf/py2/google/protobuf/pyext/message.h
index ca81a87521..9c1d4a5da8 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/message.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/message.h
@@ -36,13 +36,13 @@
#include <Python.h>
-#include <cstdint>
+#include <cstdint>
#include <memory>
-#include <string>
-#include <unordered_map>
-
-#include <google/protobuf/stubs/common.h>
+#include <string>
+#include <unordered_map>
+#include <google/protobuf/stubs/common.h>
+
namespace google {
namespace protobuf {
@@ -57,51 +57,51 @@ namespace python {
struct ExtensionDict;
struct PyMessageFactory;
-struct CMessageClass;
-
-// Most of the complexity of the Message class comes from the "Release"
-// behavior:
-//
-// When a field is cleared, it is only detached from its message. Existing
-// references to submessages, to repeated container etc. won't see any change,
-// as if the data was effectively managed by these containers.
-//
-// ExtensionDicts and UnknownFields containers do NOT follow this rule. They
-// don't store any data, and always refer to their parent message.
-
-struct ContainerBase {
+struct CMessageClass;
+
+// Most of the complexity of the Message class comes from the "Release"
+// behavior:
+//
+// When a field is cleared, it is only detached from its message. Existing
+// references to submessages, to repeated container etc. won't see any change,
+// as if the data was effectively managed by these containers.
+//
+// ExtensionDicts and UnknownFields containers do NOT follow this rule. They
+// don't store any data, and always refer to their parent message.
+
+struct ContainerBase {
PyObject_HEAD;
- // Strong reference to a parent message object. For a CMessage there are three
- // cases:
- // - For a top-level message, this pointer is NULL.
- // - For a sub-message, this points to the parent message.
- // - For a message managed externally, this is a owned reference to Py_None.
+ // Strong reference to a parent message object. For a CMessage there are three
+ // cases:
+ // - For a top-level message, this pointer is NULL.
+ // - For a sub-message, this points to the parent message.
+ // - For a message managed externally, this is a owned reference to Py_None.
//
- // For all other types: repeated containers, maps, it always point to a
- // valid parent CMessage.
+ // For all other types: repeated containers, maps, it always point to a
+ // valid parent CMessage.
struct CMessage* parent;
- // If this object belongs to a parent message, describes which field it comes
- // from.
- // The pointer is owned by the DescriptorPool (which is kept alive
- // through the message's Python class)
+ // If this object belongs to a parent message, describes which field it comes
+ // from.
+ // The pointer is owned by the DescriptorPool (which is kept alive
+ // through the message's Python class)
const FieldDescriptor* parent_field_descriptor;
- PyObject* AsPyObject() { return reinterpret_cast<PyObject*>(this); }
-
- // The Three methods below are only used by Repeated containers, and Maps.
-
- // This implementation works for all containers which have a parent.
- PyObject* DeepCopy();
- // Delete this container object from its parent. Does not work for messages.
- void RemoveFromParentCache();
-};
-
-typedef struct CMessage : public ContainerBase {
- // Pointer to the C++ Message object for this CMessage.
- // - If this object has no parent, we own this pointer.
- // - If this object has a parent message, the parent owns this pointer.
+ PyObject* AsPyObject() { return reinterpret_cast<PyObject*>(this); }
+
+ // The Three methods below are only used by Repeated containers, and Maps.
+
+ // This implementation works for all containers which have a parent.
+ PyObject* DeepCopy();
+ // Delete this container object from its parent. Does not work for messages.
+ void RemoveFromParentCache();
+};
+
+typedef struct CMessage : public ContainerBase {
+ // Pointer to the C++ Message object for this CMessage.
+ // - If this object has no parent, we own this pointer.
+ // - If this object has a parent message, the parent owns this pointer.
Message* message;
// Indicates this submessage is pointing to a default instance of a message.
@@ -109,38 +109,38 @@ typedef struct CMessage : public ContainerBase {
// made writable, at which point this field is set to false.
bool read_only;
- // A mapping indexed by field, containing weak references to contained objects
- // which need to implement the "Release" mechanism:
- // direct submessages, RepeatedCompositeContainer, RepeatedScalarContainer
- // and MapContainer.
- typedef std::unordered_map<const FieldDescriptor*, ContainerBase*>
- CompositeFieldsMap;
- CompositeFieldsMap* composite_fields;
-
- // A mapping containing weak references to indirect child messages, accessed
- // through containers: repeated messages, and values of message maps.
- // This avoid the creation of similar maps in each of those containers.
- typedef std::unordered_map<const Message*, CMessage*> SubMessagesMap;
- SubMessagesMap* child_submessages;
-
- // A reference to PyUnknownFields.
- PyObject* unknown_field_set;
-
+ // A mapping indexed by field, containing weak references to contained objects
+ // which need to implement the "Release" mechanism:
+ // direct submessages, RepeatedCompositeContainer, RepeatedScalarContainer
+ // and MapContainer.
+ typedef std::unordered_map<const FieldDescriptor*, ContainerBase*>
+ CompositeFieldsMap;
+ CompositeFieldsMap* composite_fields;
+
+ // A mapping containing weak references to indirect child messages, accessed
+ // through containers: repeated messages, and values of message maps.
+ // This avoid the creation of similar maps in each of those containers.
+ typedef std::unordered_map<const Message*, CMessage*> SubMessagesMap;
+ SubMessagesMap* child_submessages;
+
+ // A reference to PyUnknownFields.
+ PyObject* unknown_field_set;
+
// Implements the "weakref" protocol for this object.
PyObject* weakreflist;
- // Return a *borrowed* reference to the message class.
- CMessageClass* GetMessageClass() {
- return reinterpret_cast<CMessageClass*>(Py_TYPE(this));
- }
+ // Return a *borrowed* reference to the message class.
+ CMessageClass* GetMessageClass() {
+ return reinterpret_cast<CMessageClass*>(Py_TYPE(this));
+ }
- // For container containing messages, return a Python object for the given
- // pointer to a message.
- CMessage* BuildSubMessageFromPointer(const FieldDescriptor* field_descriptor,
- Message* sub_message,
- CMessageClass* message_class);
- CMessage* MaybeReleaseSubMessage(Message* sub_message);
-} CMessage;
+ // For container containing messages, return a Python object for the given
+ // pointer to a message.
+ CMessage* BuildSubMessageFromPointer(const FieldDescriptor* field_descriptor,
+ Message* sub_message,
+ CMessageClass* message_class);
+ CMessage* MaybeReleaseSubMessage(Message* sub_message);
+} CMessage;
// The (meta) type of all Messages classes.
// It allows us to cache some C++ pointers in the class object itself, they are
@@ -155,13 +155,13 @@ struct CMessageClass {
const Descriptor* message_descriptor;
// Owned reference, used to keep the pointer above alive.
- // This reference must stay alive until all message pointers are destructed.
+ // This reference must stay alive until all message pointers are destructed.
PyObject* py_message_descriptor;
// The Python MessageFactory used to create the class. It is needed to resolve
// fields descriptors, including extensions fields; its C++ MessageFactory is
// used to instantiate submessages.
- // This reference must stay alive until all message pointers are destructed.
+ // This reference must stay alive until all message pointers are destructed.
PyMessageFactory* py_message_factory;
PyObject* AsPyObject() {
@@ -169,8 +169,8 @@ struct CMessageClass {
}
};
-extern PyTypeObject* CMessageClass_Type;
-extern PyTypeObject* CMessage_Type;
+extern PyTypeObject* CMessageClass_Type;
+extern PyTypeObject* CMessage_Type;
namespace cmessage {
@@ -187,16 +187,16 @@ const FieldDescriptor* GetExtensionDescriptor(PyObject* extension);
// submessage as the result is cached in composite_fields.
//
// Corresponds to reflection api method GetMessage.
-CMessage* InternalGetSubMessage(
+CMessage* InternalGetSubMessage(
CMessage* self, const FieldDescriptor* field_descriptor);
-// Deletes a range of items in a repeated field (following a
+// Deletes a range of items in a repeated field (following a
// removal in a RepeatedCompositeContainer).
//
// Corresponds to reflection api method RemoveLast.
-int DeleteRepeatedField(CMessage* self,
- const FieldDescriptor* field_descriptor,
- PyObject* slice);
+int DeleteRepeatedField(CMessage* self,
+ const FieldDescriptor* field_descriptor,
+ PyObject* slice);
// Sets the specified scalar value to the message.
int InternalSetScalar(CMessage* self,
@@ -214,30 +214,30 @@ int InternalSetNonOneofScalar(Message* message,
PyObject* InternalGetScalar(const Message* message,
const FieldDescriptor* field_descriptor);
-bool SetCompositeField(CMessage* self, const FieldDescriptor* field,
- ContainerBase* value);
-
-bool SetSubmessage(CMessage* self, CMessage* submessage);
-
+bool SetCompositeField(CMessage* self, const FieldDescriptor* field,
+ ContainerBase* value);
+
+bool SetSubmessage(CMessage* self, CMessage* submessage);
+
// Clears the message, removing all contained data. Extension dictionary and
// submessages are released first if there are remaining external references.
//
// Corresponds to message api method Clear.
PyObject* Clear(CMessage* self);
-// Clears the data described by the given descriptor.
-// Returns -1 on error.
+// Clears the data described by the given descriptor.
+// Returns -1 on error.
//
// Corresponds to reflection api method ClearField.
-int ClearFieldByDescriptor(CMessage* self, const FieldDescriptor* descriptor);
+int ClearFieldByDescriptor(CMessage* self, const FieldDescriptor* descriptor);
// Checks if the message has the field described by the descriptor. Used for
// extensions (which have no name).
-// Returns 1 if true, 0 if false, and -1 on error.
+// Returns 1 if true, 0 if false, and -1 on error.
//
// Corresponds to reflection api method HasField
-int HasFieldByDescriptor(CMessage* self,
- const FieldDescriptor* field_descriptor);
+int HasFieldByDescriptor(CMessage* self,
+ const FieldDescriptor* field_descriptor);
// Checks if the message has the named field.
//
@@ -255,13 +255,13 @@ PyObject* MergeFrom(CMessage* self, PyObject* arg);
// has been registered with the same field number on this class.
PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle);
-// Get a field from a message.
-PyObject* GetFieldValue(CMessage* self,
- const FieldDescriptor* field_descriptor);
-// Sets the value of a scalar field in a message.
-// On error, return -1 with an extension set.
-int SetFieldValue(CMessage* self, const FieldDescriptor* field_descriptor,
- PyObject* value);
+// Get a field from a message.
+PyObject* GetFieldValue(CMessage* self,
+ const FieldDescriptor* field_descriptor);
+// Sets the value of a scalar field in a message.
+// On error, return -1 with an extension set.
+int SetFieldValue(CMessage* self, const FieldDescriptor* field_descriptor,
+ PyObject* value);
PyObject* FindInitializationErrors(CMessage* self);
@@ -283,50 +283,50 @@ PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg);
/* Is 64bit */
#define IS_64BIT (SIZEOF_LONG == 8)
-#define FIELD_IS_REPEATED(field_descriptor) \
- ((field_descriptor)->label() == FieldDescriptor::LABEL_REPEATED)
-
-#define GOOGLE_CHECK_GET_INT32(arg, value, err) \
- int32_t value; \
- if (!CheckAndGetInteger(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_INT64(arg, value, err) \
- int64_t value; \
- if (!CheckAndGetInteger(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_UINT32(arg, value, err) \
- uint32_t value; \
- if (!CheckAndGetInteger(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_UINT64(arg, value, err) \
- uint64_t value; \
- if (!CheckAndGetInteger(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_FLOAT(arg, value, err) \
- float value; \
- if (!CheckAndGetFloat(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_DOUBLE(arg, value, err) \
- double value; \
- if (!CheckAndGetDouble(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_BOOL(arg, value, err) \
- bool value; \
- if (!CheckAndGetBool(arg, &value)) { \
- return err; \
- }
+#define FIELD_IS_REPEATED(field_descriptor) \
+ ((field_descriptor)->label() == FieldDescriptor::LABEL_REPEATED)
+
+#define GOOGLE_CHECK_GET_INT32(arg, value, err) \
+ int32_t value; \
+ if (!CheckAndGetInteger(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_INT64(arg, value, err) \
+ int64_t value; \
+ if (!CheckAndGetInteger(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_UINT32(arg, value, err) \
+ uint32_t value; \
+ if (!CheckAndGetInteger(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_UINT64(arg, value, err) \
+ uint64_t value; \
+ if (!CheckAndGetInteger(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_FLOAT(arg, value, err) \
+ float value; \
+ if (!CheckAndGetFloat(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_DOUBLE(arg, value, err) \
+ double value; \
+ if (!CheckAndGetDouble(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_BOOL(arg, value, err) \
+ bool value; \
+ if (!CheckAndGetBool(arg, &value)) { \
+ return err; \
+ }
#define FULL_MODULE_NAME "google.protobuf.pyext._message"
@@ -343,8 +343,8 @@ bool CheckAndSetString(
const Reflection* reflection,
bool append,
int index);
-PyObject* ToStringObject(const FieldDescriptor* descriptor,
- const TProtoStringType& value);
+PyObject* ToStringObject(const FieldDescriptor* descriptor,
+ const TProtoStringType& value);
// Check if the passed field descriptor belongs to the given message.
// If not, return false and set a Python exception (a KeyError)
@@ -353,24 +353,24 @@ bool CheckFieldBelongsToMessage(const FieldDescriptor* field_descriptor,
extern PyObject* PickleError_class;
-PyObject* PyMessage_New(const Descriptor* descriptor,
- PyObject* py_message_factory);
-const Message* PyMessage_GetMessagePointer(PyObject* msg);
-Message* PyMessage_GetMutableMessagePointer(PyObject* msg);
-PyObject* PyMessage_NewMessageOwnedExternally(Message* message,
- PyObject* py_message_factory);
-
+PyObject* PyMessage_New(const Descriptor* descriptor,
+ PyObject* py_message_factory);
+const Message* PyMessage_GetMessagePointer(PyObject* msg);
+Message* PyMessage_GetMutableMessagePointer(PyObject* msg);
+PyObject* PyMessage_NewMessageOwnedExternally(Message* message,
+ PyObject* py_message_factory);
+
bool InitProto2MessageModule(PyObject *m);
-// These are referenced by repeated_scalar_container, and must
-// be explicitly instantiated.
-extern template bool CheckAndGetInteger<int32>(PyObject*, int32*);
-extern template bool CheckAndGetInteger<int64>(PyObject*, int64*);
-extern template bool CheckAndGetInteger<uint32>(PyObject*, uint32*);
-extern template bool CheckAndGetInteger<uint64>(PyObject*, uint64*);
-
+// These are referenced by repeated_scalar_container, and must
+// be explicitly instantiated.
+extern template bool CheckAndGetInteger<int32>(PyObject*, int32*);
+extern template bool CheckAndGetInteger<int64>(PyObject*, int64*);
+extern template bool CheckAndGetInteger<uint32>(PyObject*, uint32*);
+extern template bool CheckAndGetInteger<uint64>(PyObject*, uint64*);
+
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/message_factory.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/message_factory.cc
index 7905be0214..f35bebf0bf 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/message_factory.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/message_factory.cc
@@ -28,26 +28,26 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <unordered_map>
-
+#include <unordered_map>
+
#include <Python.h>
-#include <google/protobuf/dynamic_message.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#if PY_MAJOR_VERSION >= 3
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#endif
#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
namespace google {
@@ -69,7 +69,7 @@ PyMessageFactory* NewMessageFactory(PyTypeObject* type, PyDescriptorPool* pool)
factory->message_factory = message_factory;
factory->pool = pool;
- Py_INCREF(pool);
+ Py_INCREF(pool);
factory->classes_by_descriptor = new PyMessageFactory::ClassesByMessageMap();
@@ -79,8 +79,8 @@ PyMessageFactory* NewMessageFactory(PyTypeObject* type, PyDescriptorPool* pool)
PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
static const char* kwlist[] = {"pool", 0};
PyObject* pool = NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O",
- const_cast<char**>(kwlist), &pool)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O",
+ const_cast<char**>(kwlist), &pool)) {
return NULL;
}
ScopedPyObjectPtr owned_pool;
@@ -103,40 +103,40 @@ PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
NewMessageFactory(type, reinterpret_cast<PyDescriptorPool*>(pool)));
}
-static void Dealloc(PyObject* pself) {
- PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
-
+static void Dealloc(PyObject* pself) {
+ PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
+
typedef PyMessageFactory::ClassesByMessageMap::iterator iterator;
for (iterator it = self->classes_by_descriptor->begin();
it != self->classes_by_descriptor->end(); ++it) {
- Py_CLEAR(it->second);
+ Py_CLEAR(it->second);
}
delete self->classes_by_descriptor;
delete self->message_factory;
- Py_CLEAR(self->pool);
- Py_TYPE(self)->tp_free(pself);
-}
-
-static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
- PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
- Py_VISIT(self->pool);
- for (const auto& desc_and_class : *self->classes_by_descriptor) {
- Py_VISIT(desc_and_class.second);
- }
- return 0;
-}
-
-static int GcClear(PyObject* pself) {
- PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
- // Here it's important to not clear self->pool, so that the C++ DescriptorPool
- // is still alive when self->message_factory is destructed.
- for (auto& desc_and_class : *self->classes_by_descriptor) {
- Py_CLEAR(desc_and_class.second);
- }
-
- return 0;
+ Py_CLEAR(self->pool);
+ Py_TYPE(self)->tp_free(pself);
}
+static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
+ PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
+ Py_VISIT(self->pool);
+ for (const auto& desc_and_class : *self->classes_by_descriptor) {
+ Py_VISIT(desc_and_class.second);
+ }
+ return 0;
+}
+
+static int GcClear(PyObject* pself) {
+ PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
+ // Here it's important to not clear self->pool, so that the C++ DescriptorPool
+ // is still alive when self->message_factory is destructed.
+ for (auto& desc_and_class : *self->classes_by_descriptor) {
+ Py_CLEAR(desc_and_class.second);
+ }
+
+ return 0;
+}
+
// Add a message class to our database.
int RegisterMessageClass(PyMessageFactory* self,
const Descriptor* message_descriptor,
@@ -158,7 +158,7 @@ CMessageClass* GetOrCreateMessageClass(PyMessageFactory* self,
// This is the same implementation as MessageFactory.GetPrototype().
// Do not create a MessageClass that already exists.
- std::unordered_map<const Descriptor*, CMessageClass*>::iterator it =
+ std::unordered_map<const Descriptor*, CMessageClass*>::iterator it =
self->classes_by_descriptor->find(descriptor);
if (it != self->classes_by_descriptor->end()) {
Py_INCREF(it->second);
@@ -179,7 +179,7 @@ CMessageClass* GetOrCreateMessageClass(PyMessageFactory* self,
return NULL;
}
ScopedPyObjectPtr message_class(PyObject_CallObject(
- reinterpret_cast<PyObject*>(CMessageClass_Type), args.get()));
+ reinterpret_cast<PyObject*>(CMessageClass_Type), args.get()));
if (message_class == NULL) {
return NULL;
}
@@ -251,44 +251,44 @@ static PyGetSetDef Getters[] = {
PyTypeObject PyMessageFactory_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".MessageFactory", // tp_name
- sizeof(PyMessageFactory), // tp_basicsize
- 0, // tp_itemsize
- message_factory::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, // tp_flags
- "A static Message Factory", // tp_doc
- message_factory::GcTraverse, // tp_traverse
- message_factory::GcClear, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- message_factory::Methods, // tp_methods
- 0, // tp_members
- message_factory::Getters, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
- 0, // tp_alloc
- message_factory::New, // tp_new
- PyObject_GC_Del, // tp_free
+ ".MessageFactory", // tp_name
+ sizeof(PyMessageFactory), // tp_basicsize
+ 0, // tp_itemsize
+ message_factory::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, // tp_flags
+ "A static Message Factory", // tp_doc
+ message_factory::GcTraverse, // tp_traverse
+ message_factory::GcClear, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ message_factory::Methods, // tp_methods
+ 0, // tp_members
+ message_factory::Getters, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ message_factory::New, // tp_new
+ PyObject_GC_Del, // tp_free
};
bool InitMessageFactory() {
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/message_factory.h b/contrib/python/protobuf/py2/google/protobuf/pyext/message_factory.h
index 515c29cdb8..047ac9a75f 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/message_factory.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/message_factory.h
@@ -33,9 +33,9 @@
#include <Python.h>
-#include <unordered_map>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
+#include <unordered_map>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
namespace google {
namespace protobuf {
@@ -57,16 +57,16 @@ struct PyMessageFactory {
// The C++ one creates messages, when the Python one creates classes.
MessageFactory* message_factory;
- // Owned reference to a Python DescriptorPool.
- // This reference must stay until the message_factory is destructed.
+ // Owned reference to a Python DescriptorPool.
+ // This reference must stay until the message_factory is destructed.
PyDescriptorPool* pool;
// Make our own mapping to retrieve Python classes from C++ descriptors.
//
// Descriptor pointers stored here are owned by the DescriptorPool above.
// Python references to classes are owned by this PyDescriptorPool.
- typedef std::unordered_map<const Descriptor*, CMessageClass*>
- ClassesByMessageMap;
+ typedef std::unordered_map<const Descriptor*, CMessageClass*>
+ ClassesByMessageMap;
ClassesByMessageMap* classes_by_descriptor;
};
@@ -98,6 +98,6 @@ bool InitMessageFactory();
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/message_module.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/message_module.cc
index b5975f76c5..c5a24eea3b 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/message_module.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/message_module.cc
@@ -28,69 +28,69 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <Python.h>
-
-#include <google/protobuf/message_lite.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/proto_api.h>
-
-namespace {
-
-// C++ API. Clients get at this via proto_api.h
-struct ApiImplementation : google::protobuf::python::PyProto_API {
- const google::protobuf::Message* GetMessagePointer(PyObject* msg) const override {
- return google::protobuf::python::PyMessage_GetMessagePointer(msg);
- }
- google::protobuf::Message* GetMutableMessagePointer(PyObject* msg) const override {
- return google::protobuf::python::PyMessage_GetMutableMessagePointer(msg);
- }
- const google::protobuf::DescriptorPool* GetDefaultDescriptorPool() const override {
- return google::protobuf::python::GetDefaultDescriptorPool()->pool;
- }
-
- google::protobuf::MessageFactory* GetDefaultMessageFactory() const override {
- return google::protobuf::python::GetDefaultDescriptorPool()
- ->py_message_factory->message_factory;
- }
- PyObject* NewMessage(const google::protobuf::Descriptor* descriptor,
- PyObject* py_message_factory) const override {
- return google::protobuf::python::PyMessage_New(descriptor, py_message_factory);
- }
- PyObject* NewMessageOwnedExternally(
- google::protobuf::Message* msg, PyObject* py_message_factory) const override {
- return google::protobuf::python::PyMessage_NewMessageOwnedExternally(
- msg, py_message_factory);
- }
-};
-
-} // namespace
+#include <Python.h>
+
+#include <google/protobuf/message_lite.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/proto_api.h>
+namespace {
+
+// C++ API. Clients get at this via proto_api.h
+struct ApiImplementation : google::protobuf::python::PyProto_API {
+ const google::protobuf::Message* GetMessagePointer(PyObject* msg) const override {
+ return google::protobuf::python::PyMessage_GetMessagePointer(msg);
+ }
+ google::protobuf::Message* GetMutableMessagePointer(PyObject* msg) const override {
+ return google::protobuf::python::PyMessage_GetMutableMessagePointer(msg);
+ }
+ const google::protobuf::DescriptorPool* GetDefaultDescriptorPool() const override {
+ return google::protobuf::python::GetDefaultDescriptorPool()->pool;
+ }
+
+ google::protobuf::MessageFactory* GetDefaultMessageFactory() const override {
+ return google::protobuf::python::GetDefaultDescriptorPool()
+ ->py_message_factory->message_factory;
+ }
+ PyObject* NewMessage(const google::protobuf::Descriptor* descriptor,
+ PyObject* py_message_factory) const override {
+ return google::protobuf::python::PyMessage_New(descriptor, py_message_factory);
+ }
+ PyObject* NewMessageOwnedExternally(
+ google::protobuf::Message* msg, PyObject* py_message_factory) const override {
+ return google::protobuf::python::PyMessage_NewMessageOwnedExternally(
+ msg, py_message_factory);
+ }
+};
+
+} // namespace
+
static const char module_docstring[] =
- "python-proto2 is a module that can be used to enhance proto2 Python API\n"
- "performance.\n"
- "\n"
- "It provides access to the protocol buffers C++ reflection API that\n"
- "implements the basic protocol buffer functions.";
+ "python-proto2 is a module that can be used to enhance proto2 Python API\n"
+ "performance.\n"
+ "\n"
+ "It provides access to the protocol buffers C++ reflection API that\n"
+ "implements the basic protocol buffer functions.";
static PyMethodDef ModuleMethods[] = {
- {"SetAllowOversizeProtos",
- (PyCFunction)google::protobuf::python::cmessage::SetAllowOversizeProtos, METH_O,
- "Enable/disable oversize proto parsing."},
- // DO NOT USE: For migration and testing only.
- {NULL, NULL}};
+ {"SetAllowOversizeProtos",
+ (PyCFunction)google::protobuf::python::cmessage::SetAllowOversizeProtos, METH_O,
+ "Enable/disable oversize proto parsing."},
+ // DO NOT USE: For migration and testing only.
+ {NULL, NULL}};
#if PY_MAJOR_VERSION >= 3
-static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
- "_message",
- module_docstring,
- -1,
- ModuleMethods, /* m_methods */
- NULL,
- NULL,
- NULL,
- NULL};
+static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
+ "_message",
+ module_docstring,
+ -1,
+ ModuleMethods, /* m_methods */
+ NULL,
+ NULL,
+ NULL,
+ NULL};
#define INITFUNC PyInit__message
#define INITFUNC_ERRORVAL NULL
#else // Python 2
@@ -98,35 +98,35 @@ static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
#define INITFUNC_ERRORVAL
#endif
-PyMODINIT_FUNC INITFUNC() {
- PyObject* m;
+PyMODINIT_FUNC INITFUNC() {
+ PyObject* m;
#if PY_MAJOR_VERSION >= 3
- m = PyModule_Create(&_module);
+ m = PyModule_Create(&_module);
#else
- m = Py_InitModule3("_message", ModuleMethods, module_docstring);
+ m = Py_InitModule3("_message", ModuleMethods, module_docstring);
#endif
- if (m == NULL) {
- return INITFUNC_ERRORVAL;
- }
-
- if (!google::protobuf::python::InitProto2MessageModule(m)) {
- Py_DECREF(m);
- return INITFUNC_ERRORVAL;
- }
+ if (m == NULL) {
+ return INITFUNC_ERRORVAL;
+ }
- // Adds the C++ API
- if (PyObject* api = PyCapsule_New(
- new ApiImplementation(), google::protobuf::python::PyProtoAPICapsuleName(),
- [](PyObject* o) {
- delete (ApiImplementation*)PyCapsule_GetPointer(
- o, google::protobuf::python::PyProtoAPICapsuleName());
- })) {
- PyModule_AddObject(m, "proto_API", api);
- } else {
- return INITFUNC_ERRORVAL;
- }
+ if (!google::protobuf::python::InitProto2MessageModule(m)) {
+ Py_DECREF(m);
+ return INITFUNC_ERRORVAL;
+ }
+ // Adds the C++ API
+ if (PyObject* api = PyCapsule_New(
+ new ApiImplementation(), google::protobuf::python::PyProtoAPICapsuleName(),
+ [](PyObject* o) {
+ delete (ApiImplementation*)PyCapsule_GetPointer(
+ o, google::protobuf::python::PyProtoAPICapsuleName());
+ })) {
+ PyModule_AddObject(m, "proto_API", api);
+ } else {
+ return INITFUNC_ERRORVAL;
+ }
+
#if PY_MAJOR_VERSION >= 3
- return m;
+ return m;
#endif
}
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_composite_container.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_composite_container.cc
index f3d6fc3092..e3947c9ded 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_composite_container.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_composite_container.cc
@@ -31,22 +31,22 @@
// Author: anuraag@google.com (Anuraag Agrawal)
// Author: tibell@google.com (Johan Tibell)
-#include <google/protobuf/pyext/repeated_composite_container.h>
+#include <google/protobuf/pyext/repeated_composite_container.h>
#include <memory>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/dynamic_message.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/reflection.h>
-#include <google/protobuf/stubs/map_util.h>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/reflection.h>
+#include <google/protobuf/stubs/map_util.h>
#if PY_MAJOR_VERSION >= 3
#define PyInt_Check PyLong_Check
@@ -63,291 +63,291 @@ namespace repeated_composite_container {
// ---------------------------------------------------------------------
// len()
-static Py_ssize_t Length(PyObject* pself) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
+static Py_ssize_t Length(PyObject* pself) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
- Message* message = self->parent->message;
- return message->GetReflection()->FieldSize(*message,
- self->parent_field_descriptor);
+ Message* message = self->parent->message;
+ return message->GetReflection()->FieldSize(*message,
+ self->parent_field_descriptor);
}
// ---------------------------------------------------------------------
// add()
-PyObject* Add(RepeatedCompositeContainer* self, PyObject* args,
- PyObject* kwargs) {
- if (cmessage::AssureWritable(self->parent) == -1) return nullptr;
- Message* message = self->parent->message;
+PyObject* Add(RepeatedCompositeContainer* self, PyObject* args,
+ PyObject* kwargs) {
+ if (cmessage::AssureWritable(self->parent) == -1) return nullptr;
+ Message* message = self->parent->message;
Message* sub_message =
message->GetReflection()->AddMessage(
message,
self->parent_field_descriptor,
self->child_message_class->py_message_factory->message_factory);
- CMessage* cmsg = self->parent->BuildSubMessageFromPointer(
- self->parent_field_descriptor, sub_message, self->child_message_class);
+ CMessage* cmsg = self->parent->BuildSubMessageFromPointer(
+ self->parent_field_descriptor, sub_message, self->child_message_class);
if (cmessage::InitAttributes(cmsg, args, kwargs) < 0) {
- message->GetReflection()->RemoveLast(
- message, self->parent_field_descriptor);
+ message->GetReflection()->RemoveLast(
+ message, self->parent_field_descriptor);
Py_DECREF(cmsg);
- return nullptr;
+ return nullptr;
}
- return cmsg->AsPyObject();
-}
-
-static PyObject* AddMethod(PyObject* self, PyObject* args, PyObject* kwargs) {
- return Add(reinterpret_cast<RepeatedCompositeContainer*>(self), args, kwargs);
+ return cmsg->AsPyObject();
}
-// ---------------------------------------------------------------------
-// append()
-
-static PyObject* AddMessage(RepeatedCompositeContainer* self, PyObject* value) {
- cmessage::AssureWritable(self->parent);
- PyObject* py_cmsg;
- Message* message = self->parent->message;
- const Reflection* reflection = message->GetReflection();
- py_cmsg = Add(self, nullptr, nullptr);
- if (py_cmsg == nullptr) return nullptr;
- CMessage* cmsg = reinterpret_cast<CMessage*>(py_cmsg);
- if (ScopedPyObjectPtr(cmessage::MergeFrom(cmsg, value)) == nullptr) {
- reflection->RemoveLast(
- message, self->parent_field_descriptor);
- Py_DECREF(cmsg);
- return nullptr;
+static PyObject* AddMethod(PyObject* self, PyObject* args, PyObject* kwargs) {
+ return Add(reinterpret_cast<RepeatedCompositeContainer*>(self), args, kwargs);
+}
+
+// ---------------------------------------------------------------------
+// append()
+
+static PyObject* AddMessage(RepeatedCompositeContainer* self, PyObject* value) {
+ cmessage::AssureWritable(self->parent);
+ PyObject* py_cmsg;
+ Message* message = self->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ py_cmsg = Add(self, nullptr, nullptr);
+ if (py_cmsg == nullptr) return nullptr;
+ CMessage* cmsg = reinterpret_cast<CMessage*>(py_cmsg);
+ if (ScopedPyObjectPtr(cmessage::MergeFrom(cmsg, value)) == nullptr) {
+ reflection->RemoveLast(
+ message, self->parent_field_descriptor);
+ Py_DECREF(cmsg);
+ return nullptr;
}
return py_cmsg;
}
-static PyObject* AppendMethod(PyObject* pself, PyObject* value) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
- ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
- if (py_cmsg == nullptr) {
- return nullptr;
- }
-
- Py_RETURN_NONE;
-}
-
-// ---------------------------------------------------------------------
-// insert()
-static PyObject* Insert(PyObject* pself, PyObject* args) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
-
- Py_ssize_t index;
- PyObject* value;
- if (!PyArg_ParseTuple(args, "nO", &index, &value)) {
- return nullptr;
- }
-
- ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
- if (py_cmsg == nullptr) {
- return nullptr;
- }
-
- // Swap the element to right position.
- Message* message = self->parent->message;
- const Reflection* reflection = message->GetReflection();
- const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
- Py_ssize_t length = reflection->FieldSize(*message, field_descriptor) - 1;
- Py_ssize_t end_index = index;
- if (end_index < 0) end_index += length;
- if (end_index < 0) end_index = 0;
- for (Py_ssize_t i = length; i > end_index; i --) {
- reflection->SwapElements(message, field_descriptor, i, i - 1);
- }
-
- Py_RETURN_NONE;
+static PyObject* AppendMethod(PyObject* pself, PyObject* value) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+ ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
+ if (py_cmsg == nullptr) {
+ return nullptr;
+ }
+
+ Py_RETURN_NONE;
}
// ---------------------------------------------------------------------
+// insert()
+static PyObject* Insert(PyObject* pself, PyObject* args) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+
+ Py_ssize_t index;
+ PyObject* value;
+ if (!PyArg_ParseTuple(args, "nO", &index, &value)) {
+ return nullptr;
+ }
+
+ ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
+ if (py_cmsg == nullptr) {
+ return nullptr;
+ }
+
+ // Swap the element to right position.
+ Message* message = self->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
+ Py_ssize_t length = reflection->FieldSize(*message, field_descriptor) - 1;
+ Py_ssize_t end_index = index;
+ if (end_index < 0) end_index += length;
+ if (end_index < 0) end_index = 0;
+ for (Py_ssize_t i = length; i > end_index; i --) {
+ reflection->SwapElements(message, field_descriptor, i, i - 1);
+ }
+
+ Py_RETURN_NONE;
+}
+
+// ---------------------------------------------------------------------
// extend()
PyObject* Extend(RepeatedCompositeContainer* self, PyObject* value) {
cmessage::AssureWritable(self->parent);
ScopedPyObjectPtr iter(PyObject_GetIter(value));
- if (iter == nullptr) {
+ if (iter == nullptr) {
PyErr_SetString(PyExc_TypeError, "Value must be iterable");
- return nullptr;
+ return nullptr;
}
ScopedPyObjectPtr next;
- while ((next.reset(PyIter_Next(iter.get()))) != nullptr) {
- if (!PyObject_TypeCheck(next.get(), CMessage_Type)) {
+ while ((next.reset(PyIter_Next(iter.get()))) != nullptr) {
+ if (!PyObject_TypeCheck(next.get(), CMessage_Type)) {
PyErr_SetString(PyExc_TypeError, "Not a cmessage");
- return nullptr;
+ return nullptr;
}
- ScopedPyObjectPtr new_message(Add(self, nullptr, nullptr));
- if (new_message == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr new_message(Add(self, nullptr, nullptr));
+ if (new_message == nullptr) {
+ return nullptr;
}
CMessage* new_cmessage = reinterpret_cast<CMessage*>(new_message.get());
if (ScopedPyObjectPtr(cmessage::MergeFrom(new_cmessage, next.get())) ==
- nullptr) {
- return nullptr;
+ nullptr) {
+ return nullptr;
}
}
if (PyErr_Occurred()) {
- return nullptr;
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* ExtendMethod(PyObject* self, PyObject* value) {
- return Extend(reinterpret_cast<RepeatedCompositeContainer*>(self), value);
-}
-
+static PyObject* ExtendMethod(PyObject* self, PyObject* value) {
+ return Extend(reinterpret_cast<RepeatedCompositeContainer*>(self), value);
+}
+
PyObject* MergeFrom(RepeatedCompositeContainer* self, PyObject* other) {
return Extend(self, other);
}
-static PyObject* MergeFromMethod(PyObject* self, PyObject* other) {
- return MergeFrom(reinterpret_cast<RepeatedCompositeContainer*>(self), other);
+static PyObject* MergeFromMethod(PyObject* self, PyObject* other) {
+ return MergeFrom(reinterpret_cast<RepeatedCompositeContainer*>(self), other);
}
-// This function does not check the bounds.
-static PyObject* GetItem(RepeatedCompositeContainer* self, Py_ssize_t index,
- Py_ssize_t length = -1) {
- if (length == -1) {
- Message* message = self->parent->message;
- const Reflection* reflection = message->GetReflection();
- length = reflection->FieldSize(*message, self->parent_field_descriptor);
+// This function does not check the bounds.
+static PyObject* GetItem(RepeatedCompositeContainer* self, Py_ssize_t index,
+ Py_ssize_t length = -1) {
+ if (length == -1) {
+ Message* message = self->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ length = reflection->FieldSize(*message, self->parent_field_descriptor);
}
- if (index < 0 || index >= length) {
- PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
- return nullptr;
+ if (index < 0 || index >= length) {
+ PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
+ return nullptr;
}
- Message* message = self->parent->message;
- Message* sub_message = message->GetReflection()->MutableRepeatedMessage(
- message, self->parent_field_descriptor, index);
- return self->parent
- ->BuildSubMessageFromPointer(self->parent_field_descriptor, sub_message,
- self->child_message_class)
- ->AsPyObject();
-}
-
-PyObject* Subscript(RepeatedCompositeContainer* self, PyObject* item) {
- Message* message = self->parent->message;
- const Reflection* reflection = message->GetReflection();
- Py_ssize_t length =
- reflection->FieldSize(*message, self->parent_field_descriptor);
-
- if (PyIndex_Check(item)) {
- Py_ssize_t index;
- index = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (index == -1 && PyErr_Occurred()) return nullptr;
- if (index < 0) index += length;
- return GetItem(self, index, length);
- } else if (PySlice_Check(item)) {
- Py_ssize_t from, to, step, slicelength, cur, i;
- PyObject* result;
-
+ Message* message = self->parent->message;
+ Message* sub_message = message->GetReflection()->MutableRepeatedMessage(
+ message, self->parent_field_descriptor, index);
+ return self->parent
+ ->BuildSubMessageFromPointer(self->parent_field_descriptor, sub_message,
+ self->child_message_class)
+ ->AsPyObject();
+}
+
+PyObject* Subscript(RepeatedCompositeContainer* self, PyObject* item) {
+ Message* message = self->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ Py_ssize_t length =
+ reflection->FieldSize(*message, self->parent_field_descriptor);
+
+ if (PyIndex_Check(item)) {
+ Py_ssize_t index;
+ index = PyNumber_AsSsize_t(item, PyExc_IndexError);
+ if (index == -1 && PyErr_Occurred()) return nullptr;
+ if (index < 0) index += length;
+ return GetItem(self, index, length);
+ } else if (PySlice_Check(item)) {
+ Py_ssize_t from, to, step, slicelength, cur, i;
+ PyObject* result;
+
#if PY_MAJOR_VERSION >= 3
- if (PySlice_GetIndicesEx(item,
- length, &from, &to, &step, &slicelength) == -1) {
+ if (PySlice_GetIndicesEx(item,
+ length, &from, &to, &step, &slicelength) == -1) {
#else
- if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(item),
- length, &from, &to, &step, &slicelength) == -1) {
+ if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(item),
+ length, &from, &to, &step, &slicelength) == -1) {
#endif
- return nullptr;
- }
-
- if (slicelength <= 0) {
- return PyList_New(0);
- } else {
- result = PyList_New(slicelength);
- if (!result) return nullptr;
-
- for (cur = from, i = 0; i < slicelength; cur += step, i++) {
- PyList_SET_ITEM(result, i, GetItem(self, cur, length));
+ return nullptr;
+ }
+
+ if (slicelength <= 0) {
+ return PyList_New(0);
+ } else {
+ result = PyList_New(slicelength);
+ if (!result) return nullptr;
+
+ for (cur = from, i = 0; i < slicelength; cur += step, i++) {
+ PyList_SET_ITEM(result, i, GetItem(self, cur, length));
}
-
- return result;
+
+ return result;
}
- } else {
- PyErr_Format(PyExc_TypeError, "indices must be integers, not %.200s",
- item->ob_type->tp_name);
- return nullptr;
+ } else {
+ PyErr_Format(PyExc_TypeError, "indices must be integers, not %.200s",
+ item->ob_type->tp_name);
+ return nullptr;
}
-}
+}
-static PyObject* SubscriptMethod(PyObject* self, PyObject* slice) {
- return Subscript(reinterpret_cast<RepeatedCompositeContainer*>(self), slice);
+static PyObject* SubscriptMethod(PyObject* self, PyObject* slice) {
+ return Subscript(reinterpret_cast<RepeatedCompositeContainer*>(self), slice);
}
-int AssignSubscript(RepeatedCompositeContainer* self,
- PyObject* slice,
- PyObject* value) {
- if (value != nullptr) {
- PyErr_SetString(PyExc_TypeError, "does not support assignment");
- return -1;
+int AssignSubscript(RepeatedCompositeContainer* self,
+ PyObject* slice,
+ PyObject* value) {
+ if (value != nullptr) {
+ PyErr_SetString(PyExc_TypeError, "does not support assignment");
+ return -1;
}
-
- return cmessage::DeleteRepeatedField(self->parent,
- self->parent_field_descriptor, slice);
-}
-
-static int AssignSubscriptMethod(PyObject* self, PyObject* slice,
- PyObject* value) {
- return AssignSubscript(reinterpret_cast<RepeatedCompositeContainer*>(self),
- slice, value);
-}
-
-static PyObject* Remove(PyObject* pself, PyObject* value) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
- Py_ssize_t len = Length(reinterpret_cast<PyObject*>(self));
-
- for (Py_ssize_t i = 0; i < len; i++) {
- ScopedPyObjectPtr item(GetItem(self, i, len));
- if (item == nullptr) {
- return nullptr;
- }
- int result = PyObject_RichCompareBool(item.get(), value, Py_EQ);
- if (result < 0) {
- return nullptr;
- }
- if (result) {
- ScopedPyObjectPtr py_index(PyLong_FromSsize_t(i));
- if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
- return nullptr;
- }
- Py_RETURN_NONE;
- }
+
+ return cmessage::DeleteRepeatedField(self->parent,
+ self->parent_field_descriptor, slice);
+}
+
+static int AssignSubscriptMethod(PyObject* self, PyObject* slice,
+ PyObject* value) {
+ return AssignSubscript(reinterpret_cast<RepeatedCompositeContainer*>(self),
+ slice, value);
+}
+
+static PyObject* Remove(PyObject* pself, PyObject* value) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+ Py_ssize_t len = Length(reinterpret_cast<PyObject*>(self));
+
+ for (Py_ssize_t i = 0; i < len; i++) {
+ ScopedPyObjectPtr item(GetItem(self, i, len));
+ if (item == nullptr) {
+ return nullptr;
+ }
+ int result = PyObject_RichCompareBool(item.get(), value, Py_EQ);
+ if (result < 0) {
+ return nullptr;
+ }
+ if (result) {
+ ScopedPyObjectPtr py_index(PyLong_FromSsize_t(i));
+ if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
+ return nullptr;
+ }
+ Py_RETURN_NONE;
+ }
}
- PyErr_SetString(PyExc_ValueError, "Item to delete not in list");
- return nullptr;
+ PyErr_SetString(PyExc_ValueError, "Item to delete not in list");
+ return nullptr;
}
-static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
-
+static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+
if (!PyObject_TypeCheck(other, &RepeatedCompositeContainer_Type)) {
PyErr_SetString(PyExc_TypeError,
"Can only compare repeated composite fields "
"against other repeated composite fields.");
- return nullptr;
+ return nullptr;
}
if (opid == Py_EQ || opid == Py_NE) {
// TODO(anuraag): Don't make new lists just for this...
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
}
ScopedPyObjectPtr list(Subscript(self, full_slice.get()));
- if (list == nullptr) {
- return nullptr;
+ if (list == nullptr) {
+ return nullptr;
}
ScopedPyObjectPtr other_list(
Subscript(reinterpret_cast<RepeatedCompositeContainer*>(other),
full_slice.get()));
- if (other_list == nullptr) {
- return nullptr;
+ if (other_list == nullptr) {
+ return nullptr;
}
return PyObject_RichCompare(list.get(), other_list.get(), opid);
} else {
@@ -356,15 +356,15 @@ static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
}
}
-static PyObject* ToStr(PyObject* pself) {
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
+static PyObject* ToStr(PyObject* pself) {
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
}
- ScopedPyObjectPtr list(Subscript(
- reinterpret_cast<RepeatedCompositeContainer*>(pself), full_slice.get()));
- if (list == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr list(Subscript(
+ reinterpret_cast<RepeatedCompositeContainer*>(pself), full_slice.get()));
+ if (list == nullptr) {
+ return nullptr;
}
return PyObject_Repr(list.get());
}
@@ -372,26 +372,26 @@ static PyObject* ToStr(PyObject* pself) {
// ---------------------------------------------------------------------
// sort()
-static void ReorderAttached(RepeatedCompositeContainer* self,
- PyObject* child_list) {
- Message* message = self->parent->message;
+static void ReorderAttached(RepeatedCompositeContainer* self,
+ PyObject* child_list) {
+ Message* message = self->parent->message;
const Reflection* reflection = message->GetReflection();
const FieldDescriptor* descriptor = self->parent_field_descriptor;
- const Py_ssize_t length = Length(reinterpret_cast<PyObject*>(self));
+ const Py_ssize_t length = Length(reinterpret_cast<PyObject*>(self));
- // We need to rearrange things to match python's sort order. Because there
- // was already an O(n*log(n)) step in python and a bunch of reflection, we
- // expect an O(n**2) step in C++ won't hurt too much.
+ // We need to rearrange things to match python's sort order. Because there
+ // was already an O(n*log(n)) step in python and a bunch of reflection, we
+ // expect an O(n**2) step in C++ won't hurt too much.
for (Py_ssize_t i = 0; i < length; ++i) {
- Message* child_message =
- reinterpret_cast<CMessage*>(PyList_GET_ITEM(child_list, i))->message;
- for (Py_ssize_t j = i; j < length; ++j) {
- if (child_message ==
- &reflection->GetRepeatedMessage(*message, descriptor, j)) {
- reflection->SwapElements(message, descriptor, i, j);
- break;
- }
- }
+ Message* child_message =
+ reinterpret_cast<CMessage*>(PyList_GET_ITEM(child_list, i))->message;
+ for (Py_ssize_t j = i; j < length; ++j) {
+ if (child_message ==
+ &reflection->GetRepeatedMessage(*message, descriptor, j)) {
+ reflection->SwapElements(message, descriptor, i, j);
+ break;
+ }
+ }
}
}
@@ -400,28 +400,28 @@ static void ReorderAttached(RepeatedCompositeContainer* self,
static int SortPythonMessages(RepeatedCompositeContainer* self,
PyObject* args,
PyObject* kwds) {
- ScopedPyObjectPtr child_list(
- PySequence_List(reinterpret_cast<PyObject*>(self)));
- if (child_list == nullptr) {
+ ScopedPyObjectPtr child_list(
+ PySequence_List(reinterpret_cast<PyObject*>(self)));
+ if (child_list == nullptr) {
return -1;
- }
- ScopedPyObjectPtr m(PyObject_GetAttrString(child_list.get(), "sort"));
- if (m == nullptr) return -1;
- if (ScopedPyObjectPtr(PyObject_Call(m.get(), args, kwds)) == nullptr)
+ }
+ ScopedPyObjectPtr m(PyObject_GetAttrString(child_list.get(), "sort"));
+ if (m == nullptr) return -1;
+ if (ScopedPyObjectPtr(PyObject_Call(m.get(), args, kwds)) == nullptr)
return -1;
- ReorderAttached(self, child_list.get());
+ ReorderAttached(self, child_list.get());
return 0;
}
-static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
-
+static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+
// Support the old sort_function argument for backwards
// compatibility.
- if (kwds != nullptr) {
+ if (kwds != nullptr) {
PyObject* sort_func = PyDict_GetItemString(kwds, "sort_function");
- if (sort_func != nullptr) {
+ if (sort_func != nullptr) {
// Must set before deleting as sort_func is a borrowed reference
// and kwds might be the only thing keeping it alive.
PyDict_SetItemString(kwds, "cmp", sort_func);
@@ -430,181 +430,181 @@ static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
}
if (SortPythonMessages(self, args, kwds) < 0) {
- return nullptr;
+ return nullptr;
}
Py_RETURN_NONE;
}
// ---------------------------------------------------------------------
-// reverse()
-
-// Returns 0 if successful; returns -1 and sets an exception if
-// unsuccessful.
-static int ReversePythonMessages(RepeatedCompositeContainer* self) {
- ScopedPyObjectPtr child_list(
- PySequence_List(reinterpret_cast<PyObject*>(self)));
- if (child_list == nullptr) {
- return -1;
+// reverse()
+
+// Returns 0 if successful; returns -1 and sets an exception if
+// unsuccessful.
+static int ReversePythonMessages(RepeatedCompositeContainer* self) {
+ ScopedPyObjectPtr child_list(
+ PySequence_List(reinterpret_cast<PyObject*>(self)));
+ if (child_list == nullptr) {
+ return -1;
}
- if (ScopedPyObjectPtr(
- PyObject_CallMethod(child_list.get(), "reverse", nullptr)) == nullptr)
- return -1;
- ReorderAttached(self, child_list.get());
- return 0;
+ if (ScopedPyObjectPtr(
+ PyObject_CallMethod(child_list.get(), "reverse", nullptr)) == nullptr)
+ return -1;
+ ReorderAttached(self, child_list.get());
+ return 0;
}
-static PyObject* Reverse(PyObject* pself) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
-
- if (ReversePythonMessages(self) < 0) {
- return nullptr;
+static PyObject* Reverse(PyObject* pself) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+
+ if (ReversePythonMessages(self) < 0) {
+ return nullptr;
}
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-// ---------------------------------------------------------------------
+// ---------------------------------------------------------------------
-static PyObject* Item(PyObject* pself, Py_ssize_t index) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
- return GetItem(self, index);
+static PyObject* Item(PyObject* pself, Py_ssize_t index) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+ return GetItem(self, index);
}
-static PyObject* Pop(PyObject* pself, PyObject* args) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
+static PyObject* Pop(PyObject* pself, PyObject* args) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
- Py_ssize_t index = -1;
- if (!PyArg_ParseTuple(args, "|n", &index)) {
- return nullptr;
+ Py_ssize_t index = -1;
+ if (!PyArg_ParseTuple(args, "|n", &index)) {
+ return nullptr;
}
- Py_ssize_t length = Length(pself);
- if (index < 0) index += length;
- PyObject* item = GetItem(self, index, length);
- if (item == nullptr) {
- return nullptr;
+ Py_ssize_t length = Length(pself);
+ if (index < 0) index += length;
+ PyObject* item = GetItem(self, index, length);
+ if (item == nullptr) {
+ return nullptr;
}
- ScopedPyObjectPtr py_index(PyLong_FromSsize_t(index));
- if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
- return nullptr;
- }
- return item;
+ ScopedPyObjectPtr py_index(PyLong_FromSsize_t(index));
+ if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
+ return nullptr;
+ }
+ return item;
}
-PyObject* DeepCopy(PyObject* pself, PyObject* arg) {
- return reinterpret_cast<RepeatedCompositeContainer*>(pself)->DeepCopy();
+PyObject* DeepCopy(PyObject* pself, PyObject* arg) {
+ return reinterpret_cast<RepeatedCompositeContainer*>(pself)->DeepCopy();
}
// The private constructor of RepeatedCompositeContainer objects.
-RepeatedCompositeContainer *NewContainer(
+RepeatedCompositeContainer *NewContainer(
CMessage* parent,
const FieldDescriptor* parent_field_descriptor,
- CMessageClass* child_message_class) {
+ CMessageClass* child_message_class) {
if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
- return nullptr;
+ return nullptr;
}
RepeatedCompositeContainer* self =
reinterpret_cast<RepeatedCompositeContainer*>(
PyType_GenericAlloc(&RepeatedCompositeContainer_Type, 0));
- if (self == nullptr) {
- return nullptr;
+ if (self == nullptr) {
+ return nullptr;
}
- Py_INCREF(parent);
+ Py_INCREF(parent);
self->parent = parent;
self->parent_field_descriptor = parent_field_descriptor;
- Py_INCREF(child_message_class);
- self->child_message_class = child_message_class;
- return self;
+ Py_INCREF(child_message_class);
+ self->child_message_class = child_message_class;
+ return self;
}
-static void Dealloc(PyObject* pself) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
- self->RemoveFromParentCache();
+static void Dealloc(PyObject* pself) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+ self->RemoveFromParentCache();
Py_CLEAR(self->child_message_class);
- Py_TYPE(self)->tp_free(pself);
+ Py_TYPE(self)->tp_free(pself);
}
static PySequenceMethods SqMethods = {
- Length, /* sq_length */
- nullptr, /* sq_concat */
- nullptr, /* sq_repeat */
- Item /* sq_item */
+ Length, /* sq_length */
+ nullptr, /* sq_concat */
+ nullptr, /* sq_repeat */
+ Item /* sq_item */
};
static PyMappingMethods MpMethods = {
- Length, /* mp_length */
- SubscriptMethod, /* mp_subscript */
- AssignSubscriptMethod, /* mp_ass_subscript */
+ Length, /* mp_length */
+ SubscriptMethod, /* mp_subscript */
+ AssignSubscriptMethod, /* mp_ass_subscript */
};
static PyMethodDef Methods[] = {
- {"__deepcopy__", DeepCopy, METH_VARARGS, "Makes a deep copy of the class."},
- {"add", reinterpret_cast<PyCFunction>(AddMethod),
- METH_VARARGS | METH_KEYWORDS, "Adds an object to the repeated container."},
- {"append", AppendMethod, METH_O,
- "Appends a message to the end of the repeated container."},
- {"insert", Insert, METH_VARARGS,
- "Inserts a message before the specified index."},
- {"extend", ExtendMethod, METH_O, "Adds objects to the repeated container."},
- {"pop", Pop, METH_VARARGS,
- "Removes an object from the repeated container and returns it."},
- {"remove", Remove, METH_O,
- "Removes an object from the repeated container."},
- {"sort", reinterpret_cast<PyCFunction>(Sort), METH_VARARGS | METH_KEYWORDS,
- "Sorts the repeated container."},
- {"reverse", reinterpret_cast<PyCFunction>(Reverse), METH_NOARGS,
- "Reverses elements order of the repeated container."},
- {"MergeFrom", MergeFromMethod, METH_O,
- "Adds objects to the repeated container."},
- {nullptr, nullptr}};
+ {"__deepcopy__", DeepCopy, METH_VARARGS, "Makes a deep copy of the class."},
+ {"add", reinterpret_cast<PyCFunction>(AddMethod),
+ METH_VARARGS | METH_KEYWORDS, "Adds an object to the repeated container."},
+ {"append", AppendMethod, METH_O,
+ "Appends a message to the end of the repeated container."},
+ {"insert", Insert, METH_VARARGS,
+ "Inserts a message before the specified index."},
+ {"extend", ExtendMethod, METH_O, "Adds objects to the repeated container."},
+ {"pop", Pop, METH_VARARGS,
+ "Removes an object from the repeated container and returns it."},
+ {"remove", Remove, METH_O,
+ "Removes an object from the repeated container."},
+ {"sort", reinterpret_cast<PyCFunction>(Sort), METH_VARARGS | METH_KEYWORDS,
+ "Sorts the repeated container."},
+ {"reverse", reinterpret_cast<PyCFunction>(Reverse), METH_NOARGS,
+ "Reverses elements order of the repeated container."},
+ {"MergeFrom", MergeFromMethod, METH_O,
+ "Adds objects to the repeated container."},
+ {nullptr, nullptr}};
} // namespace repeated_composite_container
PyTypeObject RepeatedCompositeContainer_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".RepeatedCompositeContainer", // tp_name
- sizeof(RepeatedCompositeContainer), // tp_basicsize
- 0, // tp_itemsize
- repeated_composite_container::Dealloc, // tp_dealloc
-#if PY_VERSION_HEX >= 0x03080000
- 0, // tp_vectorcall_offset
-#else
- nullptr, // tp_print
-#endif
- nullptr, // tp_getattr
- nullptr, // tp_setattr
- nullptr, // tp_compare
- repeated_composite_container::ToStr, // tp_repr
- nullptr, // tp_as_number
- &repeated_composite_container::SqMethods, // tp_as_sequence
- &repeated_composite_container::MpMethods, // tp_as_mapping
- PyObject_HashNotImplemented, // tp_hash
- nullptr, // tp_call
- nullptr, // tp_str
- nullptr, // tp_getattro
- nullptr, // tp_setattro
- nullptr, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "A Repeated scalar container", // tp_doc
- nullptr, // tp_traverse
- nullptr, // tp_clear
- repeated_composite_container::RichCompare, // tp_richcompare
- 0, // tp_weaklistoffset
- nullptr, // tp_iter
- nullptr, // tp_iternext
- repeated_composite_container::Methods, // tp_methods
- nullptr, // tp_members
- nullptr, // tp_getset
- nullptr, // tp_base
- nullptr, // tp_dict
- nullptr, // tp_descr_get
- nullptr, // tp_descr_set
- 0, // tp_dictoffset
- nullptr, // tp_init
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".RepeatedCompositeContainer", // tp_name
+ sizeof(RepeatedCompositeContainer), // tp_basicsize
+ 0, // tp_itemsize
+ repeated_composite_container::Dealloc, // tp_dealloc
+#if PY_VERSION_HEX >= 0x03080000
+ 0, // tp_vectorcall_offset
+#else
+ nullptr, // tp_print
+#endif
+ nullptr, // tp_getattr
+ nullptr, // tp_setattr
+ nullptr, // tp_compare
+ repeated_composite_container::ToStr, // tp_repr
+ nullptr, // tp_as_number
+ &repeated_composite_container::SqMethods, // tp_as_sequence
+ &repeated_composite_container::MpMethods, // tp_as_mapping
+ PyObject_HashNotImplemented, // tp_hash
+ nullptr, // tp_call
+ nullptr, // tp_str
+ nullptr, // tp_getattro
+ nullptr, // tp_setattro
+ nullptr, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "A Repeated scalar container", // tp_doc
+ nullptr, // tp_traverse
+ nullptr, // tp_clear
+ repeated_composite_container::RichCompare, // tp_richcompare
+ 0, // tp_weaklistoffset
+ nullptr, // tp_iter
+ nullptr, // tp_iternext
+ repeated_composite_container::Methods, // tp_methods
+ nullptr, // tp_members
+ nullptr, // tp_getset
+ nullptr, // tp_base
+ nullptr, // tp_dict
+ nullptr, // tp_descr_get
+ nullptr, // tp_descr_set
+ 0, // tp_dictoffset
+ nullptr, // tp_init
};
} // namespace python
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_composite_container.h b/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_composite_container.h
index e241827ef5..94c4aae60a 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_composite_container.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_composite_container.h
@@ -37,11 +37,11 @@
#include <Python.h>
#include <memory>
-#include <string>
+#include <string>
#include <vector>
-#include <google/protobuf/pyext/message.h>
-
+#include <google/protobuf/pyext/message.h>
+
namespace google {
namespace protobuf {
@@ -52,9 +52,9 @@ namespace python {
struct CMessageClass;
-// A RepeatedCompositeContainer always has a parent message.
-// The parent message also caches reference to items of the container.
-typedef struct RepeatedCompositeContainer : public ContainerBase {
+// A RepeatedCompositeContainer always has a parent message.
+// The parent message also caches reference to items of the container.
+typedef struct RepeatedCompositeContainer : public ContainerBase {
// The type used to create new child messages.
CMessageClass* child_message_class;
} RepeatedCompositeContainer;
@@ -65,7 +65,7 @@ namespace repeated_composite_container {
// Builds a RepeatedCompositeContainer object, from a parent message and a
// field descriptor.
-RepeatedCompositeContainer* NewContainer(
+RepeatedCompositeContainer* NewContainer(
CMessage* parent,
const FieldDescriptor* parent_field_descriptor,
CMessageClass *child_message_class);
@@ -107,6 +107,6 @@ int AssignSubscript(RepeatedCompositeContainer* self,
} // namespace repeated_composite_container
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_COMPOSITE_CONTAINER_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_scalar_container.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_scalar_container.cc
index 3a41a58adb..e364be76b0 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_scalar_container.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_scalar_container.cc
@@ -31,30 +31,30 @@
// Author: anuraag@google.com (Anuraag Agrawal)
// Author: tibell@google.com (Johan Tibell)
-#include <google/protobuf/pyext/repeated_scalar_container.h>
+#include <google/protobuf/pyext/repeated_scalar_container.h>
-#include <cstdint>
+#include <cstdint>
#include <memory>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/dynamic_message.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#if PY_MAJOR_VERSION >= 3
-#define PyInt_FromLong PyLong_FromLong
-#if PY_VERSION_HEX < 0x03030000
-#error "Python 3.0 - 3.2 are not supported."
-#else
-#define PyString_AsString(ob) \
- (PyUnicode_Check(ob) ? PyUnicode_AsUTF8(ob) : PyBytes_AsString(ob))
-#endif
+#define PyInt_FromLong PyLong_FromLong
+#if PY_VERSION_HEX < 0x03030000
+#error "Python 3.0 - 3.2 are not supported."
+#else
+#define PyString_AsString(ob) \
+ (PyUnicode_Check(ob) ? PyUnicode_AsUTF8(ob) : PyBytes_AsString(ob))
#endif
+#endif
namespace google {
namespace protobuf {
@@ -62,33 +62,33 @@ namespace python {
namespace repeated_scalar_container {
-static int InternalAssignRepeatedField(RepeatedScalarContainer* self,
- PyObject* list) {
- Message* message = self->parent->message;
- message->GetReflection()->ClearField(message, self->parent_field_descriptor);
+static int InternalAssignRepeatedField(RepeatedScalarContainer* self,
+ PyObject* list) {
+ Message* message = self->parent->message;
+ message->GetReflection()->ClearField(message, self->parent_field_descriptor);
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(list); ++i) {
PyObject* value = PyList_GET_ITEM(list, i);
- if (ScopedPyObjectPtr(Append(self, value)) == nullptr) {
+ if (ScopedPyObjectPtr(Append(self, value)) == nullptr) {
return -1;
}
}
return 0;
}
-static Py_ssize_t Len(PyObject* pself) {
- RepeatedScalarContainer* self =
- reinterpret_cast<RepeatedScalarContainer*>(pself);
- Message* message = self->parent->message;
+static Py_ssize_t Len(PyObject* pself) {
+ RepeatedScalarContainer* self =
+ reinterpret_cast<RepeatedScalarContainer*>(pself);
+ Message* message = self->parent->message;
return message->GetReflection()->FieldSize(*message,
self->parent_field_descriptor);
}
-static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
- RepeatedScalarContainer* self =
- reinterpret_cast<RepeatedScalarContainer*>(pself);
-
+static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
+ RepeatedScalarContainer* self =
+ reinterpret_cast<RepeatedScalarContainer*>(pself);
+
cmessage::AssureWritable(self->parent);
- Message* message = self->parent->message;
+ Message* message = self->parent->message;
const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
const Reflection* reflection = message->GetReflection();
@@ -97,15 +97,15 @@ static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
index = field_size + index;
}
if (index < 0 || index >= field_size) {
- PyErr_Format(PyExc_IndexError, "list assignment index (%d) out of range",
+ PyErr_Format(PyExc_IndexError, "list assignment index (%d) out of range",
static_cast<int>(index));
return -1;
}
- if (arg == nullptr) {
+ if (arg == nullptr) {
ScopedPyObjectPtr py_index(PyLong_FromLong(index));
- return cmessage::DeleteRepeatedField(self->parent, field_descriptor,
- py_index.get());
+ return cmessage::DeleteRepeatedField(self->parent, field_descriptor,
+ py_index.get());
}
if (PySequence_Check(arg) && !(PyBytes_Check(arg) || PyUnicode_Check(arg))) {
@@ -150,8 +150,8 @@ static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- if (!CheckAndSetString(arg, message, field_descriptor, reflection, false,
- index)) {
+ if (!CheckAndSetString(arg, message, field_descriptor, reflection, false,
+ index)) {
return -1;
}
break;
@@ -165,12 +165,12 @@ static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();
const EnumValueDescriptor* enum_value =
enum_descriptor->FindValueByNumber(value);
- if (enum_value != nullptr) {
+ if (enum_value != nullptr) {
reflection->SetRepeatedEnum(message, field_descriptor, index,
enum_value);
} else {
ScopedPyObjectPtr s(PyObject_Str(arg));
- if (s != nullptr) {
+ if (s != nullptr) {
PyErr_Format(PyExc_ValueError, "Unknown enum value: %s",
PyString_AsString(s.get()));
}
@@ -180,19 +180,19 @@ static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
break;
}
default:
- PyErr_Format(PyExc_SystemError,
- "Adding value to a field of unknown type %d",
- field_descriptor->cpp_type());
+ PyErr_Format(PyExc_SystemError,
+ "Adding value to a field of unknown type %d",
+ field_descriptor->cpp_type());
return -1;
}
return 0;
}
-static PyObject* Item(PyObject* pself, Py_ssize_t index) {
- RepeatedScalarContainer* self =
- reinterpret_cast<RepeatedScalarContainer*>(pself);
-
- Message* message = self->parent->message;
+static PyObject* Item(PyObject* pself, Py_ssize_t index) {
+ RepeatedScalarContainer* self =
+ reinterpret_cast<RepeatedScalarContainer*>(pself);
+
+ Message* message = self->parent->message;
const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
const Reflection* reflection = message->GetReflection();
@@ -201,78 +201,78 @@ static PyObject* Item(PyObject* pself, Py_ssize_t index) {
index = field_size + index;
}
if (index < 0 || index >= field_size) {
- PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
- return nullptr;
+ PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
+ return nullptr;
}
- PyObject* result = nullptr;
+ PyObject* result = nullptr;
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
- int32_t value =
- reflection->GetRepeatedInt32(*message, field_descriptor, index);
+ int32_t value =
+ reflection->GetRepeatedInt32(*message, field_descriptor, index);
result = PyInt_FromLong(value);
break;
}
case FieldDescriptor::CPPTYPE_INT64: {
- int64_t value =
- reflection->GetRepeatedInt64(*message, field_descriptor, index);
+ int64_t value =
+ reflection->GetRepeatedInt64(*message, field_descriptor, index);
result = PyLong_FromLongLong(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT32: {
- uint32_t value =
- reflection->GetRepeatedUInt32(*message, field_descriptor, index);
+ uint32_t value =
+ reflection->GetRepeatedUInt32(*message, field_descriptor, index);
result = PyLong_FromLongLong(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT64: {
- uint64_t value =
- reflection->GetRepeatedUInt64(*message, field_descriptor, index);
+ uint64_t value =
+ reflection->GetRepeatedUInt64(*message, field_descriptor, index);
result = PyLong_FromUnsignedLongLong(value);
break;
}
case FieldDescriptor::CPPTYPE_FLOAT: {
- float value =
- reflection->GetRepeatedFloat(*message, field_descriptor, index);
+ float value =
+ reflection->GetRepeatedFloat(*message, field_descriptor, index);
result = PyFloat_FromDouble(value);
break;
}
case FieldDescriptor::CPPTYPE_DOUBLE: {
- double value =
- reflection->GetRepeatedDouble(*message, field_descriptor, index);
+ double value =
+ reflection->GetRepeatedDouble(*message, field_descriptor, index);
result = PyFloat_FromDouble(value);
break;
}
case FieldDescriptor::CPPTYPE_BOOL: {
- bool value =
- reflection->GetRepeatedBool(*message, field_descriptor, index);
+ bool value =
+ reflection->GetRepeatedBool(*message, field_descriptor, index);
result = PyBool_FromLong(value ? 1 : 0);
break;
}
case FieldDescriptor::CPPTYPE_ENUM: {
const EnumValueDescriptor* enum_value =
- message->GetReflection()->GetRepeatedEnum(*message, field_descriptor,
- index);
+ message->GetReflection()->GetRepeatedEnum(*message, field_descriptor,
+ index);
result = PyInt_FromLong(enum_value->number());
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- TProtoStringType scratch;
- const TProtoStringType& value = reflection->GetRepeatedStringReference(
- *message, field_descriptor, index, &scratch);
+ TProtoStringType scratch;
+ const TProtoStringType& value = reflection->GetRepeatedStringReference(
+ *message, field_descriptor, index, &scratch);
result = ToStringObject(field_descriptor, value);
break;
}
default:
- PyErr_Format(PyExc_SystemError,
- "Getting value from a repeated field of unknown type %d",
- field_descriptor->cpp_type());
+ PyErr_Format(PyExc_SystemError,
+ "Getting value from a repeated field of unknown type %d",
+ field_descriptor->cpp_type());
}
return result;
}
-static PyObject* Subscript(PyObject* pself, PyObject* slice) {
+static PyObject* Subscript(PyObject* pself, PyObject* slice) {
Py_ssize_t from;
Py_ssize_t to;
Py_ssize_t step;
@@ -284,32 +284,32 @@ static PyObject* Subscript(PyObject* pself, PyObject* slice) {
from = to = PyInt_AsLong(slice);
} else // NOLINT
#endif
- if (PyLong_Check(slice)) {
+ if (PyLong_Check(slice)) {
from = to = PyLong_AsLong(slice);
} else if (PySlice_Check(slice)) {
- length = Len(pself);
+ length = Len(pself);
#if PY_MAJOR_VERSION >= 3
- if (PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slicelength) ==
- -1) {
+ if (PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slicelength) ==
+ -1) {
#else
- if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), length,
- &from, &to, &step, &slicelength) == -1) {
+ if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), length,
+ &from, &to, &step, &slicelength) == -1) {
#endif
- return nullptr;
+ return nullptr;
}
return_list = true;
} else {
PyErr_SetString(PyExc_TypeError, "list indices must be integers");
- return nullptr;
+ return nullptr;
}
if (!return_list) {
- return Item(pself, from);
+ return Item(pself, from);
}
PyObject* list = PyList_New(0);
- if (list == nullptr) {
- return nullptr;
+ if (list == nullptr) {
+ return nullptr;
}
if (from <= to) {
if (step < 0) {
@@ -319,7 +319,7 @@ static PyObject* Subscript(PyObject* pself, PyObject* slice) {
if (index < 0 || index >= length) {
break;
}
- ScopedPyObjectPtr s(Item(pself, index));
+ ScopedPyObjectPtr s(Item(pself, index));
PyList_Append(list, s.get());
}
} else {
@@ -330,7 +330,7 @@ static PyObject* Subscript(PyObject* pself, PyObject* slice) {
if (index < 0 || index >= length) {
break;
}
- ScopedPyObjectPtr s(Item(pself, index));
+ ScopedPyObjectPtr s(Item(pself, index));
PyList_Append(list, s.get());
}
}
@@ -339,92 +339,92 @@ static PyObject* Subscript(PyObject* pself, PyObject* slice) {
PyObject* Append(RepeatedScalarContainer* self, PyObject* item) {
cmessage::AssureWritable(self->parent);
- Message* message = self->parent->message;
+ Message* message = self->parent->message;
const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
const Reflection* reflection = message->GetReflection();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
- GOOGLE_CHECK_GET_INT32(item, value, nullptr);
+ GOOGLE_CHECK_GET_INT32(item, value, nullptr);
reflection->AddInt32(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_INT64: {
- GOOGLE_CHECK_GET_INT64(item, value, nullptr);
+ GOOGLE_CHECK_GET_INT64(item, value, nullptr);
reflection->AddInt64(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_UINT32: {
- GOOGLE_CHECK_GET_UINT32(item, value, nullptr);
+ GOOGLE_CHECK_GET_UINT32(item, value, nullptr);
reflection->AddUInt32(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_UINT64: {
- GOOGLE_CHECK_GET_UINT64(item, value, nullptr);
+ GOOGLE_CHECK_GET_UINT64(item, value, nullptr);
reflection->AddUInt64(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_FLOAT: {
- GOOGLE_CHECK_GET_FLOAT(item, value, nullptr);
+ GOOGLE_CHECK_GET_FLOAT(item, value, nullptr);
reflection->AddFloat(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_DOUBLE: {
- GOOGLE_CHECK_GET_DOUBLE(item, value, nullptr);
+ GOOGLE_CHECK_GET_DOUBLE(item, value, nullptr);
reflection->AddDouble(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_BOOL: {
- GOOGLE_CHECK_GET_BOOL(item, value, nullptr);
+ GOOGLE_CHECK_GET_BOOL(item, value, nullptr);
reflection->AddBool(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- if (!CheckAndSetString(item, message, field_descriptor, reflection, true,
- -1)) {
- return nullptr;
+ if (!CheckAndSetString(item, message, field_descriptor, reflection, true,
+ -1)) {
+ return nullptr;
}
break;
}
case FieldDescriptor::CPPTYPE_ENUM: {
- GOOGLE_CHECK_GET_INT32(item, value, nullptr);
+ GOOGLE_CHECK_GET_INT32(item, value, nullptr);
if (reflection->SupportsUnknownEnumValues()) {
reflection->AddEnumValue(message, field_descriptor, value);
} else {
const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();
const EnumValueDescriptor* enum_value =
enum_descriptor->FindValueByNumber(value);
- if (enum_value != nullptr) {
+ if (enum_value != nullptr) {
reflection->AddEnum(message, field_descriptor, enum_value);
} else {
ScopedPyObjectPtr s(PyObject_Str(item));
- if (s != nullptr) {
+ if (s != nullptr) {
PyErr_Format(PyExc_ValueError, "Unknown enum value: %s",
PyString_AsString(s.get()));
}
- return nullptr;
+ return nullptr;
}
}
break;
}
default:
- PyErr_Format(PyExc_SystemError,
- "Adding value to a field of unknown type %d",
- field_descriptor->cpp_type());
- return nullptr;
+ PyErr_Format(PyExc_SystemError,
+ "Adding value to a field of unknown type %d",
+ field_descriptor->cpp_type());
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* AppendMethod(PyObject* self, PyObject* item) {
- return Append(reinterpret_cast<RepeatedScalarContainer*>(self), item);
-}
-
-static int AssSubscript(PyObject* pself, PyObject* slice, PyObject* value) {
- RepeatedScalarContainer* self =
- reinterpret_cast<RepeatedScalarContainer*>(pself);
-
+static PyObject* AppendMethod(PyObject* self, PyObject* item) {
+ return Append(reinterpret_cast<RepeatedScalarContainer*>(self), item);
+}
+
+static int AssSubscript(PyObject* pself, PyObject* slice, PyObject* value) {
+ RepeatedScalarContainer* self =
+ reinterpret_cast<RepeatedScalarContainer*>(pself);
+
Py_ssize_t from;
Py_ssize_t to;
Py_ssize_t step;
@@ -433,25 +433,25 @@ static int AssSubscript(PyObject* pself, PyObject* slice, PyObject* value) {
bool create_list = false;
cmessage::AssureWritable(self->parent);
- Message* message = self->parent->message;
- const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
+ Message* message = self->parent->message;
+ const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
#if PY_MAJOR_VERSION < 3
if (PyInt_Check(slice)) {
from = to = PyInt_AsLong(slice);
- } else // NOLINT
+ } else // NOLINT
#endif
- if (PyLong_Check(slice)) {
+ if (PyLong_Check(slice)) {
from = to = PyLong_AsLong(slice);
} else if (PySlice_Check(slice)) {
const Reflection* reflection = message->GetReflection();
length = reflection->FieldSize(*message, field_descriptor);
#if PY_MAJOR_VERSION >= 3
- if (PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slicelength) ==
- -1) {
+ if (PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slicelength) ==
+ -1) {
#else
- if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), length,
- &from, &to, &step, &slicelength) == -1) {
+ if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), length,
+ &from, &to, &step, &slicelength) == -1) {
#endif
return -1;
}
@@ -461,20 +461,20 @@ static int AssSubscript(PyObject* pself, PyObject* slice, PyObject* value) {
return -1;
}
- if (value == nullptr) {
- return cmessage::DeleteRepeatedField(self->parent, field_descriptor, slice);
+ if (value == nullptr) {
+ return cmessage::DeleteRepeatedField(self->parent, field_descriptor, slice);
}
if (!create_list) {
- return AssignItem(pself, from, value);
+ return AssignItem(pself, from, value);
}
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
return -1;
}
- ScopedPyObjectPtr new_list(Subscript(pself, full_slice.get()));
- if (new_list == nullptr) {
+ ScopedPyObjectPtr new_list(Subscript(pself, full_slice.get()));
+ if (new_list == nullptr) {
return -1;
}
if (PySequence_SetSlice(new_list.get(), from, to, value) < 0) {
@@ -491,52 +491,52 @@ PyObject* Extend(RepeatedScalarContainer* self, PyObject* value) {
if (value == Py_None) {
Py_RETURN_NONE;
}
- if ((Py_TYPE(value)->tp_as_sequence == nullptr) && PyObject_Not(value)) {
+ if ((Py_TYPE(value)->tp_as_sequence == nullptr) && PyObject_Not(value)) {
Py_RETURN_NONE;
}
ScopedPyObjectPtr iter(PyObject_GetIter(value));
- if (iter == nullptr) {
+ if (iter == nullptr) {
PyErr_SetString(PyExc_TypeError, "Value must be iterable");
- return nullptr;
+ return nullptr;
}
ScopedPyObjectPtr next;
- while ((next.reset(PyIter_Next(iter.get()))) != nullptr) {
- if (ScopedPyObjectPtr(Append(self, next.get())) == nullptr) {
- return nullptr;
+ while ((next.reset(PyIter_Next(iter.get()))) != nullptr) {
+ if (ScopedPyObjectPtr(Append(self, next.get())) == nullptr) {
+ return nullptr;
}
}
if (PyErr_Occurred()) {
- return nullptr;
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* Insert(PyObject* pself, PyObject* args) {
- RepeatedScalarContainer* self =
- reinterpret_cast<RepeatedScalarContainer*>(pself);
-
+static PyObject* Insert(PyObject* pself, PyObject* args) {
+ RepeatedScalarContainer* self =
+ reinterpret_cast<RepeatedScalarContainer*>(pself);
+
Py_ssize_t index;
PyObject* value;
if (!PyArg_ParseTuple(args, "lO", &index, &value)) {
- return nullptr;
+ return nullptr;
}
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- ScopedPyObjectPtr new_list(Subscript(pself, full_slice.get()));
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ ScopedPyObjectPtr new_list(Subscript(pself, full_slice.get()));
if (PyList_Insert(new_list.get(), index, value) < 0) {
- return nullptr;
+ return nullptr;
}
int ret = InternalAssignRepeatedField(self, new_list.get());
if (ret < 0) {
- return nullptr;
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* Remove(PyObject* pself, PyObject* value) {
+static PyObject* Remove(PyObject* pself, PyObject* value) {
Py_ssize_t match_index = -1;
- for (Py_ssize_t i = 0; i < Len(pself); ++i) {
- ScopedPyObjectPtr elem(Item(pself, i));
+ for (Py_ssize_t i = 0; i < Len(pself); ++i) {
+ ScopedPyObjectPtr elem(Item(pself, i));
if (PyObject_RichCompareBool(elem.get(), value, Py_EQ)) {
match_index = i;
break;
@@ -544,19 +544,19 @@ static PyObject* Remove(PyObject* pself, PyObject* value) {
}
if (match_index == -1) {
PyErr_SetString(PyExc_ValueError, "remove(x): x not in container");
- return nullptr;
+ return nullptr;
}
- if (AssignItem(pself, match_index, nullptr) < 0) {
- return nullptr;
+ if (AssignItem(pself, match_index, nullptr) < 0) {
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* ExtendMethod(PyObject* self, PyObject* value) {
- return Extend(reinterpret_cast<RepeatedScalarContainer*>(self), value);
-}
-
-static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
+static PyObject* ExtendMethod(PyObject* self, PyObject* value) {
+ return Extend(reinterpret_cast<RepeatedScalarContainer*>(self), value);
+}
+
+static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
if (opid != Py_EQ && opid != Py_NE) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
@@ -566,229 +566,229 @@ static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
// also a repeated scalar container, into Python lists so we can delegate
// to the list's compare method.
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
}
ScopedPyObjectPtr other_list_deleter;
if (PyObject_TypeCheck(other, &RepeatedScalarContainer_Type)) {
- other_list_deleter.reset(Subscript(other, full_slice.get()));
+ other_list_deleter.reset(Subscript(other, full_slice.get()));
other = other_list_deleter.get();
}
- ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
- if (list == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
+ if (list == nullptr) {
+ return nullptr;
}
return PyObject_RichCompare(list.get(), other, opid);
}
-PyObject* Reduce(PyObject* unused_self, PyObject* unused_other) {
- PyErr_Format(PickleError_class,
- "can't pickle repeated message fields, convert to list first");
- return nullptr;
+PyObject* Reduce(PyObject* unused_self, PyObject* unused_other) {
+ PyErr_Format(PickleError_class,
+ "can't pickle repeated message fields, convert to list first");
+ return nullptr;
}
-static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
+static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
// Support the old sort_function argument for backwards
// compatibility.
- if (kwds != nullptr) {
+ if (kwds != nullptr) {
PyObject* sort_func = PyDict_GetItemString(kwds, "sort_function");
- if (sort_func != nullptr) {
+ if (sort_func != nullptr) {
// Must set before deleting as sort_func is a borrowed reference
// and kwds might be the only thing keeping it alive.
- if (PyDict_SetItemString(kwds, "cmp", sort_func) == -1) return nullptr;
- if (PyDict_DelItemString(kwds, "sort_function") == -1) return nullptr;
+ if (PyDict_SetItemString(kwds, "cmp", sort_func) == -1) return nullptr;
+ if (PyDict_DelItemString(kwds, "sort_function") == -1) return nullptr;
}
}
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
}
- ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
- if (list == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
+ if (list == nullptr) {
+ return nullptr;
}
ScopedPyObjectPtr m(PyObject_GetAttrString(list.get(), "sort"));
- if (m == nullptr) {
- return nullptr;
+ if (m == nullptr) {
+ return nullptr;
}
ScopedPyObjectPtr res(PyObject_Call(m.get(), args, kwds));
- if (res == nullptr) {
- return nullptr;
+ if (res == nullptr) {
+ return nullptr;
}
- int ret = InternalAssignRepeatedField(
- reinterpret_cast<RepeatedScalarContainer*>(pself), list.get());
+ int ret = InternalAssignRepeatedField(
+ reinterpret_cast<RepeatedScalarContainer*>(pself), list.get());
if (ret < 0) {
- return nullptr;
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* Reverse(PyObject* pself) {
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
- }
- ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
- if (list == nullptr) {
- return nullptr;
- }
- ScopedPyObjectPtr res(PyObject_CallMethod(list.get(), "reverse", nullptr));
- if (res == nullptr) {
- return nullptr;
- }
- int ret = InternalAssignRepeatedField(
- reinterpret_cast<RepeatedScalarContainer*>(pself), list.get());
- if (ret < 0) {
- return nullptr;
- }
- Py_RETURN_NONE;
-}
-
-static PyObject* Pop(PyObject* pself, PyObject* args) {
+static PyObject* Reverse(PyObject* pself) {
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
+ }
+ ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
+ if (list == nullptr) {
+ return nullptr;
+ }
+ ScopedPyObjectPtr res(PyObject_CallMethod(list.get(), "reverse", nullptr));
+ if (res == nullptr) {
+ return nullptr;
+ }
+ int ret = InternalAssignRepeatedField(
+ reinterpret_cast<RepeatedScalarContainer*>(pself), list.get());
+ if (ret < 0) {
+ return nullptr;
+ }
+ Py_RETURN_NONE;
+}
+
+static PyObject* Pop(PyObject* pself, PyObject* args) {
Py_ssize_t index = -1;
if (!PyArg_ParseTuple(args, "|n", &index)) {
- return nullptr;
+ return nullptr;
}
- PyObject* item = Item(pself, index);
- if (item == nullptr) {
- PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
- return nullptr;
+ PyObject* item = Item(pself, index);
+ if (item == nullptr) {
+ PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
+ return nullptr;
}
- if (AssignItem(pself, index, nullptr) < 0) {
- return nullptr;
+ if (AssignItem(pself, index, nullptr) < 0) {
+ return nullptr;
}
return item;
}
-static PyObject* ToStr(PyObject* pself) {
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
+static PyObject* ToStr(PyObject* pself) {
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
}
- ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
- if (list == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
+ if (list == nullptr) {
+ return nullptr;
}
return PyObject_Repr(list.get());
}
-static PyObject* MergeFrom(PyObject* pself, PyObject* arg) {
- return Extend(reinterpret_cast<RepeatedScalarContainer*>(pself), arg);
-}
-
+static PyObject* MergeFrom(PyObject* pself, PyObject* arg) {
+ return Extend(reinterpret_cast<RepeatedScalarContainer*>(pself), arg);
+}
+
// The private constructor of RepeatedScalarContainer objects.
-RepeatedScalarContainer* NewContainer(
+RepeatedScalarContainer* NewContainer(
CMessage* parent, const FieldDescriptor* parent_field_descriptor) {
if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
- return nullptr;
+ return nullptr;
}
RepeatedScalarContainer* self = reinterpret_cast<RepeatedScalarContainer*>(
PyType_GenericAlloc(&RepeatedScalarContainer_Type, 0));
- if (self == nullptr) {
- return nullptr;
+ if (self == nullptr) {
+ return nullptr;
}
- Py_INCREF(parent);
+ Py_INCREF(parent);
self->parent = parent;
self->parent_field_descriptor = parent_field_descriptor;
- return self;
+ return self;
}
-PyObject* DeepCopy(PyObject* pself, PyObject* arg) {
- return reinterpret_cast<RepeatedScalarContainer*>(pself)->DeepCopy();
+PyObject* DeepCopy(PyObject* pself, PyObject* arg) {
+ return reinterpret_cast<RepeatedScalarContainer*>(pself)->DeepCopy();
}
-static void Dealloc(PyObject* pself) {
- reinterpret_cast<RepeatedScalarContainer*>(pself)->RemoveFromParentCache();
- Py_TYPE(pself)->tp_free(pself);
+static void Dealloc(PyObject* pself) {
+ reinterpret_cast<RepeatedScalarContainer*>(pself)->RemoveFromParentCache();
+ Py_TYPE(pself)->tp_free(pself);
}
static PySequenceMethods SqMethods = {
- Len, /* sq_length */
- nullptr, /* sq_concat */
- nullptr, /* sq_repeat */
- Item, /* sq_item */
- nullptr, /* sq_slice */
- AssignItem /* sq_ass_item */
+ Len, /* sq_length */
+ nullptr, /* sq_concat */
+ nullptr, /* sq_repeat */
+ Item, /* sq_item */
+ nullptr, /* sq_slice */
+ AssignItem /* sq_ass_item */
};
static PyMappingMethods MpMethods = {
- Len, /* mp_length */
- Subscript, /* mp_subscript */
- AssSubscript, /* mp_ass_subscript */
+ Len, /* mp_length */
+ Subscript, /* mp_subscript */
+ AssSubscript, /* mp_ass_subscript */
};
static PyMethodDef Methods[] = {
- {"__deepcopy__", DeepCopy, METH_VARARGS, "Makes a deep copy of the class."},
- {"__reduce__", Reduce, METH_NOARGS,
- "Outputs picklable representation of the repeated field."},
- {"append", AppendMethod, METH_O,
- "Appends an object to the repeated container."},
- {"extend", ExtendMethod, METH_O,
- "Appends objects to the repeated container."},
- {"insert", Insert, METH_VARARGS,
- "Inserts an object at the specified position in the container."},
- {"pop", Pop, METH_VARARGS,
- "Removes an object from the repeated container and returns it."},
- {"remove", Remove, METH_O,
- "Removes an object from the repeated container."},
- {"sort", reinterpret_cast<PyCFunction>(Sort), METH_VARARGS | METH_KEYWORDS,
- "Sorts the repeated container."},
- {"reverse", reinterpret_cast<PyCFunction>(Reverse), METH_NOARGS,
- "Reverses elements order of the repeated container."},
- {"MergeFrom", static_cast<PyCFunction>(MergeFrom), METH_O,
- "Merges a repeated container into the current container."},
- {nullptr, nullptr}};
+ {"__deepcopy__", DeepCopy, METH_VARARGS, "Makes a deep copy of the class."},
+ {"__reduce__", Reduce, METH_NOARGS,
+ "Outputs picklable representation of the repeated field."},
+ {"append", AppendMethod, METH_O,
+ "Appends an object to the repeated container."},
+ {"extend", ExtendMethod, METH_O,
+ "Appends objects to the repeated container."},
+ {"insert", Insert, METH_VARARGS,
+ "Inserts an object at the specified position in the container."},
+ {"pop", Pop, METH_VARARGS,
+ "Removes an object from the repeated container and returns it."},
+ {"remove", Remove, METH_O,
+ "Removes an object from the repeated container."},
+ {"sort", reinterpret_cast<PyCFunction>(Sort), METH_VARARGS | METH_KEYWORDS,
+ "Sorts the repeated container."},
+ {"reverse", reinterpret_cast<PyCFunction>(Reverse), METH_NOARGS,
+ "Reverses elements order of the repeated container."},
+ {"MergeFrom", static_cast<PyCFunction>(MergeFrom), METH_O,
+ "Merges a repeated container into the current container."},
+ {nullptr, nullptr}};
} // namespace repeated_scalar_container
PyTypeObject RepeatedScalarContainer_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".RepeatedScalarContainer", // tp_name
- sizeof(RepeatedScalarContainer), // tp_basicsize
- 0, // tp_itemsize
- repeated_scalar_container::Dealloc, // tp_dealloc
-#if PY_VERSION_HEX >= 0x03080000
- 0, // tp_vectorcall_offset
-#else
- nullptr, // tp_print
-#endif
- nullptr, // tp_getattr
- nullptr, // tp_setattr
- nullptr, // tp_compare
- repeated_scalar_container::ToStr, // tp_repr
- nullptr, // tp_as_number
- &repeated_scalar_container::SqMethods, // tp_as_sequence
- &repeated_scalar_container::MpMethods, // tp_as_mapping
- PyObject_HashNotImplemented, // tp_hash
- nullptr, // tp_call
- nullptr, // tp_str
- nullptr, // tp_getattro
- nullptr, // tp_setattro
- nullptr, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "A Repeated scalar container", // tp_doc
- nullptr, // tp_traverse
- nullptr, // tp_clear
- repeated_scalar_container::RichCompare, // tp_richcompare
- 0, // tp_weaklistoffset
- nullptr, // tp_iter
- nullptr, // tp_iternext
- repeated_scalar_container::Methods, // tp_methods
- nullptr, // tp_members
- nullptr, // tp_getset
- nullptr, // tp_base
- nullptr, // tp_dict
- nullptr, // tp_descr_get
- nullptr, // tp_descr_set
- 0, // tp_dictoffset
- nullptr, // tp_init
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".RepeatedScalarContainer", // tp_name
+ sizeof(RepeatedScalarContainer), // tp_basicsize
+ 0, // tp_itemsize
+ repeated_scalar_container::Dealloc, // tp_dealloc
+#if PY_VERSION_HEX >= 0x03080000
+ 0, // tp_vectorcall_offset
+#else
+ nullptr, // tp_print
+#endif
+ nullptr, // tp_getattr
+ nullptr, // tp_setattr
+ nullptr, // tp_compare
+ repeated_scalar_container::ToStr, // tp_repr
+ nullptr, // tp_as_number
+ &repeated_scalar_container::SqMethods, // tp_as_sequence
+ &repeated_scalar_container::MpMethods, // tp_as_mapping
+ PyObject_HashNotImplemented, // tp_hash
+ nullptr, // tp_call
+ nullptr, // tp_str
+ nullptr, // tp_getattro
+ nullptr, // tp_setattro
+ nullptr, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "A Repeated scalar container", // tp_doc
+ nullptr, // tp_traverse
+ nullptr, // tp_clear
+ repeated_scalar_container::RichCompare, // tp_richcompare
+ 0, // tp_weaklistoffset
+ nullptr, // tp_iter
+ nullptr, // tp_iternext
+ repeated_scalar_container::Methods, // tp_methods
+ nullptr, // tp_members
+ nullptr, // tp_getset
+ nullptr, // tp_base
+ nullptr, // tp_dict
+ nullptr, // tp_descr_get
+ nullptr, // tp_descr_set
+ 0, // tp_dictoffset
+ nullptr, // tp_init
};
} // namespace python
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_scalar_container.h b/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_scalar_container.h
index f9f0ea8f31..2d5952b192 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_scalar_container.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/repeated_scalar_container.h
@@ -38,14 +38,14 @@
#include <memory>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/pyext/message.h>
namespace google {
namespace protobuf {
namespace python {
-typedef struct RepeatedScalarContainer : public ContainerBase {
+typedef struct RepeatedScalarContainer : public ContainerBase {
} RepeatedScalarContainer;
extern PyTypeObject RepeatedScalarContainer_Type;
@@ -54,7 +54,7 @@ namespace repeated_scalar_container {
// Builds a RepeatedScalarContainer object, from a parent message and a
// field descriptor.
-extern RepeatedScalarContainer* NewContainer(
+extern RepeatedScalarContainer* NewContainer(
CMessage* parent, const FieldDescriptor* parent_field_descriptor);
// Appends the scalar 'item' to the end of the container 'self'.
@@ -72,6 +72,6 @@ PyObject* Extend(RepeatedScalarContainer* self, PyObject* value);
} // namespace repeated_scalar_container
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_SCALAR_CONTAINER_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/safe_numerics.h b/contrib/python/protobuf/py2/google/protobuf/pyext/safe_numerics.h
index 93ae640e8b..26ed54d5d6 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/safe_numerics.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/safe_numerics.h
@@ -34,8 +34,8 @@
#include <limits>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
namespace google {
namespace protobuf {
@@ -132,10 +132,10 @@ template <class Dest, class Source>
inline bool IsValidNumericCast(Source source) {
typedef std::numeric_limits<Source> SourceLimits;
typedef std::numeric_limits<Dest> DestLimits;
- static_assert(SourceLimits::is_specialized, "argument must be numeric");
- static_assert(SourceLimits::is_integer, "argument must be integral");
- static_assert(DestLimits::is_specialized, "result must be numeric");
- static_assert(DestLimits::is_integer, "result must be integral");
+ static_assert(SourceLimits::is_specialized, "argument must be numeric");
+ static_assert(SourceLimits::is_integer, "argument must be integral");
+ static_assert(DestLimits::is_specialized, "result must be numeric");
+ static_assert(DestLimits::is_integer, "result must be integral");
return IsValidNumericCastImpl<
sizeof(Dest) == sizeof(Source),
@@ -150,7 +150,7 @@ inline bool IsValidNumericCast(Source source) {
// checked_numeric_cast<> is analogous to static_cast<> for numeric types,
// except that it CHECKs that the specified numeric conversion will not
// overflow or underflow. Floating point arguments are not currently allowed
-// (this is static_asserted), though this could be supported if necessary.
+// (this is static_asserted), though this could be supported if necessary.
template <class Dest, class Source>
inline Dest checked_numeric_cast(Source source) {
GOOGLE_CHECK(IsValidNumericCast<Dest>(source));
@@ -159,6 +159,6 @@ inline Dest checked_numeric_cast(Source source) {
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_SAFE_NUMERICS_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/scoped_pyobject_ptr.h b/contrib/python/protobuf/py2/google/protobuf/pyext/scoped_pyobject_ptr.h
index 6f7fc29813..9f3c1fc51d 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/scoped_pyobject_ptr.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/scoped_pyobject_ptr.h
@@ -33,7 +33,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__
-#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/common.h>
#include <Python.h>
namespace google {
@@ -77,7 +77,7 @@ class ScopedPythonPtr {
PyObject* as_pyobject() const { return reinterpret_cast<PyObject*>(ptr_); }
- // Increments the reference count of the current object.
+ // Increments the reference count of the current object.
// Should not be called when no object is held.
void inc() const { Py_INCREF(ptr_); }
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/unknown_fields.cc b/contrib/python/protobuf/py2/google/protobuf/pyext/unknown_fields.cc
index deb86e6916..69ba22b850 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/unknown_fields.cc
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/unknown_fields.cc
@@ -1,358 +1,358 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <google/protobuf/pyext/unknown_fields.h>
-
-#include <Python.h>
-#include <set>
-#include <memory>
-
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/unknown_field_set.h>
-#include <google/protobuf/wire_format_lite.h>
-
-#if PY_MAJOR_VERSION >= 3
- #define PyInt_FromLong PyLong_FromLong
-#endif
-
-namespace google {
-namespace protobuf {
-namespace python {
-
-namespace unknown_fields {
-
-static Py_ssize_t Len(PyObject* pself) {
- PyUnknownFields* self =
- reinterpret_cast<PyUnknownFields*>(pself);
- if (self->fields == NULL) {
- PyErr_Format(PyExc_ValueError,
- "UnknownFields does not exist. "
- "The parent message might be cleared.");
- return -1;
- }
- return self->fields->field_count();
-}
-
-void Clear(PyUnknownFields* self) {
- for (std::set<PyUnknownFields*>::iterator it =
- self->sub_unknown_fields.begin();
- it != self->sub_unknown_fields.end(); it++) {
- Clear(*it);
- }
- self->fields = NULL;
- self->sub_unknown_fields.clear();
-}
-
-PyObject* NewPyUnknownFieldRef(PyUnknownFields* parent,
- Py_ssize_t index);
-
-static PyObject* Item(PyObject* pself, Py_ssize_t index) {
- PyUnknownFields* self =
- reinterpret_cast<PyUnknownFields*>(pself);
- if (self->fields == NULL) {
- PyErr_Format(PyExc_ValueError,
- "UnknownFields does not exist. "
- "The parent message might be cleared.");
- return NULL;
- }
- Py_ssize_t total_size = self->fields->field_count();
- if (index < 0) {
- index = total_size + index;
- }
- if (index < 0 || index >= total_size) {
- PyErr_Format(PyExc_IndexError,
- "index (%zd) out of range",
- index);
- return NULL;
- }
-
- return unknown_fields::NewPyUnknownFieldRef(self, index);
-}
-
-PyObject* NewPyUnknownFields(CMessage* c_message) {
- PyUnknownFields* self = reinterpret_cast<PyUnknownFields*>(
- PyType_GenericAlloc(&PyUnknownFields_Type, 0));
- if (self == NULL) {
- return NULL;
- }
- // Call "placement new" to initialize PyUnknownFields.
- new (self) PyUnknownFields;
-
- Py_INCREF(c_message);
- self->parent = reinterpret_cast<PyObject*>(c_message);
- Message* message = c_message->message;
- const Reflection* reflection = message->GetReflection();
- self->fields = &reflection->GetUnknownFields(*message);
-
- return reinterpret_cast<PyObject*>(self);
-}
-
-PyObject* NewPyUnknownFieldRef(PyUnknownFields* parent,
- Py_ssize_t index) {
- PyUnknownFieldRef* self = reinterpret_cast<PyUnknownFieldRef*>(
- PyType_GenericAlloc(&PyUnknownFieldRef_Type, 0));
- if (self == NULL) {
- return NULL;
- }
-
- Py_INCREF(parent);
- self->parent = parent;
- self->index = index;
-
- return reinterpret_cast<PyObject*>(self);
-}
-
-static void Dealloc(PyObject* pself) {
- PyUnknownFields* self =
- reinterpret_cast<PyUnknownFields*>(pself);
- if (PyObject_TypeCheck(self->parent, &PyUnknownFields_Type)) {
- reinterpret_cast<PyUnknownFields*>(
- self->parent)->sub_unknown_fields.erase(self);
- } else {
- reinterpret_cast<CMessage*>(self->parent)->unknown_field_set = nullptr;
- }
- Py_CLEAR(self->parent);
- self->~PyUnknownFields();
- Py_TYPE(pself)->tp_free(pself);
-}
-
-static PySequenceMethods SqMethods = {
- Len, /* sq_length */
- 0, /* sq_concat */
- 0, /* sq_repeat */
- Item, /* sq_item */
- 0, /* sq_slice */
- 0, /* sq_ass_item */
-};
-
-} // namespace unknown_fields
-
-PyTypeObject PyUnknownFields_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- FULL_MODULE_NAME ".PyUnknownFields", // tp_name
- sizeof(PyUnknownFields), // tp_basicsize
- 0, // tp_itemsize
- unknown_fields::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- &unknown_fields::SqMethods, // tp_as_sequence
- 0, // tp_as_mapping
- PyObject_HashNotImplemented, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "unknown field set", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- 0, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
-};
-
-namespace unknown_field {
-static PyObject* PyUnknownFields_FromUnknownFieldSet(
- PyUnknownFields* parent, const UnknownFieldSet& fields) {
- PyUnknownFields* self = reinterpret_cast<PyUnknownFields*>(
- PyType_GenericAlloc(&PyUnknownFields_Type, 0));
- if (self == NULL) {
- return NULL;
- }
- // Call "placement new" to initialize PyUnknownFields.
- new (self) PyUnknownFields;
-
- Py_INCREF(parent);
- self->parent = reinterpret_cast<PyObject*>(parent);
- self->fields = &fields;
- parent->sub_unknown_fields.emplace(self);
-
- return reinterpret_cast<PyObject*>(self);
-}
-
-const UnknownField* GetUnknownField(PyUnknownFieldRef* self) {
- const UnknownFieldSet* fields = self->parent->fields;
- if (fields == NULL) {
- PyErr_Format(PyExc_ValueError,
- "UnknownField does not exist. "
- "The parent message might be cleared.");
- return NULL;
- }
- ssize_t total_size = fields->field_count();
- if (self->index >= total_size) {
- PyErr_Format(PyExc_ValueError,
- "UnknownField does not exist. "
- "The parent message might be cleared.");
- return NULL;
- }
- return &fields->field(self->index);
-}
-
-static PyObject* GetFieldNumber(PyUnknownFieldRef* self, void *closure) {
- const UnknownField* unknown_field = GetUnknownField(self);
- if (unknown_field == NULL) {
- return NULL;
- }
- return PyInt_FromLong(unknown_field->number());
-}
-
-using internal::WireFormatLite;
-static PyObject* GetWireType(PyUnknownFieldRef* self, void *closure) {
- const UnknownField* unknown_field = GetUnknownField(self);
- if (unknown_field == NULL) {
- return NULL;
- }
-
- // Assign a default value to suppress may-uninitialized warnings (errors
- // when built in some places).
- WireFormatLite::WireType wire_type = WireFormatLite::WIRETYPE_VARINT;
- switch (unknown_field->type()) {
- case UnknownField::TYPE_VARINT:
- wire_type = WireFormatLite::WIRETYPE_VARINT;
- break;
- case UnknownField::TYPE_FIXED32:
- wire_type = WireFormatLite::WIRETYPE_FIXED32;
- break;
- case UnknownField::TYPE_FIXED64:
- wire_type = WireFormatLite::WIRETYPE_FIXED64;
- break;
- case UnknownField::TYPE_LENGTH_DELIMITED:
- wire_type = WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
- break;
- case UnknownField::TYPE_GROUP:
- wire_type = WireFormatLite::WIRETYPE_START_GROUP;
- break;
- }
- return PyInt_FromLong(wire_type);
-}
-
-static PyObject* GetData(PyUnknownFieldRef* self, void *closure) {
- const UnknownField* field = GetUnknownField(self);
- if (field == NULL) {
- return NULL;
- }
- PyObject* data = NULL;
- switch (field->type()) {
- case UnknownField::TYPE_VARINT:
- data = PyInt_FromLong(field->varint());
- break;
- case UnknownField::TYPE_FIXED32:
- data = PyInt_FromLong(field->fixed32());
- break;
- case UnknownField::TYPE_FIXED64:
- data = PyInt_FromLong(field->fixed64());
- break;
- case UnknownField::TYPE_LENGTH_DELIMITED:
- data = PyBytes_FromStringAndSize(field->length_delimited().data(),
- field->GetLengthDelimitedSize());
- break;
- case UnknownField::TYPE_GROUP:
- data = PyUnknownFields_FromUnknownFieldSet(
- self->parent, field->group());
- break;
- }
- return data;
-}
-
-static void Dealloc(PyObject* pself) {
- PyUnknownFieldRef* self =
- reinterpret_cast<PyUnknownFieldRef*>(pself);
- Py_CLEAR(self->parent);
-}
-
-static PyGetSetDef Getters[] = {
- {"field_number", (getter)GetFieldNumber, NULL},
- {"wire_type", (getter)GetWireType, NULL},
- {"data", (getter)GetData, NULL},
- {NULL}
-};
-
-} // namespace unknown_field
-
-PyTypeObject PyUnknownFieldRef_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- FULL_MODULE_NAME ".PyUnknownFieldRef", // tp_name
- sizeof(PyUnknownFieldRef), // tp_basicsize
- 0, // tp_itemsize
- unknown_field::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- PyObject_HashNotImplemented, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "unknown field", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- unknown_field::Getters, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
-};
-
-
-} // namespace python
-} // namespace protobuf
-} // namespace google
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <google/protobuf/pyext/unknown_fields.h>
+
+#include <Python.h>
+#include <set>
+#include <memory>
+
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/unknown_field_set.h>
+#include <google/protobuf/wire_format_lite.h>
+
+#if PY_MAJOR_VERSION >= 3
+ #define PyInt_FromLong PyLong_FromLong
+#endif
+
+namespace google {
+namespace protobuf {
+namespace python {
+
+namespace unknown_fields {
+
+static Py_ssize_t Len(PyObject* pself) {
+ PyUnknownFields* self =
+ reinterpret_cast<PyUnknownFields*>(pself);
+ if (self->fields == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "UnknownFields does not exist. "
+ "The parent message might be cleared.");
+ return -1;
+ }
+ return self->fields->field_count();
+}
+
+void Clear(PyUnknownFields* self) {
+ for (std::set<PyUnknownFields*>::iterator it =
+ self->sub_unknown_fields.begin();
+ it != self->sub_unknown_fields.end(); it++) {
+ Clear(*it);
+ }
+ self->fields = NULL;
+ self->sub_unknown_fields.clear();
+}
+
+PyObject* NewPyUnknownFieldRef(PyUnknownFields* parent,
+ Py_ssize_t index);
+
+static PyObject* Item(PyObject* pself, Py_ssize_t index) {
+ PyUnknownFields* self =
+ reinterpret_cast<PyUnknownFields*>(pself);
+ if (self->fields == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "UnknownFields does not exist. "
+ "The parent message might be cleared.");
+ return NULL;
+ }
+ Py_ssize_t total_size = self->fields->field_count();
+ if (index < 0) {
+ index = total_size + index;
+ }
+ if (index < 0 || index >= total_size) {
+ PyErr_Format(PyExc_IndexError,
+ "index (%zd) out of range",
+ index);
+ return NULL;
+ }
+
+ return unknown_fields::NewPyUnknownFieldRef(self, index);
+}
+
+PyObject* NewPyUnknownFields(CMessage* c_message) {
+ PyUnknownFields* self = reinterpret_cast<PyUnknownFields*>(
+ PyType_GenericAlloc(&PyUnknownFields_Type, 0));
+ if (self == NULL) {
+ return NULL;
+ }
+ // Call "placement new" to initialize PyUnknownFields.
+ new (self) PyUnknownFields;
+
+ Py_INCREF(c_message);
+ self->parent = reinterpret_cast<PyObject*>(c_message);
+ Message* message = c_message->message;
+ const Reflection* reflection = message->GetReflection();
+ self->fields = &reflection->GetUnknownFields(*message);
+
+ return reinterpret_cast<PyObject*>(self);
+}
+
+PyObject* NewPyUnknownFieldRef(PyUnknownFields* parent,
+ Py_ssize_t index) {
+ PyUnknownFieldRef* self = reinterpret_cast<PyUnknownFieldRef*>(
+ PyType_GenericAlloc(&PyUnknownFieldRef_Type, 0));
+ if (self == NULL) {
+ return NULL;
+ }
+
+ Py_INCREF(parent);
+ self->parent = parent;
+ self->index = index;
+
+ return reinterpret_cast<PyObject*>(self);
+}
+
+static void Dealloc(PyObject* pself) {
+ PyUnknownFields* self =
+ reinterpret_cast<PyUnknownFields*>(pself);
+ if (PyObject_TypeCheck(self->parent, &PyUnknownFields_Type)) {
+ reinterpret_cast<PyUnknownFields*>(
+ self->parent)->sub_unknown_fields.erase(self);
+ } else {
+ reinterpret_cast<CMessage*>(self->parent)->unknown_field_set = nullptr;
+ }
+ Py_CLEAR(self->parent);
+ self->~PyUnknownFields();
+ Py_TYPE(pself)->tp_free(pself);
+}
+
+static PySequenceMethods SqMethods = {
+ Len, /* sq_length */
+ 0, /* sq_concat */
+ 0, /* sq_repeat */
+ Item, /* sq_item */
+ 0, /* sq_slice */
+ 0, /* sq_ass_item */
+};
+
+} // namespace unknown_fields
+
+PyTypeObject PyUnknownFields_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ FULL_MODULE_NAME ".PyUnknownFields", // tp_name
+ sizeof(PyUnknownFields), // tp_basicsize
+ 0, // tp_itemsize
+ unknown_fields::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ &unknown_fields::SqMethods, // tp_as_sequence
+ 0, // tp_as_mapping
+ PyObject_HashNotImplemented, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "unknown field set", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ 0, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+};
+
+namespace unknown_field {
+static PyObject* PyUnknownFields_FromUnknownFieldSet(
+ PyUnknownFields* parent, const UnknownFieldSet& fields) {
+ PyUnknownFields* self = reinterpret_cast<PyUnknownFields*>(
+ PyType_GenericAlloc(&PyUnknownFields_Type, 0));
+ if (self == NULL) {
+ return NULL;
+ }
+ // Call "placement new" to initialize PyUnknownFields.
+ new (self) PyUnknownFields;
+
+ Py_INCREF(parent);
+ self->parent = reinterpret_cast<PyObject*>(parent);
+ self->fields = &fields;
+ parent->sub_unknown_fields.emplace(self);
+
+ return reinterpret_cast<PyObject*>(self);
+}
+
+const UnknownField* GetUnknownField(PyUnknownFieldRef* self) {
+ const UnknownFieldSet* fields = self->parent->fields;
+ if (fields == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "UnknownField does not exist. "
+ "The parent message might be cleared.");
+ return NULL;
+ }
+ ssize_t total_size = fields->field_count();
+ if (self->index >= total_size) {
+ PyErr_Format(PyExc_ValueError,
+ "UnknownField does not exist. "
+ "The parent message might be cleared.");
+ return NULL;
+ }
+ return &fields->field(self->index);
+}
+
+static PyObject* GetFieldNumber(PyUnknownFieldRef* self, void *closure) {
+ const UnknownField* unknown_field = GetUnknownField(self);
+ if (unknown_field == NULL) {
+ return NULL;
+ }
+ return PyInt_FromLong(unknown_field->number());
+}
+
+using internal::WireFormatLite;
+static PyObject* GetWireType(PyUnknownFieldRef* self, void *closure) {
+ const UnknownField* unknown_field = GetUnknownField(self);
+ if (unknown_field == NULL) {
+ return NULL;
+ }
+
+ // Assign a default value to suppress may-uninitialized warnings (errors
+ // when built in some places).
+ WireFormatLite::WireType wire_type = WireFormatLite::WIRETYPE_VARINT;
+ switch (unknown_field->type()) {
+ case UnknownField::TYPE_VARINT:
+ wire_type = WireFormatLite::WIRETYPE_VARINT;
+ break;
+ case UnknownField::TYPE_FIXED32:
+ wire_type = WireFormatLite::WIRETYPE_FIXED32;
+ break;
+ case UnknownField::TYPE_FIXED64:
+ wire_type = WireFormatLite::WIRETYPE_FIXED64;
+ break;
+ case UnknownField::TYPE_LENGTH_DELIMITED:
+ wire_type = WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
+ break;
+ case UnknownField::TYPE_GROUP:
+ wire_type = WireFormatLite::WIRETYPE_START_GROUP;
+ break;
+ }
+ return PyInt_FromLong(wire_type);
+}
+
+static PyObject* GetData(PyUnknownFieldRef* self, void *closure) {
+ const UnknownField* field = GetUnknownField(self);
+ if (field == NULL) {
+ return NULL;
+ }
+ PyObject* data = NULL;
+ switch (field->type()) {
+ case UnknownField::TYPE_VARINT:
+ data = PyInt_FromLong(field->varint());
+ break;
+ case UnknownField::TYPE_FIXED32:
+ data = PyInt_FromLong(field->fixed32());
+ break;
+ case UnknownField::TYPE_FIXED64:
+ data = PyInt_FromLong(field->fixed64());
+ break;
+ case UnknownField::TYPE_LENGTH_DELIMITED:
+ data = PyBytes_FromStringAndSize(field->length_delimited().data(),
+ field->GetLengthDelimitedSize());
+ break;
+ case UnknownField::TYPE_GROUP:
+ data = PyUnknownFields_FromUnknownFieldSet(
+ self->parent, field->group());
+ break;
+ }
+ return data;
+}
+
+static void Dealloc(PyObject* pself) {
+ PyUnknownFieldRef* self =
+ reinterpret_cast<PyUnknownFieldRef*>(pself);
+ Py_CLEAR(self->parent);
+}
+
+static PyGetSetDef Getters[] = {
+ {"field_number", (getter)GetFieldNumber, NULL},
+ {"wire_type", (getter)GetWireType, NULL},
+ {"data", (getter)GetData, NULL},
+ {NULL}
+};
+
+} // namespace unknown_field
+
+PyTypeObject PyUnknownFieldRef_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ FULL_MODULE_NAME ".PyUnknownFieldRef", // tp_name
+ sizeof(PyUnknownFieldRef), // tp_basicsize
+ 0, // tp_itemsize
+ unknown_field::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ PyObject_HashNotImplemented, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "unknown field", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ unknown_field::Getters, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+};
+
+
+} // namespace python
+} // namespace protobuf
+} // namespace google
diff --git a/contrib/python/protobuf/py2/google/protobuf/pyext/unknown_fields.h b/contrib/python/protobuf/py2/google/protobuf/pyext/unknown_fields.h
index 94d55e148d..9e661866f3 100644
--- a/contrib/python/protobuf/py2/google/protobuf/pyext/unknown_fields.h
+++ b/contrib/python/protobuf/py2/google/protobuf/pyext/unknown_fields.h
@@ -1,90 +1,90 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
-#define GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
-
-#include <Python.h>
-
-#include <memory>
-#include <set>
-
-#include <google/protobuf/pyext/message.h>
-
-namespace google {
-namespace protobuf {
-
-class UnknownField;
-class UnknownFieldSet;
-
-namespace python {
-struct CMessage;
-
-typedef struct PyUnknownFields {
- PyObject_HEAD;
- // Strong pointer to the parent CMessage or PyUnknownFields.
- // The top PyUnknownFields holds a reference to its parent CMessage
- // object before release.
- // Sub PyUnknownFields holds reference to parent PyUnknownFields.
- PyObject* parent;
-
- // Pointer to the C++ UnknownFieldSet.
- // PyUnknownFields does not own this pointer.
- const UnknownFieldSet* fields;
-
- // Weak references to child unknown fields.
- std::set<PyUnknownFields*> sub_unknown_fields;
-} PyUnknownFields;
-
-typedef struct PyUnknownFieldRef {
- PyObject_HEAD;
- // Every Python PyUnknownFieldRef holds a reference to its parent
- // PyUnknownFields in order to keep it alive.
- PyUnknownFields* parent;
-
- // The UnknownField index in UnknownFields.
- Py_ssize_t index;
-} UknownFieldRef;
-
-extern PyTypeObject PyUnknownFields_Type;
-extern PyTypeObject PyUnknownFieldRef_Type;
-
-namespace unknown_fields {
-
-// Builds an PyUnknownFields for a specific message.
-PyObject* NewPyUnknownFields(CMessage *parent);
-void Clear(PyUnknownFields* self);
-
-} // namespace unknown_fields
-} // namespace python
-} // namespace protobuf
-} // namespace google
-
-#endif // GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
+#define GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
+
+#include <Python.h>
+
+#include <memory>
+#include <set>
+
+#include <google/protobuf/pyext/message.h>
+
+namespace google {
+namespace protobuf {
+
+class UnknownField;
+class UnknownFieldSet;
+
+namespace python {
+struct CMessage;
+
+typedef struct PyUnknownFields {
+ PyObject_HEAD;
+ // Strong pointer to the parent CMessage or PyUnknownFields.
+ // The top PyUnknownFields holds a reference to its parent CMessage
+ // object before release.
+ // Sub PyUnknownFields holds reference to parent PyUnknownFields.
+ PyObject* parent;
+
+ // Pointer to the C++ UnknownFieldSet.
+ // PyUnknownFields does not own this pointer.
+ const UnknownFieldSet* fields;
+
+ // Weak references to child unknown fields.
+ std::set<PyUnknownFields*> sub_unknown_fields;
+} PyUnknownFields;
+
+typedef struct PyUnknownFieldRef {
+ PyObject_HEAD;
+ // Every Python PyUnknownFieldRef holds a reference to its parent
+ // PyUnknownFields in order to keep it alive.
+ PyUnknownFields* parent;
+
+ // The UnknownField index in UnknownFields.
+ Py_ssize_t index;
+} UknownFieldRef;
+
+extern PyTypeObject PyUnknownFields_Type;
+extern PyTypeObject PyUnknownFieldRef_Type;
+
+namespace unknown_fields {
+
+// Builds an PyUnknownFields for a specific message.
+PyObject* NewPyUnknownFields(CMessage *parent);
+void Clear(PyUnknownFields* self);
+
+} // namespace unknown_fields
+} // namespace python
+} // namespace protobuf
+} // namespace google
+
+#endif // GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
diff --git a/contrib/python/protobuf/py2/google/protobuf/reflection.py b/contrib/python/protobuf/py2/google/protobuf/reflection.py
index 81e18859a8..711b78716c 100644
--- a/contrib/python/protobuf/py2/google/protobuf/reflection.py
+++ b/contrib/python/protobuf/py2/google/protobuf/reflection.py
@@ -48,23 +48,23 @@ this file*.
__author__ = 'robinson@google.com (Will Robinson)'
-from google.protobuf import message_factory
-from google.protobuf import symbol_database
+from google.protobuf import message_factory
+from google.protobuf import symbol_database
# The type of all Message classes.
# Part of the public interface, but normally only used by message factories.
-GeneratedProtocolMessageType = message_factory._GENERATED_PROTOCOL_MESSAGE_TYPE
+GeneratedProtocolMessageType = message_factory._GENERATED_PROTOCOL_MESSAGE_TYPE
MESSAGE_CLASS_CACHE = {}
-# Deprecated. Please NEVER use reflection.ParseMessage().
+# Deprecated. Please NEVER use reflection.ParseMessage().
def ParseMessage(descriptor, byte_str):
"""Generate a new Message instance from this Descriptor and a byte string.
- DEPRECATED: ParseMessage is deprecated because it is using MakeClass().
- Please use MessageFactory.GetPrototype() instead.
-
+ DEPRECATED: ParseMessage is deprecated because it is using MakeClass().
+ Please use MessageFactory.GetPrototype() instead.
+
Args:
descriptor: Protobuf Descriptor object
byte_str: Serialized protocol buffer byte string
@@ -78,18 +78,18 @@ def ParseMessage(descriptor, byte_str):
return new_msg
-# Deprecated. Please NEVER use reflection.MakeClass().
+# Deprecated. Please NEVER use reflection.MakeClass().
def MakeClass(descriptor):
"""Construct a class object for a protobuf described by descriptor.
- DEPRECATED: use MessageFactory.GetPrototype() instead.
+ DEPRECATED: use MessageFactory.GetPrototype() instead.
Args:
descriptor: A descriptor.Descriptor object describing the protobuf.
Returns:
The Message class object described by the descriptor.
"""
- # Original implementation leads to duplicate message classes, which won't play
- # well with extensions. Message factory info is also missing.
- # Redirect to message_factory.
- return symbol_database.Default().GetPrototype(descriptor)
+ # Original implementation leads to duplicate message classes, which won't play
+ # well with extensions. Message factory info is also missing.
+ # Redirect to message_factory.
+ return symbol_database.Default().GetPrototype(descriptor)
diff --git a/contrib/python/protobuf/py2/google/protobuf/service.py b/contrib/python/protobuf/py2/google/protobuf/service.py
index 5625246324..c67fc6294e 100644
--- a/contrib/python/protobuf/py2/google/protobuf/service.py
+++ b/contrib/python/protobuf/py2/google/protobuf/service.py
@@ -73,7 +73,7 @@ class Service(object):
In the blocking case, RpcException will be raised on error.
Preconditions:
-
+
* method_descriptor.service == GetDescriptor
* request is of the exact same classes as returned by
GetRequestClass(method).
@@ -83,7 +83,7 @@ class Service(object):
RpcChannel which the stub is using.
Postconditions:
-
+
* "done" will be called when the method is complete. This may be
before CallMethod() returns or it may be at some point in the future.
* If the RPC failed, the response value passed to "done" will be None.
diff --git a/contrib/python/protobuf/py2/google/protobuf/service_reflection.py b/contrib/python/protobuf/py2/google/protobuf/service_reflection.py
index 75c51ff322..d4ea3a413a 100644
--- a/contrib/python/protobuf/py2/google/protobuf/service_reflection.py
+++ b/contrib/python/protobuf/py2/google/protobuf/service_reflection.py
@@ -49,14 +49,14 @@ class GeneratedServiceType(type):
The protocol compiler currently uses this metaclass to create protocol service
classes at runtime. Clients can also manually create their own classes at
- runtime, as in this example::
-
- mydescriptor = ServiceDescriptor(.....)
- class MyProtoService(service.Service):
- __metaclass__ = GeneratedServiceType
- DESCRIPTOR = mydescriptor
- myservice_instance = MyProtoService()
- # ...
+ runtime, as in this example::
+
+ mydescriptor = ServiceDescriptor(.....)
+ class MyProtoService(service.Service):
+ __metaclass__ = GeneratedServiceType
+ DESCRIPTOR = mydescriptor
+ myservice_instance = MyProtoService()
+ # ...
"""
_DESCRIPTOR_KEY = 'DESCRIPTOR'
@@ -76,11 +76,11 @@ class GeneratedServiceType(type):
# when a service class is subclassed.
if GeneratedServiceType._DESCRIPTOR_KEY not in dictionary:
return
-
+
descriptor = dictionary[GeneratedServiceType._DESCRIPTOR_KEY]
service_builder = _ServiceBuilder(descriptor)
service_builder.BuildService(cls)
- cls.DESCRIPTOR = descriptor
+ cls.DESCRIPTOR = descriptor
class GeneratedServiceStubType(GeneratedServiceType):
@@ -108,7 +108,7 @@ class GeneratedServiceStubType(GeneratedServiceType):
# when a service stub is subclassed.
if GeneratedServiceStubType._DESCRIPTOR_KEY not in dictionary:
return
-
+
descriptor = dictionary[GeneratedServiceStubType._DESCRIPTOR_KEY]
service_stub_builder = _ServiceStubBuilder(descriptor)
service_stub_builder.BuildServiceStub(cls)
diff --git a/contrib/python/protobuf/py2/google/protobuf/symbol_database.py b/contrib/python/protobuf/py2/google/protobuf/symbol_database.py
index fdcf8cf06c..e9bc68bf64 100644
--- a/contrib/python/protobuf/py2/google/protobuf/symbol_database.py
+++ b/contrib/python/protobuf/py2/google/protobuf/symbol_database.py
@@ -34,7 +34,7 @@ SymbolDatabase is the MessageFactory for messages generated at compile time,
and makes it easy to create new instances of a registered type, given only the
type's protocol buffer symbol name.
-Example usage::
+Example usage::
db = symbol_database.SymbolDatabase()
@@ -58,7 +58,7 @@ Example usage::
"""
-from google.protobuf.internal import api_implementation
+from google.protobuf.internal import api_implementation
from google.protobuf import descriptor_pool
from google.protobuf import message_factory
@@ -72,8 +72,8 @@ class SymbolDatabase(message_factory.MessageFactory):
Calls to GetSymbol() and GetMessages() will return messages registered here.
Args:
- message: A :class:`google.protobuf.message.Message` subclass (or
- instance); its descriptor will be registered.
+ message: A :class:`google.protobuf.message.Message` subclass (or
+ instance); its descriptor will be registered.
Returns:
The provided message.
@@ -88,46 +88,46 @@ class SymbolDatabase(message_factory.MessageFactory):
"""Registers the given message descriptor in the local database.
Args:
- message_descriptor (Descriptor): the message descriptor to add.
+ message_descriptor (Descriptor): the message descriptor to add.
"""
- if api_implementation.Type() == 'python':
- # pylint: disable=protected-access
- self.pool._AddDescriptor(message_descriptor)
+ if api_implementation.Type() == 'python':
+ # pylint: disable=protected-access
+ self.pool._AddDescriptor(message_descriptor)
def RegisterEnumDescriptor(self, enum_descriptor):
"""Registers the given enum descriptor in the local database.
Args:
- enum_descriptor (EnumDescriptor): The enum descriptor to register.
+ enum_descriptor (EnumDescriptor): The enum descriptor to register.
Returns:
- EnumDescriptor: The provided descriptor.
+ EnumDescriptor: The provided descriptor.
"""
- if api_implementation.Type() == 'python':
- # pylint: disable=protected-access
- self.pool._AddEnumDescriptor(enum_descriptor)
+ if api_implementation.Type() == 'python':
+ # pylint: disable=protected-access
+ self.pool._AddEnumDescriptor(enum_descriptor)
return enum_descriptor
def RegisterServiceDescriptor(self, service_descriptor):
"""Registers the given service descriptor in the local database.
Args:
- service_descriptor (ServiceDescriptor): the service descriptor to
- register.
+ service_descriptor (ServiceDescriptor): the service descriptor to
+ register.
"""
- if api_implementation.Type() == 'python':
- # pylint: disable=protected-access
- self.pool._AddServiceDescriptor(service_descriptor)
+ if api_implementation.Type() == 'python':
+ # pylint: disable=protected-access
+ self.pool._AddServiceDescriptor(service_descriptor)
def RegisterFileDescriptor(self, file_descriptor):
"""Registers the given file descriptor in the local database.
Args:
- file_descriptor (FileDescriptor): The file descriptor to register.
+ file_descriptor (FileDescriptor): The file descriptor to register.
"""
- if api_implementation.Type() == 'python':
- # pylint: disable=protected-access
- self.pool._InternalAddFileDescriptor(file_descriptor)
+ if api_implementation.Type() == 'python':
+ # pylint: disable=protected-access
+ self.pool._InternalAddFileDescriptor(file_descriptor)
def GetSymbol(self, symbol):
"""Tries to find a symbol in the local database.
@@ -136,7 +136,7 @@ class SymbolDatabase(message_factory.MessageFactory):
may be extended in future to support other symbol types.
Args:
- symbol (str): a protocol buffer symbol.
+ symbol (str): a protocol buffer symbol.
Returns:
A Python class corresponding to the symbol.
@@ -157,7 +157,7 @@ class SymbolDatabase(message_factory.MessageFactory):
messages, but does not register any message extensions.
Args:
- files (list[str]): The file names to extract messages from.
+ files (list[str]): The file names to extract messages from.
Returns:
A dictionary mapping proto names to the message classes.
diff --git a/contrib/python/protobuf/py2/google/protobuf/text_format.py b/contrib/python/protobuf/py2/google/protobuf/text_format.py
index 9c4ca90ee6..e8c0477b4b 100644
--- a/contrib/python/protobuf/py2/google/protobuf/text_format.py
+++ b/contrib/python/protobuf/py2/google/protobuf/text_format.py
@@ -30,7 +30,7 @@
"""Contains routines for printing protocol messages in text format.
-Simple usage example::
+Simple usage example::
# Create a proto object and serialize it to a text proto string.
message = my_proto_pb2.MyMessage(foo='bar')
@@ -42,32 +42,32 @@ Simple usage example::
__author__ = 'kenton@google.com (Kenton Varda)'
-# TODO(b/129989314) Import thread contention leads to test failures.
-import encodings.raw_unicode_escape # pylint: disable=unused-import
-import encodings.unicode_escape # pylint: disable=unused-import
+# TODO(b/129989314) Import thread contention leads to test failures.
+import encodings.raw_unicode_escape # pylint: disable=unused-import
+import encodings.unicode_escape # pylint: disable=unused-import
import io
-import math
+import math
import re
import six
-from google.protobuf.internal import decoder
-from google.protobuf.internal import type_checkers
-from google.protobuf import descriptor
-from google.protobuf import text_encoding
-
+from google.protobuf.internal import decoder
+from google.protobuf.internal import type_checkers
+from google.protobuf import descriptor
+from google.protobuf import text_encoding
+
if six.PY3:
long = int # pylint: disable=redefined-builtin,invalid-name
# pylint: disable=g-import-not-at-top
-__all__ = ['MessageToString', 'Parse', 'PrintMessage', 'PrintField',
- 'PrintFieldValue', 'Merge', 'MessageToBytes']
+__all__ = ['MessageToString', 'Parse', 'PrintMessage', 'PrintField',
+ 'PrintFieldValue', 'Merge', 'MessageToBytes']
_INTEGER_CHECKERS = (type_checkers.Uint32ValueChecker(),
type_checkers.Int32ValueChecker(),
type_checkers.Uint64ValueChecker(),
type_checkers.Int64ValueChecker())
-_FLOAT_INFINITY = re.compile('-?inf(?:inity)?f?$', re.IGNORECASE)
-_FLOAT_NAN = re.compile('nanf?$', re.IGNORECASE)
+_FLOAT_INFINITY = re.compile('-?inf(?:inity)?f?$', re.IGNORECASE)
+_FLOAT_NAN = re.compile('nanf?$', re.IGNORECASE)
_QUOTES = frozenset(("'", '"'))
_ANY_FULL_TYPE_NAME = 'google.protobuf.Any'
@@ -120,80 +120,80 @@ class TextWriter(object):
return self._writer.getvalue()
-def MessageToString(
- message,
- as_utf8=False,
- as_one_line=False,
- use_short_repeated_primitives=False,
- pointy_brackets=False,
- use_index_order=False,
- float_format=None,
- double_format=None,
- use_field_number=False,
- descriptor_pool=None,
- indent=0,
- message_formatter=None,
- print_unknown_fields=False,
- force_colon=False):
- # type: (...) -> str
+def MessageToString(
+ message,
+ as_utf8=False,
+ as_one_line=False,
+ use_short_repeated_primitives=False,
+ pointy_brackets=False,
+ use_index_order=False,
+ float_format=None,
+ double_format=None,
+ use_field_number=False,
+ descriptor_pool=None,
+ indent=0,
+ message_formatter=None,
+ print_unknown_fields=False,
+ force_colon=False):
+ # type: (...) -> str
"""Convert protobuf message to text format.
- Double values can be formatted compactly with 15 digits of
+ Double values can be formatted compactly with 15 digits of
precision (which is the most that IEEE 754 "double" can guarantee)
- using double_format='.15g'. To ensure that converting to text and back to a
- proto will result in an identical value, double_format='.17g' should be used.
+ using double_format='.15g'. To ensure that converting to text and back to a
+ proto will result in an identical value, double_format='.17g' should be used.
Args:
message: The protocol buffers message.
- as_utf8: Return unescaped Unicode for non-ASCII characters.
- In Python 3 actual Unicode characters may appear as is in strings.
- In Python 2 the return value will be valid UTF-8 rather than only ASCII.
+ as_utf8: Return unescaped Unicode for non-ASCII characters.
+ In Python 3 actual Unicode characters may appear as is in strings.
+ In Python 2 the return value will be valid UTF-8 rather than only ASCII.
as_one_line: Don't introduce newlines between fields.
- use_short_repeated_primitives: Use short repeated format for primitives.
+ use_short_repeated_primitives: Use short repeated format for primitives.
pointy_brackets: If True, use angle brackets instead of curly braces for
nesting.
- use_index_order: If True, fields of a proto message will be printed using
- the order defined in source code instead of the field number, extensions
- will be printed at the end of the message and their relative order is
- determined by the extension number. By default, use the field number
- order.
- float_format (str): If set, use this to specify float field formatting
- (per the "Format Specification Mini-Language"); otherwise, shortest float
- that has same value in wire will be printed. Also affect double field
- if double_format is not set but float_format is set.
- double_format (str): If set, use this to specify double field formatting
- (per the "Format Specification Mini-Language"); if it is not set but
- float_format is set, use float_format. Otherwise, use ``str()``
+ use_index_order: If True, fields of a proto message will be printed using
+ the order defined in source code instead of the field number, extensions
+ will be printed at the end of the message and their relative order is
+ determined by the extension number. By default, use the field number
+ order.
+ float_format (str): If set, use this to specify float field formatting
+ (per the "Format Specification Mini-Language"); otherwise, shortest float
+ that has same value in wire will be printed. Also affect double field
+ if double_format is not set but float_format is set.
+ double_format (str): If set, use this to specify double field formatting
+ (per the "Format Specification Mini-Language"); if it is not set but
+ float_format is set, use float_format. Otherwise, use ``str()``
use_field_number: If True, print field numbers instead of names.
- descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
- indent (int): The initial indent level, in terms of spaces, for pretty
- print.
- message_formatter (function(message, indent, as_one_line) -> unicode|None):
- Custom formatter for selected sub-messages (usually based on message
- type). Use to pretty print parts of the protobuf for easier diffing.
- print_unknown_fields: If True, unknown fields will be printed.
- force_colon: If set, a colon will be added after the field name even if the
- field is a proto message.
+ descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
+ indent (int): The initial indent level, in terms of spaces, for pretty
+ print.
+ message_formatter (function(message, indent, as_one_line) -> unicode|None):
+ Custom formatter for selected sub-messages (usually based on message
+ type). Use to pretty print parts of the protobuf for easier diffing.
+ print_unknown_fields: If True, unknown fields will be printed.
+ force_colon: If set, a colon will be added after the field name even if the
+ field is a proto message.
Returns:
- str: A string of the text formatted protocol buffer message.
+ str: A string of the text formatted protocol buffer message.
"""
out = TextWriter(as_utf8)
- printer = _Printer(
- out,
- indent,
- as_utf8,
- as_one_line,
- use_short_repeated_primitives,
- pointy_brackets,
- use_index_order,
- float_format,
- double_format,
- use_field_number,
- descriptor_pool,
- message_formatter,
- print_unknown_fields=print_unknown_fields,
- force_colon=force_colon)
+ printer = _Printer(
+ out,
+ indent,
+ as_utf8,
+ as_one_line,
+ use_short_repeated_primitives,
+ pointy_brackets,
+ use_index_order,
+ float_format,
+ double_format,
+ use_field_number,
+ descriptor_pool,
+ message_formatter,
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintMessage(message)
result = out.getvalue()
out.close()
@@ -202,16 +202,16 @@ def MessageToString(
return result
-def MessageToBytes(message, **kwargs):
- # type: (...) -> bytes
- """Convert protobuf message to encoded text format. See MessageToString."""
- text = MessageToString(message, **kwargs)
- if isinstance(text, bytes):
- return text
- codec = 'utf-8' if kwargs.get('as_utf8') else 'ascii'
- return text.encode(codec)
-
-
+def MessageToBytes(message, **kwargs):
+ # type: (...) -> bytes
+ """Convert protobuf message to encoded text format. See MessageToString."""
+ text = MessageToString(message, **kwargs)
+ if isinstance(text, bytes):
+ return text
+ codec = 'utf-8' if kwargs.get('as_utf8') else 'ascii'
+ return text.encode(codec)
+
+
def _IsMapEntry(field):
return (field.type == descriptor.FieldDescriptor.TYPE_MESSAGE and
field.message_type.has_options and
@@ -223,29 +223,29 @@ def PrintMessage(message,
indent=0,
as_utf8=False,
as_one_line=False,
- use_short_repeated_primitives=False,
+ use_short_repeated_primitives=False,
pointy_brackets=False,
use_index_order=False,
float_format=None,
- double_format=None,
+ double_format=None,
use_field_number=False,
descriptor_pool=None,
- message_formatter=None,
- print_unknown_fields=False,
- force_colon=False):
- printer = _Printer(
- out=out, indent=indent, as_utf8=as_utf8,
- as_one_line=as_one_line,
- use_short_repeated_primitives=use_short_repeated_primitives,
- pointy_brackets=pointy_brackets,
- use_index_order=use_index_order,
- float_format=float_format,
- double_format=double_format,
- use_field_number=use_field_number,
- descriptor_pool=descriptor_pool,
- message_formatter=message_formatter,
- print_unknown_fields=print_unknown_fields,
- force_colon=force_colon)
+ message_formatter=None,
+ print_unknown_fields=False,
+ force_colon=False):
+ printer = _Printer(
+ out=out, indent=indent, as_utf8=as_utf8,
+ as_one_line=as_one_line,
+ use_short_repeated_primitives=use_short_repeated_primitives,
+ pointy_brackets=pointy_brackets,
+ use_index_order=use_index_order,
+ float_format=float_format,
+ double_format=double_format,
+ use_field_number=use_field_number,
+ descriptor_pool=descriptor_pool,
+ message_formatter=message_formatter,
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintMessage(message)
@@ -255,21 +255,21 @@ def PrintField(field,
indent=0,
as_utf8=False,
as_one_line=False,
- use_short_repeated_primitives=False,
+ use_short_repeated_primitives=False,
pointy_brackets=False,
use_index_order=False,
float_format=None,
- double_format=None,
- message_formatter=None,
- print_unknown_fields=False,
- force_colon=False):
+ double_format=None,
+ message_formatter=None,
+ print_unknown_fields=False,
+ force_colon=False):
"""Print a single field name/value pair."""
- printer = _Printer(out, indent, as_utf8, as_one_line,
- use_short_repeated_primitives, pointy_brackets,
- use_index_order, float_format, double_format,
- message_formatter=message_formatter,
- print_unknown_fields=print_unknown_fields,
- force_colon=force_colon)
+ printer = _Printer(out, indent, as_utf8, as_one_line,
+ use_short_repeated_primitives, pointy_brackets,
+ use_index_order, float_format, double_format,
+ message_formatter=message_formatter,
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintField(field, value)
@@ -279,21 +279,21 @@ def PrintFieldValue(field,
indent=0,
as_utf8=False,
as_one_line=False,
- use_short_repeated_primitives=False,
+ use_short_repeated_primitives=False,
pointy_brackets=False,
use_index_order=False,
float_format=None,
- double_format=None,
- message_formatter=None,
- print_unknown_fields=False,
- force_colon=False):
+ double_format=None,
+ message_formatter=None,
+ print_unknown_fields=False,
+ force_colon=False):
"""Print a single field value (not including name)."""
- printer = _Printer(out, indent, as_utf8, as_one_line,
- use_short_repeated_primitives, pointy_brackets,
- use_index_order, float_format, double_format,
- message_formatter=message_formatter,
- print_unknown_fields=print_unknown_fields,
- force_colon=force_colon)
+ printer = _Printer(out, indent, as_utf8, as_one_line,
+ use_short_repeated_primitives, pointy_brackets,
+ use_index_order, float_format, double_format,
+ message_formatter=message_formatter,
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintFieldValue(field, value)
@@ -322,94 +322,94 @@ def _BuildMessageFromTypeName(type_name, descriptor_pool):
return message_type()
-# These values must match WireType enum in google/protobuf/wire_format.h.
-WIRETYPE_LENGTH_DELIMITED = 2
-WIRETYPE_START_GROUP = 3
-
-
+# These values must match WireType enum in google/protobuf/wire_format.h.
+WIRETYPE_LENGTH_DELIMITED = 2
+WIRETYPE_START_GROUP = 3
+
+
class _Printer(object):
"""Text format printer for protocol message."""
- def __init__(
- self,
- out,
- indent=0,
- as_utf8=False,
- as_one_line=False,
- use_short_repeated_primitives=False,
- pointy_brackets=False,
- use_index_order=False,
- float_format=None,
- double_format=None,
- use_field_number=False,
- descriptor_pool=None,
- message_formatter=None,
- print_unknown_fields=False,
- force_colon=False):
+ def __init__(
+ self,
+ out,
+ indent=0,
+ as_utf8=False,
+ as_one_line=False,
+ use_short_repeated_primitives=False,
+ pointy_brackets=False,
+ use_index_order=False,
+ float_format=None,
+ double_format=None,
+ use_field_number=False,
+ descriptor_pool=None,
+ message_formatter=None,
+ print_unknown_fields=False,
+ force_colon=False):
"""Initialize the Printer.
- Double values can be formatted compactly with 15 digits of precision
- (which is the most that IEEE 754 "double" can guarantee) using
- double_format='.15g'. To ensure that converting to text and back to a proto
- will result in an identical value, double_format='.17g' should be used.
+ Double values can be formatted compactly with 15 digits of precision
+ (which is the most that IEEE 754 "double" can guarantee) using
+ double_format='.15g'. To ensure that converting to text and back to a proto
+ will result in an identical value, double_format='.17g' should be used.
Args:
out: To record the text format result.
- indent: The initial indent level for pretty print.
- as_utf8: Return unescaped Unicode for non-ASCII characters.
- In Python 3 actual Unicode characters may appear as is in strings.
- In Python 2 the return value will be valid UTF-8 rather than ASCII.
+ indent: The initial indent level for pretty print.
+ as_utf8: Return unescaped Unicode for non-ASCII characters.
+ In Python 3 actual Unicode characters may appear as is in strings.
+ In Python 2 the return value will be valid UTF-8 rather than ASCII.
as_one_line: Don't introduce newlines between fields.
- use_short_repeated_primitives: Use short repeated format for primitives.
+ use_short_repeated_primitives: Use short repeated format for primitives.
pointy_brackets: If True, use angle brackets instead of curly braces for
nesting.
use_index_order: If True, print fields of a proto message using the order
defined in source code instead of the field number. By default, use the
field number order.
- float_format: If set, use this to specify float field formatting
- (per the "Format Specification Mini-Language"); otherwise, shortest
- float that has same value in wire will be printed. Also affect double
- field if double_format is not set but float_format is set.
- double_format: If set, use this to specify double field formatting
- (per the "Format Specification Mini-Language"); if it is not set but
- float_format is set, use float_format. Otherwise, str() is used.
+ float_format: If set, use this to specify float field formatting
+ (per the "Format Specification Mini-Language"); otherwise, shortest
+ float that has same value in wire will be printed. Also affect double
+ field if double_format is not set but float_format is set.
+ double_format: If set, use this to specify double field formatting
+ (per the "Format Specification Mini-Language"); if it is not set but
+ float_format is set, use float_format. Otherwise, str() is used.
use_field_number: If True, print field numbers instead of names.
descriptor_pool: A DescriptorPool used to resolve Any types.
message_formatter: A function(message, indent, as_one_line): unicode|None
to custom format selected sub-messages (usually based on message type).
Use to pretty print parts of the protobuf for easier diffing.
- print_unknown_fields: If True, unknown fields will be printed.
- force_colon: If set, a colon will be added after the field name even if
- the field is a proto message.
+ print_unknown_fields: If True, unknown fields will be printed.
+ force_colon: If set, a colon will be added after the field name even if
+ the field is a proto message.
"""
self.out = out
self.indent = indent
self.as_utf8 = as_utf8
self.as_one_line = as_one_line
- self.use_short_repeated_primitives = use_short_repeated_primitives
+ self.use_short_repeated_primitives = use_short_repeated_primitives
self.pointy_brackets = pointy_brackets
self.use_index_order = use_index_order
self.float_format = float_format
- if double_format is not None:
- self.double_format = double_format
- else:
- self.double_format = float_format
+ if double_format is not None:
+ self.double_format = double_format
+ else:
+ self.double_format = float_format
self.use_field_number = use_field_number
self.descriptor_pool = descriptor_pool
self.message_formatter = message_formatter
- self.print_unknown_fields = print_unknown_fields
- self.force_colon = force_colon
+ self.print_unknown_fields = print_unknown_fields
+ self.force_colon = force_colon
def _TryPrintAsAnyMessage(self, message):
"""Serializes if message is a google.protobuf.Any field."""
- if '/' not in message.type_url:
- return False
+ if '/' not in message.type_url:
+ return False
packed_message = _BuildMessageFromTypeName(message.TypeName(),
self.descriptor_pool)
if packed_message:
packed_message.MergeFromString(message.value)
- colon = ':' if self.force_colon else ''
- self.out.write('%s[%s]%s ' % (self.indent * ' ', message.type_url, colon))
+ colon = ':' if self.force_colon else ''
+ self.out.write('%s[%s]%s ' % (self.indent * ' ', message.type_url, colon))
self._PrintMessageFieldValue(packed_message)
self.out.write(' ' if self.as_one_line else '\n')
return True
@@ -440,12 +440,12 @@ class _Printer(object):
return
fields = message.ListFields()
if self.use_index_order:
- fields.sort(
- key=lambda x: x[0].number if x[0].is_extension else x[0].index)
+ fields.sort(
+ key=lambda x: x[0].number if x[0].is_extension else x[0].index)
for field, value in fields:
if _IsMapEntry(field):
for key in sorted(value):
- # This is slow for maps with submessage entries because it copies the
+ # This is slow for maps with submessage entries because it copies the
# entire tree. Unfortunately this would take significant refactoring
# of this file to work around.
#
@@ -453,77 +453,77 @@ class _Printer(object):
entry_submsg = value.GetEntryClass()(key=key, value=value[key])
self.PrintField(field, entry_submsg)
elif field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
- if (self.use_short_repeated_primitives
- and field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE
- and field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_STRING):
- self._PrintShortRepeatedPrimitivesValue(field, value)
- else:
- for element in value:
- self.PrintField(field, element)
+ if (self.use_short_repeated_primitives
+ and field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE
+ and field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_STRING):
+ self._PrintShortRepeatedPrimitivesValue(field, value)
+ else:
+ for element in value:
+ self.PrintField(field, element)
else:
self.PrintField(field, value)
- if self.print_unknown_fields:
- self._PrintUnknownFields(message.UnknownFields())
-
- def _PrintUnknownFields(self, unknown_fields):
- """Print unknown fields."""
- out = self.out
- for field in unknown_fields:
- out.write(' ' * self.indent)
- out.write(str(field.field_number))
- if field.wire_type == WIRETYPE_START_GROUP:
- if self.as_one_line:
- out.write(' { ')
- else:
- out.write(' {\n')
- self.indent += 2
-
- self._PrintUnknownFields(field.data)
-
- if self.as_one_line:
- out.write('} ')
- else:
- self.indent -= 2
- out.write(' ' * self.indent + '}\n')
- elif field.wire_type == WIRETYPE_LENGTH_DELIMITED:
- try:
- # If this field is parseable as a Message, it is probably
- # an embedded message.
- # pylint: disable=protected-access
- (embedded_unknown_message, pos) = decoder._DecodeUnknownFieldSet(
- memoryview(field.data), 0, len(field.data))
- except Exception: # pylint: disable=broad-except
- pos = 0
-
- if pos == len(field.data):
- if self.as_one_line:
- out.write(' { ')
- else:
- out.write(' {\n')
- self.indent += 2
-
- self._PrintUnknownFields(embedded_unknown_message)
-
- if self.as_one_line:
- out.write('} ')
- else:
- self.indent -= 2
- out.write(' ' * self.indent + '}\n')
- else:
- # A string or bytes field. self.as_utf8 may not work.
- out.write(': \"')
- out.write(text_encoding.CEscape(field.data, False))
- out.write('\" ' if self.as_one_line else '\"\n')
- else:
- # varint, fixed32, fixed64
- out.write(': ')
- out.write(str(field.data))
- out.write(' ' if self.as_one_line else '\n')
-
- def _PrintFieldName(self, field):
- """Print field name."""
+ if self.print_unknown_fields:
+ self._PrintUnknownFields(message.UnknownFields())
+
+ def _PrintUnknownFields(self, unknown_fields):
+ """Print unknown fields."""
out = self.out
+ for field in unknown_fields:
+ out.write(' ' * self.indent)
+ out.write(str(field.field_number))
+ if field.wire_type == WIRETYPE_START_GROUP:
+ if self.as_one_line:
+ out.write(' { ')
+ else:
+ out.write(' {\n')
+ self.indent += 2
+
+ self._PrintUnknownFields(field.data)
+
+ if self.as_one_line:
+ out.write('} ')
+ else:
+ self.indent -= 2
+ out.write(' ' * self.indent + '}\n')
+ elif field.wire_type == WIRETYPE_LENGTH_DELIMITED:
+ try:
+ # If this field is parseable as a Message, it is probably
+ # an embedded message.
+ # pylint: disable=protected-access
+ (embedded_unknown_message, pos) = decoder._DecodeUnknownFieldSet(
+ memoryview(field.data), 0, len(field.data))
+ except Exception: # pylint: disable=broad-except
+ pos = 0
+
+ if pos == len(field.data):
+ if self.as_one_line:
+ out.write(' { ')
+ else:
+ out.write(' {\n')
+ self.indent += 2
+
+ self._PrintUnknownFields(embedded_unknown_message)
+
+ if self.as_one_line:
+ out.write('} ')
+ else:
+ self.indent -= 2
+ out.write(' ' * self.indent + '}\n')
+ else:
+ # A string or bytes field. self.as_utf8 may not work.
+ out.write(': \"')
+ out.write(text_encoding.CEscape(field.data, False))
+ out.write('\" ' if self.as_one_line else '\"\n')
+ else:
+ # varint, fixed32, fixed64
+ out.write(': ')
+ out.write(str(field.data))
+ out.write(' ' if self.as_one_line else '\n')
+
+ def _PrintFieldName(self, field):
+ """Print field name."""
+ out = self.out
out.write(' ' * self.indent)
if self.use_field_number:
out.write(str(field.number))
@@ -541,34 +541,34 @@ class _Printer(object):
# For groups, use the capitalized name.
out.write(field.message_type.name)
else:
- out.write(field.name)
+ out.write(field.name)
- if (self.force_colon or
- field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE):
+ if (self.force_colon or
+ field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE):
# The colon is optional in this case, but our cross-language golden files
- # don't include it. Here, the colon is only included if force_colon is
- # set to True
- out.write(':')
-
- def PrintField(self, field, value):
- """Print a single field name/value pair."""
- self._PrintFieldName(field)
- self.out.write(' ')
+ # don't include it. Here, the colon is only included if force_colon is
+ # set to True
+ out.write(':')
+
+ def PrintField(self, field, value):
+ """Print a single field name/value pair."""
+ self._PrintFieldName(field)
+ self.out.write(' ')
self.PrintFieldValue(field, value)
- self.out.write(' ' if self.as_one_line else '\n')
-
- def _PrintShortRepeatedPrimitivesValue(self, field, value):
- """"Prints short repeated primitives value."""
- # Note: this is called only when value has at least one element.
- self._PrintFieldName(field)
- self.out.write(' [')
- for i in six.moves.range(len(value) - 1):
- self.PrintFieldValue(field, value[i])
- self.out.write(', ')
- self.PrintFieldValue(field, value[-1])
- self.out.write(']')
- self.out.write(' ' if self.as_one_line else '\n')
-
+ self.out.write(' ' if self.as_one_line else '\n')
+
+ def _PrintShortRepeatedPrimitivesValue(self, field, value):
+ """"Prints short repeated primitives value."""
+ # Note: this is called only when value has at least one element.
+ self._PrintFieldName(field)
+ self.out.write(' [')
+ for i in six.moves.range(len(value) - 1):
+ self.PrintFieldValue(field, value[i])
+ self.out.write(', ')
+ self.PrintFieldValue(field, value[-1])
+ self.out.write(']')
+ self.out.write(' ' if self.as_one_line else '\n')
+
def _PrintMessageFieldValue(self, value):
if self.pointy_brackets:
openb = '<'
@@ -578,11 +578,11 @@ class _Printer(object):
closeb = '}'
if self.as_one_line:
- self.out.write('%s ' % openb)
+ self.out.write('%s ' % openb)
self.PrintMessage(value)
self.out.write(closeb)
else:
- self.out.write('%s\n' % openb)
+ self.out.write('%s\n' % openb)
self.indent += 2
self.PrintMessage(value)
self.indent -= 2
@@ -608,12 +608,12 @@ class _Printer(object):
out.write(str(value))
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_STRING:
out.write('\"')
- if isinstance(value, six.text_type) and (six.PY2 or not self.as_utf8):
- out_value = value.encode('utf-8')
- else:
- out_value = value
+ if isinstance(value, six.text_type) and (six.PY2 or not self.as_utf8):
+ out_value = value.encode('utf-8')
+ else:
+ out_value = value
if field.type == descriptor.FieldDescriptor.TYPE_BYTES:
- # We always need to escape all binary data in TYPE_BYTES fields.
+ # We always need to escape all binary data in TYPE_BYTES fields.
out_as_utf8 = False
else:
out_as_utf8 = self.as_utf8
@@ -624,17 +624,17 @@ class _Printer(object):
out.write('true')
else:
out.write('false')
- elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
- if self.float_format is not None:
- out.write('{1:{0}}'.format(self.float_format, value))
- else:
- if math.isnan(value):
- out.write(str(value))
- else:
- out.write(str(type_checkers.ToShortestFloat(value)))
- elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_DOUBLE and
- self.double_format is not None):
- out.write('{1:{0}}'.format(self.double_format, value))
+ elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
+ if self.float_format is not None:
+ out.write('{1:{0}}'.format(self.float_format, value))
+ else:
+ if math.isnan(value):
+ out.write(str(value))
+ else:
+ out.write(str(type_checkers.ToShortestFloat(value)))
+ elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_DOUBLE and
+ self.double_format is not None):
+ out.write('{1:{0}}'.format(self.double_format, value))
else:
out.write(str(value))
@@ -643,108 +643,108 @@ def Parse(text,
message,
allow_unknown_extension=False,
allow_field_number=False,
- descriptor_pool=None,
- allow_unknown_field=False):
+ descriptor_pool=None,
+ allow_unknown_field=False):
"""Parses a text representation of a protocol message into a message.
NOTE: for historical reasons this function does not clear the input
message. This is different from what the binary msg.ParseFrom(...) does.
- If text contains a field already set in message, the value is appended if the
- field is repeated. Otherwise, an error is raised.
-
- Example::
+ If text contains a field already set in message, the value is appended if the
+ field is repeated. Otherwise, an error is raised.
+ Example::
+
a = MyProto()
a.repeated_field.append('test')
b = MyProto()
- # Repeated fields are combined
+ # Repeated fields are combined
text_format.Parse(repr(a), b)
text_format.Parse(repr(a), b) # repeated_field contains ["test", "test"]
- # Non-repeated fields cannot be overwritten
- a.singular_field = 1
- b.singular_field = 2
- text_format.Parse(repr(a), b) # ParseError
-
+ # Non-repeated fields cannot be overwritten
+ a.singular_field = 1
+ b.singular_field = 2
+ text_format.Parse(repr(a), b) # ParseError
+
# Binary version:
b.ParseFromString(a.SerializeToString()) # repeated_field is now "test"
Caller is responsible for clearing the message as needed.
Args:
- text (str): Message text representation.
- message (Message): A protocol buffer message to merge into.
+ text (str): Message text representation.
+ message (Message): A protocol buffer message to merge into.
allow_unknown_extension: if True, skip over missing extensions and keep
parsing
allow_field_number: if True, both field number and field name are allowed.
- descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
- allow_unknown_field: if True, skip over unknown field and keep
- parsing. Avoid to use this option if possible. It may hide some
- errors (e.g. spelling error on field name)
+ descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
+ allow_unknown_field: if True, skip over unknown field and keep
+ parsing. Avoid to use this option if possible. It may hide some
+ errors (e.g. spelling error on field name)
Returns:
- Message: The same message passed as argument.
+ Message: The same message passed as argument.
Raises:
ParseError: On text parsing problems.
"""
- return ParseLines(text.split(b'\n' if isinstance(text, bytes) else u'\n'),
+ return ParseLines(text.split(b'\n' if isinstance(text, bytes) else u'\n'),
message,
allow_unknown_extension,
allow_field_number,
- descriptor_pool=descriptor_pool,
- allow_unknown_field=allow_unknown_field)
+ descriptor_pool=descriptor_pool,
+ allow_unknown_field=allow_unknown_field)
def Merge(text,
message,
allow_unknown_extension=False,
allow_field_number=False,
- descriptor_pool=None,
- allow_unknown_field=False):
+ descriptor_pool=None,
+ allow_unknown_field=False):
"""Parses a text representation of a protocol message into a message.
Like Parse(), but allows repeated values for a non-repeated field, and uses
- the last one. This means any non-repeated, top-level fields specified in text
- replace those in the message.
+ the last one. This means any non-repeated, top-level fields specified in text
+ replace those in the message.
Args:
- text (str): Message text representation.
- message (Message): A protocol buffer message to merge into.
+ text (str): Message text representation.
+ message (Message): A protocol buffer message to merge into.
allow_unknown_extension: if True, skip over missing extensions and keep
parsing
allow_field_number: if True, both field number and field name are allowed.
- descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
- allow_unknown_field: if True, skip over unknown field and keep
- parsing. Avoid to use this option if possible. It may hide some
- errors (e.g. spelling error on field name)
+ descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
+ allow_unknown_field: if True, skip over unknown field and keep
+ parsing. Avoid to use this option if possible. It may hide some
+ errors (e.g. spelling error on field name)
Returns:
- Message: The same message passed as argument.
+ Message: The same message passed as argument.
Raises:
ParseError: On text parsing problems.
"""
return MergeLines(
- text.split(b'\n' if isinstance(text, bytes) else u'\n'),
+ text.split(b'\n' if isinstance(text, bytes) else u'\n'),
message,
allow_unknown_extension,
allow_field_number,
- descriptor_pool=descriptor_pool,
- allow_unknown_field=allow_unknown_field)
+ descriptor_pool=descriptor_pool,
+ allow_unknown_field=allow_unknown_field)
def ParseLines(lines,
message,
allow_unknown_extension=False,
allow_field_number=False,
- descriptor_pool=None,
- allow_unknown_field=False):
+ descriptor_pool=None,
+ allow_unknown_field=False):
"""Parses a text representation of a protocol message into a message.
- See Parse() for caveats.
-
+ See Parse() for caveats.
+
Args:
lines: An iterable of lines of a message's text representation.
message: A protocol buffer message to merge into.
@@ -752,9 +752,9 @@ def ParseLines(lines,
parsing
allow_field_number: if True, both field number and field name are allowed.
descriptor_pool: A DescriptorPool used to resolve Any types.
- allow_unknown_field: if True, skip over unknown field and keep
- parsing. Avoid to use this option if possible. It may hide some
- errors (e.g. spelling error on field name)
+ allow_unknown_field: if True, skip over unknown field and keep
+ parsing. Avoid to use this option if possible. It may hide some
+ errors (e.g. spelling error on field name)
Returns:
The same message passed as argument.
@@ -764,8 +764,8 @@ def ParseLines(lines,
"""
parser = _Parser(allow_unknown_extension,
allow_field_number,
- descriptor_pool=descriptor_pool,
- allow_unknown_field=allow_unknown_field)
+ descriptor_pool=descriptor_pool,
+ allow_unknown_field=allow_unknown_field)
return parser.ParseLines(lines, message)
@@ -773,12 +773,12 @@ def MergeLines(lines,
message,
allow_unknown_extension=False,
allow_field_number=False,
- descriptor_pool=None,
- allow_unknown_field=False):
+ descriptor_pool=None,
+ allow_unknown_field=False):
"""Parses a text representation of a protocol message into a message.
- See Merge() for more details.
-
+ See Merge() for more details.
+
Args:
lines: An iterable of lines of a message's text representation.
message: A protocol buffer message to merge into.
@@ -786,9 +786,9 @@ def MergeLines(lines,
parsing
allow_field_number: if True, both field number and field name are allowed.
descriptor_pool: A DescriptorPool used to resolve Any types.
- allow_unknown_field: if True, skip over unknown field and keep
- parsing. Avoid to use this option if possible. It may hide some
- errors (e.g. spelling error on field name)
+ allow_unknown_field: if True, skip over unknown field and keep
+ parsing. Avoid to use this option if possible. It may hide some
+ errors (e.g. spelling error on field name)
Returns:
The same message passed as argument.
@@ -798,8 +798,8 @@ def MergeLines(lines,
"""
parser = _Parser(allow_unknown_extension,
allow_field_number,
- descriptor_pool=descriptor_pool,
- allow_unknown_field=allow_unknown_field)
+ descriptor_pool=descriptor_pool,
+ allow_unknown_field=allow_unknown_field)
return parser.MergeLines(lines, message)
@@ -809,12 +809,12 @@ class _Parser(object):
def __init__(self,
allow_unknown_extension=False,
allow_field_number=False,
- descriptor_pool=None,
- allow_unknown_field=False):
+ descriptor_pool=None,
+ allow_unknown_field=False):
self.allow_unknown_extension = allow_unknown_extension
self.allow_field_number = allow_field_number
self.descriptor_pool = descriptor_pool
- self.allow_unknown_field = allow_unknown_field
+ self.allow_unknown_field = allow_unknown_field
def ParseLines(self, lines, message):
"""Parses a text representation of a protocol message into a message."""
@@ -838,14 +838,14 @@ class _Parser(object):
Raises:
ParseError: On text parsing problems.
"""
- # Tokenize expects native str lines.
- if six.PY2:
- str_lines = (line if isinstance(line, str) else line.encode('utf-8')
- for line in lines)
- else:
- str_lines = (line if isinstance(line, str) else line.decode('utf-8')
- for line in lines)
- tokenizer = Tokenizer(str_lines)
+ # Tokenize expects native str lines.
+ if six.PY2:
+ str_lines = (line if isinstance(line, str) else line.encode('utf-8')
+ for line in lines)
+ else:
+ str_lines = (line if isinstance(line, str) else line.decode('utf-8')
+ for line in lines)
+ tokenizer = Tokenizer(str_lines)
while not tokenizer.AtEnd():
self._MergeField(tokenizer, message)
@@ -860,33 +860,33 @@ class _Parser(object):
ParseError: In case of text parsing problems.
"""
message_descriptor = message.DESCRIPTOR
- if (message_descriptor.full_name == _ANY_FULL_TYPE_NAME and
- tokenizer.TryConsume('[')):
- type_url_prefix, packed_type_name = self._ConsumeAnyTypeUrl(tokenizer)
- tokenizer.Consume(']')
- tokenizer.TryConsume(':')
- if tokenizer.TryConsume('<'):
- expanded_any_end_token = '>'
- else:
- tokenizer.Consume('{')
- expanded_any_end_token = '}'
- expanded_any_sub_message = _BuildMessageFromTypeName(packed_type_name,
- self.descriptor_pool)
- if not expanded_any_sub_message:
- raise ParseError('Type %s not found in descriptor pool' %
- packed_type_name)
- while not tokenizer.TryConsume(expanded_any_end_token):
- if tokenizer.AtEnd():
- raise tokenizer.ParseErrorPreviousToken('Expected "%s".' %
- (expanded_any_end_token,))
- self._MergeField(tokenizer, expanded_any_sub_message)
- deterministic = False
-
- message.Pack(expanded_any_sub_message,
- type_url_prefix=type_url_prefix,
- deterministic=deterministic)
- return
-
+ if (message_descriptor.full_name == _ANY_FULL_TYPE_NAME and
+ tokenizer.TryConsume('[')):
+ type_url_prefix, packed_type_name = self._ConsumeAnyTypeUrl(tokenizer)
+ tokenizer.Consume(']')
+ tokenizer.TryConsume(':')
+ if tokenizer.TryConsume('<'):
+ expanded_any_end_token = '>'
+ else:
+ tokenizer.Consume('{')
+ expanded_any_end_token = '}'
+ expanded_any_sub_message = _BuildMessageFromTypeName(packed_type_name,
+ self.descriptor_pool)
+ if not expanded_any_sub_message:
+ raise ParseError('Type %s not found in descriptor pool' %
+ packed_type_name)
+ while not tokenizer.TryConsume(expanded_any_end_token):
+ if tokenizer.AtEnd():
+ raise tokenizer.ParseErrorPreviousToken('Expected "%s".' %
+ (expanded_any_end_token,))
+ self._MergeField(tokenizer, expanded_any_sub_message)
+ deterministic = False
+
+ message.Pack(expanded_any_sub_message,
+ type_url_prefix=type_url_prefix,
+ deterministic=deterministic)
+ return
+
if tokenizer.TryConsume('['):
name = [tokenizer.ConsumeIdentifier()]
while tokenizer.TryConsume('.'):
@@ -900,8 +900,8 @@ class _Parser(object):
# pylint: disable=protected-access
field = message.Extensions._FindExtensionByName(name)
# pylint: enable=protected-access
-
-
+
+
if not field:
if self.allow_unknown_extension:
field = None
@@ -941,7 +941,7 @@ class _Parser(object):
field.message_type.name != name):
field = None
- if not field and not self.allow_unknown_field:
+ if not field and not self.allow_unknown_field:
raise tokenizer.ParseErrorPreviousToken(
'Message type "%s" has no field named "%s".' %
(message_descriptor.full_name, name))
@@ -969,18 +969,18 @@ class _Parser(object):
if (field.label == descriptor.FieldDescriptor.LABEL_REPEATED and
tokenizer.TryConsume('[')):
# Short repeated format, e.g. "foo: [1, 2, 3]"
- if not tokenizer.TryConsume(']'):
- while True:
- merger(tokenizer, message, field)
- if tokenizer.TryConsume(']'):
- break
- tokenizer.Consume(',')
+ if not tokenizer.TryConsume(']'):
+ while True:
+ merger(tokenizer, message, field)
+ if tokenizer.TryConsume(']'):
+ break
+ tokenizer.Consume(',')
else:
merger(tokenizer, message, field)
else: # Proto field is unknown.
- assert (self.allow_unknown_extension or self.allow_unknown_field)
+ assert (self.allow_unknown_extension or self.allow_unknown_field)
_SkipFieldContents(tokenizer)
# For historical reasons, fields may optionally be separated by commas or
@@ -988,7 +988,7 @@ class _Parser(object):
if not tokenizer.TryConsume(','):
tokenizer.TryConsume(';')
-
+
def _ConsumeAnyTypeUrl(self, tokenizer):
"""Consumes a google.protobuf.Any type URL and returns the type name."""
# Consume "type.googleapis.com/".
@@ -1023,7 +1023,7 @@ class _Parser(object):
tokenizer.Consume('{')
end_token = '}'
- if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
+ if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
if field.is_extension:
sub_message = message.Extensions[field].add()
elif is_map_entry:
@@ -1032,20 +1032,20 @@ class _Parser(object):
sub_message = getattr(message, field.name).add()
else:
if field.is_extension:
- if (not self._allow_multiple_scalars and
- message.HasExtension(field)):
- raise tokenizer.ParseErrorPreviousToken(
- 'Message type "%s" should not have multiple "%s" extensions.' %
- (message.DESCRIPTOR.full_name, field.full_name))
+ if (not self._allow_multiple_scalars and
+ message.HasExtension(field)):
+ raise tokenizer.ParseErrorPreviousToken(
+ 'Message type "%s" should not have multiple "%s" extensions.' %
+ (message.DESCRIPTOR.full_name, field.full_name))
sub_message = message.Extensions[field]
else:
- # Also apply _allow_multiple_scalars to message field.
- # TODO(jieluo): Change to _allow_singular_overwrites.
- if (not self._allow_multiple_scalars and
- message.HasField(field.name)):
- raise tokenizer.ParseErrorPreviousToken(
- 'Message type "%s" should not have multiple "%s" fields.' %
- (message.DESCRIPTOR.full_name, field.name))
+ # Also apply _allow_multiple_scalars to message field.
+ # TODO(jieluo): Change to _allow_singular_overwrites.
+ if (not self._allow_multiple_scalars and
+ message.HasField(field.name)):
+ raise tokenizer.ParseErrorPreviousToken(
+ 'Message type "%s" should not have multiple "%s" fields.' %
+ (message.DESCRIPTOR.full_name, field.name))
sub_message = getattr(message, field.name)
sub_message.SetInParent()
@@ -1058,7 +1058,7 @@ class _Parser(object):
value_cpptype = field.message_type.fields_by_name['value'].cpp_type
if value_cpptype == descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
value = getattr(message, field.name)[sub_message.key]
- value.CopyFrom(sub_message.value)
+ value.CopyFrom(sub_message.value)
else:
getattr(message, field.name)[sub_message.key] = sub_message.value
@@ -1118,8 +1118,8 @@ class _Parser(object):
getattr(message, field.name).append(value)
else:
if field.is_extension:
- if (not self._allow_multiple_scalars and
- not self._IsProto3Syntax(message) and
+ if (not self._allow_multiple_scalars and
+ not self._IsProto3Syntax(message) and
message.HasExtension(field)):
raise tokenizer.ParseErrorPreviousToken(
'Message type "%s" should not have multiple "%s" extensions.' %
@@ -1127,16 +1127,16 @@ class _Parser(object):
else:
message.Extensions[field] = value
else:
- duplicate_error = False
- if not self._allow_multiple_scalars:
- if self._IsProto3Syntax(message):
- # Proto3 doesn't represent presence so we try best effort to check
- # multiple scalars by compare to default values.
- duplicate_error = bool(getattr(message, field.name))
- else:
- duplicate_error = message.HasField(field.name)
-
- if duplicate_error:
+ duplicate_error = False
+ if not self._allow_multiple_scalars:
+ if self._IsProto3Syntax(message):
+ # Proto3 doesn't represent presence so we try best effort to check
+ # multiple scalars by compare to default values.
+ duplicate_error = bool(getattr(message, field.name))
+ else:
+ duplicate_error = message.HasField(field.name)
+
+ if duplicate_error:
raise tokenizer.ParseErrorPreviousToken(
'Message type "%s" should not have multiple "%s" fields.' %
(message.DESCRIPTOR.full_name, field.name))
@@ -1176,7 +1176,7 @@ def _SkipField(tokenizer):
tokenizer.ConsumeIdentifier()
tokenizer.Consume(']')
else:
- tokenizer.ConsumeIdentifierOrNumber()
+ tokenizer.ConsumeIdentifierOrNumber()
_SkipFieldContents(tokenizer)
@@ -1243,9 +1243,9 @@ class Tokenizer(object):
r'[a-zA-Z_][0-9a-zA-Z_+-]*', # an identifier
r'([0-9+-]|(\.[0-9]))[0-9a-zA-Z_.+-]*', # a number
] + [ # quoted str for each quote mark
- # Avoid backtracking! https://stackoverflow.com/a/844267
- r'{qt}[^{qt}\n\\]*((\\.)+[^{qt}\n\\]*)*({qt}|\\?$)'.format(qt=mark)
- for mark in _QUOTES
+ # Avoid backtracking! https://stackoverflow.com/a/844267
+ r'{qt}[^{qt}\n\\]*((\\.)+[^{qt}\n\\]*)*({qt}|\\?$)'.format(qt=mark)
+ for mark in _QUOTES
]))
_IDENTIFIER = re.compile(r'[^\d\W]\w*')
@@ -1474,11 +1474,11 @@ class Tokenizer(object):
Raises:
ParseError: If a string value couldn't be consumed.
"""
- the_bytes = self.ConsumeByteString()
- try:
- return six.text_type(the_bytes, 'utf-8')
- except UnicodeDecodeError as e:
- raise self._StringParseError(e)
+ the_bytes = self.ConsumeByteString()
+ try:
+ return six.text_type(the_bytes, 'utf-8')
+ except UnicodeDecodeError as e:
+ raise self._StringParseError(e)
def ConsumeByteString(self):
"""Consumes a byte array value.
@@ -1542,8 +1542,8 @@ class Tokenizer(object):
def ParseError(self, message):
"""Creates and *returns* a ParseError for the current token."""
- return ParseError('\'' + self._current_line + '\': ' + message,
- self._line + 1, self._column + 1)
+ return ParseError('\'' + self._current_line + '\': ' + message,
+ self._line + 1, self._column + 1)
def _StringParseError(self, e):
return self.ParseError('Couldn\'t parse string: ' + str(e))
@@ -1717,12 +1717,12 @@ def _ParseAbstractInteger(text, is_long=False):
ValueError: Thrown Iff the text is not a valid integer.
"""
# Do the actual parsing. Exception handling is propagated to caller.
- orig_text = text
- c_octal_match = re.match(r'(-?)0(\d+)$', text)
- if c_octal_match:
- # Python 3 no longer supports 0755 octal syntax without the 'o', so
- # we always use the '0o' prefix for multi-digit numbers starting with 0.
- text = c_octal_match.group(1) + '0o' + c_octal_match.group(2)
+ orig_text = text
+ c_octal_match = re.match(r'(-?)0(\d+)$', text)
+ if c_octal_match:
+ # Python 3 no longer supports 0755 octal syntax without the 'o', so
+ # we always use the '0o' prefix for multi-digit numbers starting with 0.
+ text = c_octal_match.group(1) + '0o' + c_octal_match.group(2)
try:
# We force 32-bit values to int and 64-bit values to long to make
# alternate implementations where the distinction is more significant
@@ -1732,7 +1732,7 @@ def _ParseAbstractInteger(text, is_long=False):
else:
return int(text, 0)
except ValueError:
- raise ValueError('Couldn\'t parse integer: %s' % orig_text)
+ raise ValueError('Couldn\'t parse integer: %s' % orig_text)
def ParseFloat(text):
@@ -1814,11 +1814,11 @@ def ParseEnum(field, value):
(enum_descriptor.full_name, value))
else:
# Numeric value.
- if hasattr(field.file, 'syntax'):
- # Attribute is checked for compatibility.
- if field.file.syntax == 'proto3':
- # Proto3 accept numeric unknown enums.
- return number
+ if hasattr(field.file, 'syntax'):
+ # Attribute is checked for compatibility.
+ if field.file.syntax == 'proto3':
+ # Proto3 accept numeric unknown enums.
+ return number
enum_value = enum_descriptor.values_by_number.get(number, None)
if enum_value is None:
raise ValueError('Enum type "%s" has no value with number %d.' %
diff --git a/contrib/python/protobuf/py2/ya.make b/contrib/python/protobuf/py2/ya.make
index 523478a20a..83dd5f00bd 100644
--- a/contrib/python/protobuf/py2/ya.make
+++ b/contrib/python/protobuf/py2/ya.make
@@ -1,93 +1,93 @@
-PY2_LIBRARY()
-
-LICENSE(BSD-3-Clause)
-
-LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
-
-OWNER(
- g:cpp-committee
- g:cpp-contrib
-)
-
-VERSION(3.17.3)
-
-ORIGINAL_SOURCE(https://github.com/protocolbuffers/protobuf/archive/v3.17.3.tar.gz)
-
-PEERDIR(
- contrib/libs/protobuf
- contrib/libs/protobuf/builtin_proto/protos_from_protobuf
- contrib/libs/protobuf/builtin_proto/protos_from_protoc
- contrib/python/six
-)
-
-ADDINCL(
- contrib/python/protobuf/py2
-)
-
-NO_COMPILER_WARNINGS()
-
-NO_LINT()
-
-CFLAGS(
- -DPYTHON_PROTO2_CPP_IMPL_V2
-)
-
-SRCS(
- google/protobuf/internal/api_implementation.cc
- google/protobuf/pyext/descriptor.cc
- google/protobuf/pyext/descriptor_containers.cc
- google/protobuf/pyext/descriptor_database.cc
- google/protobuf/pyext/descriptor_pool.cc
- google/protobuf/pyext/extension_dict.cc
- google/protobuf/pyext/field.cc
- google/protobuf/pyext/map_container.cc
- google/protobuf/pyext/message.cc
- google/protobuf/pyext/message_factory.cc
- google/protobuf/pyext/message_module.cc
- google/protobuf/pyext/repeated_composite_container.cc
- google/protobuf/pyext/repeated_scalar_container.cc
- google/protobuf/pyext/unknown_fields.cc
-)
-
-PY_REGISTER(
- google.protobuf.internal._api_implementation
- google.protobuf.pyext._message
-)
-
-PY_SRCS(
- TOP_LEVEL
- google/__init__.py
- google/protobuf/__init__.py
- google/protobuf/compiler/__init__.py
- google/protobuf/descriptor.py
- google/protobuf/descriptor_database.py
- google/protobuf/descriptor_pool.py
- google/protobuf/internal/__init__.py
- google/protobuf/internal/_parameterized.py
- google/protobuf/internal/api_implementation.py
- google/protobuf/internal/containers.py
- google/protobuf/internal/decoder.py
- google/protobuf/internal/encoder.py
- google/protobuf/internal/enum_type_wrapper.py
- google/protobuf/internal/extension_dict.py
- google/protobuf/internal/message_listener.py
- google/protobuf/internal/python_message.py
- google/protobuf/internal/type_checkers.py
- google/protobuf/internal/well_known_types.py
- google/protobuf/internal/wire_format.py
- google/protobuf/json_format.py
- google/protobuf/message.py
- google/protobuf/message_factory.py
- google/protobuf/proto_builder.py
- google/protobuf/pyext/__init__.py
- google/protobuf/pyext/cpp_message.py
- google/protobuf/reflection.py
- google/protobuf/service.py
- google/protobuf/service_reflection.py
- google/protobuf/symbol_database.py
- google/protobuf/text_encoding.py
- google/protobuf/text_format.py
- google/protobuf/util/__init__.py
-)
-
-END()
+PY2_LIBRARY()
+
+LICENSE(BSD-3-Clause)
+
+LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
+
+OWNER(
+ g:cpp-committee
+ g:cpp-contrib
+)
+
+VERSION(3.17.3)
+
+ORIGINAL_SOURCE(https://github.com/protocolbuffers/protobuf/archive/v3.17.3.tar.gz)
+
+PEERDIR(
+ contrib/libs/protobuf
+ contrib/libs/protobuf/builtin_proto/protos_from_protobuf
+ contrib/libs/protobuf/builtin_proto/protos_from_protoc
+ contrib/python/six
+)
+
+ADDINCL(
+ contrib/python/protobuf/py2
+)
+
+NO_COMPILER_WARNINGS()
+
+NO_LINT()
+
+CFLAGS(
+ -DPYTHON_PROTO2_CPP_IMPL_V2
+)
+
+SRCS(
+ google/protobuf/internal/api_implementation.cc
+ google/protobuf/pyext/descriptor.cc
+ google/protobuf/pyext/descriptor_containers.cc
+ google/protobuf/pyext/descriptor_database.cc
+ google/protobuf/pyext/descriptor_pool.cc
+ google/protobuf/pyext/extension_dict.cc
+ google/protobuf/pyext/field.cc
+ google/protobuf/pyext/map_container.cc
+ google/protobuf/pyext/message.cc
+ google/protobuf/pyext/message_factory.cc
+ google/protobuf/pyext/message_module.cc
+ google/protobuf/pyext/repeated_composite_container.cc
+ google/protobuf/pyext/repeated_scalar_container.cc
+ google/protobuf/pyext/unknown_fields.cc
+)
+
+PY_REGISTER(
+ google.protobuf.internal._api_implementation
+ google.protobuf.pyext._message
+)
+
+PY_SRCS(
+ TOP_LEVEL
+ google/__init__.py
+ google/protobuf/__init__.py
+ google/protobuf/compiler/__init__.py
+ google/protobuf/descriptor.py
+ google/protobuf/descriptor_database.py
+ google/protobuf/descriptor_pool.py
+ google/protobuf/internal/__init__.py
+ google/protobuf/internal/_parameterized.py
+ google/protobuf/internal/api_implementation.py
+ google/protobuf/internal/containers.py
+ google/protobuf/internal/decoder.py
+ google/protobuf/internal/encoder.py
+ google/protobuf/internal/enum_type_wrapper.py
+ google/protobuf/internal/extension_dict.py
+ google/protobuf/internal/message_listener.py
+ google/protobuf/internal/python_message.py
+ google/protobuf/internal/type_checkers.py
+ google/protobuf/internal/well_known_types.py
+ google/protobuf/internal/wire_format.py
+ google/protobuf/json_format.py
+ google/protobuf/message.py
+ google/protobuf/message_factory.py
+ google/protobuf/proto_builder.py
+ google/protobuf/pyext/__init__.py
+ google/protobuf/pyext/cpp_message.py
+ google/protobuf/reflection.py
+ google/protobuf/service.py
+ google/protobuf/service_reflection.py
+ google/protobuf/symbol_database.py
+ google/protobuf/text_encoding.py
+ google/protobuf/text_format.py
+ google/protobuf/util/__init__.py
+)
+
+END()
diff --git a/contrib/python/protobuf/py3/.yandex_meta/devtools.copyrights.report b/contrib/python/protobuf/py3/.yandex_meta/devtools.copyrights.report
index 42ef206e89..67d3fd78d0 100644
--- a/contrib/python/protobuf/py3/.yandex_meta/devtools.copyrights.report
+++ b/contrib/python/protobuf/py3/.yandex_meta/devtools.copyrights.report
@@ -1,112 +1,112 @@
-# File format ($ symbol means the beginning of a line):
-#
-# $ # this message
-# $ # =======================
-# $ # comments (all commentaries should starts with some number of spaces and # symbol)
+# File format ($ symbol means the beginning of a line):
+#
+# $ # this message
+# $ # =======================
+# $ # comments (all commentaries should starts with some number of spaces and # symbol)
# $ IGNORE_FILES {file1.ext1} {file2.ext2} - (optional) ignore listed files when generating license macro and credits
# $ RENAME {original license id} TO {new license id} # user comments - (optional) use {new license id} instead {original license id} in ya.make files
# $ # user comments
# $
-# ${action} {license id} {license text hash}
-# $BELONGS ./ya/make/file/relative/path/1/ya.make ./ya/make/2/ya.make
-# ${all_file_action} filename
-# $ # user commentaries (many lines)
-# $ generated description - files with this license, license text... (some number of lines that starts with some number of spaces, do not modify)
-# ${action} {license spdx} {license text hash}
-# $BELONGS ./ya/make/file/relative/path/3/ya.make
-# ${all_file_action} filename
-# $ # user commentaries
-# $ generated description
-# $ ...
-#
-# You can modify action, all_file_action and add commentaries
-# Available actions:
-# keep - keep license in contrib and use in credits
-# skip - skip license
-# remove - remove all files with this license
-# rename - save license text/links into licenses texts file, but not store SPDX into LINCENSE macro. You should store correct license id into devtools.license.spdx.txt file
-#
-# {all file action} records will be generated when license text contains filename that exists on filesystem (in contrib directory)
-# We suppose that that files can contain some license info
-# Available all file actions:
-# FILE_IGNORE - ignore file (do nothing)
-# FILE_INCLUDE - include all file data into licenses text file
-# =======================
-
-KEEP COPYRIGHT_SERVICE_LABEL 29be00457f74dcf5f2b494d41d6a6c10
-BELONGS ya.make
- License text:
- \# Copyright 2007 Google Inc. All Rights Reserved.
- Scancode info:
- Original SPDX id: COPYRIGHT_SERVICE_LABEL
- Score : 100.00
- Match type : COPYRIGHT
- Files with this license:
- google/protobuf/__init__.py [31:31]
-
-KEEP COPYRIGHT_SERVICE_LABEL 7ddb2995f48012001146c0eb94d23367
-BELONGS ya.make
- License text:
- \# Copyright 2008 Google Inc. All rights reserved.
- Scancode info:
- Original SPDX id: COPYRIGHT_SERVICE_LABEL
- Score : 100.00
- Match type : COPYRIGHT
- Files with this license:
- google/protobuf/__init__.py [2:2]
- google/protobuf/descriptor.py [2:2]
- google/protobuf/descriptor_database.py [2:2]
- google/protobuf/descriptor_pool.py [2:2]
- google/protobuf/internal/__init__.py [2:2]
- google/protobuf/internal/_parameterized.py [4:4]
- google/protobuf/internal/api_implementation.cc [2:2]
- google/protobuf/internal/api_implementation.py [2:2]
- google/protobuf/internal/containers.py [2:2]
- google/protobuf/internal/decoder.py [2:2]
- google/protobuf/internal/encoder.py [2:2]
- google/protobuf/internal/enum_type_wrapper.py [2:2]
- google/protobuf/internal/extension_dict.py [2:2]
- google/protobuf/internal/message_listener.py [2:2]
- google/protobuf/internal/python_message.py [2:2]
- google/protobuf/internal/type_checkers.py [2:2]
- google/protobuf/internal/well_known_types.py [2:2]
- google/protobuf/internal/wire_format.py [2:2]
- google/protobuf/json_format.py [2:2]
- google/protobuf/message.py [2:2]
- google/protobuf/message_factory.py [2:2]
- google/protobuf/proto_api.h [2:2]
- google/protobuf/proto_builder.py [2:2]
- google/protobuf/pyext/cpp_message.py [2:2]
- google/protobuf/pyext/descriptor.cc [2:2]
- google/protobuf/pyext/descriptor.h [2:2]
- google/protobuf/pyext/descriptor_containers.cc [2:2]
- google/protobuf/pyext/descriptor_containers.h [2:2]
- google/protobuf/pyext/descriptor_database.cc [2:2]
- google/protobuf/pyext/descriptor_database.h [2:2]
- google/protobuf/pyext/descriptor_pool.cc [2:2]
- google/protobuf/pyext/descriptor_pool.h [2:2]
- google/protobuf/pyext/extension_dict.cc [2:2]
- google/protobuf/pyext/extension_dict.h [2:2]
- google/protobuf/pyext/field.cc [2:2]
- google/protobuf/pyext/field.h [2:2]
- google/protobuf/pyext/map_container.cc [2:2]
- google/protobuf/pyext/map_container.h [2:2]
- google/protobuf/pyext/message.cc [2:2]
- google/protobuf/pyext/message.h [2:2]
- google/protobuf/pyext/message_factory.cc [2:2]
- google/protobuf/pyext/message_factory.h [2:2]
- google/protobuf/pyext/message_module.cc [2:2]
- google/protobuf/pyext/repeated_composite_container.cc [2:2]
- google/protobuf/pyext/repeated_composite_container.h [2:2]
- google/protobuf/pyext/repeated_scalar_container.cc [2:2]
- google/protobuf/pyext/repeated_scalar_container.h [2:2]
- google/protobuf/pyext/safe_numerics.h [2:2]
- google/protobuf/pyext/scoped_pyobject_ptr.h [2:2]
- google/protobuf/pyext/unknown_fields.cc [2:2]
- google/protobuf/pyext/unknown_fields.h [2:2]
- google/protobuf/reflection.py [2:2]
- google/protobuf/service.py [2:2]
- google/protobuf/service_reflection.py [2:2]
- google/protobuf/symbol_database.py [2:2]
- google/protobuf/text_encoding.py [2:2]
- google/protobuf/text_format.py [2:2]
+# ${action} {license id} {license text hash}
+# $BELONGS ./ya/make/file/relative/path/1/ya.make ./ya/make/2/ya.make
+# ${all_file_action} filename
+# $ # user commentaries (many lines)
+# $ generated description - files with this license, license text... (some number of lines that starts with some number of spaces, do not modify)
+# ${action} {license spdx} {license text hash}
+# $BELONGS ./ya/make/file/relative/path/3/ya.make
+# ${all_file_action} filename
+# $ # user commentaries
+# $ generated description
+# $ ...
+#
+# You can modify action, all_file_action and add commentaries
+# Available actions:
+# keep - keep license in contrib and use in credits
+# skip - skip license
+# remove - remove all files with this license
+# rename - save license text/links into licenses texts file, but not store SPDX into LINCENSE macro. You should store correct license id into devtools.license.spdx.txt file
+#
+# {all file action} records will be generated when license text contains filename that exists on filesystem (in contrib directory)
+# We suppose that that files can contain some license info
+# Available all file actions:
+# FILE_IGNORE - ignore file (do nothing)
+# FILE_INCLUDE - include all file data into licenses text file
+# =======================
+
+KEEP COPYRIGHT_SERVICE_LABEL 29be00457f74dcf5f2b494d41d6a6c10
+BELONGS ya.make
+ License text:
+ \# Copyright 2007 Google Inc. All Rights Reserved.
+ Scancode info:
+ Original SPDX id: COPYRIGHT_SERVICE_LABEL
+ Score : 100.00
+ Match type : COPYRIGHT
+ Files with this license:
+ google/protobuf/__init__.py [31:31]
+
+KEEP COPYRIGHT_SERVICE_LABEL 7ddb2995f48012001146c0eb94d23367
+BELONGS ya.make
+ License text:
+ \# Copyright 2008 Google Inc. All rights reserved.
+ Scancode info:
+ Original SPDX id: COPYRIGHT_SERVICE_LABEL
+ Score : 100.00
+ Match type : COPYRIGHT
+ Files with this license:
+ google/protobuf/__init__.py [2:2]
+ google/protobuf/descriptor.py [2:2]
+ google/protobuf/descriptor_database.py [2:2]
+ google/protobuf/descriptor_pool.py [2:2]
+ google/protobuf/internal/__init__.py [2:2]
+ google/protobuf/internal/_parameterized.py [4:4]
+ google/protobuf/internal/api_implementation.cc [2:2]
+ google/protobuf/internal/api_implementation.py [2:2]
+ google/protobuf/internal/containers.py [2:2]
+ google/protobuf/internal/decoder.py [2:2]
+ google/protobuf/internal/encoder.py [2:2]
+ google/protobuf/internal/enum_type_wrapper.py [2:2]
+ google/protobuf/internal/extension_dict.py [2:2]
+ google/protobuf/internal/message_listener.py [2:2]
+ google/protobuf/internal/python_message.py [2:2]
+ google/protobuf/internal/type_checkers.py [2:2]
+ google/protobuf/internal/well_known_types.py [2:2]
+ google/protobuf/internal/wire_format.py [2:2]
+ google/protobuf/json_format.py [2:2]
+ google/protobuf/message.py [2:2]
+ google/protobuf/message_factory.py [2:2]
+ google/protobuf/proto_api.h [2:2]
+ google/protobuf/proto_builder.py [2:2]
+ google/protobuf/pyext/cpp_message.py [2:2]
+ google/protobuf/pyext/descriptor.cc [2:2]
+ google/protobuf/pyext/descriptor.h [2:2]
+ google/protobuf/pyext/descriptor_containers.cc [2:2]
+ google/protobuf/pyext/descriptor_containers.h [2:2]
+ google/protobuf/pyext/descriptor_database.cc [2:2]
+ google/protobuf/pyext/descriptor_database.h [2:2]
+ google/protobuf/pyext/descriptor_pool.cc [2:2]
+ google/protobuf/pyext/descriptor_pool.h [2:2]
+ google/protobuf/pyext/extension_dict.cc [2:2]
+ google/protobuf/pyext/extension_dict.h [2:2]
+ google/protobuf/pyext/field.cc [2:2]
+ google/protobuf/pyext/field.h [2:2]
+ google/protobuf/pyext/map_container.cc [2:2]
+ google/protobuf/pyext/map_container.h [2:2]
+ google/protobuf/pyext/message.cc [2:2]
+ google/protobuf/pyext/message.h [2:2]
+ google/protobuf/pyext/message_factory.cc [2:2]
+ google/protobuf/pyext/message_factory.h [2:2]
+ google/protobuf/pyext/message_module.cc [2:2]
+ google/protobuf/pyext/repeated_composite_container.cc [2:2]
+ google/protobuf/pyext/repeated_composite_container.h [2:2]
+ google/protobuf/pyext/repeated_scalar_container.cc [2:2]
+ google/protobuf/pyext/repeated_scalar_container.h [2:2]
+ google/protobuf/pyext/safe_numerics.h [2:2]
+ google/protobuf/pyext/scoped_pyobject_ptr.h [2:2]
+ google/protobuf/pyext/unknown_fields.cc [2:2]
+ google/protobuf/pyext/unknown_fields.h [2:2]
+ google/protobuf/reflection.py [2:2]
+ google/protobuf/service.py [2:2]
+ google/protobuf/service_reflection.py [2:2]
+ google/protobuf/symbol_database.py [2:2]
+ google/protobuf/text_encoding.py [2:2]
+ google/protobuf/text_format.py [2:2]
diff --git a/contrib/python/protobuf/py3/.yandex_meta/devtools.licenses.report b/contrib/python/protobuf/py3/.yandex_meta/devtools.licenses.report
index 0b960d4f1f..abc30aa6c1 100644
--- a/contrib/python/protobuf/py3/.yandex_meta/devtools.licenses.report
+++ b/contrib/python/protobuf/py3/.yandex_meta/devtools.licenses.report
@@ -1,111 +1,111 @@
-# File format ($ symbol means the beginning of a line):
-#
-# $ # this message
-# $ # =======================
-# $ # comments (all commentaries should starts with some number of spaces and # symbol)
+# File format ($ symbol means the beginning of a line):
+#
+# $ # this message
+# $ # =======================
+# $ # comments (all commentaries should starts with some number of spaces and # symbol)
# $ IGNORE_FILES {file1.ext1} {file2.ext2} - (optional) ignore listed files when generating license macro and credits
# $ RENAME {original license id} TO {new license id} # user comments - (optional) use {new license id} instead {original license id} in ya.make files
# $ # user comments
# $
-# ${action} {license id} {license text hash}
-# $BELONGS ./ya/make/file/relative/path/1/ya.make ./ya/make/2/ya.make
-# ${all_file_action} filename
-# $ # user commentaries (many lines)
-# $ generated description - files with this license, license text... (some number of lines that starts with some number of spaces, do not modify)
-# ${action} {license spdx} {license text hash}
-# $BELONGS ./ya/make/file/relative/path/3/ya.make
-# ${all_file_action} filename
-# $ # user commentaries
-# $ generated description
-# $ ...
-#
-# You can modify action, all_file_action and add commentaries
-# Available actions:
-# keep - keep license in contrib and use in credits
-# skip - skip license
-# remove - remove all files with this license
-# rename - save license text/links into licenses texts file, but not store SPDX into LINCENSE macro. You should store correct license id into devtools.license.spdx.txt file
-#
-# {all file action} records will be generated when license text contains filename that exists on filesystem (in contrib directory)
-# We suppose that that files can contain some license info
-# Available all file actions:
-# FILE_IGNORE - ignore file (do nothing)
-# FILE_INCLUDE - include all file data into licenses text file
-# =======================
-
-KEEP BSD-3-Clause 6aa235708ac9f5dd8e5c6ac415fc5837
-BELONGS ya.make
- Note: matched license text is too long. Read it in the source files.
- Scancode info:
- Original SPDX id: BSD-3-Clause
- Score : 100.00
- Match type : TEXT
- Links : http://www.opensource.org/licenses/BSD-3-Clause, https://spdx.org/licenses/BSD-3-Clause
- Files with this license:
- google/protobuf/internal/api_implementation.cc [5:29]
- google/protobuf/proto_api.h [5:29]
- google/protobuf/pyext/descriptor.cc [5:29]
- google/protobuf/pyext/descriptor.h [5:29]
- google/protobuf/pyext/descriptor_containers.cc [5:29]
- google/protobuf/pyext/descriptor_containers.h [5:29]
- google/protobuf/pyext/descriptor_database.cc [5:29]
- google/protobuf/pyext/descriptor_database.h [5:29]
- google/protobuf/pyext/descriptor_pool.cc [5:29]
- google/protobuf/pyext/descriptor_pool.h [5:29]
- google/protobuf/pyext/extension_dict.cc [5:29]
- google/protobuf/pyext/extension_dict.h [5:29]
- google/protobuf/pyext/field.cc [5:29]
- google/protobuf/pyext/field.h [5:29]
- google/protobuf/pyext/map_container.cc [5:29]
- google/protobuf/pyext/map_container.h [5:29]
- google/protobuf/pyext/message.cc [5:29]
- google/protobuf/pyext/message.h [5:29]
- google/protobuf/pyext/message_factory.cc [5:29]
- google/protobuf/pyext/message_factory.h [5:29]
- google/protobuf/pyext/message_module.cc [5:29]
- google/protobuf/pyext/repeated_composite_container.cc [5:29]
- google/protobuf/pyext/repeated_composite_container.h [5:29]
- google/protobuf/pyext/repeated_scalar_container.cc [5:29]
- google/protobuf/pyext/repeated_scalar_container.h [5:29]
- google/protobuf/pyext/safe_numerics.h [5:29]
- google/protobuf/pyext/scoped_pyobject_ptr.h [5:29]
- google/protobuf/pyext/unknown_fields.cc [5:29]
- google/protobuf/pyext/unknown_fields.h [5:29]
-
-KEEP BSD-3-Clause 8aaace038fd54f3a52b1f041f9504709
-BELONGS ya.make
- Note: matched license text is too long. Read it in the source files.
- Scancode info:
- Original SPDX id: BSD-3-Clause
- Score : 100.00
- Match type : TEXT
- Links : http://www.opensource.org/licenses/BSD-3-Clause, https://spdx.org/licenses/BSD-3-Clause
- Files with this license:
- google/protobuf/__init__.py [5:29]
- google/protobuf/descriptor.py [5:29]
- google/protobuf/descriptor_database.py [5:29]
- google/protobuf/descriptor_pool.py [5:29]
- google/protobuf/internal/__init__.py [5:29]
- google/protobuf/internal/_parameterized.py [7:31]
- google/protobuf/internal/api_implementation.py [5:29]
- google/protobuf/internal/containers.py [5:29]
- google/protobuf/internal/decoder.py [5:29]
- google/protobuf/internal/encoder.py [5:29]
- google/protobuf/internal/enum_type_wrapper.py [5:29]
- google/protobuf/internal/extension_dict.py [5:29]
- google/protobuf/internal/message_listener.py [5:29]
- google/protobuf/internal/python_message.py [5:29]
- google/protobuf/internal/type_checkers.py [5:29]
- google/protobuf/internal/well_known_types.py [5:29]
- google/protobuf/internal/wire_format.py [5:29]
- google/protobuf/json_format.py [5:29]
- google/protobuf/message.py [5:29]
- google/protobuf/message_factory.py [5:29]
- google/protobuf/proto_builder.py [5:29]
- google/protobuf/pyext/cpp_message.py [5:29]
- google/protobuf/reflection.py [5:29]
- google/protobuf/service.py [5:29]
- google/protobuf/service_reflection.py [5:29]
- google/protobuf/symbol_database.py [5:29]
- google/protobuf/text_encoding.py [5:29]
- google/protobuf/text_format.py [5:29]
+# ${action} {license id} {license text hash}
+# $BELONGS ./ya/make/file/relative/path/1/ya.make ./ya/make/2/ya.make
+# ${all_file_action} filename
+# $ # user commentaries (many lines)
+# $ generated description - files with this license, license text... (some number of lines that starts with some number of spaces, do not modify)
+# ${action} {license spdx} {license text hash}
+# $BELONGS ./ya/make/file/relative/path/3/ya.make
+# ${all_file_action} filename
+# $ # user commentaries
+# $ generated description
+# $ ...
+#
+# You can modify action, all_file_action and add commentaries
+# Available actions:
+# keep - keep license in contrib and use in credits
+# skip - skip license
+# remove - remove all files with this license
+# rename - save license text/links into licenses texts file, but not store SPDX into LINCENSE macro. You should store correct license id into devtools.license.spdx.txt file
+#
+# {all file action} records will be generated when license text contains filename that exists on filesystem (in contrib directory)
+# We suppose that that files can contain some license info
+# Available all file actions:
+# FILE_IGNORE - ignore file (do nothing)
+# FILE_INCLUDE - include all file data into licenses text file
+# =======================
+
+KEEP BSD-3-Clause 6aa235708ac9f5dd8e5c6ac415fc5837
+BELONGS ya.make
+ Note: matched license text is too long. Read it in the source files.
+ Scancode info:
+ Original SPDX id: BSD-3-Clause
+ Score : 100.00
+ Match type : TEXT
+ Links : http://www.opensource.org/licenses/BSD-3-Clause, https://spdx.org/licenses/BSD-3-Clause
+ Files with this license:
+ google/protobuf/internal/api_implementation.cc [5:29]
+ google/protobuf/proto_api.h [5:29]
+ google/protobuf/pyext/descriptor.cc [5:29]
+ google/protobuf/pyext/descriptor.h [5:29]
+ google/protobuf/pyext/descriptor_containers.cc [5:29]
+ google/protobuf/pyext/descriptor_containers.h [5:29]
+ google/protobuf/pyext/descriptor_database.cc [5:29]
+ google/protobuf/pyext/descriptor_database.h [5:29]
+ google/protobuf/pyext/descriptor_pool.cc [5:29]
+ google/protobuf/pyext/descriptor_pool.h [5:29]
+ google/protobuf/pyext/extension_dict.cc [5:29]
+ google/protobuf/pyext/extension_dict.h [5:29]
+ google/protobuf/pyext/field.cc [5:29]
+ google/protobuf/pyext/field.h [5:29]
+ google/protobuf/pyext/map_container.cc [5:29]
+ google/protobuf/pyext/map_container.h [5:29]
+ google/protobuf/pyext/message.cc [5:29]
+ google/protobuf/pyext/message.h [5:29]
+ google/protobuf/pyext/message_factory.cc [5:29]
+ google/protobuf/pyext/message_factory.h [5:29]
+ google/protobuf/pyext/message_module.cc [5:29]
+ google/protobuf/pyext/repeated_composite_container.cc [5:29]
+ google/protobuf/pyext/repeated_composite_container.h [5:29]
+ google/protobuf/pyext/repeated_scalar_container.cc [5:29]
+ google/protobuf/pyext/repeated_scalar_container.h [5:29]
+ google/protobuf/pyext/safe_numerics.h [5:29]
+ google/protobuf/pyext/scoped_pyobject_ptr.h [5:29]
+ google/protobuf/pyext/unknown_fields.cc [5:29]
+ google/protobuf/pyext/unknown_fields.h [5:29]
+
+KEEP BSD-3-Clause 8aaace038fd54f3a52b1f041f9504709
+BELONGS ya.make
+ Note: matched license text is too long. Read it in the source files.
+ Scancode info:
+ Original SPDX id: BSD-3-Clause
+ Score : 100.00
+ Match type : TEXT
+ Links : http://www.opensource.org/licenses/BSD-3-Clause, https://spdx.org/licenses/BSD-3-Clause
+ Files with this license:
+ google/protobuf/__init__.py [5:29]
+ google/protobuf/descriptor.py [5:29]
+ google/protobuf/descriptor_database.py [5:29]
+ google/protobuf/descriptor_pool.py [5:29]
+ google/protobuf/internal/__init__.py [5:29]
+ google/protobuf/internal/_parameterized.py [7:31]
+ google/protobuf/internal/api_implementation.py [5:29]
+ google/protobuf/internal/containers.py [5:29]
+ google/protobuf/internal/decoder.py [5:29]
+ google/protobuf/internal/encoder.py [5:29]
+ google/protobuf/internal/enum_type_wrapper.py [5:29]
+ google/protobuf/internal/extension_dict.py [5:29]
+ google/protobuf/internal/message_listener.py [5:29]
+ google/protobuf/internal/python_message.py [5:29]
+ google/protobuf/internal/type_checkers.py [5:29]
+ google/protobuf/internal/well_known_types.py [5:29]
+ google/protobuf/internal/wire_format.py [5:29]
+ google/protobuf/json_format.py [5:29]
+ google/protobuf/message.py [5:29]
+ google/protobuf/message_factory.py [5:29]
+ google/protobuf/proto_builder.py [5:29]
+ google/protobuf/pyext/cpp_message.py [5:29]
+ google/protobuf/reflection.py [5:29]
+ google/protobuf/service.py [5:29]
+ google/protobuf/service_reflection.py [5:29]
+ google/protobuf/symbol_database.py [5:29]
+ google/protobuf/text_encoding.py [5:29]
+ google/protobuf/text_format.py [5:29]
diff --git a/contrib/python/protobuf/py3/.yandex_meta/licenses.list.txt b/contrib/python/protobuf/py3/.yandex_meta/licenses.list.txt
index 81364a2ff7..c8ea6f050b 100644
--- a/contrib/python/protobuf/py3/.yandex_meta/licenses.list.txt
+++ b/contrib/python/protobuf/py3/.yandex_meta/licenses.list.txt
@@ -1,62 +1,62 @@
-====================BSD-3-Clause====================
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-# * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-====================BSD-3-Clause====================
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-====================COPYRIGHT====================
-# Copyright 2007 Google Inc. All Rights Reserved.
-
-
-====================COPYRIGHT====================
-# Copyright 2008 Google Inc. All rights reserved.
+====================BSD-3-Clause====================
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+====================BSD-3-Clause====================
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+====================COPYRIGHT====================
+# Copyright 2007 Google Inc. All Rights Reserved.
+
+
+====================COPYRIGHT====================
+# Copyright 2008 Google Inc. All rights reserved.
diff --git a/contrib/python/protobuf/py3/README.md b/contrib/python/protobuf/py3/README.md
index cb8b7e9892..4a178ccad5 100644
--- a/contrib/python/protobuf/py3/README.md
+++ b/contrib/python/protobuf/py3/README.md
@@ -1,132 +1,132 @@
-Protocol Buffers - Google's data interchange format
-===================================================
-
-[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python_compatibility.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython_compatibility%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython_cpp%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-python.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fpython%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-python_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fpython_cpp%2Fcontinuous) [![Compat check PyPI](https://python-compatibility-tools.appspot.com/one_badge_image?package=protobuf)](https://python-compatibility-tools.appspot.com/one_badge_target?package=protobuf)
-
-Copyright 2008 Google Inc.
-
-This directory contains the Python Protocol Buffers runtime library.
-
-Normally, this directory comes as part of the protobuf package, available
-from:
-
- https://developers.google.com/protocol-buffers/
-
-The complete package includes the C++ source code, which includes the
-Protocol Compiler (protoc). If you downloaded this package from PyPI
-or some other Python-specific source, you may have received only the
-Python part of the code. In this case, you will need to obtain the
-Protocol Compiler from some other source before you can use this
-package.
-
-Development Warning
-===================
-
-The pure python performance is slow. For better performance please
-use python c++ implementation.
-
-Installation
-============
-
-1) Make sure you have Python 2.7 or newer. If in doubt, run:
-
- $ python -V
-
-2) If you do not have setuptools installed, note that it will be
- downloaded and installed automatically as soon as you run `setup.py`.
- If you would rather install it manually, you may do so by following
- the instructions on [this page](https://packaging.python.org/en/latest/installing.html#setup-for-installing-packages).
-
-3) Build the C++ code, or install a binary distribution of `protoc`. If
- you install a binary distribution, make sure that it is the same
- version as this package. If in doubt, run:
-
- $ protoc --version
-
-4) Build and run the tests:
-
- $ python setup.py build
- $ python setup.py test
-
- To build, test, and use the C++ implementation, you must first compile
- `libprotobuf.so`:
-
- $ (cd .. && make)
-
- On OS X:
-
- If you are running a Homebrew-provided Python, you must make sure another
- version of protobuf is not already installed, as Homebrew's Python will
- search `/usr/local/lib` for `libprotobuf.so` before it searches
- `../src/.libs`.
-
- You can either unlink Homebrew's protobuf or install the `libprotobuf` you
- built earlier:
-
- $ brew unlink protobuf
-
- or
-
- $ (cd .. && make install)
-
- On other *nix:
-
- You must make `libprotobuf.so` dynamically available. You can either
- install libprotobuf you built earlier, or set `LD_LIBRARY_PATH`:
-
- $ export LD_LIBRARY_PATH=../src/.libs
-
- or
-
- $ (cd .. && make install)
-
- To build the C++ implementation run:
-
- $ python setup.py build --cpp_implementation
-
- Then run the tests like so:
-
- $ python setup.py test --cpp_implementation
-
- If some tests fail, this library may not work correctly on your
- system. Continue at your own risk.
-
- Please note that there is a known problem with some versions of
- Python on Cygwin which causes the tests to fail after printing the
- error: `sem_init: Resource temporarily unavailable`. This appears
- to be a [bug either in Cygwin or in
- Python](http://www.cygwin.com/ml/cygwin/2005-07/msg01378.html).
-
- We do not know if or when it might be fixed. We also do not know
- how likely it is that this bug will affect users in practice.
-
-5) Install:
-
- $ python setup.py install
-
- or:
-
- $ (cd .. && make install)
- $ python setup.py install --cpp_implementation
-
- This step may require superuser privileges.
- NOTE: To use C++ implementation, you need to export an environment
- variable before running your program. See the "C++ Implementation"
- section below for more details.
-
-Usage
-=====
-
-The complete documentation for Protocol Buffers is available via the
-web at:
-
- https://developers.google.com/protocol-buffers/
-
-C++ Implementation
-==================
-
-The C++ implementation for Python messages is built as a Python extension to
-improve the overall protobuf Python performance.
-
-To use the C++ implementation, you need to install the C++ protobuf runtime
-library, please see instructions in the parent directory.
+Protocol Buffers - Google's data interchange format
+===================================================
+
+[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python_compatibility.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython_compatibility%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-python_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fpython_cpp%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-python.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fpython%2Fcontinuous) [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-python_cpp.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fpython_cpp%2Fcontinuous) [![Compat check PyPI](https://python-compatibility-tools.appspot.com/one_badge_image?package=protobuf)](https://python-compatibility-tools.appspot.com/one_badge_target?package=protobuf)
+
+Copyright 2008 Google Inc.
+
+This directory contains the Python Protocol Buffers runtime library.
+
+Normally, this directory comes as part of the protobuf package, available
+from:
+
+ https://developers.google.com/protocol-buffers/
+
+The complete package includes the C++ source code, which includes the
+Protocol Compiler (protoc). If you downloaded this package from PyPI
+or some other Python-specific source, you may have received only the
+Python part of the code. In this case, you will need to obtain the
+Protocol Compiler from some other source before you can use this
+package.
+
+Development Warning
+===================
+
+The pure python performance is slow. For better performance please
+use python c++ implementation.
+
+Installation
+============
+
+1) Make sure you have Python 2.7 or newer. If in doubt, run:
+
+ $ python -V
+
+2) If you do not have setuptools installed, note that it will be
+ downloaded and installed automatically as soon as you run `setup.py`.
+ If you would rather install it manually, you may do so by following
+ the instructions on [this page](https://packaging.python.org/en/latest/installing.html#setup-for-installing-packages).
+
+3) Build the C++ code, or install a binary distribution of `protoc`. If
+ you install a binary distribution, make sure that it is the same
+ version as this package. If in doubt, run:
+
+ $ protoc --version
+
+4) Build and run the tests:
+
+ $ python setup.py build
+ $ python setup.py test
+
+ To build, test, and use the C++ implementation, you must first compile
+ `libprotobuf.so`:
+
+ $ (cd .. && make)
+
+ On OS X:
+
+ If you are running a Homebrew-provided Python, you must make sure another
+ version of protobuf is not already installed, as Homebrew's Python will
+ search `/usr/local/lib` for `libprotobuf.so` before it searches
+ `../src/.libs`.
+
+ You can either unlink Homebrew's protobuf or install the `libprotobuf` you
+ built earlier:
+
+ $ brew unlink protobuf
+
+ or
+
+ $ (cd .. && make install)
+
+ On other *nix:
+
+ You must make `libprotobuf.so` dynamically available. You can either
+ install libprotobuf you built earlier, or set `LD_LIBRARY_PATH`:
+
+ $ export LD_LIBRARY_PATH=../src/.libs
+
+ or
+
+ $ (cd .. && make install)
+
+ To build the C++ implementation run:
+
+ $ python setup.py build --cpp_implementation
+
+ Then run the tests like so:
+
+ $ python setup.py test --cpp_implementation
+
+ If some tests fail, this library may not work correctly on your
+ system. Continue at your own risk.
+
+ Please note that there is a known problem with some versions of
+ Python on Cygwin which causes the tests to fail after printing the
+ error: `sem_init: Resource temporarily unavailable`. This appears
+ to be a [bug either in Cygwin or in
+ Python](http://www.cygwin.com/ml/cygwin/2005-07/msg01378.html).
+
+ We do not know if or when it might be fixed. We also do not know
+ how likely it is that this bug will affect users in practice.
+
+5) Install:
+
+ $ python setup.py install
+
+ or:
+
+ $ (cd .. && make install)
+ $ python setup.py install --cpp_implementation
+
+ This step may require superuser privileges.
+ NOTE: To use C++ implementation, you need to export an environment
+ variable before running your program. See the "C++ Implementation"
+ section below for more details.
+
+Usage
+=====
+
+The complete documentation for Protocol Buffers is available via the
+web at:
+
+ https://developers.google.com/protocol-buffers/
+
+C++ Implementation
+==================
+
+The C++ implementation for Python messages is built as a Python extension to
+improve the overall protobuf Python performance.
+
+To use the C++ implementation, you need to install the C++ protobuf runtime
+library, please see instructions in the parent directory.
diff --git a/contrib/python/protobuf/py3/google/__init__.py b/contrib/python/protobuf/py3/google/__init__.py
index 5585614122..79f9960a79 100644
--- a/contrib/python/protobuf/py3/google/__init__.py
+++ b/contrib/python/protobuf/py3/google/__init__.py
@@ -1,4 +1,4 @@
-try:
- __import__('pkg_resources').declare_namespace(__name__)
-except ImportError:
- __path__ = __import__('pkgutil').extend_path(__path__, __name__)
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ __path__ = __import__('pkgutil').extend_path(__path__, __name__)
diff --git a/contrib/python/protobuf/py3/google/protobuf/__init__.py b/contrib/python/protobuf/py3/google/protobuf/__init__.py
index 496df6adaf..fade4d257a 100644
--- a/contrib/python/protobuf/py3/google/protobuf/__init__.py
+++ b/contrib/python/protobuf/py3/google/protobuf/__init__.py
@@ -30,4 +30,4 @@
# Copyright 2007 Google Inc. All Rights Reserved.
-__version__ = '3.17.3'
+__version__ = '3.17.3'
diff --git a/contrib/python/protobuf/py3/google/protobuf/descriptor.py b/contrib/python/protobuf/py3/google/protobuf/descriptor.py
index 70fdae16ff..a3a40b740d 100644
--- a/contrib/python/protobuf/py3/google/protobuf/descriptor.py
+++ b/contrib/python/protobuf/py3/google/protobuf/descriptor.py
@@ -34,8 +34,8 @@ file, in types that make this information accessible in Python.
__author__ = 'robinson@google.com (Will Robinson)'
-import threading
-import warnings
+import threading
+import warnings
import six
from google.protobuf.internal import api_implementation
@@ -43,10 +43,10 @@ from google.protobuf.internal import api_implementation
_USE_C_DESCRIPTORS = False
if api_implementation.Type() == 'cpp':
# Used by MakeDescriptor in cpp mode
- import binascii
+ import binascii
import os
from google.protobuf.pyext import _message
- _USE_C_DESCRIPTORS = True
+ _USE_C_DESCRIPTORS = True
class Error(Exception):
@@ -74,43 +74,43 @@ else:
DescriptorMetaclass = type
-class _Lock(object):
- """Wrapper class of threading.Lock(), which is allowed by 'with'."""
-
- def __new__(cls):
- self = object.__new__(cls)
- self._lock = threading.Lock() # pylint: disable=protected-access
- return self
-
- def __enter__(self):
- self._lock.acquire()
-
- def __exit__(self, exc_type, exc_value, exc_tb):
- self._lock.release()
-
-
-_lock = threading.Lock()
-
-
-def _Deprecated(name):
- if _Deprecated.count > 0:
- _Deprecated.count -= 1
- warnings.warn(
- 'Call to deprecated create function %s(). Note: Create unlinked '
- 'descriptors is going to go away. Please use get/find descriptors from '
- 'generated code or query the descriptor_pool.'
- % name,
- category=DeprecationWarning, stacklevel=3)
-
-
-# Deprecated warnings will print 100 times at most which should be enough for
-# users to notice and do not cause timeout.
-_Deprecated.count = 100
-
-
-_internal_create_key = object()
-
-
+class _Lock(object):
+ """Wrapper class of threading.Lock(), which is allowed by 'with'."""
+
+ def __new__(cls):
+ self = object.__new__(cls)
+ self._lock = threading.Lock() # pylint: disable=protected-access
+ return self
+
+ def __enter__(self):
+ self._lock.acquire()
+
+ def __exit__(self, exc_type, exc_value, exc_tb):
+ self._lock.release()
+
+
+_lock = threading.Lock()
+
+
+def _Deprecated(name):
+ if _Deprecated.count > 0:
+ _Deprecated.count -= 1
+ warnings.warn(
+ 'Call to deprecated create function %s(). Note: Create unlinked '
+ 'descriptors is going to go away. Please use get/find descriptors from '
+ 'generated code or query the descriptor_pool.'
+ % name,
+ category=DeprecationWarning, stacklevel=3)
+
+
+# Deprecated warnings will print 100 times at most which should be enough for
+# users to notice and do not cause timeout.
+_Deprecated.count = 100
+
+
+_internal_create_key = object()
+
+
class DescriptorBase(six.with_metaclass(DescriptorMetaclass)):
"""Descriptors base class.
@@ -131,17 +131,17 @@ class DescriptorBase(six.with_metaclass(DescriptorMetaclass)):
# subclasses" of this descriptor class.
_C_DESCRIPTOR_CLASS = ()
- def __init__(self, options, serialized_options, options_class_name):
+ def __init__(self, options, serialized_options, options_class_name):
"""Initialize the descriptor given its options message and the name of the
class of the options message. The name of the class is required in case
the options message is None and has to be created.
"""
self._options = options
self._options_class_name = options_class_name
- self._serialized_options = serialized_options
+ self._serialized_options = serialized_options
# Does this descriptor have non-default options?
- self.has_options = (options is not None) or (serialized_options is not None)
+ self.has_options = (options is not None) or (serialized_options is not None)
def _SetOptions(self, options, options_class_name):
"""Sets the descriptor's options
@@ -163,52 +163,52 @@ class DescriptorBase(six.with_metaclass(DescriptorMetaclass)):
"""
if self._options:
return self._options
-
+
from google.protobuf import descriptor_pb2
try:
- options_class = getattr(descriptor_pb2,
- self._options_class_name)
+ options_class = getattr(descriptor_pb2,
+ self._options_class_name)
except AttributeError:
raise RuntimeError('Unknown options class name %s!' %
(self._options_class_name))
- with _lock:
- if self._serialized_options is None:
- self._options = options_class()
- else:
- self._options = _ParseOptions(options_class(),
- self._serialized_options)
-
- return self._options
-
+ with _lock:
+ if self._serialized_options is None:
+ self._options = options_class()
+ else:
+ self._options = _ParseOptions(options_class(),
+ self._serialized_options)
+ return self._options
+
+
class _NestedDescriptorBase(DescriptorBase):
"""Common class for descriptors that can be nested."""
def __init__(self, options, options_class_name, name, full_name,
file, containing_type, serialized_start=None,
- serialized_end=None, serialized_options=None):
+ serialized_end=None, serialized_options=None):
"""Constructor.
Args:
options: Protocol message options or None
to use default message options.
- options_class_name (str): The class name of the above options.
- name (str): Name of this protocol message type.
- full_name (str): Fully-qualified name of this protocol message type,
+ options_class_name (str): The class name of the above options.
+ name (str): Name of this protocol message type.
+ full_name (str): Fully-qualified name of this protocol message type,
which will include protocol "package" name and the name of any
enclosing types.
- file (FileDescriptor): Reference to file info.
+ file (FileDescriptor): Reference to file info.
containing_type: if provided, this is a nested descriptor, with this
descriptor as parent, otherwise None.
serialized_start: The start index (inclusive) in block in the
file.serialized_pb that describes this descriptor.
serialized_end: The end index (exclusive) in block in the
file.serialized_pb that describes this descriptor.
- serialized_options: Protocol message serialized options or None.
+ serialized_options: Protocol message serialized options or None.
"""
super(_NestedDescriptorBase, self).__init__(
- options, serialized_options, options_class_name)
+ options, serialized_options, options_class_name)
self.name = name
# TODO(falk): Add function to calculate full_name instead of having it in
@@ -227,8 +227,8 @@ class _NestedDescriptorBase(DescriptorBase):
proto: An empty proto instance from descriptor_pb2.
Raises:
- Error: If self couldn't be serialized, due to to few constructor
- arguments.
+ Error: If self couldn't be serialized, due to to few constructor
+ arguments.
"""
if (self.file is not None and
self._serialized_start is not None and
@@ -243,70 +243,70 @@ class Descriptor(_NestedDescriptorBase):
"""Descriptor for a protocol message type.
- Attributes:
- name (str): Name of this protocol message type.
- full_name (str): Fully-qualified name of this protocol message type,
- which will include protocol "package" name and the name of any
- enclosing types.
- containing_type (Descriptor): Reference to the descriptor of the type
- containing us, or None if this is top-level.
- fields (list[FieldDescriptor]): Field descriptors for all fields in
- this type.
- fields_by_number (dict(int, FieldDescriptor)): Same
- :class:`FieldDescriptor` objects as in :attr:`fields`, but indexed
- by "number" attribute in each FieldDescriptor.
- fields_by_name (dict(str, FieldDescriptor)): Same
- :class:`FieldDescriptor` objects as in :attr:`fields`, but indexed by
- "name" attribute in each :class:`FieldDescriptor`.
- nested_types (list[Descriptor]): Descriptor references
- for all protocol message types nested within this one.
- nested_types_by_name (dict(str, Descriptor)): Same Descriptor
- objects as in :attr:`nested_types`, but indexed by "name" attribute
- in each Descriptor.
- enum_types (list[EnumDescriptor]): :class:`EnumDescriptor` references
- for all enums contained within this type.
- enum_types_by_name (dict(str, EnumDescriptor)): Same
- :class:`EnumDescriptor` objects as in :attr:`enum_types`, but
- indexed by "name" attribute in each EnumDescriptor.
- enum_values_by_name (dict(str, EnumValueDescriptor)): Dict mapping
- from enum value name to :class:`EnumValueDescriptor` for that value.
- extensions (list[FieldDescriptor]): All extensions defined directly
- within this message type (NOT within a nested type).
- extensions_by_name (dict(str, FieldDescriptor)): Same FieldDescriptor
- objects as :attr:`extensions`, but indexed by "name" attribute of each
- FieldDescriptor.
- is_extendable (bool): Does this type define any extension ranges?
- oneofs (list[OneofDescriptor]): The list of descriptors for oneof fields
- in this message.
- oneofs_by_name (dict(str, OneofDescriptor)): Same objects as in
- :attr:`oneofs`, but indexed by "name" attribute.
- file (FileDescriptor): Reference to file descriptor.
+ Attributes:
+ name (str): Name of this protocol message type.
+ full_name (str): Fully-qualified name of this protocol message type,
+ which will include protocol "package" name and the name of any
+ enclosing types.
+ containing_type (Descriptor): Reference to the descriptor of the type
+ containing us, or None if this is top-level.
+ fields (list[FieldDescriptor]): Field descriptors for all fields in
+ this type.
+ fields_by_number (dict(int, FieldDescriptor)): Same
+ :class:`FieldDescriptor` objects as in :attr:`fields`, but indexed
+ by "number" attribute in each FieldDescriptor.
+ fields_by_name (dict(str, FieldDescriptor)): Same
+ :class:`FieldDescriptor` objects as in :attr:`fields`, but indexed by
+ "name" attribute in each :class:`FieldDescriptor`.
+ nested_types (list[Descriptor]): Descriptor references
+ for all protocol message types nested within this one.
+ nested_types_by_name (dict(str, Descriptor)): Same Descriptor
+ objects as in :attr:`nested_types`, but indexed by "name" attribute
+ in each Descriptor.
+ enum_types (list[EnumDescriptor]): :class:`EnumDescriptor` references
+ for all enums contained within this type.
+ enum_types_by_name (dict(str, EnumDescriptor)): Same
+ :class:`EnumDescriptor` objects as in :attr:`enum_types`, but
+ indexed by "name" attribute in each EnumDescriptor.
+ enum_values_by_name (dict(str, EnumValueDescriptor)): Dict mapping
+ from enum value name to :class:`EnumValueDescriptor` for that value.
+ extensions (list[FieldDescriptor]): All extensions defined directly
+ within this message type (NOT within a nested type).
+ extensions_by_name (dict(str, FieldDescriptor)): Same FieldDescriptor
+ objects as :attr:`extensions`, but indexed by "name" attribute of each
+ FieldDescriptor.
+ is_extendable (bool): Does this type define any extension ranges?
+ oneofs (list[OneofDescriptor]): The list of descriptors for oneof fields
+ in this message.
+ oneofs_by_name (dict(str, OneofDescriptor)): Same objects as in
+ :attr:`oneofs`, but indexed by "name" attribute.
+ file (FileDescriptor): Reference to file descriptor.
"""
if _USE_C_DESCRIPTORS:
_C_DESCRIPTOR_CLASS = _message.Descriptor
- def __new__(
- cls,
- name=None,
- full_name=None,
- filename=None,
- containing_type=None,
- fields=None,
- nested_types=None,
- enum_types=None,
- extensions=None,
- options=None,
- serialized_options=None,
- is_extendable=True,
- extension_ranges=None,
- oneofs=None,
- file=None, # pylint: disable=redefined-builtin
- serialized_start=None,
- serialized_end=None,
- syntax=None,
- create_key=None):
+ def __new__(
+ cls,
+ name=None,
+ full_name=None,
+ filename=None,
+ containing_type=None,
+ fields=None,
+ nested_types=None,
+ enum_types=None,
+ extensions=None,
+ options=None,
+ serialized_options=None,
+ is_extendable=True,
+ extension_ranges=None,
+ oneofs=None,
+ file=None, # pylint: disable=redefined-builtin
+ serialized_start=None,
+ serialized_end=None,
+ syntax=None,
+ create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindMessageTypeByName(full_name)
@@ -315,23 +315,23 @@ class Descriptor(_NestedDescriptorBase):
# name of the argument.
def __init__(self, name, full_name, filename, containing_type, fields,
nested_types, enum_types, extensions, options=None,
- serialized_options=None,
+ serialized_options=None,
is_extendable=True, extension_ranges=None, oneofs=None,
file=None, serialized_start=None, serialized_end=None, # pylint: disable=redefined-builtin
- syntax=None, create_key=None):
+ syntax=None, create_key=None):
"""Arguments to __init__() are as described in the description
of Descriptor fields above.
Note that filename is an obsolete argument, that is not used anymore.
Please use file.name to access this as an attribute.
"""
- if create_key is not _internal_create_key:
- _Deprecated('Descriptor')
-
+ if create_key is not _internal_create_key:
+ _Deprecated('Descriptor')
+
super(Descriptor, self).__init__(
options, 'MessageOptions', name, full_name, file,
containing_type, serialized_start=serialized_start,
- serialized_end=serialized_end, serialized_options=serialized_options)
+ serialized_end=serialized_end, serialized_options=serialized_options)
# We have fields in addition to fields_by_name and fields_by_number,
# so that:
@@ -371,9 +371,9 @@ class Descriptor(_NestedDescriptorBase):
@property
def fields_by_camelcase_name(self):
- """Same FieldDescriptor objects as in :attr:`fields`, but indexed by
- :attr:`FieldDescriptor.camelcase_name`.
- """
+ """Same FieldDescriptor objects as in :attr:`fields`, but indexed by
+ :attr:`FieldDescriptor.camelcase_name`.
+ """
if self._fields_by_camelcase_name is None:
self._fields_by_camelcase_name = dict(
(f.camelcase_name, f) for f in self.fields)
@@ -422,51 +422,51 @@ class FieldDescriptor(DescriptorBase):
"""Descriptor for a single field in a .proto file.
- Attributes:
- name (str): Name of this field, exactly as it appears in .proto.
- full_name (str): Name of this field, including containing scope. This is
+ Attributes:
+ name (str): Name of this field, exactly as it appears in .proto.
+ full_name (str): Name of this field, including containing scope. This is
particularly relevant for extensions.
- index (int): Dense, 0-indexed index giving the order that this
+ index (int): Dense, 0-indexed index giving the order that this
field textually appears within its message in the .proto file.
- number (int): Tag number declared for this field in the .proto file.
+ number (int): Tag number declared for this field in the .proto file.
- type (int): (One of the TYPE_* constants below) Declared type.
- cpp_type (int): (One of the CPPTYPE_* constants below) C++ type used to
+ type (int): (One of the TYPE_* constants below) Declared type.
+ cpp_type (int): (One of the CPPTYPE_* constants below) C++ type used to
represent this field.
- label (int): (One of the LABEL_* constants below) Tells whether this
+ label (int): (One of the LABEL_* constants below) Tells whether this
field is optional, required, or repeated.
- has_default_value (bool): True if this field has a default value defined,
+ has_default_value (bool): True if this field has a default value defined,
otherwise false.
- default_value (Varies): Default value of this field. Only
+ default_value (Varies): Default value of this field. Only
meaningful for non-repeated scalar fields. Repeated fields
should always set this to [], and non-repeated composite
fields should always set this to None.
- containing_type (Descriptor): Descriptor of the protocol message
+ containing_type (Descriptor): Descriptor of the protocol message
type that contains this field. Set by the Descriptor constructor
if we're passed into one.
Somewhat confusingly, for extension fields, this is the
descriptor of the EXTENDED message, not the descriptor
of the message containing this field. (See is_extension and
extension_scope below).
- message_type (Descriptor): If a composite field, a descriptor
+ message_type (Descriptor): If a composite field, a descriptor
of the message type contained in this field. Otherwise, this is None.
- enum_type (EnumDescriptor): If this field contains an enum, a
+ enum_type (EnumDescriptor): If this field contains an enum, a
descriptor of that enum. Otherwise, this is None.
is_extension: True iff this describes an extension field.
- extension_scope (Descriptor): Only meaningful if is_extension is True.
+ extension_scope (Descriptor): Only meaningful if is_extension is True.
Gives the message that immediately contains this extension field.
Will be None iff we're a top-level (file-level) extension field.
- options (descriptor_pb2.FieldOptions): Protocol message field options or
+ options (descriptor_pb2.FieldOptions): Protocol message field options or
None to use default field options.
- containing_oneof (OneofDescriptor): If the field is a member of a oneof
+ containing_oneof (OneofDescriptor): If the field is a member of a oneof
union, contains its descriptor. Otherwise, None.
- file (FileDescriptor): Reference to file descriptor.
+ file (FileDescriptor): Reference to file descriptor.
"""
# Must be consistent with C++ FieldDescriptor::Type enum in
@@ -551,9 +551,9 @@ class FieldDescriptor(DescriptorBase):
def __new__(cls, name, full_name, index, number, type, cpp_type, label,
default_value, message_type, enum_type, containing_type,
is_extension, extension_scope, options=None,
- serialized_options=None,
+ serialized_options=None,
has_default_value=True, containing_oneof=None, json_name=None,
- file=None, create_key=None): # pylint: disable=redefined-builtin
+ file=None, create_key=None): # pylint: disable=redefined-builtin
_message.Message._CheckCalledFromGeneratedFile()
if is_extension:
return _message.default_pool.FindExtensionByName(full_name)
@@ -563,9 +563,9 @@ class FieldDescriptor(DescriptorBase):
def __init__(self, name, full_name, index, number, type, cpp_type, label,
default_value, message_type, enum_type, containing_type,
is_extension, extension_scope, options=None,
- serialized_options=None,
+ serialized_options=None,
has_default_value=True, containing_oneof=None, json_name=None,
- file=None, create_key=None): # pylint: disable=redefined-builtin
+ file=None, create_key=None): # pylint: disable=redefined-builtin
"""The arguments are as described in the description of FieldDescriptor
attributes above.
@@ -573,11 +573,11 @@ class FieldDescriptor(DescriptorBase):
(to deal with circular references between message types, for example).
Likewise for extension_scope.
"""
- if create_key is not _internal_create_key:
- _Deprecated('FieldDescriptor')
-
- super(FieldDescriptor, self).__init__(
- options, serialized_options, 'FieldOptions')
+ if create_key is not _internal_create_key:
+ _Deprecated('FieldDescriptor')
+
+ super(FieldDescriptor, self).__init__(
+ options, serialized_options, 'FieldOptions')
self.name = name
self.full_name = full_name
self.file = file
@@ -609,11 +609,11 @@ class FieldDescriptor(DescriptorBase):
@property
def camelcase_name(self):
- """Camelcase name of this field.
-
- Returns:
- str: the name in CamelCase.
- """
+ """Camelcase name of this field.
+
+ Returns:
+ str: the name in CamelCase.
+ """
if self._camelcase_name is None:
self._camelcase_name = _ToCamelCase(self.name)
return self._camelcase_name
@@ -629,7 +629,7 @@ class FieldDescriptor(DescriptorBase):
Args:
proto_type: the Python proto type (descriptor.FieldDescriptor.TYPE_*)
Returns:
- int: descriptor.FieldDescriptor.CPPTYPE_*, the C++ type.
+ int: descriptor.FieldDescriptor.CPPTYPE_*, the C++ type.
Raises:
TypeTransformationError: when the Python proto type isn't known.
"""
@@ -643,23 +643,23 @@ class EnumDescriptor(_NestedDescriptorBase):
"""Descriptor for an enum defined in a .proto file.
- Attributes:
- name (str): Name of the enum type.
- full_name (str): Full name of the type, including package name
+ Attributes:
+ name (str): Name of the enum type.
+ full_name (str): Full name of the type, including package name
and any enclosing type(s).
- values (list[EnumValueDescriptors]): List of the values
+ values (list[EnumValueDescriptors]): List of the values
in this enum.
- values_by_name (dict(str, EnumValueDescriptor)): Same as :attr:`values`,
+ values_by_name (dict(str, EnumValueDescriptor)): Same as :attr:`values`,
but indexed by the "name" field of each EnumValueDescriptor.
- values_by_number (dict(int, EnumValueDescriptor)): Same as :attr:`values`,
+ values_by_number (dict(int, EnumValueDescriptor)): Same as :attr:`values`,
but indexed by the "number" field of each EnumValueDescriptor.
- containing_type (Descriptor): Descriptor of the immediate containing
+ containing_type (Descriptor): Descriptor of the immediate containing
type of this enum, or None if this is an enum defined at the
top level in a .proto file. Set by Descriptor's constructor
if we're passed into one.
- file (FileDescriptor): Reference to file descriptor.
- options (descriptor_pb2.EnumOptions): Enum options message or
+ file (FileDescriptor): Reference to file descriptor.
+ options (descriptor_pb2.EnumOptions): Enum options message or
None to use default enum options.
"""
@@ -667,41 +667,41 @@ class EnumDescriptor(_NestedDescriptorBase):
_C_DESCRIPTOR_CLASS = _message.EnumDescriptor
def __new__(cls, name, full_name, filename, values,
- containing_type=None, options=None,
- serialized_options=None, file=None, # pylint: disable=redefined-builtin
- serialized_start=None, serialized_end=None, create_key=None):
+ containing_type=None, options=None,
+ serialized_options=None, file=None, # pylint: disable=redefined-builtin
+ serialized_start=None, serialized_end=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindEnumTypeByName(full_name)
def __init__(self, name, full_name, filename, values,
- containing_type=None, options=None,
- serialized_options=None, file=None, # pylint: disable=redefined-builtin
- serialized_start=None, serialized_end=None, create_key=None):
+ containing_type=None, options=None,
+ serialized_options=None, file=None, # pylint: disable=redefined-builtin
+ serialized_start=None, serialized_end=None, create_key=None):
"""Arguments are as described in the attribute description above.
Note that filename is an obsolete argument, that is not used anymore.
Please use file.name to access this as an attribute.
"""
- if create_key is not _internal_create_key:
- _Deprecated('EnumDescriptor')
-
+ if create_key is not _internal_create_key:
+ _Deprecated('EnumDescriptor')
+
super(EnumDescriptor, self).__init__(
options, 'EnumOptions', name, full_name, file,
containing_type, serialized_start=serialized_start,
- serialized_end=serialized_end, serialized_options=serialized_options)
+ serialized_end=serialized_end, serialized_options=serialized_options)
self.values = values
for value in self.values:
value.type = self
self.values_by_name = dict((v.name, v) for v in values)
- # Values are reversed to ensure that the first alias is retained.
- self.values_by_number = dict((v.number, v) for v in reversed(values))
+ # Values are reversed to ensure that the first alias is retained.
+ self.values_by_number = dict((v.number, v) for v in reversed(values))
def CopyToProto(self, proto):
"""Copies this to a descriptor_pb2.EnumDescriptorProto.
Args:
- proto (descriptor_pb2.EnumDescriptorProto): An empty descriptor proto.
+ proto (descriptor_pb2.EnumDescriptorProto): An empty descriptor proto.
"""
# This function is overridden to give a better doc comment.
super(EnumDescriptor, self).CopyToProto(proto)
@@ -711,24 +711,24 @@ class EnumValueDescriptor(DescriptorBase):
"""Descriptor for a single value within an enum.
- Attributes:
- name (str): Name of this value.
- index (int): Dense, 0-indexed index giving the order that this
+ Attributes:
+ name (str): Name of this value.
+ index (int): Dense, 0-indexed index giving the order that this
value appears textually within its enum in the .proto file.
- number (int): Actual number assigned to this enum value.
- type (EnumDescriptor): :class:`EnumDescriptor` to which this value
- belongs. Set by :class:`EnumDescriptor`'s constructor if we're
+ number (int): Actual number assigned to this enum value.
+ type (EnumDescriptor): :class:`EnumDescriptor` to which this value
+ belongs. Set by :class:`EnumDescriptor`'s constructor if we're
passed into one.
- options (descriptor_pb2.EnumValueOptions): Enum value options message or
+ options (descriptor_pb2.EnumValueOptions): Enum value options message or
None to use default enum value options options.
"""
if _USE_C_DESCRIPTORS:
_C_DESCRIPTOR_CLASS = _message.EnumValueDescriptor
- def __new__(cls, name, index, number,
- type=None, # pylint: disable=redefined-builtin
- options=None, serialized_options=None, create_key=None):
+ def __new__(cls, name, index, number,
+ type=None, # pylint: disable=redefined-builtin
+ options=None, serialized_options=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
# There is no way we can build a complete EnumValueDescriptor with the
# given parameters (the name of the Enum is not known, for example).
@@ -736,15 +736,15 @@ class EnumValueDescriptor(DescriptorBase):
# constructor, which will ignore it, so returning None is good enough.
return None
- def __init__(self, name, index, number,
- type=None, # pylint: disable=redefined-builtin
- options=None, serialized_options=None, create_key=None):
+ def __init__(self, name, index, number,
+ type=None, # pylint: disable=redefined-builtin
+ options=None, serialized_options=None, create_key=None):
"""Arguments are as described in the attribute description above."""
- if create_key is not _internal_create_key:
- _Deprecated('EnumValueDescriptor')
-
- super(EnumValueDescriptor, self).__init__(
- options, serialized_options, 'EnumValueOptions')
+ if create_key is not _internal_create_key:
+ _Deprecated('EnumValueDescriptor')
+
+ super(EnumValueDescriptor, self).__init__(
+ options, serialized_options, 'EnumValueOptions')
self.name = name
self.index = index
self.number = number
@@ -754,15 +754,15 @@ class EnumValueDescriptor(DescriptorBase):
class OneofDescriptor(DescriptorBase):
"""Descriptor for a oneof field.
- Attributes:
- name (str): Name of the oneof field.
- full_name (str): Full name of the oneof field, including package name.
- index (int): 0-based index giving the order of the oneof field inside
+ Attributes:
+ name (str): Name of the oneof field.
+ full_name (str): Full name of the oneof field, including package name.
+ index (int): 0-based index giving the order of the oneof field inside
its containing type.
- containing_type (Descriptor): :class:`Descriptor` of the protocol message
- type that contains this field. Set by the :class:`Descriptor` constructor
+ containing_type (Descriptor): :class:`Descriptor` of the protocol message
+ type that contains this field. Set by the :class:`Descriptor` constructor
if we're passed into one.
- fields (list[FieldDescriptor]): The list of field descriptors this
+ fields (list[FieldDescriptor]): The list of field descriptors this
oneof can contain.
"""
@@ -770,20 +770,20 @@ class OneofDescriptor(DescriptorBase):
_C_DESCRIPTOR_CLASS = _message.OneofDescriptor
def __new__(
- cls, name, full_name, index, containing_type, fields, options=None,
- serialized_options=None, create_key=None):
+ cls, name, full_name, index, containing_type, fields, options=None,
+ serialized_options=None, create_key=None):
_message.Message._CheckCalledFromGeneratedFile()
return _message.default_pool.FindOneofByName(full_name)
def __init__(
- self, name, full_name, index, containing_type, fields, options=None,
- serialized_options=None, create_key=None):
+ self, name, full_name, index, containing_type, fields, options=None,
+ serialized_options=None, create_key=None):
"""Arguments are as described in the attribute description above."""
- if create_key is not _internal_create_key:
- _Deprecated('OneofDescriptor')
-
- super(OneofDescriptor, self).__init__(
- options, serialized_options, 'OneofOptions')
+ if create_key is not _internal_create_key:
+ _Deprecated('OneofDescriptor')
+
+ super(OneofDescriptor, self).__init__(
+ options, serialized_options, 'OneofOptions')
self.name = name
self.full_name = full_name
self.index = index
@@ -795,49 +795,49 @@ class ServiceDescriptor(_NestedDescriptorBase):
"""Descriptor for a service.
- Attributes:
- name (str): Name of the service.
- full_name (str): Full name of the service, including package name.
- index (int): 0-indexed index giving the order that this services
- definition appears within the .proto file.
- methods (list[MethodDescriptor]): List of methods provided by this
+ Attributes:
+ name (str): Name of the service.
+ full_name (str): Full name of the service, including package name.
+ index (int): 0-indexed index giving the order that this services
+ definition appears within the .proto file.
+ methods (list[MethodDescriptor]): List of methods provided by this
service.
- methods_by_name (dict(str, MethodDescriptor)): Same
- :class:`MethodDescriptor` objects as in :attr:`methods_by_name`, but
- indexed by "name" attribute in each :class:`MethodDescriptor`.
- options (descriptor_pb2.ServiceOptions): Service options message or
+ methods_by_name (dict(str, MethodDescriptor)): Same
+ :class:`MethodDescriptor` objects as in :attr:`methods_by_name`, but
+ indexed by "name" attribute in each :class:`MethodDescriptor`.
+ options (descriptor_pb2.ServiceOptions): Service options message or
None to use default service options.
- file (FileDescriptor): Reference to file info.
+ file (FileDescriptor): Reference to file info.
"""
if _USE_C_DESCRIPTORS:
_C_DESCRIPTOR_CLASS = _message.ServiceDescriptor
- def __new__(
- cls,
- name=None,
- full_name=None,
- index=None,
- methods=None,
- options=None,
- serialized_options=None,
- file=None, # pylint: disable=redefined-builtin
- serialized_start=None,
- serialized_end=None,
- create_key=None):
+ def __new__(
+ cls,
+ name=None,
+ full_name=None,
+ index=None,
+ methods=None,
+ options=None,
+ serialized_options=None,
+ file=None, # pylint: disable=redefined-builtin
+ serialized_start=None,
+ serialized_end=None,
+ create_key=None):
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
return _message.default_pool.FindServiceByName(full_name)
- def __init__(self, name, full_name, index, methods, options=None,
- serialized_options=None, file=None, # pylint: disable=redefined-builtin
- serialized_start=None, serialized_end=None, create_key=None):
- if create_key is not _internal_create_key:
- _Deprecated('ServiceDescriptor')
-
+ def __init__(self, name, full_name, index, methods, options=None,
+ serialized_options=None, file=None, # pylint: disable=redefined-builtin
+ serialized_start=None, serialized_end=None, create_key=None):
+ if create_key is not _internal_create_key:
+ _Deprecated('ServiceDescriptor')
+
super(ServiceDescriptor, self).__init__(
options, 'ServiceOptions', name, full_name, file,
None, serialized_start=serialized_start,
- serialized_end=serialized_end, serialized_options=serialized_options)
+ serialized_end=serialized_end, serialized_options=serialized_options)
self.index = index
self.methods = methods
self.methods_by_name = dict((m.name, m) for m in methods)
@@ -846,21 +846,21 @@ class ServiceDescriptor(_NestedDescriptorBase):
method.containing_service = self
def FindMethodByName(self, name):
- """Searches for the specified method, and returns its descriptor.
-
- Args:
- name (str): Name of the method.
- Returns:
- MethodDescriptor or None: the descriptor for the requested method, if
- found.
- """
+ """Searches for the specified method, and returns its descriptor.
+
+ Args:
+ name (str): Name of the method.
+ Returns:
+ MethodDescriptor or None: the descriptor for the requested method, if
+ found.
+ """
return self.methods_by_name.get(name, None)
def CopyToProto(self, proto):
"""Copies this to a descriptor_pb2.ServiceDescriptorProto.
Args:
- proto (descriptor_pb2.ServiceDescriptorProto): An empty descriptor proto.
+ proto (descriptor_pb2.ServiceDescriptorProto): An empty descriptor proto.
"""
# This function is overridden to give a better doc comment.
super(ServiceDescriptor, self).CopyToProto(proto)
@@ -870,42 +870,42 @@ class MethodDescriptor(DescriptorBase):
"""Descriptor for a method in a service.
- Attributes:
- name (str): Name of the method within the service.
- full_name (str): Full name of method.
- index (int): 0-indexed index of the method inside the service.
- containing_service (ServiceDescriptor): The service that contains this
- method.
- input_type (Descriptor): The descriptor of the message that this method
- accepts.
- output_type (Descriptor): The descriptor of the message that this method
- returns.
- options (descriptor_pb2.MethodOptions or None): Method options message, or
- None to use default method options.
+ Attributes:
+ name (str): Name of the method within the service.
+ full_name (str): Full name of method.
+ index (int): 0-indexed index of the method inside the service.
+ containing_service (ServiceDescriptor): The service that contains this
+ method.
+ input_type (Descriptor): The descriptor of the message that this method
+ accepts.
+ output_type (Descriptor): The descriptor of the message that this method
+ returns.
+ options (descriptor_pb2.MethodOptions or None): Method options message, or
+ None to use default method options.
"""
if _USE_C_DESCRIPTORS:
_C_DESCRIPTOR_CLASS = _message.MethodDescriptor
def __new__(cls, name, full_name, index, containing_service,
- input_type, output_type, options=None, serialized_options=None,
- create_key=None):
+ input_type, output_type, options=None, serialized_options=None,
+ create_key=None):
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
return _message.default_pool.FindMethodByName(full_name)
def __init__(self, name, full_name, index, containing_service,
- input_type, output_type, options=None, serialized_options=None,
- create_key=None):
+ input_type, output_type, options=None, serialized_options=None,
+ create_key=None):
"""The arguments are as described in the description of MethodDescriptor
attributes above.
Note that containing_service may be None, and may be set later if necessary.
"""
- if create_key is not _internal_create_key:
- _Deprecated('MethodDescriptor')
-
- super(MethodDescriptor, self).__init__(
- options, serialized_options, 'MethodOptions')
+ if create_key is not _internal_create_key:
+ _Deprecated('MethodDescriptor')
+
+ super(MethodDescriptor, self).__init__(
+ options, serialized_options, 'MethodOptions')
self.name = name
self.full_name = full_name
self.index = index
@@ -913,88 +913,88 @@ class MethodDescriptor(DescriptorBase):
self.input_type = input_type
self.output_type = output_type
- def CopyToProto(self, proto):
- """Copies this to a descriptor_pb2.MethodDescriptorProto.
-
- Args:
- proto (descriptor_pb2.MethodDescriptorProto): An empty descriptor proto.
-
- Raises:
- Error: If self couldn't be serialized, due to too few constructor
- arguments.
- """
- if self.containing_service is not None:
- from google.protobuf import descriptor_pb2
- service_proto = descriptor_pb2.ServiceDescriptorProto()
- self.containing_service.CopyToProto(service_proto)
- proto.CopyFrom(service_proto.method[self.index])
- else:
- raise Error('Descriptor does not contain a service.')
-
-
+ def CopyToProto(self, proto):
+ """Copies this to a descriptor_pb2.MethodDescriptorProto.
+
+ Args:
+ proto (descriptor_pb2.MethodDescriptorProto): An empty descriptor proto.
+
+ Raises:
+ Error: If self couldn't be serialized, due to too few constructor
+ arguments.
+ """
+ if self.containing_service is not None:
+ from google.protobuf import descriptor_pb2
+ service_proto = descriptor_pb2.ServiceDescriptorProto()
+ self.containing_service.CopyToProto(service_proto)
+ proto.CopyFrom(service_proto.method[self.index])
+ else:
+ raise Error('Descriptor does not contain a service.')
+
+
class FileDescriptor(DescriptorBase):
"""Descriptor for a file. Mimics the descriptor_pb2.FileDescriptorProto.
- Note that :attr:`enum_types_by_name`, :attr:`extensions_by_name`, and
- :attr:`dependencies` fields are only set by the
- :py:mod:`google.protobuf.message_factory` module, and not by the generated
- proto code.
-
- Attributes:
- name (str): Name of file, relative to root of source tree.
- package (str): Name of the package
- syntax (str): string indicating syntax of the file (can be "proto2" or
- "proto3")
- serialized_pb (bytes): Byte string of serialized
- :class:`descriptor_pb2.FileDescriptorProto`.
- dependencies (list[FileDescriptor]): List of other :class:`FileDescriptor`
- objects this :class:`FileDescriptor` depends on.
- public_dependencies (list[FileDescriptor]): A subset of
- :attr:`dependencies`, which were declared as "public".
- message_types_by_name (dict(str, Descriptor)): Mapping from message names
- to their :class:`Desctiptor`.
- enum_types_by_name (dict(str, EnumDescriptor)): Mapping from enum names to
- their :class:`EnumDescriptor`.
- extensions_by_name (dict(str, FieldDescriptor)): Mapping from extension
- names declared at file scope to their :class:`FieldDescriptor`.
- services_by_name (dict(str, ServiceDescriptor)): Mapping from services'
- names to their :class:`ServiceDescriptor`.
- pool (DescriptorPool): The pool this descriptor belongs to. When not
- passed to the constructor, the global default pool is used.
+ Note that :attr:`enum_types_by_name`, :attr:`extensions_by_name`, and
+ :attr:`dependencies` fields are only set by the
+ :py:mod:`google.protobuf.message_factory` module, and not by the generated
+ proto code.
+
+ Attributes:
+ name (str): Name of file, relative to root of source tree.
+ package (str): Name of the package
+ syntax (str): string indicating syntax of the file (can be "proto2" or
+ "proto3")
+ serialized_pb (bytes): Byte string of serialized
+ :class:`descriptor_pb2.FileDescriptorProto`.
+ dependencies (list[FileDescriptor]): List of other :class:`FileDescriptor`
+ objects this :class:`FileDescriptor` depends on.
+ public_dependencies (list[FileDescriptor]): A subset of
+ :attr:`dependencies`, which were declared as "public".
+ message_types_by_name (dict(str, Descriptor)): Mapping from message names
+ to their :class:`Desctiptor`.
+ enum_types_by_name (dict(str, EnumDescriptor)): Mapping from enum names to
+ their :class:`EnumDescriptor`.
+ extensions_by_name (dict(str, FieldDescriptor)): Mapping from extension
+ names declared at file scope to their :class:`FieldDescriptor`.
+ services_by_name (dict(str, ServiceDescriptor)): Mapping from services'
+ names to their :class:`ServiceDescriptor`.
+ pool (DescriptorPool): The pool this descriptor belongs to. When not
+ passed to the constructor, the global default pool is used.
"""
if _USE_C_DESCRIPTORS:
_C_DESCRIPTOR_CLASS = _message.FileDescriptor
- def __new__(cls, name, package, options=None,
- serialized_options=None, serialized_pb=None,
+ def __new__(cls, name, package, options=None,
+ serialized_options=None, serialized_pb=None,
dependencies=None, public_dependencies=None,
- syntax=None, pool=None, create_key=None):
+ syntax=None, pool=None, create_key=None):
# FileDescriptor() is called from various places, not only from generated
# files, to register dynamic proto files and messages.
- # pylint: disable=g-explicit-bool-comparison
- if serialized_pb == b'':
- # Cpp generated code must be linked in if serialized_pb is ''
- try:
- return _message.default_pool.FindFileByName(name)
- except KeyError:
- raise RuntimeError('Please link in cpp generated lib for %s' % (name))
- elif serialized_pb:
+ # pylint: disable=g-explicit-bool-comparison
+ if serialized_pb == b'':
+ # Cpp generated code must be linked in if serialized_pb is ''
+ try:
+ return _message.default_pool.FindFileByName(name)
+ except KeyError:
+ raise RuntimeError('Please link in cpp generated lib for %s' % (name))
+ elif serialized_pb:
return _message.default_pool.AddSerializedFile(serialized_pb)
else:
return super(FileDescriptor, cls).__new__(cls)
- def __init__(self, name, package, options=None,
- serialized_options=None, serialized_pb=None,
+ def __init__(self, name, package, options=None,
+ serialized_options=None, serialized_pb=None,
dependencies=None, public_dependencies=None,
- syntax=None, pool=None, create_key=None):
+ syntax=None, pool=None, create_key=None):
"""Constructor."""
- if create_key is not _internal_create_key:
- _Deprecated('FileDescriptor')
-
- super(FileDescriptor, self).__init__(
- options, serialized_options, 'FileOptions')
+ if create_key is not _internal_create_key:
+ _Deprecated('FileDescriptor')
+ super(FileDescriptor, self).__init__(
+ options, serialized_options, 'FileOptions')
+
if pool is None:
from google.protobuf import descriptor_pool
pool = descriptor_pool.Default()
@@ -1107,7 +1107,7 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
# imported ones. We need to specify a file name so the descriptor pool
# accepts our FileDescriptorProto, but it is not important what that file
# name is actually set to.
- proto_name = binascii.hexlify(os.urandom(16)).decode('ascii')
+ proto_name = binascii.hexlify(os.urandom(16)).decode('ascii')
if package:
file_descriptor_proto.name = os.path.join(package.replace('.', '/'),
@@ -1130,11 +1130,11 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
for enum_proto in desc_proto.enum_type:
full_name = '.'.join(full_message_name + [enum_proto.name])
enum_desc = EnumDescriptor(
- enum_proto.name, full_name, None, [
- EnumValueDescriptor(enum_val.name, ii, enum_val.number,
- create_key=_internal_create_key)
- for ii, enum_val in enumerate(enum_proto.value)],
- create_key=_internal_create_key)
+ enum_proto.name, full_name, None, [
+ EnumValueDescriptor(enum_val.name, ii, enum_val.number,
+ create_key=_internal_create_key)
+ for ii, enum_val in enumerate(enum_proto.value)],
+ create_key=_internal_create_key)
enum_types[full_name] = enum_desc
# Create Descriptors for nested types
@@ -1173,11 +1173,11 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type),
field_proto.label, None, nested_desc, enum_desc, None, False, None,
options=_OptionsOrNone(field_proto), has_default_value=False,
- json_name=json_name, create_key=_internal_create_key)
+ json_name=json_name, create_key=_internal_create_key)
fields.append(field)
desc_name = '.'.join(full_message_name)
return Descriptor(desc_proto.name, desc_name, None, None, fields,
list(nested_types.values()), list(enum_types.values()), [],
- options=_OptionsOrNone(desc_proto),
- create_key=_internal_create_key)
+ options=_OptionsOrNone(desc_proto),
+ create_key=_internal_create_key)
diff --git a/contrib/python/protobuf/py3/google/protobuf/descriptor_database.py b/contrib/python/protobuf/py3/google/protobuf/descriptor_database.py
index 073eddc711..bd3fee2f05 100644
--- a/contrib/python/protobuf/py3/google/protobuf/descriptor_database.py
+++ b/contrib/python/protobuf/py3/google/protobuf/descriptor_database.py
@@ -32,9 +32,9 @@
__author__ = 'matthewtoia@google.com (Matt Toia)'
-import warnings
-
+import warnings
+
class Error(Exception):
pass
@@ -58,7 +58,7 @@ class DescriptorDatabase(object):
Raises:
DescriptorDatabaseConflictingDefinitionError: if an attempt is made to
add a proto with the same name but different definition than an
- existing proto in the database.
+ existing proto in the database.
"""
proto_name = file_desc_proto.name
if proto_name not in self._file_desc_protos_by_file:
@@ -66,23 +66,23 @@ class DescriptorDatabase(object):
elif self._file_desc_protos_by_file[proto_name] != file_desc_proto:
raise DescriptorDatabaseConflictingDefinitionError(
'%s already added, but with different descriptor.' % proto_name)
- else:
- return
+ else:
+ return
# Add all the top-level descriptors to the index.
package = file_desc_proto.package
for message in file_desc_proto.message_type:
- for name in _ExtractSymbols(message, package):
- self._AddSymbol(name, file_desc_proto)
+ for name in _ExtractSymbols(message, package):
+ self._AddSymbol(name, file_desc_proto)
for enum in file_desc_proto.enum_type:
- self._AddSymbol(('.'.join((package, enum.name))), file_desc_proto)
- for enum_value in enum.value:
- self._file_desc_protos_by_symbol[
- '.'.join((package, enum_value.name))] = file_desc_proto
+ self._AddSymbol(('.'.join((package, enum.name))), file_desc_proto)
+ for enum_value in enum.value:
+ self._file_desc_protos_by_symbol[
+ '.'.join((package, enum_value.name))] = file_desc_proto
for extension in file_desc_proto.extension:
- self._AddSymbol(('.'.join((package, extension.name))), file_desc_proto)
+ self._AddSymbol(('.'.join((package, extension.name))), file_desc_proto)
for service in file_desc_proto.service:
- self._AddSymbol(('.'.join((package, service.name))), file_desc_proto)
+ self._AddSymbol(('.'.join((package, service.name))), file_desc_proto)
def FindFileByName(self, name):
"""Finds the file descriptor proto by file name.
@@ -111,7 +111,7 @@ class DescriptorDatabase(object):
'some.package.name.Message'
'some.package.name.Message.NestedEnum'
- 'some.package.name.Message.some_field'
+ 'some.package.name.Message.some_field'
The file descriptor proto containing the specified symbol must be added to
this database using the Add method or else an error will be raised.
@@ -125,39 +125,39 @@ class DescriptorDatabase(object):
Raises:
KeyError if no file contains the specified symbol.
"""
- try:
- return self._file_desc_protos_by_symbol[symbol]
- except KeyError:
- # Fields, enum values, and nested extensions are not in
- # _file_desc_protos_by_symbol. Try to find the top level
- # descriptor. Non-existent nested symbol under a valid top level
- # descriptor can also be found. The behavior is the same with
- # protobuf C++.
- top_level, _, _ = symbol.rpartition('.')
- try:
- return self._file_desc_protos_by_symbol[top_level]
- except KeyError:
- # Raise the original symbol as a KeyError for better diagnostics.
- raise KeyError(symbol)
-
- def FindFileContainingExtension(self, extendee_name, extension_number):
- # TODO(jieluo): implement this API.
- return None
-
- def FindAllExtensionNumbers(self, extendee_name):
- # TODO(jieluo): implement this API.
- return []
-
- def _AddSymbol(self, name, file_desc_proto):
- if name in self._file_desc_protos_by_symbol:
- warn_msg = ('Conflict register for file "' + file_desc_proto.name +
- '": ' + name +
- ' is already defined in file "' +
- self._file_desc_protos_by_symbol[name].name + '"')
- warnings.warn(warn_msg, RuntimeWarning)
- self._file_desc_protos_by_symbol[name] = file_desc_proto
-
-
+ try:
+ return self._file_desc_protos_by_symbol[symbol]
+ except KeyError:
+ # Fields, enum values, and nested extensions are not in
+ # _file_desc_protos_by_symbol. Try to find the top level
+ # descriptor. Non-existent nested symbol under a valid top level
+ # descriptor can also be found. The behavior is the same with
+ # protobuf C++.
+ top_level, _, _ = symbol.rpartition('.')
+ try:
+ return self._file_desc_protos_by_symbol[top_level]
+ except KeyError:
+ # Raise the original symbol as a KeyError for better diagnostics.
+ raise KeyError(symbol)
+
+ def FindFileContainingExtension(self, extendee_name, extension_number):
+ # TODO(jieluo): implement this API.
+ return None
+
+ def FindAllExtensionNumbers(self, extendee_name):
+ # TODO(jieluo): implement this API.
+ return []
+
+ def _AddSymbol(self, name, file_desc_proto):
+ if name in self._file_desc_protos_by_symbol:
+ warn_msg = ('Conflict register for file "' + file_desc_proto.name +
+ '": ' + name +
+ ' is already defined in file "' +
+ self._file_desc_protos_by_symbol[name].name + '"')
+ warnings.warn(warn_msg, RuntimeWarning)
+ self._file_desc_protos_by_symbol[name] = file_desc_proto
+
+
def _ExtractSymbols(desc_proto, package):
"""Pulls out all the symbols from a descriptor proto.
diff --git a/contrib/python/protobuf/py3/google/protobuf/descriptor_pool.py b/contrib/python/protobuf/py3/google/protobuf/descriptor_pool.py
index de9100b09c..37df6e7562 100644
--- a/contrib/python/protobuf/py3/google/protobuf/descriptor_pool.py
+++ b/contrib/python/protobuf/py3/google/protobuf/descriptor_pool.py
@@ -38,7 +38,7 @@ For most applications protocol buffers should be used via modules generated by
the protocol buffer compiler tool. This should only be used when the type of
protocol buffers used in an application or library cannot be predetermined.
-Below is a straightforward example on how to use this class::
+Below is a straightforward example on how to use this class::
pool = DescriptorPool()
file_descriptor_protos = [ ... ]
@@ -58,7 +58,7 @@ directly instead of this class.
__author__ = 'matthewtoia@google.com (Matt Toia)'
import collections
-import warnings
+import warnings
from google.protobuf import descriptor
from google.protobuf import descriptor_database
@@ -68,22 +68,22 @@ from google.protobuf import text_encoding
_USE_C_DESCRIPTORS = descriptor._USE_C_DESCRIPTORS # pylint: disable=protected-access
-def _Deprecated(func):
- """Mark functions as deprecated."""
-
- def NewFunc(*args, **kwargs):
- warnings.warn(
- 'Call to deprecated function %s(). Note: Do add unlinked descriptors '
- 'to descriptor_pool is wrong. Use Add() or AddSerializedFile() '
- 'instead.' % func.__name__,
- category=DeprecationWarning)
- return func(*args, **kwargs)
- NewFunc.__name__ = func.__name__
- NewFunc.__doc__ = func.__doc__
- NewFunc.__dict__.update(func.__dict__)
- return NewFunc
-
-
+def _Deprecated(func):
+ """Mark functions as deprecated."""
+
+ def NewFunc(*args, **kwargs):
+ warnings.warn(
+ 'Call to deprecated function %s(). Note: Do add unlinked descriptors '
+ 'to descriptor_pool is wrong. Use Add() or AddSerializedFile() '
+ 'instead.' % func.__name__,
+ category=DeprecationWarning)
+ return func(*args, **kwargs)
+ NewFunc.__name__ = func.__name__
+ NewFunc.__doc__ = func.__doc__
+ NewFunc.__dict__.update(func.__dict__)
+ return NewFunc
+
+
def _NormalizeFullyQualifiedName(name):
"""Remove leading period from fully-qualified type name.
@@ -91,10 +91,10 @@ def _NormalizeFullyQualifiedName(name):
generated with a leading period. This function removes that prefix.
Args:
- name (str): The fully-qualified symbol name.
+ name (str): The fully-qualified symbol name.
Returns:
- str: The normalized fully-qualified symbol name.
+ str: The normalized fully-qualified symbol name.
"""
return name.lstrip('.')
@@ -144,59 +144,59 @@ class DescriptorPool(object):
self._service_descriptors = {}
self._file_descriptors = {}
self._toplevel_extensions = {}
- # TODO(jieluo): Remove _file_desc_by_toplevel_extension after
- # maybe year 2020 for compatibility issue (with 3.4.1 only).
+ # TODO(jieluo): Remove _file_desc_by_toplevel_extension after
+ # maybe year 2020 for compatibility issue (with 3.4.1 only).
self._file_desc_by_toplevel_extension = {}
- self._top_enum_values = {}
+ self._top_enum_values = {}
# We store extensions in two two-level mappings: The first key is the
# descriptor of the message being extended, the second key is the extension
# full name or its tag number.
self._extensions_by_name = collections.defaultdict(dict)
self._extensions_by_number = collections.defaultdict(dict)
- def _CheckConflictRegister(self, desc, desc_name, file_name):
- """Check if the descriptor name conflicts with another of the same name.
-
- Args:
- desc: Descriptor of a message, enum, service, extension or enum value.
- desc_name (str): the full name of desc.
- file_name (str): The file name of descriptor.
- """
- for register, descriptor_type in [
- (self._descriptors, descriptor.Descriptor),
- (self._enum_descriptors, descriptor.EnumDescriptor),
- (self._service_descriptors, descriptor.ServiceDescriptor),
- (self._toplevel_extensions, descriptor.FieldDescriptor),
- (self._top_enum_values, descriptor.EnumValueDescriptor)]:
- if desc_name in register:
- old_desc = register[desc_name]
- if isinstance(old_desc, descriptor.EnumValueDescriptor):
- old_file = old_desc.type.file.name
- else:
- old_file = old_desc.file.name
-
- if not isinstance(desc, descriptor_type) or (
- old_file != file_name):
- error_msg = ('Conflict register for file "' + file_name +
- '": ' + desc_name +
- ' is already defined in file "' +
- old_file + '". Please fix the conflict by adding '
- 'package name on the proto file, or use different '
- 'name for the duplication.')
- if isinstance(desc, descriptor.EnumValueDescriptor):
- error_msg += ('\nNote: enum values appear as '
- 'siblings of the enum type instead of '
- 'children of it.')
-
- raise TypeError(error_msg)
-
- return
-
+ def _CheckConflictRegister(self, desc, desc_name, file_name):
+ """Check if the descriptor name conflicts with another of the same name.
+
+ Args:
+ desc: Descriptor of a message, enum, service, extension or enum value.
+ desc_name (str): the full name of desc.
+ file_name (str): The file name of descriptor.
+ """
+ for register, descriptor_type in [
+ (self._descriptors, descriptor.Descriptor),
+ (self._enum_descriptors, descriptor.EnumDescriptor),
+ (self._service_descriptors, descriptor.ServiceDescriptor),
+ (self._toplevel_extensions, descriptor.FieldDescriptor),
+ (self._top_enum_values, descriptor.EnumValueDescriptor)]:
+ if desc_name in register:
+ old_desc = register[desc_name]
+ if isinstance(old_desc, descriptor.EnumValueDescriptor):
+ old_file = old_desc.type.file.name
+ else:
+ old_file = old_desc.file.name
+
+ if not isinstance(desc, descriptor_type) or (
+ old_file != file_name):
+ error_msg = ('Conflict register for file "' + file_name +
+ '": ' + desc_name +
+ ' is already defined in file "' +
+ old_file + '". Please fix the conflict by adding '
+ 'package name on the proto file, or use different '
+ 'name for the duplication.')
+ if isinstance(desc, descriptor.EnumValueDescriptor):
+ error_msg += ('\nNote: enum values appear as '
+ 'siblings of the enum type instead of '
+ 'children of it.')
+
+ raise TypeError(error_msg)
+
+ return
+
def Add(self, file_desc_proto):
"""Adds the FileDescriptorProto and its types to this pool.
Args:
- file_desc_proto (FileDescriptorProto): The file descriptor to add.
+ file_desc_proto (FileDescriptorProto): The file descriptor to add.
"""
self._internal_db.Add(file_desc_proto)
@@ -205,8 +205,8 @@ class DescriptorPool(object):
"""Adds the FileDescriptorProto and its types to this pool.
Args:
- serialized_file_desc_proto (bytes): A bytes string, serialization of the
- :class:`FileDescriptorProto` to add.
+ serialized_file_desc_proto (bytes): A bytes string, serialization of the
+ :class:`FileDescriptorProto` to add.
"""
# pylint: disable=g-import-not-at-top
@@ -215,14 +215,14 @@ class DescriptorPool(object):
serialized_file_desc_proto)
self.Add(file_desc_proto)
- # Add Descriptor to descriptor pool is dreprecated. Please use Add()
- # or AddSerializedFile() to add a FileDescriptorProto instead.
- @_Deprecated
+ # Add Descriptor to descriptor pool is dreprecated. Please use Add()
+ # or AddSerializedFile() to add a FileDescriptorProto instead.
+ @_Deprecated
def AddDescriptor(self, desc):
- self._AddDescriptor(desc)
-
- # Never call this method. It is for internal usage only.
- def _AddDescriptor(self, desc):
+ self._AddDescriptor(desc)
+
+ # Never call this method. It is for internal usage only.
+ def _AddDescriptor(self, desc):
"""Adds a Descriptor to the pool, non-recursively.
If the Descriptor contains nested messages or enums, the caller must
@@ -235,19 +235,19 @@ class DescriptorPool(object):
if not isinstance(desc, descriptor.Descriptor):
raise TypeError('Expected instance of descriptor.Descriptor.')
- self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
-
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
+
self._descriptors[desc.full_name] = desc
self._AddFileDescriptor(desc.file)
- # Add EnumDescriptor to descriptor pool is dreprecated. Please use Add()
- # or AddSerializedFile() to add a FileDescriptorProto instead.
- @_Deprecated
+ # Add EnumDescriptor to descriptor pool is dreprecated. Please use Add()
+ # or AddSerializedFile() to add a FileDescriptorProto instead.
+ @_Deprecated
def AddEnumDescriptor(self, enum_desc):
- self._AddEnumDescriptor(enum_desc)
-
- # Never call this method. It is for internal usage only.
- def _AddEnumDescriptor(self, enum_desc):
+ self._AddEnumDescriptor(enum_desc)
+
+ # Never call this method. It is for internal usage only.
+ def _AddEnumDescriptor(self, enum_desc):
"""Adds an EnumDescriptor to the pool.
This method also registers the FileDescriptor associated with the enum.
@@ -259,36 +259,36 @@ class DescriptorPool(object):
if not isinstance(enum_desc, descriptor.EnumDescriptor):
raise TypeError('Expected instance of descriptor.EnumDescriptor.')
- file_name = enum_desc.file.name
- self._CheckConflictRegister(enum_desc, enum_desc.full_name, file_name)
+ file_name = enum_desc.file.name
+ self._CheckConflictRegister(enum_desc, enum_desc.full_name, file_name)
self._enum_descriptors[enum_desc.full_name] = enum_desc
-
- # Top enum values need to be indexed.
- # Count the number of dots to see whether the enum is toplevel or nested
- # in a message. We cannot use enum_desc.containing_type at this stage.
- if enum_desc.file.package:
- top_level = (enum_desc.full_name.count('.')
- - enum_desc.file.package.count('.') == 1)
- else:
- top_level = enum_desc.full_name.count('.') == 0
- if top_level:
- file_name = enum_desc.file.name
- package = enum_desc.file.package
- for enum_value in enum_desc.values:
- full_name = _NormalizeFullyQualifiedName(
- '.'.join((package, enum_value.name)))
- self._CheckConflictRegister(enum_value, full_name, file_name)
- self._top_enum_values[full_name] = enum_value
+
+ # Top enum values need to be indexed.
+ # Count the number of dots to see whether the enum is toplevel or nested
+ # in a message. We cannot use enum_desc.containing_type at this stage.
+ if enum_desc.file.package:
+ top_level = (enum_desc.full_name.count('.')
+ - enum_desc.file.package.count('.') == 1)
+ else:
+ top_level = enum_desc.full_name.count('.') == 0
+ if top_level:
+ file_name = enum_desc.file.name
+ package = enum_desc.file.package
+ for enum_value in enum_desc.values:
+ full_name = _NormalizeFullyQualifiedName(
+ '.'.join((package, enum_value.name)))
+ self._CheckConflictRegister(enum_value, full_name, file_name)
+ self._top_enum_values[full_name] = enum_value
self._AddFileDescriptor(enum_desc.file)
- # Add ServiceDescriptor to descriptor pool is dreprecated. Please use Add()
- # or AddSerializedFile() to add a FileDescriptorProto instead.
- @_Deprecated
+ # Add ServiceDescriptor to descriptor pool is dreprecated. Please use Add()
+ # or AddSerializedFile() to add a FileDescriptorProto instead.
+ @_Deprecated
def AddServiceDescriptor(self, service_desc):
- self._AddServiceDescriptor(service_desc)
-
- # Never call this method. It is for internal usage only.
- def _AddServiceDescriptor(self, service_desc):
+ self._AddServiceDescriptor(service_desc)
+
+ # Never call this method. It is for internal usage only.
+ def _AddServiceDescriptor(self, service_desc):
"""Adds a ServiceDescriptor to the pool.
Args:
@@ -298,18 +298,18 @@ class DescriptorPool(object):
if not isinstance(service_desc, descriptor.ServiceDescriptor):
raise TypeError('Expected instance of descriptor.ServiceDescriptor.')
- self._CheckConflictRegister(service_desc, service_desc.full_name,
- service_desc.file.name)
+ self._CheckConflictRegister(service_desc, service_desc.full_name,
+ service_desc.file.name)
self._service_descriptors[service_desc.full_name] = service_desc
- # Add ExtensionDescriptor to descriptor pool is dreprecated. Please use Add()
- # or AddSerializedFile() to add a FileDescriptorProto instead.
- @_Deprecated
+ # Add ExtensionDescriptor to descriptor pool is dreprecated. Please use Add()
+ # or AddSerializedFile() to add a FileDescriptorProto instead.
+ @_Deprecated
def AddExtensionDescriptor(self, extension):
- self._AddExtensionDescriptor(extension)
-
- # Never call this method. It is for internal usage only.
- def _AddExtensionDescriptor(self, extension):
+ self._AddExtensionDescriptor(extension)
+
+ # Never call this method. It is for internal usage only.
+ def _AddExtensionDescriptor(self, extension):
"""Adds a FieldDescriptor describing an extension to the pool.
Args:
@@ -351,12 +351,12 @@ class DescriptorPool(object):
self._extensions_by_name[extension.containing_type][
extension.message_type.full_name] = extension
- @_Deprecated
+ @_Deprecated
def AddFileDescriptor(self, file_desc):
- self._InternalAddFileDescriptor(file_desc)
-
- # Never call this method. It is for internal usage only.
- def _InternalAddFileDescriptor(self, file_desc):
+ self._InternalAddFileDescriptor(file_desc)
+
+ # Never call this method. It is for internal usage only.
+ def _InternalAddFileDescriptor(self, file_desc):
"""Adds a FileDescriptor to the pool, non-recursively.
If the FileDescriptor contains messages or enums, the caller must explicitly
@@ -368,8 +368,8 @@ class DescriptorPool(object):
self._AddFileDescriptor(file_desc)
# TODO(jieluo): This is a temporary solution for FieldDescriptor.file.
- # FieldDescriptor.file is added in code gen. Remove this solution after
- # maybe 2020 for compatibility reason (with 3.4.1 only).
+ # FieldDescriptor.file is added in code gen. Remove this solution after
+ # maybe 2020 for compatibility reason (with 3.4.1 only).
for extension in file_desc.extensions_by_name.values():
self._file_desc_by_toplevel_extension[
extension.full_name] = file_desc
@@ -392,10 +392,10 @@ class DescriptorPool(object):
"""Gets a FileDescriptor by file name.
Args:
- file_name (str): The path to the file to get a descriptor for.
+ file_name (str): The path to the file to get a descriptor for.
Returns:
- FileDescriptor: The descriptor for the named file.
+ FileDescriptor: The descriptor for the named file.
Raises:
KeyError: if the file cannot be found in the pool.
@@ -421,11 +421,11 @@ class DescriptorPool(object):
"""Gets the FileDescriptor for the file containing the specified symbol.
Args:
- symbol (str): The name of the symbol to search for.
+ symbol (str): The name of the symbol to search for.
Returns:
- FileDescriptor: Descriptor for the file that contains the specified
- symbol.
+ FileDescriptor: Descriptor for the file that contains the specified
+ symbol.
Raises:
KeyError: if the file cannot be found in the pool.
@@ -433,31 +433,31 @@ class DescriptorPool(object):
symbol = _NormalizeFullyQualifiedName(symbol)
try:
- return self._InternalFindFileContainingSymbol(symbol)
- except KeyError:
- pass
-
- try:
- # Try fallback database. Build and find again if possible.
- self._FindFileContainingSymbolInDb(symbol)
- return self._InternalFindFileContainingSymbol(symbol)
- except KeyError:
- raise KeyError('Cannot find a file containing %s' % symbol)
-
- def _InternalFindFileContainingSymbol(self, symbol):
- """Gets the already built FileDescriptor containing the specified symbol.
-
- Args:
- symbol (str): The name of the symbol to search for.
-
- Returns:
- FileDescriptor: Descriptor for the file that contains the specified
- symbol.
-
- Raises:
- KeyError: if the file cannot be found in the pool.
- """
- try:
+ return self._InternalFindFileContainingSymbol(symbol)
+ except KeyError:
+ pass
+
+ try:
+ # Try fallback database. Build and find again if possible.
+ self._FindFileContainingSymbolInDb(symbol)
+ return self._InternalFindFileContainingSymbol(symbol)
+ except KeyError:
+ raise KeyError('Cannot find a file containing %s' % symbol)
+
+ def _InternalFindFileContainingSymbol(self, symbol):
+ """Gets the already built FileDescriptor containing the specified symbol.
+
+ Args:
+ symbol (str): The name of the symbol to search for.
+
+ Returns:
+ FileDescriptor: Descriptor for the file that contains the specified
+ symbol.
+
+ Raises:
+ KeyError: if the file cannot be found in the pool.
+ """
+ try:
return self._descriptors[symbol].file
except KeyError:
pass
@@ -473,7 +473,7 @@ class DescriptorPool(object):
pass
try:
- return self._top_enum_values[symbol].type.file
+ return self._top_enum_values[symbol].type.file
except KeyError:
pass
@@ -482,25 +482,25 @@ class DescriptorPool(object):
except KeyError:
pass
- # Try fields, enum values and nested extensions inside a message.
- top_name, _, sub_name = symbol.rpartition('.')
+ # Try fields, enum values and nested extensions inside a message.
+ top_name, _, sub_name = symbol.rpartition('.')
try:
- message = self.FindMessageTypeByName(top_name)
- assert (sub_name in message.extensions_by_name or
- sub_name in message.fields_by_name or
- sub_name in message.enum_values_by_name)
+ message = self.FindMessageTypeByName(top_name)
+ assert (sub_name in message.extensions_by_name or
+ sub_name in message.fields_by_name or
+ sub_name in message.enum_values_by_name)
return message.file
- except (KeyError, AssertionError):
+ except (KeyError, AssertionError):
raise KeyError('Cannot find a file containing %s' % symbol)
def FindMessageTypeByName(self, full_name):
"""Loads the named descriptor from the pool.
Args:
- full_name (str): The full name of the descriptor to load.
+ full_name (str): The full name of the descriptor to load.
Returns:
- Descriptor: The descriptor for the named type.
+ Descriptor: The descriptor for the named type.
Raises:
KeyError: if the message cannot be found in the pool.
@@ -515,10 +515,10 @@ class DescriptorPool(object):
"""Loads the named enum descriptor from the pool.
Args:
- full_name (str): The full name of the enum descriptor to load.
+ full_name (str): The full name of the enum descriptor to load.
Returns:
- EnumDescriptor: The enum descriptor for the named type.
+ EnumDescriptor: The enum descriptor for the named type.
Raises:
KeyError: if the enum cannot be found in the pool.
@@ -533,10 +533,10 @@ class DescriptorPool(object):
"""Loads the named field descriptor from the pool.
Args:
- full_name (str): The full name of the field descriptor to load.
+ full_name (str): The full name of the field descriptor to load.
Returns:
- FieldDescriptor: The field descriptor for the named field.
+ FieldDescriptor: The field descriptor for the named field.
Raises:
KeyError: if the field cannot be found in the pool.
@@ -546,31 +546,31 @@ class DescriptorPool(object):
message_descriptor = self.FindMessageTypeByName(message_name)
return message_descriptor.fields_by_name[field_name]
- def FindOneofByName(self, full_name):
- """Loads the named oneof descriptor from the pool.
-
- Args:
- full_name (str): The full name of the oneof descriptor to load.
-
- Returns:
- OneofDescriptor: The oneof descriptor for the named oneof.
-
- Raises:
- KeyError: if the oneof cannot be found in the pool.
- """
- full_name = _NormalizeFullyQualifiedName(full_name)
- message_name, _, oneof_name = full_name.rpartition('.')
- message_descriptor = self.FindMessageTypeByName(message_name)
- return message_descriptor.oneofs_by_name[oneof_name]
-
+ def FindOneofByName(self, full_name):
+ """Loads the named oneof descriptor from the pool.
+
+ Args:
+ full_name (str): The full name of the oneof descriptor to load.
+
+ Returns:
+ OneofDescriptor: The oneof descriptor for the named oneof.
+
+ Raises:
+ KeyError: if the oneof cannot be found in the pool.
+ """
+ full_name = _NormalizeFullyQualifiedName(full_name)
+ message_name, _, oneof_name = full_name.rpartition('.')
+ message_descriptor = self.FindMessageTypeByName(message_name)
+ return message_descriptor.oneofs_by_name[oneof_name]
+
def FindExtensionByName(self, full_name):
"""Loads the named extension descriptor from the pool.
Args:
- full_name (str): The full name of the extension descriptor to load.
+ full_name (str): The full name of the extension descriptor to load.
Returns:
- FieldDescriptor: The field descriptor for the named extension.
+ FieldDescriptor: The field descriptor for the named extension.
Raises:
KeyError: if the extension cannot be found in the pool.
@@ -596,86 +596,86 @@ class DescriptorPool(object):
def FindExtensionByNumber(self, message_descriptor, number):
"""Gets the extension of the specified message with the specified number.
- Extensions have to be registered to this pool by calling :func:`Add` or
- :func:`AddExtensionDescriptor`.
+ Extensions have to be registered to this pool by calling :func:`Add` or
+ :func:`AddExtensionDescriptor`.
Args:
- message_descriptor (Descriptor): descriptor of the extended message.
- number (int): Number of the extension field.
+ message_descriptor (Descriptor): descriptor of the extended message.
+ number (int): Number of the extension field.
Returns:
- FieldDescriptor: The descriptor for the extension.
+ FieldDescriptor: The descriptor for the extension.
Raises:
KeyError: when no extension with the given number is known for the
specified message.
"""
- try:
- return self._extensions_by_number[message_descriptor][number]
- except KeyError:
- self._TryLoadExtensionFromDB(message_descriptor, number)
- return self._extensions_by_number[message_descriptor][number]
+ try:
+ return self._extensions_by_number[message_descriptor][number]
+ except KeyError:
+ self._TryLoadExtensionFromDB(message_descriptor, number)
+ return self._extensions_by_number[message_descriptor][number]
def FindAllExtensions(self, message_descriptor):
- """Gets all the known extensions of a given message.
+ """Gets all the known extensions of a given message.
- Extensions have to be registered to this pool by build related
- :func:`Add` or :func:`AddExtensionDescriptor`.
+ Extensions have to be registered to this pool by build related
+ :func:`Add` or :func:`AddExtensionDescriptor`.
Args:
- message_descriptor (Descriptor): Descriptor of the extended message.
+ message_descriptor (Descriptor): Descriptor of the extended message.
Returns:
- list[FieldDescriptor]: Field descriptors describing the extensions.
+ list[FieldDescriptor]: Field descriptors describing the extensions.
"""
- # Fallback to descriptor db if FindAllExtensionNumbers is provided.
- if self._descriptor_db and hasattr(
- self._descriptor_db, 'FindAllExtensionNumbers'):
- full_name = message_descriptor.full_name
- all_numbers = self._descriptor_db.FindAllExtensionNumbers(full_name)
- for number in all_numbers:
- if number in self._extensions_by_number[message_descriptor]:
- continue
- self._TryLoadExtensionFromDB(message_descriptor, number)
-
+ # Fallback to descriptor db if FindAllExtensionNumbers is provided.
+ if self._descriptor_db and hasattr(
+ self._descriptor_db, 'FindAllExtensionNumbers'):
+ full_name = message_descriptor.full_name
+ all_numbers = self._descriptor_db.FindAllExtensionNumbers(full_name)
+ for number in all_numbers:
+ if number in self._extensions_by_number[message_descriptor]:
+ continue
+ self._TryLoadExtensionFromDB(message_descriptor, number)
+
return list(self._extensions_by_number[message_descriptor].values())
- def _TryLoadExtensionFromDB(self, message_descriptor, number):
- """Try to Load extensions from descriptor db.
-
- Args:
- message_descriptor: descriptor of the extended message.
- number: the extension number that needs to be loaded.
- """
- if not self._descriptor_db:
- return
- # Only supported when FindFileContainingExtension is provided.
- if not hasattr(
- self._descriptor_db, 'FindFileContainingExtension'):
- return
-
- full_name = message_descriptor.full_name
- file_proto = self._descriptor_db.FindFileContainingExtension(
- full_name, number)
-
- if file_proto is None:
- return
-
- try:
- self._ConvertFileProtoToFileDescriptor(file_proto)
- except:
- warn_msg = ('Unable to load proto file %s for extension number %d.' %
- (file_proto.name, number))
- warnings.warn(warn_msg, RuntimeWarning)
-
+ def _TryLoadExtensionFromDB(self, message_descriptor, number):
+ """Try to Load extensions from descriptor db.
+
+ Args:
+ message_descriptor: descriptor of the extended message.
+ number: the extension number that needs to be loaded.
+ """
+ if not self._descriptor_db:
+ return
+ # Only supported when FindFileContainingExtension is provided.
+ if not hasattr(
+ self._descriptor_db, 'FindFileContainingExtension'):
+ return
+
+ full_name = message_descriptor.full_name
+ file_proto = self._descriptor_db.FindFileContainingExtension(
+ full_name, number)
+
+ if file_proto is None:
+ return
+
+ try:
+ self._ConvertFileProtoToFileDescriptor(file_proto)
+ except:
+ warn_msg = ('Unable to load proto file %s for extension number %d.' %
+ (file_proto.name, number))
+ warnings.warn(warn_msg, RuntimeWarning)
+
def FindServiceByName(self, full_name):
"""Loads the named service descriptor from the pool.
Args:
- full_name (str): The full name of the service descriptor to load.
+ full_name (str): The full name of the service descriptor to load.
Returns:
- ServiceDescriptor: The service descriptor for the named service.
+ ServiceDescriptor: The service descriptor for the named service.
Raises:
KeyError: if the service cannot be found in the pool.
@@ -685,31 +685,31 @@ class DescriptorPool(object):
self._FindFileContainingSymbolInDb(full_name)
return self._service_descriptors[full_name]
- def FindMethodByName(self, full_name):
- """Loads the named service method descriptor from the pool.
-
- Args:
- full_name (str): The full name of the method descriptor to load.
-
- Returns:
- MethodDescriptor: The method descriptor for the service method.
-
- Raises:
- KeyError: if the method cannot be found in the pool.
- """
- full_name = _NormalizeFullyQualifiedName(full_name)
- service_name, _, method_name = full_name.rpartition('.')
- service_descriptor = self.FindServiceByName(service_name)
- return service_descriptor.methods_by_name[method_name]
-
+ def FindMethodByName(self, full_name):
+ """Loads the named service method descriptor from the pool.
+
+ Args:
+ full_name (str): The full name of the method descriptor to load.
+
+ Returns:
+ MethodDescriptor: The method descriptor for the service method.
+
+ Raises:
+ KeyError: if the method cannot be found in the pool.
+ """
+ full_name = _NormalizeFullyQualifiedName(full_name)
+ service_name, _, method_name = full_name.rpartition('.')
+ service_descriptor = self.FindServiceByName(service_name)
+ return service_descriptor.methods_by_name[method_name]
+
def _FindFileContainingSymbolInDb(self, symbol):
"""Finds the file in descriptor DB containing the specified symbol.
Args:
- symbol (str): The name of the symbol to search for.
+ symbol (str): The name of the symbol to search for.
Returns:
- FileDescriptor: The file that contains the specified symbol.
+ FileDescriptor: The file that contains the specified symbol.
Raises:
KeyError: if the file cannot be found in the descriptor database.
@@ -750,9 +750,9 @@ class DescriptorPool(object):
options=_OptionsOrNone(file_proto),
serialized_pb=file_proto.SerializeToString(),
dependencies=direct_deps,
- public_dependencies=public_deps,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ public_dependencies=public_deps,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
scope = {}
# This loop extracts all the message and enum types from all the
@@ -775,7 +775,7 @@ class DescriptorPool(object):
for enum_type in file_proto.enum_type:
file_descriptor.enum_types_by_name[enum_type.name] = (
self._ConvertEnumDescriptor(enum_type, file_proto.package,
- file_descriptor, None, scope, True))
+ file_descriptor, None, scope, True))
for index, extension_proto in enumerate(file_proto.extension):
extension_desc = self._MakeFieldDescriptor(
@@ -787,8 +787,8 @@ class DescriptorPool(object):
file_descriptor.package, scope)
file_descriptor.extensions_by_name[extension_desc.name] = (
extension_desc)
- self._file_desc_by_toplevel_extension[extension_desc.full_name] = (
- file_descriptor)
+ self._file_desc_by_toplevel_extension[extension_desc.full_name] = (
+ file_descriptor)
for desc_proto in file_proto.message_type:
self._SetAllFieldTypes(file_proto.package, desc_proto, scope)
@@ -811,16 +811,16 @@ class DescriptorPool(object):
self.Add(file_proto)
self._file_descriptors[file_proto.name] = file_descriptor
- # Add extensions to the pool
- file_desc = self._file_descriptors[file_proto.name]
- for extension in file_desc.extensions_by_name.values():
- self._AddExtensionDescriptor(extension)
- for message_type in file_desc.message_types_by_name.values():
- for extension in message_type.extensions:
- self._AddExtensionDescriptor(extension)
-
- return file_desc
+ # Add extensions to the pool
+ file_desc = self._file_descriptors[file_proto.name]
+ for extension in file_desc.extensions_by_name.values():
+ self._AddExtensionDescriptor(extension)
+ for message_type in file_desc.message_types_by_name.values():
+ for extension in message_type.extensions:
+ self._AddExtensionDescriptor(extension)
+ return file_desc
+
def _ConvertMessageDescriptor(self, desc_proto, package=None, file_desc=None,
scope=None, syntax=None):
"""Adds the proto to the pool in the specified package.
@@ -854,8 +854,8 @@ class DescriptorPool(object):
nested, desc_name, file_desc, scope, syntax)
for nested in desc_proto.nested_type]
enums = [
- self._ConvertEnumDescriptor(enum, desc_name, file_desc, None,
- scope, False)
+ self._ConvertEnumDescriptor(enum, desc_name, file_desc, None,
+ scope, False)
for enum in desc_proto.enum_type]
fields = [self._MakeFieldDescriptor(field, desc_name, index, file_desc)
for index, field in enumerate(desc_proto.field)]
@@ -864,11 +864,11 @@ class DescriptorPool(object):
is_extension=True)
for index, extension in enumerate(desc_proto.extension)]
oneofs = [
- # pylint: disable=g-complex-comprehension
+ # pylint: disable=g-complex-comprehension
descriptor.OneofDescriptor(desc.name, '.'.join((desc_name, desc.name)),
- index, None, [], desc.options,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ index, None, [], desc.options,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
for index, desc in enumerate(desc_proto.oneof_decl)]
extension_ranges = [(r.start, r.end) for r in desc_proto.extension_range]
if extension_ranges:
@@ -891,9 +891,9 @@ class DescriptorPool(object):
file=file_desc,
serialized_start=None,
serialized_end=None,
- syntax=syntax,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ syntax=syntax,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
for nested in desc.nested_types:
nested.containing_type = desc
for enum in desc.enum_types:
@@ -905,12 +905,12 @@ class DescriptorPool(object):
fields[field_index].containing_oneof = oneofs[oneof_index]
scope[_PrefixWithDot(desc_name)] = desc
- self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
self._descriptors[desc_name] = desc
return desc
def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None,
- containing_type=None, scope=None, top_level=False):
+ containing_type=None, scope=None, top_level=False):
"""Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf.
Args:
@@ -919,8 +919,8 @@ class DescriptorPool(object):
file_desc: The file containing the enum descriptor.
containing_type: The type containing this enum.
scope: Scope containing available types.
- top_level: If True, the enum is a top level symbol. If False, the enum
- is defined inside a message.
+ top_level: If True, the enum is a top level symbol. If False, the enum
+ is defined inside a message.
Returns:
The added descriptor
@@ -944,21 +944,21 @@ class DescriptorPool(object):
file=file_desc,
values=values,
containing_type=containing_type,
- options=_OptionsOrNone(enum_proto),
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ options=_OptionsOrNone(enum_proto),
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
scope['.%s' % enum_name] = desc
- self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
self._enum_descriptors[enum_name] = desc
-
- # Add top level enum values.
- if top_level:
- for value in values:
- full_name = _NormalizeFullyQualifiedName(
- '.'.join((package, value.name)))
- self._CheckConflictRegister(value, full_name, file_name)
- self._top_enum_values[full_name] = value
-
+
+ # Add top level enum values.
+ if top_level:
+ for value in values:
+ full_name = _NormalizeFullyQualifiedName(
+ '.'.join((package, value.name)))
+ self._CheckConflictRegister(value, full_name, file_name)
+ self._top_enum_values[full_name] = value
+
return desc
def _MakeFieldDescriptor(self, field_proto, message_name, index,
@@ -1003,9 +1003,9 @@ class DescriptorPool(object):
is_extension=is_extension,
extension_scope=None,
options=_OptionsOrNone(field_proto),
- file=file_desc,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ file=file_desc,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
def _SetAllFieldTypes(self, package, desc_proto, scope):
"""Sets all the descriptor's fields's types.
@@ -1044,7 +1044,7 @@ class DescriptorPool(object):
Args:
field_proto: Data about the field in proto format.
- field_desc: The descriptor to modify.
+ field_desc: The descriptor to modify.
package: The package the field's container is in.
scope: Enclosing scope of available types.
"""
@@ -1087,8 +1087,8 @@ class DescriptorPool(object):
elif field_proto.type == descriptor.FieldDescriptor.TYPE_BYTES:
field_desc.default_value = text_encoding.CUnescape(
field_proto.default_value)
- elif field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE:
- field_desc.default_value = None
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE:
+ field_desc.default_value = None
else:
# All other types are of the "int" type.
field_desc.default_value = int(field_proto.default_value)
@@ -1105,8 +1105,8 @@ class DescriptorPool(object):
field_desc.default_value = field_desc.enum_type.values[0].number
elif field_proto.type == descriptor.FieldDescriptor.TYPE_BYTES:
field_desc.default_value = b''
- elif field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE:
- field_desc.default_value = None
+ elif field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE:
+ field_desc.default_value = None
else:
# All other types are of the "int" type.
field_desc.default_value = 0
@@ -1129,9 +1129,9 @@ class DescriptorPool(object):
index=index,
number=value_proto.number,
options=_OptionsOrNone(value_proto),
- type=None,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ type=None,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
def _MakeServiceDescriptor(self, service_proto, service_index, scope,
package, file_desc):
@@ -1156,16 +1156,16 @@ class DescriptorPool(object):
methods = [self._MakeMethodDescriptor(method_proto, service_name, package,
scope, index)
for index, method_proto in enumerate(service_proto.method)]
- desc = descriptor.ServiceDescriptor(
- name=service_proto.name,
- full_name=service_name,
- index=service_index,
- methods=methods,
- options=_OptionsOrNone(service_proto),
- file=file_desc,
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
- self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
+ desc = descriptor.ServiceDescriptor(
+ name=service_proto.name,
+ full_name=service_name,
+ index=service_index,
+ methods=methods,
+ options=_OptionsOrNone(service_proto),
+ file=file_desc,
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
+ self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
self._service_descriptors[service_name] = desc
return desc
@@ -1188,16 +1188,16 @@ class DescriptorPool(object):
package, method_proto.input_type, scope)
output_type = self._GetTypeFromScope(
package, method_proto.output_type, scope)
- return descriptor.MethodDescriptor(
- name=method_proto.name,
- full_name=full_name,
- index=index,
- containing_service=None,
- input_type=input_type,
- output_type=output_type,
- options=_OptionsOrNone(method_proto),
- # pylint: disable=protected-access
- create_key=descriptor._internal_create_key)
+ return descriptor.MethodDescriptor(
+ name=method_proto.name,
+ full_name=full_name,
+ index=index,
+ containing_service=None,
+ input_type=input_type,
+ output_type=output_type,
+ options=_OptionsOrNone(method_proto),
+ # pylint: disable=protected-access
+ create_key=descriptor._internal_create_key)
def _ExtractSymbols(self, descriptors):
"""Pulls out all the symbols from descriptor protos.
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/__init__.py b/contrib/python/protobuf/py3/google/protobuf/internal/__init__.py
index 7d2e571a14..70cba29297 100644
--- a/contrib/python/protobuf/py3/google/protobuf/internal/__init__.py
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/__init__.py
@@ -1,30 +1,30 @@
-# Protocol Buffers - Google's data interchange format
-# Copyright 2008 Google Inc. All rights reserved.
-# https://developers.google.com/protocol-buffers/
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-# * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+# Protocol Buffers - Google's data interchange format
+# Copyright 2008 Google Inc. All rights reserved.
+# https://developers.google.com/protocol-buffers/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/_parameterized.py b/contrib/python/protobuf/py3/google/protobuf/internal/_parameterized.py
index 4cba1d479d..784af0856f 100755
--- a/contrib/python/protobuf/py3/google/protobuf/internal/_parameterized.py
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/_parameterized.py
@@ -37,8 +37,8 @@ argument tuples.
A simple example:
- class AdditionExample(parameterized.TestCase):
- @parameterized.parameters(
+ class AdditionExample(parameterized.TestCase):
+ @parameterized.parameters(
(1, 2, 3),
(4, 5, 9),
(1, 1, 3))
@@ -51,11 +51,11 @@ like a normal test method, with its own setUp/tearDown cycle. In the
example above, there are three separate testcases, one of which will
fail due to an assertion error (1 + 1 != 3).
-Parameters for individual test cases can be tuples (with positional parameters)
+Parameters for individual test cases can be tuples (with positional parameters)
or dictionaries (with named parameters):
- class AdditionExample(parameterized.TestCase):
- @parameterized.parameters(
+ class AdditionExample(parameterized.TestCase):
+ @parameterized.parameters(
{'op1': 1, 'op2': 2, 'result': 3},
{'op1': 4, 'op2': 5, 'result': 9},
)
@@ -77,13 +77,13 @@ stay the same across several invocations, object representations like
'<__main__.Foo object at 0x23d8610>'
are turned into '<__main__.Foo>'. For even more descriptive names,
-especially in test logs, you can use the named_parameters decorator. In
+especially in test logs, you can use the named_parameters decorator. In
this case, only tuples are supported, and the first parameters has to
be a string (or an object that returns an apt name when converted via
str()):
- class NamedExample(parameterized.TestCase):
- @parameterized.named_parameters(
+ class NamedExample(parameterized.TestCase):
+ @parameterized.named_parameters(
('Normal', 'aa', 'aaa', True),
('EmptyPrefix', '', 'abc', True),
('BothEmpty', '', '', True))
@@ -103,13 +103,13 @@ from the command line:
Parameterized Classes
=====================
If invocation arguments are shared across test methods in a single
-TestCase class, instead of decorating all test methods
+TestCase class, instead of decorating all test methods
individually, the class itself can be decorated:
- @parameterized.parameters(
+ @parameterized.parameters(
(1, 2, 3)
(4, 5, 9))
- class ArithmeticTest(parameterized.TestCase):
+ class ArithmeticTest(parameterized.TestCase):
def testAdd(self, arg1, arg2, result):
self.assertEqual(arg1 + arg2, result)
@@ -122,8 +122,8 @@ If parameters should be shared across several test cases, or are dynamically
created from other sources, a single non-tuple iterable can be passed into
the decorator. This iterable will be used to obtain the test cases:
- class AdditionExample(parameterized.TestCase):
- @parameterized.parameters(
+ class AdditionExample(parameterized.TestCase):
+ @parameterized.parameters(
c.op1, c.op2, c.result for c in testcases
)
def testAddition(self, op1, op2, result):
@@ -135,8 +135,8 @@ Single-Argument Test Methods
If a test method takes only one argument, the single argument does not need to
be wrapped into a tuple:
- class NegativeNumberExample(parameterized.TestCase):
- @parameterized.parameters(
+ class NegativeNumberExample(parameterized.TestCase):
+ @parameterized.parameters(
-1, -3, -4, -5
)
def testIsNegative(self, arg):
@@ -218,7 +218,7 @@ class _ParameterizedTestIter(object):
def __call__(self, *args, **kwargs):
raise RuntimeError('You appear to be running a parameterized test case '
'without having inherited from parameterized.'
- 'TestCase. This is bad because none of '
+ 'TestCase. This is bad because none of '
'your test cases are actually being run.')
def __iter__(self):
@@ -269,7 +269,7 @@ def _ModifyClass(class_object, testcases, naming_type):
'Cannot add parameters to %s,'
' which already has parameterized methods.' % (class_object,))
class_object._id_suffix = id_suffix = {}
- # We change the size of __dict__ while we iterate over it,
+ # We change the size of __dict__ while we iterate over it,
# which Python 3.x will complain about, so use copy().
for name, obj in class_object.__dict__.copy().items():
if (name.startswith(unittest.TestLoader.testMethodPrefix)
@@ -312,7 +312,7 @@ def _ParameterDecorator(naming_type, testcases):
return _Apply
-def parameters(*testcases): # pylint: disable=invalid-name
+def parameters(*testcases): # pylint: disable=invalid-name
"""A decorator for creating parameterized tests.
See the module docstring for a usage example.
@@ -327,7 +327,7 @@ def parameters(*testcases): # pylint: disable=invalid-name
return _ParameterDecorator(_ARGUMENT_REPR, testcases)
-def named_parameters(*testcases): # pylint: disable=invalid-name
+def named_parameters(*testcases): # pylint: disable=invalid-name
"""A decorator for creating parameterized tests.
See the module docstring for a usage example. The first element of
@@ -354,7 +354,7 @@ class TestGeneratorMetaclass(type):
up as tests by the unittest framework.
In general, it is supposed to be used in conjunction with the
- parameters decorator.
+ parameters decorator.
"""
def __new__(mcs, class_name, bases, dct):
@@ -391,8 +391,8 @@ def _UpdateClassDictForParamTestCase(dct, id_suffix, name, iterator):
id_suffix[new_name] = getattr(func, '__x_extra_id__', '')
-class TestCase(unittest.TestCase):
- """Base class for test cases using the parameters decorator."""
+class TestCase(unittest.TestCase):
+ """Base class for test cases using the parameters decorator."""
__metaclass__ = TestGeneratorMetaclass
def _OriginalName(self):
@@ -415,10 +415,10 @@ class TestCase(unittest.TestCase):
self._id_suffix.get(self._testMethodName, ''))
-def CoopTestCase(other_base_class):
+def CoopTestCase(other_base_class):
"""Returns a new base class with a cooperative metaclass base.
- This enables the TestCase to be used in combination
+ This enables the TestCase to be used in combination
with other base classes that have custom metaclasses, such as
mox.MoxTestBase.
@@ -431,7 +431,7 @@ def CoopTestCase(other_base_class):
from google3.testing.pybase import parameterized
- class ExampleTest(parameterized.CoopTestCase(mox.MoxTestBase)):
+ class ExampleTest(parameterized.CoopTestCase(mox.MoxTestBase)):
...
Args:
@@ -445,5 +445,5 @@ def CoopTestCase(other_base_class):
(other_base_class.__metaclass__,
TestGeneratorMetaclass), {})
return metaclass(
- 'CoopTestCase',
- (other_base_class, TestCase), {})
+ 'CoopTestCase',
+ (other_base_class, TestCase), {})
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.cc b/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.cc
index 2a7f41d2d6..f99ba09602 100644
--- a/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.cc
@@ -69,24 +69,24 @@ static const char* kImplVersionName = "api_version";
static const char* kModuleName = "_api_implementation";
static const char kModuleDocstring[] =
- "_api_implementation is a module that exposes compile-time constants that\n"
- "determine the default API implementation to use for Python proto2.\n"
- "\n"
- "It complements api_implementation.py by setting defaults using "
- "compile-time\n"
- "constants defined in C, such that one can set defaults at compilation\n"
- "(e.g. with blaze flag --copt=-DPYTHON_PROTO2_CPP_IMPL_V2).";
+ "_api_implementation is a module that exposes compile-time constants that\n"
+ "determine the default API implementation to use for Python proto2.\n"
+ "\n"
+ "It complements api_implementation.py by setting defaults using "
+ "compile-time\n"
+ "constants defined in C, such that one can set defaults at compilation\n"
+ "(e.g. with blaze flag --copt=-DPYTHON_PROTO2_CPP_IMPL_V2).";
#if PY_MAJOR_VERSION >= 3
-static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
- kModuleName,
- kModuleDocstring,
- -1,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL};
+static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
+ kModuleName,
+ kModuleDocstring,
+ -1,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL};
#define INITFUNC PyInit__api_implementation
#define INITFUNC_ERRORVAL NULL
#else
@@ -95,32 +95,32 @@ static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
#endif
extern "C" {
-PyMODINIT_FUNC INITFUNC() {
+PyMODINIT_FUNC INITFUNC() {
#if PY_MAJOR_VERSION >= 3
- PyObject* module = PyModule_Create(&_module);
+ PyObject* module = PyModule_Create(&_module);
#else
- PyObject* module = Py_InitModule3(const_cast<char*>(kModuleName), NULL,
- const_cast<char*>(kModuleDocstring));
+ PyObject* module = Py_InitModule3(const_cast<char*>(kModuleName), NULL,
+ const_cast<char*>(kModuleDocstring));
#endif
- if (module == NULL) {
- return INITFUNC_ERRORVAL;
- }
+ if (module == NULL) {
+ return INITFUNC_ERRORVAL;
+ }
- // Adds the module variable "api_version".
- if (PyModule_AddIntConstant(module, const_cast<char*>(kImplVersionName),
- kImplVersion))
+ // Adds the module variable "api_version".
+ if (PyModule_AddIntConstant(module, const_cast<char*>(kImplVersionName),
+ kImplVersion))
#if PY_MAJOR_VERSION < 3
- return;
+ return;
#else
- {
- Py_DECREF(module);
- return NULL;
- }
+ {
+ Py_DECREF(module);
+ return NULL;
+ }
- return module;
+ return module;
#endif
}
-}
+}
} // namespace python
} // namespace protobuf
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.py b/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.py
index be1af7df6b..a9d37acdd3 100644
--- a/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.py
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.py
@@ -32,7 +32,7 @@
"""
import os
-import sys
+import sys
import warnings
try:
@@ -60,25 +60,25 @@ if _api_version < 0: # Still unspecified?
raise ImportError('_use_fast_cpp_protos import succeeded but was None')
del _use_fast_cpp_protos
_api_version = 2
- from google.protobuf import use_pure_python
- raise RuntimeError(
- 'Conflicting deps on both :use_fast_cpp_protos and :use_pure_python.\n'
- ' go/build_deps_on_BOTH_use_fast_cpp_protos_AND_use_pure_python\n'
- 'This should be impossible via a link error at build time...')
+ from google.protobuf import use_pure_python
+ raise RuntimeError(
+ 'Conflicting deps on both :use_fast_cpp_protos and :use_pure_python.\n'
+ ' go/build_deps_on_BOTH_use_fast_cpp_protos_AND_use_pure_python\n'
+ 'This should be impossible via a link error at build time...')
except ImportError:
- try:
- # pylint: disable=g-import-not-at-top
- from google.protobuf import use_pure_python
- del use_pure_python # Avoids a pylint error and namespace pollution.
- _api_version = 0
- except ImportError:
- # TODO(b/74017912): It's unsafe to enable :use_fast_cpp_protos by default;
- # it can cause data loss if you have any Python-only extensions to any
- # message passed back and forth with C++ code.
- #
- # TODO(b/17427486): Once that bug is fixed, we want to make both Python 2
- # and Python 3 default to `_api_version = 2` (C++ implementation V2).
- pass
+ try:
+ # pylint: disable=g-import-not-at-top
+ from google.protobuf import use_pure_python
+ del use_pure_python # Avoids a pylint error and namespace pollution.
+ _api_version = 0
+ except ImportError:
+ # TODO(b/74017912): It's unsafe to enable :use_fast_cpp_protos by default;
+ # it can cause data loss if you have any Python-only extensions to any
+ # message passed back and forth with C++ code.
+ #
+ # TODO(b/17427486): Once that bug is fixed, we want to make both Python 2
+ # and Python 3 default to `_api_version = 2` (C++ implementation V2).
+ pass
_default_implementation_type = (
'python' if _api_version <= 0 else 'cpp')
@@ -143,12 +143,12 @@ def Type():
return _implementation_type
-def _SetType(implementation_type):
- """Never use! Only for protobuf benchmark."""
- global _implementation_type
- _implementation_type = implementation_type
-
-
+def _SetType(implementation_type):
+ """Never use! Only for protobuf benchmark."""
+ global _implementation_type
+ _implementation_type = implementation_type
+
+
# See comment on 'Type' above.
def Version():
return _implementation_version
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/containers.py b/contrib/python/protobuf/py3/google/protobuf/internal/containers.py
index 92793490bb..2653a235c3 100644
--- a/contrib/python/protobuf/py3/google/protobuf/internal/containers.py
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/containers.py
@@ -33,21 +33,21 @@
This file defines container classes which represent categories of protocol
buffer field types which need extra maintenance. Currently these categories
are:
-
-- Repeated scalar fields - These are all repeated fields which aren't
+
+- Repeated scalar fields - These are all repeated fields which aren't
composite (e.g. they are of simple types like int32, string, etc).
-- Repeated composite fields - Repeated fields which are composite. This
+- Repeated composite fields - Repeated fields which are composite. This
includes groups and nested messages.
"""
__author__ = 'petar@google.com (Petar Petrov)'
-import sys
+import sys
try:
- # This fallback applies for all versions of Python before 3.3
- import collections.abc as collections_abc
+ # This fallback applies for all versions of Python before 3.3
+ import collections.abc as collections_abc
except ImportError:
- import collections as collections_abc
+ import collections as collections_abc
if sys.version_info[0] < 3:
# We would use collections_abc.MutableMapping all the time, but in Python 2
@@ -231,13 +231,13 @@ class BaseContainer(object):
kwargs['cmp'] = kwargs.pop('sort_function')
self._values.sort(*args, **kwargs)
- def reverse(self):
- self._values.reverse()
-
-
-collections_abc.MutableSequence.register(BaseContainer)
-
+ def reverse(self):
+ self._values.reverse()
+
+collections_abc.MutableSequence.register(BaseContainer)
+
+
class RepeatedScalarFieldContainer(BaseContainer):
"""Simple, type-checked, list-like container for holding repeated scalars."""
@@ -245,13 +245,13 @@ class RepeatedScalarFieldContainer(BaseContainer):
__slots__ = ['_type_checker']
def __init__(self, message_listener, type_checker):
- """Args:
-
- message_listener: A MessageListener implementation. The
- RepeatedScalarFieldContainer will call this object's Modified() method
- when it is modified.
+ """Args:
+
+ message_listener: A MessageListener implementation. The
+ RepeatedScalarFieldContainer will call this object's Modified() method
+ when it is modified.
type_checker: A type_checkers.ValueChecker instance to run on elements
- inserted into this container.
+ inserted into this container.
"""
super(RepeatedScalarFieldContainer, self).__init__(message_listener)
self._type_checker = type_checker
@@ -384,27 +384,27 @@ class RepeatedCompositeFieldContainer(BaseContainer):
self._message_listener.Modified()
return new_element
- def append(self, value):
- """Appends one element by copying the message."""
- new_element = self._message_descriptor._concrete_class()
- new_element._SetListener(self._message_listener)
- new_element.CopyFrom(value)
- self._values.append(new_element)
- if not self._message_listener.dirty:
- self._message_listener.Modified()
-
- def insert(self, key, value):
- """Inserts the item at the specified position by copying."""
- new_element = self._message_descriptor._concrete_class()
- new_element._SetListener(self._message_listener)
- new_element.CopyFrom(value)
- self._values.insert(key, new_element)
- if not self._message_listener.dirty:
- self._message_listener.Modified()
-
+ def append(self, value):
+ """Appends one element by copying the message."""
+ new_element = self._message_descriptor._concrete_class()
+ new_element._SetListener(self._message_listener)
+ new_element.CopyFrom(value)
+ self._values.append(new_element)
+ if not self._message_listener.dirty:
+ self._message_listener.Modified()
+
+ def insert(self, key, value):
+ """Inserts the item at the specified position by copying."""
+ new_element = self._message_descriptor._concrete_class()
+ new_element._SetListener(self._message_listener)
+ new_element.CopyFrom(value)
+ self._values.insert(key, new_element)
+ if not self._message_listener.dirty:
+ self._message_listener.Modified()
+
def extend(self, elem_seq):
"""Extends by appending the given sequence of elements of the same type
-
+
as this one, copying each individual message.
"""
message_class = self._message_descriptor._concrete_class
@@ -576,7 +576,7 @@ class MessageMap(MutableMapping):
self._values = {}
def __getitem__(self, key):
- key = self._key_checker.CheckValue(key)
+ key = self._key_checker.CheckValue(key)
try:
return self._values[key]
except KeyError:
@@ -611,14 +611,14 @@ class MessageMap(MutableMapping):
return default
def __contains__(self, item):
- item = self._key_checker.CheckValue(item)
+ item = self._key_checker.CheckValue(item)
return item in self._values
def __setitem__(self, key, value):
raise ValueError('May not set values directly, call my_map[key].foo = 5')
def __delitem__(self, key):
- key = self._key_checker.CheckValue(key)
+ key = self._key_checker.CheckValue(key)
del self._values[key]
self._message_listener.Modified()
@@ -632,8 +632,8 @@ class MessageMap(MutableMapping):
return repr(self._values)
def MergeFrom(self, other):
- # pylint: disable=protected-access
- for key in other._values:
+ # pylint: disable=protected-access
+ for key in other._values:
# According to documentation: "When parsing from the wire or when merging,
# if there are duplicate map keys the last key seen is used".
if key in self:
@@ -656,130 +656,130 @@ class MessageMap(MutableMapping):
def GetEntryClass(self):
return self._entry_descriptor._concrete_class
-
-
-class _UnknownField(object):
-
- """A parsed unknown field."""
-
- # Disallows assignment to other attributes.
- __slots__ = ['_field_number', '_wire_type', '_data']
-
- def __init__(self, field_number, wire_type, data):
- self._field_number = field_number
- self._wire_type = wire_type
- self._data = data
- return
-
- def __lt__(self, other):
- # pylint: disable=protected-access
- return self._field_number < other._field_number
-
- def __eq__(self, other):
- if self is other:
- return True
- # pylint: disable=protected-access
- return (self._field_number == other._field_number and
- self._wire_type == other._wire_type and
- self._data == other._data)
-
-
-class UnknownFieldRef(object):
-
- def __init__(self, parent, index):
- self._parent = parent
- self._index = index
- return
-
- def _check_valid(self):
- if not self._parent:
- raise ValueError('UnknownField does not exist. '
- 'The parent message might be cleared.')
- if self._index >= len(self._parent):
- raise ValueError('UnknownField does not exist. '
- 'The parent message might be cleared.')
-
- @property
- def field_number(self):
- self._check_valid()
- # pylint: disable=protected-access
- return self._parent._internal_get(self._index)._field_number
-
- @property
- def wire_type(self):
- self._check_valid()
- # pylint: disable=protected-access
- return self._parent._internal_get(self._index)._wire_type
-
- @property
- def data(self):
- self._check_valid()
- # pylint: disable=protected-access
- return self._parent._internal_get(self._index)._data
-
-
-class UnknownFieldSet(object):
-
- """UnknownField container"""
-
- # Disallows assignment to other attributes.
- __slots__ = ['_values']
-
- def __init__(self):
- self._values = []
-
- def __getitem__(self, index):
- if self._values is None:
- raise ValueError('UnknownFields does not exist. '
- 'The parent message might be cleared.')
- size = len(self._values)
- if index < 0:
- index += size
- if index < 0 or index >= size:
- raise IndexError('index %d out of range'.index)
-
- return UnknownFieldRef(self, index)
-
- def _internal_get(self, index):
- return self._values[index]
-
- def __len__(self):
- if self._values is None:
- raise ValueError('UnknownFields does not exist. '
- 'The parent message might be cleared.')
- return len(self._values)
-
- def _add(self, field_number, wire_type, data):
- unknown_field = _UnknownField(field_number, wire_type, data)
- self._values.append(unknown_field)
- return unknown_field
-
- def __iter__(self):
- for i in range(len(self)):
- yield UnknownFieldRef(self, i)
-
- def _extend(self, other):
- if other is None:
- return
- # pylint: disable=protected-access
- self._values.extend(other._values)
-
- def __eq__(self, other):
- if self is other:
- return True
- # Sort unknown fields because their order shouldn't
- # affect equality test.
- values = list(self._values)
- if other is None:
- return not values
- values.sort()
- # pylint: disable=protected-access
- other_values = sorted(other._values)
- return values == other_values
-
- def _clear(self):
- for value in self._values:
- # pylint: disable=protected-access
- if isinstance(value._data, UnknownFieldSet):
- value._data._clear() # pylint: disable=protected-access
- self._values = None
+
+
+class _UnknownField(object):
+
+ """A parsed unknown field."""
+
+ # Disallows assignment to other attributes.
+ __slots__ = ['_field_number', '_wire_type', '_data']
+
+ def __init__(self, field_number, wire_type, data):
+ self._field_number = field_number
+ self._wire_type = wire_type
+ self._data = data
+ return
+
+ def __lt__(self, other):
+ # pylint: disable=protected-access
+ return self._field_number < other._field_number
+
+ def __eq__(self, other):
+ if self is other:
+ return True
+ # pylint: disable=protected-access
+ return (self._field_number == other._field_number and
+ self._wire_type == other._wire_type and
+ self._data == other._data)
+
+
+class UnknownFieldRef(object):
+
+ def __init__(self, parent, index):
+ self._parent = parent
+ self._index = index
+ return
+
+ def _check_valid(self):
+ if not self._parent:
+ raise ValueError('UnknownField does not exist. '
+ 'The parent message might be cleared.')
+ if self._index >= len(self._parent):
+ raise ValueError('UnknownField does not exist. '
+ 'The parent message might be cleared.')
+
+ @property
+ def field_number(self):
+ self._check_valid()
+ # pylint: disable=protected-access
+ return self._parent._internal_get(self._index)._field_number
+
+ @property
+ def wire_type(self):
+ self._check_valid()
+ # pylint: disable=protected-access
+ return self._parent._internal_get(self._index)._wire_type
+
+ @property
+ def data(self):
+ self._check_valid()
+ # pylint: disable=protected-access
+ return self._parent._internal_get(self._index)._data
+
+
+class UnknownFieldSet(object):
+
+ """UnknownField container"""
+
+ # Disallows assignment to other attributes.
+ __slots__ = ['_values']
+
+ def __init__(self):
+ self._values = []
+
+ def __getitem__(self, index):
+ if self._values is None:
+ raise ValueError('UnknownFields does not exist. '
+ 'The parent message might be cleared.')
+ size = len(self._values)
+ if index < 0:
+ index += size
+ if index < 0 or index >= size:
+ raise IndexError('index %d out of range'.index)
+
+ return UnknownFieldRef(self, index)
+
+ def _internal_get(self, index):
+ return self._values[index]
+
+ def __len__(self):
+ if self._values is None:
+ raise ValueError('UnknownFields does not exist. '
+ 'The parent message might be cleared.')
+ return len(self._values)
+
+ def _add(self, field_number, wire_type, data):
+ unknown_field = _UnknownField(field_number, wire_type, data)
+ self._values.append(unknown_field)
+ return unknown_field
+
+ def __iter__(self):
+ for i in range(len(self)):
+ yield UnknownFieldRef(self, i)
+
+ def _extend(self, other):
+ if other is None:
+ return
+ # pylint: disable=protected-access
+ self._values.extend(other._values)
+
+ def __eq__(self, other):
+ if self is other:
+ return True
+ # Sort unknown fields because their order shouldn't
+ # affect equality test.
+ values = list(self._values)
+ if other is None:
+ return not values
+ values.sort()
+ # pylint: disable=protected-access
+ other_values = sorted(other._values)
+ return values == other_values
+
+ def _clear(self):
+ for value in self._values:
+ # pylint: disable=protected-access
+ if isinstance(value._data, UnknownFieldSet):
+ value._data._clear() # pylint: disable=protected-access
+ self._values = None
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/decoder.py b/contrib/python/protobuf/py3/google/protobuf/internal/decoder.py
index 6804986b6e..050f845cce 100644
--- a/contrib/python/protobuf/py3/google/protobuf/internal/decoder.py
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/decoder.py
@@ -81,17 +81,17 @@ we repeatedly read a tag, look up the corresponding decoder, and invoke it.
__author__ = 'kenton@google.com (Kenton Varda)'
import struct
-import sys
+import sys
import six
-_UCS2_MAXUNICODE = 65535
+_UCS2_MAXUNICODE = 65535
if six.PY3:
long = int
-else:
- import re # pylint: disable=g-import-not-at-top
- _SURROGATE_PATTERN = re.compile(six.u(r'[\ud800-\udfff]'))
+else:
+ import re # pylint: disable=g-import-not-at-top
+ _SURROGATE_PATTERN = re.compile(six.u(r'[\ud800-\udfff]'))
-from google.protobuf.internal import containers
+from google.protobuf.internal import containers
from google.protobuf.internal import encoder
from google.protobuf.internal import wire_format
from google.protobuf import message
@@ -172,7 +172,7 @@ _DecodeSignedVarint32 = _SignedVarintDecoder(32, int)
def ReadTag(buffer, pos):
- """Read a tag from the memoryview, and return a (tag_bytes, new_pos) tuple.
+ """Read a tag from the memoryview, and return a (tag_bytes, new_pos) tuple.
We return the raw bytes of the tag rather than decoding them. The raw
bytes can then be used to look up the proper decoder. This effectively allows
@@ -180,23 +180,23 @@ def ReadTag(buffer, pos):
for work that is done in C (searching for a byte string in a hash table).
In a low-level language it would be much cheaper to decode the varint and
use that, but not in Python.
-
- Args:
- buffer: memoryview object of the encoded bytes
- pos: int of the current position to start from
-
- Returns:
- Tuple[bytes, int] of the tag data and new position.
+
+ Args:
+ buffer: memoryview object of the encoded bytes
+ pos: int of the current position to start from
+
+ Returns:
+ Tuple[bytes, int] of the tag data and new position.
"""
start = pos
while six.indexbytes(buffer, pos) & 0x80:
pos += 1
pos += 1
- tag_bytes = buffer[start:pos].tobytes()
- return tag_bytes, pos
-
+ tag_bytes = buffer[start:pos].tobytes()
+ return tag_bytes, pos
+
# --------------------------------------------------------------------
@@ -209,8 +209,8 @@ def _SimpleDecoder(wire_type, decode_value):
_DecodeVarint()
"""
- def SpecificDecoder(field_number, is_repeated, is_packed, key, new_default,
- clear_if_default=False):
+ def SpecificDecoder(field_number, is_repeated, is_packed, key, new_default,
+ clear_if_default=False):
if is_packed:
local_DecodeVarint = _DecodeVarint
def DecodePackedField(buffer, pos, end, message, field_dict):
@@ -250,13 +250,13 @@ def _SimpleDecoder(wire_type, decode_value):
return DecodeRepeatedField
else:
def DecodeField(buffer, pos, end, message, field_dict):
- (new_value, pos) = decode_value(buffer, pos)
+ (new_value, pos) = decode_value(buffer, pos)
if pos > end:
raise _DecodeError('Truncated message.')
- if clear_if_default and not new_value:
- field_dict.pop(key, None)
- else:
- field_dict[key] = new_value
+ if clear_if_default and not new_value:
+ field_dict.pop(key, None)
+ else:
+ field_dict[key] = new_value
return pos
return DecodeField
@@ -312,20 +312,20 @@ def _FloatDecoder():
local_unpack = struct.unpack
def InnerDecode(buffer, pos):
- """Decode serialized float to a float and new position.
-
- Args:
- buffer: memoryview of the serialized bytes
- pos: int, position in the memory view to start at.
-
- Returns:
- Tuple[float, int] of the deserialized float value and new position
- in the serialized data.
- """
+ """Decode serialized float to a float and new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes
+ pos: int, position in the memory view to start at.
+
+ Returns:
+ Tuple[float, int] of the deserialized float value and new position
+ in the serialized data.
+ """
# We expect a 32-bit value in little-endian byte order. Bit 1 is the sign
# bit, bits 2-9 represent the exponent, and bits 10-32 are the significand.
new_pos = pos + 4
- float_bytes = buffer[pos:new_pos].tobytes()
+ float_bytes = buffer[pos:new_pos].tobytes()
# If this value has all its exponent bits set, then it's non-finite.
# In Python 2.4, struct.unpack will convert it to a finite 64-bit value.
@@ -356,20 +356,20 @@ def _DoubleDecoder():
local_unpack = struct.unpack
def InnerDecode(buffer, pos):
- """Decode serialized double to a double and new position.
-
- Args:
- buffer: memoryview of the serialized bytes.
- pos: int, position in the memory view to start at.
-
- Returns:
- Tuple[float, int] of the decoded double value and new position
- in the serialized data.
- """
+ """Decode serialized double to a double and new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes.
+ pos: int, position in the memory view to start at.
+
+ Returns:
+ Tuple[float, int] of the decoded double value and new position
+ in the serialized data.
+ """
# We expect a 64-bit value in little-endian byte order. Bit 1 is the sign
# bit, bits 2-12 represent the exponent, and bits 13-64 are the significand.
new_pos = pos + 8
- double_bytes = buffer[pos:new_pos].tobytes()
+ double_bytes = buffer[pos:new_pos].tobytes()
# If this value has all its exponent bits set and at least one significand
# bit set, it's not a number. In Python 2.4, struct.unpack will treat it
@@ -387,25 +387,25 @@ def _DoubleDecoder():
return _SimpleDecoder(wire_format.WIRETYPE_FIXED64, InnerDecode)
-def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
- clear_if_default=False):
- """Returns a decoder for enum field."""
+def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
+ clear_if_default=False):
+ """Returns a decoder for enum field."""
enum_type = key.enum_type
if is_packed:
local_DecodeVarint = _DecodeVarint
def DecodePackedField(buffer, pos, end, message, field_dict):
- """Decode serialized packed enum to its value and a new position.
-
- Args:
- buffer: memoryview of the serialized bytes.
- pos: int, position in the memory view to start at.
- end: int, end position of serialized data
- message: Message object to store unknown fields in
- field_dict: Map[Descriptor, Any] to store decoded values in.
-
- Returns:
- int, new position in serialized data.
- """
+ """Decode serialized packed enum to its value and a new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes.
+ pos: int, position in the memory view to start at.
+ end: int, end position of serialized data
+ message: Message object to store unknown fields in
+ field_dict: Map[Descriptor, Any] to store decoded values in.
+
+ Returns:
+ int, new position in serialized data.
+ """
value = field_dict.get(key)
if value is None:
value = field_dict.setdefault(key, new_default(message))
@@ -416,7 +416,7 @@ def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
while pos < endpoint:
value_start_pos = pos
(element, pos) = _DecodeSignedVarint32(buffer, pos)
- # pylint: disable=protected-access
+ # pylint: disable=protected-access
if element in enum_type.values_by_number:
value.append(element)
else:
@@ -424,22 +424,22 @@ def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
message._unknown_fields = []
tag_bytes = encoder.TagBytes(field_number,
wire_format.WIRETYPE_VARINT)
-
+
message._unknown_fields.append(
- (tag_bytes, buffer[value_start_pos:pos].tobytes()))
- if message._unknown_field_set is None:
- message._unknown_field_set = containers.UnknownFieldSet()
- message._unknown_field_set._add(
- field_number, wire_format.WIRETYPE_VARINT, element)
- # pylint: enable=protected-access
+ (tag_bytes, buffer[value_start_pos:pos].tobytes()))
+ if message._unknown_field_set is None:
+ message._unknown_field_set = containers.UnknownFieldSet()
+ message._unknown_field_set._add(
+ field_number, wire_format.WIRETYPE_VARINT, element)
+ # pylint: enable=protected-access
if pos > endpoint:
if element in enum_type.values_by_number:
del value[-1] # Discard corrupt value.
else:
del message._unknown_fields[-1]
- # pylint: disable=protected-access
- del message._unknown_field_set._values[-1]
- # pylint: enable=protected-access
+ # pylint: disable=protected-access
+ del message._unknown_field_set._values[-1]
+ # pylint: enable=protected-access
raise _DecodeError('Packed element was truncated.')
return pos
return DecodePackedField
@@ -447,36 +447,36 @@ def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
tag_bytes = encoder.TagBytes(field_number, wire_format.WIRETYPE_VARINT)
tag_len = len(tag_bytes)
def DecodeRepeatedField(buffer, pos, end, message, field_dict):
- """Decode serialized repeated enum to its value and a new position.
-
- Args:
- buffer: memoryview of the serialized bytes.
- pos: int, position in the memory view to start at.
- end: int, end position of serialized data
- message: Message object to store unknown fields in
- field_dict: Map[Descriptor, Any] to store decoded values in.
-
- Returns:
- int, new position in serialized data.
- """
+ """Decode serialized repeated enum to its value and a new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes.
+ pos: int, position in the memory view to start at.
+ end: int, end position of serialized data
+ message: Message object to store unknown fields in
+ field_dict: Map[Descriptor, Any] to store decoded values in.
+
+ Returns:
+ int, new position in serialized data.
+ """
value = field_dict.get(key)
if value is None:
value = field_dict.setdefault(key, new_default(message))
while 1:
(element, new_pos) = _DecodeSignedVarint32(buffer, pos)
- # pylint: disable=protected-access
+ # pylint: disable=protected-access
if element in enum_type.values_by_number:
value.append(element)
else:
if not message._unknown_fields:
message._unknown_fields = []
message._unknown_fields.append(
- (tag_bytes, buffer[pos:new_pos].tobytes()))
- if message._unknown_field_set is None:
- message._unknown_field_set = containers.UnknownFieldSet()
- message._unknown_field_set._add(
- field_number, wire_format.WIRETYPE_VARINT, element)
- # pylint: enable=protected-access
+ (tag_bytes, buffer[pos:new_pos].tobytes()))
+ if message._unknown_field_set is None:
+ message._unknown_field_set = containers.UnknownFieldSet()
+ message._unknown_field_set._add(
+ field_number, wire_format.WIRETYPE_VARINT, element)
+ # pylint: enable=protected-access
# Predict that the next tag is another copy of the same repeated
# field.
pos = new_pos + tag_len
@@ -488,26 +488,26 @@ def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
return DecodeRepeatedField
else:
def DecodeField(buffer, pos, end, message, field_dict):
- """Decode serialized repeated enum to its value and a new position.
-
- Args:
- buffer: memoryview of the serialized bytes.
- pos: int, position in the memory view to start at.
- end: int, end position of serialized data
- message: Message object to store unknown fields in
- field_dict: Map[Descriptor, Any] to store decoded values in.
-
- Returns:
- int, new position in serialized data.
- """
+ """Decode serialized repeated enum to its value and a new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes.
+ pos: int, position in the memory view to start at.
+ end: int, end position of serialized data
+ message: Message object to store unknown fields in
+ field_dict: Map[Descriptor, Any] to store decoded values in.
+
+ Returns:
+ int, new position in serialized data.
+ """
value_start_pos = pos
(enum_value, pos) = _DecodeSignedVarint32(buffer, pos)
if pos > end:
raise _DecodeError('Truncated message.')
- if clear_if_default and not enum_value:
- field_dict.pop(key, None)
- return pos
- # pylint: disable=protected-access
+ if clear_if_default and not enum_value:
+ field_dict.pop(key, None)
+ return pos
+ # pylint: disable=protected-access
if enum_value in enum_type.values_by_number:
field_dict[key] = enum_value
else:
@@ -516,12 +516,12 @@ def EnumDecoder(field_number, is_repeated, is_packed, key, new_default,
tag_bytes = encoder.TagBytes(field_number,
wire_format.WIRETYPE_VARINT)
message._unknown_fields.append(
- (tag_bytes, buffer[value_start_pos:pos].tobytes()))
- if message._unknown_field_set is None:
- message._unknown_field_set = containers.UnknownFieldSet()
- message._unknown_field_set._add(
- field_number, wire_format.WIRETYPE_VARINT, enum_value)
- # pylint: enable=protected-access
+ (tag_bytes, buffer[value_start_pos:pos].tobytes()))
+ if message._unknown_field_set is None:
+ message._unknown_field_set = containers.UnknownFieldSet()
+ message._unknown_field_set._add(
+ field_number, wire_format.WIRETYPE_VARINT, enum_value)
+ # pylint: enable=protected-access
return pos
return DecodeField
@@ -558,34 +558,34 @@ BoolDecoder = _ModifiedDecoder(
wire_format.WIRETYPE_VARINT, _DecodeVarint, bool)
-def StringDecoder(field_number, is_repeated, is_packed, key, new_default,
- is_strict_utf8=False, clear_if_default=False):
+def StringDecoder(field_number, is_repeated, is_packed, key, new_default,
+ is_strict_utf8=False, clear_if_default=False):
"""Returns a decoder for a string field."""
local_DecodeVarint = _DecodeVarint
local_unicode = six.text_type
- def _ConvertToUnicode(memview):
- """Convert byte to unicode."""
- byte_str = memview.tobytes()
+ def _ConvertToUnicode(memview):
+ """Convert byte to unicode."""
+ byte_str = memview.tobytes()
try:
- value = local_unicode(byte_str, 'utf-8')
+ value = local_unicode(byte_str, 'utf-8')
except UnicodeDecodeError as e:
# add more information to the error message and re-raise it.
e.reason = '%s in field: %s' % (e, key.full_name)
raise
- if is_strict_utf8 and six.PY2 and sys.maxunicode > _UCS2_MAXUNICODE:
- # Only do the check for python2 ucs4 when is_strict_utf8 enabled
- if _SURROGATE_PATTERN.search(value):
- reason = ('String field %s contains invalid UTF-8 data when parsing'
- 'a protocol buffer: surrogates not allowed. Use'
- 'the bytes type if you intend to send raw bytes.') % (
- key.full_name)
- raise message.DecodeError(reason)
-
- return value
-
+ if is_strict_utf8 and six.PY2 and sys.maxunicode > _UCS2_MAXUNICODE:
+ # Only do the check for python2 ucs4 when is_strict_utf8 enabled
+ if _SURROGATE_PATTERN.search(value):
+ reason = ('String field %s contains invalid UTF-8 data when parsing'
+ 'a protocol buffer: surrogates not allowed. Use'
+ 'the bytes type if you intend to send raw bytes.') % (
+ key.full_name)
+ raise message.DecodeError(reason)
+
+ return value
+
assert not is_packed
if is_repeated:
tag_bytes = encoder.TagBytes(field_number,
@@ -613,16 +613,16 @@ def StringDecoder(field_number, is_repeated, is_packed, key, new_default,
new_pos = pos + size
if new_pos > end:
raise _DecodeError('Truncated string.')
- if clear_if_default and not size:
- field_dict.pop(key, None)
- else:
- field_dict[key] = _ConvertToUnicode(buffer[pos:new_pos])
+ if clear_if_default and not size:
+ field_dict.pop(key, None)
+ else:
+ field_dict[key] = _ConvertToUnicode(buffer[pos:new_pos])
return new_pos
return DecodeField
-def BytesDecoder(field_number, is_repeated, is_packed, key, new_default,
- clear_if_default=False):
+def BytesDecoder(field_number, is_repeated, is_packed, key, new_default,
+ clear_if_default=False):
"""Returns a decoder for a bytes field."""
local_DecodeVarint = _DecodeVarint
@@ -641,7 +641,7 @@ def BytesDecoder(field_number, is_repeated, is_packed, key, new_default,
new_pos = pos + size
if new_pos > end:
raise _DecodeError('Truncated string.')
- value.append(buffer[pos:new_pos].tobytes())
+ value.append(buffer[pos:new_pos].tobytes())
# Predict that the next tag is another copy of the same repeated field.
pos = new_pos + tag_len
if buffer[new_pos:pos] != tag_bytes or new_pos == end:
@@ -654,10 +654,10 @@ def BytesDecoder(field_number, is_repeated, is_packed, key, new_default,
new_pos = pos + size
if new_pos > end:
raise _DecodeError('Truncated string.')
- if clear_if_default and not size:
- field_dict.pop(key, None)
- else:
- field_dict[key] = buffer[pos:new_pos].tobytes()
+ if clear_if_default and not size:
+ field_dict.pop(key, None)
+ else:
+ field_dict[key] = buffer[pos:new_pos].tobytes()
return new_pos
return DecodeField
@@ -786,18 +786,18 @@ def MessageSetItemDecoder(descriptor):
local_SkipField = SkipField
def DecodeItem(buffer, pos, end, message, field_dict):
- """Decode serialized message set to its value and new position.
-
- Args:
- buffer: memoryview of the serialized bytes.
- pos: int, position in the memory view to start at.
- end: int, end position of serialized data
- message: Message object to store unknown fields in
- field_dict: Map[Descriptor, Any] to store decoded values in.
-
- Returns:
- int, new position in serialized data.
- """
+ """Decode serialized message set to its value and new position.
+
+ Args:
+ buffer: memoryview of the serialized bytes.
+ pos: int, position in the memory view to start at.
+ end: int, end position of serialized data
+ message: Message object to store unknown fields in
+ field_dict: Map[Descriptor, Any] to store decoded values in.
+
+ Returns:
+ int, new position in serialized data.
+ """
message_set_item_start = pos
type_id = -1
message_start = -1
@@ -828,16 +828,16 @@ def MessageSetItemDecoder(descriptor):
raise _DecodeError('MessageSet item missing message.')
extension = message.Extensions._FindExtensionByNumber(type_id)
- # pylint: disable=protected-access
+ # pylint: disable=protected-access
if extension is not None:
value = field_dict.get(extension)
if value is None:
- message_type = extension.message_type
- if not hasattr(message_type, '_concrete_class'):
- # pylint: disable=protected-access
- message._FACTORY.GetPrototype(message_type)
+ message_type = extension.message_type
+ if not hasattr(message_type, '_concrete_class'):
+ # pylint: disable=protected-access
+ message._FACTORY.GetPrototype(message_type)
value = field_dict.setdefault(
- extension, message_type._concrete_class())
+ extension, message_type._concrete_class())
if value._InternalParse(buffer, message_start,message_end) != message_end:
# The only reason _InternalParse would return early is if it encountered
# an end-group tag.
@@ -845,15 +845,15 @@ def MessageSetItemDecoder(descriptor):
else:
if not message._unknown_fields:
message._unknown_fields = []
- message._unknown_fields.append(
- (MESSAGE_SET_ITEM_TAG, buffer[message_set_item_start:pos].tobytes()))
- if message._unknown_field_set is None:
- message._unknown_field_set = containers.UnknownFieldSet()
- message._unknown_field_set._add(
- type_id,
- wire_format.WIRETYPE_LENGTH_DELIMITED,
- buffer[message_start:message_end].tobytes())
- # pylint: enable=protected-access
+ message._unknown_fields.append(
+ (MESSAGE_SET_ITEM_TAG, buffer[message_set_item_start:pos].tobytes()))
+ if message._unknown_field_set is None:
+ message._unknown_field_set = containers.UnknownFieldSet()
+ message._unknown_field_set._add(
+ type_id,
+ wire_format.WIRETYPE_LENGTH_DELIMITED,
+ buffer[message_start:message_end].tobytes())
+ # pylint: enable=protected-access
return pos
@@ -891,7 +891,7 @@ def MapDecoder(field_descriptor, new_default, is_message_map):
raise _DecodeError('Unexpected end-group tag.')
if is_message_map:
- value[submsg.key].CopyFrom(submsg.value)
+ value[submsg.key].CopyFrom(submsg.value)
else:
value[submsg.key] = submsg.value
@@ -912,7 +912,7 @@ def _SkipVarint(buffer, pos, end):
# Previously ord(buffer[pos]) raised IndexError when pos is out of range.
# With this code, ord(b'') raises TypeError. Both are handled in
# python_message.py to generate a 'Truncated message' error.
- while ord(buffer[pos:pos+1].tobytes()) & 0x80:
+ while ord(buffer[pos:pos+1].tobytes()) & 0x80:
pos += 1
pos += 1
if pos > end:
@@ -927,13 +927,13 @@ def _SkipFixed64(buffer, pos, end):
raise _DecodeError('Truncated message.')
return pos
-
-def _DecodeFixed64(buffer, pos):
- """Decode a fixed64."""
- new_pos = pos + 8
- return (struct.unpack('<Q', buffer[pos:new_pos])[0], new_pos)
-
-
+
+def _DecodeFixed64(buffer, pos):
+ """Decode a fixed64."""
+ new_pos = pos + 8
+ return (struct.unpack('<Q', buffer[pos:new_pos])[0], new_pos)
+
+
def _SkipLengthDelimited(buffer, pos, end):
"""Skip a length-delimited value. Returns the new position."""
@@ -943,7 +943,7 @@ def _SkipLengthDelimited(buffer, pos, end):
raise _DecodeError('Truncated message.')
return pos
-
+
def _SkipGroup(buffer, pos, end):
"""Skip sub-group. Returns the new position."""
@@ -954,53 +954,53 @@ def _SkipGroup(buffer, pos, end):
return pos
pos = new_pos
-
-def _DecodeUnknownFieldSet(buffer, pos, end_pos=None):
- """Decode UnknownFieldSet. Returns the UnknownFieldSet and new position."""
-
- unknown_field_set = containers.UnknownFieldSet()
- while end_pos is None or pos < end_pos:
- (tag_bytes, pos) = ReadTag(buffer, pos)
- (tag, _) = _DecodeVarint(tag_bytes, 0)
- field_number, wire_type = wire_format.UnpackTag(tag)
- if wire_type == wire_format.WIRETYPE_END_GROUP:
- break
- (data, pos) = _DecodeUnknownField(buffer, pos, wire_type)
- # pylint: disable=protected-access
- unknown_field_set._add(field_number, wire_type, data)
-
- return (unknown_field_set, pos)
-
-
-def _DecodeUnknownField(buffer, pos, wire_type):
- """Decode a unknown field. Returns the UnknownField and new position."""
-
- if wire_type == wire_format.WIRETYPE_VARINT:
- (data, pos) = _DecodeVarint(buffer, pos)
- elif wire_type == wire_format.WIRETYPE_FIXED64:
- (data, pos) = _DecodeFixed64(buffer, pos)
- elif wire_type == wire_format.WIRETYPE_FIXED32:
- (data, pos) = _DecodeFixed32(buffer, pos)
- elif wire_type == wire_format.WIRETYPE_LENGTH_DELIMITED:
- (size, pos) = _DecodeVarint(buffer, pos)
- data = buffer[pos:pos+size].tobytes()
- pos += size
- elif wire_type == wire_format.WIRETYPE_START_GROUP:
- (data, pos) = _DecodeUnknownFieldSet(buffer, pos)
- elif wire_type == wire_format.WIRETYPE_END_GROUP:
- return (0, -1)
- else:
- raise _DecodeError('Wrong wire type in tag.')
-
- return (data, pos)
-
-
+
+def _DecodeUnknownFieldSet(buffer, pos, end_pos=None):
+ """Decode UnknownFieldSet. Returns the UnknownFieldSet and new position."""
+
+ unknown_field_set = containers.UnknownFieldSet()
+ while end_pos is None or pos < end_pos:
+ (tag_bytes, pos) = ReadTag(buffer, pos)
+ (tag, _) = _DecodeVarint(tag_bytes, 0)
+ field_number, wire_type = wire_format.UnpackTag(tag)
+ if wire_type == wire_format.WIRETYPE_END_GROUP:
+ break
+ (data, pos) = _DecodeUnknownField(buffer, pos, wire_type)
+ # pylint: disable=protected-access
+ unknown_field_set._add(field_number, wire_type, data)
+
+ return (unknown_field_set, pos)
+
+
+def _DecodeUnknownField(buffer, pos, wire_type):
+ """Decode a unknown field. Returns the UnknownField and new position."""
+
+ if wire_type == wire_format.WIRETYPE_VARINT:
+ (data, pos) = _DecodeVarint(buffer, pos)
+ elif wire_type == wire_format.WIRETYPE_FIXED64:
+ (data, pos) = _DecodeFixed64(buffer, pos)
+ elif wire_type == wire_format.WIRETYPE_FIXED32:
+ (data, pos) = _DecodeFixed32(buffer, pos)
+ elif wire_type == wire_format.WIRETYPE_LENGTH_DELIMITED:
+ (size, pos) = _DecodeVarint(buffer, pos)
+ data = buffer[pos:pos+size].tobytes()
+ pos += size
+ elif wire_type == wire_format.WIRETYPE_START_GROUP:
+ (data, pos) = _DecodeUnknownFieldSet(buffer, pos)
+ elif wire_type == wire_format.WIRETYPE_END_GROUP:
+ return (0, -1)
+ else:
+ raise _DecodeError('Wrong wire type in tag.')
+
+ return (data, pos)
+
+
def _EndGroup(buffer, pos, end):
"""Skipping an END_GROUP tag returns -1 to tell the parent loop to break."""
return -1
-
+
def _SkipFixed32(buffer, pos, end):
"""Skip a fixed32 value. Returns the new position."""
@@ -1009,14 +1009,14 @@ def _SkipFixed32(buffer, pos, end):
raise _DecodeError('Truncated message.')
return pos
-
-def _DecodeFixed32(buffer, pos):
- """Decode a fixed32."""
-
- new_pos = pos + 4
- return (struct.unpack('<I', buffer[pos:new_pos])[0], new_pos)
-
-
+
+def _DecodeFixed32(buffer, pos):
+ """Decode a fixed32."""
+
+ new_pos = pos + 4
+ return (struct.unpack('<I', buffer[pos:new_pos])[0], new_pos)
+
+
def _RaiseInvalidWireType(buffer, pos, end):
"""Skip function for unknown wire types. Raises an exception."""
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/encoder.py b/contrib/python/protobuf/py3/google/protobuf/internal/encoder.py
index 0c016f3cfa..5392199155 100644
--- a/contrib/python/protobuf/py3/google/protobuf/internal/encoder.py
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/encoder.py
@@ -372,15 +372,15 @@ def MapSizer(field_descriptor, is_message_map):
def _VarintEncoder():
"""Return an encoder for a basic varint value (does not include tag)."""
- local_int2byte = six.int2byte
- def EncodeVarint(write, value, unused_deterministic=None):
+ local_int2byte = six.int2byte
+ def EncodeVarint(write, value, unused_deterministic=None):
bits = value & 0x7f
value >>= 7
while value:
- write(local_int2byte(0x80|bits))
+ write(local_int2byte(0x80|bits))
bits = value & 0x7f
value >>= 7
- return write(local_int2byte(bits))
+ return write(local_int2byte(bits))
return EncodeVarint
@@ -389,17 +389,17 @@ def _SignedVarintEncoder():
"""Return an encoder for a basic signed varint value (does not include
tag)."""
- local_int2byte = six.int2byte
- def EncodeSignedVarint(write, value, unused_deterministic=None):
+ local_int2byte = six.int2byte
+ def EncodeSignedVarint(write, value, unused_deterministic=None):
if value < 0:
value += (1 << 64)
bits = value & 0x7f
value >>= 7
while value:
- write(local_int2byte(0x80|bits))
+ write(local_int2byte(0x80|bits))
bits = value & 0x7f
value >>= 7
- return write(local_int2byte(bits))
+ return write(local_int2byte(bits))
return EncodeSignedVarint
@@ -420,8 +420,8 @@ def _VarintBytes(value):
def TagBytes(field_number, wire_type):
"""Encode the given tag and return the bytes. Only called at startup."""
- return six.binary_type(
- _VarintBytes(wire_format.PackTag(field_number, wire_type)))
+ return six.binary_type(
+ _VarintBytes(wire_format.PackTag(field_number, wire_type)))
# --------------------------------------------------------------------
# As with sizers (see above), we have a number of common encoder
@@ -526,14 +526,14 @@ def _StructPackEncoder(wire_type, format):
return EncodePackedField
elif is_repeated:
tag_bytes = TagBytes(field_number, wire_type)
- def EncodeRepeatedField(write, value, unused_deterministic=None):
+ def EncodeRepeatedField(write, value, unused_deterministic=None):
for element in value:
write(tag_bytes)
write(local_struct_pack(format, element))
return EncodeRepeatedField
else:
tag_bytes = TagBytes(field_number, wire_type)
- def EncodeField(write, value, unused_deterministic=None):
+ def EncodeField(write, value, unused_deterministic=None):
write(tag_bytes)
return write(local_struct_pack(format, value))
return EncodeField
@@ -597,7 +597,7 @@ def _FloatingPointEncoder(wire_type, format):
return EncodePackedField
elif is_repeated:
tag_bytes = TagBytes(field_number, wire_type)
- def EncodeRepeatedField(write, value, unused_deterministic=None):
+ def EncodeRepeatedField(write, value, unused_deterministic=None):
for element in value:
write(tag_bytes)
try:
@@ -607,7 +607,7 @@ def _FloatingPointEncoder(wire_type, format):
return EncodeRepeatedField
else:
tag_bytes = TagBytes(field_number, wire_type)
- def EncodeField(write, value, unused_deterministic=None):
+ def EncodeField(write, value, unused_deterministic=None):
write(tag_bytes)
try:
write(local_struct_pack(format, value))
@@ -664,7 +664,7 @@ def BoolEncoder(field_number, is_repeated, is_packed):
return EncodePackedField
elif is_repeated:
tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
- def EncodeRepeatedField(write, value, unused_deterministic=None):
+ def EncodeRepeatedField(write, value, unused_deterministic=None):
for element in value:
write(tag_bytes)
if element:
@@ -674,7 +674,7 @@ def BoolEncoder(field_number, is_repeated, is_packed):
return EncodeRepeatedField
else:
tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
- def EncodeField(write, value, unused_deterministic=None):
+ def EncodeField(write, value, unused_deterministic=None):
write(tag_bytes)
if value:
return write(true_byte)
@@ -822,7 +822,7 @@ def MapEncoder(field_descriptor):
encode_message = MessageEncoder(field_descriptor.number, False, False)
def EncodeField(write, value, deterministic):
- value_keys = sorted(value.keys()) if deterministic else value
+ value_keys = sorted(value.keys()) if deterministic else value
for key in value_keys:
entry_msg = message_type._concrete_class(key=key, value=value[key])
encode_message(write, entry_msg, deterministic)
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/enum_type_wrapper.py b/contrib/python/protobuf/py3/google/protobuf/internal/enum_type_wrapper.py
index 9ae0066584..d5cbf56bab 100644
--- a/contrib/python/protobuf/py3/google/protobuf/internal/enum_type_wrapper.py
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/enum_type_wrapper.py
@@ -37,9 +37,9 @@ on proto classes. For usage, see:
__author__ = 'rabsatt@google.com (Kevin Rabsatt)'
-import six
-
+import six
+
class EnumTypeWrapper(object):
"""A utility for finding the names of enum values."""
@@ -48,38 +48,38 @@ class EnumTypeWrapper(object):
def __init__(self, enum_type):
"""Inits EnumTypeWrapper with an EnumDescriptor."""
self._enum_type = enum_type
- self.DESCRIPTOR = enum_type # pylint: disable=invalid-name
+ self.DESCRIPTOR = enum_type # pylint: disable=invalid-name
- def Name(self, number): # pylint: disable=invalid-name
+ def Name(self, number): # pylint: disable=invalid-name
"""Returns a string containing the name of an enum value."""
- try:
+ try:
return self._enum_type.values_by_number[number].name
- except KeyError:
- pass # fall out to break exception chaining
-
- if not isinstance(number, six.integer_types):
- raise TypeError(
- 'Enum value for {} must be an int, but got {} {!r}.'.format(
- self._enum_type.name, type(number), number))
- else:
- # repr here to handle the odd case when you pass in a boolean.
- raise ValueError('Enum {} has no name defined for value {!r}'.format(
- self._enum_type.name, number))
-
- def Value(self, name): # pylint: disable=invalid-name
- """Returns the value corresponding to the given enum name."""
- try:
+ except KeyError:
+ pass # fall out to break exception chaining
+
+ if not isinstance(number, six.integer_types):
+ raise TypeError(
+ 'Enum value for {} must be an int, but got {} {!r}.'.format(
+ self._enum_type.name, type(number), number))
+ else:
+ # repr here to handle the odd case when you pass in a boolean.
+ raise ValueError('Enum {} has no name defined for value {!r}'.format(
+ self._enum_type.name, number))
+
+ def Value(self, name): # pylint: disable=invalid-name
+ """Returns the value corresponding to the given enum name."""
+ try:
return self._enum_type.values_by_name[name].number
- except KeyError:
- pass # fall out to break exception chaining
- raise ValueError('Enum {} has no value defined for name {!r}'.format(
+ except KeyError:
+ pass # fall out to break exception chaining
+ raise ValueError('Enum {} has no value defined for name {!r}'.format(
self._enum_type.name, name))
def keys(self):
"""Return a list of the string names in the enum.
- Returns:
- A list of strs, in the order they were defined in the .proto file.
+ Returns:
+ A list of strs, in the order they were defined in the .proto file.
"""
return [value_descriptor.name
@@ -88,8 +88,8 @@ class EnumTypeWrapper(object):
def values(self):
"""Return a list of the integer values in the enum.
- Returns:
- A list of ints, in the order they were defined in the .proto file.
+ Returns:
+ A list of ints, in the order they were defined in the .proto file.
"""
return [value_descriptor.number
@@ -98,20 +98,20 @@ class EnumTypeWrapper(object):
def items(self):
"""Return a list of the (name, value) pairs of the enum.
- Returns:
- A list of (str, int) pairs, in the order they were defined
- in the .proto file.
+ Returns:
+ A list of (str, int) pairs, in the order they were defined
+ in the .proto file.
"""
return [(value_descriptor.name, value_descriptor.number)
for value_descriptor in self._enum_type.values]
def __getattr__(self, name):
- """Returns the value corresponding to the given enum name."""
- try:
- return super(
- EnumTypeWrapper,
- self).__getattribute__('_enum_type').values_by_name[name].number
- except KeyError:
- pass # fall out to break exception chaining
- raise AttributeError('Enum {} has no value defined for name {!r}'.format(
- self._enum_type.name, name))
+ """Returns the value corresponding to the given enum name."""
+ try:
+ return super(
+ EnumTypeWrapper,
+ self).__getattribute__('_enum_type').values_by_name[name].number
+ except KeyError:
+ pass # fall out to break exception chaining
+ raise AttributeError('Enum {} has no value defined for name {!r}'.format(
+ self._enum_type.name, name))
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/extension_dict.py b/contrib/python/protobuf/py3/google/protobuf/internal/extension_dict.py
index b346cf283e..799e15600e 100644
--- a/contrib/python/protobuf/py3/google/protobuf/internal/extension_dict.py
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/extension_dict.py
@@ -1,213 +1,213 @@
-# Protocol Buffers - Google's data interchange format
-# Copyright 2008 Google Inc. All rights reserved.
-# https://developers.google.com/protocol-buffers/
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-# * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-"""Contains _ExtensionDict class to represent extensions.
-"""
-
-from google.protobuf.internal import type_checkers
-from google.protobuf.descriptor import FieldDescriptor
-
-
-def _VerifyExtensionHandle(message, extension_handle):
- """Verify that the given extension handle is valid."""
-
- if not isinstance(extension_handle, FieldDescriptor):
- raise KeyError('HasExtension() expects an extension handle, got: %s' %
- extension_handle)
-
- if not extension_handle.is_extension:
- raise KeyError('"%s" is not an extension.' % extension_handle.full_name)
-
- if not extension_handle.containing_type:
- raise KeyError('"%s" is missing a containing_type.'
- % extension_handle.full_name)
-
- if extension_handle.containing_type is not message.DESCRIPTOR:
- raise KeyError('Extension "%s" extends message type "%s", but this '
- 'message is of type "%s".' %
- (extension_handle.full_name,
- extension_handle.containing_type.full_name,
- message.DESCRIPTOR.full_name))
-
-
-# TODO(robinson): Unify error handling of "unknown extension" crap.
-# TODO(robinson): Support iteritems()-style iteration over all
-# extensions with the "has" bits turned on?
-class _ExtensionDict(object):
-
- """Dict-like container for Extension fields on proto instances.
-
- Note that in all cases we expect extension handles to be
- FieldDescriptors.
- """
-
- def __init__(self, extended_message):
- """
- Args:
- extended_message: Message instance for which we are the Extensions dict.
- """
- self._extended_message = extended_message
-
- def __getitem__(self, extension_handle):
- """Returns the current value of the given extension handle."""
-
- _VerifyExtensionHandle(self._extended_message, extension_handle)
-
- result = self._extended_message._fields.get(extension_handle)
- if result is not None:
- return result
-
- if extension_handle.label == FieldDescriptor.LABEL_REPEATED:
- result = extension_handle._default_constructor(self._extended_message)
- elif extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
- message_type = extension_handle.message_type
- if not hasattr(message_type, '_concrete_class'):
- # pylint: disable=protected-access
- self._extended_message._FACTORY.GetPrototype(message_type)
- assert getattr(extension_handle.message_type, '_concrete_class', None), (
- 'Uninitialized concrete class found for field %r (message type %r)'
- % (extension_handle.full_name,
- extension_handle.message_type.full_name))
- result = extension_handle.message_type._concrete_class()
- try:
- result._SetListener(self._extended_message._listener_for_children)
- except ReferenceError:
- pass
- else:
- # Singular scalar -- just return the default without inserting into the
- # dict.
- return extension_handle.default_value
-
- # Atomically check if another thread has preempted us and, if not, swap
- # in the new object we just created. If someone has preempted us, we
- # take that object and discard ours.
- # WARNING: We are relying on setdefault() being atomic. This is true
- # in CPython but we haven't investigated others. This warning appears
- # in several other locations in this file.
- result = self._extended_message._fields.setdefault(
- extension_handle, result)
-
- return result
-
- def __eq__(self, other):
- if not isinstance(other, self.__class__):
- return False
-
- my_fields = self._extended_message.ListFields()
- other_fields = other._extended_message.ListFields()
-
- # Get rid of non-extension fields.
- my_fields = [field for field in my_fields if field.is_extension]
- other_fields = [field for field in other_fields if field.is_extension]
-
- return my_fields == other_fields
-
- def __ne__(self, other):
- return not self == other
-
- def __len__(self):
- fields = self._extended_message.ListFields()
- # Get rid of non-extension fields.
- extension_fields = [field for field in fields if field[0].is_extension]
- return len(extension_fields)
-
- def __hash__(self):
- raise TypeError('unhashable object')
-
- # Note that this is only meaningful for non-repeated, scalar extension
- # fields. Note also that we may have to call _Modified() when we do
- # successfully set a field this way, to set any necessary "has" bits in the
- # ancestors of the extended message.
- def __setitem__(self, extension_handle, value):
- """If extension_handle specifies a non-repeated, scalar extension
- field, sets the value of that field.
- """
-
- _VerifyExtensionHandle(self._extended_message, extension_handle)
-
- if (extension_handle.label == FieldDescriptor.LABEL_REPEATED or
- extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE):
- raise TypeError(
- 'Cannot assign to extension "%s" because it is a repeated or '
- 'composite type.' % extension_handle.full_name)
-
- # It's slightly wasteful to lookup the type checker each time,
- # but we expect this to be a vanishingly uncommon case anyway.
- type_checker = type_checkers.GetTypeChecker(extension_handle)
- # pylint: disable=protected-access
- self._extended_message._fields[extension_handle] = (
- type_checker.CheckValue(value))
- self._extended_message._Modified()
-
- def __delitem__(self, extension_handle):
- self._extended_message.ClearExtension(extension_handle)
-
- def _FindExtensionByName(self, name):
- """Tries to find a known extension with the specified name.
-
- Args:
- name: Extension full name.
-
- Returns:
- Extension field descriptor.
- """
- return self._extended_message._extensions_by_name.get(name, None)
-
- def _FindExtensionByNumber(self, number):
- """Tries to find a known extension with the field number.
-
- Args:
- number: Extension field number.
-
- Returns:
- Extension field descriptor.
- """
- return self._extended_message._extensions_by_number.get(number, None)
-
- def __iter__(self):
- # Return a generator over the populated extension fields
- return (f[0] for f in self._extended_message.ListFields()
- if f[0].is_extension)
-
- def __contains__(self, extension_handle):
- _VerifyExtensionHandle(self._extended_message, extension_handle)
-
- if extension_handle not in self._extended_message._fields:
- return False
-
- if extension_handle.label == FieldDescriptor.LABEL_REPEATED:
- return bool(self._extended_message._fields.get(extension_handle))
-
- if extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
- value = self._extended_message._fields.get(extension_handle)
- # pylint: disable=protected-access
- return value is not None and value._is_present_in_parent
-
- return True
+# Protocol Buffers - Google's data interchange format
+# Copyright 2008 Google Inc. All rights reserved.
+# https://developers.google.com/protocol-buffers/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Contains _ExtensionDict class to represent extensions.
+"""
+
+from google.protobuf.internal import type_checkers
+from google.protobuf.descriptor import FieldDescriptor
+
+
+def _VerifyExtensionHandle(message, extension_handle):
+ """Verify that the given extension handle is valid."""
+
+ if not isinstance(extension_handle, FieldDescriptor):
+ raise KeyError('HasExtension() expects an extension handle, got: %s' %
+ extension_handle)
+
+ if not extension_handle.is_extension:
+ raise KeyError('"%s" is not an extension.' % extension_handle.full_name)
+
+ if not extension_handle.containing_type:
+ raise KeyError('"%s" is missing a containing_type.'
+ % extension_handle.full_name)
+
+ if extension_handle.containing_type is not message.DESCRIPTOR:
+ raise KeyError('Extension "%s" extends message type "%s", but this '
+ 'message is of type "%s".' %
+ (extension_handle.full_name,
+ extension_handle.containing_type.full_name,
+ message.DESCRIPTOR.full_name))
+
+
+# TODO(robinson): Unify error handling of "unknown extension" crap.
+# TODO(robinson): Support iteritems()-style iteration over all
+# extensions with the "has" bits turned on?
+class _ExtensionDict(object):
+
+ """Dict-like container for Extension fields on proto instances.
+
+ Note that in all cases we expect extension handles to be
+ FieldDescriptors.
+ """
+
+ def __init__(self, extended_message):
+ """
+ Args:
+ extended_message: Message instance for which we are the Extensions dict.
+ """
+ self._extended_message = extended_message
+
+ def __getitem__(self, extension_handle):
+ """Returns the current value of the given extension handle."""
+
+ _VerifyExtensionHandle(self._extended_message, extension_handle)
+
+ result = self._extended_message._fields.get(extension_handle)
+ if result is not None:
+ return result
+
+ if extension_handle.label == FieldDescriptor.LABEL_REPEATED:
+ result = extension_handle._default_constructor(self._extended_message)
+ elif extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
+ message_type = extension_handle.message_type
+ if not hasattr(message_type, '_concrete_class'):
+ # pylint: disable=protected-access
+ self._extended_message._FACTORY.GetPrototype(message_type)
+ assert getattr(extension_handle.message_type, '_concrete_class', None), (
+ 'Uninitialized concrete class found for field %r (message type %r)'
+ % (extension_handle.full_name,
+ extension_handle.message_type.full_name))
+ result = extension_handle.message_type._concrete_class()
+ try:
+ result._SetListener(self._extended_message._listener_for_children)
+ except ReferenceError:
+ pass
+ else:
+ # Singular scalar -- just return the default without inserting into the
+ # dict.
+ return extension_handle.default_value
+
+ # Atomically check if another thread has preempted us and, if not, swap
+ # in the new object we just created. If someone has preempted us, we
+ # take that object and discard ours.
+ # WARNING: We are relying on setdefault() being atomic. This is true
+ # in CPython but we haven't investigated others. This warning appears
+ # in several other locations in this file.
+ result = self._extended_message._fields.setdefault(
+ extension_handle, result)
+
+ return result
+
+ def __eq__(self, other):
+ if not isinstance(other, self.__class__):
+ return False
+
+ my_fields = self._extended_message.ListFields()
+ other_fields = other._extended_message.ListFields()
+
+ # Get rid of non-extension fields.
+ my_fields = [field for field in my_fields if field.is_extension]
+ other_fields = [field for field in other_fields if field.is_extension]
+
+ return my_fields == other_fields
+
+ def __ne__(self, other):
+ return not self == other
+
+ def __len__(self):
+ fields = self._extended_message.ListFields()
+ # Get rid of non-extension fields.
+ extension_fields = [field for field in fields if field[0].is_extension]
+ return len(extension_fields)
+
+ def __hash__(self):
+ raise TypeError('unhashable object')
+
+ # Note that this is only meaningful for non-repeated, scalar extension
+ # fields. Note also that we may have to call _Modified() when we do
+ # successfully set a field this way, to set any necessary "has" bits in the
+ # ancestors of the extended message.
+ def __setitem__(self, extension_handle, value):
+ """If extension_handle specifies a non-repeated, scalar extension
+ field, sets the value of that field.
+ """
+
+ _VerifyExtensionHandle(self._extended_message, extension_handle)
+
+ if (extension_handle.label == FieldDescriptor.LABEL_REPEATED or
+ extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE):
+ raise TypeError(
+ 'Cannot assign to extension "%s" because it is a repeated or '
+ 'composite type.' % extension_handle.full_name)
+
+ # It's slightly wasteful to lookup the type checker each time,
+ # but we expect this to be a vanishingly uncommon case anyway.
+ type_checker = type_checkers.GetTypeChecker(extension_handle)
+ # pylint: disable=protected-access
+ self._extended_message._fields[extension_handle] = (
+ type_checker.CheckValue(value))
+ self._extended_message._Modified()
+
+ def __delitem__(self, extension_handle):
+ self._extended_message.ClearExtension(extension_handle)
+
+ def _FindExtensionByName(self, name):
+ """Tries to find a known extension with the specified name.
+
+ Args:
+ name: Extension full name.
+
+ Returns:
+ Extension field descriptor.
+ """
+ return self._extended_message._extensions_by_name.get(name, None)
+
+ def _FindExtensionByNumber(self, number):
+ """Tries to find a known extension with the field number.
+
+ Args:
+ number: Extension field number.
+
+ Returns:
+ Extension field descriptor.
+ """
+ return self._extended_message._extensions_by_number.get(number, None)
+
+ def __iter__(self):
+ # Return a generator over the populated extension fields
+ return (f[0] for f in self._extended_message.ListFields()
+ if f[0].is_extension)
+
+ def __contains__(self, extension_handle):
+ _VerifyExtensionHandle(self._extended_message, extension_handle)
+
+ if extension_handle not in self._extended_message._fields:
+ return False
+
+ if extension_handle.label == FieldDescriptor.LABEL_REPEATED:
+ return bool(self._extended_message._fields.get(extension_handle))
+
+ if extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
+ value = self._extended_message._fields.get(extension_handle)
+ # pylint: disable=protected-access
+ return value is not None and value._is_present_in_parent
+
+ return True
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/python_message.py b/contrib/python/protobuf/py3/google/protobuf/internal/python_message.py
index 99d2f078de..0107202581 100644
--- a/contrib/python/protobuf/py3/google/protobuf/internal/python_message.py
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/python_message.py
@@ -56,7 +56,7 @@ import sys
import weakref
import six
-from six.moves import range
+from six.moves import range
# We use "as" to avoid name collisions with variables.
from google.protobuf.internal import api_implementation
@@ -64,7 +64,7 @@ from google.protobuf.internal import containers
from google.protobuf.internal import decoder
from google.protobuf.internal import encoder
from google.protobuf.internal import enum_type_wrapper
-from google.protobuf.internal import extension_dict
+from google.protobuf.internal import extension_dict
from google.protobuf.internal import message_listener as message_listener_mod
from google.protobuf.internal import type_checkers
from google.protobuf.internal import well_known_types
@@ -75,7 +75,7 @@ from google.protobuf import text_format
_FieldDescriptor = descriptor_mod.FieldDescriptor
_AnyFullTypeName = 'google.protobuf.Any'
-_ExtensionDict = extension_dict._ExtensionDict
+_ExtensionDict = extension_dict._ExtensionDict
class GeneratedProtocolMessageType(type):
@@ -124,30 +124,30 @@ class GeneratedProtocolMessageType(type):
Returns:
Newly-allocated class.
-
- Raises:
- RuntimeError: Generated code only work with python cpp extension.
+
+ Raises:
+ RuntimeError: Generated code only work with python cpp extension.
"""
descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY]
-
- if isinstance(descriptor, str):
- raise RuntimeError('The generated code only work with python cpp '
- 'extension, but it is using pure python runtime.')
-
- # If a concrete class already exists for this descriptor, don't try to
- # create another. Doing so will break any messages that already exist with
- # the existing class.
- #
- # The C++ implementation appears to have its own internal `PyMessageFactory`
- # to achieve similar results.
- #
- # This most commonly happens in `text_format.py` when using descriptors from
- # a custom pool; it calls symbol_database.Global().getPrototype() on a
- # descriptor which already has an existing concrete class.
- new_class = getattr(descriptor, '_concrete_class', None)
- if new_class:
- return new_class
-
+
+ if isinstance(descriptor, str):
+ raise RuntimeError('The generated code only work with python cpp '
+ 'extension, but it is using pure python runtime.')
+
+ # If a concrete class already exists for this descriptor, don't try to
+ # create another. Doing so will break any messages that already exist with
+ # the existing class.
+ #
+ # The C++ implementation appears to have its own internal `PyMessageFactory`
+ # to achieve similar results.
+ #
+ # This most commonly happens in `text_format.py` when using descriptors from
+ # a custom pool; it calls symbol_database.Global().getPrototype() on a
+ # descriptor which already has an existing concrete class.
+ new_class = getattr(descriptor, '_concrete_class', None)
+ if new_class:
+ return new_class
+
if descriptor.full_name in well_known_types.WKTBASES:
bases += (well_known_types.WKTBASES[descriptor.full_name],)
_AddClassAttributesForNestedExtensions(descriptor, dictionary)
@@ -175,16 +175,16 @@ class GeneratedProtocolMessageType(type):
type.
"""
descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY]
-
- # If this is an _existing_ class looked up via `_concrete_class` in the
- # __new__ method above, then we don't need to re-initialize anything.
- existing_class = getattr(descriptor, '_concrete_class', None)
- if existing_class:
- assert existing_class is cls, (
- 'Duplicate `GeneratedProtocolMessageType` created for descriptor %r'
- % (descriptor.full_name))
- return
-
+
+ # If this is an _existing_ class looked up via `_concrete_class` in the
+ # __new__ method above, then we don't need to re-initialize anything.
+ existing_class = getattr(descriptor, '_concrete_class', None)
+ if existing_class:
+ assert existing_class is cls, (
+ 'Duplicate `GeneratedProtocolMessageType` created for descriptor %r'
+ % (descriptor.full_name))
+ return
+
cls._decoders_by_tag = {}
if (descriptor.has_options and
descriptor.GetOptions().message_set_wire_format):
@@ -257,7 +257,7 @@ def _AddSlots(message_descriptor, dictionary):
'_cached_byte_size_dirty',
'_fields',
'_unknown_fields',
- '_unknown_field_set',
+ '_unknown_field_set',
'_is_present_in_parent',
'_listener',
'_listener_for_children',
@@ -280,30 +280,30 @@ def _IsMapField(field):
def _IsMessageMapField(field):
- value_type = field.message_type.fields_by_name['value']
+ value_type = field.message_type.fields_by_name['value']
return value_type.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE
-def _IsStrictUtf8Check(field):
- if field.containing_type.syntax != 'proto3':
- return False
- enforce_utf8 = True
- return enforce_utf8
-
-
+def _IsStrictUtf8Check(field):
+ if field.containing_type.syntax != 'proto3':
+ return False
+ enforce_utf8 = True
+ return enforce_utf8
+
+
def _AttachFieldHelpers(cls, field_descriptor):
is_repeated = (field_descriptor.label == _FieldDescriptor.LABEL_REPEATED)
is_packable = (is_repeated and
wire_format.IsTypePackable(field_descriptor.type))
- is_proto3 = field_descriptor.containing_type.syntax == 'proto3'
+ is_proto3 = field_descriptor.containing_type.syntax == 'proto3'
if not is_packable:
is_packed = False
- elif field_descriptor.containing_type.syntax == 'proto2':
+ elif field_descriptor.containing_type.syntax == 'proto2':
is_packed = (field_descriptor.has_options and
field_descriptor.GetOptions().packed)
else:
has_packed_false = (field_descriptor.has_options and
- field_descriptor.GetOptions().HasField('packed') and
+ field_descriptor.GetOptions().HasField('packed') and
field_descriptor.GetOptions().packed == False)
is_packed = not has_packed_false
is_map_entry = _IsMapField(field_descriptor)
@@ -334,12 +334,12 @@ def _AttachFieldHelpers(cls, field_descriptor):
decode_type = _FieldDescriptor.TYPE_INT32
oneof_descriptor = None
- clear_if_default = False
+ clear_if_default = False
if field_descriptor.containing_oneof is not None:
oneof_descriptor = field_descriptor
- elif (is_proto3 and not is_repeated and
- field_descriptor.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE):
- clear_if_default = True
+ elif (is_proto3 and not is_repeated and
+ field_descriptor.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE):
+ clear_if_default = True
if is_map_entry:
is_message_map = _IsMessageMapField(field_descriptor)
@@ -347,22 +347,22 @@ def _AttachFieldHelpers(cls, field_descriptor):
field_decoder = decoder.MapDecoder(
field_descriptor, _GetInitializeDefaultForMap(field_descriptor),
is_message_map)
- elif decode_type == _FieldDescriptor.TYPE_STRING:
- is_strict_utf8_check = _IsStrictUtf8Check(field_descriptor)
- field_decoder = decoder.StringDecoder(
- field_descriptor.number, is_repeated, is_packed,
- field_descriptor, field_descriptor._default_constructor,
- is_strict_utf8_check, clear_if_default)
- elif field_descriptor.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
- field_decoder = type_checkers.TYPE_TO_DECODER[decode_type](
- field_descriptor.number, is_repeated, is_packed,
- field_descriptor, field_descriptor._default_constructor)
+ elif decode_type == _FieldDescriptor.TYPE_STRING:
+ is_strict_utf8_check = _IsStrictUtf8Check(field_descriptor)
+ field_decoder = decoder.StringDecoder(
+ field_descriptor.number, is_repeated, is_packed,
+ field_descriptor, field_descriptor._default_constructor,
+ is_strict_utf8_check, clear_if_default)
+ elif field_descriptor.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+ field_decoder = type_checkers.TYPE_TO_DECODER[decode_type](
+ field_descriptor.number, is_repeated, is_packed,
+ field_descriptor, field_descriptor._default_constructor)
else:
field_decoder = type_checkers.TYPE_TO_DECODER[decode_type](
- field_descriptor.number, is_repeated, is_packed,
- # pylint: disable=protected-access
- field_descriptor, field_descriptor._default_constructor,
- clear_if_default)
+ field_descriptor.number, is_repeated, is_packed,
+ # pylint: disable=protected-access
+ field_descriptor, field_descriptor._default_constructor,
+ clear_if_default)
cls._decoders_by_tag[tag_bytes] = (field_decoder, oneof_descriptor)
@@ -376,8 +376,8 @@ def _AttachFieldHelpers(cls, field_descriptor):
def _AddClassAttributesForNestedExtensions(descriptor, dictionary):
- extensions = descriptor.extensions_by_name
- for extension_name, extension_field in extensions.items():
+ extensions = descriptor.extensions_by_name
+ for extension_name, extension_field in extensions.items():
assert extension_name not in dictionary
dictionary[extension_name] = extension_field
@@ -459,9 +459,9 @@ def _DefaultValueConstructorForField(field):
# _concrete_class may not yet be initialized.
message_type = field.message_type
def MakeSubMessageDefault(message):
- assert getattr(message_type, '_concrete_class', None), (
- 'Uninitialized concrete class found for field %r (message type %r)'
- % (field.full_name, message_type.full_name))
+ assert getattr(message_type, '_concrete_class', None), (
+ 'Uninitialized concrete class found for field %r (message type %r)'
+ % (field.full_name, message_type.full_name))
result = message_type._concrete_class()
result._SetListener(
_OneofListener(message, field)
@@ -517,16 +517,16 @@ def _AddInitMethod(message_descriptor, cls):
# _unknown_fields is () when empty for efficiency, and will be turned into
# a list if fields are added.
self._unknown_fields = ()
- # _unknown_field_set is None when empty for efficiency, and will be
- # turned into UnknownFieldSet struct if fields are added.
- self._unknown_field_set = None # pylint: disable=protected-access
+ # _unknown_field_set is None when empty for efficiency, and will be
+ # turned into UnknownFieldSet struct if fields are added.
+ self._unknown_field_set = None # pylint: disable=protected-access
self._is_present_in_parent = False
self._listener = message_listener_mod.NullMessageListener()
self._listener_for_children = _Listener(self)
for field_name, field_value in kwargs.items():
field = _GetFieldByName(message_descriptor, field_name)
if field is None:
- raise TypeError('%s() got an unexpected keyword argument "%s"' %
+ raise TypeError('%s() got an unexpected keyword argument "%s"' %
(message_descriptor.name, field_name))
if field_value is None:
# field=None is the same as no field at all.
@@ -616,7 +616,7 @@ def _AddPropertiesForField(field, cls):
# handle specially here.
assert _FieldDescriptor.MAX_CPPTYPE == 10
- constant_name = field.name.upper() + '_FIELD_NUMBER'
+ constant_name = field.name.upper() + '_FIELD_NUMBER'
setattr(cls, constant_name, field.number)
if field.label == _FieldDescriptor.LABEL_REPEATED:
@@ -627,18 +627,18 @@ def _AddPropertiesForField(field, cls):
_AddPropertiesForNonRepeatedScalarField(field, cls)
-class _FieldProperty(property):
- __slots__ = ('DESCRIPTOR',)
-
- def __init__(self, descriptor, getter, setter, doc):
- property.__init__(self, getter, setter, doc=doc)
- self.DESCRIPTOR = descriptor
-
-
+class _FieldProperty(property):
+ __slots__ = ('DESCRIPTOR',)
+
+ def __init__(self, descriptor, getter, setter, doc):
+ property.__init__(self, getter, setter, doc=doc)
+ self.DESCRIPTOR = descriptor
+
+
def _AddPropertiesForRepeatedField(field, cls):
"""Adds a public property for a "repeated" protocol message field. Clients
can use this property to get the value of the field, which will be either a
- RepeatedScalarFieldContainer or RepeatedCompositeFieldContainer (see
+ RepeatedScalarFieldContainer or RepeatedCompositeFieldContainer (see
below).
Note that when clients add values to these containers, we perform
@@ -676,7 +676,7 @@ def _AddPropertiesForRepeatedField(field, cls):
'"%s" in protocol message object.' % proto_field_name)
doc = 'Magic attribute generated for "%s" proto field.' % proto_field_name
- setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
+ setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
def _AddPropertiesForNonRepeatedScalarField(field, cls):
@@ -694,7 +694,7 @@ def _AddPropertiesForNonRepeatedScalarField(field, cls):
property_name = _PropertyName(proto_field_name)
type_checker = type_checkers.GetTypeChecker(field)
default_value = field.default_value
- is_proto3 = field.containing_type.syntax == 'proto3'
+ is_proto3 = field.containing_type.syntax == 'proto3'
def getter(self):
# TODO(protobuf-team): This may be broken since there may not be
@@ -709,11 +709,11 @@ def _AddPropertiesForNonRepeatedScalarField(field, cls):
# pylint: disable=protected-access
# Testing the value for truthiness captures all of the proto3 defaults
# (0, 0.0, enum 0, and False).
- try:
- new_value = type_checker.CheckValue(new_value)
- except TypeError as e:
- raise TypeError(
- 'Cannot set %s to %.1024r: %s' % (field.full_name, new_value, e))
+ try:
+ new_value = type_checker.CheckValue(new_value)
+ except TypeError as e:
+ raise TypeError(
+ 'Cannot set %s to %.1024r: %s' % (field.full_name, new_value, e))
if clear_when_set_to_default and not new_value:
self._fields.pop(field, None)
else:
@@ -735,7 +735,7 @@ def _AddPropertiesForNonRepeatedScalarField(field, cls):
# Add a property to encapsulate the getter/setter.
doc = 'Magic attribute generated for "%s" proto field.' % proto_field_name
- setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
+ setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
def _AddPropertiesForNonRepeatedCompositeField(field, cls):
@@ -779,14 +779,14 @@ def _AddPropertiesForNonRepeatedCompositeField(field, cls):
# Add a property to encapsulate the getter.
doc = 'Magic attribute generated for "%s" proto field.' % proto_field_name
- setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
+ setattr(cls, property_name, _FieldProperty(field, getter, setter, doc=doc))
def _AddPropertiesForExtensions(descriptor, cls):
"""Adds properties for all fields in this protocol message type."""
- extensions = descriptor.extensions_by_name
- for extension_name, extension_field in extensions.items():
- constant_name = extension_name.upper() + '_FIELD_NUMBER'
+ extensions = descriptor.extensions_by_name
+ for extension_name, extension_field in extensions.items():
+ constant_name = extension_name.upper() + '_FIELD_NUMBER'
setattr(cls, constant_name, extension_field.number)
# TODO(amauryfa): Migrate all users of these attributes to functions like
@@ -802,8 +802,8 @@ def _AddStaticMethods(cls):
def RegisterExtension(extension_handle):
extension_handle.containing_type = cls.DESCRIPTOR
# TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
- # pylint: disable=protected-access
- cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+ # pylint: disable=protected-access
+ cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
_AttachFieldHelpers(cls, extension_handle)
cls.RegisterExtension = staticmethod(RegisterExtension)
@@ -836,16 +836,16 @@ def _AddListFieldsMethod(message_descriptor, cls):
cls.ListFields = ListFields
-_PROTO3_ERROR_TEMPLATE = \
- ('Protocol message %s has no non-repeated submessage field "%s" '
- 'nor marked as optional')
-_PROTO2_ERROR_TEMPLATE = 'Protocol message %s has no non-repeated field "%s"'
+_PROTO3_ERROR_TEMPLATE = \
+ ('Protocol message %s has no non-repeated submessage field "%s" '
+ 'nor marked as optional')
+_PROTO2_ERROR_TEMPLATE = 'Protocol message %s has no non-repeated field "%s"'
def _AddHasFieldMethod(message_descriptor, cls):
"""Helper for _AddMessageMethods()."""
is_proto3 = (message_descriptor.syntax == "proto3")
- error_msg = _PROTO3_ERROR_TEMPLATE if is_proto3 else _PROTO2_ERROR_TEMPLATE
+ error_msg = _PROTO3_ERROR_TEMPLATE if is_proto3 else _PROTO2_ERROR_TEMPLATE
hassable_fields = {}
for field in message_descriptor.fields:
@@ -857,15 +857,15 @@ def _AddHasFieldMethod(message_descriptor, cls):
continue
hassable_fields[field.name] = field
- # Has methods are supported for oneof descriptors.
- for oneof in message_descriptor.oneofs:
- hassable_fields[oneof.name] = oneof
+ # Has methods are supported for oneof descriptors.
+ for oneof in message_descriptor.oneofs:
+ hassable_fields[oneof.name] = oneof
def HasField(self, field_name):
try:
field = hassable_fields[field_name]
except KeyError:
- raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+ raise ValueError(error_msg % (message_descriptor.full_name, field_name))
if isinstance(field, descriptor_mod.OneofDescriptor):
try:
@@ -895,7 +895,7 @@ def _AddClearFieldMethod(message_descriptor, cls):
else:
return
except KeyError:
- raise ValueError('Protocol message %s has no "%s" field.' %
+ raise ValueError('Protocol message %s has no "%s" field.' %
(message_descriptor.name, field_name))
if field in self._fields:
@@ -923,7 +923,7 @@ def _AddClearFieldMethod(message_descriptor, cls):
def _AddClearExtensionMethod(cls):
"""Helper for _AddMessageMethods()."""
def ClearExtension(self, extension_handle):
- extension_dict._VerifyExtensionHandle(self, extension_handle)
+ extension_dict._VerifyExtensionHandle(self, extension_handle)
# Similar to ClearField(), above.
if extension_handle in self._fields:
@@ -935,7 +935,7 @@ def _AddClearExtensionMethod(cls):
def _AddHasExtensionMethod(cls):
"""Helper for _AddMessageMethods()."""
def HasExtension(self, extension_handle):
- extension_dict._VerifyExtensionHandle(self, extension_handle)
+ extension_dict._VerifyExtensionHandle(self, extension_handle)
if extension_handle.label == _FieldDescriptor.LABEL_REPEATED:
raise KeyError('"%s" is repeated.' % extension_handle.full_name)
@@ -1005,8 +1005,8 @@ def _AddEqualsMethod(message_descriptor, cls):
if not self.ListFields() == other.ListFields():
return False
- # TODO(jieluo): Fix UnknownFieldSet to consider MessageSet extensions,
- # then use it for the comparison.
+ # TODO(jieluo): Fix UnknownFieldSet to consider MessageSet extensions,
+ # then use it for the comparison.
unknown_fields = list(self._unknown_fields)
unknown_fields.sort()
other_unknown_fields = list(other._unknown_fields)
@@ -1066,16 +1066,16 @@ def _AddByteSizeMethod(message_descriptor, cls):
return self._cached_byte_size
size = 0
- descriptor = self.DESCRIPTOR
- if descriptor.GetOptions().map_entry:
- # Fields of map entry should always be serialized.
- size = descriptor.fields_by_name['key']._sizer(self.key)
- size += descriptor.fields_by_name['value']._sizer(self.value)
- else:
- for field_descriptor, field_value in self.ListFields():
- size += field_descriptor._sizer(field_value)
- for tag_bytes, value_bytes in self._unknown_fields:
- size += len(tag_bytes) + len(value_bytes)
+ descriptor = self.DESCRIPTOR
+ if descriptor.GetOptions().map_entry:
+ # Fields of map entry should always be serialized.
+ size = descriptor.fields_by_name['key']._sizer(self.key)
+ size += descriptor.fields_by_name['value']._sizer(self.value)
+ else:
+ for field_descriptor, field_value in self.ListFields():
+ size += field_descriptor._sizer(field_value)
+ for tag_bytes, value_bytes in self._unknown_fields:
+ size += len(tag_bytes) + len(value_bytes)
self._cached_byte_size = size
self._cached_byte_size_dirty = False
@@ -1113,27 +1113,27 @@ def _AddSerializePartialToStringMethod(message_descriptor, cls):
api_implementation.IsPythonDefaultSerializationDeterministic())
else:
deterministic = bool(deterministic)
-
- descriptor = self.DESCRIPTOR
- if descriptor.GetOptions().map_entry:
- # Fields of map entry should always be serialized.
- descriptor.fields_by_name['key']._encoder(
- write_bytes, self.key, deterministic)
- descriptor.fields_by_name['value']._encoder(
- write_bytes, self.value, deterministic)
- else:
- for field_descriptor, field_value in self.ListFields():
- field_descriptor._encoder(write_bytes, field_value, deterministic)
- for tag_bytes, value_bytes in self._unknown_fields:
- write_bytes(tag_bytes)
- write_bytes(value_bytes)
+
+ descriptor = self.DESCRIPTOR
+ if descriptor.GetOptions().map_entry:
+ # Fields of map entry should always be serialized.
+ descriptor.fields_by_name['key']._encoder(
+ write_bytes, self.key, deterministic)
+ descriptor.fields_by_name['value']._encoder(
+ write_bytes, self.value, deterministic)
+ else:
+ for field_descriptor, field_value in self.ListFields():
+ field_descriptor._encoder(write_bytes, field_value, deterministic)
+ for tag_bytes, value_bytes in self._unknown_fields:
+ write_bytes(tag_bytes)
+ write_bytes(value_bytes)
cls._InternalSerialize = InternalSerialize
def _AddMergeFromStringMethod(message_descriptor, cls):
"""Helper for _AddMessageMethods()."""
def MergeFromString(self, serialized):
- serialized = memoryview(serialized)
+ serialized = memoryview(serialized)
length = len(serialized)
try:
if self._InternalParse(serialized, 0, length) != length:
@@ -1153,54 +1153,54 @@ def _AddMergeFromStringMethod(message_descriptor, cls):
decoders_by_tag = cls._decoders_by_tag
def InternalParse(self, buffer, pos, end):
- """Create a message from serialized bytes.
-
- Args:
- self: Message, instance of the proto message object.
- buffer: memoryview of the serialized data.
- pos: int, position to start in the serialized data.
- end: int, end position of the serialized data.
-
- Returns:
- Message object.
- """
- # Guard against internal misuse, since this function is called internally
- # quite extensively, and its easy to accidentally pass bytes.
- assert isinstance(buffer, memoryview)
+ """Create a message from serialized bytes.
+
+ Args:
+ self: Message, instance of the proto message object.
+ buffer: memoryview of the serialized data.
+ pos: int, position to start in the serialized data.
+ end: int, end position of the serialized data.
+
+ Returns:
+ Message object.
+ """
+ # Guard against internal misuse, since this function is called internally
+ # quite extensively, and its easy to accidentally pass bytes.
+ assert isinstance(buffer, memoryview)
self._Modified()
field_dict = self._fields
- # pylint: disable=protected-access
- unknown_field_set = self._unknown_field_set
+ # pylint: disable=protected-access
+ unknown_field_set = self._unknown_field_set
while pos != end:
(tag_bytes, new_pos) = local_ReadTag(buffer, pos)
field_decoder, field_desc = decoders_by_tag.get(tag_bytes, (None, None))
if field_decoder is None:
- if not self._unknown_fields: # pylint: disable=protected-access
- self._unknown_fields = [] # pylint: disable=protected-access
- if unknown_field_set is None:
- # pylint: disable=protected-access
- self._unknown_field_set = containers.UnknownFieldSet()
- # pylint: disable=protected-access
- unknown_field_set = self._unknown_field_set
- # pylint: disable=protected-access
- (tag, _) = decoder._DecodeVarint(tag_bytes, 0)
- field_number, wire_type = wire_format.UnpackTag(tag)
- if field_number == 0:
- raise message_mod.DecodeError('Field number 0 is illegal.')
- # TODO(jieluo): remove old_pos.
- old_pos = new_pos
- (data, new_pos) = decoder._DecodeUnknownField(
- buffer, new_pos, wire_type) # pylint: disable=protected-access
- if new_pos == -1:
- return pos
- # pylint: disable=protected-access
- unknown_field_set._add(field_number, wire_type, data)
- # TODO(jieluo): remove _unknown_fields.
- new_pos = local_SkipField(buffer, old_pos, end, tag_bytes)
+ if not self._unknown_fields: # pylint: disable=protected-access
+ self._unknown_fields = [] # pylint: disable=protected-access
+ if unknown_field_set is None:
+ # pylint: disable=protected-access
+ self._unknown_field_set = containers.UnknownFieldSet()
+ # pylint: disable=protected-access
+ unknown_field_set = self._unknown_field_set
+ # pylint: disable=protected-access
+ (tag, _) = decoder._DecodeVarint(tag_bytes, 0)
+ field_number, wire_type = wire_format.UnpackTag(tag)
+ if field_number == 0:
+ raise message_mod.DecodeError('Field number 0 is illegal.')
+ # TODO(jieluo): remove old_pos.
+ old_pos = new_pos
+ (data, new_pos) = decoder._DecodeUnknownField(
+ buffer, new_pos, wire_type) # pylint: disable=protected-access
if new_pos == -1:
return pos
- self._unknown_fields.append(
- (tag_bytes, buffer[old_pos:new_pos].tobytes()))
+ # pylint: disable=protected-access
+ unknown_field_set._add(field_number, wire_type, data)
+ # TODO(jieluo): remove _unknown_fields.
+ new_pos = local_SkipField(buffer, old_pos, end, tag_bytes)
+ if new_pos == -1:
+ return pos
+ self._unknown_fields.append(
+ (tag_bytes, buffer[old_pos:new_pos].tobytes()))
pos = new_pos
else:
pos = field_decoder(buffer, new_pos, end, self, field_dict)
@@ -1275,7 +1275,7 @@ def _AddIsInitializedMethod(message_descriptor, cls):
for field, value in self.ListFields():
if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
if field.is_extension:
- name = '(%s)' % field.full_name
+ name = '(%s)' % field.full_name
else:
name = field.name
@@ -1283,7 +1283,7 @@ def _AddIsInitializedMethod(message_descriptor, cls):
if _IsMessageMapField(field):
for key in value:
element = value[key]
- prefix = '%s[%s].' % (name, key)
+ prefix = '%s[%s].' % (name, key)
sub_errors = element.FindInitializationErrors()
errors += [prefix + error for error in sub_errors]
else:
@@ -1292,11 +1292,11 @@ def _AddIsInitializedMethod(message_descriptor, cls):
elif field.label == _FieldDescriptor.LABEL_REPEATED:
for i in range(len(value)):
element = value[i]
- prefix = '%s[%d].' % (name, i)
+ prefix = '%s[%d].' % (name, i)
sub_errors = element.FindInitializationErrors()
errors += [prefix + error for error in sub_errors]
else:
- prefix = name + '.'
+ prefix = name + '.'
sub_errors = value.FindInitializationErrors()
errors += [prefix + error for error in sub_errors]
@@ -1312,7 +1312,7 @@ def _AddMergeFromMethod(cls):
def MergeFrom(self, msg):
if not isinstance(msg, cls):
raise TypeError(
- 'Parameter to MergeFrom() must be instance of same class: '
+ 'Parameter to MergeFrom() must be instance of same class: '
'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
assert msg is not self
@@ -1345,10 +1345,10 @@ def _AddMergeFromMethod(cls):
if not self._unknown_fields:
self._unknown_fields = []
self._unknown_fields.extend(msg._unknown_fields)
- # pylint: disable=protected-access
- if self._unknown_field_set is None:
- self._unknown_field_set = containers.UnknownFieldSet()
- self._unknown_field_set._extend(msg._unknown_field_set)
+ # pylint: disable=protected-access
+ if self._unknown_field_set is None:
+ self._unknown_field_set = containers.UnknownFieldSet()
+ self._unknown_field_set._extend(msg._unknown_field_set)
cls.MergeFrom = MergeFrom
@@ -1375,32 +1375,32 @@ def _Clear(self):
# Clear fields.
self._fields = {}
self._unknown_fields = ()
- # pylint: disable=protected-access
- if self._unknown_field_set is not None:
- self._unknown_field_set._clear()
- self._unknown_field_set = None
-
+ # pylint: disable=protected-access
+ if self._unknown_field_set is not None:
+ self._unknown_field_set._clear()
+ self._unknown_field_set = None
+
self._oneofs = {}
self._Modified()
-def _UnknownFields(self):
- if self._unknown_field_set is None: # pylint: disable=protected-access
- # pylint: disable=protected-access
- self._unknown_field_set = containers.UnknownFieldSet()
- return self._unknown_field_set # pylint: disable=protected-access
-
-
+def _UnknownFields(self):
+ if self._unknown_field_set is None: # pylint: disable=protected-access
+ # pylint: disable=protected-access
+ self._unknown_field_set = containers.UnknownFieldSet()
+ return self._unknown_field_set # pylint: disable=protected-access
+
+
def _DiscardUnknownFields(self):
self._unknown_fields = []
- self._unknown_field_set = None # pylint: disable=protected-access
+ self._unknown_field_set = None # pylint: disable=protected-access
for field, value in self.ListFields():
if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
- if _IsMapField(field):
- if _IsMessageMapField(field):
- for key in value:
- value[key].DiscardUnknownFields()
- elif field.label == _FieldDescriptor.LABEL_REPEATED:
+ if _IsMapField(field):
+ if _IsMessageMapField(field):
+ for key in value:
+ value[key].DiscardUnknownFields()
+ elif field.label == _FieldDescriptor.LABEL_REPEATED:
for sub_message in value:
sub_message.DiscardUnknownFields()
else:
@@ -1435,7 +1435,7 @@ def _AddMessageMethods(message_descriptor, cls):
_AddWhichOneofMethod(message_descriptor, cls)
# Adds methods which do not depend on cls.
cls.Clear = _Clear
- cls.UnknownFields = _UnknownFields
+ cls.UnknownFields = _UnknownFields
cls.DiscardUnknownFields = _DiscardUnknownFields
cls._SetListener = _SetListener
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/type_checkers.py b/contrib/python/protobuf/py3/google/protobuf/internal/type_checkers.py
index eb66f9f6fb..3e3bd9aa0a 100644
--- a/contrib/python/protobuf/py3/google/protobuf/internal/type_checkers.py
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/type_checkers.py
@@ -38,18 +38,18 @@ TYPE_TO_BYTE_SIZE_FN: A dictionary with field types and a size computing
TYPE_TO_SERIALIZE_METHOD: A dictionary with field types and serialization
function.
FIELD_TYPE_TO_WIRE_TYPE: A dictionary with field typed and their
- corresponding wire types.
+ corresponding wire types.
TYPE_TO_DESERIALIZE_METHOD: A dictionary with field types and deserialization
function.
"""
__author__ = 'robinson@google.com (Will Robinson)'
-try:
- import ctypes
-except Exception: # pylint: disable=broad-except
- ctypes = None
- import struct
+try:
+ import ctypes
+except Exception: # pylint: disable=broad-except
+ ctypes = None
+ import struct
import numbers
import six
@@ -64,29 +64,29 @@ from google.protobuf import descriptor
_FieldDescriptor = descriptor.FieldDescriptor
-
-def TruncateToFourByteFloat(original):
- if ctypes:
- return ctypes.c_float(original).value
- else:
- return struct.unpack('<f', struct.pack('<f', original))[0]
-
-
-def ToShortestFloat(original):
- """Returns the shortest float that has same value in wire."""
- # All 4 byte floats have between 6 and 9 significant digits, so we
- # start with 6 as the lower bound.
- # It has to be iterative because use '.9g' directly can not get rid
- # of the noises for most values. For example if set a float_field=0.9
- # use '.9g' will print 0.899999976.
- precision = 6
- rounded = float('{0:.{1}g}'.format(original, precision))
- while TruncateToFourByteFloat(rounded) != original:
- precision += 1
- rounded = float('{0:.{1}g}'.format(original, precision))
- return rounded
-
-
+
+def TruncateToFourByteFloat(original):
+ if ctypes:
+ return ctypes.c_float(original).value
+ else:
+ return struct.unpack('<f', struct.pack('<f', original))[0]
+
+
+def ToShortestFloat(original):
+ """Returns the shortest float that has same value in wire."""
+ # All 4 byte floats have between 6 and 9 significant digits, so we
+ # start with 6 as the lower bound.
+ # It has to be iterative because use '.9g' directly can not get rid
+ # of the noises for most values. For example if set a float_field=0.9
+ # use '.9g' will print 0.899999976.
+ precision = 6
+ rounded = float('{0:.{1}g}'.format(original, precision))
+ while TruncateToFourByteFloat(rounded) != original:
+ precision += 1
+ rounded = float('{0:.{1}g}'.format(original, precision))
+ return rounded
+
+
def SupportsOpenEnums(field_descriptor):
return field_descriptor.containing_type.syntax == "proto3"
@@ -101,7 +101,7 @@ def GetTypeChecker(field):
of values assigned to a field of the specified type.
"""
if (field.cpp_type == _FieldDescriptor.CPPTYPE_STRING and
- field.type == _FieldDescriptor.TYPE_STRING):
+ field.type == _FieldDescriptor.TYPE_STRING):
return UnicodeValueChecker()
if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM:
if SupportsOpenEnums(field):
@@ -135,18 +135,18 @@ class TypeChecker(object):
message = ('%.1024r has type %s, but expected one of: %s' %
(proposed_value, type(proposed_value), self._acceptable_types))
raise TypeError(message)
- # Some field types(float, double and bool) accept other types, must
- # convert to the correct type in such cases.
- if self._acceptable_types:
- if self._acceptable_types[0] in (bool, float):
- return self._acceptable_types[0](proposed_value)
+ # Some field types(float, double and bool) accept other types, must
+ # convert to the correct type in such cases.
+ if self._acceptable_types:
+ if self._acceptable_types[0] in (bool, float):
+ return self._acceptable_types[0](proposed_value)
return proposed_value
class TypeCheckerWithDefault(TypeChecker):
def __init__(self, default_value, *acceptable_types):
- TypeChecker.__init__(self, *acceptable_types)
+ TypeChecker.__init__(self, *acceptable_types)
self._default_value = default_value
def DefaultValue(self):
@@ -218,14 +218,14 @@ class UnicodeValueChecker(object):
'encoding. Non-UTF-8 strings must be converted to '
'unicode objects before being added.' %
(proposed_value))
- else:
- try:
- proposed_value.encode('utf8')
- except UnicodeEncodeError:
- raise ValueError('%.1024r isn\'t a valid unicode string and '
- 'can\'t be encoded in UTF-8.'%
- (proposed_value))
-
+ else:
+ try:
+ proposed_value.encode('utf8')
+ except UnicodeEncodeError:
+ raise ValueError('%.1024r isn\'t a valid unicode string and '
+ 'can\'t be encoded in UTF-8.'%
+ (proposed_value))
+
return proposed_value
def DefaultValue(self):
@@ -258,39 +258,39 @@ class Uint64ValueChecker(IntValueChecker):
_TYPE = long
-# The max 4 bytes float is about 3.4028234663852886e+38
-_FLOAT_MAX = float.fromhex('0x1.fffffep+127')
-_FLOAT_MIN = -_FLOAT_MAX
-_INF = float('inf')
-_NEG_INF = float('-inf')
-
-
-class FloatValueChecker(object):
-
- """Checker used for float fields. Performs type-check and range check.
-
- Values exceeding a 32-bit float will be converted to inf/-inf.
- """
-
- def CheckValue(self, proposed_value):
- """Check and convert proposed_value to float."""
- if not isinstance(proposed_value, numbers.Real):
- message = ('%.1024r has type %s, but expected one of: numbers.Real' %
- (proposed_value, type(proposed_value)))
- raise TypeError(message)
- converted_value = float(proposed_value)
- # This inf rounding matches the C++ proto SafeDoubleToFloat logic.
- if converted_value > _FLOAT_MAX:
- return _INF
- if converted_value < _FLOAT_MIN:
- return _NEG_INF
-
- return TruncateToFourByteFloat(converted_value)
-
- def DefaultValue(self):
- return 0.0
-
-
+# The max 4 bytes float is about 3.4028234663852886e+38
+_FLOAT_MAX = float.fromhex('0x1.fffffep+127')
+_FLOAT_MIN = -_FLOAT_MAX
+_INF = float('inf')
+_NEG_INF = float('-inf')
+
+
+class FloatValueChecker(object):
+
+ """Checker used for float fields. Performs type-check and range check.
+
+ Values exceeding a 32-bit float will be converted to inf/-inf.
+ """
+
+ def CheckValue(self, proposed_value):
+ """Check and convert proposed_value to float."""
+ if not isinstance(proposed_value, numbers.Real):
+ message = ('%.1024r has type %s, but expected one of: numbers.Real' %
+ (proposed_value, type(proposed_value)))
+ raise TypeError(message)
+ converted_value = float(proposed_value)
+ # This inf rounding matches the C++ proto SafeDoubleToFloat logic.
+ if converted_value > _FLOAT_MAX:
+ return _INF
+ if converted_value < _FLOAT_MIN:
+ return _NEG_INF
+
+ return TruncateToFourByteFloat(converted_value)
+
+ def DefaultValue(self):
+ return 0.0
+
+
# Type-checkers for all scalar CPPTYPEs.
_VALUE_CHECKERS = {
_FieldDescriptor.CPPTYPE_INT32: Int32ValueChecker(),
@@ -298,8 +298,8 @@ _VALUE_CHECKERS = {
_FieldDescriptor.CPPTYPE_UINT32: Uint32ValueChecker(),
_FieldDescriptor.CPPTYPE_UINT64: Uint64ValueChecker(),
_FieldDescriptor.CPPTYPE_DOUBLE: TypeCheckerWithDefault(
- 0.0, float, numbers.Real),
- _FieldDescriptor.CPPTYPE_FLOAT: FloatValueChecker(),
+ 0.0, float, numbers.Real),
+ _FieldDescriptor.CPPTYPE_FLOAT: FloatValueChecker(),
_FieldDescriptor.CPPTYPE_BOOL: TypeCheckerWithDefault(
False, bool, numbers.Integral),
_FieldDescriptor.CPPTYPE_STRING: TypeCheckerWithDefault(b'', bytes),
diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/well_known_types.py b/contrib/python/protobuf/py3/google/protobuf/internal/well_known_types.py
index 6f55d6b17b..df45c027f7 100644
--- a/contrib/python/protobuf/py3/google/protobuf/internal/well_known_types.py
+++ b/contrib/python/protobuf/py3/google/protobuf/internal/well_known_types.py
@@ -40,18 +40,18 @@ This files defines well known classes which need extra maintenance including:
__author__ = 'jieluo@google.com (Jie Luo)'
-import calendar
+import calendar
from datetime import datetime
from datetime import timedelta
import six
-try:
- # Since python 3
- import collections.abc as collections_abc
-except ImportError:
- # Won't work after python 3.8
- import collections as collections_abc
-
+try:
+ # Since python 3
+ import collections.abc as collections_abc
+except ImportError:
+ # Won't work after python 3.8
+ import collections as collections_abc
+
from google.protobuf.descriptor import FieldDescriptor
_TIMESTAMPFOMAT = '%Y-%m-%dT%H:%M:%S'
@@ -67,16 +67,16 @@ _DURATION_SECONDS_MAX = 315576000000
class Any(object):
"""Class for Any Message type."""
- __slots__ = ()
-
- def Pack(self, msg, type_url_prefix='type.googleapis.com/',
- deterministic=None):
+ __slots__ = ()
+
+ def Pack(self, msg, type_url_prefix='type.googleapis.com/',
+ deterministic=None):
"""Packs the specified message into current Any message."""
if len(type_url_prefix) < 1 or type_url_prefix[-1] != '/':
self.type_url = '%s/%s' % (type_url_prefix, msg.DESCRIPTOR.full_name)
else:
self.type_url = '%s%s' % (type_url_prefix, msg.DESCRIPTOR.full_name)
- self.value = msg.SerializeToString(deterministic=deterministic)
+ self.value = msg.SerializeToString(deterministic=deterministic)
def Unpack(self, msg):
"""Unpacks the current Any message into specified message."""
@@ -93,17 +93,17 @@ class Any(object):
def Is(self, descriptor):
"""Checks if this Any represents the given protobuf type."""
- return '/' in self.type_url and self.TypeName() == descriptor.full_name
-
-
-_EPOCH_DATETIME = datetime.utcfromtimestamp(0)
+ return '/' in self.type_url and self.TypeName() == descriptor.full_name
+_EPOCH_DATETIME = datetime.utcfromtimestamp(0)
+
+
class Timestamp(object):
"""Class for Timestamp message type."""
- __slots__ = ()
-
+ __slots__ = ()
+
def ToJsonString(self):
"""Converts Timestamp to RFC 3339 date string format.
@@ -141,7 +141,7 @@ class Timestamp(object):
Example of accepted format: '1972-01-01T10:00:20.021-05:00'
Raises:
- ValueError: On parsing problems.
+ ValueError: On parsing problems.
"""
timezone_offset = value.find('Z')
if timezone_offset == -1:
@@ -149,7 +149,7 @@ class Timestamp(object):
if timezone_offset == -1:
timezone_offset = value.rfind('-')
if timezone_offset == -1:
- raise ValueError(
+ raise ValueError(
'Failed to parse timestamp: missing valid timezone offset.')
time_value = value[0:timezone_offset]
# Parse datetime and nanos.
@@ -160,15 +160,15 @@ class Timestamp(object):
else:
second_value = time_value[:point_position]
nano_value = time_value[point_position + 1:]
- if 't' in second_value:
- raise ValueError(
- 'time data \'{0}\' does not match format \'%Y-%m-%dT%H:%M:%S\', '
- 'lowercase \'t\' is not accepted'.format(second_value))
+ if 't' in second_value:
+ raise ValueError(
+ 'time data \'{0}\' does not match format \'%Y-%m-%dT%H:%M:%S\', '
+ 'lowercase \'t\' is not accepted'.format(second_value))
date_object = datetime.strptime(second_value, _TIMESTAMPFOMAT)
td = date_object - datetime(1970, 1, 1)
seconds = td.seconds + td.days * _SECONDS_PER_DAY
if len(nano_value) > 9:
- raise ValueError(
+ raise ValueError(
'Failed to parse Timestamp: nanos {0} more than '
'9 fractional digits.'.format(nano_value))
if nano_value:
@@ -178,13 +178,13 @@ class Timestamp(object):
# Parse timezone offsets.
if value[timezone_offset] == 'Z':
if len(value) != timezone_offset + 1:
- raise ValueError('Failed to parse timestamp: invalid trailing'
+ raise ValueError('Failed to parse timestamp: invalid trailing'
' data {0}.'.format(value))
else:
timezone = value[timezone_offset:]
pos = timezone.find(':')
if pos == -1:
- raise ValueError(
+ raise ValueError(
'Invalid timezone offset value: {0}.'.format(timezone))
if timezone[0] == '+':
seconds -= (int(timezone[1:pos])*60+int(timezone[pos+1:]))*60
@@ -238,28 +238,28 @@ class Timestamp(object):
def ToDatetime(self):
"""Converts Timestamp to datetime."""
- return _EPOCH_DATETIME + timedelta(
- seconds=self.seconds, microseconds=_RoundTowardZero(
- self.nanos, _NANOS_PER_MICROSECOND))
+ return _EPOCH_DATETIME + timedelta(
+ seconds=self.seconds, microseconds=_RoundTowardZero(
+ self.nanos, _NANOS_PER_MICROSECOND))
def FromDatetime(self, dt):
"""Converts datetime to Timestamp."""
- # Using this guide: http://wiki.python.org/moin/WorkingWithTime
- # And this conversion guide: http://docs.python.org/library/time.html
-
- # Turn the date parameter into a tuple (struct_time) that can then be
- # manipulated into a long value of seconds. During the conversion from
- # struct_time to long, the source date in UTC, and so it follows that the
- # correct transformation is calendar.timegm()
- self.seconds = calendar.timegm(dt.utctimetuple())
- self.nanos = dt.microsecond * _NANOS_PER_MICROSECOND
+ # Using this guide: http://wiki.python.org/moin/WorkingWithTime
+ # And this conversion guide: http://docs.python.org/library/time.html
+ # Turn the date parameter into a tuple (struct_time) that can then be
+ # manipulated into a long value of seconds. During the conversion from
+ # struct_time to long, the source date in UTC, and so it follows that the
+ # correct transformation is calendar.timegm()
+ self.seconds = calendar.timegm(dt.utctimetuple())
+ self.nanos = dt.microsecond * _NANOS_PER_MICROSECOND
+
class Duration(object):
"""Class for Duration message type."""
- __slots__ = ()
-
+ __slots__ = ()
+
def ToJsonString(self):
"""Converts Duration to string format.
@@ -301,10 +301,10 @@ class Duration(object):
precision. For example: "1s", "1.01s", "1.0000001s", "-3.100s
Raises:
- ValueError: On parsing problems.
+ ValueError: On parsing problems.
"""
if len(value) < 1 or value[-1] != 's':
- raise ValueError(
+ raise ValueError(
'Duration must end with letter "s": {0}.'.format(value))
try:
pos = value.find('.')
@@ -320,9 +320,9 @@ class Duration(object):
_CheckDurationValid(seconds, nanos)
self.seconds = seconds
self.nanos = nanos
- except ValueError as e:
- raise ValueError(
- 'Couldn\'t parse duration: {0} : {1}.'.format(value, e))
+ except ValueError as e:
+ raise ValueError(
+ 'Couldn\'t parse duration: {0} : {1}.'.format(value, e))
def ToNanoseconds(self):
"""Converts a Duration to nanoseconds."""
@@ -387,21 +387,21 @@ class Duration(object):
def _CheckDurationValid(seconds, nanos):
if seconds < -_DURATION_SECONDS_MAX or seconds > _DURATION_SECONDS_MAX:
- raise ValueError(
+ raise ValueError(
'Duration is not valid: Seconds {0} must be in range '
'[-315576000000, 315576000000].'.format(seconds))
if nanos <= -_NANOS_PER_SECOND or nanos >= _NANOS_PER_SECOND:
- raise ValueError(
+ raise ValueError(
'Duration is not valid: Nanos {0} must be in range '
'[-999999999, 999999999].'.format(nanos))
- if (nanos < 0 and seconds > 0) or (nanos > 0 and seconds < 0):
- raise ValueError(
- 'Duration is not valid: Sign mismatch.')
+ if (nanos < 0 and seconds > 0) or (nanos > 0 and seconds < 0):
+ raise ValueError(
+ 'Duration is not valid: Sign mismatch.')
def _RoundTowardZero(value, divider):
"""Truncates the remainder part after division."""
- # For some languages, the sign of the remainder is implementation
+ # For some languages, the sign of the remainder is implementation
# dependent if any of the operands is negative. Here we enforce
# "rounded toward zero" semantics. For example, for (-5) / 2 an
# implementation may give -3 as the result with the remainder being
@@ -417,8 +417,8 @@ def _RoundTowardZero(value, divider):
class FieldMask(object):
"""Class for FieldMask message type."""
- __slots__ = ()
-
+ __slots__ = ()
+
def ToJsonString(self):
"""Converts FieldMask to string according to proto3 JSON spec."""
camelcase_paths = []
@@ -429,9 +429,9 @@ class FieldMask(object):
def FromJsonString(self, value):
"""Converts string to FieldMask according to proto3 JSON spec."""
self.Clear()
- if value:
- for path in value.split(','):
- self.paths.append(_CamelCaseToSnakeCase(path))
+ if value:
+ for path in value.split(','):
+ self.paths.append(_CamelCaseToSnakeCase(path))
def IsValidForDescriptor(self, message_descriptor):
"""Checks whether the FieldMask is valid for Message Descriptor."""
@@ -500,7 +500,7 @@ def _IsValidPath(message_descriptor, path):
parts = path.split('.')
last = parts.pop()
for name in parts:
- field = message_descriptor.fields_by_name.get(name)
+ field = message_descriptor.fields_by_name.get(name)
if (field is None or
field.label == FieldDescriptor.LABEL_REPEATED or
field.type != FieldDescriptor.TYPE_MESSAGE):
@@ -524,26 +524,26 @@ def _SnakeCaseToCamelCase(path_name):
after_underscore = False
for c in path_name:
if c.isupper():
- raise ValueError(
- 'Fail to print FieldMask to Json string: Path name '
- '{0} must not contain uppercase letters.'.format(path_name))
+ raise ValueError(
+ 'Fail to print FieldMask to Json string: Path name '
+ '{0} must not contain uppercase letters.'.format(path_name))
if after_underscore:
if c.islower():
result.append(c.upper())
after_underscore = False
else:
- raise ValueError(
- 'Fail to print FieldMask to Json string: The '
- 'character after a "_" must be a lowercase letter '
- 'in path name {0}.'.format(path_name))
+ raise ValueError(
+ 'Fail to print FieldMask to Json string: The '
+ 'character after a "_" must be a lowercase letter '
+ 'in path name {0}.'.format(path_name))
elif c == '_':
after_underscore = True
else:
result += c
if after_underscore:
- raise ValueError('Fail to print FieldMask to Json string: Trailing "_" '
- 'in path name {0}.'.format(path_name))
+ raise ValueError('Fail to print FieldMask to Json string: Trailing "_" '
+ 'in path name {0}.'.format(path_name))
return ''.join(result)
@@ -552,7 +552,7 @@ def _CamelCaseToSnakeCase(path_name):
result = []
for c in path_name:
if c == '_':
- raise ValueError('Fail to parse FieldMask: Path name '
+ raise ValueError('Fail to parse FieldMask: Path name '
'{0} must not contain "_"s.'.format(path_name))
if c.isupper():
result += '_'
@@ -575,8 +575,8 @@ class _FieldMaskTree(object):
In the tree, each leaf node represents a field path.
"""
- __slots__ = ('_root',)
-
+ __slots__ = ('_root',)
+
def __init__(self, field_mask=None):
"""Initializes the tree by FieldMask."""
self._root = {}
@@ -678,17 +678,17 @@ def _MergeMessage(
raise ValueError('Error: Field {0} in message {1} is not a singular '
'message field and cannot have sub-fields.'.format(
name, source_descriptor.full_name))
- if source.HasField(name):
- _MergeMessage(
- child, getattr(source, name), getattr(destination, name),
- replace_message, replace_repeated)
+ if source.HasField(name):
+ _MergeMessage(
+ child, getattr(source, name), getattr(destination, name),
+ replace_message, replace_repeated)
continue
if field.label == FieldDescriptor.LABEL_REPEATED:
if replace_repeated:
destination.ClearField(_StrConvert(name))
repeated_source = getattr(source, name)
repeated_destination = getattr(destination, name)
- repeated_destination.MergeFrom(repeated_source)
+ repeated_destination.MergeFrom(repeated_source)
else:
if field.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
if replace_message:
@@ -701,7 +701,7 @@ def _MergeMessage(
def _AddFieldPaths(node, prefix, field_mask):
"""Adds the field paths descended from node to field_mask."""
- if not node and prefix:
+ if not node and prefix:
field_mask.paths.append(prefix)
return
for name in sorted(node):
@@ -726,12 +726,12 @@ def _SetStructValue(struct_value, value):
struct_value.string_value = value
elif isinstance(value, _INT_OR_FLOAT):
struct_value.number_value = value
- elif isinstance(value, (dict, Struct)):
- struct_value.struct_value.Clear()
- struct_value.struct_value.update(value)
- elif isinstance(value, (list, ListValue)):
- struct_value.list_value.Clear()
- struct_value.list_value.extend(value)
+ elif isinstance(value, (dict, Struct)):
+ struct_value.struct_value.Clear()
+ struct_value.struct_value.update(value)
+ elif isinstance(value, (list, ListValue)):
+ struct_value.list_value.Clear()
+ struct_value.list_value.extend(value)
else:
raise ValueError('Unexpected type')
@@ -757,61 +757,61 @@ def _GetStructValue(struct_value):
class Struct(object):
"""Class for Struct message type."""
- __slots__ = ()
+ __slots__ = ()
def __getitem__(self, key):
return _GetStructValue(self.fields[key])
- def __contains__(self, item):
- return item in self.fields
-
+ def __contains__(self, item):
+ return item in self.fields
+
def __setitem__(self, key, value):
_SetStructValue(self.fields[key], value)
- def __delitem__(self, key):
- del self.fields[key]
-
- def __len__(self):
- return len(self.fields)
-
- def __iter__(self):
- return iter(self.fields)
-
- def keys(self): # pylint: disable=invalid-name
- return self.fields.keys()
-
- def values(self): # pylint: disable=invalid-name
- return [self[key] for key in self]
-
- def items(self): # pylint: disable=invalid-name
- return [(key, self[key]) for key in self]
-
+ def __delitem__(self, key):
+ del self.fields[key]
+
+ def __len__(self):
+ return len(self.fields)
+
+ def __iter__(self):
+ return iter(self.fields)
+
+ def keys(self): # pylint: disable=invalid-name
+ return self.fields.keys()
+
+ def values(self): # pylint: disable=invalid-name
+ return [self[key] for key in self]
+
+ def items(self): # pylint: disable=invalid-name
+ return [(key, self[key]) for key in self]
+
def get_or_create_list(self, key):
"""Returns a list for this key, creating if it didn't exist already."""
- if not self.fields[key].HasField('list_value'):
- # Clear will mark list_value modified which will indeed create a list.
- self.fields[key].list_value.Clear()
+ if not self.fields[key].HasField('list_value'):
+ # Clear will mark list_value modified which will indeed create a list.
+ self.fields[key].list_value.Clear()
return self.fields[key].list_value
def get_or_create_struct(self, key):
"""Returns a struct for this key, creating if it didn't exist already."""
- if not self.fields[key].HasField('struct_value'):
- # Clear will mark struct_value modified which will indeed create a struct.
- self.fields[key].struct_value.Clear()
+ if not self.fields[key].HasField('struct_value'):
+ # Clear will mark struct_value modified which will indeed create a struct.
+ self.fields[key].struct_value.Clear()
return self.fields[key].struct_value
- def update(self, dictionary): # pylint: disable=invalid-name
- for key, value in dictionary.items():
- _SetStructValue(self.fields[key], value)
-
-collections_abc.MutableMapping.register(Struct)
+ def update(self, dictionary): # pylint: disable=invalid-name
+ for key, value in dictionary.items():
+ _SetStructValue(self.fields[key], value)
+collections_abc.MutableMapping.register(Struct)
+
class ListValue(object):
"""Class for ListValue message type."""
- __slots__ = ()
-
+ __slots__ = ()
+
def __len__(self):
return len(self.values)
@@ -829,30 +829,30 @@ class ListValue(object):
def __setitem__(self, index, value):
_SetStructValue(self.values.__getitem__(index), value)
- def __delitem__(self, key):
- del self.values[key]
-
+ def __delitem__(self, key):
+ del self.values[key]
+
def items(self):
for i in range(len(self)):
yield self[i]
def add_struct(self):
"""Appends and returns a struct value as the next value in the list."""
- struct_value = self.values.add().struct_value
- # Clear will mark struct_value modified which will indeed create a struct.
- struct_value.Clear()
- return struct_value
+ struct_value = self.values.add().struct_value
+ # Clear will mark struct_value modified which will indeed create a struct.
+ struct_value.Clear()
+ return struct_value
def add_list(self):
"""Appends and returns a list value as the next value in the list."""
- list_value = self.values.add().list_value
- # Clear will mark list_value modified which will indeed create a list.
- list_value.Clear()
- return list_value
-
-collections_abc.MutableSequence.register(ListValue)
+ list_value = self.values.add().list_value
+ # Clear will mark list_value modified which will indeed create a list.
+ list_value.Clear()
+ return list_value
+collections_abc.MutableSequence.register(ListValue)
+
WKTBASES = {
'google.protobuf.Any': Any,
'google.protobuf.Duration': Duration,
diff --git a/contrib/python/protobuf/py3/google/protobuf/json_format.py b/contrib/python/protobuf/py3/google/protobuf/json_format.py
index 965614d803..7e88d33a26 100644
--- a/contrib/python/protobuf/py3/google/protobuf/json_format.py
+++ b/contrib/python/protobuf/py3/google/protobuf/json_format.py
@@ -42,29 +42,29 @@ Simple usage example:
__author__ = 'jieluo@google.com (Jie Luo)'
-# pylint: disable=g-statement-before-imports,g-import-not-at-top
+# pylint: disable=g-statement-before-imports,g-import-not-at-top
try:
from collections import OrderedDict
except ImportError:
- from ordereddict import OrderedDict # PY26
-# pylint: enable=g-statement-before-imports,g-import-not-at-top
-
+ from ordereddict import OrderedDict # PY26
+# pylint: enable=g-statement-before-imports,g-import-not-at-top
+
import base64
import json
import math
-
-from operator import methodcaller
-
+
+from operator import methodcaller
+
import re
import sys
-import six
-
-from google.protobuf.internal import type_checkers
+import six
+
+from google.protobuf.internal import type_checkers
from google.protobuf import descriptor
from google.protobuf import symbol_database
-
+
_TIMESTAMPFOMAT = '%Y-%m-%dT%H:%M:%S'
_INT_TYPES = frozenset([descriptor.FieldDescriptor.CPPTYPE_INT32,
descriptor.FieldDescriptor.CPPTYPE_UINT32,
@@ -97,15 +97,15 @@ class ParseError(Error):
"""Thrown in case of parsing error."""
-def MessageToJson(
- message,
- including_default_value_fields=False,
- preserving_proto_field_name=False,
- indent=2,
- sort_keys=False,
- use_integers_for_enums=False,
- descriptor_pool=None,
- float_precision=None):
+def MessageToJson(
+ message,
+ including_default_value_fields=False,
+ preserving_proto_field_name=False,
+ indent=2,
+ sort_keys=False,
+ use_integers_for_enums=False,
+ descriptor_pool=None,
+ float_precision=None):
"""Converts protobuf message to JSON format.
Args:
@@ -121,29 +121,29 @@ def MessageToJson(
An indent level of 0 or negative will only insert newlines.
sort_keys: If True, then the output will be sorted by field names.
use_integers_for_enums: If true, print integers instead of enum names.
- descriptor_pool: A Descriptor Pool for resolving types. If None use the
- default.
- float_precision: If set, use this to specify float field valid digits.
+ descriptor_pool: A Descriptor Pool for resolving types. If None use the
+ default.
+ float_precision: If set, use this to specify float field valid digits.
Returns:
A string containing the JSON formatted protocol buffer message.
"""
- printer = _Printer(
- including_default_value_fields,
- preserving_proto_field_name,
- use_integers_for_enums,
- descriptor_pool,
- float_precision=float_precision)
+ printer = _Printer(
+ including_default_value_fields,
+ preserving_proto_field_name,
+ use_integers_for_enums,
+ descriptor_pool,
+ float_precision=float_precision)
return printer.ToJsonString(message, indent, sort_keys)
-def MessageToDict(
- message,
- including_default_value_fields=False,
- preserving_proto_field_name=False,
- use_integers_for_enums=False,
- descriptor_pool=None,
- float_precision=None):
+def MessageToDict(
+ message,
+ including_default_value_fields=False,
+ preserving_proto_field_name=False,
+ use_integers_for_enums=False,
+ descriptor_pool=None,
+ float_precision=None):
"""Converts protobuf message to a dictionary.
When the dictionary is encoded to JSON, it conforms to proto3 JSON spec.
@@ -158,19 +158,19 @@ def MessageToDict(
names as defined in the .proto file. If False, convert the field
names to lowerCamelCase.
use_integers_for_enums: If true, print integers instead of enum names.
- descriptor_pool: A Descriptor Pool for resolving types. If None use the
- default.
- float_precision: If set, use this to specify float field valid digits.
+ descriptor_pool: A Descriptor Pool for resolving types. If None use the
+ default.
+ float_precision: If set, use this to specify float field valid digits.
Returns:
A dict representation of the protocol buffer message.
"""
- printer = _Printer(
- including_default_value_fields,
- preserving_proto_field_name,
- use_integers_for_enums,
- descriptor_pool,
- float_precision=float_precision)
+ printer = _Printer(
+ including_default_value_fields,
+ preserving_proto_field_name,
+ use_integers_for_enums,
+ descriptor_pool,
+ float_precision=float_precision)
# pylint: disable=protected-access
return printer._MessageToJsonObject(message)
@@ -184,25 +184,25 @@ def _IsMapEntry(field):
class _Printer(object):
"""JSON format printer for protocol message."""
- def __init__(
- self,
- including_default_value_fields=False,
- preserving_proto_field_name=False,
- use_integers_for_enums=False,
- descriptor_pool=None,
- float_precision=None):
+ def __init__(
+ self,
+ including_default_value_fields=False,
+ preserving_proto_field_name=False,
+ use_integers_for_enums=False,
+ descriptor_pool=None,
+ float_precision=None):
self.including_default_value_fields = including_default_value_fields
self.preserving_proto_field_name = preserving_proto_field_name
self.use_integers_for_enums = use_integers_for_enums
- self.descriptor_pool = descriptor_pool
- if float_precision:
- self.float_format = '.{}g'.format(float_precision)
- else:
- self.float_format = None
+ self.descriptor_pool = descriptor_pool
+ if float_precision:
+ self.float_format = '.{}g'.format(float_precision)
+ else:
+ self.float_format = None
def ToJsonString(self, message, indent, sort_keys):
js = self._MessageToJsonObject(message)
- return json.dumps(js, indent=indent, sort_keys=sort_keys)
+ return json.dumps(js, indent=indent, sort_keys=sort_keys)
def _MessageToJsonObject(self, message):
"""Converts message to an object according to Proto3 JSON Specification."""
@@ -245,7 +245,7 @@ class _Printer(object):
js[name] = [self._FieldToJsonObject(field, k)
for k in value]
elif field.is_extension:
- name = '[%s]' % field.full_name
+ name = '[%s]' % field.full_name
js[name] = self._FieldToJsonObject(field, value)
else:
js[name] = self._FieldToJsonObject(field, value)
@@ -264,7 +264,7 @@ class _Printer(object):
else:
name = field.json_name
if name in js:
- # Skip the field which has been serialized already.
+ # Skip the field which has been serialized already.
continue
if _IsMapEntry(field):
js[name] = {}
@@ -286,14 +286,14 @@ class _Printer(object):
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_ENUM:
if self.use_integers_for_enums:
return value
- if field.enum_type.full_name == 'google.protobuf.NullValue':
- return None
+ if field.enum_type.full_name == 'google.protobuf.NullValue':
+ return None
enum_value = field.enum_type.values_by_number.get(value, None)
if enum_value is not None:
return enum_value.name
else:
- if field.file.syntax == 'proto3':
- return value
+ if field.file.syntax == 'proto3':
+ return value
raise SerializeToJsonError('Enum field contains an integer value '
'which can not mapped to an enum value.')
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_STRING:
@@ -314,12 +314,12 @@ class _Printer(object):
return _INFINITY
if math.isnan(value):
return _NAN
- if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
- if self.float_format:
- return float(format(value, self.float_format))
- else:
- return type_checkers.ToShortestFloat(value)
-
+ if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
+ if self.float_format:
+ return float(format(value, self.float_format))
+ else:
+ return type_checkers.ToShortestFloat(value)
+
return value
def _AnyMessageToJsonObject(self, message):
@@ -330,7 +330,7 @@ class _Printer(object):
js = OrderedDict()
type_url = message.type_url
js['@type'] = type_url
- sub_message = _CreateMessageFromTypeUrl(type_url, self.descriptor_pool)
+ sub_message = _CreateMessageFromTypeUrl(type_url, self.descriptor_pool)
sub_message.ParseFromString(message.value)
message_descriptor = sub_message.DESCRIPTOR
full_name = message_descriptor.full_name
@@ -396,13 +396,13 @@ def _DuplicateChecker(js):
return result
-def _CreateMessageFromTypeUrl(type_url, descriptor_pool):
- """Creates a message from a type URL."""
+def _CreateMessageFromTypeUrl(type_url, descriptor_pool):
+ """Creates a message from a type URL."""
db = symbol_database.Default()
- pool = db.pool if descriptor_pool is None else descriptor_pool
+ pool = db.pool if descriptor_pool is None else descriptor_pool
type_name = type_url.split('/')[-1]
try:
- message_descriptor = pool.FindMessageTypeByName(type_name)
+ message_descriptor = pool.FindMessageTypeByName(type_name)
except KeyError:
raise TypeError(
'Can not find message descriptor by type_url: {0}.'.format(type_url))
@@ -410,15 +410,15 @@ def _CreateMessageFromTypeUrl(type_url, descriptor_pool):
return message_class()
-def Parse(text, message, ignore_unknown_fields=False, descriptor_pool=None):
+def Parse(text, message, ignore_unknown_fields=False, descriptor_pool=None):
"""Parses a JSON representation of a protocol message into a message.
Args:
text: Message JSON representation.
message: A protocol buffer message to merge into.
ignore_unknown_fields: If True, do not raise errors for unknown fields.
- descriptor_pool: A Descriptor Pool for resolving types. If None use the
- default.
+ descriptor_pool: A Descriptor Pool for resolving types. If None use the
+ default.
Returns:
The same message passed as argument.
@@ -428,29 +428,29 @@ def Parse(text, message, ignore_unknown_fields=False, descriptor_pool=None):
"""
if not isinstance(text, six.text_type): text = text.decode('utf-8')
try:
- js = json.loads(text, object_pairs_hook=_DuplicateChecker)
+ js = json.loads(text, object_pairs_hook=_DuplicateChecker)
except ValueError as e:
raise ParseError('Failed to load JSON: {0}.'.format(str(e)))
- return ParseDict(js, message, ignore_unknown_fields, descriptor_pool)
+ return ParseDict(js, message, ignore_unknown_fields, descriptor_pool)
-def ParseDict(js_dict,
- message,
- ignore_unknown_fields=False,
- descriptor_pool=None):
+def ParseDict(js_dict,
+ message,
+ ignore_unknown_fields=False,
+ descriptor_pool=None):
"""Parses a JSON dictionary representation into a message.
Args:
js_dict: Dict representation of a JSON message.
message: A protocol buffer message to merge into.
ignore_unknown_fields: If True, do not raise errors for unknown fields.
- descriptor_pool: A Descriptor Pool for resolving types. If None use the
- default.
+ descriptor_pool: A Descriptor Pool for resolving types. If None use the
+ default.
Returns:
The same message passed as argument.
"""
- parser = _Parser(ignore_unknown_fields, descriptor_pool)
+ parser = _Parser(ignore_unknown_fields, descriptor_pool)
parser.ConvertMessage(js_dict, message)
return message
@@ -461,9 +461,9 @@ _INT_OR_FLOAT = six.integer_types + (float,)
class _Parser(object):
"""JSON format parser for protocol message."""
- def __init__(self, ignore_unknown_fields, descriptor_pool):
+ def __init__(self, ignore_unknown_fields, descriptor_pool):
self.ignore_unknown_fields = ignore_unknown_fields
- self.descriptor_pool = descriptor_pool
+ self.descriptor_pool = descriptor_pool
def ConvertMessage(self, value, message):
"""Convert a JSON object into a message.
@@ -511,13 +511,13 @@ class _Parser(object):
# pylint: disable=protected-access
field = message.Extensions._FindExtensionByName(identifier)
# pylint: enable=protected-access
- if not field:
- # Try looking for extension by the message type name, dropping the
- # field name following the final . separator in full_name.
- identifier = '.'.join(identifier.split('.')[:-1])
- # pylint: disable=protected-access
- field = message.Extensions._FindExtensionByName(identifier)
- # pylint: enable=protected-access
+ if not field:
+ # Try looking for extension by the message type name, dropping the
+ # field name following the final . separator in full_name.
+ identifier = '.'.join(identifier.split('.')[:-1])
+ # pylint: disable=protected-access
+ field = message.Extensions._FindExtensionByName(identifier)
+ # pylint: enable=protected-access
if not field:
if self.ignore_unknown_fields:
continue
@@ -525,15 +525,15 @@ class _Parser(object):
('Message type "{0}" has no field named "{1}".\n'
' Available Fields(except extensions): {2}').format(
message_descriptor.full_name, name,
- [f.json_name for f in message_descriptor.fields]))
+ [f.json_name for f in message_descriptor.fields]))
if name in names:
raise ParseError('Message type "{0}" should not have multiple '
'"{1}" fields.'.format(
message.DESCRIPTOR.full_name, name))
names.append(name)
- value = js[name]
+ value = js[name]
# Check no other oneof field is parsed.
- if field.containing_oneof is not None and value is not None:
+ if field.containing_oneof is not None and value is not None:
oneof_name = field.containing_oneof.name
if oneof_name in names:
raise ParseError('Message type "{0}" should not have multiple '
@@ -546,9 +546,9 @@ class _Parser(object):
and field.message_type.full_name == 'google.protobuf.Value'):
sub_message = getattr(message, field.name)
sub_message.null_value = 0
- elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_ENUM
- and field.enum_type.full_name == 'google.protobuf.NullValue'):
- setattr(message, field.name, 0)
+ elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_ENUM
+ and field.enum_type.full_name == 'google.protobuf.NullValue'):
+ setattr(message, field.name, 0)
else:
message.ClearField(field.name)
continue
@@ -588,13 +588,13 @@ class _Parser(object):
sub_message.SetInParent()
self.ConvertMessage(value, sub_message)
else:
- if field.is_extension:
- message.Extensions[field] = _ConvertScalarFieldValue(value, field)
- else:
- setattr(message, field.name, _ConvertScalarFieldValue(value, field))
+ if field.is_extension:
+ message.Extensions[field] = _ConvertScalarFieldValue(value, field)
+ else:
+ setattr(message, field.name, _ConvertScalarFieldValue(value, field))
except ParseError as e:
if field and field.containing_oneof is None:
- raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
+ raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
else:
raise ParseError(str(e))
except ValueError as e:
@@ -611,7 +611,7 @@ class _Parser(object):
except KeyError:
raise ParseError('@type is missing when parsing any message.')
- sub_message = _CreateMessageFromTypeUrl(type_url, self.descriptor_pool)
+ sub_message = _CreateMessageFromTypeUrl(type_url, self.descriptor_pool)
message_descriptor = sub_message.DESCRIPTOR
full_name = message_descriptor.full_name
if _IsWrapperMessage(message_descriptor):
@@ -622,7 +622,7 @@ class _Parser(object):
else:
del value['@type']
self._ConvertFieldValuePair(value, sub_message)
- value['@type'] = type_url
+ value['@type'] = type_url
# Sets Any message
message.value = sub_message.SerializeToString()
message.type_url = type_url
@@ -631,10 +631,10 @@ class _Parser(object):
"""Convert a JSON representation into message with FromJsonString."""
# Duration, Timestamp, FieldMask have a FromJsonString method to do the
# conversion. Users can also call the method directly.
- try:
- message.FromJsonString(value)
- except ValueError as e:
- raise ParseError(e)
+ try:
+ message.FromJsonString(value)
+ except ValueError as e:
+ raise ParseError(e)
def _ConvertValueMessage(self, value, message):
"""Convert a JSON representation into Value message."""
@@ -651,8 +651,8 @@ class _Parser(object):
elif isinstance(value, _INT_OR_FLOAT):
message.number_value = value
else:
- raise ParseError('Value {0} has unexpected type {1}.'.format(
- value, type(value)))
+ raise ParseError('Value {0} has unexpected type {1}.'.format(
+ value, type(value)))
def _ConvertListValueMessage(self, value, message):
"""Convert a JSON representation into ListValue message."""
@@ -668,9 +668,9 @@ class _Parser(object):
if not isinstance(value, dict):
raise ParseError(
'Struct must be in a dict which is {0}.'.format(value))
- # Clear will mark the struct as modified so it will be created even if
- # there are no values.
- message.Clear()
+ # Clear will mark the struct as modified so it will be created even if
+ # there are no values.
+ message.Clear()
for key in value:
self._ConvertValueMessage(value[key], message.fields[key])
return
@@ -724,18 +724,18 @@ def _ConvertScalarFieldValue(value, field, require_str=False):
if field.cpp_type in _INT_TYPES:
return _ConvertInteger(value)
elif field.cpp_type in _FLOAT_TYPES:
- return _ConvertFloat(value, field)
+ return _ConvertFloat(value, field)
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_BOOL:
return _ConvertBool(value, require_str)
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_STRING:
if field.type == descriptor.FieldDescriptor.TYPE_BYTES:
- if isinstance(value, six.text_type):
- encoded = value.encode('utf-8')
- else:
- encoded = value
- # Add extra padding '='
- padded_value = encoded + b'=' * (4 - len(encoded) % 4)
- return base64.urlsafe_b64decode(padded_value)
+ if isinstance(value, six.text_type):
+ encoded = value.encode('utf-8')
+ else:
+ encoded = value
+ # Add extra padding '='
+ padded_value = encoded + b'=' * (4 - len(encoded) % 4)
+ return base64.urlsafe_b64decode(padded_value)
else:
# Checking for unpaired surrogates appears to be unreliable,
# depending on the specific Python version, so we check manually.
@@ -753,9 +753,9 @@ def _ConvertScalarFieldValue(value, field, require_str=False):
raise ParseError('Invalid enum value {0} for enum type {1}.'.format(
value, field.enum_type.full_name))
if enum_value is None:
- if field.file.syntax == 'proto3':
- # Proto3 accepts unknown enums.
- return number
+ if field.file.syntax == 'proto3':
+ # Proto3 accepts unknown enums.
+ return number
raise ParseError('Invalid enum value {0} for enum type {1}.'.format(
value, field.enum_type.full_name))
return enum_value.number
@@ -779,32 +779,32 @@ def _ConvertInteger(value):
if isinstance(value, six.text_type) and value.find(' ') != -1:
raise ParseError('Couldn\'t parse integer: "{0}".'.format(value))
- if isinstance(value, bool):
- raise ParseError('Bool value {0} is not acceptable for '
- 'integer field.'.format(value))
-
+ if isinstance(value, bool):
+ raise ParseError('Bool value {0} is not acceptable for '
+ 'integer field.'.format(value))
+
return int(value)
-def _ConvertFloat(value, field):
+def _ConvertFloat(value, field):
"""Convert an floating point number."""
- if isinstance(value, float):
- if math.isnan(value):
- raise ParseError('Couldn\'t parse NaN, use quoted "NaN" instead.')
- if math.isinf(value):
- if value > 0:
- raise ParseError('Couldn\'t parse Infinity or value too large, '
- 'use quoted "Infinity" instead.')
- else:
- raise ParseError('Couldn\'t parse -Infinity or value too small, '
- 'use quoted "-Infinity" instead.')
- if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
- # pylint: disable=protected-access
- if value > type_checkers._FLOAT_MAX:
- raise ParseError('Float value too large')
- # pylint: disable=protected-access
- if value < type_checkers._FLOAT_MIN:
- raise ParseError('Float value too small')
+ if isinstance(value, float):
+ if math.isnan(value):
+ raise ParseError('Couldn\'t parse NaN, use quoted "NaN" instead.')
+ if math.isinf(value):
+ if value > 0:
+ raise ParseError('Couldn\'t parse Infinity or value too large, '
+ 'use quoted "Infinity" instead.')
+ else:
+ raise ParseError('Couldn\'t parse -Infinity or value too small, '
+ 'use quoted "-Infinity" instead.')
+ if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
+ # pylint: disable=protected-access
+ if value > type_checkers._FLOAT_MAX:
+ raise ParseError('Float value too large')
+ # pylint: disable=protected-access
+ if value < type_checkers._FLOAT_MIN:
+ raise ParseError('Float value too small')
if value == 'nan':
raise ParseError('Couldn\'t parse float "nan", use "NaN" instead.')
try:
diff --git a/contrib/python/protobuf/py3/google/protobuf/message.py b/contrib/python/protobuf/py3/google/protobuf/message.py
index 224d2fc491..7355745855 100644
--- a/contrib/python/protobuf/py3/google/protobuf/message.py
+++ b/contrib/python/protobuf/py3/google/protobuf/message.py
@@ -36,21 +36,21 @@
__author__ = 'robinson@google.com (Will Robinson)'
-class Error(Exception):
- """Base error type for this module."""
- pass
-
-
-class DecodeError(Error):
- """Exception raised when deserializing messages."""
- pass
-
-
-class EncodeError(Error):
- """Exception raised when serializing messages."""
- pass
-
-
+class Error(Exception):
+ """Base error type for this module."""
+ pass
+
+
+class DecodeError(Error):
+ """Exception raised when deserializing messages."""
+ pass
+
+
+class EncodeError(Error):
+ """Exception raised when serializing messages."""
+ pass
+
+
class Message(object):
"""Abstract base class for protocol messages.
@@ -58,23 +58,23 @@ class Message(object):
Protocol message classes are almost always generated by the protocol
compiler. These generated types subclass Message and implement the methods
shown below.
- """
+ """
- # TODO(robinson): Link to an HTML document here.
+ # TODO(robinson): Link to an HTML document here.
- # TODO(robinson): Document that instances of this class will also
- # have an Extensions attribute with __getitem__ and __setitem__.
- # Again, not sure how to best convey this.
+ # TODO(robinson): Document that instances of this class will also
+ # have an Extensions attribute with __getitem__ and __setitem__.
+ # Again, not sure how to best convey this.
- # TODO(robinson): Document that the class must also have a static
- # RegisterExtension(extension_field) method.
- # Not sure how to best express at this point.
+ # TODO(robinson): Document that the class must also have a static
+ # RegisterExtension(extension_field) method.
+ # Not sure how to best express at this point.
# TODO(robinson): Document these fields and methods.
__slots__ = []
- #: The :class:`google.protobuf.descriptor.Descriptor` for this message type.
+ #: The :class:`google.protobuf.descriptor.Descriptor` for this message type.
DESCRIPTOR = None
def __deepcopy__(self, memo=None):
@@ -110,7 +110,7 @@ class Message(object):
appended. Singular sub-messages and groups are recursively merged.
Args:
- other_msg (Message): A message to merge into the current message.
+ other_msg (Message): A message to merge into the current message.
"""
raise NotImplementedError
@@ -121,7 +121,7 @@ class Message(object):
message using MergeFrom.
Args:
- other_msg (Message): A message to copy into the current one.
+ other_msg (Message): A message to copy into the current one.
"""
if self is other_msg:
return
@@ -138,16 +138,16 @@ class Message(object):
This normally happens automatically when you assign a field of a
sub-message, but sometimes you want to make the sub-message
present while keeping it empty. If you find yourself using this,
- you may want to reconsider your design.
- """
+ you may want to reconsider your design.
+ """
raise NotImplementedError
def IsInitialized(self):
"""Checks if the message is initialized.
Returns:
- bool: The method returns True if the message is initialized (i.e. all of
- its required fields are set).
+ bool: The method returns True if the message is initialized (i.e. all of
+ its required fields are set).
"""
raise NotImplementedError
@@ -160,57 +160,57 @@ class Message(object):
def MergeFromString(self, serialized):
"""Merges serialized protocol buffer data into this message.
- When we find a field in `serialized` that is already present
+ When we find a field in `serialized` that is already present
in this message:
-
- - If it's a "repeated" field, we append to the end of our list.
- - Else, if it's a scalar, we overwrite our field.
- - Else, (it's a nonrepeated composite), we recursively merge
+
+ - If it's a "repeated" field, we append to the end of our list.
+ - Else, if it's a scalar, we overwrite our field.
+ - Else, (it's a nonrepeated composite), we recursively merge
into the existing composite.
Args:
- serialized (bytes): Any object that allows us to call
- ``memoryview(serialized)`` to access a string of bytes using the
- buffer interface.
+ serialized (bytes): Any object that allows us to call
+ ``memoryview(serialized)`` to access a string of bytes using the
+ buffer interface.
Returns:
- int: The number of bytes read from `serialized`.
- For non-group messages, this will always be `len(serialized)`,
+ int: The number of bytes read from `serialized`.
+ For non-group messages, this will always be `len(serialized)`,
but for messages which are actually groups, this will
- generally be less than `len(serialized)`, since we must
- stop when we reach an ``END_GROUP`` tag. Note that if
- we *do* stop because of an ``END_GROUP`` tag, the number
+ generally be less than `len(serialized)`, since we must
+ stop when we reach an ``END_GROUP`` tag. Note that if
+ we *do* stop because of an ``END_GROUP`` tag, the number
of bytes returned does not include the bytes
- for the ``END_GROUP`` tag information.
-
- Raises:
- DecodeError: if the input cannot be parsed.
+ for the ``END_GROUP`` tag information.
+
+ Raises:
+ DecodeError: if the input cannot be parsed.
"""
- # TODO(robinson): Document handling of unknown fields.
- # TODO(robinson): When we switch to a helper, this will return None.
+ # TODO(robinson): Document handling of unknown fields.
+ # TODO(robinson): When we switch to a helper, this will return None.
raise NotImplementedError
def ParseFromString(self, serialized):
"""Parse serialized protocol buffer data into this message.
- Like :func:`MergeFromString()`, except we clear the object first.
+ Like :func:`MergeFromString()`, except we clear the object first.
"""
self.Clear()
- return self.MergeFromString(serialized)
+ return self.MergeFromString(serialized)
def SerializeToString(self, **kwargs):
"""Serializes the protocol message to a binary string.
- Keyword Args:
- deterministic (bool): If true, requests deterministic serialization
- of the protobuf, with predictable ordering of map keys.
+ Keyword Args:
+ deterministic (bool): If true, requests deterministic serialization
+ of the protobuf, with predictable ordering of map keys.
Returns:
A binary string representation of the message if all of the required
fields in the message are set (i.e. the message is initialized).
Raises:
- EncodeError: if the message isn't initialized (see :func:`IsInitialized`).
+ EncodeError: if the message isn't initialized (see :func:`IsInitialized`).
"""
raise NotImplementedError
@@ -220,12 +220,12 @@ class Message(object):
This method is similar to SerializeToString but doesn't check if the
message is initialized.
- Keyword Args:
- deterministic (bool): If true, requests deterministic serialization
- of the protobuf, with predictable ordering of map keys.
+ Keyword Args:
+ deterministic (bool): If true, requests deterministic serialization
+ of the protobuf, with predictable ordering of map keys.
Returns:
- bytes: A serialized representation of the partial message.
+ bytes: A serialized representation of the partial message.
"""
raise NotImplementedError
@@ -246,116 +246,116 @@ class Message(object):
# keywords. So they would become lambda_ or yield_.
# """
def ListFields(self):
- """Returns a list of (FieldDescriptor, value) tuples for present fields.
-
- A message field is non-empty if HasField() would return true. A singular
- primitive field is non-empty if HasField() would return true in proto2 or it
- is non zero in proto3. A repeated field is non-empty if it contains at least
- one element. The fields are ordered by field number.
-
- Returns:
- list[tuple(FieldDescriptor, value)]: field descriptors and values
- for all fields in the message which are not empty. The values vary by
- field type.
- """
+ """Returns a list of (FieldDescriptor, value) tuples for present fields.
+
+ A message field is non-empty if HasField() would return true. A singular
+ primitive field is non-empty if HasField() would return true in proto2 or it
+ is non zero in proto3. A repeated field is non-empty if it contains at least
+ one element. The fields are ordered by field number.
+
+ Returns:
+ list[tuple(FieldDescriptor, value)]: field descriptors and values
+ for all fields in the message which are not empty. The values vary by
+ field type.
+ """
raise NotImplementedError
def HasField(self, field_name):
- """Checks if a certain field is set for the message.
-
- For a oneof group, checks if any field inside is set. Note that if the
- field_name is not defined in the message descriptor, :exc:`ValueError` will
- be raised.
-
- Args:
- field_name (str): The name of the field to check for presence.
-
- Returns:
- bool: Whether a value has been set for the named field.
-
- Raises:
- ValueError: if the `field_name` is not a member of this message.
- """
+ """Checks if a certain field is set for the message.
+
+ For a oneof group, checks if any field inside is set. Note that if the
+ field_name is not defined in the message descriptor, :exc:`ValueError` will
+ be raised.
+
+ Args:
+ field_name (str): The name of the field to check for presence.
+
+ Returns:
+ bool: Whether a value has been set for the named field.
+
+ Raises:
+ ValueError: if the `field_name` is not a member of this message.
+ """
raise NotImplementedError
def ClearField(self, field_name):
- """Clears the contents of a given field.
-
- Inside a oneof group, clears the field set. If the name neither refers to a
- defined field or oneof group, :exc:`ValueError` is raised.
-
- Args:
- field_name (str): The name of the field to check for presence.
-
- Raises:
- ValueError: if the `field_name` is not a member of this message.
- """
+ """Clears the contents of a given field.
+
+ Inside a oneof group, clears the field set. If the name neither refers to a
+ defined field or oneof group, :exc:`ValueError` is raised.
+
+ Args:
+ field_name (str): The name of the field to check for presence.
+
+ Raises:
+ ValueError: if the `field_name` is not a member of this message.
+ """
raise NotImplementedError
def WhichOneof(self, oneof_group):
- """Returns the name of the field that is set inside a oneof group.
-
- If no field is set, returns None.
-
- Args:
- oneof_group (str): the name of the oneof group to check.
-
- Returns:
- str or None: The name of the group that is set, or None.
-
- Raises:
- ValueError: no group with the given name exists
- """
+ """Returns the name of the field that is set inside a oneof group.
+
+ If no field is set, returns None.
+
+ Args:
+ oneof_group (str): the name of the oneof group to check.
+
+ Returns:
+ str or None: The name of the group that is set, or None.
+
+ Raises:
+ ValueError: no group with the given name exists
+ """
raise NotImplementedError
def HasExtension(self, extension_handle):
- """Checks if a certain extension is present for this message.
-
- Extensions are retrieved using the :attr:`Extensions` mapping (if present).
-
- Args:
- extension_handle: The handle for the extension to check.
-
- Returns:
- bool: Whether the extension is present for this message.
-
- Raises:
- KeyError: if the extension is repeated. Similar to repeated fields,
- there is no separate notion of presence: a "not present" repeated
- extension is an empty list.
- """
+ """Checks if a certain extension is present for this message.
+
+ Extensions are retrieved using the :attr:`Extensions` mapping (if present).
+
+ Args:
+ extension_handle: The handle for the extension to check.
+
+ Returns:
+ bool: Whether the extension is present for this message.
+
+ Raises:
+ KeyError: if the extension is repeated. Similar to repeated fields,
+ there is no separate notion of presence: a "not present" repeated
+ extension is an empty list.
+ """
raise NotImplementedError
def ClearExtension(self, extension_handle):
- """Clears the contents of a given extension.
-
- Args:
- extension_handle: The handle for the extension to clear.
- """
- raise NotImplementedError
-
- def UnknownFields(self):
- """Returns the UnknownFieldSet.
-
- Returns:
- UnknownFieldSet: The unknown fields stored in this message.
- """
+ """Clears the contents of a given extension.
+
+ Args:
+ extension_handle: The handle for the extension to clear.
+ """
raise NotImplementedError
+ def UnknownFields(self):
+ """Returns the UnknownFieldSet.
+
+ Returns:
+ UnknownFieldSet: The unknown fields stored in this message.
+ """
+ raise NotImplementedError
+
def DiscardUnknownFields(self):
- """Clears all fields in the :class:`UnknownFieldSet`.
-
- This operation is recursive for nested message.
- """
+ """Clears all fields in the :class:`UnknownFieldSet`.
+
+ This operation is recursive for nested message.
+ """
raise NotImplementedError
def ByteSize(self):
"""Returns the serialized size of this message.
-
+
Recursively calls ByteSize() on all contained messages.
-
- Returns:
- int: The number of bytes required to serialize this message.
+
+ Returns:
+ int: The number of bytes required to serialize this message.
"""
raise NotImplementedError
@@ -387,27 +387,27 @@ class Message(object):
def __setstate__(self, state):
"""Support the pickle protocol."""
self.__init__()
- serialized = state['serialized']
- # On Python 3, using encoding='latin1' is required for unpickling
- # protos pickled by Python 2.
- if not isinstance(serialized, bytes):
- serialized = serialized.encode('latin1')
- self.ParseFromString(serialized)
-
- def __reduce__(self):
- message_descriptor = self.DESCRIPTOR
- if message_descriptor.containing_type is None:
- return type(self), (), self.__getstate__()
- # the message type must be nested.
- # Python does not pickle nested classes; use the symbol_database on the
- # receiving end.
- container = message_descriptor
- return (_InternalConstructMessage, (container.full_name,),
- self.__getstate__())
-
-
-def _InternalConstructMessage(full_name):
- """Constructs a nested message."""
- from google.protobuf import symbol_database # pylint:disable=g-import-not-at-top
-
- return symbol_database.Default().GetSymbol(full_name)()
+ serialized = state['serialized']
+ # On Python 3, using encoding='latin1' is required for unpickling
+ # protos pickled by Python 2.
+ if not isinstance(serialized, bytes):
+ serialized = serialized.encode('latin1')
+ self.ParseFromString(serialized)
+
+ def __reduce__(self):
+ message_descriptor = self.DESCRIPTOR
+ if message_descriptor.containing_type is None:
+ return type(self), (), self.__getstate__()
+ # the message type must be nested.
+ # Python does not pickle nested classes; use the symbol_database on the
+ # receiving end.
+ container = message_descriptor
+ return (_InternalConstructMessage, (container.full_name,),
+ self.__getstate__())
+
+
+def _InternalConstructMessage(full_name):
+ """Constructs a nested message."""
+ from google.protobuf import symbol_database # pylint:disable=g-import-not-at-top
+
+ return symbol_database.Default().GetSymbol(full_name)()
diff --git a/contrib/python/protobuf/py3/google/protobuf/message_factory.py b/contrib/python/protobuf/py3/google/protobuf/message_factory.py
index 7dfaec88e1..8ff16c6023 100644
--- a/contrib/python/protobuf/py3/google/protobuf/message_factory.py
+++ b/contrib/python/protobuf/py3/google/protobuf/message_factory.py
@@ -39,20 +39,20 @@ my_proto_instance = message_classes['some.proto.package.MessageName']()
__author__ = 'matthewtoia@google.com (Matt Toia)'
-from google.protobuf.internal import api_implementation
+from google.protobuf.internal import api_implementation
from google.protobuf import descriptor_pool
from google.protobuf import message
-if api_implementation.Type() == 'cpp':
- from google.protobuf.pyext import cpp_message as message_impl
-else:
- from google.protobuf.internal import python_message as message_impl
-
-
-# The type of all Message classes.
-_GENERATED_PROTOCOL_MESSAGE_TYPE = message_impl.GeneratedProtocolMessageType
-
+if api_implementation.Type() == 'cpp':
+ from google.protobuf.pyext import cpp_message as message_impl
+else:
+ from google.protobuf.internal import python_message as message_impl
+
+# The type of all Message classes.
+_GENERATED_PROTOCOL_MESSAGE_TYPE = message_impl.GeneratedProtocolMessageType
+
+
class MessageFactory(object):
"""Factory for creating Proto2 messages from descriptors in a pool."""
@@ -64,7 +64,7 @@ class MessageFactory(object):
self._classes = {}
def GetPrototype(self, descriptor):
- """Obtains a proto2 message class based on the passed in descriptor.
+ """Obtains a proto2 message class based on the passed in descriptor.
Passing a descriptor with a fully qualified name matching a previous
invocation will cause the same class to be returned.
@@ -76,52 +76,52 @@ class MessageFactory(object):
A class describing the passed in descriptor.
"""
if descriptor not in self._classes:
- result_class = self.CreatePrototype(descriptor)
- # The assignment to _classes is redundant for the base implementation, but
- # might avoid confusion in cases where CreatePrototype gets overridden and
- # does not call the base implementation.
+ result_class = self.CreatePrototype(descriptor)
+ # The assignment to _classes is redundant for the base implementation, but
+ # might avoid confusion in cases where CreatePrototype gets overridden and
+ # does not call the base implementation.
self._classes[descriptor] = result_class
- return result_class
+ return result_class
return self._classes[descriptor]
- def CreatePrototype(self, descriptor):
- """Builds a proto2 message class based on the passed in descriptor.
-
- Don't call this function directly, it always creates a new class. Call
- GetPrototype() instead. This method is meant to be overridden in subblasses
- to perform additional operations on the newly constructed class.
-
- Args:
- descriptor: The descriptor to build from.
-
- Returns:
- A class describing the passed in descriptor.
- """
- descriptor_name = descriptor.name
- if str is bytes: # PY2
- descriptor_name = descriptor.name.encode('ascii', 'ignore')
- result_class = _GENERATED_PROTOCOL_MESSAGE_TYPE(
- descriptor_name,
- (message.Message,),
- {
- 'DESCRIPTOR': descriptor,
- # If module not set, it wrongly points to message_factory module.
- '__module__': None,
- })
- result_class._FACTORY = self # pylint: disable=protected-access
- # Assign in _classes before doing recursive calls to avoid infinite
- # recursion.
- self._classes[descriptor] = result_class
- for field in descriptor.fields:
- if field.message_type:
- self.GetPrototype(field.message_type)
- for extension in result_class.DESCRIPTOR.extensions:
- if extension.containing_type not in self._classes:
- self.GetPrototype(extension.containing_type)
- extended_class = self._classes[extension.containing_type]
- extended_class.RegisterExtension(extension)
- return result_class
-
+ def CreatePrototype(self, descriptor):
+ """Builds a proto2 message class based on the passed in descriptor.
+
+ Don't call this function directly, it always creates a new class. Call
+ GetPrototype() instead. This method is meant to be overridden in subblasses
+ to perform additional operations on the newly constructed class.
+
+ Args:
+ descriptor: The descriptor to build from.
+
+ Returns:
+ A class describing the passed in descriptor.
+ """
+ descriptor_name = descriptor.name
+ if str is bytes: # PY2
+ descriptor_name = descriptor.name.encode('ascii', 'ignore')
+ result_class = _GENERATED_PROTOCOL_MESSAGE_TYPE(
+ descriptor_name,
+ (message.Message,),
+ {
+ 'DESCRIPTOR': descriptor,
+ # If module not set, it wrongly points to message_factory module.
+ '__module__': None,
+ })
+ result_class._FACTORY = self # pylint: disable=protected-access
+ # Assign in _classes before doing recursive calls to avoid infinite
+ # recursion.
+ self._classes[descriptor] = result_class
+ for field in descriptor.fields:
+ if field.message_type:
+ self.GetPrototype(field.message_type)
+ for extension in result_class.DESCRIPTOR.extensions:
+ if extension.containing_type not in self._classes:
+ self.GetPrototype(extension.containing_type)
+ extended_class = self._classes[extension.containing_type]
+ extended_class.RegisterExtension(extension)
+ return result_class
+
def GetMessages(self, files):
"""Gets all the messages from a specified file.
@@ -166,22 +166,22 @@ def GetMessages(file_protos):
"""Builds a dictionary of all the messages available in a set of files.
Args:
- file_protos: Iterable of FileDescriptorProto to build messages out of.
+ file_protos: Iterable of FileDescriptorProto to build messages out of.
Returns:
A dictionary mapping proto names to the message classes. This will include
any dependent messages as well as any messages defined in the same file as
a specified message.
"""
- # The cpp implementation of the protocol buffer library requires to add the
- # message in topological order of the dependency graph.
- file_by_name = {file_proto.name: file_proto for file_proto in file_protos}
- def _AddFile(file_proto):
- for dependency in file_proto.dependency:
- if dependency in file_by_name:
- # Remove from elements to be visited, in order to cut cycles.
- _AddFile(file_by_name.pop(dependency))
+ # The cpp implementation of the protocol buffer library requires to add the
+ # message in topological order of the dependency graph.
+ file_by_name = {file_proto.name: file_proto for file_proto in file_protos}
+ def _AddFile(file_proto):
+ for dependency in file_proto.dependency:
+ if dependency in file_by_name:
+ # Remove from elements to be visited, in order to cut cycles.
+ _AddFile(file_by_name.pop(dependency))
_FACTORY.pool.Add(file_proto)
- while file_by_name:
- _AddFile(file_by_name.popitem()[1])
+ while file_by_name:
+ _AddFile(file_by_name.popitem()[1])
return _FACTORY.GetMessages([file_proto.name for file_proto in file_protos])
diff --git a/contrib/python/protobuf/py3/google/protobuf/proto_api.h b/contrib/python/protobuf/py3/google/protobuf/proto_api.h
index c869bce058..420c54a723 100644
--- a/contrib/python/protobuf/py3/google/protobuf/proto_api.h
+++ b/contrib/python/protobuf/py3/google/protobuf/proto_api.h
@@ -1,123 +1,123 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// This file can be included by other C++ libraries, typically extension modules
-// which want to interact with the Python Messages coming from the "cpp"
-// implementation of protocol buffers.
-//
-// Usage:
-// Declare a (probably static) variable to hold the API:
-// const PyProto_API* py_proto_api;
-// In some initialization function, write:
-// py_proto_api = static_cast<const PyProto_API*>(PyCapsule_Import(
-// PyProtoAPICapsuleName(), 0));
-// if (!py_proto_api) { ...handle ImportError... }
-// Then use the methods of the returned class:
-// py_proto_api->GetMessagePointer(...);
-
-#ifndef GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
-#define GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
-
-#include <Python.h>
-
-#include <google/protobuf/descriptor_database.h>
-#include <google/protobuf/message.h>
-
-namespace google {
-namespace protobuf {
-namespace python {
-
-// Note on the implementation:
-// This API is designed after
-// https://docs.python.org/3/extending/extending.html#providing-a-c-api-for-an-extension-module
-// The class below contains no mutable state, and all methods are "const";
-// we use a C++ class instead of a C struct with functions pointers just because
-// the code looks more readable.
-struct PyProto_API {
- // The API object is created at initialization time and never freed.
- // This destructor is never called.
- virtual ~PyProto_API() {}
-
- // Operations on Messages.
-
- // If the passed object is a Python Message, returns its internal pointer.
- // Otherwise, returns NULL with an exception set.
- virtual const Message* GetMessagePointer(PyObject* msg) const = 0;
-
- // If the passed object is a Python Message, returns a mutable pointer.
- // Otherwise, returns NULL with an exception set.
- // This function will succeed only if there are no other Python objects
- // pointing to the message, like submessages or repeated containers.
- // With the current implementation, only empty messages are in this case.
- virtual Message* GetMutableMessagePointer(PyObject* msg) const = 0;
-
- // Expose the underlying DescriptorPool and MessageFactory to enable C++ code
- // to create Python-compatible message.
- virtual const DescriptorPool* GetDefaultDescriptorPool() const = 0;
- virtual MessageFactory* GetDefaultMessageFactory() const = 0;
-
- // Allocate a new protocol buffer as a python object for the provided
- // descriptor. This function works even if no Python module has been imported
- // for the corresponding protocol buffer class.
- // The factory is usually null; when provided, it is the MessageFactory which
- // owns the Python class, and will be used to find and create Extensions for
- // this message.
- // When null is returned, a python error has already been set.
- virtual PyObject* NewMessage(const Descriptor* descriptor,
- PyObject* py_message_factory) const = 0;
-
- // Allocate a new protocol buffer where the underlying object is owned by C++.
- // The factory must currently be null. This function works even if no Python
- // module has been imported for the corresponding protocol buffer class.
- // When null is returned, a python error has already been set.
- //
- // Since this call returns a python object owned by C++, some operations
- // are risky, and it must be used carefully. In particular:
- // * Avoid modifying the returned object from the C++ side while there are
- // existing python references to it or it's subobjects.
- // * Avoid using python references to this object or any subobjects after the
- // C++ object has been freed.
- // * Calling this with the same C++ pointer will result in multiple distinct
- // python objects referencing the same C++ object.
- virtual PyObject* NewMessageOwnedExternally(
- Message* msg, PyObject* py_message_factory) const = 0;
-};
-
-inline const char* PyProtoAPICapsuleName() {
- static const char kCapsuleName[] =
- "google.protobuf.pyext._message.proto_API";
- return kCapsuleName;
-}
-
-} // namespace python
-} // namespace protobuf
-} // namespace google
-
-#endif // GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// This file can be included by other C++ libraries, typically extension modules
+// which want to interact with the Python Messages coming from the "cpp"
+// implementation of protocol buffers.
+//
+// Usage:
+// Declare a (probably static) variable to hold the API:
+// const PyProto_API* py_proto_api;
+// In some initialization function, write:
+// py_proto_api = static_cast<const PyProto_API*>(PyCapsule_Import(
+// PyProtoAPICapsuleName(), 0));
+// if (!py_proto_api) { ...handle ImportError... }
+// Then use the methods of the returned class:
+// py_proto_api->GetMessagePointer(...);
+
+#ifndef GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
+#define GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
+
+#include <Python.h>
+
+#include <google/protobuf/descriptor_database.h>
+#include <google/protobuf/message.h>
+
+namespace google {
+namespace protobuf {
+namespace python {
+
+// Note on the implementation:
+// This API is designed after
+// https://docs.python.org/3/extending/extending.html#providing-a-c-api-for-an-extension-module
+// The class below contains no mutable state, and all methods are "const";
+// we use a C++ class instead of a C struct with functions pointers just because
+// the code looks more readable.
+struct PyProto_API {
+ // The API object is created at initialization time and never freed.
+ // This destructor is never called.
+ virtual ~PyProto_API() {}
+
+ // Operations on Messages.
+
+ // If the passed object is a Python Message, returns its internal pointer.
+ // Otherwise, returns NULL with an exception set.
+ virtual const Message* GetMessagePointer(PyObject* msg) const = 0;
+
+ // If the passed object is a Python Message, returns a mutable pointer.
+ // Otherwise, returns NULL with an exception set.
+ // This function will succeed only if there are no other Python objects
+ // pointing to the message, like submessages or repeated containers.
+ // With the current implementation, only empty messages are in this case.
+ virtual Message* GetMutableMessagePointer(PyObject* msg) const = 0;
+
+ // Expose the underlying DescriptorPool and MessageFactory to enable C++ code
+ // to create Python-compatible message.
+ virtual const DescriptorPool* GetDefaultDescriptorPool() const = 0;
+ virtual MessageFactory* GetDefaultMessageFactory() const = 0;
+
+ // Allocate a new protocol buffer as a python object for the provided
+ // descriptor. This function works even if no Python module has been imported
+ // for the corresponding protocol buffer class.
+ // The factory is usually null; when provided, it is the MessageFactory which
+ // owns the Python class, and will be used to find and create Extensions for
+ // this message.
+ // When null is returned, a python error has already been set.
+ virtual PyObject* NewMessage(const Descriptor* descriptor,
+ PyObject* py_message_factory) const = 0;
+
+ // Allocate a new protocol buffer where the underlying object is owned by C++.
+ // The factory must currently be null. This function works even if no Python
+ // module has been imported for the corresponding protocol buffer class.
+ // When null is returned, a python error has already been set.
+ //
+ // Since this call returns a python object owned by C++, some operations
+ // are risky, and it must be used carefully. In particular:
+ // * Avoid modifying the returned object from the C++ side while there are
+ // existing python references to it or it's subobjects.
+ // * Avoid using python references to this object or any subobjects after the
+ // C++ object has been freed.
+ // * Calling this with the same C++ pointer will result in multiple distinct
+ // python objects referencing the same C++ object.
+ virtual PyObject* NewMessageOwnedExternally(
+ Message* msg, PyObject* py_message_factory) const = 0;
+};
+
+inline const char* PyProtoAPICapsuleName() {
+ static const char kCapsuleName[] =
+ "google.protobuf.pyext._message.proto_API";
+ return kCapsuleName;
+}
+
+} // namespace python
+} // namespace protobuf
+} // namespace google
+
+#endif // GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/proto_builder.py b/contrib/python/protobuf/py3/google/protobuf/proto_builder.py
index 2b7dddcbd3..115e50319e 100644
--- a/contrib/python/protobuf/py3/google/protobuf/proto_builder.py
+++ b/contrib/python/protobuf/py3/google/protobuf/proto_builder.py
@@ -31,14 +31,14 @@
"""Dynamic Protobuf class creator."""
try:
- from collections import OrderedDict
+ from collections import OrderedDict
except ImportError:
- from ordereddict import OrderedDict #PY26
+ from ordereddict import OrderedDict #PY26
import hashlib
import os
from google.protobuf import descriptor_pb2
-from google.protobuf import descriptor
+from google.protobuf import descriptor
from google.protobuf import message_factory
@@ -125,12 +125,12 @@ def _MakeFileDescriptorProto(proto_file_name, full_name, field_items):
for f_number, (f_name, f_type) in enumerate(field_items, 1):
field_proto = desc_proto.field.add()
field_proto.name = f_name
- # # If the number falls in the reserved range, reassign it to the correct
- # # number after the range.
- if f_number >= descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER:
- f_number += (
- descriptor.FieldDescriptor.LAST_RESERVED_FIELD_NUMBER -
- descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER + 1)
+ # # If the number falls in the reserved range, reassign it to the correct
+ # # number after the range.
+ if f_number >= descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER:
+ f_number += (
+ descriptor.FieldDescriptor.LAST_RESERVED_FIELD_NUMBER -
+ descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER + 1)
field_proto.number = f_number
field_proto.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
field_proto.type = f_type
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.cc
index de788afa2f..b6a495e5b6 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.cc
@@ -30,24 +30,24 @@
// Author: petar@google.com (Petar Petrov)
-#include <google/protobuf/pyext/descriptor.h>
-
+#include <google/protobuf/pyext/descriptor.h>
+
#include <Python.h>
#include <frameobject.h>
-
-#include <cstdint>
-#include <string>
-#include <unordered_map>
-
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/dynamic_message.h>
-#include <google/protobuf/pyext/descriptor_containers.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/stubs/hash.h>
+
+#include <cstdint>
+#include <string>
+#include <unordered_map>
+
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/pyext/descriptor_containers.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/stubs/hash.h>
#if PY_MAJOR_VERSION >= 3
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
@@ -58,12 +58,12 @@
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#endif
-#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
+#define PyString_AsStringAndSize(ob, charpp, sizep) \
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
namespace google {
@@ -76,9 +76,9 @@ namespace python {
// released.
// This is enough to support the "is" operator on live objects.
// All descriptors are stored here.
-std::unordered_map<const void*, PyObject*>* interned_descriptors;
+std::unordered_map<const void*, PyObject*>* interned_descriptors;
-PyObject* PyString_FromCppString(const TProtoStringType& str) {
+PyObject* PyString_FromCppString(const TProtoStringType& str) {
return PyString_FromStringAndSize(str.c_str(), str.size());
}
@@ -125,12 +125,12 @@ bool _CalledFromGeneratedFile(int stacklevel) {
PyErr_Clear();
return false;
}
- if ((filename_size < 3) ||
- (strcmp(&filename[filename_size - 3], ".py") != 0)) {
- // Cython's stack does not have .py file name and is not at global module
- // scope.
- return true;
- }
+ if ((filename_size < 3) ||
+ (strcmp(&filename[filename_size - 3], ".py") != 0)) {
+ // Cython's stack does not have .py file name and is not at global module
+ // scope.
+ return true;
+ }
if (filename_size < 7) {
// filename is too short.
return false;
@@ -139,11 +139,11 @@ bool _CalledFromGeneratedFile(int stacklevel) {
// Filename is not ending with _pb2.
return false;
}
-
- if (frame->f_globals != frame->f_locals) {
- // Not at global module scope
- return false;
- }
+
+ if (frame->f_globals != frame->f_locals) {
+ // Not at global module scope
+ return false;
+ }
#endif
return true;
}
@@ -192,21 +192,21 @@ const FileDescriptor* GetFileDescriptor(const MethodDescriptor* descriptor) {
return descriptor->service()->file();
}
-bool Reparse(
- PyMessageFactory* message_factory, const Message& from, Message* to) {
- // Reparse message.
- TProtoStringType serialized;
- from.SerializeToString(&serialized);
- io::CodedInputStream input(
- reinterpret_cast<const uint8_t*>(serialized.c_str()), serialized.size());
- input.SetExtensionRegistry(message_factory->pool->pool,
- message_factory->message_factory);
- bool success = to->ParseFromCodedStream(&input);
- if (!success) {
- return false;
- }
- return true;
-}
+bool Reparse(
+ PyMessageFactory* message_factory, const Message& from, Message* to) {
+ // Reparse message.
+ TProtoStringType serialized;
+ from.SerializeToString(&serialized);
+ io::CodedInputStream input(
+ reinterpret_cast<const uint8_t*>(serialized.c_str()), serialized.size());
+ input.SetExtensionRegistry(message_factory->pool->pool,
+ message_factory->message_factory);
+ bool success = to->ParseFromCodedStream(&input);
+ if (!success) {
+ return false;
+ }
+ return true;
+}
// Converts options into a Python protobuf, and cache the result.
//
// This is a bit tricky because options can contain extension fields defined in
@@ -216,48 +216,48 @@ bool Reparse(
// Always returns a new reference.
template<class DescriptorClass>
static PyObject* GetOrBuildOptions(const DescriptorClass *descriptor) {
- // Options are cached in the pool that owns the descriptor.
- // First search in the cache.
- PyDescriptorPool* caching_pool = GetDescriptorPool_FromPool(
+ // Options are cached in the pool that owns the descriptor.
+ // First search in the cache.
+ PyDescriptorPool* caching_pool = GetDescriptorPool_FromPool(
GetFileDescriptor(descriptor)->pool());
- std::unordered_map<const void*, PyObject*>* descriptor_options =
- caching_pool->descriptor_options;
+ std::unordered_map<const void*, PyObject*>* descriptor_options =
+ caching_pool->descriptor_options;
if (descriptor_options->find(descriptor) != descriptor_options->end()) {
PyObject *value = (*descriptor_options)[descriptor];
Py_INCREF(value);
return value;
}
- // Similar to the C++ implementation, we return an Options object from the
- // default (generated) factory, so that client code know that they can use
- // extensions from generated files:
- // d.GetOptions().Extensions[some_pb2.extension]
- //
- // The consequence is that extensions not defined in the default pool won't
- // be available. If needed, we could add an optional 'message_factory'
- // parameter to the GetOptions() function.
- PyMessageFactory* message_factory =
- GetDefaultDescriptorPool()->py_message_factory;
-
+ // Similar to the C++ implementation, we return an Options object from the
+ // default (generated) factory, so that client code know that they can use
+ // extensions from generated files:
+ // d.GetOptions().Extensions[some_pb2.extension]
+ //
+ // The consequence is that extensions not defined in the default pool won't
+ // be available. If needed, we could add an optional 'message_factory'
+ // parameter to the GetOptions() function.
+ PyMessageFactory* message_factory =
+ GetDefaultDescriptorPool()->py_message_factory;
+
// Build the Options object: get its Python class, and make a copy of the C++
// read-only instance.
const Message& options(descriptor->options());
const Descriptor *message_type = options.GetDescriptor();
- CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
+ CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
message_factory, message_type);
if (message_class == NULL) {
PyErr_Format(PyExc_TypeError, "Could not retrieve class for Options: %s",
message_type->full_name().c_str());
return NULL;
}
- ScopedPyObjectPtr args(PyTuple_New(0));
+ ScopedPyObjectPtr args(PyTuple_New(0));
ScopedPyObjectPtr value(
- PyObject_Call(message_class->AsPyObject(), args.get(), NULL));
- Py_DECREF(message_class);
+ PyObject_Call(message_class->AsPyObject(), args.get(), NULL));
+ Py_DECREF(message_class);
if (value == NULL) {
return NULL;
}
- if (!PyObject_TypeCheck(value.get(), CMessage_Type)) {
+ if (!PyObject_TypeCheck(value.get(), CMessage_Type)) {
PyErr_Format(PyExc_TypeError, "Invalid class for %s: %s",
message_type->full_name().c_str(),
Py_TYPE(value.get())->tp_name);
@@ -271,8 +271,8 @@ static PyObject* GetOrBuildOptions(const DescriptorClass *descriptor) {
cmsg->message->CopyFrom(options);
} else {
// Reparse options string! XXX call cmessage::MergeFromString
- if (!Reparse(message_factory, options, cmsg->message)) {
- PyErr_Format(PyExc_ValueError, "Error reparsing Options message");
+ if (!Reparse(message_factory, options, cmsg->message)) {
+ PyErr_Format(PyExc_ValueError, "Error reparsing Options message");
return NULL;
}
}
@@ -293,7 +293,7 @@ static PyObject* CopyToPythonProto(const DescriptorClass *descriptor,
const Descriptor* self_descriptor =
DescriptorProtoClass::default_instance().GetDescriptor();
CMessage* message = reinterpret_cast<CMessage*>(target);
- if (!PyObject_TypeCheck(target, CMessage_Type) ||
+ if (!PyObject_TypeCheck(target, CMessage_Type) ||
message->message->GetDescriptor() != self_descriptor) {
PyErr_Format(PyExc_TypeError, "Not a %s message",
self_descriptor->full_name().c_str());
@@ -303,16 +303,16 @@ static PyObject* CopyToPythonProto(const DescriptorClass *descriptor,
DescriptorProtoClass* descriptor_message =
static_cast<DescriptorProtoClass*>(message->message);
descriptor->CopyTo(descriptor_message);
- // Custom options might in unknown extensions. Reparse
- // the descriptor_message. Can't skip reparse when options unknown
- // fields is empty, because they might in sub descriptors' options.
- PyMessageFactory* message_factory =
- GetDefaultDescriptorPool()->py_message_factory;
- if (!Reparse(message_factory, *descriptor_message, descriptor_message)) {
- PyErr_Format(PyExc_ValueError, "Error reparsing descriptor message");
- return nullptr;
- }
-
+ // Custom options might in unknown extensions. Reparse
+ // the descriptor_message. Can't skip reparse when options unknown
+ // fields is empty, because they might in sub descriptors' options.
+ PyMessageFactory* message_factory =
+ GetDefaultDescriptorPool()->py_message_factory;
+ if (!Reparse(message_factory, *descriptor_message, descriptor_message)) {
+ PyErr_Format(PyExc_ValueError, "Error reparsing descriptor message");
+ return nullptr;
+ }
+
Py_RETURN_NONE;
}
@@ -360,15 +360,15 @@ PyObject* NewInternedDescriptor(PyTypeObject* type,
}
// See if the object is in the map of interned descriptors
- std::unordered_map<const void*, PyObject*>::iterator it =
- interned_descriptors->find(descriptor);
- if (it != interned_descriptors->end()) {
+ std::unordered_map<const void*, PyObject*>::iterator it =
+ interned_descriptors->find(descriptor);
+ if (it != interned_descriptors->end()) {
GOOGLE_DCHECK(Py_TYPE(it->second) == type);
Py_INCREF(it->second);
return it->second;
}
// Create a new descriptor object
- PyBaseDescriptor* py_descriptor = PyObject_GC_New(
+ PyBaseDescriptor* py_descriptor = PyObject_GC_New(
PyBaseDescriptor, type);
if (py_descriptor == NULL) {
return NULL;
@@ -376,7 +376,7 @@ PyObject* NewInternedDescriptor(PyTypeObject* type,
py_descriptor->descriptor = descriptor;
// and cache it.
- interned_descriptors->insert(
+ interned_descriptors->insert(
std::make_pair(descriptor, reinterpret_cast<PyObject*>(py_descriptor)));
// Ensures that the DescriptorPool stays alive.
@@ -390,69 +390,69 @@ PyObject* NewInternedDescriptor(PyTypeObject* type,
Py_INCREF(pool);
py_descriptor->pool = pool;
- PyObject_GC_Track(py_descriptor);
-
+ PyObject_GC_Track(py_descriptor);
+
if (was_created) {
*was_created = true;
}
return reinterpret_cast<PyObject*>(py_descriptor);
}
-static void Dealloc(PyObject* pself) {
- PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
+static void Dealloc(PyObject* pself) {
+ PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
// Remove from interned dictionary
- interned_descriptors->erase(self->descriptor);
- Py_CLEAR(self->pool);
- Py_TYPE(self)->tp_free(pself);
-}
-
-static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
- PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
- Py_VISIT(self->pool);
- return 0;
-}
-
-static int GcClear(PyObject* pself) {
- PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
+ interned_descriptors->erase(self->descriptor);
Py_CLEAR(self->pool);
- return 0;
-}
-
+ Py_TYPE(self)->tp_free(pself);
+}
+
+static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
+ PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
+ Py_VISIT(self->pool);
+ return 0;
+}
+
+static int GcClear(PyObject* pself) {
+ PyBaseDescriptor* self = reinterpret_cast<PyBaseDescriptor*>(pself);
+ Py_CLEAR(self->pool);
+ return 0;
+}
+
static PyGetSetDef Getters[] = {
{NULL}
};
PyTypeObject PyBaseDescriptor_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".DescriptorBase", // tp_name
- sizeof(PyBaseDescriptor), // tp_basicsize
- 0, // tp_itemsize
- (destructor)Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
- "Descriptors base class", // tp_doc
- GcTraverse, // tp_traverse
- GcClear, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- Getters, // tp_getset
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".DescriptorBase", // tp_name
+ sizeof(PyBaseDescriptor), // tp_basicsize
+ 0, // tp_itemsize
+ (destructor)Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
+ "Descriptors base class", // tp_doc
+ GcTraverse, // tp_traverse
+ GcClear, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ Getters, // tp_getset
};
} // namespace descriptor
@@ -485,7 +485,7 @@ static PyObject* GetFile(PyBaseDescriptor *self, void *closure) {
}
static PyObject* GetConcreteClass(PyBaseDescriptor* self, void *closure) {
- // Returns the canonical class for the given descriptor.
+ // Returns the canonical class for the given descriptor.
// This is the class that was registered with the primary descriptor pool
// which contains this descriptor.
// This might not be the one you expect! For example the returned object does
@@ -610,11 +610,11 @@ static int SetOptions(PyBaseDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
-
+static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
+
static PyObject* CopyToProto(PyBaseDescriptor *self, PyObject *target) {
return CopyToPythonProto<DescriptorProto>(_GetDescriptor(self), target);
}
@@ -674,8 +674,8 @@ static PyGetSetDef Getters[] = {
{ "is_extendable", (getter)IsExtendable, (setter)NULL},
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{ "syntax", (getter)GetSyntax, (setter)NULL, "Syntax"},
{NULL}
};
@@ -801,29 +801,29 @@ static PyObject* HasDefaultValue(PyBaseDescriptor *self, void *closure) {
static PyObject* GetDefaultValue(PyBaseDescriptor *self, void *closure) {
PyObject *result;
- if (_GetDescriptor(self)->is_repeated()) {
- return PyList_New(0);
- }
-
-
+ if (_GetDescriptor(self)->is_repeated()) {
+ return PyList_New(0);
+ }
+
+
switch (_GetDescriptor(self)->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
- int32_t value = _GetDescriptor(self)->default_value_int32();
+ int32_t value = _GetDescriptor(self)->default_value_int32();
result = PyInt_FromLong(value);
break;
}
case FieldDescriptor::CPPTYPE_INT64: {
- int64_t value = _GetDescriptor(self)->default_value_int64();
+ int64_t value = _GetDescriptor(self)->default_value_int64();
result = PyLong_FromLongLong(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT32: {
- uint32_t value = _GetDescriptor(self)->default_value_uint32();
+ uint32_t value = _GetDescriptor(self)->default_value_uint32();
result = PyInt_FromSize_t(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT64: {
- uint64_t value = _GetDescriptor(self)->default_value_uint64();
+ uint64_t value = _GetDescriptor(self)->default_value_uint64();
result = PyLong_FromUnsignedLongLong(value);
break;
}
@@ -843,7 +843,7 @@ static PyObject* GetDefaultValue(PyBaseDescriptor *self, void *closure) {
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- const TProtoStringType& value = _GetDescriptor(self)->default_value_string();
+ const TProtoStringType& value = _GetDescriptor(self)->default_value_string();
result = ToStringObject(_GetDescriptor(self), value);
break;
}
@@ -853,10 +853,10 @@ static PyObject* GetDefaultValue(PyBaseDescriptor *self, void *closure) {
result = PyInt_FromLong(value->number());
break;
}
- case FieldDescriptor::CPPTYPE_MESSAGE: {
- Py_RETURN_NONE;
- break;
- }
+ case FieldDescriptor::CPPTYPE_MESSAGE: {
+ Py_RETURN_NONE;
+ break;
+ }
default:
PyErr_Format(PyExc_NotImplementedError, "default value for %s",
_GetDescriptor(self)->full_name().c_str());
@@ -959,10 +959,10 @@ static int SetOptions(PyBaseDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
+static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
static PyGetSetDef Getters[] = {
{ "full_name", (getter)GetFullName, NULL, "Full name"},
@@ -992,8 +992,8 @@ static PyGetSetDef Getters[] = {
"Containing oneof"},
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{NULL}
};
@@ -1123,11 +1123,11 @@ static int SetOptions(PyBaseDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
-
+static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
+
static PyObject* CopyToProto(PyBaseDescriptor *self, PyObject *target) {
return CopyToPythonProto<EnumDescriptorProto>(_GetDescriptor(self), target);
}
@@ -1152,8 +1152,8 @@ static PyGetSetDef Getters[] = {
"Containing type"},
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{NULL}
};
@@ -1254,10 +1254,10 @@ static int SetOptions(PyBaseDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
+static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
static PyGetSetDef Getters[] = {
{ "name", (getter)GetName, NULL, "name"},
@@ -1267,8 +1267,8 @@ static PyGetSetDef Getters[] = {
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{NULL}
};
@@ -1328,7 +1328,7 @@ static const FileDescriptor* _GetDescriptor(PyFileDescriptor *self) {
static void Dealloc(PyFileDescriptor* self) {
Py_XDECREF(self->serialized_pb);
- descriptor::Dealloc(reinterpret_cast<PyObject*>(self));
+ descriptor::Dealloc(reinterpret_cast<PyObject*>(self));
}
static PyObject* GetPool(PyFileDescriptor *self, void *closure) {
@@ -1354,7 +1354,7 @@ static PyObject* GetSerializedPb(PyFileDescriptor *self, void *closure) {
}
FileDescriptorProto file_proto;
_GetDescriptor(self)->CopyTo(&file_proto);
- TProtoStringType contents;
+ TProtoStringType contents;
file_proto.SerializePartialToString(&contents);
self->serialized_pb = PyBytes_FromStringAndSize(
contents.c_str(), contents.size());
@@ -1411,11 +1411,11 @@ static int SetOptions(PyFileDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyFileDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
-
+static int SetSerializedOptions(PyFileDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
+
static PyObject* GetSyntax(PyFileDescriptor *self, void *closure) {
return PyString_InternFromString(
FileDescriptor::SyntaxName(_GetDescriptor(self)->syntax()));
@@ -1441,8 +1441,8 @@ static PyGetSetDef Getters[] = {
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{ "syntax", (getter)GetSyntax, (setter)NULL, "Syntax"},
{NULL}
};
@@ -1456,45 +1456,45 @@ static PyMethodDef Methods[] = {
} // namespace file_descriptor
PyTypeObject PyFileDescriptor_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".FileDescriptor", // tp_name
- sizeof(PyFileDescriptor), // tp_basicsize
- 0, // tp_itemsize
- (destructor)file_descriptor::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "A File Descriptor", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- file_descriptor::Methods, // tp_methods
- 0, // tp_members
- file_descriptor::Getters, // tp_getset
- &descriptor::PyBaseDescriptor_Type, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
- 0, // tp_alloc
- 0, // tp_new
- PyObject_GC_Del, // tp_free
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".FileDescriptor", // tp_name
+ sizeof(PyFileDescriptor), // tp_basicsize
+ 0, // tp_itemsize
+ (destructor)file_descriptor::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "A File Descriptor", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ file_descriptor::Methods, // tp_methods
+ 0, // tp_members
+ file_descriptor::Getters, // tp_getset
+ &descriptor::PyBaseDescriptor_Type, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ 0, // tp_new
+ PyObject_GC_Del, // tp_free
};
PyObject* PyFileDescriptor_FromDescriptor(
@@ -1588,11 +1588,11 @@ static int SetOptions(PyBaseDescriptor *self, PyObject *value,
return CheckCalledFromGeneratedFile("_options");
}
-static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
- void *closure) {
- return CheckCalledFromGeneratedFile("_serialized_options");
-}
-
+static int SetSerializedOptions(PyBaseDescriptor *self, PyObject *value,
+ void *closure) {
+ return CheckCalledFromGeneratedFile("_serialized_options");
+}
+
static PyGetSetDef Getters[] = {
{ "name", (getter)GetName, NULL, "Name"},
{ "full_name", (getter)GetFullName, NULL, "Full name"},
@@ -1601,8 +1601,8 @@ static PyGetSetDef Getters[] = {
{ "containing_type", (getter)GetContainingType, NULL, "Containing type"},
{ "has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"},
{ "_options", (getter)NULL, (setter)SetOptions, "Options"},
- { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
- "Serialized Options"},
+ { "_serialized_options", (getter)NULL, (setter)SetSerializedOptions,
+ "Serialized Options"},
{ "fields", (getter)GetFields, NULL, "Fields"},
{NULL}
};
@@ -1694,7 +1694,7 @@ static PyObject* FindMethodByName(PyBaseDescriptor *self, PyObject* arg) {
}
const MethodDescriptor* method_descriptor =
- _GetDescriptor(self)->FindMethodByName(StringParam(name, name_size));
+ _GetDescriptor(self)->FindMethodByName(StringParam(name, name_size));
if (method_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find method %.200s", name);
return NULL;
@@ -1962,9 +1962,9 @@ bool InitDescriptor() {
if (!InitDescriptorMappingTypes())
return false;
- // Initialize globals defined in this file.
- interned_descriptors = new std::unordered_map<const void*, PyObject*>;
-
+ // Initialize globals defined in this file.
+ interned_descriptors = new std::unordered_map<const void*, PyObject*>;
+
return true;
}
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.h b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.h
index 47efbe35d7..fda7d0ca43 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.h
@@ -35,15 +35,15 @@
#include <Python.h>
-#include <google/protobuf/descriptor.h>
+#include <google/protobuf/descriptor.h>
namespace google {
namespace protobuf {
namespace python {
-// Should match the type of ConstStringParam.
-using StringParam = TProtoStringType;
-
+// Should match the type of ConstStringParam.
+using StringParam = TProtoStringType;
+
extern PyTypeObject PyMessageDescriptor_Type;
extern PyTypeObject PyFieldDescriptor_Type;
extern PyTypeObject PyEnumDescriptor_Type;
@@ -102,6 +102,6 @@ bool InitDescriptor();
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.cc
index 7990604ff0..64969fe426 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.cc
@@ -33,7 +33,7 @@
//
// They avoid the allocation of a full dictionary or a full list: they simply
// store a pointer to the parent descriptor, use the C++ Descriptor methods (see
-// net/proto2/public/descriptor.h) to retrieve other descriptors, and create
+// net/proto2/public/descriptor.h) to retrieve other descriptors, and create
// Python objects on the fly.
//
// The containers fully conform to abc.Mapping and abc.Sequence, and behave just
@@ -51,11 +51,11 @@
#include <Python.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/pyext/descriptor_containers.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/pyext/descriptor_containers.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#if PY_MAJOR_VERSION >= 3
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
@@ -64,12 +64,12 @@
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#endif
-#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
+#define PyString_AsStringAndSize(ob, charpp, sizep) \
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
namespace google {
@@ -80,15 +80,15 @@ struct PyContainer;
typedef int (*CountMethod)(PyContainer* self);
typedef const void* (*GetByIndexMethod)(PyContainer* self, int index);
-typedef const void* (*GetByNameMethod)(PyContainer* self,
- ConstStringParam name);
+typedef const void* (*GetByNameMethod)(PyContainer* self,
+ ConstStringParam name);
typedef const void* (*GetByCamelcaseNameMethod)(PyContainer* self,
- ConstStringParam name);
+ ConstStringParam name);
typedef const void* (*GetByNumberMethod)(PyContainer* self, int index);
typedef PyObject* (*NewObjectFromItemMethod)(const void* descriptor);
-typedef const TProtoStringType& (*GetItemNameMethod)(const void* descriptor);
-typedef const TProtoStringType& (*GetItemCamelcaseNameMethod)(
- const void* descriptor);
+typedef const TProtoStringType& (*GetItemNameMethod)(const void* descriptor);
+typedef const TProtoStringType& (*GetItemCamelcaseNameMethod)(
+ const void* descriptor);
typedef int (*GetItemNumberMethod)(const void* descriptor);
typedef int (*GetItemIndexMethod)(const void* descriptor);
@@ -183,7 +183,7 @@ static bool _GetItemByKey(PyContainer* self, PyObject* key, const void** item) {
return false;
}
*item = self->container_def->get_by_name_fn(
- self, StringParam(name, name_size));
+ self, StringParam(name, name_size));
return true;
}
case PyContainer::KIND_BYCAMELCASENAME:
@@ -200,7 +200,7 @@ static bool _GetItemByKey(PyContainer* self, PyObject* key, const void** item) {
return false;
}
*item = self->container_def->get_by_camelcase_name_fn(
- self, StringParam(camelcase_name, name_size));
+ self, StringParam(camelcase_name, name_size));
return true;
}
case PyContainer::KIND_BYNUMBER:
@@ -231,14 +231,14 @@ static PyObject* _NewKey_ByIndex(PyContainer* self, Py_ssize_t index) {
switch (self->kind) {
case PyContainer::KIND_BYNAME:
{
- const TProtoStringType& name(self->container_def->get_item_name_fn(item));
- return PyString_FromStringAndSize(name.c_str(), name.size());
+ const TProtoStringType& name(self->container_def->get_item_name_fn(item));
+ return PyString_FromStringAndSize(name.c_str(), name.size());
}
case PyContainer::KIND_BYCAMELCASENAME:
{
- const TProtoStringType& name(
- self->container_def->get_item_camelcase_name_fn(item));
- return PyString_FromStringAndSize(name.c_str(), name.size());
+ const TProtoStringType& name(
+ self->container_def->get_item_camelcase_name_fn(item));
+ return PyString_FromStringAndSize(name.c_str(), name.size());
}
case PyContainer::KIND_BYNUMBER:
{
@@ -641,7 +641,7 @@ int Find(PyContainer* self, PyObject* item) {
// the .proto file definition.
const void* descriptor_ptr = PyDescriptor_AsVoidPtr(item);
if (descriptor_ptr == NULL) {
- PyErr_Clear();
+ PyErr_Clear();
// Not a descriptor, it cannot be in the list.
return -1;
}
@@ -962,55 +962,55 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->field_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindFieldByName(name);
}
-static const void* GetByCamelcaseName(PyContainer* self,
- ConstStringParam name) {
+static const void* GetByCamelcaseName(PyContainer* self,
+ ConstStringParam name) {
return GetDescriptor(self)->FindFieldByCamelcaseName(name);
}
-static const void* GetByNumber(PyContainer* self, int number) {
+static const void* GetByNumber(PyContainer* self, int number) {
return GetDescriptor(self)->FindFieldByNumber(number);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->field(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static const TProtoStringType& GetItemCamelcaseName(const void* item) {
- return static_cast<ItemDescriptor>(item)->camelcase_name();
+static const TProtoStringType& GetItemCamelcaseName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->camelcase_name();
}
-static int GetItemNumber(const void* item) {
- return static_cast<ItemDescriptor>(item)->number();
+static int GetItemNumber(const void* item) {
+ return static_cast<ItemDescriptor>(item)->number();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"MessageFields",
- Count,
- GetByIndex,
- GetByName,
- GetByCamelcaseName,
- GetByNumber,
- NewObjectFromItem,
- GetItemName,
- GetItemCamelcaseName,
- GetItemNumber,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ GetByCamelcaseName,
+ GetByNumber,
+ NewObjectFromItem,
+ GetItemName,
+ GetItemCamelcaseName,
+ GetItemNumber,
+ GetItemIndex,
};
} // namespace fields
@@ -1040,38 +1040,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->nested_type_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindNestedTypeByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->nested_type(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyMessageDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyMessageDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"MessageNestedTypes",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace nested_types
@@ -1092,38 +1092,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->enum_type_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindEnumTypeByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->enum_type(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyEnumDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyEnumDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"MessageNestedEnums",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace enums
@@ -1155,11 +1155,11 @@ static int Count(PyContainer* self) {
return count;
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindEnumValueByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
// This is not optimal, but the number of enums *types* in a given message
// is small. This function is only used when iterating over the mapping.
const EnumDescriptor* enum_type = NULL;
@@ -1178,27 +1178,27 @@ static const void* GetByIndex(PyContainer* self, int index) {
return enum_type->value(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyEnumValueDescriptor_FromDescriptor(
- static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyEnumValueDescriptor_FromDescriptor(
+ static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
static DescriptorContainerDef ContainerDef = {
"MessageEnumValues",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- NULL,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ NULL,
};
} // namespace enumvalues
@@ -1215,38 +1215,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->extension_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindExtensionByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->extension(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"MessageExtensions",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace extensions
@@ -1267,38 +1267,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->oneof_decl_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindOneofByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->oneof_decl(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyOneofDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyOneofDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"MessageOneofs",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace oneofs
@@ -1329,47 +1329,47 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->value_count();
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->value(index);
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindValueByName(name);
}
-static const void* GetByNumber(PyContainer* self, int number) {
+static const void* GetByNumber(PyContainer* self, int number) {
return GetDescriptor(self)->FindValueByNumber(number);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyEnumValueDescriptor_FromDescriptor(
- static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyEnumValueDescriptor_FromDescriptor(
+ static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemNumber(const void* item) {
- return static_cast<ItemDescriptor>(item)->number();
+static int GetItemNumber(const void* item) {
+ return static_cast<ItemDescriptor>(item)->number();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"EnumValues",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- GetByNumber,
- NewObjectFromItem,
- GetItemName,
- NULL,
- GetItemNumber,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ GetByNumber,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ GetItemNumber,
+ GetItemIndex,
};
} // namespace enumvalues
@@ -1404,30 +1404,30 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->field_count();
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->field(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index_in_oneof();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index_in_oneof();
}
static DescriptorContainerDef ContainerDef = {
"OneofFields",
- Count,
- GetByIndex,
- NULL,
- NULL,
- NULL,
- NewObjectFromItem,
- NULL,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ NULL,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ NULL,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace fields
@@ -1454,38 +1454,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->method_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindMethodByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->method(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyMethodDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyMethodDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"ServiceMethods",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace methods
@@ -1516,38 +1516,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->message_type_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindMessageTypeByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->message_type(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyMessageDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyMessageDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"FileMessages",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace messages
@@ -1564,38 +1564,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->enum_type_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindEnumTypeByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->enum_type(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyEnumDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyEnumDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"FileEnums",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace enums
@@ -1612,38 +1612,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->extension_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindExtensionByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->extension(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFieldDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"FileExtensions",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace extensions
@@ -1660,38 +1660,38 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->service_count();
}
-static const void* GetByName(PyContainer* self, ConstStringParam name) {
+static const void* GetByName(PyContainer* self, ConstStringParam name) {
return GetDescriptor(self)->FindServiceByName(name);
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->service(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyServiceDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyServiceDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
-static const TProtoStringType& GetItemName(const void* item) {
- return static_cast<ItemDescriptor>(item)->name();
+static const TProtoStringType& GetItemName(const void* item) {
+ return static_cast<ItemDescriptor>(item)->name();
}
-static int GetItemIndex(const void* item) {
- return static_cast<ItemDescriptor>(item)->index();
+static int GetItemIndex(const void* item) {
+ return static_cast<ItemDescriptor>(item)->index();
}
static DescriptorContainerDef ContainerDef = {
"FileServices",
- Count,
- GetByIndex,
- GetByName,
- NULL,
- NULL,
- NewObjectFromItem,
- GetItemName,
- NULL,
- NULL,
- GetItemIndex,
+ Count,
+ GetByIndex,
+ GetByName,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ GetItemName,
+ NULL,
+ NULL,
+ GetItemIndex,
};
} // namespace services
@@ -1708,26 +1708,26 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->dependency_count();
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->dependency(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFileDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFileDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
static DescriptorContainerDef ContainerDef = {
"FileDependencies",
- Count,
- GetByIndex,
- NULL,
- NULL,
- NULL,
- NewObjectFromItem,
- NULL,
- NULL,
- NULL,
- NULL,
+ Count,
+ GetByIndex,
+ NULL,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
};
} // namespace dependencies
@@ -1744,26 +1744,26 @@ static int Count(PyContainer* self) {
return GetDescriptor(self)->public_dependency_count();
}
-static const void* GetByIndex(PyContainer* self, int index) {
+static const void* GetByIndex(PyContainer* self, int index) {
return GetDescriptor(self)->public_dependency(index);
}
-static PyObject* NewObjectFromItem(const void* item) {
- return PyFileDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
+static PyObject* NewObjectFromItem(const void* item) {
+ return PyFileDescriptor_FromDescriptor(static_cast<ItemDescriptor>(item));
}
static DescriptorContainerDef ContainerDef = {
"FilePublicDependencies",
- Count,
- GetByIndex,
- NULL,
- NULL,
- NULL,
- NewObjectFromItem,
- NULL,
- NULL,
- NULL,
- NULL,
+ Count,
+ GetByIndex,
+ NULL,
+ NULL,
+ NULL,
+ NewObjectFromItem,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
};
} // namespace public_dependencies
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.h b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.h
index 4e05c58e2b..2e7960f227 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.h
@@ -104,6 +104,6 @@ PyObject* NewServiceMethodsByName(const ServiceDescriptor* descriptor);
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_CONTAINERS_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_database.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_database.cc
index be8089841c..fdf53cab1d 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_database.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_database.cc
@@ -31,15 +31,15 @@
// This file defines a C++ DescriptorDatabase, which wraps a Python Database
// and delegate all its operations to Python methods.
-#include <google/protobuf/pyext/descriptor_database.h>
+#include <google/protobuf/pyext/descriptor_database.h>
-#include <cstdint>
-
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <cstdint>
+
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
namespace google {
namespace protobuf {
@@ -72,7 +72,7 @@ static bool GetFileDescriptorProto(PyObject* py_descriptor,
const Descriptor* filedescriptor_descriptor =
FileDescriptorProto::default_instance().GetDescriptor();
CMessage* message = reinterpret_cast<CMessage*>(py_descriptor);
- if (PyObject_TypeCheck(py_descriptor, CMessage_Type) &&
+ if (PyObject_TypeCheck(py_descriptor, CMessage_Type) &&
message->message->GetDescriptor() == filedescriptor_descriptor) {
// Fast path: Just use the pointer.
FileDescriptorProto* file_proto =
@@ -110,7 +110,7 @@ static bool GetFileDescriptorProto(PyObject* py_descriptor,
}
// Find a file by file name.
-bool PyDescriptorDatabase::FindFileByName(const TProtoStringType& filename,
+bool PyDescriptorDatabase::FindFileByName(const TProtoStringType& filename,
FileDescriptorProto* output) {
ScopedPyObjectPtr py_descriptor(PyObject_CallMethod(
py_database_, "FindFileByName", "s#", filename.c_str(), filename.size()));
@@ -119,7 +119,7 @@ bool PyDescriptorDatabase::FindFileByName(const TProtoStringType& filename,
// Find the file that declares the given fully-qualified symbol name.
bool PyDescriptorDatabase::FindFileContainingSymbol(
- const TProtoStringType& symbol_name, FileDescriptorProto* output) {
+ const TProtoStringType& symbol_name, FileDescriptorProto* output) {
ScopedPyObjectPtr py_descriptor(
PyObject_CallMethod(py_database_, "FindFileContainingSymbol", "s#",
symbol_name.c_str(), symbol_name.size()));
@@ -130,7 +130,7 @@ bool PyDescriptorDatabase::FindFileContainingSymbol(
// with the given field number.
// Python DescriptorDatabases are not required to implement this method.
bool PyDescriptorDatabase::FindFileContainingExtension(
- const TProtoStringType& containing_type, int field_number,
+ const TProtoStringType& containing_type, int field_number,
FileDescriptorProto* output) {
ScopedPyObjectPtr py_method(
PyObject_GetAttrString(py_database_, "FindFileContainingExtension"));
@@ -145,43 +145,43 @@ bool PyDescriptorDatabase::FindFileContainingExtension(
return GetFileDescriptorProto(py_descriptor.get(), output);
}
-// Finds the tag numbers used by all known extensions of
-// containing_type, and appends them to output in an undefined
-// order.
-// Python DescriptorDatabases are not required to implement this method.
-bool PyDescriptorDatabase::FindAllExtensionNumbers(
- const TProtoStringType& containing_type, std::vector<int>* output) {
- ScopedPyObjectPtr py_method(
- PyObject_GetAttrString(py_database_, "FindAllExtensionNumbers"));
- if (py_method == NULL) {
- // This method is not implemented, returns without error.
- PyErr_Clear();
- return false;
- }
- ScopedPyObjectPtr py_list(
- PyObject_CallFunction(py_method.get(), "s#", containing_type.c_str(),
- containing_type.size()));
- if (py_list == NULL) {
- PyErr_Print();
- return false;
- }
- Py_ssize_t size = PyList_Size(py_list.get());
- int64_t item_value;
- for (Py_ssize_t i = 0 ; i < size; ++i) {
- ScopedPyObjectPtr item(PySequence_GetItem(py_list.get(), i));
- item_value = PyLong_AsLong(item.get());
- if (item_value < 0) {
- GOOGLE_LOG(ERROR)
- << "FindAllExtensionNumbers method did not return "
- << "valid extension numbers.";
- PyErr_Print();
- return false;
- }
- output->push_back(item_value);
- }
- return true;
-}
-
+// Finds the tag numbers used by all known extensions of
+// containing_type, and appends them to output in an undefined
+// order.
+// Python DescriptorDatabases are not required to implement this method.
+bool PyDescriptorDatabase::FindAllExtensionNumbers(
+ const TProtoStringType& containing_type, std::vector<int>* output) {
+ ScopedPyObjectPtr py_method(
+ PyObject_GetAttrString(py_database_, "FindAllExtensionNumbers"));
+ if (py_method == NULL) {
+ // This method is not implemented, returns without error.
+ PyErr_Clear();
+ return false;
+ }
+ ScopedPyObjectPtr py_list(
+ PyObject_CallFunction(py_method.get(), "s#", containing_type.c_str(),
+ containing_type.size()));
+ if (py_list == NULL) {
+ PyErr_Print();
+ return false;
+ }
+ Py_ssize_t size = PyList_Size(py_list.get());
+ int64_t item_value;
+ for (Py_ssize_t i = 0 ; i < size; ++i) {
+ ScopedPyObjectPtr item(PySequence_GetItem(py_list.get(), i));
+ item_value = PyLong_AsLong(item.get());
+ if (item_value < 0) {
+ GOOGLE_LOG(ERROR)
+ << "FindAllExtensionNumbers method did not return "
+ << "valid extension numbers.";
+ PyErr_Print();
+ return false;
+ }
+ output->push_back(item_value);
+ }
+ return true;
+}
+
} // namespace python
} // namespace protobuf
} // namespace google
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_database.h b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_database.h
index 59918a6d92..3c7dc88c37 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_database.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_database.h
@@ -33,7 +33,7 @@
#include <Python.h>
-#include <google/protobuf/descriptor_database.h>
+#include <google/protobuf/descriptor_database.h>
namespace google {
namespace protobuf {
@@ -48,27 +48,27 @@ class PyDescriptorDatabase : public DescriptorDatabase {
// with a copy of FileDescriptorProto.
// Find a file by file name.
- bool FindFileByName(const TProtoStringType& filename, FileDescriptorProto* output);
+ bool FindFileByName(const TProtoStringType& filename, FileDescriptorProto* output);
// Find the file that declares the given fully-qualified symbol name.
- bool FindFileContainingSymbol(const TProtoStringType& symbol_name,
+ bool FindFileContainingSymbol(const TProtoStringType& symbol_name,
FileDescriptorProto* output);
// Find the file which defines an extension extending the given message type
// with the given field number.
// Containing_type must be a fully-qualified type name.
// Python objects are not required to implement this method.
- bool FindFileContainingExtension(const TProtoStringType& containing_type,
+ bool FindFileContainingExtension(const TProtoStringType& containing_type,
int field_number,
FileDescriptorProto* output);
- // Finds the tag numbers used by all known extensions of
- // containing_type, and appends them to output in an undefined
- // order.
- // Python objects are not required to implement this method.
- bool FindAllExtensionNumbers(const TProtoStringType& containing_type,
- std::vector<int>* output);
-
+ // Finds the tag numbers used by all known extensions of
+ // containing_type, and appends them to output in an undefined
+ // order.
+ // Python objects are not required to implement this method.
+ bool FindAllExtensionNumbers(const TProtoStringType& containing_type,
+ std::vector<int>* output);
+
private:
// The python object that implements the database. The reference is owned.
PyObject* py_database_;
@@ -76,6 +76,6 @@ class PyDescriptorDatabase : public DescriptorDatabase {
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_DATABASE_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.cc
index a53411e797..1e6fe82cbf 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.cc
@@ -30,30 +30,30 @@
// Implements the DescriptorPool, which collects all descriptors.
-#include <unordered_map>
-
+#include <unordered_map>
+
#include <Python.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/descriptor_database.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/stubs/hash.h>
+#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/descriptor_database.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/stubs/hash.h>
#if PY_MAJOR_VERSION >= 3
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#endif
-#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
+#define PyString_AsStringAndSize(ob, charpp, sizep) \
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
namespace google {
@@ -62,57 +62,57 @@ namespace python {
// A map to cache Python Pools per C++ pointer.
// Pointers are not owned here, and belong to the PyDescriptorPool.
-static std::unordered_map<const DescriptorPool*, PyDescriptorPool*>*
- descriptor_pool_map;
+static std::unordered_map<const DescriptorPool*, PyDescriptorPool*>*
+ descriptor_pool_map;
namespace cdescriptor_pool {
-// Collects errors that occur during proto file building to allow them to be
-// propagated in the python exception instead of only living in ERROR logs.
-class BuildFileErrorCollector : public DescriptorPool::ErrorCollector {
- public:
- BuildFileErrorCollector() : error_message(""), had_errors_(false) {}
-
- void AddError(const TProtoStringType& filename, const TProtoStringType& element_name,
- const Message* descriptor, ErrorLocation location,
- const TProtoStringType& message) override {
- // Replicates the logging behavior that happens in the C++ implementation
- // when an error collector is not passed in.
- if (!had_errors_) {
- error_message +=
- ("Invalid proto descriptor for file \"" + filename + "\":\n");
- had_errors_ = true;
- }
- // As this only happens on failure and will result in the program not
- // running at all, no effort is made to optimize this string manipulation.
- error_message += (" " + element_name + ": " + message + "\n");
- }
-
- void Clear() {
- had_errors_ = false;
- error_message = "";
- }
-
- TProtoStringType error_message;
-
- private:
- bool had_errors_;
-};
-
+// Collects errors that occur during proto file building to allow them to be
+// propagated in the python exception instead of only living in ERROR logs.
+class BuildFileErrorCollector : public DescriptorPool::ErrorCollector {
+ public:
+ BuildFileErrorCollector() : error_message(""), had_errors_(false) {}
+
+ void AddError(const TProtoStringType& filename, const TProtoStringType& element_name,
+ const Message* descriptor, ErrorLocation location,
+ const TProtoStringType& message) override {
+ // Replicates the logging behavior that happens in the C++ implementation
+ // when an error collector is not passed in.
+ if (!had_errors_) {
+ error_message +=
+ ("Invalid proto descriptor for file \"" + filename + "\":\n");
+ had_errors_ = true;
+ }
+ // As this only happens on failure and will result in the program not
+ // running at all, no effort is made to optimize this string manipulation.
+ error_message += (" " + element_name + ": " + message + "\n");
+ }
+
+ void Clear() {
+ had_errors_ = false;
+ error_message = "";
+ }
+
+ TProtoStringType error_message;
+
+ private:
+ bool had_errors_;
+};
+
// Create a Python DescriptorPool object, but does not fill the "pool"
// attribute.
static PyDescriptorPool* _CreateDescriptorPool() {
- PyDescriptorPool* cpool = PyObject_GC_New(
+ PyDescriptorPool* cpool = PyObject_GC_New(
PyDescriptorPool, &PyDescriptorPool_Type);
if (cpool == NULL) {
return NULL;
}
- cpool->error_collector = nullptr;
+ cpool->error_collector = nullptr;
cpool->underlay = NULL;
cpool->database = NULL;
- cpool->descriptor_options = new std::unordered_map<const void*, PyObject*>();
+ cpool->descriptor_options = new std::unordered_map<const void*, PyObject*>();
cpool->py_message_factory = message_factory::NewMessageFactory(
&PyMessageFactory_Type, cpool);
@@ -121,8 +121,8 @@ static PyDescriptorPool* _CreateDescriptorPool() {
return NULL;
}
- PyObject_GC_Track(cpool);
-
+ PyObject_GC_Track(cpool);
+
return cpool;
}
@@ -140,7 +140,7 @@ static PyDescriptorPool* PyDescriptorPool_NewWithUnderlay(
cpool->pool = new DescriptorPool(underlay);
cpool->underlay = underlay;
- if (!descriptor_pool_map->insert(
+ if (!descriptor_pool_map->insert(
std::make_pair(cpool->pool, cpool)).second) {
// Should never happen -- would indicate an internal error / bug.
PyErr_SetString(PyExc_ValueError, "DescriptorPool already registered");
@@ -157,14 +157,14 @@ static PyDescriptorPool* PyDescriptorPool_NewWithDatabase(
return NULL;
}
if (database != NULL) {
- cpool->error_collector = new BuildFileErrorCollector();
- cpool->pool = new DescriptorPool(database, cpool->error_collector);
+ cpool->error_collector = new BuildFileErrorCollector();
+ cpool->pool = new DescriptorPool(database, cpool->error_collector);
cpool->database = database;
} else {
cpool->pool = new DescriptorPool();
}
- if (!descriptor_pool_map->insert(std::make_pair(cpool->pool, cpool)).second) {
+ if (!descriptor_pool_map->insert(std::make_pair(cpool->pool, cpool)).second) {
// Should never happen -- would indicate an internal error / bug.
PyErr_SetString(PyExc_ValueError, "DescriptorPool already registered");
return NULL;
@@ -178,8 +178,8 @@ static PyObject* New(PyTypeObject* type,
PyObject* args, PyObject* kwargs) {
static const char* kwlist[] = {"descriptor_db", 0};
PyObject* py_database = NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O",
- const_cast<char**>(kwlist), &py_database)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O",
+ const_cast<char**>(kwlist), &py_database)) {
return NULL;
}
DescriptorDatabase* database = NULL;
@@ -190,11 +190,11 @@ static PyObject* New(PyTypeObject* type,
PyDescriptorPool_NewWithDatabase(database));
}
-static void Dealloc(PyObject* pself) {
- PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
- descriptor_pool_map->erase(self->pool);
+static void Dealloc(PyObject* pself) {
+ PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
+ descriptor_pool_map->erase(self->pool);
Py_CLEAR(self->py_message_factory);
- for (std::unordered_map<const void*, PyObject*>::iterator it =
+ for (std::unordered_map<const void*, PyObject*>::iterator it =
self->descriptor_options->begin();
it != self->descriptor_options->end(); ++it) {
Py_DECREF(it->second);
@@ -202,37 +202,37 @@ static void Dealloc(PyObject* pself) {
delete self->descriptor_options;
delete self->database;
delete self->pool;
- delete self->error_collector;
- Py_TYPE(self)->tp_free(pself);
-}
-
-static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
- PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
- Py_VISIT(self->py_message_factory);
- return 0;
-}
-
-static int GcClear(PyObject* pself) {
- PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
- Py_CLEAR(self->py_message_factory);
- return 0;
-}
-
-PyObject* SetErrorFromCollector(DescriptorPool::ErrorCollector* self,
- const char* name, const char* error_type) {
- BuildFileErrorCollector* error_collector =
- reinterpret_cast<BuildFileErrorCollector*>(self);
- if (error_collector && !error_collector->error_message.empty()) {
- PyErr_Format(PyExc_KeyError, "Couldn't build file for %s %.200s\n%s",
- error_type, name, error_collector->error_message.c_str());
- error_collector->Clear();
- return NULL;
- }
- PyErr_Format(PyExc_KeyError, "Couldn't find %s %.200s", error_type, name);
- return NULL;
-}
-
-static PyObject* FindMessageByName(PyObject* self, PyObject* arg) {
+ delete self->error_collector;
+ Py_TYPE(self)->tp_free(pself);
+}
+
+static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
+ PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
+ Py_VISIT(self->py_message_factory);
+ return 0;
+}
+
+static int GcClear(PyObject* pself) {
+ PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
+ Py_CLEAR(self->py_message_factory);
+ return 0;
+}
+
+PyObject* SetErrorFromCollector(DescriptorPool::ErrorCollector* self,
+ const char* name, const char* error_type) {
+ BuildFileErrorCollector* error_collector =
+ reinterpret_cast<BuildFileErrorCollector*>(self);
+ if (error_collector && !error_collector->error_message.empty()) {
+ PyErr_Format(PyExc_KeyError, "Couldn't build file for %s %.200s\n%s",
+ error_type, name, error_collector->error_message.c_str());
+ error_collector->Clear();
+ return NULL;
+ }
+ PyErr_Format(PyExc_KeyError, "Couldn't find %s %.200s", error_type, name);
+ return NULL;
+}
+
+static PyObject* FindMessageByName(PyObject* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
@@ -240,35 +240,35 @@ static PyObject* FindMessageByName(PyObject* self, PyObject* arg) {
}
const Descriptor* message_descriptor =
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMessageTypeByName(
- StringParam(name, name_size));
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMessageTypeByName(
+ StringParam(name, name_size));
if (message_descriptor == NULL) {
- return SetErrorFromCollector(
- reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
- "message");
+ return SetErrorFromCollector(
+ reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
+ "message");
}
-
+
return PyMessageDescriptor_FromDescriptor(message_descriptor);
}
-static PyObject* FindFileByName(PyObject* self, PyObject* arg) {
+static PyObject* FindFileByName(PyObject* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
return NULL;
}
- PyDescriptorPool* py_pool = reinterpret_cast<PyDescriptorPool*>(self);
+ PyDescriptorPool* py_pool = reinterpret_cast<PyDescriptorPool*>(self);
const FileDescriptor* file_descriptor =
- py_pool->pool->FindFileByName(StringParam(name, name_size));
-
+ py_pool->pool->FindFileByName(StringParam(name, name_size));
+
if (file_descriptor == NULL) {
- return SetErrorFromCollector(py_pool->error_collector, name, "file");
+ return SetErrorFromCollector(py_pool->error_collector, name, "file");
}
return PyFileDescriptor_FromDescriptor(file_descriptor);
}
@@ -281,19 +281,19 @@ PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* arg) {
}
const FieldDescriptor* field_descriptor =
- self->pool->FindFieldByName(StringParam(name, name_size));
+ self->pool->FindFieldByName(StringParam(name, name_size));
if (field_descriptor == NULL) {
- return SetErrorFromCollector(self->error_collector, name, "field");
+ return SetErrorFromCollector(self->error_collector, name, "field");
}
-
+
return PyFieldDescriptor_FromDescriptor(field_descriptor);
}
-static PyObject* FindFieldByNameMethod(PyObject* self, PyObject* arg) {
- return FindFieldByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
-}
-
+static PyObject* FindFieldByNameMethod(PyObject* self, PyObject* arg) {
+ return FindFieldByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
+}
+
PyObject* FindExtensionByName(PyDescriptorPool* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
@@ -302,20 +302,20 @@ PyObject* FindExtensionByName(PyDescriptorPool* self, PyObject* arg) {
}
const FieldDescriptor* field_descriptor =
- self->pool->FindExtensionByName(StringParam(name, name_size));
+ self->pool->FindExtensionByName(StringParam(name, name_size));
if (field_descriptor == NULL) {
- return SetErrorFromCollector(self->error_collector, name,
- "extension field");
+ return SetErrorFromCollector(self->error_collector, name,
+ "extension field");
}
-
+
return PyFieldDescriptor_FromDescriptor(field_descriptor);
}
-static PyObject* FindExtensionByNameMethod(PyObject* self, PyObject* arg) {
- return FindExtensionByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
-}
-
+static PyObject* FindExtensionByNameMethod(PyObject* self, PyObject* arg) {
+ return FindExtensionByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
+}
+
PyObject* FindEnumTypeByName(PyDescriptorPool* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
@@ -324,19 +324,19 @@ PyObject* FindEnumTypeByName(PyDescriptorPool* self, PyObject* arg) {
}
const EnumDescriptor* enum_descriptor =
- self->pool->FindEnumTypeByName(StringParam(name, name_size));
+ self->pool->FindEnumTypeByName(StringParam(name, name_size));
if (enum_descriptor == NULL) {
- return SetErrorFromCollector(self->error_collector, name, "enum");
+ return SetErrorFromCollector(self->error_collector, name, "enum");
}
-
+
return PyEnumDescriptor_FromDescriptor(enum_descriptor);
}
-static PyObject* FindEnumTypeByNameMethod(PyObject* self, PyObject* arg) {
- return FindEnumTypeByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
-}
-
+static PyObject* FindEnumTypeByNameMethod(PyObject* self, PyObject* arg) {
+ return FindEnumTypeByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
+}
+
PyObject* FindOneofByName(PyDescriptorPool* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
@@ -345,20 +345,20 @@ PyObject* FindOneofByName(PyDescriptorPool* self, PyObject* arg) {
}
const OneofDescriptor* oneof_descriptor =
- self->pool->FindOneofByName(StringParam(name, name_size));
+ self->pool->FindOneofByName(StringParam(name, name_size));
if (oneof_descriptor == NULL) {
- return SetErrorFromCollector(self->error_collector, name, "oneof");
+ return SetErrorFromCollector(self->error_collector, name, "oneof");
}
-
+
return PyOneofDescriptor_FromDescriptor(oneof_descriptor);
}
-static PyObject* FindOneofByNameMethod(PyObject* self, PyObject* arg) {
- return FindOneofByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
-}
-
-static PyObject* FindServiceByName(PyObject* self, PyObject* arg) {
+static PyObject* FindOneofByNameMethod(PyObject* self, PyObject* arg) {
+ return FindOneofByName(reinterpret_cast<PyDescriptorPool*>(self), arg);
+}
+
+static PyObject* FindServiceByName(PyObject* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
@@ -366,19 +366,19 @@ static PyObject* FindServiceByName(PyObject* self, PyObject* arg) {
}
const ServiceDescriptor* service_descriptor =
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindServiceByName(
- StringParam(name, name_size));
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindServiceByName(
+ StringParam(name, name_size));
if (service_descriptor == NULL) {
- return SetErrorFromCollector(
- reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
- "service");
+ return SetErrorFromCollector(
+ reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
+ "service");
}
-
+
return PyServiceDescriptor_FromDescriptor(service_descriptor);
}
-static PyObject* FindMethodByName(PyObject* self, PyObject* arg) {
+static PyObject* FindMethodByName(PyObject* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
@@ -386,19 +386,19 @@ static PyObject* FindMethodByName(PyObject* self, PyObject* arg) {
}
const MethodDescriptor* method_descriptor =
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMethodByName(
- StringParam(name, name_size));
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMethodByName(
+ StringParam(name, name_size));
if (method_descriptor == NULL) {
- return SetErrorFromCollector(
- reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
- "method");
+ return SetErrorFromCollector(
+ reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
+ "method");
}
-
+
return PyMethodDescriptor_FromDescriptor(method_descriptor);
}
-static PyObject* FindFileContainingSymbol(PyObject* self, PyObject* arg) {
+static PyObject* FindFileContainingSymbol(PyObject* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
@@ -406,19 +406,19 @@ static PyObject* FindFileContainingSymbol(PyObject* self, PyObject* arg) {
}
const FileDescriptor* file_descriptor =
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileContainingSymbol(
- StringParam(name, name_size));
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileContainingSymbol(
+ StringParam(name, name_size));
if (file_descriptor == NULL) {
- return SetErrorFromCollector(
- reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
- "symbol");
+ return SetErrorFromCollector(
+ reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
+ "symbol");
}
-
+
return PyFileDescriptor_FromDescriptor(file_descriptor);
}
-static PyObject* FindExtensionByNumber(PyObject* self, PyObject* args) {
+static PyObject* FindExtensionByNumber(PyObject* self, PyObject* args) {
PyObject* message_descriptor;
int number;
if (!PyArg_ParseTuple(args, "Oi", &message_descriptor, &number)) {
@@ -431,35 +431,35 @@ static PyObject* FindExtensionByNumber(PyObject* self, PyObject* args) {
}
const FieldDescriptor* extension_descriptor =
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindExtensionByNumber(
- descriptor, number);
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindExtensionByNumber(
+ descriptor, number);
if (extension_descriptor == NULL) {
- BuildFileErrorCollector* error_collector =
- reinterpret_cast<BuildFileErrorCollector*>(
- reinterpret_cast<PyDescriptorPool*>(self)->error_collector);
- if (error_collector && !error_collector->error_message.empty()) {
- PyErr_Format(PyExc_KeyError, "Couldn't build file for Extension %.d\n%s",
- number, error_collector->error_message.c_str());
- error_collector->Clear();
- return NULL;
- }
- PyErr_Format(PyExc_KeyError, "Couldn't find Extension %d", number);
+ BuildFileErrorCollector* error_collector =
+ reinterpret_cast<BuildFileErrorCollector*>(
+ reinterpret_cast<PyDescriptorPool*>(self)->error_collector);
+ if (error_collector && !error_collector->error_message.empty()) {
+ PyErr_Format(PyExc_KeyError, "Couldn't build file for Extension %.d\n%s",
+ number, error_collector->error_message.c_str());
+ error_collector->Clear();
+ return NULL;
+ }
+ PyErr_Format(PyExc_KeyError, "Couldn't find Extension %d", number);
return NULL;
}
-
+
return PyFieldDescriptor_FromDescriptor(extension_descriptor);
}
-static PyObject* FindAllExtensions(PyObject* self, PyObject* arg) {
+static PyObject* FindAllExtensions(PyObject* self, PyObject* arg) {
const Descriptor* descriptor = PyMessageDescriptor_AsDescriptor(arg);
if (descriptor == NULL) {
return NULL;
}
std::vector<const FieldDescriptor*> extensions;
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindAllExtensions(
- descriptor, &extensions);
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindAllExtensions(
+ descriptor, &extensions);
ScopedPyObjectPtr result(PyList_New(extensions.size()));
if (result == NULL) {
@@ -484,15 +484,15 @@ static PyObject* FindAllExtensions(PyObject* self, PyObject* arg) {
// call a function that will just be a no-op?
// TODO(amauryfa): Need to investigate further.
-static PyObject* AddFileDescriptor(PyObject* self, PyObject* descriptor) {
+static PyObject* AddFileDescriptor(PyObject* self, PyObject* descriptor) {
const FileDescriptor* file_descriptor =
PyFileDescriptor_AsDescriptor(descriptor);
if (!file_descriptor) {
return NULL;
}
if (file_descriptor !=
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileByName(
- file_descriptor->name())) {
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileByName(
+ file_descriptor->name())) {
PyErr_Format(PyExc_ValueError,
"The file descriptor %s does not belong to this pool",
file_descriptor->name().c_str());
@@ -501,15 +501,15 @@ static PyObject* AddFileDescriptor(PyObject* self, PyObject* descriptor) {
Py_RETURN_NONE;
}
-static PyObject* AddDescriptor(PyObject* self, PyObject* descriptor) {
+static PyObject* AddDescriptor(PyObject* self, PyObject* descriptor) {
const Descriptor* message_descriptor =
PyMessageDescriptor_AsDescriptor(descriptor);
if (!message_descriptor) {
return NULL;
}
if (message_descriptor !=
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMessageTypeByName(
- message_descriptor->full_name())) {
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMessageTypeByName(
+ message_descriptor->full_name())) {
PyErr_Format(PyExc_ValueError,
"The message descriptor %s does not belong to this pool",
message_descriptor->full_name().c_str());
@@ -518,15 +518,15 @@ static PyObject* AddDescriptor(PyObject* self, PyObject* descriptor) {
Py_RETURN_NONE;
}
-static PyObject* AddEnumDescriptor(PyObject* self, PyObject* descriptor) {
+static PyObject* AddEnumDescriptor(PyObject* self, PyObject* descriptor) {
const EnumDescriptor* enum_descriptor =
PyEnumDescriptor_AsDescriptor(descriptor);
if (!enum_descriptor) {
return NULL;
}
if (enum_descriptor !=
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindEnumTypeByName(
- enum_descriptor->full_name())) {
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindEnumTypeByName(
+ enum_descriptor->full_name())) {
PyErr_Format(PyExc_ValueError,
"The enum descriptor %s does not belong to this pool",
enum_descriptor->full_name().c_str());
@@ -535,15 +535,15 @@ static PyObject* AddEnumDescriptor(PyObject* self, PyObject* descriptor) {
Py_RETURN_NONE;
}
-static PyObject* AddExtensionDescriptor(PyObject* self, PyObject* descriptor) {
+static PyObject* AddExtensionDescriptor(PyObject* self, PyObject* descriptor) {
const FieldDescriptor* extension_descriptor =
PyFieldDescriptor_AsDescriptor(descriptor);
if (!extension_descriptor) {
return NULL;
}
if (extension_descriptor !=
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindExtensionByName(
- extension_descriptor->full_name())) {
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindExtensionByName(
+ extension_descriptor->full_name())) {
PyErr_Format(PyExc_ValueError,
"The extension descriptor %s does not belong to this pool",
extension_descriptor->full_name().c_str());
@@ -552,15 +552,15 @@ static PyObject* AddExtensionDescriptor(PyObject* self, PyObject* descriptor) {
Py_RETURN_NONE;
}
-static PyObject* AddServiceDescriptor(PyObject* self, PyObject* descriptor) {
+static PyObject* AddServiceDescriptor(PyObject* self, PyObject* descriptor) {
const ServiceDescriptor* service_descriptor =
PyServiceDescriptor_AsDescriptor(descriptor);
if (!service_descriptor) {
return NULL;
}
if (service_descriptor !=
- reinterpret_cast<PyDescriptorPool*>(self)->pool->FindServiceByName(
- service_descriptor->full_name())) {
+ reinterpret_cast<PyDescriptorPool*>(self)->pool->FindServiceByName(
+ service_descriptor->full_name())) {
PyErr_Format(PyExc_ValueError,
"The service descriptor %s does not belong to this pool",
service_descriptor->full_name().c_str());
@@ -570,8 +570,8 @@ static PyObject* AddServiceDescriptor(PyObject* self, PyObject* descriptor) {
}
// The code below loads new Descriptors from a serialized FileDescriptorProto.
-static PyObject* AddSerializedFile(PyObject* pself, PyObject* serialized_pb) {
- PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
+static PyObject* AddSerializedFile(PyObject* pself, PyObject* serialized_pb) {
+ PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
char* message_type;
Py_ssize_t message_len;
@@ -619,7 +619,7 @@ static PyObject* AddSerializedFile(PyObject* pself, PyObject* serialized_pb) {
descriptor, serialized_pb);
}
-static PyObject* Add(PyObject* self, PyObject* file_descriptor_proto) {
+static PyObject* Add(PyObject* self, PyObject* file_descriptor_proto) {
ScopedPyObjectPtr serialized_pb(
PyObject_CallMethod(file_descriptor_proto, "SerializeToString", NULL));
if (serialized_pb == NULL) {
@@ -629,46 +629,46 @@ static PyObject* Add(PyObject* self, PyObject* file_descriptor_proto) {
}
static PyMethodDef Methods[] = {
- { "Add", Add, METH_O,
+ { "Add", Add, METH_O,
"Adds the FileDescriptorProto and its types to this pool." },
- { "AddSerializedFile", AddSerializedFile, METH_O,
+ { "AddSerializedFile", AddSerializedFile, METH_O,
"Adds a serialized FileDescriptorProto to this pool." },
// TODO(amauryfa): Understand why the Python implementation differs from
// this one, ask users to use another API and deprecate these functions.
- { "AddFileDescriptor", AddFileDescriptor, METH_O,
+ { "AddFileDescriptor", AddFileDescriptor, METH_O,
"No-op. Add() must have been called before." },
- { "AddDescriptor", AddDescriptor, METH_O,
+ { "AddDescriptor", AddDescriptor, METH_O,
"No-op. Add() must have been called before." },
- { "AddEnumDescriptor", AddEnumDescriptor, METH_O,
+ { "AddEnumDescriptor", AddEnumDescriptor, METH_O,
"No-op. Add() must have been called before." },
- { "AddExtensionDescriptor", AddExtensionDescriptor, METH_O,
+ { "AddExtensionDescriptor", AddExtensionDescriptor, METH_O,
"No-op. Add() must have been called before." },
- { "AddServiceDescriptor", AddServiceDescriptor, METH_O,
+ { "AddServiceDescriptor", AddServiceDescriptor, METH_O,
"No-op. Add() must have been called before." },
- { "FindFileByName", FindFileByName, METH_O,
+ { "FindFileByName", FindFileByName, METH_O,
"Searches for a file descriptor by its .proto name." },
- { "FindMessageTypeByName", FindMessageByName, METH_O,
+ { "FindMessageTypeByName", FindMessageByName, METH_O,
"Searches for a message descriptor by full name." },
- { "FindFieldByName", FindFieldByNameMethod, METH_O,
+ { "FindFieldByName", FindFieldByNameMethod, METH_O,
"Searches for a field descriptor by full name." },
- { "FindExtensionByName", FindExtensionByNameMethod, METH_O,
+ { "FindExtensionByName", FindExtensionByNameMethod, METH_O,
"Searches for extension descriptor by full name." },
- { "FindEnumTypeByName", FindEnumTypeByNameMethod, METH_O,
+ { "FindEnumTypeByName", FindEnumTypeByNameMethod, METH_O,
"Searches for enum type descriptor by full name." },
- { "FindOneofByName", FindOneofByNameMethod, METH_O,
+ { "FindOneofByName", FindOneofByNameMethod, METH_O,
"Searches for oneof descriptor by full name." },
- { "FindServiceByName", FindServiceByName, METH_O,
+ { "FindServiceByName", FindServiceByName, METH_O,
"Searches for service descriptor by full name." },
- { "FindMethodByName", FindMethodByName, METH_O,
+ { "FindMethodByName", FindMethodByName, METH_O,
"Searches for method descriptor by full name." },
- { "FindFileContainingSymbol", FindFileContainingSymbol, METH_O,
+ { "FindFileContainingSymbol", FindFileContainingSymbol, METH_O,
"Gets the FileDescriptor containing the specified symbol." },
- { "FindExtensionByNumber", FindExtensionByNumber, METH_VARARGS,
+ { "FindExtensionByNumber", FindExtensionByNumber, METH_VARARGS,
"Gets the extension descriptor for the given number." },
- { "FindAllExtensions", FindAllExtensions, METH_O,
+ { "FindAllExtensions", FindAllExtensions, METH_O,
"Gets all known extensions of the given message descriptor." },
{NULL}
};
@@ -676,45 +676,45 @@ static PyMethodDef Methods[] = {
} // namespace cdescriptor_pool
PyTypeObject PyDescriptorPool_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".DescriptorPool", // tp_name
- sizeof(PyDescriptorPool), // tp_basicsize
- 0, // tp_itemsize
- cdescriptor_pool::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
- "A Descriptor Pool", // tp_doc
- cdescriptor_pool::GcTraverse, // tp_traverse
- cdescriptor_pool::GcClear, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- cdescriptor_pool::Methods, // tp_methods
- 0, // tp_members
- 0, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
- 0, // tp_alloc
- cdescriptor_pool::New, // tp_new
- PyObject_GC_Del, // tp_free
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".DescriptorPool", // tp_name
+ sizeof(PyDescriptorPool), // tp_basicsize
+ 0, // tp_itemsize
+ cdescriptor_pool::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
+ "A Descriptor Pool", // tp_doc
+ cdescriptor_pool::GcTraverse, // tp_traverse
+ cdescriptor_pool::GcClear, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ cdescriptor_pool::Methods, // tp_methods
+ 0, // tp_members
+ 0, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ cdescriptor_pool::New, // tp_new
+ PyObject_GC_Del, // tp_free
};
// This is the DescriptorPool which contains all the definitions from the
@@ -728,17 +728,17 @@ bool InitDescriptorPool() {
// The Pool of messages declared in Python libraries.
// generated_pool() contains all messages already linked in C++ libraries, and
// is used as underlay.
- descriptor_pool_map =
- new std::unordered_map<const DescriptorPool*, PyDescriptorPool*>;
+ descriptor_pool_map =
+ new std::unordered_map<const DescriptorPool*, PyDescriptorPool*>;
python_generated_pool = cdescriptor_pool::PyDescriptorPool_NewWithUnderlay(
DescriptorPool::generated_pool());
if (python_generated_pool == NULL) {
- delete descriptor_pool_map;
+ delete descriptor_pool_map;
return false;
}
-
+
// Register this pool to be found for C++-generated descriptors.
- descriptor_pool_map->insert(
+ descriptor_pool_map->insert(
std::make_pair(DescriptorPool::generated_pool(),
python_generated_pool));
@@ -759,9 +759,9 @@ PyDescriptorPool* GetDescriptorPool_FromPool(const DescriptorPool* pool) {
pool == DescriptorPool::generated_pool()) {
return python_generated_pool;
}
- std::unordered_map<const DescriptorPool*, PyDescriptorPool*>::iterator it =
- descriptor_pool_map->find(pool);
- if (it == descriptor_pool_map->end()) {
+ std::unordered_map<const DescriptorPool*, PyDescriptorPool*>::iterator it =
+ descriptor_pool_map->find(pool);
+ if (it == descriptor_pool_map->end()) {
PyErr_SetString(PyExc_KeyError, "Unknown descriptor pool");
return NULL;
}
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.h b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.h
index 2d456f9088..fe8c87ced7 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.h
@@ -33,8 +33,8 @@
#include <Python.h>
-#include <unordered_map>
-#include <google/protobuf/descriptor.h>
+#include <unordered_map>
+#include <google/protobuf/descriptor.h>
namespace google {
namespace protobuf {
@@ -59,10 +59,10 @@ typedef struct PyDescriptorPool {
// The C++ pool containing Descriptors.
DescriptorPool* pool;
- // The error collector to store error info. Can be NULL. This pointer is
- // owned.
- DescriptorPool::ErrorCollector* error_collector;
-
+ // The error collector to store error info. Can be NULL. This pointer is
+ // owned.
+ DescriptorPool::ErrorCollector* error_collector;
+
// The C++ pool acting as an underlay. Can be NULL.
// This pointer is not owned and must stay alive.
const DescriptorPool* underlay;
@@ -79,7 +79,7 @@ typedef struct PyDescriptorPool {
// Cache the options for any kind of descriptor.
// Descriptor pointers are owned by the DescriptorPool above.
// Python objects are owned by the map.
- std::unordered_map<const void*, PyObject*>* descriptor_options;
+ std::unordered_map<const void*, PyObject*>* descriptor_options;
} PyDescriptorPool;
@@ -131,6 +131,6 @@ bool InitDescriptorPool();
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.cc
index 37b414c375..2fdd9b2cf2 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.cc
@@ -31,34 +31,34 @@
// Author: anuraag@google.com (Anuraag Agrawal)
// Author: tibell@google.com (Johan Tibell)
-#include <google/protobuf/pyext/extension_dict.h>
-
-#include <cstdint>
-#include <memory>
-
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/dynamic_message.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/repeated_composite_container.h>
-#include <google/protobuf/pyext/repeated_scalar_container.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/pyext/extension_dict.h>
+
+#include <cstdint>
+#include <memory>
+
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/repeated_composite_container.h>
+#include <google/protobuf/pyext/repeated_scalar_container.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#if PY_MAJOR_VERSION >= 3
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#endif
-#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
+#define PyString_AsStringAndSize(ob, charpp, sizep) \
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
namespace google {
@@ -67,103 +67,103 @@ namespace python {
namespace extension_dict {
-static Py_ssize_t len(ExtensionDict* self) {
- Py_ssize_t size = 0;
- std::vector<const FieldDescriptor*> fields;
- self->parent->message->GetReflection()->ListFields(*self->parent->message,
- &fields);
-
- for (size_t i = 0; i < fields.size(); ++i) {
- if (fields[i]->is_extension()) {
- // With C++ descriptors, the field can always be retrieved, but for
- // unknown extensions which have not been imported in Python code, there
- // is no message class and we cannot retrieve the value.
- // ListFields() has the same behavior.
- if (fields[i]->message_type() != nullptr &&
- message_factory::GetMessageClass(
- cmessage::GetFactoryForMessage(self->parent),
- fields[i]->message_type()) == nullptr) {
- PyErr_Clear();
- continue;
- }
- ++size;
- }
- }
- return size;
-}
-
-struct ExtensionIterator {
- PyObject_HEAD;
- Py_ssize_t index;
- std::vector<const FieldDescriptor*> fields;
-
- // Owned reference, to keep the FieldDescriptors alive.
- ExtensionDict* extension_dict;
-};
-
-PyObject* GetIter(PyObject* _self) {
- ExtensionDict* self = reinterpret_cast<ExtensionDict*>(_self);
-
- ScopedPyObjectPtr obj(PyType_GenericAlloc(&ExtensionIterator_Type, 0));
- if (obj == nullptr) {
- return PyErr_Format(PyExc_MemoryError,
- "Could not allocate extension iterator");
- }
-
- ExtensionIterator* iter = reinterpret_cast<ExtensionIterator*>(obj.get());
-
- // Call "placement new" to initialize. So the constructor of
- // std::vector<...> fields will be called.
- new (iter) ExtensionIterator;
-
- self->parent->message->GetReflection()->ListFields(*self->parent->message,
- &iter->fields);
- iter->index = 0;
- Py_INCREF(self);
- iter->extension_dict = self;
-
- return obj.release();
-}
-
-static void DeallocExtensionIterator(PyObject* _self) {
- ExtensionIterator* self = reinterpret_cast<ExtensionIterator*>(_self);
- self->fields.clear();
- Py_XDECREF(self->extension_dict);
- self->~ExtensionIterator();
- Py_TYPE(_self)->tp_free(_self);
+static Py_ssize_t len(ExtensionDict* self) {
+ Py_ssize_t size = 0;
+ std::vector<const FieldDescriptor*> fields;
+ self->parent->message->GetReflection()->ListFields(*self->parent->message,
+ &fields);
+
+ for (size_t i = 0; i < fields.size(); ++i) {
+ if (fields[i]->is_extension()) {
+ // With C++ descriptors, the field can always be retrieved, but for
+ // unknown extensions which have not been imported in Python code, there
+ // is no message class and we cannot retrieve the value.
+ // ListFields() has the same behavior.
+ if (fields[i]->message_type() != nullptr &&
+ message_factory::GetMessageClass(
+ cmessage::GetFactoryForMessage(self->parent),
+ fields[i]->message_type()) == nullptr) {
+ PyErr_Clear();
+ continue;
+ }
+ ++size;
+ }
+ }
+ return size;
}
+struct ExtensionIterator {
+ PyObject_HEAD;
+ Py_ssize_t index;
+ std::vector<const FieldDescriptor*> fields;
+
+ // Owned reference, to keep the FieldDescriptors alive.
+ ExtensionDict* extension_dict;
+};
+
+PyObject* GetIter(PyObject* _self) {
+ ExtensionDict* self = reinterpret_cast<ExtensionDict*>(_self);
+
+ ScopedPyObjectPtr obj(PyType_GenericAlloc(&ExtensionIterator_Type, 0));
+ if (obj == nullptr) {
+ return PyErr_Format(PyExc_MemoryError,
+ "Could not allocate extension iterator");
+ }
+
+ ExtensionIterator* iter = reinterpret_cast<ExtensionIterator*>(obj.get());
+
+ // Call "placement new" to initialize. So the constructor of
+ // std::vector<...> fields will be called.
+ new (iter) ExtensionIterator;
+
+ self->parent->message->GetReflection()->ListFields(*self->parent->message,
+ &iter->fields);
+ iter->index = 0;
+ Py_INCREF(self);
+ iter->extension_dict = self;
+
+ return obj.release();
+}
+
+static void DeallocExtensionIterator(PyObject* _self) {
+ ExtensionIterator* self = reinterpret_cast<ExtensionIterator*>(_self);
+ self->fields.clear();
+ Py_XDECREF(self->extension_dict);
+ self->~ExtensionIterator();
+ Py_TYPE(_self)->tp_free(_self);
+}
+
PyObject* subscript(ExtensionDict* self, PyObject* key) {
const FieldDescriptor* descriptor = cmessage::GetExtensionDescriptor(key);
if (descriptor == NULL) {
return NULL;
}
- if (!CheckFieldBelongsToMessage(descriptor, self->parent->message)) {
+ if (!CheckFieldBelongsToMessage(descriptor, self->parent->message)) {
return NULL;
}
if (descriptor->label() != FieldDescriptor::LABEL_REPEATED &&
descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
- return cmessage::InternalGetScalar(self->parent->message, descriptor);
+ return cmessage::InternalGetScalar(self->parent->message, descriptor);
}
- CMessage::CompositeFieldsMap::iterator iterator =
- self->parent->composite_fields->find(descriptor);
- if (iterator != self->parent->composite_fields->end()) {
- Py_INCREF(iterator->second);
- return iterator->second->AsPyObject();
+ CMessage::CompositeFieldsMap::iterator iterator =
+ self->parent->composite_fields->find(descriptor);
+ if (iterator != self->parent->composite_fields->end()) {
+ Py_INCREF(iterator->second);
+ return iterator->second->AsPyObject();
}
if (descriptor->label() != FieldDescriptor::LABEL_REPEATED &&
descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
// TODO(plabatut): consider building the class on the fly!
- ContainerBase* sub_message = cmessage::InternalGetSubMessage(
+ ContainerBase* sub_message = cmessage::InternalGetSubMessage(
self->parent, descriptor);
if (sub_message == NULL) {
return NULL;
}
- (*self->parent->composite_fields)[descriptor] = sub_message;
- return sub_message->AsPyObject();
+ (*self->parent->composite_fields)[descriptor] = sub_message;
+ return sub_message->AsPyObject();
}
if (descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
@@ -186,21 +186,21 @@ PyObject* subscript(ExtensionDict* self, PyObject* key) {
if (message_class == NULL) {
return NULL;
}
- ContainerBase* py_container = repeated_composite_container::NewContainer(
+ ContainerBase* py_container = repeated_composite_container::NewContainer(
self->parent, descriptor, message_class);
if (py_container == NULL) {
return NULL;
}
- (*self->parent->composite_fields)[descriptor] = py_container;
- return py_container->AsPyObject();
+ (*self->parent->composite_fields)[descriptor] = py_container;
+ return py_container->AsPyObject();
} else {
- ContainerBase* py_container = repeated_scalar_container::NewContainer(
+ ContainerBase* py_container = repeated_scalar_container::NewContainer(
self->parent, descriptor);
if (py_container == NULL) {
return NULL;
}
- (*self->parent->composite_fields)[descriptor] = py_container;
- return py_container->AsPyObject();
+ (*self->parent->composite_fields)[descriptor] = py_container;
+ return py_container->AsPyObject();
}
}
PyErr_SetString(PyExc_ValueError, "control reached unexpected line");
@@ -212,23 +212,23 @@ int ass_subscript(ExtensionDict* self, PyObject* key, PyObject* value) {
if (descriptor == NULL) {
return -1;
}
- if (!CheckFieldBelongsToMessage(descriptor, self->parent->message)) {
+ if (!CheckFieldBelongsToMessage(descriptor, self->parent->message)) {
return -1;
}
- if (value == nullptr) {
- return cmessage::ClearFieldByDescriptor(self->parent, descriptor);
- }
-
+ if (value == nullptr) {
+ return cmessage::ClearFieldByDescriptor(self->parent, descriptor);
+ }
+
if (descriptor->label() != FieldDescriptor::LABEL_OPTIONAL ||
descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
PyErr_SetString(PyExc_TypeError, "Extension is repeated and/or composite "
"type");
return -1;
}
- cmessage::AssureWritable(self->parent);
- if (cmessage::InternalSetScalar(self->parent, descriptor, value) < 0) {
- return -1;
+ cmessage::AssureWritable(self->parent);
+ if (cmessage::InternalSetScalar(self->parent, descriptor, value) < 0) {
+ return -1;
}
return 0;
}
@@ -242,11 +242,11 @@ PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* arg) {
PyDescriptorPool* pool = cmessage::GetFactoryForMessage(self->parent)->pool;
const FieldDescriptor* message_extension =
- pool->pool->FindExtensionByName(StringParam(name, name_size));
+ pool->pool->FindExtensionByName(StringParam(name, name_size));
if (message_extension == NULL) {
// Is is the name of a message set extension?
- const Descriptor* message_descriptor =
- pool->pool->FindMessageTypeByName(StringParam(name, name_size));
+ const Descriptor* message_descriptor =
+ pool->pool->FindMessageTypeByName(StringParam(name, name_size));
if (message_descriptor && message_descriptor->extension_count() > 0) {
const FieldDescriptor* extension = message_descriptor->extension(0);
if (extension->is_extension() &&
@@ -265,7 +265,7 @@ PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* arg) {
}
PyObject* _FindExtensionByNumber(ExtensionDict* self, PyObject* arg) {
- int64_t number = PyLong_AsLong(arg);
+ int64_t number = PyLong_AsLong(arg);
if (number == -1 && PyErr_Occurred()) {
return NULL;
}
@@ -280,35 +280,35 @@ PyObject* _FindExtensionByNumber(ExtensionDict* self, PyObject* arg) {
return PyFieldDescriptor_FromDescriptor(message_extension);
}
-static int Contains(PyObject* _self, PyObject* key) {
- ExtensionDict* self = reinterpret_cast<ExtensionDict*>(_self);
- const FieldDescriptor* field_descriptor =
- cmessage::GetExtensionDescriptor(key);
- if (field_descriptor == nullptr) {
- return -1;
- }
-
- if (!field_descriptor->is_extension()) {
- PyErr_Format(PyExc_KeyError, "%s is not an extension",
- field_descriptor->full_name().c_str());
- return -1;
- }
-
- const Message* message = self->parent->message;
- const Reflection* reflection = message->GetReflection();
- if (field_descriptor->is_repeated()) {
- if (reflection->FieldSize(*message, field_descriptor) > 0) {
- return 1;
- }
- } else {
- if (reflection->HasField(*message, field_descriptor)) {
- return 1;
- }
- }
-
- return 0;
-}
-
+static int Contains(PyObject* _self, PyObject* key) {
+ ExtensionDict* self = reinterpret_cast<ExtensionDict*>(_self);
+ const FieldDescriptor* field_descriptor =
+ cmessage::GetExtensionDescriptor(key);
+ if (field_descriptor == nullptr) {
+ return -1;
+ }
+
+ if (!field_descriptor->is_extension()) {
+ PyErr_Format(PyExc_KeyError, "%s is not an extension",
+ field_descriptor->full_name().c_str());
+ return -1;
+ }
+
+ const Message* message = self->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ if (field_descriptor->is_repeated()) {
+ if (reflection->FieldSize(*message, field_descriptor) > 0) {
+ return 1;
+ }
+ } else {
+ if (reflection->HasField(*message, field_descriptor)) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
ExtensionDict* NewExtensionDict(CMessage *parent) {
ExtensionDict* self = reinterpret_cast<ExtensionDict*>(
PyType_GenericAlloc(&ExtensionDict_Type, 0));
@@ -316,165 +316,165 @@ ExtensionDict* NewExtensionDict(CMessage *parent) {
return NULL;
}
- Py_INCREF(parent);
- self->parent = parent;
+ Py_INCREF(parent);
+ self->parent = parent;
return self;
}
-void dealloc(PyObject* pself) {
- ExtensionDict* self = reinterpret_cast<ExtensionDict*>(pself);
- Py_CLEAR(self->parent);
+void dealloc(PyObject* pself) {
+ ExtensionDict* self = reinterpret_cast<ExtensionDict*>(pself);
+ Py_CLEAR(self->parent);
Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self));
}
-static PyObject* RichCompare(ExtensionDict* self, PyObject* other, int opid) {
- // Only equality comparisons are implemented.
- if (opid != Py_EQ && opid != Py_NE) {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
- }
- bool equals = false;
- if (PyObject_TypeCheck(other, &ExtensionDict_Type)) {
- equals = self->parent == reinterpret_cast<ExtensionDict*>(other)->parent;;
- }
- if (equals ^ (opid == Py_EQ)) {
- Py_RETURN_FALSE;
- } else {
- Py_RETURN_TRUE;
- }
-}
-static PySequenceMethods SeqMethods = {
- (lenfunc)len, // sq_length
- 0, // sq_concat
- 0, // sq_repeat
- 0, // sq_item
- 0, // sq_slice
- 0, // sq_ass_item
- 0, // sq_ass_slice
- (objobjproc)Contains, // sq_contains
-};
-
+static PyObject* RichCompare(ExtensionDict* self, PyObject* other, int opid) {
+ // Only equality comparisons are implemented.
+ if (opid != Py_EQ && opid != Py_NE) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+ bool equals = false;
+ if (PyObject_TypeCheck(other, &ExtensionDict_Type)) {
+ equals = self->parent == reinterpret_cast<ExtensionDict*>(other)->parent;;
+ }
+ if (equals ^ (opid == Py_EQ)) {
+ Py_RETURN_FALSE;
+ } else {
+ Py_RETURN_TRUE;
+ }
+}
+static PySequenceMethods SeqMethods = {
+ (lenfunc)len, // sq_length
+ 0, // sq_concat
+ 0, // sq_repeat
+ 0, // sq_item
+ 0, // sq_slice
+ 0, // sq_ass_item
+ 0, // sq_ass_slice
+ (objobjproc)Contains, // sq_contains
+};
+
static PyMappingMethods MpMethods = {
- (lenfunc)len, /* mp_length */
- (binaryfunc)subscript, /* mp_subscript */
+ (lenfunc)len, /* mp_length */
+ (binaryfunc)subscript, /* mp_subscript */
(objobjargproc)ass_subscript,/* mp_ass_subscript */
};
#define EDMETHOD(name, args, doc) { #name, (PyCFunction)name, args, doc }
static PyMethodDef Methods[] = {
- EDMETHOD(_FindExtensionByName, METH_O, "Finds an extension by name."),
- EDMETHOD(_FindExtensionByNumber, METH_O,
- "Finds an extension by field number."),
- {NULL, NULL},
+ EDMETHOD(_FindExtensionByName, METH_O, "Finds an extension by name."),
+ EDMETHOD(_FindExtensionByNumber, METH_O,
+ "Finds an extension by field number."),
+ {NULL, NULL},
};
} // namespace extension_dict
PyTypeObject ExtensionDict_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) //
- FULL_MODULE_NAME ".ExtensionDict", // tp_name
- sizeof(ExtensionDict), // tp_basicsize
- 0, // tp_itemsize
- (destructor)extension_dict::dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- &extension_dict::SeqMethods, // tp_as_sequence
- &extension_dict::MpMethods, // tp_as_mapping
- PyObject_HashNotImplemented, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "An extension dict", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- (richcmpfunc)extension_dict::RichCompare, // tp_richcompare
- 0, // tp_weaklistoffset
- extension_dict::GetIter, // tp_iter
- 0, // tp_iternext
- extension_dict::Methods, // tp_methods
- 0, // tp_members
- 0, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) //
+ FULL_MODULE_NAME ".ExtensionDict", // tp_name
+ sizeof(ExtensionDict), // tp_basicsize
+ 0, // tp_itemsize
+ (destructor)extension_dict::dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ &extension_dict::SeqMethods, // tp_as_sequence
+ &extension_dict::MpMethods, // tp_as_mapping
+ PyObject_HashNotImplemented, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "An extension dict", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ (richcmpfunc)extension_dict::RichCompare, // tp_richcompare
+ 0, // tp_weaklistoffset
+ extension_dict::GetIter, // tp_iter
+ 0, // tp_iternext
+ extension_dict::Methods, // tp_methods
+ 0, // tp_members
+ 0, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
};
-PyObject* IterNext(PyObject* _self) {
- extension_dict::ExtensionIterator* self =
- reinterpret_cast<extension_dict::ExtensionIterator*>(_self);
- Py_ssize_t total_size = self->fields.size();
- Py_ssize_t index = self->index;
- while (self->index < total_size) {
- index = self->index;
- ++self->index;
- if (self->fields[index]->is_extension()) {
- // With C++ descriptors, the field can always be retrieved, but for
- // unknown extensions which have not been imported in Python code, there
- // is no message class and we cannot retrieve the value.
- // ListFields() has the same behavior.
- if (self->fields[index]->message_type() != nullptr &&
- message_factory::GetMessageClass(
- cmessage::GetFactoryForMessage(self->extension_dict->parent),
- self->fields[index]->message_type()) == nullptr) {
- PyErr_Clear();
- continue;
- }
-
- return PyFieldDescriptor_FromDescriptor(self->fields[index]);
- }
- }
-
- return nullptr;
-}
-
-PyTypeObject ExtensionIterator_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) //
- FULL_MODULE_NAME ".ExtensionIterator", // tp_name
- sizeof(extension_dict::ExtensionIterator), // tp_basicsize
- 0, // tp_itemsize
- extension_dict::DeallocExtensionIterator, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "A scalar map iterator", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- PyObject_SelfIter, // tp_iter
- IterNext, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- 0, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
-};
+PyObject* IterNext(PyObject* _self) {
+ extension_dict::ExtensionIterator* self =
+ reinterpret_cast<extension_dict::ExtensionIterator*>(_self);
+ Py_ssize_t total_size = self->fields.size();
+ Py_ssize_t index = self->index;
+ while (self->index < total_size) {
+ index = self->index;
+ ++self->index;
+ if (self->fields[index]->is_extension()) {
+ // With C++ descriptors, the field can always be retrieved, but for
+ // unknown extensions which have not been imported in Python code, there
+ // is no message class and we cannot retrieve the value.
+ // ListFields() has the same behavior.
+ if (self->fields[index]->message_type() != nullptr &&
+ message_factory::GetMessageClass(
+ cmessage::GetFactoryForMessage(self->extension_dict->parent),
+ self->fields[index]->message_type()) == nullptr) {
+ PyErr_Clear();
+ continue;
+ }
+
+ return PyFieldDescriptor_FromDescriptor(self->fields[index]);
+ }
+ }
+
+ return nullptr;
+}
+
+PyTypeObject ExtensionIterator_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) //
+ FULL_MODULE_NAME ".ExtensionIterator", // tp_name
+ sizeof(extension_dict::ExtensionIterator), // tp_basicsize
+ 0, // tp_itemsize
+ extension_dict::DeallocExtensionIterator, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "A scalar map iterator", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ PyObject_SelfIter, // tp_iter
+ IterNext, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ 0, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+};
} // namespace python
} // namespace protobuf
} // namespace google
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.h b/contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.h
index c9da443161..52f11729f5 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.h
@@ -38,8 +38,8 @@
#include <memory>
-#include <google/protobuf/pyext/message.h>
-
+#include <google/protobuf/pyext/message.h>
+
namespace google {
namespace protobuf {
@@ -51,12 +51,12 @@ namespace python {
typedef struct ExtensionDict {
PyObject_HEAD;
- // Strong, owned reference to the parent message. Never NULL.
+ // Strong, owned reference to the parent message. Never NULL.
CMessage* parent;
} ExtensionDict;
extern PyTypeObject ExtensionDict_Type;
-extern PyTypeObject ExtensionIterator_Type;
+extern PyTypeObject ExtensionIterator_Type;
namespace extension_dict {
@@ -66,6 +66,6 @@ ExtensionDict* NewExtensionDict(CMessage *parent);
} // namespace extension_dict
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/field.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/field.cc
index 1afd4583b3..e3328998e6 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/field.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/field.cc
@@ -1,142 +1,142 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <google/protobuf/pyext/field.h>
-
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/message.h>
-
-#if PY_MAJOR_VERSION >= 3
- #define PyString_FromFormat PyUnicode_FromFormat
-#endif
-
-namespace google {
-namespace protobuf {
-namespace python {
-
-namespace field {
-
-static PyObject* Repr(PyMessageFieldProperty* self) {
- return PyString_FromFormat("<field property '%s'>",
- self->field_descriptor->full_name().c_str());
-}
-
-static PyObject* DescrGet(PyMessageFieldProperty* self, PyObject* obj,
- PyObject* type) {
- if (obj == NULL) {
- Py_INCREF(self);
- return reinterpret_cast<PyObject*>(self);
- }
- return cmessage::GetFieldValue(reinterpret_cast<CMessage*>(obj),
- self->field_descriptor);
-}
-
-static int DescrSet(PyMessageFieldProperty* self, PyObject* obj,
- PyObject* value) {
- if (value == NULL) {
- PyErr_SetString(PyExc_AttributeError, "Cannot delete field attribute");
- return -1;
- }
- return cmessage::SetFieldValue(reinterpret_cast<CMessage*>(obj),
- self->field_descriptor, value);
-}
-
-static PyObject* GetDescriptor(PyMessageFieldProperty* self, void* closure) {
- return PyFieldDescriptor_FromDescriptor(self->field_descriptor);
-}
-
-static PyObject* GetDoc(PyMessageFieldProperty* self, void* closure) {
- return PyString_FromFormat("Field %s",
- self->field_descriptor->full_name().c_str());
-}
-
-static PyGetSetDef Getters[] = {
- {"DESCRIPTOR", (getter)GetDescriptor, NULL, "Field descriptor"},
- {"__doc__", (getter)GetDoc, NULL, NULL},
- {NULL}};
-} // namespace field
-
-static PyTypeObject _CFieldProperty_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) // head
- FULL_MODULE_NAME ".FieldProperty", // tp_name
- sizeof(PyMessageFieldProperty), // tp_basicsize
- 0, // tp_itemsize
- 0, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- (reprfunc)field::Repr, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "Field property of a Message", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- field::Getters, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- (descrgetfunc)field::DescrGet, // tp_descr_get
- (descrsetfunc)field::DescrSet, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
- 0, // tp_alloc
- 0, // tp_new
-};
-PyTypeObject* CFieldProperty_Type = &_CFieldProperty_Type;
-
-PyObject* NewFieldProperty(const FieldDescriptor* field_descriptor) {
- // Create a new descriptor object
- PyMessageFieldProperty* property =
- PyObject_New(PyMessageFieldProperty, CFieldProperty_Type);
- if (property == NULL) {
- return NULL;
- }
- property->field_descriptor = field_descriptor;
- return reinterpret_cast<PyObject*>(property);
-}
-
-} // namespace python
-} // namespace protobuf
-} // namespace google
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <google/protobuf/pyext/field.h>
+
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/message.h>
+
+#if PY_MAJOR_VERSION >= 3
+ #define PyString_FromFormat PyUnicode_FromFormat
+#endif
+
+namespace google {
+namespace protobuf {
+namespace python {
+
+namespace field {
+
+static PyObject* Repr(PyMessageFieldProperty* self) {
+ return PyString_FromFormat("<field property '%s'>",
+ self->field_descriptor->full_name().c_str());
+}
+
+static PyObject* DescrGet(PyMessageFieldProperty* self, PyObject* obj,
+ PyObject* type) {
+ if (obj == NULL) {
+ Py_INCREF(self);
+ return reinterpret_cast<PyObject*>(self);
+ }
+ return cmessage::GetFieldValue(reinterpret_cast<CMessage*>(obj),
+ self->field_descriptor);
+}
+
+static int DescrSet(PyMessageFieldProperty* self, PyObject* obj,
+ PyObject* value) {
+ if (value == NULL) {
+ PyErr_SetString(PyExc_AttributeError, "Cannot delete field attribute");
+ return -1;
+ }
+ return cmessage::SetFieldValue(reinterpret_cast<CMessage*>(obj),
+ self->field_descriptor, value);
+}
+
+static PyObject* GetDescriptor(PyMessageFieldProperty* self, void* closure) {
+ return PyFieldDescriptor_FromDescriptor(self->field_descriptor);
+}
+
+static PyObject* GetDoc(PyMessageFieldProperty* self, void* closure) {
+ return PyString_FromFormat("Field %s",
+ self->field_descriptor->full_name().c_str());
+}
+
+static PyGetSetDef Getters[] = {
+ {"DESCRIPTOR", (getter)GetDescriptor, NULL, "Field descriptor"},
+ {"__doc__", (getter)GetDoc, NULL, NULL},
+ {NULL}};
+} // namespace field
+
+static PyTypeObject _CFieldProperty_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) // head
+ FULL_MODULE_NAME ".FieldProperty", // tp_name
+ sizeof(PyMessageFieldProperty), // tp_basicsize
+ 0, // tp_itemsize
+ 0, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ (reprfunc)field::Repr, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "Field property of a Message", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ field::Getters, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ (descrgetfunc)field::DescrGet, // tp_descr_get
+ (descrsetfunc)field::DescrSet, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ 0, // tp_new
+};
+PyTypeObject* CFieldProperty_Type = &_CFieldProperty_Type;
+
+PyObject* NewFieldProperty(const FieldDescriptor* field_descriptor) {
+ // Create a new descriptor object
+ PyMessageFieldProperty* property =
+ PyObject_New(PyMessageFieldProperty, CFieldProperty_Type);
+ if (property == NULL) {
+ return NULL;
+ }
+ property->field_descriptor = field_descriptor;
+ return reinterpret_cast<PyObject*>(property);
+}
+
+} // namespace python
+} // namespace protobuf
+} // namespace google
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/field.h b/contrib/python/protobuf/py3/google/protobuf/pyext/field.h
index 7b4660cab5..349e1a9615 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/field.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/field.h
@@ -1,59 +1,59 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
-#define GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
-
-#include <Python.h>
-
-namespace google {
-namespace protobuf {
-
-class FieldDescriptor;
-
-namespace python {
-
-// A data descriptor that represents a field in a Message class.
-struct PyMessageFieldProperty {
- PyObject_HEAD;
-
- // This pointer is owned by the same pool as the Message class it belongs to.
- const FieldDescriptor* field_descriptor;
-};
-
-extern PyTypeObject* CFieldProperty_Type;
-
-PyObject* NewFieldProperty(const FieldDescriptor* field_descriptor);
-
-} // namespace python
-} // namespace protobuf
-} // namespace google
-
-#endif // GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
+#define GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
+
+#include <Python.h>
+
+namespace google {
+namespace protobuf {
+
+class FieldDescriptor;
+
+namespace python {
+
+// A data descriptor that represents a field in a Message class.
+struct PyMessageFieldProperty {
+ PyObject_HEAD;
+
+ // This pointer is owned by the same pool as the Message class it belongs to.
+ const FieldDescriptor* field_descriptor;
+};
+
+extern PyTypeObject* CFieldProperty_Type;
+
+PyObject* NewFieldProperty(const FieldDescriptor* field_descriptor);
+
+} // namespace python
+} // namespace protobuf
+} // namespace google
+
+#endif // GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/map_container.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/map_container.cc
index e7a9cca23b..11da49cb3b 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/map_container.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/map_container.cc
@@ -30,21 +30,21 @@
// Author: haberman@google.com (Josh Haberman)
-#include <google/protobuf/pyext/map_container.h>
+#include <google/protobuf/pyext/map_container.h>
-#include <cstdint>
+#include <cstdint>
#include <memory>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/map.h>
-#include <google/protobuf/map_field.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/repeated_composite_container.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/stubs/map_util.h>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/map.h>
+#include <google/protobuf/map_field.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/repeated_composite_container.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/stubs/map_util.h>
#if PY_MAJOR_VERSION >= 3
#define PyInt_FromLong PyLong_FromLong
@@ -64,52 +64,52 @@ class MapReflectionFriend {
static Py_ssize_t Length(PyObject* _self);
static PyObject* GetIterator(PyObject *_self);
static PyObject* IterNext(PyObject* _self);
- static PyObject* MergeFrom(PyObject* _self, PyObject* arg);
+ static PyObject* MergeFrom(PyObject* _self, PyObject* arg);
// Methods that differ between the map types.
static PyObject* ScalarMapGetItem(PyObject* _self, PyObject* key);
static PyObject* MessageMapGetItem(PyObject* _self, PyObject* key);
static int ScalarMapSetItem(PyObject* _self, PyObject* key, PyObject* v);
static int MessageMapSetItem(PyObject* _self, PyObject* key, PyObject* v);
- static PyObject* ScalarMapToStr(PyObject* _self);
- static PyObject* MessageMapToStr(PyObject* _self);
+ static PyObject* ScalarMapToStr(PyObject* _self);
+ static PyObject* MessageMapToStr(PyObject* _self);
};
struct MapIterator {
PyObject_HEAD;
- std::unique_ptr<::google::protobuf::MapIterator> iter;
+ std::unique_ptr<::google::protobuf::MapIterator> iter;
// A pointer back to the container, so we can notice changes to the version.
// We own a ref on this.
MapContainer* container;
- // We need to keep a ref on the parent Message too, because
+ // We need to keep a ref on the parent Message too, because
// MapIterator::~MapIterator() accesses it. Normally this would be ok because
// the ref on container (above) would guarantee outlive semantics. However in
- // the case of ClearField(), the MapContainer points to a different message,
- // a copy of the original. But our iterator still points to the original,
- // which could now get deleted before us.
+ // the case of ClearField(), the MapContainer points to a different message,
+ // a copy of the original. But our iterator still points to the original,
+ // which could now get deleted before us.
//
// To prevent this, we ensure that the Message will always stay alive as long
// as this iterator does. This is solely for the benefit of the MapIterator
// destructor -- we should never actually access the iterator in this state
// except to delete it.
- CMessage* parent;
+ CMessage* parent;
// The version of the map when we took the iterator to it.
//
// We store this so that if the map is modified during iteration we can throw
// an error.
- uint64_t version;
+ uint64_t version;
};
Message* MapContainer::GetMutableMessage() {
cmessage::AssureWritable(parent);
- return parent->message;
+ return parent->message;
}
// Consumes a reference on the Python string object.
-static bool PyStringToSTL(PyObject* py_string, TProtoStringType* stl_string) {
+static bool PyStringToSTL(PyObject* py_string, TProtoStringType* stl_string) {
char *value;
Py_ssize_t value_len;
@@ -126,9 +126,9 @@ static bool PyStringToSTL(PyObject* py_string, TProtoStringType* stl_string) {
}
}
-static bool PythonToMapKey(MapContainer* self, PyObject* obj, MapKey* key) {
- const FieldDescriptor* field_descriptor =
- self->parent_field_descriptor->message_type()->map_key();
+static bool PythonToMapKey(MapContainer* self, PyObject* obj, MapKey* key) {
+ const FieldDescriptor* field_descriptor =
+ self->parent_field_descriptor->message_type()->map_key();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
GOOGLE_CHECK_GET_INT32(obj, value, false);
@@ -156,7 +156,7 @@ static bool PythonToMapKey(MapContainer* self, PyObject* obj, MapKey* key) {
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- TProtoStringType str;
+ TProtoStringType str;
if (!PyStringToSTL(CheckString(obj, field_descriptor), &str)) {
return false;
}
@@ -172,9 +172,9 @@ static bool PythonToMapKey(MapContainer* self, PyObject* obj, MapKey* key) {
return true;
}
-static PyObject* MapKeyToPython(MapContainer* self, const MapKey& key) {
- const FieldDescriptor* field_descriptor =
- self->parent_field_descriptor->message_type()->map_key();
+static PyObject* MapKeyToPython(MapContainer* self, const MapKey& key) {
+ const FieldDescriptor* field_descriptor =
+ self->parent_field_descriptor->message_type()->map_key();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
return PyInt_FromLong(key.GetInt32Value());
@@ -198,28 +198,28 @@ static PyObject* MapKeyToPython(MapContainer* self, const MapKey& key) {
// This is only used for ScalarMap, so we don't need to handle the
// CPPTYPE_MESSAGE case.
-PyObject* MapValueRefToPython(MapContainer* self, const MapValueRef& value) {
- const FieldDescriptor* field_descriptor =
- self->parent_field_descriptor->message_type()->map_value();
+PyObject* MapValueRefToPython(MapContainer* self, const MapValueRef& value) {
+ const FieldDescriptor* field_descriptor =
+ self->parent_field_descriptor->message_type()->map_value();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
- return PyInt_FromLong(value.GetInt32Value());
+ return PyInt_FromLong(value.GetInt32Value());
case FieldDescriptor::CPPTYPE_INT64:
- return PyLong_FromLongLong(value.GetInt64Value());
+ return PyLong_FromLongLong(value.GetInt64Value());
case FieldDescriptor::CPPTYPE_UINT32:
- return PyInt_FromSize_t(value.GetUInt32Value());
+ return PyInt_FromSize_t(value.GetUInt32Value());
case FieldDescriptor::CPPTYPE_UINT64:
- return PyLong_FromUnsignedLongLong(value.GetUInt64Value());
+ return PyLong_FromUnsignedLongLong(value.GetUInt64Value());
case FieldDescriptor::CPPTYPE_FLOAT:
- return PyFloat_FromDouble(value.GetFloatValue());
+ return PyFloat_FromDouble(value.GetFloatValue());
case FieldDescriptor::CPPTYPE_DOUBLE:
- return PyFloat_FromDouble(value.GetDoubleValue());
+ return PyFloat_FromDouble(value.GetDoubleValue());
case FieldDescriptor::CPPTYPE_BOOL:
- return PyBool_FromLong(value.GetBoolValue());
+ return PyBool_FromLong(value.GetBoolValue());
case FieldDescriptor::CPPTYPE_STRING:
- return ToStringObject(field_descriptor, value.GetStringValue());
+ return ToStringObject(field_descriptor, value.GetStringValue());
case FieldDescriptor::CPPTYPE_ENUM:
- return PyInt_FromLong(value.GetEnumValue());
+ return PyInt_FromLong(value.GetEnumValue());
default:
PyErr_Format(
PyExc_SystemError, "Couldn't convert type %d to value",
@@ -230,11 +230,11 @@ PyObject* MapValueRefToPython(MapContainer* self, const MapValueRef& value) {
// This is only used for ScalarMap, so we don't need to handle the
// CPPTYPE_MESSAGE case.
-static bool PythonToMapValueRef(MapContainer* self, PyObject* obj,
+static bool PythonToMapValueRef(MapContainer* self, PyObject* obj,
bool allow_unknown_enum_values,
MapValueRef* value_ref) {
- const FieldDescriptor* field_descriptor =
- self->parent_field_descriptor->message_type()->map_value();
+ const FieldDescriptor* field_descriptor =
+ self->parent_field_descriptor->message_type()->map_value();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
GOOGLE_CHECK_GET_INT32(obj, value, false);
@@ -272,7 +272,7 @@ static bool PythonToMapValueRef(MapContainer* self, PyObject* obj,
return true;;
}
case FieldDescriptor::CPPTYPE_STRING: {
- TProtoStringType str;
+ TProtoStringType str;
if (!PyStringToSTL(CheckString(obj, field_descriptor), &str)) {
return false;
}
@@ -314,7 +314,7 @@ static MapContainer* GetMap(PyObject* obj) {
Py_ssize_t MapReflectionFriend::Length(PyObject* _self) {
MapContainer* self = GetMap(_self);
- const google::protobuf::Message* message = self->parent->message;
+ const google::protobuf::Message* message = self->parent->message;
return message->GetReflection()->MapSize(*message,
self->parent_field_descriptor);
}
@@ -338,35 +338,35 @@ PyObject* GetEntryClass(PyObject* _self) {
return reinterpret_cast<PyObject*>(message_class);
}
-PyObject* MapReflectionFriend::MergeFrom(PyObject* _self, PyObject* arg) {
- MapContainer* self = GetMap(_self);
- if (!PyObject_TypeCheck(arg, ScalarMapContainer_Type) &&
- !PyObject_TypeCheck(arg, MessageMapContainer_Type)) {
- PyErr_SetString(PyExc_AttributeError, "Not a map field");
- return nullptr;
- }
- MapContainer* other_map = GetMap(arg);
- Message* message = self->GetMutableMessage();
- const Message* other_message = other_map->parent->message;
- const Reflection* reflection = message->GetReflection();
- const Reflection* other_reflection = other_message->GetReflection();
- internal::MapFieldBase* field = reflection->MutableMapData(
- message, self->parent_field_descriptor);
- const internal::MapFieldBase* other_field = other_reflection->GetMapData(
- *other_message, other_map->parent_field_descriptor);
- field->MergeFrom(*other_field);
- self->version++;
- Py_RETURN_NONE;
-}
-
+PyObject* MapReflectionFriend::MergeFrom(PyObject* _self, PyObject* arg) {
+ MapContainer* self = GetMap(_self);
+ if (!PyObject_TypeCheck(arg, ScalarMapContainer_Type) &&
+ !PyObject_TypeCheck(arg, MessageMapContainer_Type)) {
+ PyErr_SetString(PyExc_AttributeError, "Not a map field");
+ return nullptr;
+ }
+ MapContainer* other_map = GetMap(arg);
+ Message* message = self->GetMutableMessage();
+ const Message* other_message = other_map->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ const Reflection* other_reflection = other_message->GetReflection();
+ internal::MapFieldBase* field = reflection->MutableMapData(
+ message, self->parent_field_descriptor);
+ const internal::MapFieldBase* other_field = other_reflection->GetMapData(
+ *other_message, other_map->parent_field_descriptor);
+ field->MergeFrom(*other_field);
+ self->version++;
+ Py_RETURN_NONE;
+}
+
PyObject* MapReflectionFriend::Contains(PyObject* _self, PyObject* key) {
MapContainer* self = GetMap(_self);
- const Message* message = self->parent->message;
+ const Message* message = self->parent->message;
const Reflection* reflection = message->GetReflection();
MapKey map_key;
- if (!PythonToMapKey(self, key, &map_key)) {
+ if (!PythonToMapKey(self, key, &map_key)) {
return NULL;
}
@@ -380,27 +380,27 @@ PyObject* MapReflectionFriend::Contains(PyObject* _self, PyObject* key) {
// ScalarMap ///////////////////////////////////////////////////////////////////
-MapContainer* NewScalarMapContainer(
+MapContainer* NewScalarMapContainer(
CMessage* parent, const google::protobuf::FieldDescriptor* parent_field_descriptor) {
if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
return NULL;
}
- PyObject* obj(PyType_GenericAlloc(ScalarMapContainer_Type, 0));
- if (obj == NULL) {
- PyErr_Format(PyExc_RuntimeError,
- "Could not allocate new container.");
- return NULL;
+ PyObject* obj(PyType_GenericAlloc(ScalarMapContainer_Type, 0));
+ if (obj == NULL) {
+ PyErr_Format(PyExc_RuntimeError,
+ "Could not allocate new container.");
+ return NULL;
}
- MapContainer* self = GetMap(obj);
+ MapContainer* self = GetMap(obj);
- Py_INCREF(parent);
+ Py_INCREF(parent);
self->parent = parent;
self->parent_field_descriptor = parent_field_descriptor;
self->version = 0;
- return self;
+ return self;
}
PyObject* MapReflectionFriend::ScalarMapGetItem(PyObject* _self,
@@ -412,7 +412,7 @@ PyObject* MapReflectionFriend::ScalarMapGetItem(PyObject* _self,
MapKey map_key;
MapValueRef value;
- if (!PythonToMapKey(self, key, &map_key)) {
+ if (!PythonToMapKey(self, key, &map_key)) {
return NULL;
}
@@ -421,7 +421,7 @@ PyObject* MapReflectionFriend::ScalarMapGetItem(PyObject* _self,
self->version++;
}
- return MapValueRefToPython(self, value);
+ return MapValueRefToPython(self, value);
}
int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,
@@ -433,7 +433,7 @@ int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,
MapKey map_key;
MapValueRef value;
- if (!PythonToMapKey(self, key, &map_key)) {
+ if (!PythonToMapKey(self, key, &map_key)) {
return -1;
}
@@ -444,11 +444,11 @@ int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,
reflection->InsertOrLookupMapValue(message, self->parent_field_descriptor,
map_key, &value);
- if (!PythonToMapValueRef(self, v, reflection->SupportsUnknownEnumValues(),
- &value)) {
- return -1;
- }
- return 0;
+ if (!PythonToMapValueRef(self, v, reflection->SupportsUnknownEnumValues(),
+ &value)) {
+ return -1;
+ }
+ return 0;
} else {
// Delete key from map.
if (reflection->DeleteMapValue(message, self->parent_field_descriptor,
@@ -461,14 +461,14 @@ int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,
}
}
-static PyObject* ScalarMapGet(PyObject* self, PyObject* args,
- PyObject* kwargs) {
- static const char* kwlist[] = {"key", "default", nullptr};
+static PyObject* ScalarMapGet(PyObject* self, PyObject* args,
+ PyObject* kwargs) {
+ static const char* kwlist[] = {"key", "default", nullptr};
PyObject* key;
PyObject* default_value = NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
- const_cast<char**>(kwlist), &key,
- &default_value)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
+ const_cast<char**>(kwlist), &key,
+ &default_value)) {
return NULL;
}
@@ -489,65 +489,65 @@ static PyObject* ScalarMapGet(PyObject* self, PyObject* args,
}
}
-PyObject* MapReflectionFriend::ScalarMapToStr(PyObject* _self) {
- ScopedPyObjectPtr dict(PyDict_New());
- if (dict == NULL) {
- return NULL;
- }
- ScopedPyObjectPtr key;
- ScopedPyObjectPtr value;
-
- MapContainer* self = GetMap(_self);
- Message* message = self->GetMutableMessage();
- const Reflection* reflection = message->GetReflection();
- for (google::protobuf::MapIterator it = reflection->MapBegin(
- message, self->parent_field_descriptor);
- it != reflection->MapEnd(message, self->parent_field_descriptor);
- ++it) {
- key.reset(MapKeyToPython(self, it.GetKey()));
- if (key == NULL) {
- return NULL;
- }
- value.reset(MapValueRefToPython(self, it.GetValueRef()));
- if (value == NULL) {
- return NULL;
- }
- if (PyDict_SetItem(dict.get(), key.get(), value.get()) < 0) {
- return NULL;
- }
- }
- return PyObject_Repr(dict.get());
-}
-
+PyObject* MapReflectionFriend::ScalarMapToStr(PyObject* _self) {
+ ScopedPyObjectPtr dict(PyDict_New());
+ if (dict == NULL) {
+ return NULL;
+ }
+ ScopedPyObjectPtr key;
+ ScopedPyObjectPtr value;
+
+ MapContainer* self = GetMap(_self);
+ Message* message = self->GetMutableMessage();
+ const Reflection* reflection = message->GetReflection();
+ for (google::protobuf::MapIterator it = reflection->MapBegin(
+ message, self->parent_field_descriptor);
+ it != reflection->MapEnd(message, self->parent_field_descriptor);
+ ++it) {
+ key.reset(MapKeyToPython(self, it.GetKey()));
+ if (key == NULL) {
+ return NULL;
+ }
+ value.reset(MapValueRefToPython(self, it.GetValueRef()));
+ if (value == NULL) {
+ return NULL;
+ }
+ if (PyDict_SetItem(dict.get(), key.get(), value.get()) < 0) {
+ return NULL;
+ }
+ }
+ return PyObject_Repr(dict.get());
+}
+
static void ScalarMapDealloc(PyObject* _self) {
MapContainer* self = GetMap(_self);
- self->RemoveFromParentCache();
- PyTypeObject *type = Py_TYPE(_self);
- type->tp_free(_self);
- if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
- // With Python3, the Map class is not static, and must be managed.
- Py_DECREF(type);
- }
+ self->RemoveFromParentCache();
+ PyTypeObject *type = Py_TYPE(_self);
+ type->tp_free(_self);
+ if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
+ // With Python3, the Map class is not static, and must be managed.
+ Py_DECREF(type);
+ }
}
static PyMethodDef ScalarMapMethods[] = {
- {"__contains__", MapReflectionFriend::Contains, METH_O,
- "Tests whether a key is a member of the map."},
- {"clear", (PyCFunction)Clear, METH_NOARGS,
- "Removes all elements from the map."},
- {"get", (PyCFunction)ScalarMapGet, METH_VARARGS | METH_KEYWORDS,
- "Gets the value for the given key if present, or otherwise a default"},
- {"GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS,
- "Return the class used to build Entries of (key, value) pairs."},
- {"MergeFrom", (PyCFunction)MapReflectionFriend::MergeFrom, METH_O,
- "Merges a map into the current map."},
- /*
- { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
- "Makes a deep copy of the class." },
- { "__reduce__", (PyCFunction)Reduce, METH_NOARGS,
- "Outputs picklable representation of the repeated field." },
- */
- {NULL, NULL},
+ {"__contains__", MapReflectionFriend::Contains, METH_O,
+ "Tests whether a key is a member of the map."},
+ {"clear", (PyCFunction)Clear, METH_NOARGS,
+ "Removes all elements from the map."},
+ {"get", (PyCFunction)ScalarMapGet, METH_VARARGS | METH_KEYWORDS,
+ "Gets the value for the given key if present, or otherwise a default"},
+ {"GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS,
+ "Return the class used to build Entries of (key, value) pairs."},
+ {"MergeFrom", (PyCFunction)MapReflectionFriend::MergeFrom, METH_O,
+ "Merges a map into the current map."},
+ /*
+ { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
+ "Makes a deep copy of the class." },
+ { "__reduce__", (PyCFunction)Reduce, METH_NOARGS,
+ "Outputs picklable representation of the repeated field." },
+ */
+ {NULL, NULL},
};
PyTypeObject *ScalarMapContainer_Type;
@@ -559,7 +559,7 @@ PyTypeObject *ScalarMapContainer_Type;
{Py_mp_ass_subscript, (void *)MapReflectionFriend::ScalarMapSetItem},
{Py_tp_methods, (void *)ScalarMapMethods},
{Py_tp_iter, (void *)MapReflectionFriend::GetIterator},
- {Py_tp_repr, (void *)MapReflectionFriend::ScalarMapToStr},
+ {Py_tp_repr, (void *)MapReflectionFriend::ScalarMapToStr},
{0, 0},
};
@@ -587,7 +587,7 @@ PyTypeObject *ScalarMapContainer_Type;
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
- MapReflectionFriend::ScalarMapToStr, // tp_repr
+ MapReflectionFriend::ScalarMapToStr, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
&ScalarMapMappingMethods, // tp_as_mapping
@@ -626,13 +626,13 @@ static MessageMapContainer* GetMessageMap(PyObject* obj) {
static PyObject* GetCMessage(MessageMapContainer* self, Message* message) {
// Get or create the CMessage object corresponding to this message.
- return self->parent
- ->BuildSubMessageFromPointer(self->parent_field_descriptor, message,
- self->message_class)
- ->AsPyObject();
+ return self->parent
+ ->BuildSubMessageFromPointer(self->parent_field_descriptor, message,
+ self->message_class)
+ ->AsPyObject();
}
-MessageMapContainer* NewMessageMapContainer(
+MessageMapContainer* NewMessageMapContainer(
CMessage* parent, const google::protobuf::FieldDescriptor* parent_field_descriptor,
CMessageClass* message_class) {
if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
@@ -641,13 +641,13 @@ MessageMapContainer* NewMessageMapContainer(
PyObject* obj = PyType_GenericAlloc(MessageMapContainer_Type, 0);
if (obj == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "Could not allocate new container.");
- return NULL;
+ PyErr_SetString(PyExc_RuntimeError, "Could not allocate new container.");
+ return NULL;
}
MessageMapContainer* self = GetMessageMap(obj);
- Py_INCREF(parent);
+ Py_INCREF(parent);
self->parent = parent;
self->parent_field_descriptor = parent_field_descriptor;
self->version = 0;
@@ -655,7 +655,7 @@ MessageMapContainer* NewMessageMapContainer(
Py_INCREF(message_class);
self->message_class = message_class;
- return self;
+ return self;
}
int MapReflectionFriend::MessageMapSetItem(PyObject* _self, PyObject* key,
@@ -676,7 +676,7 @@ int MapReflectionFriend::MessageMapSetItem(PyObject* _self, PyObject* key,
self->version++;
- if (!PythonToMapKey(self, key, &map_key)) {
+ if (!PythonToMapKey(self, key, &map_key)) {
return -1;
}
@@ -687,15 +687,15 @@ int MapReflectionFriend::MessageMapSetItem(PyObject* _self, PyObject* key,
MapValueRef value;
reflection->InsertOrLookupMapValue(message, self->parent_field_descriptor,
map_key, &value);
- Message* sub_message = value.MutableMessageValue();
- // If there is a living weak reference to an item, we "Release" it,
- // otherwise we just discard the C++ value.
- if (CMessage* released =
- self->parent->MaybeReleaseSubMessage(sub_message)) {
- Message* msg = released->message;
- released->message = msg->New();
- msg->GetReflection()->Swap(msg, released->message);
- }
+ Message* sub_message = value.MutableMessageValue();
+ // If there is a living weak reference to an item, we "Release" it,
+ // otherwise we just discard the C++ value.
+ if (CMessage* released =
+ self->parent->MaybeReleaseSubMessage(sub_message)) {
+ Message* msg = released->message;
+ released->message = msg->New();
+ msg->GetReflection()->Swap(msg, released->message);
+ }
// Delete key from map.
reflection->DeleteMapValue(message, self->parent_field_descriptor,
@@ -716,7 +716,7 @@ PyObject* MapReflectionFriend::MessageMapGetItem(PyObject* _self,
MapKey map_key;
MapValueRef value;
- if (!PythonToMapKey(self, key, &map_key)) {
+ if (!PythonToMapKey(self, key, &map_key)) {
return NULL;
}
@@ -728,43 +728,43 @@ PyObject* MapReflectionFriend::MessageMapGetItem(PyObject* _self,
return GetCMessage(self, value.MutableMessageValue());
}
-PyObject* MapReflectionFriend::MessageMapToStr(PyObject* _self) {
- ScopedPyObjectPtr dict(PyDict_New());
- if (dict == NULL) {
- return NULL;
- }
- ScopedPyObjectPtr key;
- ScopedPyObjectPtr value;
-
- MessageMapContainer* self = GetMessageMap(_self);
- Message* message = self->GetMutableMessage();
- const Reflection* reflection = message->GetReflection();
- for (google::protobuf::MapIterator it = reflection->MapBegin(
- message, self->parent_field_descriptor);
- it != reflection->MapEnd(message, self->parent_field_descriptor);
- ++it) {
- key.reset(MapKeyToPython(self, it.GetKey()));
- if (key == NULL) {
- return NULL;
- }
- value.reset(GetCMessage(self, it.MutableValueRef()->MutableMessageValue()));
- if (value == NULL) {
- return NULL;
- }
- if (PyDict_SetItem(dict.get(), key.get(), value.get()) < 0) {
- return NULL;
- }
- }
- return PyObject_Repr(dict.get());
-}
-
-PyObject* MessageMapGet(PyObject* self, PyObject* args, PyObject* kwargs) {
- static const char* kwlist[] = {"key", "default", nullptr};
+PyObject* MapReflectionFriend::MessageMapToStr(PyObject* _self) {
+ ScopedPyObjectPtr dict(PyDict_New());
+ if (dict == NULL) {
+ return NULL;
+ }
+ ScopedPyObjectPtr key;
+ ScopedPyObjectPtr value;
+
+ MessageMapContainer* self = GetMessageMap(_self);
+ Message* message = self->GetMutableMessage();
+ const Reflection* reflection = message->GetReflection();
+ for (google::protobuf::MapIterator it = reflection->MapBegin(
+ message, self->parent_field_descriptor);
+ it != reflection->MapEnd(message, self->parent_field_descriptor);
+ ++it) {
+ key.reset(MapKeyToPython(self, it.GetKey()));
+ if (key == NULL) {
+ return NULL;
+ }
+ value.reset(GetCMessage(self, it.MutableValueRef()->MutableMessageValue()));
+ if (value == NULL) {
+ return NULL;
+ }
+ if (PyDict_SetItem(dict.get(), key.get(), value.get()) < 0) {
+ return NULL;
+ }
+ }
+ return PyObject_Repr(dict.get());
+}
+
+PyObject* MessageMapGet(PyObject* self, PyObject* args, PyObject* kwargs) {
+ static const char* kwlist[] = {"key", "default", nullptr};
PyObject* key;
PyObject* default_value = NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
- const_cast<char**>(kwlist), &key,
- &default_value)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
+ const_cast<char**>(kwlist), &key,
+ &default_value)) {
return NULL;
}
@@ -787,36 +787,36 @@ PyObject* MessageMapGet(PyObject* self, PyObject* args, PyObject* kwargs) {
static void MessageMapDealloc(PyObject* _self) {
MessageMapContainer* self = GetMessageMap(_self);
- self->RemoveFromParentCache();
+ self->RemoveFromParentCache();
Py_DECREF(self->message_class);
- PyTypeObject *type = Py_TYPE(_self);
- type->tp_free(_self);
- if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
- // With Python3, the Map class is not static, and must be managed.
- Py_DECREF(type);
- }
+ PyTypeObject *type = Py_TYPE(_self);
+ type->tp_free(_self);
+ if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
+ // With Python3, the Map class is not static, and must be managed.
+ Py_DECREF(type);
+ }
}
static PyMethodDef MessageMapMethods[] = {
- {"__contains__", (PyCFunction)MapReflectionFriend::Contains, METH_O,
- "Tests whether the map contains this element."},
- {"clear", (PyCFunction)Clear, METH_NOARGS,
- "Removes all elements from the map."},
- {"get", (PyCFunction)MessageMapGet, METH_VARARGS | METH_KEYWORDS,
- "Gets the value for the given key if present, or otherwise a default"},
- {"get_or_create", MapReflectionFriend::MessageMapGetItem, METH_O,
- "Alias for getitem, useful to make explicit that the map is mutated."},
- {"GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS,
- "Return the class used to build Entries of (key, value) pairs."},
- {"MergeFrom", (PyCFunction)MapReflectionFriend::MergeFrom, METH_O,
- "Merges a map into the current map."},
- /*
- { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
- "Makes a deep copy of the class." },
- { "__reduce__", (PyCFunction)Reduce, METH_NOARGS,
- "Outputs picklable representation of the repeated field." },
- */
- {NULL, NULL},
+ {"__contains__", (PyCFunction)MapReflectionFriend::Contains, METH_O,
+ "Tests whether the map contains this element."},
+ {"clear", (PyCFunction)Clear, METH_NOARGS,
+ "Removes all elements from the map."},
+ {"get", (PyCFunction)MessageMapGet, METH_VARARGS | METH_KEYWORDS,
+ "Gets the value for the given key if present, or otherwise a default"},
+ {"get_or_create", MapReflectionFriend::MessageMapGetItem, METH_O,
+ "Alias for getitem, useful to make explicit that the map is mutated."},
+ {"GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS,
+ "Return the class used to build Entries of (key, value) pairs."},
+ {"MergeFrom", (PyCFunction)MapReflectionFriend::MergeFrom, METH_O,
+ "Merges a map into the current map."},
+ /*
+ { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
+ "Makes a deep copy of the class." },
+ { "__reduce__", (PyCFunction)Reduce, METH_NOARGS,
+ "Outputs picklable representation of the repeated field." },
+ */
+ {NULL, NULL},
};
PyTypeObject *MessageMapContainer_Type;
@@ -828,7 +828,7 @@ PyTypeObject *MessageMapContainer_Type;
{Py_mp_ass_subscript, (void *)MapReflectionFriend::MessageMapSetItem},
{Py_tp_methods, (void *)MessageMapMethods},
{Py_tp_iter, (void *)MapReflectionFriend::GetIterator},
- {Py_tp_repr, (void *)MapReflectionFriend::MessageMapToStr},
+ {Py_tp_repr, (void *)MapReflectionFriend::MessageMapToStr},
{0, 0}
};
@@ -856,7 +856,7 @@ PyTypeObject *MessageMapContainer_Type;
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
- MapReflectionFriend::MessageMapToStr, // tp_repr
+ MapReflectionFriend::MessageMapToStr, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
&MessageMapMappingMethods, // tp_as_mapping
@@ -905,8 +905,8 @@ PyObject* MapReflectionFriend::GetIterator(PyObject *_self) {
Py_INCREF(self);
iter->container = self;
iter->version = self->version;
- Py_INCREF(self->parent);
- iter->parent = self->parent;
+ Py_INCREF(self->parent);
+ iter->parent = self->parent;
if (MapReflectionFriend::Length(_self) > 0) {
Message* message = self->GetMutableMessage();
@@ -928,10 +928,10 @@ PyObject* MapReflectionFriend::IterNext(PyObject* _self) {
return PyErr_Format(PyExc_RuntimeError,
"Map modified during iteration.");
}
- if (self->parent != self->container->parent) {
- return PyErr_Format(PyExc_RuntimeError,
- "Map cleared during iteration.");
- }
+ if (self->parent != self->container->parent) {
+ return PyErr_Format(PyExc_RuntimeError,
+ "Map cleared during iteration.");
+ }
if (self->iter.get() == NULL) {
return NULL;
@@ -945,7 +945,7 @@ PyObject* MapReflectionFriend::IterNext(PyObject* _self) {
return NULL;
}
- PyObject* ret = MapKeyToPython(self->container, self->iter->GetKey());
+ PyObject* ret = MapKeyToPython(self->container, self->iter->GetKey());
++(*self->iter);
@@ -955,8 +955,8 @@ PyObject* MapReflectionFriend::IterNext(PyObject* _self) {
static void DeallocMapIterator(PyObject* _self) {
MapIterator* self = GetIter(_self);
self->iter.reset();
- Py_CLEAR(self->container);
- Py_CLEAR(self->parent);
+ Py_CLEAR(self->container);
+ Py_CLEAR(self->parent);
Py_TYPE(_self)->tp_free(_self);
}
@@ -1013,15 +1013,15 @@ bool InitMapContainers() {
return false;
}
- Py_INCREF(mutable_mapping.get());
-#if PY_MAJOR_VERSION >= 3
- ScopedPyObjectPtr bases(PyTuple_Pack(1, mutable_mapping.get()));
- if (bases == NULL) {
+ Py_INCREF(mutable_mapping.get());
+#if PY_MAJOR_VERSION >= 3
+ ScopedPyObjectPtr bases(PyTuple_Pack(1, mutable_mapping.get()));
+ if (bases == NULL) {
return false;
}
ScalarMapContainer_Type = reinterpret_cast<PyTypeObject*>(
- PyType_FromSpecWithBases(&ScalarMapContainer_Type_spec, bases.get()));
+ PyType_FromSpecWithBases(&ScalarMapContainer_Type_spec, bases.get()));
#else
_ScalarMapContainer_Type.tp_base =
reinterpret_cast<PyTypeObject*>(mutable_mapping.get());
@@ -1039,7 +1039,7 @@ bool InitMapContainers() {
#if PY_MAJOR_VERSION >= 3
MessageMapContainer_Type = reinterpret_cast<PyTypeObject*>(
- PyType_FromSpecWithBases(&MessageMapContainer_Type_spec, bases.get()));
+ PyType_FromSpecWithBases(&MessageMapContainer_Type_spec, bases.get()));
#else
Py_INCREF(mutable_mapping.get());
_MessageMapContainer_Type.tp_base =
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/map_container.h b/contrib/python/protobuf/py3/google/protobuf/pyext/map_container.h
index 842602e79f..7a5bfed193 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/map_container.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/map_container.h
@@ -33,12 +33,12 @@
#include <Python.h>
-#include <cstdint>
+#include <cstdint>
#include <memory>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/message.h>
namespace google {
namespace protobuf {
@@ -51,13 +51,13 @@ struct CMessageClass;
// This struct is used directly for ScalarMap, and is the base class of
// MessageMapContainer, which is used for MessageMap.
-struct MapContainer : public ContainerBase {
+struct MapContainer : public ContainerBase {
// Use to get a mutable message when necessary.
Message* GetMutableMessage();
// We bump this whenever we perform a mutation, to invalidate existing
// iterators.
- uint64_t version;
+ uint64_t version;
};
struct MessageMapContainer : public MapContainer {
@@ -73,17 +73,17 @@ extern PyTypeObject MapIterator_Type; // Both map types use the same iterator.
// Builds a MapContainer object, from a parent message and a
// field descriptor.
-extern MapContainer* NewScalarMapContainer(
+extern MapContainer* NewScalarMapContainer(
CMessage* parent, const FieldDescriptor* parent_field_descriptor);
// Builds a MessageMap object, from a parent message and a
// field descriptor.
-extern MessageMapContainer* NewMessageMapContainer(
+extern MessageMapContainer* NewMessageMapContainer(
CMessage* parent, const FieldDescriptor* parent_field_descriptor,
CMessageClass* message_class);
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/message.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/message.cc
index 8b41ca47dd..bdc4bfd612 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/message.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/message.cc
@@ -31,52 +31,52 @@
// Author: anuraag@google.com (Anuraag Agrawal)
// Author: tibell@google.com (Johan Tibell)
-#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message.h>
-#include <structmember.h> // A Python header file.
-
-#include <cstdint>
+#include <structmember.h> // A Python header file.
+
+#include <cstdint>
#include <map>
#include <memory>
-#include <string>
+#include <string>
#include <vector>
-#include <google/protobuf/stubs/strutil.h>
-
+#include <google/protobuf/stubs/strutil.h>
+
#ifndef PyVarObject_HEAD_INIT
#define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
#endif
#ifndef Py_TYPE
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#endif
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/text_format.h>
-#include <google/protobuf/unknown_field_set.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/extension_dict.h>
-#include <google/protobuf/pyext/field.h>
-#include <google/protobuf/pyext/map_container.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/repeated_composite_container.h>
-#include <google/protobuf/pyext/repeated_scalar_container.h>
-#include <google/protobuf/pyext/safe_numerics.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/pyext/unknown_fields.h>
-#include <google/protobuf/util/message_differencer.h>
-#include <google/protobuf/io/strtod.h>
-#include <google/protobuf/stubs/map_util.h>
-
-// clang-format off
-#include <google/protobuf/port_def.inc>
-// clang-format on
-
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
+#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/text_format.h>
+#include <google/protobuf/unknown_field_set.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/extension_dict.h>
+#include <google/protobuf/pyext/field.h>
+#include <google/protobuf/pyext/map_container.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/repeated_composite_container.h>
+#include <google/protobuf/pyext/repeated_scalar_container.h>
+#include <google/protobuf/pyext/safe_numerics.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/pyext/unknown_fields.h>
+#include <google/protobuf/util/message_differencer.h>
+#include <google/protobuf/io/strtod.h>
+#include <google/protobuf/stubs/map_util.h>
+
+// clang-format off
+#include <google/protobuf/port_def.inc>
+// clang-format on
+
#if PY_MAJOR_VERSION >= 3
#define PyInt_AsLong PyLong_AsLong
#define PyInt_FromLong PyLong_FromLong
@@ -84,34 +84,34 @@
#define PyString_Check PyUnicode_Check
#define PyString_FromString PyUnicode_FromString
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
- #define PyString_FromFormat PyUnicode_FromFormat
+ #define PyString_FromFormat PyUnicode_FromFormat
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#else
#define PyString_AsString(ob) \
(PyUnicode_Check(ob)? PyUnicode_AsUTF8(ob): PyBytes_AsString(ob))
-#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
-#endif
+#define PyString_AsStringAndSize(ob, charpp, sizep) \
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
+#endif
namespace google {
namespace protobuf {
namespace python {
-class MessageReflectionFriend {
- public:
- static void UnsafeShallowSwapFields(
- Message* lhs, Message* rhs,
- const std::vector<const FieldDescriptor*>& fields) {
- lhs->GetReflection()->UnsafeShallowSwapFields(lhs, rhs, fields);
- }
-};
-
+class MessageReflectionFriend {
+ public:
+ static void UnsafeShallowSwapFields(
+ Message* lhs, Message* rhs,
+ const std::vector<const FieldDescriptor*>& fields) {
+ lhs->GetReflection()->UnsafeShallowSwapFields(lhs, rhs, fields);
+ }
+};
+
static PyObject* kDESCRIPTOR;
PyObject* EnumTypeWrapper_class;
static PyObject* PythonMessage_class;
@@ -122,26 +122,26 @@ namespace message_meta {
static int InsertEmptyWeakref(PyTypeObject* base);
-namespace {
-// Copied over from internal 'google/protobuf/stubs/strutil.h'.
-inline void LowerString(TProtoStringType* s) {
- s->to_lower();
+namespace {
+// Copied over from internal 'google/protobuf/stubs/strutil.h'.
+inline void LowerString(TProtoStringType* s) {
+ s->to_lower();
}
-} // namespace
+} // namespace
// Finalize the creation of the Message class.
static int AddDescriptors(PyObject* cls, const Descriptor* descriptor) {
// For each field set: cls.<field>_FIELD_NUMBER = <number>
for (int i = 0; i < descriptor->field_count(); ++i) {
- const FieldDescriptor* field_descriptor = descriptor->field(i);
- ScopedPyObjectPtr property(NewFieldProperty(field_descriptor));
- if (property == NULL) {
- return -1;
- }
- if (PyObject_SetAttrString(cls, field_descriptor->name().c_str(),
- property.get()) < 0) {
+ const FieldDescriptor* field_descriptor = descriptor->field(i);
+ ScopedPyObjectPtr property(NewFieldProperty(field_descriptor));
+ if (property == NULL) {
return -1;
}
+ if (PyObject_SetAttrString(cls, field_descriptor->name().c_str(),
+ property.get()) < 0) {
+ return -1;
+ }
}
// For each enum set cls.<enum name> = EnumTypeWrapper(<enum descriptor>).
@@ -151,7 +151,7 @@ static int AddDescriptors(PyObject* cls, const Descriptor* descriptor) {
PyEnumDescriptor_FromDescriptor(enum_descriptor));
if (enum_type == NULL) {
return -1;
- }
+ }
// Add wrapped enum type to message class.
ScopedPyObjectPtr wrapped(PyObject_CallFunctionObjArgs(
EnumTypeWrapper_class, enum_type.get(), NULL));
@@ -201,15 +201,15 @@ static int AddDescriptors(PyObject* cls, const Descriptor* descriptor) {
return 0;
}
-static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
- static const char* kwlist[] = {"name", "bases", "dict", 0};
+static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
+ static const char* kwlist[] = {"name", "bases", "dict", 0};
PyObject *bases, *dict;
const char* name;
// Check arguments: (name, bases, dict)
- if (!PyArg_ParseTupleAndKeywords(
- args, kwargs, "sO!O!:type", const_cast<char**>(kwlist), &name,
- &PyTuple_Type, &bases, &PyDict_Type, &dict)) {
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kwargs, "sO!O!:type", const_cast<char**>(kwlist), &name,
+ &PyTuple_Type, &bases, &PyDict_Type, &dict)) {
return NULL;
}
@@ -224,20 +224,20 @@ static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
// Check dict['DESCRIPTOR']
PyObject* py_descriptor = PyDict_GetItem(dict, kDESCRIPTOR);
- if (py_descriptor == nullptr) {
+ if (py_descriptor == nullptr) {
PyErr_SetString(PyExc_TypeError, "Message class has no DESCRIPTOR");
- return nullptr;
+ return nullptr;
}
if (!PyObject_TypeCheck(py_descriptor, &PyMessageDescriptor_Type)) {
PyErr_Format(PyExc_TypeError, "Expected a message Descriptor, got %s",
py_descriptor->ob_type->tp_name);
- return nullptr;
- }
- const Descriptor* message_descriptor =
- PyMessageDescriptor_AsDescriptor(py_descriptor);
- if (message_descriptor == nullptr) {
- return nullptr;
+ return nullptr;
}
+ const Descriptor* message_descriptor =
+ PyMessageDescriptor_AsDescriptor(py_descriptor);
+ if (message_descriptor == nullptr) {
+ return nullptr;
+ }
// Messages have no __dict__
ScopedPyObjectPtr slots(PyTuple_New(0));
@@ -261,10 +261,10 @@ static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
PyObject* well_known_class = PyDict_GetItemString(
WKT_classes, message_descriptor->full_name().c_str());
if (well_known_class == NULL) {
- new_args.reset(Py_BuildValue("s(OO)O", name, CMessage_Type,
+ new_args.reset(Py_BuildValue("s(OO)O", name, CMessage_Type,
PythonMessage_class, dict));
} else {
- new_args.reset(Py_BuildValue("s(OOO)O", name, CMessage_Type,
+ new_args.reset(Py_BuildValue("s(OOO)O", name, CMessage_Type,
PythonMessage_class, well_known_class, dict));
}
@@ -281,7 +281,7 @@ static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
// Insert the empty weakref into the base classes.
if (InsertEmptyWeakref(
reinterpret_cast<PyTypeObject*>(PythonMessage_class)) < 0 ||
- InsertEmptyWeakref(CMessage_Type) < 0) {
+ InsertEmptyWeakref(CMessage_Type) < 0) {
return NULL;
}
@@ -319,26 +319,26 @@ static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
return result.release();
}
-static void Dealloc(PyObject* pself) {
- CMessageClass* self = reinterpret_cast<CMessageClass*>(pself);
+static void Dealloc(PyObject* pself) {
+ CMessageClass* self = reinterpret_cast<CMessageClass*>(pself);
Py_XDECREF(self->py_message_descriptor);
Py_XDECREF(self->py_message_factory);
- return PyType_Type.tp_dealloc(pself);
-}
-
-static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
- CMessageClass* self = reinterpret_cast<CMessageClass*>(pself);
- Py_VISIT(self->py_message_descriptor);
- Py_VISIT(self->py_message_factory);
- return PyType_Type.tp_traverse(pself, visit, arg);
-}
-
-static int GcClear(PyObject* pself) {
- // It's important to keep the descriptor and factory alive, until the
- // C++ message is fully destructed.
- return PyType_Type.tp_clear(pself);
-}
-
+ return PyType_Type.tp_dealloc(pself);
+}
+
+static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
+ CMessageClass* self = reinterpret_cast<CMessageClass*>(pself);
+ Py_VISIT(self->py_message_descriptor);
+ Py_VISIT(self->py_message_factory);
+ return PyType_Type.tp_traverse(pself, visit, arg);
+}
+
+static int GcClear(PyObject* pself) {
+ // It's important to keep the descriptor and factory alive, until the
+ // C++ message is fully destructed.
+ return PyType_Type.tp_clear(pself);
+}
+
// This function inserts and empty weakref at the end of the list of
// subclasses for the main protocol buffer Message class.
//
@@ -351,16 +351,16 @@ static int InsertEmptyWeakref(PyTypeObject *base_type) {
// https://bugs.python.org/issue17936.
return 0;
#else
-#ifdef Py_DEBUG
- // The code below causes all new subclasses to append an entry, which is never
- // cleared. This is a small memory leak, which we disable in Py_DEBUG mode
- // to have stable refcounting checks.
-#else
+#ifdef Py_DEBUG
+ // The code below causes all new subclasses to append an entry, which is never
+ // cleared. This is a small memory leak, which we disable in Py_DEBUG mode
+ // to have stable refcounting checks.
+#else
PyObject *subclasses = base_type->tp_subclasses;
if (subclasses && PyList_CheckExact(subclasses)) {
return PyList_Append(subclasses, kEmptyWeakref);
}
-#endif // !Py_DEBUG
+#endif // !Py_DEBUG
return 0;
#endif // PY_MAJOR_VERSION >= 3
}
@@ -368,13 +368,13 @@ static int InsertEmptyWeakref(PyTypeObject *base_type) {
// The _extensions_by_name dictionary is built on every access.
// TODO(amauryfa): Migrate all users to pool.FindAllExtensions()
static PyObject* GetExtensionsByName(CMessageClass *self, void *closure) {
- if (self->message_descriptor == NULL) {
- // This is the base Message object, simply raise AttributeError.
- PyErr_SetString(PyExc_AttributeError,
- "Base Message class has no DESCRIPTOR");
- return NULL;
- }
-
+ if (self->message_descriptor == NULL) {
+ // This is the base Message object, simply raise AttributeError.
+ PyErr_SetString(PyExc_AttributeError,
+ "Base Message class has no DESCRIPTOR");
+ return NULL;
+ }
+
const PyDescriptorPool* pool = self->py_message_factory->pool;
std::vector<const FieldDescriptor*> extensions;
@@ -398,13 +398,13 @@ static PyObject* GetExtensionsByName(CMessageClass *self, void *closure) {
// The _extensions_by_number dictionary is built on every access.
// TODO(amauryfa): Migrate all users to pool.FindExtensionByNumber()
static PyObject* GetExtensionsByNumber(CMessageClass *self, void *closure) {
- if (self->message_descriptor == NULL) {
- // This is the base Message object, simply raise AttributeError.
- PyErr_SetString(PyExc_AttributeError,
- "Base Message class has no DESCRIPTOR");
- return NULL;
- }
-
+ if (self->message_descriptor == NULL) {
+ // This is the base Message object, simply raise AttributeError.
+ PyErr_SetString(PyExc_AttributeError,
+ "Base Message class has no DESCRIPTOR");
+ return NULL;
+ }
+
const PyDescriptorPool* pool = self->py_message_factory->pool;
std::vector<const FieldDescriptor*> extensions;
@@ -434,94 +434,94 @@ static PyGetSetDef Getters[] = {
{NULL}
};
-// Compute some class attributes on the fly:
-// - All the _FIELD_NUMBER attributes, for all fields and nested extensions.
-// Returns a new reference, or NULL with an exception set.
-static PyObject* GetClassAttribute(CMessageClass *self, PyObject* name) {
- char* attr;
- Py_ssize_t attr_size;
- static const char kSuffix[] = "_FIELD_NUMBER";
- if (PyString_AsStringAndSize(name, &attr, &attr_size) >= 0 &&
- HasSuffixString(StringPiece(attr, attr_size), kSuffix)) {
- TProtoStringType field_name(attr, attr_size - sizeof(kSuffix) + 1);
- LowerString(&field_name);
-
- // Try to find a field with the given name, without the suffix.
- const FieldDescriptor* field =
- self->message_descriptor->FindFieldByLowercaseName(field_name);
- if (!field) {
- // Search nested extensions as well.
- field =
- self->message_descriptor->FindExtensionByLowercaseName(field_name);
- }
- if (field) {
- return PyInt_FromLong(field->number());
- }
- }
- PyErr_SetObject(PyExc_AttributeError, name);
- return NULL;
-}
-
-static PyObject* GetAttr(CMessageClass* self, PyObject* name) {
- PyObject* result = CMessageClass_Type->tp_base->tp_getattro(
- reinterpret_cast<PyObject*>(self), name);
- if (result != NULL) {
- return result;
- }
- if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
- return NULL;
- }
-
- PyErr_Clear();
- return GetClassAttribute(self, name);
-}
-
+// Compute some class attributes on the fly:
+// - All the _FIELD_NUMBER attributes, for all fields and nested extensions.
+// Returns a new reference, or NULL with an exception set.
+static PyObject* GetClassAttribute(CMessageClass *self, PyObject* name) {
+ char* attr;
+ Py_ssize_t attr_size;
+ static const char kSuffix[] = "_FIELD_NUMBER";
+ if (PyString_AsStringAndSize(name, &attr, &attr_size) >= 0 &&
+ HasSuffixString(StringPiece(attr, attr_size), kSuffix)) {
+ TProtoStringType field_name(attr, attr_size - sizeof(kSuffix) + 1);
+ LowerString(&field_name);
+
+ // Try to find a field with the given name, without the suffix.
+ const FieldDescriptor* field =
+ self->message_descriptor->FindFieldByLowercaseName(field_name);
+ if (!field) {
+ // Search nested extensions as well.
+ field =
+ self->message_descriptor->FindExtensionByLowercaseName(field_name);
+ }
+ if (field) {
+ return PyInt_FromLong(field->number());
+ }
+ }
+ PyErr_SetObject(PyExc_AttributeError, name);
+ return NULL;
+}
+
+static PyObject* GetAttr(CMessageClass* self, PyObject* name) {
+ PyObject* result = CMessageClass_Type->tp_base->tp_getattro(
+ reinterpret_cast<PyObject*>(self), name);
+ if (result != NULL) {
+ return result;
+ }
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ return NULL;
+ }
+
+ PyErr_Clear();
+ return GetClassAttribute(self, name);
+}
+
} // namespace message_meta
-static PyTypeObject _CMessageClass_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".MessageMeta", // tp_name
- sizeof(CMessageClass), // tp_basicsize
- 0, // tp_itemsize
- message_meta::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- (getattrofunc)message_meta::GetAttr, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, // tp_flags
- "The metaclass of ProtocolMessages", // tp_doc
- message_meta::GcTraverse, // tp_traverse
- message_meta::GcClear, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- message_meta::Getters, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
- 0, // tp_alloc
- message_meta::New, // tp_new
+static PyTypeObject _CMessageClass_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".MessageMeta", // tp_name
+ sizeof(CMessageClass), // tp_basicsize
+ 0, // tp_itemsize
+ message_meta::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ (getattrofunc)message_meta::GetAttr, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, // tp_flags
+ "The metaclass of ProtocolMessages", // tp_doc
+ message_meta::GcTraverse, // tp_traverse
+ message_meta::GcClear, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ message_meta::Getters, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ message_meta::New, // tp_new
};
-PyTypeObject* CMessageClass_Type = &_CMessageClass_Type;
+PyTypeObject* CMessageClass_Type = &_CMessageClass_Type;
static CMessageClass* CheckMessageClass(PyTypeObject* cls) {
- if (!PyObject_TypeCheck(cls, CMessageClass_Type)) {
+ if (!PyObject_TypeCheck(cls, CMessageClass_Type)) {
PyErr_Format(PyExc_TypeError, "Class %s is not a Message", cls->tp_name);
return NULL;
}
@@ -540,7 +540,7 @@ static const Descriptor* GetMessageDescriptor(PyTypeObject* cls) {
namespace cmessage {
int InternalReleaseFieldByDescriptor(
CMessage* self,
- const FieldDescriptor* field_descriptor);
+ const FieldDescriptor* field_descriptor);
} // namespace cmessage
// ---------------------------------------------------------------------
@@ -549,12 +549,12 @@ PyObject* EncodeError_class;
PyObject* DecodeError_class;
PyObject* PickleError_class;
-// Format an error message for unexpected types.
-// Always return with an exception set.
+// Format an error message for unexpected types.
+// Always return with an exception set.
void FormatTypeError(PyObject* arg, const char* expected_types) {
- // This function is often called with an exception set.
- // Clear it to call PyObject_Repr() in good conditions.
- PyErr_Clear();
+ // This function is often called with an exception set.
+ // Clear it to call PyObject_Repr() in good conditions.
+ PyErr_Clear();
PyObject* repr = PyObject_Repr(arg);
if (repr) {
PyErr_Format(PyExc_TypeError,
@@ -578,7 +578,7 @@ void OutOfRangeError(PyObject* arg) {
template<class RangeType, class ValueType>
bool VerifyIntegerCastAndRange(PyObject* arg, ValueType value) {
- if (PROTOBUF_PREDICT_FALSE(value == -1 && PyErr_Occurred())) {
+ if (PROTOBUF_PREDICT_FALSE(value == -1 && PyErr_Occurred())) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
// Replace it with the same ValueError as pure python protos instead of
// the default one.
@@ -587,21 +587,21 @@ bool VerifyIntegerCastAndRange(PyObject* arg, ValueType value) {
} // Otherwise propagate existing error.
return false;
}
- if (PROTOBUF_PREDICT_FALSE(!IsValidNumericCast<RangeType>(value))) {
+ if (PROTOBUF_PREDICT_FALSE(!IsValidNumericCast<RangeType>(value))) {
OutOfRangeError(arg);
return false;
}
return true;
}
-template <class T>
+template <class T>
bool CheckAndGetInteger(PyObject* arg, T* value) {
// The fast path.
#if PY_MAJOR_VERSION < 3
// For the typical case, offer a fast path.
- if (PROTOBUF_PREDICT_TRUE(PyInt_Check(arg))) {
- long int_result = PyInt_AsLong(arg);
- if (PROTOBUF_PREDICT_TRUE(IsValidNumericCast<T>(int_result))) {
+ if (PROTOBUF_PREDICT_TRUE(PyInt_Check(arg))) {
+ long int_result = PyInt_AsLong(arg);
+ if (PROTOBUF_PREDICT_TRUE(IsValidNumericCast<T>(int_result))) {
*value = static_cast<T>(int_result);
return true;
} else {
@@ -614,7 +614,7 @@ bool CheckAndGetInteger(PyObject* arg, T* value) {
// an integer and can be used as an ordinal number".
// This definition includes everything that implements numbers.Integral
// and shouldn't cast the net too wide.
- if (PROTOBUF_PREDICT_FALSE(!PyIndex_Check(arg))) {
+ if (PROTOBUF_PREDICT_FALSE(!PyIndex_Check(arg))) {
FormatTypeError(arg, "int, long");
return false;
}
@@ -631,7 +631,7 @@ bool CheckAndGetInteger(PyObject* arg, T* value) {
// Unlike PyLong_AsLongLong, PyLong_AsUnsignedLongLong is very
// picky about the exact type.
PyObject* casted = PyNumber_Long(arg);
- if (PROTOBUF_PREDICT_FALSE(casted == nullptr)) {
+ if (PROTOBUF_PREDICT_FALSE(casted == nullptr)) {
// Propagate existing error.
return false;
}
@@ -656,7 +656,7 @@ bool CheckAndGetInteger(PyObject* arg, T* value) {
// Valid subclasses of numbers.Integral should have a __long__() method
// so fall back to that.
PyObject* casted = PyNumber_Long(arg);
- if (PROTOBUF_PREDICT_FALSE(casted == nullptr)) {
+ if (PROTOBUF_PREDICT_FALSE(casted == nullptr)) {
// Propagate existing error.
return false;
}
@@ -682,7 +682,7 @@ template bool CheckAndGetInteger<uint64>(PyObject*, uint64*);
bool CheckAndGetDouble(PyObject* arg, double* value) {
*value = PyFloat_AsDouble(arg);
- if (PROTOBUF_PREDICT_FALSE(*value == -1 && PyErr_Occurred())) {
+ if (PROTOBUF_PREDICT_FALSE(*value == -1 && PyErr_Occurred())) {
FormatTypeError(arg, "int, long, float");
return false;
}
@@ -694,7 +694,7 @@ bool CheckAndGetFloat(PyObject* arg, float* value) {
if (!CheckAndGetDouble(arg, &double_value)) {
return false;
}
- *value = io::SafeDoubleToFloat(double_value);
+ *value = io::SafeDoubleToFloat(double_value);
return true;
}
@@ -792,20 +792,20 @@ bool CheckAndSetString(
return false;
}
- TProtoStringType value_string(value, value_len);
+ TProtoStringType value_string(value, value_len);
if (append) {
- reflection->AddString(message, descriptor, std::move(value_string));
+ reflection->AddString(message, descriptor, std::move(value_string));
} else if (index < 0) {
- reflection->SetString(message, descriptor, std::move(value_string));
+ reflection->SetString(message, descriptor, std::move(value_string));
} else {
- reflection->SetRepeatedString(message, descriptor, index,
- std::move(value_string));
+ reflection->SetRepeatedString(message, descriptor, index,
+ std::move(value_string));
}
return true;
}
-PyObject* ToStringObject(const FieldDescriptor* descriptor,
- const TProtoStringType& value) {
+PyObject* ToStringObject(const FieldDescriptor* descriptor,
+ const TProtoStringType& value) {
#if PY_MAJOR_VERSION >= 3
if (descriptor->type() != FieldDescriptor::TYPE_STRING) {
return PyBytes_FromStringAndSize(value.c_str(), value.length());
@@ -840,7 +840,7 @@ bool CheckFieldBelongsToMessage(const FieldDescriptor* field_descriptor,
namespace cmessage {
PyMessageFactory* GetFactoryForMessage(CMessage* message) {
- GOOGLE_DCHECK(PyObject_TypeCheck(message, CMessage_Type));
+ GOOGLE_DCHECK(PyObject_TypeCheck(message, CMessage_Type));
return reinterpret_cast<CMessageClass*>(Py_TYPE(message))->py_message_factory;
}
@@ -864,78 +864,78 @@ static int MaybeReleaseOverlappingOneofField(
// Non-message fields don't need to be released.
return 0;
}
- if (InternalReleaseFieldByDescriptor(cmessage, existing_field) < 0) {
+ if (InternalReleaseFieldByDescriptor(cmessage, existing_field) < 0) {
return -1;
}
-#endif
+#endif
return 0;
}
-// After a Merge, visit every sub-message that was read-only, and
-// eventually update their pointer if the Merge operation modified them.
-int FixupMessageAfterMerge(CMessage* self) {
- if (!self->composite_fields) {
+// After a Merge, visit every sub-message that was read-only, and
+// eventually update their pointer if the Merge operation modified them.
+int FixupMessageAfterMerge(CMessage* self) {
+ if (!self->composite_fields) {
return 0;
}
- for (const auto& item : *self->composite_fields) {
- const FieldDescriptor* descriptor = item.first;
- if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
- !descriptor->is_repeated()) {
- CMessage* cmsg = reinterpret_cast<CMessage*>(item.second);
- if (cmsg->read_only == false) {
- return 0;
- }
- Message* message = self->message;
- const Reflection* reflection = message->GetReflection();
- if (reflection->HasField(*message, descriptor)) {
- // Message used to be read_only, but is no longer. Get the new pointer
- // and record it.
- Message* mutable_message =
- reflection->MutableMessage(message, descriptor, nullptr);
- cmsg->message = mutable_message;
- cmsg->read_only = false;
- if (FixupMessageAfterMerge(cmsg) < 0) {
- return -1;
- }
- }
- }
- }
-
- return 0;
-}
-
-// ---------------------------------------------------------------------
-// Making a message writable
+ for (const auto& item : *self->composite_fields) {
+ const FieldDescriptor* descriptor = item.first;
+ if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
+ !descriptor->is_repeated()) {
+ CMessage* cmsg = reinterpret_cast<CMessage*>(item.second);
+ if (cmsg->read_only == false) {
+ return 0;
+ }
+ Message* message = self->message;
+ const Reflection* reflection = message->GetReflection();
+ if (reflection->HasField(*message, descriptor)) {
+ // Message used to be read_only, but is no longer. Get the new pointer
+ // and record it.
+ Message* mutable_message =
+ reflection->MutableMessage(message, descriptor, nullptr);
+ cmsg->message = mutable_message;
+ cmsg->read_only = false;
+ if (FixupMessageAfterMerge(cmsg) < 0) {
+ return -1;
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+// ---------------------------------------------------------------------
+// Making a message writable
int AssureWritable(CMessage* self) {
if (self == NULL || !self->read_only) {
return 0;
}
- // Toplevel messages are always mutable.
- GOOGLE_DCHECK(self->parent);
+ // Toplevel messages are always mutable.
+ GOOGLE_DCHECK(self->parent);
- if (AssureWritable(self->parent) == -1) {
- return -1;
- }
- // If this message is part of a oneof, there might be a field to release in
- // the parent.
- if (MaybeReleaseOverlappingOneofField(self->parent,
- self->parent_field_descriptor) < 0) {
- return -1;
+ if (AssureWritable(self->parent) == -1) {
+ return -1;
}
+ // If this message is part of a oneof, there might be a field to release in
+ // the parent.
+ if (MaybeReleaseOverlappingOneofField(self->parent,
+ self->parent_field_descriptor) < 0) {
+ return -1;
+ }
- // Make self->message writable.
- Message* parent_message = self->parent->message;
- const Reflection* reflection = parent_message->GetReflection();
- Message* mutable_message = reflection->MutableMessage(
- parent_message, self->parent_field_descriptor,
- GetFactoryForMessage(self->parent)->message_factory);
- if (mutable_message == NULL) {
+ // Make self->message writable.
+ Message* parent_message = self->parent->message;
+ const Reflection* reflection = parent_message->GetReflection();
+ Message* mutable_message = reflection->MutableMessage(
+ parent_message, self->parent_field_descriptor,
+ GetFactoryForMessage(self->parent)->message_factory);
+ if (mutable_message == NULL) {
return -1;
- }
- self->message = mutable_message;
- self->read_only = false;
+ }
+ self->message = mutable_message;
+ self->read_only = false;
return 0;
}
@@ -971,9 +971,9 @@ static PyObject* GetIntegerEnumValue(const FieldDescriptor& descriptor,
return NULL;
}
const EnumValueDescriptor* enum_value_descriptor =
- enum_descriptor->FindValueByName(StringParam(enum_label, size));
+ enum_descriptor->FindValueByName(StringParam(enum_label, size));
if (enum_value_descriptor == NULL) {
- PyErr_Format(PyExc_ValueError, "unknown enum label \"%s\"", enum_label);
+ PyErr_Format(PyExc_ValueError, "unknown enum label \"%s\"", enum_label);
return NULL;
}
return PyInt_FromLong(enum_value_descriptor->number());
@@ -982,15 +982,15 @@ static PyObject* GetIntegerEnumValue(const FieldDescriptor& descriptor,
return value;
}
-// Delete a slice from a repeated field.
-// The only way to remove items in C++ protos is to delete the last one,
-// so we swap items to move the deleted ones at the end, and then strip the
-// sequence.
-int DeleteRepeatedField(
+// Delete a slice from a repeated field.
+// The only way to remove items in C++ protos is to delete the last one,
+// so we swap items to move the deleted ones at the end, and then strip the
+// sequence.
+int DeleteRepeatedField(
CMessage* self,
const FieldDescriptor* field_descriptor,
- PyObject* slice) {
- Py_ssize_t length, from, to, step, slice_length;
+ PyObject* slice) {
+ Py_ssize_t length, from, to, step, slice_length;
Message* message = self->message;
const Reflection* reflection = message->GetReflection();
int min, max;
@@ -1041,7 +1041,7 @@ int DeleteRepeatedField(
i += step;
}
- // Swap elements so that items to delete are at the end.
+ // Swap elements so that items to delete are at the end.
to = 0;
for (i = 0; i < length; ++i) {
if (!to_delete[i]) {
@@ -1052,22 +1052,22 @@ int DeleteRepeatedField(
}
}
- // Remove items, starting from the end.
- for (; length > to; length--) {
- if (field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
+ // Remove items, starting from the end.
+ for (; length > to; length--) {
+ if (field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
reflection->RemoveLast(message, field_descriptor);
- continue;
- }
- // It seems that RemoveLast() is less efficient for sub-messages, and
- // the memory is not completely released. Prefer ReleaseLast().
- Message* sub_message = reflection->ReleaseLast(message, field_descriptor);
- // If there is a live weak reference to an item being removed, we "Release"
- // it, and it takes ownership of the message.
- if (CMessage* released = self->MaybeReleaseSubMessage(sub_message)) {
- released->message = sub_message;
+ continue;
+ }
+ // It seems that RemoveLast() is less efficient for sub-messages, and
+ // the memory is not completely released. Prefer ReleaseLast().
+ Message* sub_message = reflection->ReleaseLast(message, field_descriptor);
+ // If there is a live weak reference to an item being removed, we "Release"
+ // it, and it takes ownership of the message.
+ if (CMessage* released = self->MaybeReleaseSubMessage(sub_message)) {
+ released->message = sub_message;
} else {
- // sub_message was not transferred, delete it.
- delete sub_message;
+ // sub_message was not transferred, delete it.
+ delete sub_message;
}
}
@@ -1089,45 +1089,45 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
PyObject* name;
PyObject* value;
while (PyDict_Next(kwargs, &pos, &name, &value)) {
- if (!(PyString_Check(name) || PyUnicode_Check(name))) {
+ if (!(PyString_Check(name) || PyUnicode_Check(name))) {
PyErr_SetString(PyExc_ValueError, "Field name must be a string");
return -1;
}
- ScopedPyObjectPtr property(
- PyObject_GetAttr(reinterpret_cast<PyObject*>(Py_TYPE(self)), name));
- if (property == NULL ||
- !PyObject_TypeCheck(property.get(), CFieldProperty_Type)) {
+ ScopedPyObjectPtr property(
+ PyObject_GetAttr(reinterpret_cast<PyObject*>(Py_TYPE(self)), name));
+ if (property == NULL ||
+ !PyObject_TypeCheck(property.get(), CFieldProperty_Type)) {
PyErr_Format(PyExc_ValueError, "Protocol message %s has no \"%s\" field.",
self->message->GetDescriptor()->name().c_str(),
PyString_AsString(name));
return -1;
}
- const FieldDescriptor* descriptor =
- reinterpret_cast<PyMessageFieldProperty*>(property.get())
- ->field_descriptor;
+ const FieldDescriptor* descriptor =
+ reinterpret_cast<PyMessageFieldProperty*>(property.get())
+ ->field_descriptor;
if (value == Py_None) {
// field=None is the same as no field at all.
continue;
}
if (descriptor->is_map()) {
- ScopedPyObjectPtr map(GetFieldValue(self, descriptor));
+ ScopedPyObjectPtr map(GetFieldValue(self, descriptor));
const FieldDescriptor* value_descriptor =
descriptor->message_type()->FindFieldByName("value");
if (value_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- ScopedPyObjectPtr iter(PyObject_GetIter(value));
- if (iter == NULL) {
- PyErr_Format(PyExc_TypeError, "Argument %s is not iterable", PyString_AsString(name));
- return -1;
- }
- ScopedPyObjectPtr next;
- while ((next.reset(PyIter_Next(iter.get()))) != NULL) {
- ScopedPyObjectPtr source_value(PyObject_GetItem(value, next.get()));
- ScopedPyObjectPtr dest_value(PyObject_GetItem(map.get(), next.get()));
- if (source_value.get() == NULL || dest_value.get() == NULL) {
+ ScopedPyObjectPtr iter(PyObject_GetIter(value));
+ if (iter == NULL) {
+ PyErr_Format(PyExc_TypeError, "Argument %s is not iterable", PyString_AsString(name));
+ return -1;
+ }
+ ScopedPyObjectPtr next;
+ while ((next.reset(PyIter_Next(iter.get()))) != NULL) {
+ ScopedPyObjectPtr source_value(PyObject_GetItem(value, next.get()));
+ ScopedPyObjectPtr dest_value(PyObject_GetItem(map.get(), next.get()));
+ if (source_value.get() == NULL || dest_value.get() == NULL) {
return -1;
}
ScopedPyObjectPtr ok(PyObject_CallMethod(
- dest_value.get(), "MergeFrom", "O", source_value.get()));
+ dest_value.get(), "MergeFrom", "O", source_value.get()));
if (ok.get() == NULL) {
return -1;
}
@@ -1141,7 +1141,7 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
}
}
} else if (descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
- ScopedPyObjectPtr container(GetFieldValue(self, descriptor));
+ ScopedPyObjectPtr container(GetFieldValue(self, descriptor));
if (container == NULL) {
return -1;
}
@@ -1208,7 +1208,7 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
}
}
} else if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- ScopedPyObjectPtr message(GetFieldValue(self, descriptor));
+ ScopedPyObjectPtr message(GetFieldValue(self, descriptor));
if (message == NULL) {
return -1;
}
@@ -1232,9 +1232,9 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
if (new_val == NULL) {
return -1;
}
- value = new_val.get();
+ value = new_val.get();
}
- if (SetFieldValue(self, descriptor, value) < 0) {
+ if (SetFieldValue(self, descriptor, value) < 0) {
return -1;
}
}
@@ -1242,8 +1242,8 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
return 0;
}
-// Allocates an incomplete Python Message: the caller must fill self->message
-// and eventually self->parent.
+// Allocates an incomplete Python Message: the caller must fill self->message
+// and eventually self->parent.
CMessage* NewEmptyMessage(CMessageClass* type) {
CMessage* self = reinterpret_cast<CMessage*>(
PyType_GenericAlloc(&type->super.ht_type, 0));
@@ -1257,52 +1257,52 @@ CMessage* NewEmptyMessage(CMessageClass* type) {
self->read_only = false;
self->composite_fields = NULL;
- self->child_submessages = NULL;
-
- self->unknown_field_set = NULL;
+ self->child_submessages = NULL;
+ self->unknown_field_set = NULL;
+
return self;
}
// The __new__ method of Message classes.
// Creates a new C++ message and takes ownership.
-static CMessage* NewCMessage(CMessageClass* type) {
+static CMessage* NewCMessage(CMessageClass* type) {
// Retrieve the message descriptor and the default instance (=prototype).
const Descriptor* message_descriptor = type->message_descriptor;
- if (message_descriptor == nullptr) {
- // This would be very unexpected since the CMessageClass has already
- // been checked.
- PyErr_Format(PyExc_TypeError,
- "CMessageClass object '%s' has no descriptor.",
- Py_TYPE(type)->tp_name);
- return nullptr;
- }
- const Message* prototype =
- type->py_message_factory->message_factory->GetPrototype(
- message_descriptor);
- if (prototype == nullptr) {
+ if (message_descriptor == nullptr) {
+ // This would be very unexpected since the CMessageClass has already
+ // been checked.
+ PyErr_Format(PyExc_TypeError,
+ "CMessageClass object '%s' has no descriptor.",
+ Py_TYPE(type)->tp_name);
+ return nullptr;
+ }
+ const Message* prototype =
+ type->py_message_factory->message_factory->GetPrototype(
+ message_descriptor);
+ if (prototype == nullptr) {
PyErr_SetString(PyExc_TypeError, message_descriptor->full_name().c_str());
- return nullptr;
+ return nullptr;
}
CMessage* self = NewEmptyMessage(type);
- if (self == nullptr) {
- return nullptr;
- }
- self->message = prototype->New(nullptr); // Ensures no arena is used.
- self->parent = nullptr; // This message owns its data.
- return self;
-}
-
-static PyObject* New(PyTypeObject* cls, PyObject* unused_args,
- PyObject* unused_kwargs) {
- CMessageClass* type = CheckMessageClass(cls);
- if (type == nullptr) {
- return nullptr;
- }
- return reinterpret_cast<PyObject*>(NewCMessage(type));
-}
-
+ if (self == nullptr) {
+ return nullptr;
+ }
+ self->message = prototype->New(nullptr); // Ensures no arena is used.
+ self->parent = nullptr; // This message owns its data.
+ return self;
+}
+
+static PyObject* New(PyTypeObject* cls, PyObject* unused_args,
+ PyObject* unused_kwargs) {
+ CMessageClass* type = CheckMessageClass(cls);
+ if (type == nullptr) {
+ return nullptr;
+ }
+ return reinterpret_cast<PyObject*>(NewCMessage(type));
+}
+
// The __init__ method of Message classes.
// It initializes fields from keywords passed to the constructor.
static int Init(CMessage* self, PyObject* args, PyObject* kwargs) {
@@ -1316,34 +1316,34 @@ static void Dealloc(CMessage* self) {
if (self->weakreflist) {
PyObject_ClearWeakRefs(reinterpret_cast<PyObject*>(self));
}
- // At this point all dependent objects have been removed.
- GOOGLE_DCHECK(!self->child_submessages || self->child_submessages->empty());
- GOOGLE_DCHECK(!self->composite_fields || self->composite_fields->empty());
- delete self->child_submessages;
- delete self->composite_fields;
- if (self->unknown_field_set) {
- unknown_fields::Clear(
- reinterpret_cast<PyUnknownFields*>(self->unknown_field_set));
- }
-
- CMessage* parent = self->parent;
- if (!parent) {
- // No parent, we own the message.
- delete self->message;
- } else if (parent->AsPyObject() == Py_None) {
- // Message owned externally: Nothing to dealloc
- Py_CLEAR(self->parent);
- } else {
- // Clear this message from its parent's map.
- if (self->parent_field_descriptor->is_repeated()) {
- if (parent->child_submessages)
- parent->child_submessages->erase(self->message);
- } else {
- if (parent->composite_fields)
- parent->composite_fields->erase(self->parent_field_descriptor);
- }
- Py_CLEAR(self->parent);
- }
+ // At this point all dependent objects have been removed.
+ GOOGLE_DCHECK(!self->child_submessages || self->child_submessages->empty());
+ GOOGLE_DCHECK(!self->composite_fields || self->composite_fields->empty());
+ delete self->child_submessages;
+ delete self->composite_fields;
+ if (self->unknown_field_set) {
+ unknown_fields::Clear(
+ reinterpret_cast<PyUnknownFields*>(self->unknown_field_set));
+ }
+
+ CMessage* parent = self->parent;
+ if (!parent) {
+ // No parent, we own the message.
+ delete self->message;
+ } else if (parent->AsPyObject() == Py_None) {
+ // Message owned externally: Nothing to dealloc
+ Py_CLEAR(self->parent);
+ } else {
+ // Clear this message from its parent's map.
+ if (self->parent_field_descriptor->is_repeated()) {
+ if (parent->child_submessages)
+ parent->child_submessages->erase(self->message);
+ } else {
+ if (parent->composite_fields)
+ parent->composite_fields->erase(self->parent_field_descriptor);
+ }
+ Py_CLEAR(self->parent);
+ }
Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self));
}
@@ -1352,7 +1352,7 @@ static void Dealloc(CMessage* self) {
PyObject* IsInitialized(CMessage* self, PyObject* args) {
PyObject* errors = NULL;
- if (!PyArg_ParseTuple(args, "|O", &errors)) {
+ if (!PyArg_ParseTuple(args, "|O", &errors)) {
return NULL;
}
if (self->message->IsInitialized()) {
@@ -1380,23 +1380,23 @@ PyObject* IsInitialized(CMessage* self, PyObject* args) {
Py_RETURN_FALSE;
}
-int HasFieldByDescriptor(CMessage* self,
- const FieldDescriptor* field_descriptor) {
+int HasFieldByDescriptor(CMessage* self,
+ const FieldDescriptor* field_descriptor) {
Message* message = self->message;
if (!CheckFieldBelongsToMessage(field_descriptor, message)) {
- return -1;
+ return -1;
}
if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
PyErr_SetString(PyExc_KeyError,
"Field is repeated. A singular method is required.");
- return -1;
+ return -1;
}
- return message->GetReflection()->HasField(*message, field_descriptor);
+ return message->GetReflection()->HasField(*message, field_descriptor);
}
-const FieldDescriptor* FindFieldWithOneofs(const Message* message,
- ConstStringParam field_name,
- bool* in_oneof) {
+const FieldDescriptor* FindFieldWithOneofs(const Message* message,
+ ConstStringParam field_name,
+ bool* in_oneof) {
*in_oneof = false;
const Descriptor* descriptor = message->GetDescriptor();
const FieldDescriptor* field_descriptor =
@@ -1415,20 +1415,20 @@ const FieldDescriptor* FindFieldWithOneofs(const Message* message,
}
bool CheckHasPresence(const FieldDescriptor* field_descriptor, bool in_oneof) {
- auto message_name = field_descriptor->containing_type()->name();
+ auto message_name = field_descriptor->containing_type()->name();
if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
PyErr_Format(PyExc_ValueError,
- "Protocol message %s has no singular \"%s\" field.",
- message_name.c_str(), field_descriptor->name().c_str());
+ "Protocol message %s has no singular \"%s\" field.",
+ message_name.c_str(), field_descriptor->name().c_str());
return false;
}
- if (!field_descriptor->has_presence()) {
- PyErr_Format(PyExc_ValueError,
- "Can't test non-optional, non-submessage field \"%s.%s\" for "
- "presence in proto3.",
- message_name.c_str(), field_descriptor->name().c_str());
- return false;
+ if (!field_descriptor->has_presence()) {
+ PyErr_Format(PyExc_ValueError,
+ "Can't test non-optional, non-submessage field \"%s.%s\" for "
+ "presence in proto3.",
+ message_name.c_str(), field_descriptor->name().c_str());
+ return false;
}
return true;
@@ -1451,11 +1451,11 @@ PyObject* HasField(CMessage* self, PyObject* arg) {
Message* message = self->message;
bool is_in_oneof;
const FieldDescriptor* field_descriptor =
- FindFieldWithOneofs(message, StringParam(field_name, size), &is_in_oneof);
+ FindFieldWithOneofs(message, StringParam(field_name, size), &is_in_oneof);
if (field_descriptor == NULL) {
if (!is_in_oneof) {
- PyErr_Format(PyExc_ValueError, "Protocol message %s has no field %s.",
- message->GetDescriptor()->name().c_str(), field_name);
+ PyErr_Format(PyExc_ValueError, "Protocol message %s has no field %s.",
+ message->GetDescriptor()->name().c_str(), field_name);
return NULL;
} else {
Py_RETURN_FALSE;
@@ -1469,7 +1469,7 @@ PyObject* HasField(CMessage* self, PyObject* arg) {
if (message->GetReflection()->HasField(*message, field_descriptor)) {
Py_RETURN_TRUE;
}
-
+
Py_RETURN_FALSE;
}
@@ -1478,10 +1478,10 @@ PyObject* ClearExtension(CMessage* self, PyObject* extension) {
if (descriptor == NULL) {
return NULL;
}
- if (ClearFieldByDescriptor(self, descriptor) < 0) {
- return nullptr;
+ if (ClearFieldByDescriptor(self, descriptor) < 0) {
+ return nullptr;
}
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
PyObject* HasExtension(CMessage* self, PyObject* extension) {
@@ -1489,12 +1489,12 @@ PyObject* HasExtension(CMessage* self, PyObject* extension) {
if (descriptor == NULL) {
return NULL;
}
- int has_field = HasFieldByDescriptor(self, descriptor);
- if (has_field < 0) {
- return nullptr;
- } else {
- return PyBool_FromLong(has_field);
- }
+ int has_field = HasFieldByDescriptor(self, descriptor);
+ if (has_field < 0) {
+ return nullptr;
+ } else {
+ return PyBool_FromLong(has_field);
+ }
}
// ---------------------------------------------------------------------
@@ -1502,188 +1502,188 @@ PyObject* HasExtension(CMessage* self, PyObject* extension) {
//
// The Python API's ClearField() and Clear() methods behave
// differently than their C++ counterparts. While the C++ versions
-// clears the children, the Python versions detaches the children,
+// clears the children, the Python versions detaches the children,
// without touching their content. This impedance mismatch causes
// some complexity in the implementation, which is captured in this
// section.
//
-// When one or multiple fields are cleared we need to:
+// When one or multiple fields are cleared we need to:
//
-// * Gather all child objects that need to be detached from the message.
-// In composite_fields and child_submessages.
+// * Gather all child objects that need to be detached from the message.
+// In composite_fields and child_submessages.
//
-// * Create a new Python message of the same kind. Use SwapFields() to move
-// data from the original message.
+// * Create a new Python message of the same kind. Use SwapFields() to move
+// data from the original message.
//
-// * Change the parent of all child objects: update their strong reference
-// to their parent, and move their presence in composite_fields and
-// child_submessages.
+// * Change the parent of all child objects: update their strong reference
+// to their parent, and move their presence in composite_fields and
+// child_submessages.
-// ---------------------------------------------------------------------
-// Release a composite child of a CMessage
+// ---------------------------------------------------------------------
+// Release a composite child of a CMessage
-static int InternalReparentFields(
- CMessage* self, const std::vector<CMessage*>& messages_to_release,
- const std::vector<ContainerBase*>& containers_to_release) {
- if (messages_to_release.empty() && containers_to_release.empty()) {
+static int InternalReparentFields(
+ CMessage* self, const std::vector<CMessage*>& messages_to_release,
+ const std::vector<ContainerBase*>& containers_to_release) {
+ if (messages_to_release.empty() && containers_to_release.empty()) {
return 0;
}
- // Move all the passed sub_messages to another message.
- CMessage* new_message = cmessage::NewEmptyMessage(self->GetMessageClass());
- if (new_message == nullptr) {
- return -1;
- }
- new_message->message = self->message->New(nullptr);
- ScopedPyObjectPtr holder(reinterpret_cast<PyObject*>(new_message));
- new_message->child_submessages = new CMessage::SubMessagesMap();
- new_message->composite_fields = new CMessage::CompositeFieldsMap();
- std::set<const FieldDescriptor*> fields_to_swap;
-
- // In case this the removed fields are the last reference to a message, keep
- // a reference.
- Py_INCREF(self);
-
- for (const auto& to_release : messages_to_release) {
- fields_to_swap.insert(to_release->parent_field_descriptor);
- // Reparent
- Py_INCREF(new_message);
- Py_DECREF(to_release->parent);
- to_release->parent = new_message;
- self->child_submessages->erase(to_release->message);
- new_message->child_submessages->emplace(to_release->message, to_release);
- }
-
- for (const auto& to_release : containers_to_release) {
- fields_to_swap.insert(to_release->parent_field_descriptor);
- Py_INCREF(new_message);
- Py_DECREF(to_release->parent);
- to_release->parent = new_message;
- self->composite_fields->erase(to_release->parent_field_descriptor);
- new_message->composite_fields->emplace(to_release->parent_field_descriptor,
- to_release);
- }
-
- if (self->message->GetArena() == new_message->message->GetArena()) {
- MessageReflectionFriend::UnsafeShallowSwapFields(
- self->message, new_message->message,
- std::vector<const FieldDescriptor*>(fields_to_swap.begin(),
- fields_to_swap.end()));
- } else {
- self->message->GetReflection()->SwapFields(
- self->message, new_message->message,
- std::vector<const FieldDescriptor*>(fields_to_swap.begin(),
- fields_to_swap.end()));
- }
-
- // This might delete the Python message completely if all children were moved.
- Py_DECREF(self);
-
+ // Move all the passed sub_messages to another message.
+ CMessage* new_message = cmessage::NewEmptyMessage(self->GetMessageClass());
+ if (new_message == nullptr) {
+ return -1;
+ }
+ new_message->message = self->message->New(nullptr);
+ ScopedPyObjectPtr holder(reinterpret_cast<PyObject*>(new_message));
+ new_message->child_submessages = new CMessage::SubMessagesMap();
+ new_message->composite_fields = new CMessage::CompositeFieldsMap();
+ std::set<const FieldDescriptor*> fields_to_swap;
+
+ // In case this the removed fields are the last reference to a message, keep
+ // a reference.
+ Py_INCREF(self);
+
+ for (const auto& to_release : messages_to_release) {
+ fields_to_swap.insert(to_release->parent_field_descriptor);
+ // Reparent
+ Py_INCREF(new_message);
+ Py_DECREF(to_release->parent);
+ to_release->parent = new_message;
+ self->child_submessages->erase(to_release->message);
+ new_message->child_submessages->emplace(to_release->message, to_release);
+ }
+
+ for (const auto& to_release : containers_to_release) {
+ fields_to_swap.insert(to_release->parent_field_descriptor);
+ Py_INCREF(new_message);
+ Py_DECREF(to_release->parent);
+ to_release->parent = new_message;
+ self->composite_fields->erase(to_release->parent_field_descriptor);
+ new_message->composite_fields->emplace(to_release->parent_field_descriptor,
+ to_release);
+ }
+
+ if (self->message->GetArena() == new_message->message->GetArena()) {
+ MessageReflectionFriend::UnsafeShallowSwapFields(
+ self->message, new_message->message,
+ std::vector<const FieldDescriptor*>(fields_to_swap.begin(),
+ fields_to_swap.end()));
+ } else {
+ self->message->GetReflection()->SwapFields(
+ self->message, new_message->message,
+ std::vector<const FieldDescriptor*>(fields_to_swap.begin(),
+ fields_to_swap.end()));
+ }
+
+ // This might delete the Python message completely if all children were moved.
+ Py_DECREF(self);
+
return 0;
}
-int InternalReleaseFieldByDescriptor(
- CMessage* self,
- const FieldDescriptor* field_descriptor) {
- if (!field_descriptor->is_repeated() &&
- field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
- // Single scalars are not in any cache.
- return 0;
+int InternalReleaseFieldByDescriptor(
+ CMessage* self,
+ const FieldDescriptor* field_descriptor) {
+ if (!field_descriptor->is_repeated() &&
+ field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
+ // Single scalars are not in any cache.
+ return 0;
}
- std::vector<CMessage*> messages_to_release;
- std::vector<ContainerBase*> containers_to_release;
- if (self->child_submessages && field_descriptor->is_repeated() &&
- field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- for (const auto& child_item : *self->child_submessages) {
- if (child_item.second->parent_field_descriptor == field_descriptor) {
- messages_to_release.push_back(child_item.second);
- }
- }
+ std::vector<CMessage*> messages_to_release;
+ std::vector<ContainerBase*> containers_to_release;
+ if (self->child_submessages && field_descriptor->is_repeated() &&
+ field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ for (const auto& child_item : *self->child_submessages) {
+ if (child_item.second->parent_field_descriptor == field_descriptor) {
+ messages_to_release.push_back(child_item.second);
+ }
+ }
}
- if (self->composite_fields) {
- CMessage::CompositeFieldsMap::iterator it =
- self->composite_fields->find(field_descriptor);
- if (it != self->composite_fields->end()) {
- containers_to_release.push_back(it->second);
- }
+ if (self->composite_fields) {
+ CMessage::CompositeFieldsMap::iterator it =
+ self->composite_fields->find(field_descriptor);
+ if (it != self->composite_fields->end()) {
+ containers_to_release.push_back(it->second);
+ }
}
- return InternalReparentFields(self, messages_to_release,
- containers_to_release);
+ return InternalReparentFields(self, messages_to_release,
+ containers_to_release);
}
-int ClearFieldByDescriptor(CMessage* self,
- const FieldDescriptor* field_descriptor) {
+int ClearFieldByDescriptor(CMessage* self,
+ const FieldDescriptor* field_descriptor) {
if (!CheckFieldBelongsToMessage(field_descriptor, self->message)) {
- return -1;
- }
- if (InternalReleaseFieldByDescriptor(self, field_descriptor) < 0) {
- return -1;
+ return -1;
}
+ if (InternalReleaseFieldByDescriptor(self, field_descriptor) < 0) {
+ return -1;
+ }
AssureWritable(self);
Message* message = self->message;
message->GetReflection()->ClearField(message, field_descriptor);
- return 0;
+ return 0;
}
PyObject* ClearField(CMessage* self, PyObject* arg) {
- char* field_name;
- Py_ssize_t field_size;
- if (PyString_AsStringAndSize(arg, &field_name, &field_size) < 0) {
+ char* field_name;
+ Py_ssize_t field_size;
+ if (PyString_AsStringAndSize(arg, &field_name, &field_size) < 0) {
return NULL;
}
AssureWritable(self);
bool is_in_oneof;
- const FieldDescriptor* field_descriptor = FindFieldWithOneofs(
- self->message, StringParam(field_name, field_size), &is_in_oneof);
+ const FieldDescriptor* field_descriptor = FindFieldWithOneofs(
+ self->message, StringParam(field_name, field_size), &is_in_oneof);
if (field_descriptor == NULL) {
- if (is_in_oneof) {
- // We gave the name of a oneof, and none of its fields are set.
- Py_RETURN_NONE;
- } else {
+ if (is_in_oneof) {
+ // We gave the name of a oneof, and none of its fields are set.
+ Py_RETURN_NONE;
+ } else {
PyErr_Format(PyExc_ValueError,
"Protocol message has no \"%s\" field.", field_name);
return NULL;
}
}
- if (ClearFieldByDescriptor(self, field_descriptor) < 0) {
- return nullptr;
+ if (ClearFieldByDescriptor(self, field_descriptor) < 0) {
+ return nullptr;
}
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
PyObject* Clear(CMessage* self) {
AssureWritable(self);
- // Detach all current fields of this message
- std::vector<CMessage*> messages_to_release;
- std::vector<ContainerBase*> containers_to_release;
- if (self->child_submessages) {
- for (const auto& item : *self->child_submessages) {
- messages_to_release.push_back(item.second);
- }
- }
+ // Detach all current fields of this message
+ std::vector<CMessage*> messages_to_release;
+ std::vector<ContainerBase*> containers_to_release;
+ if (self->child_submessages) {
+ for (const auto& item : *self->child_submessages) {
+ messages_to_release.push_back(item.second);
+ }
+ }
if (self->composite_fields) {
- for (const auto& item : *self->composite_fields) {
- containers_to_release.push_back(item.second);
- }
- }
- if (InternalReparentFields(self, messages_to_release, containers_to_release) <
- 0) {
- return NULL;
- }
- if (self->unknown_field_set) {
- unknown_fields::Clear(
- reinterpret_cast<PyUnknownFields*>(self->unknown_field_set));
- self->unknown_field_set = nullptr;
- }
+ for (const auto& item : *self->composite_fields) {
+ containers_to_release.push_back(item.second);
+ }
+ }
+ if (InternalReparentFields(self, messages_to_release, containers_to_release) <
+ 0) {
+ return NULL;
+ }
+ if (self->unknown_field_set) {
+ unknown_fields::Clear(
+ reinterpret_cast<PyUnknownFields*>(self->unknown_field_set));
+ self->unknown_field_set = nullptr;
+ }
self->message->Clear();
Py_RETURN_NONE;
}
// ---------------------------------------------------------------------
-static TProtoStringType GetMessageName(CMessage* self) {
+static TProtoStringType GetMessageName(CMessage* self) {
if (self->parent_field_descriptor != NULL) {
return self->parent_field_descriptor->full_name();
} else {
@@ -1695,10 +1695,10 @@ static PyObject* InternalSerializeToString(
CMessage* self, PyObject* args, PyObject* kwargs,
bool require_initialized) {
// Parse the "deterministic" kwarg; defaults to False.
- static const char* kwlist[] = {"deterministic", 0};
+ static const char* kwlist[] = {"deterministic", 0};
PyObject* deterministic_obj = Py_None;
- if (!PyArg_ParseTupleAndKeywords(
- args, kwargs, "|O", const_cast<char**>(kwlist), &deterministic_obj)) {
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kwargs, "|O", const_cast<char**>(kwlist), &deterministic_obj)) {
return NULL;
}
// Preemptively convert to a bool first, so we don't need to back out of
@@ -1753,15 +1753,15 @@ static PyObject* InternalSerializeToString(
if (size == 0) {
return PyBytes_FromString("");
}
-
- if (size > INT_MAX) {
- PyErr_Format(PyExc_ValueError,
- "Message %s exceeds maximum protobuf "
- "size of 2GB: %zu",
- GetMessageName(self).c_str(), size);
- return nullptr;
- }
-
+
+ if (size > INT_MAX) {
+ PyErr_Format(PyExc_ValueError,
+ "Message %s exceeds maximum protobuf "
+ "size of 2GB: %zu",
+ GetMessageName(self).c_str(), size);
+ return nullptr;
+ }
+
PyObject* result = PyBytes_FromStringAndSize(NULL, size);
if (result == NULL) {
return NULL;
@@ -1790,7 +1790,7 @@ static PyObject* SerializePartialToString(
// Formats proto fields for ascii dumps using python formatting functions where
// appropriate.
-class PythonFieldValuePrinter : public TextFormat::FastFieldValuePrinter {
+class PythonFieldValuePrinter : public TextFormat::FastFieldValuePrinter {
public:
// Python has some differences from C++ when printing floating point numbers.
//
@@ -1802,12 +1802,12 @@ class PythonFieldValuePrinter : public TextFormat::FastFieldValuePrinter {
//
// We override floating point printing with the C-API function for printing
// Python floats to ensure consistency.
- void PrintFloat(float val,
- TextFormat::BaseTextGenerator* generator) const override {
- PrintDouble(val, generator);
- }
- void PrintDouble(double val,
- TextFormat::BaseTextGenerator* generator) const override {
+ void PrintFloat(float val,
+ TextFormat::BaseTextGenerator* generator) const override {
+ PrintDouble(val, generator);
+ }
+ void PrintDouble(double val,
+ TextFormat::BaseTextGenerator* generator) const override {
// This implementation is not highly optimized (it allocates two temporary
// Python objects) but it is simple and portable. If this is shown to be a
// performance bottleneck, we can optimize it, but the results will likely
@@ -1816,17 +1816,17 @@ class PythonFieldValuePrinter : public TextFormat::FastFieldValuePrinter {
//
// (Though a valid question is: do we really want to make out output
// dependent on the Python version?)
- ScopedPyObjectPtr py_value(PyFloat_FromDouble(val));
+ ScopedPyObjectPtr py_value(PyFloat_FromDouble(val));
if (!py_value.get()) {
- return;
+ return;
}
ScopedPyObjectPtr py_str(PyObject_Str(py_value.get()));
if (!py_str.get()) {
- return;
+ return;
}
- generator->PrintString(PyString_AsString(py_str.get()));
+ generator->PrintString(PyString_AsString(py_str.get()));
}
};
@@ -1835,7 +1835,7 @@ static PyObject* ToStr(CMessage* self) {
// Passes ownership
printer.SetDefaultFieldValuePrinter(new PythonFieldValuePrinter());
printer.SetHideUnknownFields(true);
- TProtoStringType output;
+ TProtoStringType output;
if (!printer.PrintToString(*self->message, &output)) {
PyErr_SetString(PyExc_ValueError, "Unable to convert message to str");
return NULL;
@@ -1845,7 +1845,7 @@ static PyObject* ToStr(CMessage* self) {
PyObject* MergeFrom(CMessage* self, PyObject* arg) {
CMessage* other_message;
- if (!PyObject_TypeCheck(arg, CMessage_Type)) {
+ if (!PyObject_TypeCheck(arg, CMessage_Type)) {
PyErr_Format(PyExc_TypeError,
"Parameter to MergeFrom() must be instance of same class: "
"expected %s got %s.",
@@ -1866,19 +1866,19 @@ PyObject* MergeFrom(CMessage* self, PyObject* arg) {
}
AssureWritable(self);
- self->message->MergeFrom(*other_message->message);
- // Child message might be lazily created before MergeFrom. Make sure they
- // are mutable at this point if child messages are really created.
- if (FixupMessageAfterMerge(self) < 0) {
- return NULL;
- }
+ self->message->MergeFrom(*other_message->message);
+ // Child message might be lazily created before MergeFrom. Make sure they
+ // are mutable at this point if child messages are really created.
+ if (FixupMessageAfterMerge(self) < 0) {
+ return NULL;
+ }
Py_RETURN_NONE;
}
static PyObject* CopyFrom(CMessage* self, PyObject* arg) {
CMessage* other_message;
- if (!PyObject_TypeCheck(arg, CMessage_Type)) {
+ if (!PyObject_TypeCheck(arg, CMessage_Type)) {
PyErr_Format(PyExc_TypeError,
"Parameter to CopyFrom() must be instance of same class: "
"expected %s got %s.",
@@ -1943,48 +1943,48 @@ PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg) {
}
static PyObject* MergeFromString(CMessage* self, PyObject* arg) {
- Py_buffer data;
- if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) < 0) {
+ Py_buffer data;
+ if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) < 0) {
return NULL;
}
AssureWritable(self);
-
+
PyMessageFactory* factory = GetFactoryForMessage(self);
- int depth = allow_oversize_protos
- ? INT_MAX
- : io::CodedInputStream::GetDefaultRecursionLimit();
- const char* ptr;
- internal::ParseContext ctx(
- depth, false, &ptr,
- StringPiece(static_cast<const char*>(data.buf), data.len));
- PyBuffer_Release(&data);
- ctx.data().pool = factory->pool->pool;
- ctx.data().factory = factory->message_factory;
-
- ptr = self->message->_InternalParse(ptr, &ctx);
-
- // Child message might be lazily created before MergeFrom. Make sure they
- // are mutable at this point if child messages are really created.
- if (FixupMessageAfterMerge(self) < 0) {
- return NULL;
- }
-
- // Python makes distinction in error message, between a general parse failure
- // and in-correct ending on a terminating tag. Hence we need to be a bit more
- // explicit in our correctness checks.
- if (ptr == nullptr || ctx.BytesUntilLimit(ptr) < 0) {
- // Parse error or the parser overshoot the limit.
- PyErr_Format(DecodeError_class, "Error parsing message");
- return NULL;
- }
- // ctx has an explicit limit set (length of string_view), so we have to
- // check we ended at that limit.
- if (!ctx.EndedAtLimit()) {
- PyErr_Format(DecodeError_class, "Unexpected end-group tag: Not all data was converted");
- return nullptr;
- }
- return PyInt_FromLong(data.len);
+ int depth = allow_oversize_protos
+ ? INT_MAX
+ : io::CodedInputStream::GetDefaultRecursionLimit();
+ const char* ptr;
+ internal::ParseContext ctx(
+ depth, false, &ptr,
+ StringPiece(static_cast<const char*>(data.buf), data.len));
+ PyBuffer_Release(&data);
+ ctx.data().pool = factory->pool->pool;
+ ctx.data().factory = factory->message_factory;
+
+ ptr = self->message->_InternalParse(ptr, &ctx);
+
+ // Child message might be lazily created before MergeFrom. Make sure they
+ // are mutable at this point if child messages are really created.
+ if (FixupMessageAfterMerge(self) < 0) {
+ return NULL;
+ }
+
+ // Python makes distinction in error message, between a general parse failure
+ // and in-correct ending on a terminating tag. Hence we need to be a bit more
+ // explicit in our correctness checks.
+ if (ptr == nullptr || ctx.BytesUntilLimit(ptr) < 0) {
+ // Parse error or the parser overshoot the limit.
+ PyErr_Format(DecodeError_class, "Error parsing message");
+ return NULL;
+ }
+ // ctx has an explicit limit set (length of string_view), so we have to
+ // check we ended at that limit.
+ if (!ctx.EndedAtLimit()) {
+ PyErr_Format(DecodeError_class, "Unexpected end-group tag: Not all data was converted");
+ return nullptr;
+ }
+ return PyInt_FromLong(data.len);
}
static PyObject* ParseFromString(CMessage* self, PyObject* arg) {
@@ -1995,7 +1995,7 @@ static PyObject* ParseFromString(CMessage* self, PyObject* arg) {
}
static PyObject* ByteSize(CMessage* self, PyObject* args) {
- return PyLong_FromLong(self->message->ByteSizeLong());
+ return PyLong_FromLong(self->message->ByteSizeLong());
}
PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle) {
@@ -2004,7 +2004,7 @@ PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle) {
if (descriptor == NULL) {
return NULL;
}
- if (!PyObject_TypeCheck(cls, CMessageClass_Type)) {
+ if (!PyObject_TypeCheck(cls, CMessageClass_Type)) {
PyErr_Format(PyExc_TypeError, "Expected a message class, got %s",
cls->ob_type->tp_name);
return NULL;
@@ -2035,11 +2035,11 @@ static PyObject* WhichOneof(CMessage* self, PyObject* arg) {
if (PyString_AsStringAndSize(arg, &name_data, &name_size) < 0)
return NULL;
const OneofDescriptor* oneof_desc =
- self->message->GetDescriptor()->FindOneofByName(
- StringParam(name_data, name_size));
+ self->message->GetDescriptor()->FindOneofByName(
+ StringParam(name_data, name_size));
if (oneof_desc == NULL) {
PyErr_Format(PyExc_ValueError,
- "Protocol message has no oneof \"%s\" field.", name_data);
+ "Protocol message has no oneof \"%s\" field.", name_data);
return NULL;
}
const FieldDescriptor* field_in_oneof =
@@ -2048,7 +2048,7 @@ static PyObject* WhichOneof(CMessage* self, PyObject* arg) {
if (field_in_oneof == NULL) {
Py_RETURN_NONE;
} else {
- const TProtoStringType& name = field_in_oneof->name();
+ const TProtoStringType& name = field_in_oneof->name();
return PyString_FromStringAndSize(name.c_str(), name.size());
}
}
@@ -2113,9 +2113,9 @@ static PyObject* ListFields(CMessage* self) {
return NULL;
}
- PyObject* field_value = GetFieldValue(self, fields[i]);
+ PyObject* field_value = GetFieldValue(self, fields[i]);
if (field_value == NULL) {
- PyErr_SetString(PyExc_ValueError, fields[i]->name().c_str());
+ PyErr_SetString(PyExc_ValueError, fields[i]->name().c_str());
return NULL;
}
PyTuple_SET_ITEM(t.get(), 0, field_descriptor.release());
@@ -2140,7 +2140,7 @@ static PyObject* DiscardUnknownFields(CMessage* self) {
PyObject* FindInitializationErrors(CMessage* self) {
Message* message = self->message;
- std::vector<TProtoStringType> errors;
+ std::vector<TProtoStringType> errors;
message->FindInitializationErrors(&errors);
PyObject* error_list = PyList_New(errors.size());
@@ -2148,7 +2148,7 @@ PyObject* FindInitializationErrors(CMessage* self) {
return NULL;
}
for (size_t i = 0; i < errors.size(); ++i) {
- const TProtoStringType& error = errors[i];
+ const TProtoStringType& error = errors[i];
PyObject* error_string = PyString_FromStringAndSize(
error.c_str(), error.length());
if (error_string == NULL) {
@@ -2168,25 +2168,25 @@ static PyObject* RichCompare(CMessage* self, PyObject* other, int opid) {
}
bool equals = true;
// If other is not a message, it cannot be equal.
- if (!PyObject_TypeCheck(other, CMessage_Type)) {
+ if (!PyObject_TypeCheck(other, CMessage_Type)) {
equals = false;
- } else {
- // Otherwise, we have a CMessage whose message we can inspect.
- const google::protobuf::Message* other_message =
- reinterpret_cast<CMessage*>(other)->message;
- // If messages don't have the same descriptors, they are not equal.
- if (equals &&
- self->message->GetDescriptor() != other_message->GetDescriptor()) {
- equals = false;
- }
- // Check the message contents.
- if (equals &&
- !google::protobuf::util::MessageDifferencer::Equals(
- *self->message, *reinterpret_cast<CMessage*>(other)->message)) {
- equals = false;
- }
- }
-
+ } else {
+ // Otherwise, we have a CMessage whose message we can inspect.
+ const google::protobuf::Message* other_message =
+ reinterpret_cast<CMessage*>(other)->message;
+ // If messages don't have the same descriptors, they are not equal.
+ if (equals &&
+ self->message->GetDescriptor() != other_message->GetDescriptor()) {
+ equals = false;
+ }
+ // Check the message contents.
+ if (equals &&
+ !google::protobuf::util::MessageDifferencer::Equals(
+ *self->message, *reinterpret_cast<CMessage*>(other)->message)) {
+ equals = false;
+ }
+ }
+
if (equals ^ (opid == Py_EQ)) {
Py_RETURN_FALSE;
} else {
@@ -2205,22 +2205,22 @@ PyObject* InternalGetScalar(const Message* message,
PyObject* result = NULL;
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
- int32_t value = reflection->GetInt32(*message, field_descriptor);
+ int32_t value = reflection->GetInt32(*message, field_descriptor);
result = PyInt_FromLong(value);
break;
}
case FieldDescriptor::CPPTYPE_INT64: {
- int64_t value = reflection->GetInt64(*message, field_descriptor);
+ int64_t value = reflection->GetInt64(*message, field_descriptor);
result = PyLong_FromLongLong(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT32: {
- uint32_t value = reflection->GetUInt32(*message, field_descriptor);
+ uint32_t value = reflection->GetUInt32(*message, field_descriptor);
result = PyInt_FromSize_t(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT64: {
- uint64_t value = reflection->GetUInt64(*message, field_descriptor);
+ uint64_t value = reflection->GetUInt64(*message, field_descriptor);
result = PyLong_FromUnsignedLongLong(value);
break;
}
@@ -2240,16 +2240,16 @@ PyObject* InternalGetScalar(const Message* message,
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- TProtoStringType scratch;
- const TProtoStringType& value =
- reflection->GetStringReference(*message, field_descriptor, &scratch);
+ TProtoStringType scratch;
+ const TProtoStringType& value =
+ reflection->GetStringReference(*message, field_descriptor, &scratch);
result = ToStringObject(field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_ENUM: {
- const EnumValueDescriptor* enum_value =
- message->GetReflection()->GetEnum(*message, field_descriptor);
- result = PyInt_FromLong(enum_value->number());
+ const EnumValueDescriptor* enum_value =
+ message->GetReflection()->GetEnum(*message, field_descriptor);
+ result = PyInt_FromLong(enum_value->number());
break;
}
default:
@@ -2261,7 +2261,7 @@ PyObject* InternalGetScalar(const Message* message,
return result;
}
-CMessage* InternalGetSubMessage(
+CMessage* InternalGetSubMessage(
CMessage* self, const FieldDescriptor* field_descriptor) {
const Reflection* reflection = self->message->GetReflection();
PyMessageFactory* factory = GetFactoryForMessage(self);
@@ -2270,7 +2270,7 @@ CMessage* InternalGetSubMessage(
CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
factory, field_descriptor->message_type());
- ScopedPyObjectPtr message_class_owner(
+ ScopedPyObjectPtr message_class_owner(
reinterpret_cast<PyObject*>(message_class));
if (message_class == NULL) {
return NULL;
@@ -2281,12 +2281,12 @@ CMessage* InternalGetSubMessage(
return NULL;
}
- Py_INCREF(self);
+ Py_INCREF(self);
cmsg->parent = self;
cmsg->parent_field_descriptor = field_descriptor;
cmsg->read_only = !reflection->HasField(*self->message, field_descriptor);
cmsg->message = const_cast<Message*>(&sub_message);
- return cmsg;
+ return cmsg;
}
int InternalSetNonOneofScalar(
@@ -2407,7 +2407,7 @@ PyObject* DeepCopy(CMessage* self, PyObject* arg) {
if (clone == NULL) {
return NULL;
}
- if (!PyObject_TypeCheck(clone, CMessage_Type)) {
+ if (!PyObject_TypeCheck(clone, CMessage_Type)) {
Py_DECREF(clone);
return NULL;
}
@@ -2465,27 +2465,27 @@ static PyObject* GetExtensionDict(CMessage* self, void *closure) {
// If there are extension_ranges, the message is "extendable". Allocate a
// dictionary to store the extension fields.
const Descriptor* descriptor = GetMessageDescriptor(Py_TYPE(self));
- if (!descriptor->extension_range_count()) {
- PyErr_SetNone(PyExc_AttributeError);
- return NULL;
- }
- if (!self->composite_fields) {
- self->composite_fields = new CMessage::CompositeFieldsMap();
- }
- if (!self->composite_fields) {
- return NULL;
- }
- ExtensionDict* extension_dict = extension_dict::NewExtensionDict(self);
- return reinterpret_cast<PyObject*>(extension_dict);
-}
-
-static PyObject* UnknownFieldSet(CMessage* self) {
- if (self->unknown_field_set == NULL) {
- self->unknown_field_set = unknown_fields::NewPyUnknownFields(self);
- } else {
- Py_INCREF(self->unknown_field_set);
- }
- return self->unknown_field_set;
+ if (!descriptor->extension_range_count()) {
+ PyErr_SetNone(PyExc_AttributeError);
+ return NULL;
+ }
+ if (!self->composite_fields) {
+ self->composite_fields = new CMessage::CompositeFieldsMap();
+ }
+ if (!self->composite_fields) {
+ return NULL;
+ }
+ ExtensionDict* extension_dict = extension_dict::NewExtensionDict(self);
+ return reinterpret_cast<PyObject*>(extension_dict);
+}
+
+static PyObject* UnknownFieldSet(CMessage* self) {
+ if (self->unknown_field_set == NULL) {
+ self->unknown_field_set = unknown_fields::NewPyUnknownFields(self);
+ } else {
+ Py_INCREF(self->unknown_field_set);
+ }
+ return self->unknown_field_set;
}
static PyObject* GetExtensionsByName(CMessage *self, void *closure) {
@@ -2552,8 +2552,8 @@ static PyMethodDef Methods[] = {
"Serializes the message to a string, only for initialized messages." },
{ "SetInParent", (PyCFunction)SetInParent, METH_NOARGS,
"Sets the has bit of the given field in its parent message." },
- { "UnknownFields", (PyCFunction)UnknownFieldSet, METH_NOARGS,
- "Parse unknown field set"},
+ { "UnknownFields", (PyCFunction)UnknownFieldSet, METH_NOARGS,
+ "Parse unknown field set"},
{ "WhichOneof", (PyCFunction)WhichOneof, METH_O,
"Returns the name of the field set inside a oneof, "
"or None if no field is set." },
@@ -2565,65 +2565,65 @@ static PyMethodDef Methods[] = {
{ NULL, NULL}
};
-bool SetCompositeField(CMessage* self, const FieldDescriptor* field,
- ContainerBase* value) {
+bool SetCompositeField(CMessage* self, const FieldDescriptor* field,
+ ContainerBase* value) {
if (self->composite_fields == NULL) {
- self->composite_fields = new CMessage::CompositeFieldsMap();
- }
- (*self->composite_fields)[field] = value;
- return true;
-}
-
-bool SetSubmessage(CMessage* self, CMessage* submessage) {
- if (self->child_submessages == NULL) {
- self->child_submessages = new CMessage::SubMessagesMap();
- }
- (*self->child_submessages)[submessage->message] = submessage;
- return true;
-}
-
-PyObject* GetAttr(PyObject* pself, PyObject* name) {
- CMessage* self = reinterpret_cast<CMessage*>(pself);
- PyObject* result = PyObject_GenericGetAttr(
- reinterpret_cast<PyObject*>(self), name);
- if (result != NULL) {
- return result;
- }
- if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
- return NULL;
- }
-
- PyErr_Clear();
- return message_meta::GetClassAttribute(
- CheckMessageClass(Py_TYPE(self)), name);
-}
-
-PyObject* GetFieldValue(CMessage* self,
- const FieldDescriptor* field_descriptor) {
- if (self->composite_fields) {
- CMessage::CompositeFieldsMap::iterator it =
- self->composite_fields->find(field_descriptor);
- if (it != self->composite_fields->end()) {
- ContainerBase* value = it->second;
- Py_INCREF(value);
- return value->AsPyObject();
- }
- }
-
- if (self->message->GetDescriptor() != field_descriptor->containing_type()) {
- PyErr_Format(PyExc_TypeError,
- "descriptor to field '%s' doesn't apply to '%s' object",
- field_descriptor->full_name().c_str(),
- Py_TYPE(self)->tp_name);
- return NULL;
- }
-
- if (!field_descriptor->is_repeated() &&
- field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
- return InternalGetScalar(self->message, field_descriptor);
- }
-
- ContainerBase* py_container = nullptr;
+ self->composite_fields = new CMessage::CompositeFieldsMap();
+ }
+ (*self->composite_fields)[field] = value;
+ return true;
+}
+
+bool SetSubmessage(CMessage* self, CMessage* submessage) {
+ if (self->child_submessages == NULL) {
+ self->child_submessages = new CMessage::SubMessagesMap();
+ }
+ (*self->child_submessages)[submessage->message] = submessage;
+ return true;
+}
+
+PyObject* GetAttr(PyObject* pself, PyObject* name) {
+ CMessage* self = reinterpret_cast<CMessage*>(pself);
+ PyObject* result = PyObject_GenericGetAttr(
+ reinterpret_cast<PyObject*>(self), name);
+ if (result != NULL) {
+ return result;
+ }
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ return NULL;
+ }
+
+ PyErr_Clear();
+ return message_meta::GetClassAttribute(
+ CheckMessageClass(Py_TYPE(self)), name);
+}
+
+PyObject* GetFieldValue(CMessage* self,
+ const FieldDescriptor* field_descriptor) {
+ if (self->composite_fields) {
+ CMessage::CompositeFieldsMap::iterator it =
+ self->composite_fields->find(field_descriptor);
+ if (it != self->composite_fields->end()) {
+ ContainerBase* value = it->second;
+ Py_INCREF(value);
+ return value->AsPyObject();
+ }
+ }
+
+ if (self->message->GetDescriptor() != field_descriptor->containing_type()) {
+ PyErr_Format(PyExc_TypeError,
+ "descriptor to field '%s' doesn't apply to '%s' object",
+ field_descriptor->full_name().c_str(),
+ Py_TYPE(self)->tp_name);
+ return NULL;
+ }
+
+ if (!field_descriptor->is_repeated() &&
+ field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
+ return InternalGetScalar(self->message, field_descriptor);
+ }
+
+ ContainerBase* py_container = nullptr;
if (field_descriptor->is_map()) {
const Descriptor* entry_type = field_descriptor->message_type();
const FieldDescriptor* value_type = entry_type->FindFieldByName("value");
@@ -2638,7 +2638,7 @@ PyObject* GetFieldValue(CMessage* self,
} else {
py_container = NewScalarMapContainer(self, field_descriptor);
}
- } else if (field_descriptor->is_repeated()) {
+ } else if (field_descriptor->is_repeated()) {
if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
CMessageClass* message_class = message_factory::GetMessageClass(
GetFactoryForMessage(self), field_descriptor->message_type());
@@ -2648,129 +2648,129 @@ PyObject* GetFieldValue(CMessage* self,
py_container = repeated_composite_container::NewContainer(
self, field_descriptor, message_class);
} else {
- py_container =
- repeated_scalar_container::NewContainer(self, field_descriptor);
+ py_container =
+ repeated_scalar_container::NewContainer(self, field_descriptor);
}
- } else if (field_descriptor->cpp_type() ==
- FieldDescriptor::CPPTYPE_MESSAGE) {
- py_container = InternalGetSubMessage(self, field_descriptor);
- } else {
- PyErr_SetString(PyExc_SystemError, "Should never happen");
+ } else if (field_descriptor->cpp_type() ==
+ FieldDescriptor::CPPTYPE_MESSAGE) {
+ py_container = InternalGetSubMessage(self, field_descriptor);
+ } else {
+ PyErr_SetString(PyExc_SystemError, "Should never happen");
}
- if (py_container == NULL) {
- return NULL;
- }
- if (!SetCompositeField(self, field_descriptor, py_container)) {
- Py_DECREF(py_container);
- return NULL;
+ if (py_container == NULL) {
+ return NULL;
}
- return py_container->AsPyObject();
+ if (!SetCompositeField(self, field_descriptor, py_container)) {
+ Py_DECREF(py_container);
+ return NULL;
+ }
+ return py_container->AsPyObject();
}
-int SetFieldValue(CMessage* self, const FieldDescriptor* field_descriptor,
- PyObject* value) {
- if (self->message->GetDescriptor() != field_descriptor->containing_type()) {
- PyErr_Format(PyExc_TypeError,
- "descriptor to field '%s' doesn't apply to '%s' object",
- field_descriptor->full_name().c_str(),
- Py_TYPE(self)->tp_name);
+int SetFieldValue(CMessage* self, const FieldDescriptor* field_descriptor,
+ PyObject* value) {
+ if (self->message->GetDescriptor() != field_descriptor->containing_type()) {
+ PyErr_Format(PyExc_TypeError,
+ "descriptor to field '%s' doesn't apply to '%s' object",
+ field_descriptor->full_name().c_str(),
+ Py_TYPE(self)->tp_name);
return -1;
- } else if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
- PyErr_Format(PyExc_AttributeError,
- "Assignment not allowed to repeated "
- "field \"%s\" in protocol message object.",
- field_descriptor->name().c_str());
- return -1;
- } else if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- PyErr_Format(PyExc_AttributeError,
- "Assignment not allowed to "
- "field \"%s\" in protocol message object.",
- field_descriptor->name().c_str());
- return -1;
- } else {
- AssureWritable(self);
- return InternalSetScalar(self, field_descriptor, value);
- }
-}
-
-} // namespace cmessage
-
-// All containers which are not messages:
-// - Make a new parent message
-// - Copy the field
-// - return the field.
-PyObject* ContainerBase::DeepCopy() {
- CMessage* new_parent =
- cmessage::NewEmptyMessage(this->parent->GetMessageClass());
- new_parent->message = this->parent->message->New(nullptr);
-
- // Copy the map field into the new message.
- this->parent->message->GetReflection()->SwapFields(
- this->parent->message, new_parent->message,
- {this->parent_field_descriptor});
- this->parent->message->MergeFrom(*new_parent->message);
-
- PyObject* result =
- cmessage::GetFieldValue(new_parent, this->parent_field_descriptor);
- Py_DECREF(new_parent);
- return result;
-}
-
-void ContainerBase::RemoveFromParentCache() {
- CMessage* parent = this->parent;
- if (parent) {
- if (parent->composite_fields)
- parent->composite_fields->erase(this->parent_field_descriptor);
- Py_CLEAR(parent);
- }
-}
-
-CMessage* CMessage::BuildSubMessageFromPointer(
- const FieldDescriptor* field_descriptor, Message* sub_message,
- CMessageClass* message_class) {
- if (!this->child_submessages) {
- this->child_submessages = new CMessage::SubMessagesMap();
- }
- CMessage* cmsg = FindPtrOrNull(
- *this->child_submessages, sub_message);
- if (cmsg) {
- Py_INCREF(cmsg);
- } else {
- cmsg = cmessage::NewEmptyMessage(message_class);
-
- if (cmsg == NULL) {
- return NULL;
- }
- cmsg->message = sub_message;
- Py_INCREF(this);
- cmsg->parent = this;
- cmsg->parent_field_descriptor = field_descriptor;
- cmessage::SetSubmessage(this, cmsg);
- }
- return cmsg;
-}
-
-CMessage* CMessage::MaybeReleaseSubMessage(Message* sub_message) {
- if (!this->child_submessages) {
- return nullptr;
- }
- CMessage* released = FindPtrOrNull(
- *this->child_submessages, sub_message);
- if (!released) {
- return nullptr;
- }
- // The target message will now own its content.
- Py_CLEAR(released->parent);
- released->parent_field_descriptor = nullptr;
- released->read_only = false;
- // Delete it from the cache.
- this->child_submessages->erase(sub_message);
- return released;
-}
-
-static CMessageClass _CMessage_Type = { { {
- PyVarObject_HEAD_INIT(&_CMessageClass_Type, 0)
+ } else if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
+ PyErr_Format(PyExc_AttributeError,
+ "Assignment not allowed to repeated "
+ "field \"%s\" in protocol message object.",
+ field_descriptor->name().c_str());
+ return -1;
+ } else if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ PyErr_Format(PyExc_AttributeError,
+ "Assignment not allowed to "
+ "field \"%s\" in protocol message object.",
+ field_descriptor->name().c_str());
+ return -1;
+ } else {
+ AssureWritable(self);
+ return InternalSetScalar(self, field_descriptor, value);
+ }
+}
+
+} // namespace cmessage
+
+// All containers which are not messages:
+// - Make a new parent message
+// - Copy the field
+// - return the field.
+PyObject* ContainerBase::DeepCopy() {
+ CMessage* new_parent =
+ cmessage::NewEmptyMessage(this->parent->GetMessageClass());
+ new_parent->message = this->parent->message->New(nullptr);
+
+ // Copy the map field into the new message.
+ this->parent->message->GetReflection()->SwapFields(
+ this->parent->message, new_parent->message,
+ {this->parent_field_descriptor});
+ this->parent->message->MergeFrom(*new_parent->message);
+
+ PyObject* result =
+ cmessage::GetFieldValue(new_parent, this->parent_field_descriptor);
+ Py_DECREF(new_parent);
+ return result;
+}
+
+void ContainerBase::RemoveFromParentCache() {
+ CMessage* parent = this->parent;
+ if (parent) {
+ if (parent->composite_fields)
+ parent->composite_fields->erase(this->parent_field_descriptor);
+ Py_CLEAR(parent);
+ }
+}
+
+CMessage* CMessage::BuildSubMessageFromPointer(
+ const FieldDescriptor* field_descriptor, Message* sub_message,
+ CMessageClass* message_class) {
+ if (!this->child_submessages) {
+ this->child_submessages = new CMessage::SubMessagesMap();
+ }
+ CMessage* cmsg = FindPtrOrNull(
+ *this->child_submessages, sub_message);
+ if (cmsg) {
+ Py_INCREF(cmsg);
+ } else {
+ cmsg = cmessage::NewEmptyMessage(message_class);
+
+ if (cmsg == NULL) {
+ return NULL;
+ }
+ cmsg->message = sub_message;
+ Py_INCREF(this);
+ cmsg->parent = this;
+ cmsg->parent_field_descriptor = field_descriptor;
+ cmessage::SetSubmessage(this, cmsg);
+ }
+ return cmsg;
+}
+
+CMessage* CMessage::MaybeReleaseSubMessage(Message* sub_message) {
+ if (!this->child_submessages) {
+ return nullptr;
+ }
+ CMessage* released = FindPtrOrNull(
+ *this->child_submessages, sub_message);
+ if (!released) {
+ return nullptr;
+ }
+ // The target message will now own its content.
+ Py_CLEAR(released->parent);
+ released->parent_field_descriptor = nullptr;
+ released->read_only = false;
+ // Delete it from the cache.
+ this->child_submessages->erase(sub_message);
+ return released;
+}
+
+static CMessageClass _CMessage_Type = { { {
+ PyVarObject_HEAD_INIT(&_CMessageClass_Type, 0)
FULL_MODULE_NAME ".CMessage", // tp_name
sizeof(CMessage), // tp_basicsize
0, // tp_itemsize
@@ -2786,11 +2786,11 @@ static CMessageClass _CMessage_Type = { { {
PyObject_HashNotImplemented, // tp_hash
0, // tp_call
(reprfunc)cmessage::ToStr, // tp_str
- cmessage::GetAttr, // tp_getattro
- 0, // tp_setattro
+ cmessage::GetAttr, // tp_getattro
+ 0, // tp_setattro
0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
- | Py_TPFLAGS_HAVE_VERSION_TAG, // tp_flags
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
+ | Py_TPFLAGS_HAVE_VERSION_TAG, // tp_flags
"A ProtocolMessage", // tp_doc
0, // tp_traverse
0, // tp_clear
@@ -2809,121 +2809,121 @@ static CMessageClass _CMessage_Type = { { {
(initproc)cmessage::Init, // tp_init
0, // tp_alloc
cmessage::New, // tp_new
-} } };
-PyTypeObject* CMessage_Type = &_CMessage_Type.super.ht_type;
+} } };
+PyTypeObject* CMessage_Type = &_CMessage_Type.super.ht_type;
// --- Exposing the C proto living inside Python proto to C code:
-const Message* (*GetCProtoInsidePyProtoPtr)(PyObject* msg);
-Message* (*MutableCProtoInsidePyProtoPtr)(PyObject* msg);
+const Message* (*GetCProtoInsidePyProtoPtr)(PyObject* msg);
+Message* (*MutableCProtoInsidePyProtoPtr)(PyObject* msg);
static const Message* GetCProtoInsidePyProtoImpl(PyObject* msg) {
- const Message* message = PyMessage_GetMessagePointer(msg);
- if (message == NULL) {
- PyErr_Clear();
- return NULL;
- }
- return message;
-}
-
-static Message* MutableCProtoInsidePyProtoImpl(PyObject* msg) {
- Message* message = PyMessage_GetMutableMessagePointer(msg);
- if (message == NULL) {
- PyErr_Clear();
- return NULL;
- }
- return message;
-}
-
-const Message* PyMessage_GetMessagePointer(PyObject* msg) {
- if (!PyObject_TypeCheck(msg, CMessage_Type)) {
- PyErr_SetString(PyExc_TypeError, "Not a Message instance");
- return NULL;
- }
+ const Message* message = PyMessage_GetMessagePointer(msg);
+ if (message == NULL) {
+ PyErr_Clear();
+ return NULL;
+ }
+ return message;
+}
+
+static Message* MutableCProtoInsidePyProtoImpl(PyObject* msg) {
+ Message* message = PyMessage_GetMutableMessagePointer(msg);
+ if (message == NULL) {
+ PyErr_Clear();
+ return NULL;
+ }
+ return message;
+}
+
+const Message* PyMessage_GetMessagePointer(PyObject* msg) {
+ if (!PyObject_TypeCheck(msg, CMessage_Type)) {
+ PyErr_SetString(PyExc_TypeError, "Not a Message instance");
+ return NULL;
+ }
CMessage* cmsg = reinterpret_cast<CMessage*>(msg);
return cmsg->message;
}
-Message* PyMessage_GetMutableMessagePointer(PyObject* msg) {
- if (!PyObject_TypeCheck(msg, CMessage_Type)) {
- PyErr_SetString(PyExc_TypeError, "Not a Message instance");
+Message* PyMessage_GetMutableMessagePointer(PyObject* msg) {
+ if (!PyObject_TypeCheck(msg, CMessage_Type)) {
+ PyErr_SetString(PyExc_TypeError, "Not a Message instance");
return NULL;
}
CMessage* cmsg = reinterpret_cast<CMessage*>(msg);
-
-
- if ((cmsg->composite_fields && !cmsg->composite_fields->empty()) ||
- (cmsg->child_submessages && !cmsg->child_submessages->empty())) {
+
+
+ if ((cmsg->composite_fields && !cmsg->composite_fields->empty()) ||
+ (cmsg->child_submessages && !cmsg->child_submessages->empty())) {
// There is currently no way of accurately syncing arbitrary changes to
// the underlying C++ message back to the CMessage (e.g. removed repeated
// composite containers). We only allow direct mutation of the underlying
// C++ message if there is no child data in the CMessage.
- PyErr_SetString(PyExc_ValueError,
- "Cannot reliably get a mutable pointer "
- "to a message with extra references");
+ PyErr_SetString(PyExc_ValueError,
+ "Cannot reliably get a mutable pointer "
+ "to a message with extra references");
return NULL;
}
cmessage::AssureWritable(cmsg);
return cmsg->message;
}
-PyObject* PyMessage_New(const Descriptor* descriptor,
- PyObject* py_message_factory) {
- PyMessageFactory* factory = nullptr;
- if (py_message_factory == nullptr) {
- factory = GetDescriptorPool_FromPool(descriptor->file()->pool())
- ->py_message_factory;
- } else if (PyObject_TypeCheck(py_message_factory, &PyMessageFactory_Type)) {
- factory = reinterpret_cast<PyMessageFactory*>(py_message_factory);
- } else {
- PyErr_SetString(PyExc_TypeError, "Expected a MessageFactory");
- return nullptr;
- }
- auto* message_class =
- message_factory::GetOrCreateMessageClass(factory, descriptor);
- if (message_class == nullptr) {
- return nullptr;
- }
-
- CMessage* self = cmessage::NewCMessage(message_class);
- Py_DECREF(message_class);
- if (self == nullptr) {
- return nullptr;
- }
- return self->AsPyObject();
-}
-
-PyObject* PyMessage_NewMessageOwnedExternally(Message* message,
- PyObject* py_message_factory) {
- if (py_message_factory) {
- PyErr_SetString(PyExc_NotImplementedError,
- "Default message_factory=NULL is the only supported value");
- return nullptr;
- }
- if (message->GetReflection()->GetMessageFactory() !=
- MessageFactory::generated_factory()) {
- PyErr_SetString(PyExc_TypeError,
- "Message pointer was not created from the default factory");
- return nullptr;
- }
-
- CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
- GetDefaultDescriptorPool()->py_message_factory, message->GetDescriptor());
- if (message_class == nullptr) {
- return nullptr;
- }
-
- CMessage* self = cmessage::NewEmptyMessage(message_class);
- Py_DECREF(message_class);
- if (self == nullptr) {
- return nullptr;
- }
- self->message = message;
- Py_INCREF(Py_None);
- self->parent = reinterpret_cast<CMessage*>(Py_None);
- return self->AsPyObject();
-}
-
+PyObject* PyMessage_New(const Descriptor* descriptor,
+ PyObject* py_message_factory) {
+ PyMessageFactory* factory = nullptr;
+ if (py_message_factory == nullptr) {
+ factory = GetDescriptorPool_FromPool(descriptor->file()->pool())
+ ->py_message_factory;
+ } else if (PyObject_TypeCheck(py_message_factory, &PyMessageFactory_Type)) {
+ factory = reinterpret_cast<PyMessageFactory*>(py_message_factory);
+ } else {
+ PyErr_SetString(PyExc_TypeError, "Expected a MessageFactory");
+ return nullptr;
+ }
+ auto* message_class =
+ message_factory::GetOrCreateMessageClass(factory, descriptor);
+ if (message_class == nullptr) {
+ return nullptr;
+ }
+
+ CMessage* self = cmessage::NewCMessage(message_class);
+ Py_DECREF(message_class);
+ if (self == nullptr) {
+ return nullptr;
+ }
+ return self->AsPyObject();
+}
+
+PyObject* PyMessage_NewMessageOwnedExternally(Message* message,
+ PyObject* py_message_factory) {
+ if (py_message_factory) {
+ PyErr_SetString(PyExc_NotImplementedError,
+ "Default message_factory=NULL is the only supported value");
+ return nullptr;
+ }
+ if (message->GetReflection()->GetMessageFactory() !=
+ MessageFactory::generated_factory()) {
+ PyErr_SetString(PyExc_TypeError,
+ "Message pointer was not created from the default factory");
+ return nullptr;
+ }
+
+ CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
+ GetDefaultDescriptorPool()->py_message_factory, message->GetDescriptor());
+ if (message_class == nullptr) {
+ return nullptr;
+ }
+
+ CMessage* self = cmessage::NewEmptyMessage(message_class);
+ Py_DECREF(message_class);
+ if (self == nullptr) {
+ return nullptr;
+ }
+ self->message = message;
+ Py_INCREF(Py_None);
+ self->parent = reinterpret_cast<CMessage*>(Py_None);
+ return self->AsPyObject();
+}
+
void InitGlobals() {
// TODO(gps): Check all return values in this function for NULL and propagate
// the error (MemoryError) on up to result in an import failure. These should
@@ -2954,29 +2954,29 @@ bool InitProto2MessageModule(PyObject *m) {
// Initialize constants defined in this file.
InitGlobals();
- CMessageClass_Type->tp_base = &PyType_Type;
- if (PyType_Ready(CMessageClass_Type) < 0) {
+ CMessageClass_Type->tp_base = &PyType_Type;
+ if (PyType_Ready(CMessageClass_Type) < 0) {
return false;
}
PyModule_AddObject(m, "MessageMeta",
- reinterpret_cast<PyObject*>(CMessageClass_Type));
+ reinterpret_cast<PyObject*>(CMessageClass_Type));
- if (PyType_Ready(CMessage_Type) < 0) {
- return false;
- }
- if (PyType_Ready(CFieldProperty_Type) < 0) {
+ if (PyType_Ready(CMessage_Type) < 0) {
return false;
}
+ if (PyType_Ready(CFieldProperty_Type) < 0) {
+ return false;
+ }
// DESCRIPTOR is set on each protocol buffer message class elsewhere, but set
// it here as well to document that subclasses need to set it.
- PyDict_SetItem(CMessage_Type->tp_dict, kDESCRIPTOR, Py_None);
- // Invalidate any cached data for the CMessage type.
- // This call is necessary to correctly support Py_TPFLAGS_HAVE_VERSION_TAG,
- // after we have modified CMessage_Type.tp_dict.
- PyType_Modified(CMessage_Type);
+ PyDict_SetItem(CMessage_Type->tp_dict, kDESCRIPTOR, Py_None);
+ // Invalidate any cached data for the CMessage type.
+ // This call is necessary to correctly support Py_TPFLAGS_HAVE_VERSION_TAG,
+ // after we have modified CMessage_Type.tp_dict.
+ PyType_Modified(CMessage_Type);
- PyModule_AddObject(m, "Message", reinterpret_cast<PyObject*>(CMessage_Type));
+ PyModule_AddObject(m, "Message", reinterpret_cast<PyObject*>(CMessage_Type));
// Initialize Repeated container types.
{
@@ -2984,9 +2984,9 @@ bool InitProto2MessageModule(PyObject *m) {
return false;
}
- PyModule_AddObject(
- m, "RepeatedScalarContainer",
- reinterpret_cast<PyObject*>(&RepeatedScalarContainer_Type));
+ PyModule_AddObject(
+ m, "RepeatedScalarContainer",
+ reinterpret_cast<PyObject*>(&RepeatedScalarContainer_Type));
if (PyType_Ready(&RepeatedCompositeContainer_Type) < 0) {
return false;
@@ -2994,7 +2994,7 @@ bool InitProto2MessageModule(PyObject *m) {
PyModule_AddObject(
m, "RepeatedCompositeContainer",
- reinterpret_cast<PyObject*>(&RepeatedCompositeContainer_Type));
+ reinterpret_cast<PyObject*>(&RepeatedCompositeContainer_Type));
// Register them as MutableSequence.
#if PY_MAJOR_VERSION >= 3
@@ -3022,20 +3022,20 @@ bool InitProto2MessageModule(PyObject *m) {
}
}
- if (PyType_Ready(&PyUnknownFields_Type) < 0) {
- return false;
- }
-
- PyModule_AddObject(m, "UnknownFieldSet",
- reinterpret_cast<PyObject*>(&PyUnknownFields_Type));
-
- if (PyType_Ready(&PyUnknownFieldRef_Type) < 0) {
- return false;
- }
-
- PyModule_AddObject(m, "UnknownField",
- reinterpret_cast<PyObject*>(&PyUnknownFieldRef_Type));
-
+ if (PyType_Ready(&PyUnknownFields_Type) < 0) {
+ return false;
+ }
+
+ PyModule_AddObject(m, "UnknownFieldSet",
+ reinterpret_cast<PyObject*>(&PyUnknownFields_Type));
+
+ if (PyType_Ready(&PyUnknownFieldRef_Type) < 0) {
+ return false;
+ }
+
+ PyModule_AddObject(m, "UnknownField",
+ reinterpret_cast<PyObject*>(&PyUnknownFieldRef_Type));
+
// Initialize Map container types.
if (!InitMapContainers()) {
return false;
@@ -3050,13 +3050,13 @@ bool InitProto2MessageModule(PyObject *m) {
if (PyType_Ready(&ExtensionDict_Type) < 0) {
return false;
}
- PyModule_AddObject(m, "ExtensionDict",
- reinterpret_cast<PyObject*>(&ExtensionDict_Type));
- if (PyType_Ready(&ExtensionIterator_Type) < 0) {
- return false;
- }
- PyModule_AddObject(m, "ExtensionIterator",
- reinterpret_cast<PyObject*>(&ExtensionIterator_Type));
+ PyModule_AddObject(m, "ExtensionDict",
+ reinterpret_cast<PyObject*>(&ExtensionDict_Type));
+ if (PyType_Ready(&ExtensionIterator_Type) < 0) {
+ return false;
+ }
+ PyModule_AddObject(m, "ExtensionIterator",
+ reinterpret_cast<PyObject*>(&ExtensionIterator_Type));
// Expose the DescriptorPool used to hold all descriptors added from generated
// pb2.py files.
@@ -3065,24 +3065,24 @@ bool InitProto2MessageModule(PyObject *m) {
PyModule_AddObject(m, "default_pool",
reinterpret_cast<PyObject*>(GetDefaultDescriptorPool()));
- PyModule_AddObject(m, "DescriptorPool",
- reinterpret_cast<PyObject*>(&PyDescriptorPool_Type));
- PyModule_AddObject(m, "Descriptor",
- reinterpret_cast<PyObject*>(&PyMessageDescriptor_Type));
- PyModule_AddObject(m, "FieldDescriptor",
- reinterpret_cast<PyObject*>(&PyFieldDescriptor_Type));
- PyModule_AddObject(m, "EnumDescriptor",
- reinterpret_cast<PyObject*>(&PyEnumDescriptor_Type));
- PyModule_AddObject(m, "EnumValueDescriptor",
- reinterpret_cast<PyObject*>(&PyEnumValueDescriptor_Type));
- PyModule_AddObject(m, "FileDescriptor",
- reinterpret_cast<PyObject*>(&PyFileDescriptor_Type));
- PyModule_AddObject(m, "OneofDescriptor",
- reinterpret_cast<PyObject*>(&PyOneofDescriptor_Type));
- PyModule_AddObject(m, "ServiceDescriptor",
- reinterpret_cast<PyObject*>(&PyServiceDescriptor_Type));
- PyModule_AddObject(m, "MethodDescriptor",
- reinterpret_cast<PyObject*>(&PyMethodDescriptor_Type));
+ PyModule_AddObject(m, "DescriptorPool",
+ reinterpret_cast<PyObject*>(&PyDescriptorPool_Type));
+ PyModule_AddObject(m, "Descriptor",
+ reinterpret_cast<PyObject*>(&PyMessageDescriptor_Type));
+ PyModule_AddObject(m, "FieldDescriptor",
+ reinterpret_cast<PyObject*>(&PyFieldDescriptor_Type));
+ PyModule_AddObject(m, "EnumDescriptor",
+ reinterpret_cast<PyObject*>(&PyEnumDescriptor_Type));
+ PyModule_AddObject(m, "EnumValueDescriptor",
+ reinterpret_cast<PyObject*>(&PyEnumValueDescriptor_Type));
+ PyModule_AddObject(m, "FileDescriptor",
+ reinterpret_cast<PyObject*>(&PyFileDescriptor_Type));
+ PyModule_AddObject(m, "OneofDescriptor",
+ reinterpret_cast<PyObject*>(&PyOneofDescriptor_Type));
+ PyModule_AddObject(m, "ServiceDescriptor",
+ reinterpret_cast<PyObject*>(&PyServiceDescriptor_Type));
+ PyModule_AddObject(m, "MethodDescriptor",
+ reinterpret_cast<PyObject*>(&PyMethodDescriptor_Type));
PyObject* enum_type_wrapper = PyImport_ImportModule(
"google.protobuf.internal.enum_type_wrapper");
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/message.h b/contrib/python/protobuf/py3/google/protobuf/pyext/message.h
index ca81a87521..9c1d4a5da8 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/message.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/message.h
@@ -36,13 +36,13 @@
#include <Python.h>
-#include <cstdint>
+#include <cstdint>
#include <memory>
-#include <string>
-#include <unordered_map>
-
-#include <google/protobuf/stubs/common.h>
+#include <string>
+#include <unordered_map>
+#include <google/protobuf/stubs/common.h>
+
namespace google {
namespace protobuf {
@@ -57,51 +57,51 @@ namespace python {
struct ExtensionDict;
struct PyMessageFactory;
-struct CMessageClass;
-
-// Most of the complexity of the Message class comes from the "Release"
-// behavior:
-//
-// When a field is cleared, it is only detached from its message. Existing
-// references to submessages, to repeated container etc. won't see any change,
-// as if the data was effectively managed by these containers.
-//
-// ExtensionDicts and UnknownFields containers do NOT follow this rule. They
-// don't store any data, and always refer to their parent message.
-
-struct ContainerBase {
+struct CMessageClass;
+
+// Most of the complexity of the Message class comes from the "Release"
+// behavior:
+//
+// When a field is cleared, it is only detached from its message. Existing
+// references to submessages, to repeated container etc. won't see any change,
+// as if the data was effectively managed by these containers.
+//
+// ExtensionDicts and UnknownFields containers do NOT follow this rule. They
+// don't store any data, and always refer to their parent message.
+
+struct ContainerBase {
PyObject_HEAD;
- // Strong reference to a parent message object. For a CMessage there are three
- // cases:
- // - For a top-level message, this pointer is NULL.
- // - For a sub-message, this points to the parent message.
- // - For a message managed externally, this is a owned reference to Py_None.
+ // Strong reference to a parent message object. For a CMessage there are three
+ // cases:
+ // - For a top-level message, this pointer is NULL.
+ // - For a sub-message, this points to the parent message.
+ // - For a message managed externally, this is a owned reference to Py_None.
//
- // For all other types: repeated containers, maps, it always point to a
- // valid parent CMessage.
+ // For all other types: repeated containers, maps, it always point to a
+ // valid parent CMessage.
struct CMessage* parent;
- // If this object belongs to a parent message, describes which field it comes
- // from.
- // The pointer is owned by the DescriptorPool (which is kept alive
- // through the message's Python class)
+ // If this object belongs to a parent message, describes which field it comes
+ // from.
+ // The pointer is owned by the DescriptorPool (which is kept alive
+ // through the message's Python class)
const FieldDescriptor* parent_field_descriptor;
- PyObject* AsPyObject() { return reinterpret_cast<PyObject*>(this); }
-
- // The Three methods below are only used by Repeated containers, and Maps.
-
- // This implementation works for all containers which have a parent.
- PyObject* DeepCopy();
- // Delete this container object from its parent. Does not work for messages.
- void RemoveFromParentCache();
-};
-
-typedef struct CMessage : public ContainerBase {
- // Pointer to the C++ Message object for this CMessage.
- // - If this object has no parent, we own this pointer.
- // - If this object has a parent message, the parent owns this pointer.
+ PyObject* AsPyObject() { return reinterpret_cast<PyObject*>(this); }
+
+ // The Three methods below are only used by Repeated containers, and Maps.
+
+ // This implementation works for all containers which have a parent.
+ PyObject* DeepCopy();
+ // Delete this container object from its parent. Does not work for messages.
+ void RemoveFromParentCache();
+};
+
+typedef struct CMessage : public ContainerBase {
+ // Pointer to the C++ Message object for this CMessage.
+ // - If this object has no parent, we own this pointer.
+ // - If this object has a parent message, the parent owns this pointer.
Message* message;
// Indicates this submessage is pointing to a default instance of a message.
@@ -109,38 +109,38 @@ typedef struct CMessage : public ContainerBase {
// made writable, at which point this field is set to false.
bool read_only;
- // A mapping indexed by field, containing weak references to contained objects
- // which need to implement the "Release" mechanism:
- // direct submessages, RepeatedCompositeContainer, RepeatedScalarContainer
- // and MapContainer.
- typedef std::unordered_map<const FieldDescriptor*, ContainerBase*>
- CompositeFieldsMap;
- CompositeFieldsMap* composite_fields;
-
- // A mapping containing weak references to indirect child messages, accessed
- // through containers: repeated messages, and values of message maps.
- // This avoid the creation of similar maps in each of those containers.
- typedef std::unordered_map<const Message*, CMessage*> SubMessagesMap;
- SubMessagesMap* child_submessages;
-
- // A reference to PyUnknownFields.
- PyObject* unknown_field_set;
-
+ // A mapping indexed by field, containing weak references to contained objects
+ // which need to implement the "Release" mechanism:
+ // direct submessages, RepeatedCompositeContainer, RepeatedScalarContainer
+ // and MapContainer.
+ typedef std::unordered_map<const FieldDescriptor*, ContainerBase*>
+ CompositeFieldsMap;
+ CompositeFieldsMap* composite_fields;
+
+ // A mapping containing weak references to indirect child messages, accessed
+ // through containers: repeated messages, and values of message maps.
+ // This avoid the creation of similar maps in each of those containers.
+ typedef std::unordered_map<const Message*, CMessage*> SubMessagesMap;
+ SubMessagesMap* child_submessages;
+
+ // A reference to PyUnknownFields.
+ PyObject* unknown_field_set;
+
// Implements the "weakref" protocol for this object.
PyObject* weakreflist;
- // Return a *borrowed* reference to the message class.
- CMessageClass* GetMessageClass() {
- return reinterpret_cast<CMessageClass*>(Py_TYPE(this));
- }
+ // Return a *borrowed* reference to the message class.
+ CMessageClass* GetMessageClass() {
+ return reinterpret_cast<CMessageClass*>(Py_TYPE(this));
+ }
- // For container containing messages, return a Python object for the given
- // pointer to a message.
- CMessage* BuildSubMessageFromPointer(const FieldDescriptor* field_descriptor,
- Message* sub_message,
- CMessageClass* message_class);
- CMessage* MaybeReleaseSubMessage(Message* sub_message);
-} CMessage;
+ // For container containing messages, return a Python object for the given
+ // pointer to a message.
+ CMessage* BuildSubMessageFromPointer(const FieldDescriptor* field_descriptor,
+ Message* sub_message,
+ CMessageClass* message_class);
+ CMessage* MaybeReleaseSubMessage(Message* sub_message);
+} CMessage;
// The (meta) type of all Messages classes.
// It allows us to cache some C++ pointers in the class object itself, they are
@@ -155,13 +155,13 @@ struct CMessageClass {
const Descriptor* message_descriptor;
// Owned reference, used to keep the pointer above alive.
- // This reference must stay alive until all message pointers are destructed.
+ // This reference must stay alive until all message pointers are destructed.
PyObject* py_message_descriptor;
// The Python MessageFactory used to create the class. It is needed to resolve
// fields descriptors, including extensions fields; its C++ MessageFactory is
// used to instantiate submessages.
- // This reference must stay alive until all message pointers are destructed.
+ // This reference must stay alive until all message pointers are destructed.
PyMessageFactory* py_message_factory;
PyObject* AsPyObject() {
@@ -169,8 +169,8 @@ struct CMessageClass {
}
};
-extern PyTypeObject* CMessageClass_Type;
-extern PyTypeObject* CMessage_Type;
+extern PyTypeObject* CMessageClass_Type;
+extern PyTypeObject* CMessage_Type;
namespace cmessage {
@@ -187,16 +187,16 @@ const FieldDescriptor* GetExtensionDescriptor(PyObject* extension);
// submessage as the result is cached in composite_fields.
//
// Corresponds to reflection api method GetMessage.
-CMessage* InternalGetSubMessage(
+CMessage* InternalGetSubMessage(
CMessage* self, const FieldDescriptor* field_descriptor);
-// Deletes a range of items in a repeated field (following a
+// Deletes a range of items in a repeated field (following a
// removal in a RepeatedCompositeContainer).
//
// Corresponds to reflection api method RemoveLast.
-int DeleteRepeatedField(CMessage* self,
- const FieldDescriptor* field_descriptor,
- PyObject* slice);
+int DeleteRepeatedField(CMessage* self,
+ const FieldDescriptor* field_descriptor,
+ PyObject* slice);
// Sets the specified scalar value to the message.
int InternalSetScalar(CMessage* self,
@@ -214,30 +214,30 @@ int InternalSetNonOneofScalar(Message* message,
PyObject* InternalGetScalar(const Message* message,
const FieldDescriptor* field_descriptor);
-bool SetCompositeField(CMessage* self, const FieldDescriptor* field,
- ContainerBase* value);
-
-bool SetSubmessage(CMessage* self, CMessage* submessage);
-
+bool SetCompositeField(CMessage* self, const FieldDescriptor* field,
+ ContainerBase* value);
+
+bool SetSubmessage(CMessage* self, CMessage* submessage);
+
// Clears the message, removing all contained data. Extension dictionary and
// submessages are released first if there are remaining external references.
//
// Corresponds to message api method Clear.
PyObject* Clear(CMessage* self);
-// Clears the data described by the given descriptor.
-// Returns -1 on error.
+// Clears the data described by the given descriptor.
+// Returns -1 on error.
//
// Corresponds to reflection api method ClearField.
-int ClearFieldByDescriptor(CMessage* self, const FieldDescriptor* descriptor);
+int ClearFieldByDescriptor(CMessage* self, const FieldDescriptor* descriptor);
// Checks if the message has the field described by the descriptor. Used for
// extensions (which have no name).
-// Returns 1 if true, 0 if false, and -1 on error.
+// Returns 1 if true, 0 if false, and -1 on error.
//
// Corresponds to reflection api method HasField
-int HasFieldByDescriptor(CMessage* self,
- const FieldDescriptor* field_descriptor);
+int HasFieldByDescriptor(CMessage* self,
+ const FieldDescriptor* field_descriptor);
// Checks if the message has the named field.
//
@@ -255,13 +255,13 @@ PyObject* MergeFrom(CMessage* self, PyObject* arg);
// has been registered with the same field number on this class.
PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle);
-// Get a field from a message.
-PyObject* GetFieldValue(CMessage* self,
- const FieldDescriptor* field_descriptor);
-// Sets the value of a scalar field in a message.
-// On error, return -1 with an extension set.
-int SetFieldValue(CMessage* self, const FieldDescriptor* field_descriptor,
- PyObject* value);
+// Get a field from a message.
+PyObject* GetFieldValue(CMessage* self,
+ const FieldDescriptor* field_descriptor);
+// Sets the value of a scalar field in a message.
+// On error, return -1 with an extension set.
+int SetFieldValue(CMessage* self, const FieldDescriptor* field_descriptor,
+ PyObject* value);
PyObject* FindInitializationErrors(CMessage* self);
@@ -283,50 +283,50 @@ PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg);
/* Is 64bit */
#define IS_64BIT (SIZEOF_LONG == 8)
-#define FIELD_IS_REPEATED(field_descriptor) \
- ((field_descriptor)->label() == FieldDescriptor::LABEL_REPEATED)
-
-#define GOOGLE_CHECK_GET_INT32(arg, value, err) \
- int32_t value; \
- if (!CheckAndGetInteger(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_INT64(arg, value, err) \
- int64_t value; \
- if (!CheckAndGetInteger(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_UINT32(arg, value, err) \
- uint32_t value; \
- if (!CheckAndGetInteger(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_UINT64(arg, value, err) \
- uint64_t value; \
- if (!CheckAndGetInteger(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_FLOAT(arg, value, err) \
- float value; \
- if (!CheckAndGetFloat(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_DOUBLE(arg, value, err) \
- double value; \
- if (!CheckAndGetDouble(arg, &value)) { \
- return err; \
- }
-
-#define GOOGLE_CHECK_GET_BOOL(arg, value, err) \
- bool value; \
- if (!CheckAndGetBool(arg, &value)) { \
- return err; \
- }
+#define FIELD_IS_REPEATED(field_descriptor) \
+ ((field_descriptor)->label() == FieldDescriptor::LABEL_REPEATED)
+
+#define GOOGLE_CHECK_GET_INT32(arg, value, err) \
+ int32_t value; \
+ if (!CheckAndGetInteger(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_INT64(arg, value, err) \
+ int64_t value; \
+ if (!CheckAndGetInteger(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_UINT32(arg, value, err) \
+ uint32_t value; \
+ if (!CheckAndGetInteger(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_UINT64(arg, value, err) \
+ uint64_t value; \
+ if (!CheckAndGetInteger(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_FLOAT(arg, value, err) \
+ float value; \
+ if (!CheckAndGetFloat(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_DOUBLE(arg, value, err) \
+ double value; \
+ if (!CheckAndGetDouble(arg, &value)) { \
+ return err; \
+ }
+
+#define GOOGLE_CHECK_GET_BOOL(arg, value, err) \
+ bool value; \
+ if (!CheckAndGetBool(arg, &value)) { \
+ return err; \
+ }
#define FULL_MODULE_NAME "google.protobuf.pyext._message"
@@ -343,8 +343,8 @@ bool CheckAndSetString(
const Reflection* reflection,
bool append,
int index);
-PyObject* ToStringObject(const FieldDescriptor* descriptor,
- const TProtoStringType& value);
+PyObject* ToStringObject(const FieldDescriptor* descriptor,
+ const TProtoStringType& value);
// Check if the passed field descriptor belongs to the given message.
// If not, return false and set a Python exception (a KeyError)
@@ -353,24 +353,24 @@ bool CheckFieldBelongsToMessage(const FieldDescriptor* field_descriptor,
extern PyObject* PickleError_class;
-PyObject* PyMessage_New(const Descriptor* descriptor,
- PyObject* py_message_factory);
-const Message* PyMessage_GetMessagePointer(PyObject* msg);
-Message* PyMessage_GetMutableMessagePointer(PyObject* msg);
-PyObject* PyMessage_NewMessageOwnedExternally(Message* message,
- PyObject* py_message_factory);
-
+PyObject* PyMessage_New(const Descriptor* descriptor,
+ PyObject* py_message_factory);
+const Message* PyMessage_GetMessagePointer(PyObject* msg);
+Message* PyMessage_GetMutableMessagePointer(PyObject* msg);
+PyObject* PyMessage_NewMessageOwnedExternally(Message* message,
+ PyObject* py_message_factory);
+
bool InitProto2MessageModule(PyObject *m);
-// These are referenced by repeated_scalar_container, and must
-// be explicitly instantiated.
-extern template bool CheckAndGetInteger<int32>(PyObject*, int32*);
-extern template bool CheckAndGetInteger<int64>(PyObject*, int64*);
-extern template bool CheckAndGetInteger<uint32>(PyObject*, uint32*);
-extern template bool CheckAndGetInteger<uint64>(PyObject*, uint64*);
-
+// These are referenced by repeated_scalar_container, and must
+// be explicitly instantiated.
+extern template bool CheckAndGetInteger<int32>(PyObject*, int32*);
+extern template bool CheckAndGetInteger<int64>(PyObject*, int64*);
+extern template bool CheckAndGetInteger<uint32>(PyObject*, uint32*);
+extern template bool CheckAndGetInteger<uint64>(PyObject*, uint64*);
+
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.cc
index 7905be0214..f35bebf0bf 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.cc
@@ -28,26 +28,26 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <unordered_map>
-
+#include <unordered_map>
+
#include <Python.h>
-#include <google/protobuf/dynamic_message.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#if PY_MAJOR_VERSION >= 3
#if PY_VERSION_HEX < 0x03030000
#error "Python 3.0 - 3.2 are not supported."
#endif
#define PyString_AsStringAndSize(ob, charpp, sizep) \
- (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
- PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
- ? -1 \
- : 0) \
- : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
+ (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
+ PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
+ ? -1 \
+ : 0) \
+ : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif
namespace google {
@@ -69,7 +69,7 @@ PyMessageFactory* NewMessageFactory(PyTypeObject* type, PyDescriptorPool* pool)
factory->message_factory = message_factory;
factory->pool = pool;
- Py_INCREF(pool);
+ Py_INCREF(pool);
factory->classes_by_descriptor = new PyMessageFactory::ClassesByMessageMap();
@@ -79,8 +79,8 @@ PyMessageFactory* NewMessageFactory(PyTypeObject* type, PyDescriptorPool* pool)
PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
static const char* kwlist[] = {"pool", 0};
PyObject* pool = NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O",
- const_cast<char**>(kwlist), &pool)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O",
+ const_cast<char**>(kwlist), &pool)) {
return NULL;
}
ScopedPyObjectPtr owned_pool;
@@ -103,40 +103,40 @@ PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
NewMessageFactory(type, reinterpret_cast<PyDescriptorPool*>(pool)));
}
-static void Dealloc(PyObject* pself) {
- PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
-
+static void Dealloc(PyObject* pself) {
+ PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
+
typedef PyMessageFactory::ClassesByMessageMap::iterator iterator;
for (iterator it = self->classes_by_descriptor->begin();
it != self->classes_by_descriptor->end(); ++it) {
- Py_CLEAR(it->second);
+ Py_CLEAR(it->second);
}
delete self->classes_by_descriptor;
delete self->message_factory;
- Py_CLEAR(self->pool);
- Py_TYPE(self)->tp_free(pself);
-}
-
-static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
- PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
- Py_VISIT(self->pool);
- for (const auto& desc_and_class : *self->classes_by_descriptor) {
- Py_VISIT(desc_and_class.second);
- }
- return 0;
-}
-
-static int GcClear(PyObject* pself) {
- PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
- // Here it's important to not clear self->pool, so that the C++ DescriptorPool
- // is still alive when self->message_factory is destructed.
- for (auto& desc_and_class : *self->classes_by_descriptor) {
- Py_CLEAR(desc_and_class.second);
- }
-
- return 0;
+ Py_CLEAR(self->pool);
+ Py_TYPE(self)->tp_free(pself);
}
+static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
+ PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
+ Py_VISIT(self->pool);
+ for (const auto& desc_and_class : *self->classes_by_descriptor) {
+ Py_VISIT(desc_and_class.second);
+ }
+ return 0;
+}
+
+static int GcClear(PyObject* pself) {
+ PyMessageFactory* self = reinterpret_cast<PyMessageFactory*>(pself);
+ // Here it's important to not clear self->pool, so that the C++ DescriptorPool
+ // is still alive when self->message_factory is destructed.
+ for (auto& desc_and_class : *self->classes_by_descriptor) {
+ Py_CLEAR(desc_and_class.second);
+ }
+
+ return 0;
+}
+
// Add a message class to our database.
int RegisterMessageClass(PyMessageFactory* self,
const Descriptor* message_descriptor,
@@ -158,7 +158,7 @@ CMessageClass* GetOrCreateMessageClass(PyMessageFactory* self,
// This is the same implementation as MessageFactory.GetPrototype().
// Do not create a MessageClass that already exists.
- std::unordered_map<const Descriptor*, CMessageClass*>::iterator it =
+ std::unordered_map<const Descriptor*, CMessageClass*>::iterator it =
self->classes_by_descriptor->find(descriptor);
if (it != self->classes_by_descriptor->end()) {
Py_INCREF(it->second);
@@ -179,7 +179,7 @@ CMessageClass* GetOrCreateMessageClass(PyMessageFactory* self,
return NULL;
}
ScopedPyObjectPtr message_class(PyObject_CallObject(
- reinterpret_cast<PyObject*>(CMessageClass_Type), args.get()));
+ reinterpret_cast<PyObject*>(CMessageClass_Type), args.get()));
if (message_class == NULL) {
return NULL;
}
@@ -251,44 +251,44 @@ static PyGetSetDef Getters[] = {
PyTypeObject PyMessageFactory_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".MessageFactory", // tp_name
- sizeof(PyMessageFactory), // tp_basicsize
- 0, // tp_itemsize
- message_factory::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, // tp_flags
- "A static Message Factory", // tp_doc
- message_factory::GcTraverse, // tp_traverse
- message_factory::GcClear, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- message_factory::Methods, // tp_methods
- 0, // tp_members
- message_factory::Getters, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
- 0, // tp_alloc
- message_factory::New, // tp_new
- PyObject_GC_Del, // tp_free
+ ".MessageFactory", // tp_name
+ sizeof(PyMessageFactory), // tp_basicsize
+ 0, // tp_itemsize
+ message_factory::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, // tp_flags
+ "A static Message Factory", // tp_doc
+ message_factory::GcTraverse, // tp_traverse
+ message_factory::GcClear, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ message_factory::Methods, // tp_methods
+ 0, // tp_members
+ message_factory::Getters, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ message_factory::New, // tp_new
+ PyObject_GC_Del, // tp_free
};
bool InitMessageFactory() {
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.h b/contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.h
index 515c29cdb8..047ac9a75f 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.h
@@ -33,9 +33,9 @@
#include <Python.h>
-#include <unordered_map>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
+#include <unordered_map>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
namespace google {
namespace protobuf {
@@ -57,16 +57,16 @@ struct PyMessageFactory {
// The C++ one creates messages, when the Python one creates classes.
MessageFactory* message_factory;
- // Owned reference to a Python DescriptorPool.
- // This reference must stay until the message_factory is destructed.
+ // Owned reference to a Python DescriptorPool.
+ // This reference must stay until the message_factory is destructed.
PyDescriptorPool* pool;
// Make our own mapping to retrieve Python classes from C++ descriptors.
//
// Descriptor pointers stored here are owned by the DescriptorPool above.
// Python references to classes are owned by this PyDescriptorPool.
- typedef std::unordered_map<const Descriptor*, CMessageClass*>
- ClassesByMessageMap;
+ typedef std::unordered_map<const Descriptor*, CMessageClass*>
+ ClassesByMessageMap;
ClassesByMessageMap* classes_by_descriptor;
};
@@ -98,6 +98,6 @@ bool InitMessageFactory();
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/message_module.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/message_module.cc
index b5975f76c5..c5a24eea3b 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/message_module.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/message_module.cc
@@ -28,69 +28,69 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <Python.h>
-
-#include <google/protobuf/message_lite.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/proto_api.h>
-
-namespace {
-
-// C++ API. Clients get at this via proto_api.h
-struct ApiImplementation : google::protobuf::python::PyProto_API {
- const google::protobuf::Message* GetMessagePointer(PyObject* msg) const override {
- return google::protobuf::python::PyMessage_GetMessagePointer(msg);
- }
- google::protobuf::Message* GetMutableMessagePointer(PyObject* msg) const override {
- return google::protobuf::python::PyMessage_GetMutableMessagePointer(msg);
- }
- const google::protobuf::DescriptorPool* GetDefaultDescriptorPool() const override {
- return google::protobuf::python::GetDefaultDescriptorPool()->pool;
- }
-
- google::protobuf::MessageFactory* GetDefaultMessageFactory() const override {
- return google::protobuf::python::GetDefaultDescriptorPool()
- ->py_message_factory->message_factory;
- }
- PyObject* NewMessage(const google::protobuf::Descriptor* descriptor,
- PyObject* py_message_factory) const override {
- return google::protobuf::python::PyMessage_New(descriptor, py_message_factory);
- }
- PyObject* NewMessageOwnedExternally(
- google::protobuf::Message* msg, PyObject* py_message_factory) const override {
- return google::protobuf::python::PyMessage_NewMessageOwnedExternally(
- msg, py_message_factory);
- }
-};
-
-} // namespace
+#include <Python.h>
+
+#include <google/protobuf/message_lite.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/proto_api.h>
+namespace {
+
+// C++ API. Clients get at this via proto_api.h
+struct ApiImplementation : google::protobuf::python::PyProto_API {
+ const google::protobuf::Message* GetMessagePointer(PyObject* msg) const override {
+ return google::protobuf::python::PyMessage_GetMessagePointer(msg);
+ }
+ google::protobuf::Message* GetMutableMessagePointer(PyObject* msg) const override {
+ return google::protobuf::python::PyMessage_GetMutableMessagePointer(msg);
+ }
+ const google::protobuf::DescriptorPool* GetDefaultDescriptorPool() const override {
+ return google::protobuf::python::GetDefaultDescriptorPool()->pool;
+ }
+
+ google::protobuf::MessageFactory* GetDefaultMessageFactory() const override {
+ return google::protobuf::python::GetDefaultDescriptorPool()
+ ->py_message_factory->message_factory;
+ }
+ PyObject* NewMessage(const google::protobuf::Descriptor* descriptor,
+ PyObject* py_message_factory) const override {
+ return google::protobuf::python::PyMessage_New(descriptor, py_message_factory);
+ }
+ PyObject* NewMessageOwnedExternally(
+ google::protobuf::Message* msg, PyObject* py_message_factory) const override {
+ return google::protobuf::python::PyMessage_NewMessageOwnedExternally(
+ msg, py_message_factory);
+ }
+};
+
+} // namespace
+
static const char module_docstring[] =
- "python-proto2 is a module that can be used to enhance proto2 Python API\n"
- "performance.\n"
- "\n"
- "It provides access to the protocol buffers C++ reflection API that\n"
- "implements the basic protocol buffer functions.";
+ "python-proto2 is a module that can be used to enhance proto2 Python API\n"
+ "performance.\n"
+ "\n"
+ "It provides access to the protocol buffers C++ reflection API that\n"
+ "implements the basic protocol buffer functions.";
static PyMethodDef ModuleMethods[] = {
- {"SetAllowOversizeProtos",
- (PyCFunction)google::protobuf::python::cmessage::SetAllowOversizeProtos, METH_O,
- "Enable/disable oversize proto parsing."},
- // DO NOT USE: For migration and testing only.
- {NULL, NULL}};
+ {"SetAllowOversizeProtos",
+ (PyCFunction)google::protobuf::python::cmessage::SetAllowOversizeProtos, METH_O,
+ "Enable/disable oversize proto parsing."},
+ // DO NOT USE: For migration and testing only.
+ {NULL, NULL}};
#if PY_MAJOR_VERSION >= 3
-static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
- "_message",
- module_docstring,
- -1,
- ModuleMethods, /* m_methods */
- NULL,
- NULL,
- NULL,
- NULL};
+static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
+ "_message",
+ module_docstring,
+ -1,
+ ModuleMethods, /* m_methods */
+ NULL,
+ NULL,
+ NULL,
+ NULL};
#define INITFUNC PyInit__message
#define INITFUNC_ERRORVAL NULL
#else // Python 2
@@ -98,35 +98,35 @@ static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
#define INITFUNC_ERRORVAL
#endif
-PyMODINIT_FUNC INITFUNC() {
- PyObject* m;
+PyMODINIT_FUNC INITFUNC() {
+ PyObject* m;
#if PY_MAJOR_VERSION >= 3
- m = PyModule_Create(&_module);
+ m = PyModule_Create(&_module);
#else
- m = Py_InitModule3("_message", ModuleMethods, module_docstring);
+ m = Py_InitModule3("_message", ModuleMethods, module_docstring);
#endif
- if (m == NULL) {
- return INITFUNC_ERRORVAL;
- }
-
- if (!google::protobuf::python::InitProto2MessageModule(m)) {
- Py_DECREF(m);
- return INITFUNC_ERRORVAL;
- }
+ if (m == NULL) {
+ return INITFUNC_ERRORVAL;
+ }
- // Adds the C++ API
- if (PyObject* api = PyCapsule_New(
- new ApiImplementation(), google::protobuf::python::PyProtoAPICapsuleName(),
- [](PyObject* o) {
- delete (ApiImplementation*)PyCapsule_GetPointer(
- o, google::protobuf::python::PyProtoAPICapsuleName());
- })) {
- PyModule_AddObject(m, "proto_API", api);
- } else {
- return INITFUNC_ERRORVAL;
- }
+ if (!google::protobuf::python::InitProto2MessageModule(m)) {
+ Py_DECREF(m);
+ return INITFUNC_ERRORVAL;
+ }
+ // Adds the C++ API
+ if (PyObject* api = PyCapsule_New(
+ new ApiImplementation(), google::protobuf::python::PyProtoAPICapsuleName(),
+ [](PyObject* o) {
+ delete (ApiImplementation*)PyCapsule_GetPointer(
+ o, google::protobuf::python::PyProtoAPICapsuleName());
+ })) {
+ PyModule_AddObject(m, "proto_API", api);
+ } else {
+ return INITFUNC_ERRORVAL;
+ }
+
#if PY_MAJOR_VERSION >= 3
- return m;
+ return m;
#endif
}
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_composite_container.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_composite_container.cc
index f3d6fc3092..e3947c9ded 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_composite_container.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_composite_container.cc
@@ -31,22 +31,22 @@
// Author: anuraag@google.com (Anuraag Agrawal)
// Author: tibell@google.com (Johan Tibell)
-#include <google/protobuf/pyext/repeated_composite_container.h>
+#include <google/protobuf/pyext/repeated_composite_container.h>
#include <memory>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/dynamic_message.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/message_factory.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/reflection.h>
-#include <google/protobuf/stubs/map_util.h>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/reflection.h>
+#include <google/protobuf/stubs/map_util.h>
#if PY_MAJOR_VERSION >= 3
#define PyInt_Check PyLong_Check
@@ -63,291 +63,291 @@ namespace repeated_composite_container {
// ---------------------------------------------------------------------
// len()
-static Py_ssize_t Length(PyObject* pself) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
+static Py_ssize_t Length(PyObject* pself) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
- Message* message = self->parent->message;
- return message->GetReflection()->FieldSize(*message,
- self->parent_field_descriptor);
+ Message* message = self->parent->message;
+ return message->GetReflection()->FieldSize(*message,
+ self->parent_field_descriptor);
}
// ---------------------------------------------------------------------
// add()
-PyObject* Add(RepeatedCompositeContainer* self, PyObject* args,
- PyObject* kwargs) {
- if (cmessage::AssureWritable(self->parent) == -1) return nullptr;
- Message* message = self->parent->message;
+PyObject* Add(RepeatedCompositeContainer* self, PyObject* args,
+ PyObject* kwargs) {
+ if (cmessage::AssureWritable(self->parent) == -1) return nullptr;
+ Message* message = self->parent->message;
Message* sub_message =
message->GetReflection()->AddMessage(
message,
self->parent_field_descriptor,
self->child_message_class->py_message_factory->message_factory);
- CMessage* cmsg = self->parent->BuildSubMessageFromPointer(
- self->parent_field_descriptor, sub_message, self->child_message_class);
+ CMessage* cmsg = self->parent->BuildSubMessageFromPointer(
+ self->parent_field_descriptor, sub_message, self->child_message_class);
if (cmessage::InitAttributes(cmsg, args, kwargs) < 0) {
- message->GetReflection()->RemoveLast(
- message, self->parent_field_descriptor);
+ message->GetReflection()->RemoveLast(
+ message, self->parent_field_descriptor);
Py_DECREF(cmsg);
- return nullptr;
+ return nullptr;
}
- return cmsg->AsPyObject();
-}
-
-static PyObject* AddMethod(PyObject* self, PyObject* args, PyObject* kwargs) {
- return Add(reinterpret_cast<RepeatedCompositeContainer*>(self), args, kwargs);
+ return cmsg->AsPyObject();
}
-// ---------------------------------------------------------------------
-// append()
-
-static PyObject* AddMessage(RepeatedCompositeContainer* self, PyObject* value) {
- cmessage::AssureWritable(self->parent);
- PyObject* py_cmsg;
- Message* message = self->parent->message;
- const Reflection* reflection = message->GetReflection();
- py_cmsg = Add(self, nullptr, nullptr);
- if (py_cmsg == nullptr) return nullptr;
- CMessage* cmsg = reinterpret_cast<CMessage*>(py_cmsg);
- if (ScopedPyObjectPtr(cmessage::MergeFrom(cmsg, value)) == nullptr) {
- reflection->RemoveLast(
- message, self->parent_field_descriptor);
- Py_DECREF(cmsg);
- return nullptr;
+static PyObject* AddMethod(PyObject* self, PyObject* args, PyObject* kwargs) {
+ return Add(reinterpret_cast<RepeatedCompositeContainer*>(self), args, kwargs);
+}
+
+// ---------------------------------------------------------------------
+// append()
+
+static PyObject* AddMessage(RepeatedCompositeContainer* self, PyObject* value) {
+ cmessage::AssureWritable(self->parent);
+ PyObject* py_cmsg;
+ Message* message = self->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ py_cmsg = Add(self, nullptr, nullptr);
+ if (py_cmsg == nullptr) return nullptr;
+ CMessage* cmsg = reinterpret_cast<CMessage*>(py_cmsg);
+ if (ScopedPyObjectPtr(cmessage::MergeFrom(cmsg, value)) == nullptr) {
+ reflection->RemoveLast(
+ message, self->parent_field_descriptor);
+ Py_DECREF(cmsg);
+ return nullptr;
}
return py_cmsg;
}
-static PyObject* AppendMethod(PyObject* pself, PyObject* value) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
- ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
- if (py_cmsg == nullptr) {
- return nullptr;
- }
-
- Py_RETURN_NONE;
-}
-
-// ---------------------------------------------------------------------
-// insert()
-static PyObject* Insert(PyObject* pself, PyObject* args) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
-
- Py_ssize_t index;
- PyObject* value;
- if (!PyArg_ParseTuple(args, "nO", &index, &value)) {
- return nullptr;
- }
-
- ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
- if (py_cmsg == nullptr) {
- return nullptr;
- }
-
- // Swap the element to right position.
- Message* message = self->parent->message;
- const Reflection* reflection = message->GetReflection();
- const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
- Py_ssize_t length = reflection->FieldSize(*message, field_descriptor) - 1;
- Py_ssize_t end_index = index;
- if (end_index < 0) end_index += length;
- if (end_index < 0) end_index = 0;
- for (Py_ssize_t i = length; i > end_index; i --) {
- reflection->SwapElements(message, field_descriptor, i, i - 1);
- }
-
- Py_RETURN_NONE;
+static PyObject* AppendMethod(PyObject* pself, PyObject* value) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+ ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
+ if (py_cmsg == nullptr) {
+ return nullptr;
+ }
+
+ Py_RETURN_NONE;
}
// ---------------------------------------------------------------------
+// insert()
+static PyObject* Insert(PyObject* pself, PyObject* args) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+
+ Py_ssize_t index;
+ PyObject* value;
+ if (!PyArg_ParseTuple(args, "nO", &index, &value)) {
+ return nullptr;
+ }
+
+ ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
+ if (py_cmsg == nullptr) {
+ return nullptr;
+ }
+
+ // Swap the element to right position.
+ Message* message = self->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
+ Py_ssize_t length = reflection->FieldSize(*message, field_descriptor) - 1;
+ Py_ssize_t end_index = index;
+ if (end_index < 0) end_index += length;
+ if (end_index < 0) end_index = 0;
+ for (Py_ssize_t i = length; i > end_index; i --) {
+ reflection->SwapElements(message, field_descriptor, i, i - 1);
+ }
+
+ Py_RETURN_NONE;
+}
+
+// ---------------------------------------------------------------------
// extend()
PyObject* Extend(RepeatedCompositeContainer* self, PyObject* value) {
cmessage::AssureWritable(self->parent);
ScopedPyObjectPtr iter(PyObject_GetIter(value));
- if (iter == nullptr) {
+ if (iter == nullptr) {
PyErr_SetString(PyExc_TypeError, "Value must be iterable");
- return nullptr;
+ return nullptr;
}
ScopedPyObjectPtr next;
- while ((next.reset(PyIter_Next(iter.get()))) != nullptr) {
- if (!PyObject_TypeCheck(next.get(), CMessage_Type)) {
+ while ((next.reset(PyIter_Next(iter.get()))) != nullptr) {
+ if (!PyObject_TypeCheck(next.get(), CMessage_Type)) {
PyErr_SetString(PyExc_TypeError, "Not a cmessage");
- return nullptr;
+ return nullptr;
}
- ScopedPyObjectPtr new_message(Add(self, nullptr, nullptr));
- if (new_message == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr new_message(Add(self, nullptr, nullptr));
+ if (new_message == nullptr) {
+ return nullptr;
}
CMessage* new_cmessage = reinterpret_cast<CMessage*>(new_message.get());
if (ScopedPyObjectPtr(cmessage::MergeFrom(new_cmessage, next.get())) ==
- nullptr) {
- return nullptr;
+ nullptr) {
+ return nullptr;
}
}
if (PyErr_Occurred()) {
- return nullptr;
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* ExtendMethod(PyObject* self, PyObject* value) {
- return Extend(reinterpret_cast<RepeatedCompositeContainer*>(self), value);
-}
-
+static PyObject* ExtendMethod(PyObject* self, PyObject* value) {
+ return Extend(reinterpret_cast<RepeatedCompositeContainer*>(self), value);
+}
+
PyObject* MergeFrom(RepeatedCompositeContainer* self, PyObject* other) {
return Extend(self, other);
}
-static PyObject* MergeFromMethod(PyObject* self, PyObject* other) {
- return MergeFrom(reinterpret_cast<RepeatedCompositeContainer*>(self), other);
+static PyObject* MergeFromMethod(PyObject* self, PyObject* other) {
+ return MergeFrom(reinterpret_cast<RepeatedCompositeContainer*>(self), other);
}
-// This function does not check the bounds.
-static PyObject* GetItem(RepeatedCompositeContainer* self, Py_ssize_t index,
- Py_ssize_t length = -1) {
- if (length == -1) {
- Message* message = self->parent->message;
- const Reflection* reflection = message->GetReflection();
- length = reflection->FieldSize(*message, self->parent_field_descriptor);
+// This function does not check the bounds.
+static PyObject* GetItem(RepeatedCompositeContainer* self, Py_ssize_t index,
+ Py_ssize_t length = -1) {
+ if (length == -1) {
+ Message* message = self->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ length = reflection->FieldSize(*message, self->parent_field_descriptor);
}
- if (index < 0 || index >= length) {
- PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
- return nullptr;
+ if (index < 0 || index >= length) {
+ PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
+ return nullptr;
}
- Message* message = self->parent->message;
- Message* sub_message = message->GetReflection()->MutableRepeatedMessage(
- message, self->parent_field_descriptor, index);
- return self->parent
- ->BuildSubMessageFromPointer(self->parent_field_descriptor, sub_message,
- self->child_message_class)
- ->AsPyObject();
-}
-
-PyObject* Subscript(RepeatedCompositeContainer* self, PyObject* item) {
- Message* message = self->parent->message;
- const Reflection* reflection = message->GetReflection();
- Py_ssize_t length =
- reflection->FieldSize(*message, self->parent_field_descriptor);
-
- if (PyIndex_Check(item)) {
- Py_ssize_t index;
- index = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (index == -1 && PyErr_Occurred()) return nullptr;
- if (index < 0) index += length;
- return GetItem(self, index, length);
- } else if (PySlice_Check(item)) {
- Py_ssize_t from, to, step, slicelength, cur, i;
- PyObject* result;
-
+ Message* message = self->parent->message;
+ Message* sub_message = message->GetReflection()->MutableRepeatedMessage(
+ message, self->parent_field_descriptor, index);
+ return self->parent
+ ->BuildSubMessageFromPointer(self->parent_field_descriptor, sub_message,
+ self->child_message_class)
+ ->AsPyObject();
+}
+
+PyObject* Subscript(RepeatedCompositeContainer* self, PyObject* item) {
+ Message* message = self->parent->message;
+ const Reflection* reflection = message->GetReflection();
+ Py_ssize_t length =
+ reflection->FieldSize(*message, self->parent_field_descriptor);
+
+ if (PyIndex_Check(item)) {
+ Py_ssize_t index;
+ index = PyNumber_AsSsize_t(item, PyExc_IndexError);
+ if (index == -1 && PyErr_Occurred()) return nullptr;
+ if (index < 0) index += length;
+ return GetItem(self, index, length);
+ } else if (PySlice_Check(item)) {
+ Py_ssize_t from, to, step, slicelength, cur, i;
+ PyObject* result;
+
#if PY_MAJOR_VERSION >= 3
- if (PySlice_GetIndicesEx(item,
- length, &from, &to, &step, &slicelength) == -1) {
+ if (PySlice_GetIndicesEx(item,
+ length, &from, &to, &step, &slicelength) == -1) {
#else
- if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(item),
- length, &from, &to, &step, &slicelength) == -1) {
+ if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(item),
+ length, &from, &to, &step, &slicelength) == -1) {
#endif
- return nullptr;
- }
-
- if (slicelength <= 0) {
- return PyList_New(0);
- } else {
- result = PyList_New(slicelength);
- if (!result) return nullptr;
-
- for (cur = from, i = 0; i < slicelength; cur += step, i++) {
- PyList_SET_ITEM(result, i, GetItem(self, cur, length));
+ return nullptr;
+ }
+
+ if (slicelength <= 0) {
+ return PyList_New(0);
+ } else {
+ result = PyList_New(slicelength);
+ if (!result) return nullptr;
+
+ for (cur = from, i = 0; i < slicelength; cur += step, i++) {
+ PyList_SET_ITEM(result, i, GetItem(self, cur, length));
}
-
- return result;
+
+ return result;
}
- } else {
- PyErr_Format(PyExc_TypeError, "indices must be integers, not %.200s",
- item->ob_type->tp_name);
- return nullptr;
+ } else {
+ PyErr_Format(PyExc_TypeError, "indices must be integers, not %.200s",
+ item->ob_type->tp_name);
+ return nullptr;
}
-}
+}
-static PyObject* SubscriptMethod(PyObject* self, PyObject* slice) {
- return Subscript(reinterpret_cast<RepeatedCompositeContainer*>(self), slice);
+static PyObject* SubscriptMethod(PyObject* self, PyObject* slice) {
+ return Subscript(reinterpret_cast<RepeatedCompositeContainer*>(self), slice);
}
-int AssignSubscript(RepeatedCompositeContainer* self,
- PyObject* slice,
- PyObject* value) {
- if (value != nullptr) {
- PyErr_SetString(PyExc_TypeError, "does not support assignment");
- return -1;
+int AssignSubscript(RepeatedCompositeContainer* self,
+ PyObject* slice,
+ PyObject* value) {
+ if (value != nullptr) {
+ PyErr_SetString(PyExc_TypeError, "does not support assignment");
+ return -1;
}
-
- return cmessage::DeleteRepeatedField(self->parent,
- self->parent_field_descriptor, slice);
-}
-
-static int AssignSubscriptMethod(PyObject* self, PyObject* slice,
- PyObject* value) {
- return AssignSubscript(reinterpret_cast<RepeatedCompositeContainer*>(self),
- slice, value);
-}
-
-static PyObject* Remove(PyObject* pself, PyObject* value) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
- Py_ssize_t len = Length(reinterpret_cast<PyObject*>(self));
-
- for (Py_ssize_t i = 0; i < len; i++) {
- ScopedPyObjectPtr item(GetItem(self, i, len));
- if (item == nullptr) {
- return nullptr;
- }
- int result = PyObject_RichCompareBool(item.get(), value, Py_EQ);
- if (result < 0) {
- return nullptr;
- }
- if (result) {
- ScopedPyObjectPtr py_index(PyLong_FromSsize_t(i));
- if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
- return nullptr;
- }
- Py_RETURN_NONE;
- }
+
+ return cmessage::DeleteRepeatedField(self->parent,
+ self->parent_field_descriptor, slice);
+}
+
+static int AssignSubscriptMethod(PyObject* self, PyObject* slice,
+ PyObject* value) {
+ return AssignSubscript(reinterpret_cast<RepeatedCompositeContainer*>(self),
+ slice, value);
+}
+
+static PyObject* Remove(PyObject* pself, PyObject* value) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+ Py_ssize_t len = Length(reinterpret_cast<PyObject*>(self));
+
+ for (Py_ssize_t i = 0; i < len; i++) {
+ ScopedPyObjectPtr item(GetItem(self, i, len));
+ if (item == nullptr) {
+ return nullptr;
+ }
+ int result = PyObject_RichCompareBool(item.get(), value, Py_EQ);
+ if (result < 0) {
+ return nullptr;
+ }
+ if (result) {
+ ScopedPyObjectPtr py_index(PyLong_FromSsize_t(i));
+ if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
+ return nullptr;
+ }
+ Py_RETURN_NONE;
+ }
}
- PyErr_SetString(PyExc_ValueError, "Item to delete not in list");
- return nullptr;
+ PyErr_SetString(PyExc_ValueError, "Item to delete not in list");
+ return nullptr;
}
-static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
-
+static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+
if (!PyObject_TypeCheck(other, &RepeatedCompositeContainer_Type)) {
PyErr_SetString(PyExc_TypeError,
"Can only compare repeated composite fields "
"against other repeated composite fields.");
- return nullptr;
+ return nullptr;
}
if (opid == Py_EQ || opid == Py_NE) {
// TODO(anuraag): Don't make new lists just for this...
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
}
ScopedPyObjectPtr list(Subscript(self, full_slice.get()));
- if (list == nullptr) {
- return nullptr;
+ if (list == nullptr) {
+ return nullptr;
}
ScopedPyObjectPtr other_list(
Subscript(reinterpret_cast<RepeatedCompositeContainer*>(other),
full_slice.get()));
- if (other_list == nullptr) {
- return nullptr;
+ if (other_list == nullptr) {
+ return nullptr;
}
return PyObject_RichCompare(list.get(), other_list.get(), opid);
} else {
@@ -356,15 +356,15 @@ static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
}
}
-static PyObject* ToStr(PyObject* pself) {
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
+static PyObject* ToStr(PyObject* pself) {
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
}
- ScopedPyObjectPtr list(Subscript(
- reinterpret_cast<RepeatedCompositeContainer*>(pself), full_slice.get()));
- if (list == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr list(Subscript(
+ reinterpret_cast<RepeatedCompositeContainer*>(pself), full_slice.get()));
+ if (list == nullptr) {
+ return nullptr;
}
return PyObject_Repr(list.get());
}
@@ -372,26 +372,26 @@ static PyObject* ToStr(PyObject* pself) {
// ---------------------------------------------------------------------
// sort()
-static void ReorderAttached(RepeatedCompositeContainer* self,
- PyObject* child_list) {
- Message* message = self->parent->message;
+static void ReorderAttached(RepeatedCompositeContainer* self,
+ PyObject* child_list) {
+ Message* message = self->parent->message;
const Reflection* reflection = message->GetReflection();
const FieldDescriptor* descriptor = self->parent_field_descriptor;
- const Py_ssize_t length = Length(reinterpret_cast<PyObject*>(self));
+ const Py_ssize_t length = Length(reinterpret_cast<PyObject*>(self));
- // We need to rearrange things to match python's sort order. Because there
- // was already an O(n*log(n)) step in python and a bunch of reflection, we
- // expect an O(n**2) step in C++ won't hurt too much.
+ // We need to rearrange things to match python's sort order. Because there
+ // was already an O(n*log(n)) step in python and a bunch of reflection, we
+ // expect an O(n**2) step in C++ won't hurt too much.
for (Py_ssize_t i = 0; i < length; ++i) {
- Message* child_message =
- reinterpret_cast<CMessage*>(PyList_GET_ITEM(child_list, i))->message;
- for (Py_ssize_t j = i; j < length; ++j) {
- if (child_message ==
- &reflection->GetRepeatedMessage(*message, descriptor, j)) {
- reflection->SwapElements(message, descriptor, i, j);
- break;
- }
- }
+ Message* child_message =
+ reinterpret_cast<CMessage*>(PyList_GET_ITEM(child_list, i))->message;
+ for (Py_ssize_t j = i; j < length; ++j) {
+ if (child_message ==
+ &reflection->GetRepeatedMessage(*message, descriptor, j)) {
+ reflection->SwapElements(message, descriptor, i, j);
+ break;
+ }
+ }
}
}
@@ -400,28 +400,28 @@ static void ReorderAttached(RepeatedCompositeContainer* self,
static int SortPythonMessages(RepeatedCompositeContainer* self,
PyObject* args,
PyObject* kwds) {
- ScopedPyObjectPtr child_list(
- PySequence_List(reinterpret_cast<PyObject*>(self)));
- if (child_list == nullptr) {
+ ScopedPyObjectPtr child_list(
+ PySequence_List(reinterpret_cast<PyObject*>(self)));
+ if (child_list == nullptr) {
return -1;
- }
- ScopedPyObjectPtr m(PyObject_GetAttrString(child_list.get(), "sort"));
- if (m == nullptr) return -1;
- if (ScopedPyObjectPtr(PyObject_Call(m.get(), args, kwds)) == nullptr)
+ }
+ ScopedPyObjectPtr m(PyObject_GetAttrString(child_list.get(), "sort"));
+ if (m == nullptr) return -1;
+ if (ScopedPyObjectPtr(PyObject_Call(m.get(), args, kwds)) == nullptr)
return -1;
- ReorderAttached(self, child_list.get());
+ ReorderAttached(self, child_list.get());
return 0;
}
-static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
-
+static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+
// Support the old sort_function argument for backwards
// compatibility.
- if (kwds != nullptr) {
+ if (kwds != nullptr) {
PyObject* sort_func = PyDict_GetItemString(kwds, "sort_function");
- if (sort_func != nullptr) {
+ if (sort_func != nullptr) {
// Must set before deleting as sort_func is a borrowed reference
// and kwds might be the only thing keeping it alive.
PyDict_SetItemString(kwds, "cmp", sort_func);
@@ -430,181 +430,181 @@ static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
}
if (SortPythonMessages(self, args, kwds) < 0) {
- return nullptr;
+ return nullptr;
}
Py_RETURN_NONE;
}
// ---------------------------------------------------------------------
-// reverse()
-
-// Returns 0 if successful; returns -1 and sets an exception if
-// unsuccessful.
-static int ReversePythonMessages(RepeatedCompositeContainer* self) {
- ScopedPyObjectPtr child_list(
- PySequence_List(reinterpret_cast<PyObject*>(self)));
- if (child_list == nullptr) {
- return -1;
+// reverse()
+
+// Returns 0 if successful; returns -1 and sets an exception if
+// unsuccessful.
+static int ReversePythonMessages(RepeatedCompositeContainer* self) {
+ ScopedPyObjectPtr child_list(
+ PySequence_List(reinterpret_cast<PyObject*>(self)));
+ if (child_list == nullptr) {
+ return -1;
}
- if (ScopedPyObjectPtr(
- PyObject_CallMethod(child_list.get(), "reverse", nullptr)) == nullptr)
- return -1;
- ReorderAttached(self, child_list.get());
- return 0;
+ if (ScopedPyObjectPtr(
+ PyObject_CallMethod(child_list.get(), "reverse", nullptr)) == nullptr)
+ return -1;
+ ReorderAttached(self, child_list.get());
+ return 0;
}
-static PyObject* Reverse(PyObject* pself) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
-
- if (ReversePythonMessages(self) < 0) {
- return nullptr;
+static PyObject* Reverse(PyObject* pself) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+
+ if (ReversePythonMessages(self) < 0) {
+ return nullptr;
}
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
-// ---------------------------------------------------------------------
+// ---------------------------------------------------------------------
-static PyObject* Item(PyObject* pself, Py_ssize_t index) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
- return GetItem(self, index);
+static PyObject* Item(PyObject* pself, Py_ssize_t index) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+ return GetItem(self, index);
}
-static PyObject* Pop(PyObject* pself, PyObject* args) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
+static PyObject* Pop(PyObject* pself, PyObject* args) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
- Py_ssize_t index = -1;
- if (!PyArg_ParseTuple(args, "|n", &index)) {
- return nullptr;
+ Py_ssize_t index = -1;
+ if (!PyArg_ParseTuple(args, "|n", &index)) {
+ return nullptr;
}
- Py_ssize_t length = Length(pself);
- if (index < 0) index += length;
- PyObject* item = GetItem(self, index, length);
- if (item == nullptr) {
- return nullptr;
+ Py_ssize_t length = Length(pself);
+ if (index < 0) index += length;
+ PyObject* item = GetItem(self, index, length);
+ if (item == nullptr) {
+ return nullptr;
}
- ScopedPyObjectPtr py_index(PyLong_FromSsize_t(index));
- if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
- return nullptr;
- }
- return item;
+ ScopedPyObjectPtr py_index(PyLong_FromSsize_t(index));
+ if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
+ return nullptr;
+ }
+ return item;
}
-PyObject* DeepCopy(PyObject* pself, PyObject* arg) {
- return reinterpret_cast<RepeatedCompositeContainer*>(pself)->DeepCopy();
+PyObject* DeepCopy(PyObject* pself, PyObject* arg) {
+ return reinterpret_cast<RepeatedCompositeContainer*>(pself)->DeepCopy();
}
// The private constructor of RepeatedCompositeContainer objects.
-RepeatedCompositeContainer *NewContainer(
+RepeatedCompositeContainer *NewContainer(
CMessage* parent,
const FieldDescriptor* parent_field_descriptor,
- CMessageClass* child_message_class) {
+ CMessageClass* child_message_class) {
if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
- return nullptr;
+ return nullptr;
}
RepeatedCompositeContainer* self =
reinterpret_cast<RepeatedCompositeContainer*>(
PyType_GenericAlloc(&RepeatedCompositeContainer_Type, 0));
- if (self == nullptr) {
- return nullptr;
+ if (self == nullptr) {
+ return nullptr;
}
- Py_INCREF(parent);
+ Py_INCREF(parent);
self->parent = parent;
self->parent_field_descriptor = parent_field_descriptor;
- Py_INCREF(child_message_class);
- self->child_message_class = child_message_class;
- return self;
+ Py_INCREF(child_message_class);
+ self->child_message_class = child_message_class;
+ return self;
}
-static void Dealloc(PyObject* pself) {
- RepeatedCompositeContainer* self =
- reinterpret_cast<RepeatedCompositeContainer*>(pself);
- self->RemoveFromParentCache();
+static void Dealloc(PyObject* pself) {
+ RepeatedCompositeContainer* self =
+ reinterpret_cast<RepeatedCompositeContainer*>(pself);
+ self->RemoveFromParentCache();
Py_CLEAR(self->child_message_class);
- Py_TYPE(self)->tp_free(pself);
+ Py_TYPE(self)->tp_free(pself);
}
static PySequenceMethods SqMethods = {
- Length, /* sq_length */
- nullptr, /* sq_concat */
- nullptr, /* sq_repeat */
- Item /* sq_item */
+ Length, /* sq_length */
+ nullptr, /* sq_concat */
+ nullptr, /* sq_repeat */
+ Item /* sq_item */
};
static PyMappingMethods MpMethods = {
- Length, /* mp_length */
- SubscriptMethod, /* mp_subscript */
- AssignSubscriptMethod, /* mp_ass_subscript */
+ Length, /* mp_length */
+ SubscriptMethod, /* mp_subscript */
+ AssignSubscriptMethod, /* mp_ass_subscript */
};
static PyMethodDef Methods[] = {
- {"__deepcopy__", DeepCopy, METH_VARARGS, "Makes a deep copy of the class."},
- {"add", reinterpret_cast<PyCFunction>(AddMethod),
- METH_VARARGS | METH_KEYWORDS, "Adds an object to the repeated container."},
- {"append", AppendMethod, METH_O,
- "Appends a message to the end of the repeated container."},
- {"insert", Insert, METH_VARARGS,
- "Inserts a message before the specified index."},
- {"extend", ExtendMethod, METH_O, "Adds objects to the repeated container."},
- {"pop", Pop, METH_VARARGS,
- "Removes an object from the repeated container and returns it."},
- {"remove", Remove, METH_O,
- "Removes an object from the repeated container."},
- {"sort", reinterpret_cast<PyCFunction>(Sort), METH_VARARGS | METH_KEYWORDS,
- "Sorts the repeated container."},
- {"reverse", reinterpret_cast<PyCFunction>(Reverse), METH_NOARGS,
- "Reverses elements order of the repeated container."},
- {"MergeFrom", MergeFromMethod, METH_O,
- "Adds objects to the repeated container."},
- {nullptr, nullptr}};
+ {"__deepcopy__", DeepCopy, METH_VARARGS, "Makes a deep copy of the class."},
+ {"add", reinterpret_cast<PyCFunction>(AddMethod),
+ METH_VARARGS | METH_KEYWORDS, "Adds an object to the repeated container."},
+ {"append", AppendMethod, METH_O,
+ "Appends a message to the end of the repeated container."},
+ {"insert", Insert, METH_VARARGS,
+ "Inserts a message before the specified index."},
+ {"extend", ExtendMethod, METH_O, "Adds objects to the repeated container."},
+ {"pop", Pop, METH_VARARGS,
+ "Removes an object from the repeated container and returns it."},
+ {"remove", Remove, METH_O,
+ "Removes an object from the repeated container."},
+ {"sort", reinterpret_cast<PyCFunction>(Sort), METH_VARARGS | METH_KEYWORDS,
+ "Sorts the repeated container."},
+ {"reverse", reinterpret_cast<PyCFunction>(Reverse), METH_NOARGS,
+ "Reverses elements order of the repeated container."},
+ {"MergeFrom", MergeFromMethod, METH_O,
+ "Adds objects to the repeated container."},
+ {nullptr, nullptr}};
} // namespace repeated_composite_container
PyTypeObject RepeatedCompositeContainer_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".RepeatedCompositeContainer", // tp_name
- sizeof(RepeatedCompositeContainer), // tp_basicsize
- 0, // tp_itemsize
- repeated_composite_container::Dealloc, // tp_dealloc
-#if PY_VERSION_HEX >= 0x03080000
- 0, // tp_vectorcall_offset
-#else
- nullptr, // tp_print
-#endif
- nullptr, // tp_getattr
- nullptr, // tp_setattr
- nullptr, // tp_compare
- repeated_composite_container::ToStr, // tp_repr
- nullptr, // tp_as_number
- &repeated_composite_container::SqMethods, // tp_as_sequence
- &repeated_composite_container::MpMethods, // tp_as_mapping
- PyObject_HashNotImplemented, // tp_hash
- nullptr, // tp_call
- nullptr, // tp_str
- nullptr, // tp_getattro
- nullptr, // tp_setattro
- nullptr, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "A Repeated scalar container", // tp_doc
- nullptr, // tp_traverse
- nullptr, // tp_clear
- repeated_composite_container::RichCompare, // tp_richcompare
- 0, // tp_weaklistoffset
- nullptr, // tp_iter
- nullptr, // tp_iternext
- repeated_composite_container::Methods, // tp_methods
- nullptr, // tp_members
- nullptr, // tp_getset
- nullptr, // tp_base
- nullptr, // tp_dict
- nullptr, // tp_descr_get
- nullptr, // tp_descr_set
- 0, // tp_dictoffset
- nullptr, // tp_init
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".RepeatedCompositeContainer", // tp_name
+ sizeof(RepeatedCompositeContainer), // tp_basicsize
+ 0, // tp_itemsize
+ repeated_composite_container::Dealloc, // tp_dealloc
+#if PY_VERSION_HEX >= 0x03080000
+ 0, // tp_vectorcall_offset
+#else
+ nullptr, // tp_print
+#endif
+ nullptr, // tp_getattr
+ nullptr, // tp_setattr
+ nullptr, // tp_compare
+ repeated_composite_container::ToStr, // tp_repr
+ nullptr, // tp_as_number
+ &repeated_composite_container::SqMethods, // tp_as_sequence
+ &repeated_composite_container::MpMethods, // tp_as_mapping
+ PyObject_HashNotImplemented, // tp_hash
+ nullptr, // tp_call
+ nullptr, // tp_str
+ nullptr, // tp_getattro
+ nullptr, // tp_setattro
+ nullptr, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "A Repeated scalar container", // tp_doc
+ nullptr, // tp_traverse
+ nullptr, // tp_clear
+ repeated_composite_container::RichCompare, // tp_richcompare
+ 0, // tp_weaklistoffset
+ nullptr, // tp_iter
+ nullptr, // tp_iternext
+ repeated_composite_container::Methods, // tp_methods
+ nullptr, // tp_members
+ nullptr, // tp_getset
+ nullptr, // tp_base
+ nullptr, // tp_dict
+ nullptr, // tp_descr_get
+ nullptr, // tp_descr_set
+ 0, // tp_dictoffset
+ nullptr, // tp_init
};
} // namespace python
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_composite_container.h b/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_composite_container.h
index e241827ef5..94c4aae60a 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_composite_container.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_composite_container.h
@@ -37,11 +37,11 @@
#include <Python.h>
#include <memory>
-#include <string>
+#include <string>
#include <vector>
-#include <google/protobuf/pyext/message.h>
-
+#include <google/protobuf/pyext/message.h>
+
namespace google {
namespace protobuf {
@@ -52,9 +52,9 @@ namespace python {
struct CMessageClass;
-// A RepeatedCompositeContainer always has a parent message.
-// The parent message also caches reference to items of the container.
-typedef struct RepeatedCompositeContainer : public ContainerBase {
+// A RepeatedCompositeContainer always has a parent message.
+// The parent message also caches reference to items of the container.
+typedef struct RepeatedCompositeContainer : public ContainerBase {
// The type used to create new child messages.
CMessageClass* child_message_class;
} RepeatedCompositeContainer;
@@ -65,7 +65,7 @@ namespace repeated_composite_container {
// Builds a RepeatedCompositeContainer object, from a parent message and a
// field descriptor.
-RepeatedCompositeContainer* NewContainer(
+RepeatedCompositeContainer* NewContainer(
CMessage* parent,
const FieldDescriptor* parent_field_descriptor,
CMessageClass *child_message_class);
@@ -107,6 +107,6 @@ int AssignSubscript(RepeatedCompositeContainer* self,
} // namespace repeated_composite_container
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_COMPOSITE_CONTAINER_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_scalar_container.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_scalar_container.cc
index 3a41a58adb..e364be76b0 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_scalar_container.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_scalar_container.cc
@@ -31,30 +31,30 @@
// Author: anuraag@google.com (Anuraag Agrawal)
// Author: tibell@google.com (Johan Tibell)
-#include <google/protobuf/pyext/repeated_scalar_container.h>
+#include <google/protobuf/pyext/repeated_scalar_container.h>
-#include <cstdint>
+#include <cstdint>
#include <memory>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/dynamic_message.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#if PY_MAJOR_VERSION >= 3
-#define PyInt_FromLong PyLong_FromLong
-#if PY_VERSION_HEX < 0x03030000
-#error "Python 3.0 - 3.2 are not supported."
-#else
-#define PyString_AsString(ob) \
- (PyUnicode_Check(ob) ? PyUnicode_AsUTF8(ob) : PyBytes_AsString(ob))
-#endif
+#define PyInt_FromLong PyLong_FromLong
+#if PY_VERSION_HEX < 0x03030000
+#error "Python 3.0 - 3.2 are not supported."
+#else
+#define PyString_AsString(ob) \
+ (PyUnicode_Check(ob) ? PyUnicode_AsUTF8(ob) : PyBytes_AsString(ob))
#endif
+#endif
namespace google {
namespace protobuf {
@@ -62,33 +62,33 @@ namespace python {
namespace repeated_scalar_container {
-static int InternalAssignRepeatedField(RepeatedScalarContainer* self,
- PyObject* list) {
- Message* message = self->parent->message;
- message->GetReflection()->ClearField(message, self->parent_field_descriptor);
+static int InternalAssignRepeatedField(RepeatedScalarContainer* self,
+ PyObject* list) {
+ Message* message = self->parent->message;
+ message->GetReflection()->ClearField(message, self->parent_field_descriptor);
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(list); ++i) {
PyObject* value = PyList_GET_ITEM(list, i);
- if (ScopedPyObjectPtr(Append(self, value)) == nullptr) {
+ if (ScopedPyObjectPtr(Append(self, value)) == nullptr) {
return -1;
}
}
return 0;
}
-static Py_ssize_t Len(PyObject* pself) {
- RepeatedScalarContainer* self =
- reinterpret_cast<RepeatedScalarContainer*>(pself);
- Message* message = self->parent->message;
+static Py_ssize_t Len(PyObject* pself) {
+ RepeatedScalarContainer* self =
+ reinterpret_cast<RepeatedScalarContainer*>(pself);
+ Message* message = self->parent->message;
return message->GetReflection()->FieldSize(*message,
self->parent_field_descriptor);
}
-static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
- RepeatedScalarContainer* self =
- reinterpret_cast<RepeatedScalarContainer*>(pself);
-
+static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
+ RepeatedScalarContainer* self =
+ reinterpret_cast<RepeatedScalarContainer*>(pself);
+
cmessage::AssureWritable(self->parent);
- Message* message = self->parent->message;
+ Message* message = self->parent->message;
const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
const Reflection* reflection = message->GetReflection();
@@ -97,15 +97,15 @@ static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
index = field_size + index;
}
if (index < 0 || index >= field_size) {
- PyErr_Format(PyExc_IndexError, "list assignment index (%d) out of range",
+ PyErr_Format(PyExc_IndexError, "list assignment index (%d) out of range",
static_cast<int>(index));
return -1;
}
- if (arg == nullptr) {
+ if (arg == nullptr) {
ScopedPyObjectPtr py_index(PyLong_FromLong(index));
- return cmessage::DeleteRepeatedField(self->parent, field_descriptor,
- py_index.get());
+ return cmessage::DeleteRepeatedField(self->parent, field_descriptor,
+ py_index.get());
}
if (PySequence_Check(arg) && !(PyBytes_Check(arg) || PyUnicode_Check(arg))) {
@@ -150,8 +150,8 @@ static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- if (!CheckAndSetString(arg, message, field_descriptor, reflection, false,
- index)) {
+ if (!CheckAndSetString(arg, message, field_descriptor, reflection, false,
+ index)) {
return -1;
}
break;
@@ -165,12 +165,12 @@ static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();
const EnumValueDescriptor* enum_value =
enum_descriptor->FindValueByNumber(value);
- if (enum_value != nullptr) {
+ if (enum_value != nullptr) {
reflection->SetRepeatedEnum(message, field_descriptor, index,
enum_value);
} else {
ScopedPyObjectPtr s(PyObject_Str(arg));
- if (s != nullptr) {
+ if (s != nullptr) {
PyErr_Format(PyExc_ValueError, "Unknown enum value: %s",
PyString_AsString(s.get()));
}
@@ -180,19 +180,19 @@ static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
break;
}
default:
- PyErr_Format(PyExc_SystemError,
- "Adding value to a field of unknown type %d",
- field_descriptor->cpp_type());
+ PyErr_Format(PyExc_SystemError,
+ "Adding value to a field of unknown type %d",
+ field_descriptor->cpp_type());
return -1;
}
return 0;
}
-static PyObject* Item(PyObject* pself, Py_ssize_t index) {
- RepeatedScalarContainer* self =
- reinterpret_cast<RepeatedScalarContainer*>(pself);
-
- Message* message = self->parent->message;
+static PyObject* Item(PyObject* pself, Py_ssize_t index) {
+ RepeatedScalarContainer* self =
+ reinterpret_cast<RepeatedScalarContainer*>(pself);
+
+ Message* message = self->parent->message;
const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
const Reflection* reflection = message->GetReflection();
@@ -201,78 +201,78 @@ static PyObject* Item(PyObject* pself, Py_ssize_t index) {
index = field_size + index;
}
if (index < 0 || index >= field_size) {
- PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
- return nullptr;
+ PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
+ return nullptr;
}
- PyObject* result = nullptr;
+ PyObject* result = nullptr;
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
- int32_t value =
- reflection->GetRepeatedInt32(*message, field_descriptor, index);
+ int32_t value =
+ reflection->GetRepeatedInt32(*message, field_descriptor, index);
result = PyInt_FromLong(value);
break;
}
case FieldDescriptor::CPPTYPE_INT64: {
- int64_t value =
- reflection->GetRepeatedInt64(*message, field_descriptor, index);
+ int64_t value =
+ reflection->GetRepeatedInt64(*message, field_descriptor, index);
result = PyLong_FromLongLong(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT32: {
- uint32_t value =
- reflection->GetRepeatedUInt32(*message, field_descriptor, index);
+ uint32_t value =
+ reflection->GetRepeatedUInt32(*message, field_descriptor, index);
result = PyLong_FromLongLong(value);
break;
}
case FieldDescriptor::CPPTYPE_UINT64: {
- uint64_t value =
- reflection->GetRepeatedUInt64(*message, field_descriptor, index);
+ uint64_t value =
+ reflection->GetRepeatedUInt64(*message, field_descriptor, index);
result = PyLong_FromUnsignedLongLong(value);
break;
}
case FieldDescriptor::CPPTYPE_FLOAT: {
- float value =
- reflection->GetRepeatedFloat(*message, field_descriptor, index);
+ float value =
+ reflection->GetRepeatedFloat(*message, field_descriptor, index);
result = PyFloat_FromDouble(value);
break;
}
case FieldDescriptor::CPPTYPE_DOUBLE: {
- double value =
- reflection->GetRepeatedDouble(*message, field_descriptor, index);
+ double value =
+ reflection->GetRepeatedDouble(*message, field_descriptor, index);
result = PyFloat_FromDouble(value);
break;
}
case FieldDescriptor::CPPTYPE_BOOL: {
- bool value =
- reflection->GetRepeatedBool(*message, field_descriptor, index);
+ bool value =
+ reflection->GetRepeatedBool(*message, field_descriptor, index);
result = PyBool_FromLong(value ? 1 : 0);
break;
}
case FieldDescriptor::CPPTYPE_ENUM: {
const EnumValueDescriptor* enum_value =
- message->GetReflection()->GetRepeatedEnum(*message, field_descriptor,
- index);
+ message->GetReflection()->GetRepeatedEnum(*message, field_descriptor,
+ index);
result = PyInt_FromLong(enum_value->number());
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- TProtoStringType scratch;
- const TProtoStringType& value = reflection->GetRepeatedStringReference(
- *message, field_descriptor, index, &scratch);
+ TProtoStringType scratch;
+ const TProtoStringType& value = reflection->GetRepeatedStringReference(
+ *message, field_descriptor, index, &scratch);
result = ToStringObject(field_descriptor, value);
break;
}
default:
- PyErr_Format(PyExc_SystemError,
- "Getting value from a repeated field of unknown type %d",
- field_descriptor->cpp_type());
+ PyErr_Format(PyExc_SystemError,
+ "Getting value from a repeated field of unknown type %d",
+ field_descriptor->cpp_type());
}
return result;
}
-static PyObject* Subscript(PyObject* pself, PyObject* slice) {
+static PyObject* Subscript(PyObject* pself, PyObject* slice) {
Py_ssize_t from;
Py_ssize_t to;
Py_ssize_t step;
@@ -284,32 +284,32 @@ static PyObject* Subscript(PyObject* pself, PyObject* slice) {
from = to = PyInt_AsLong(slice);
} else // NOLINT
#endif
- if (PyLong_Check(slice)) {
+ if (PyLong_Check(slice)) {
from = to = PyLong_AsLong(slice);
} else if (PySlice_Check(slice)) {
- length = Len(pself);
+ length = Len(pself);
#if PY_MAJOR_VERSION >= 3
- if (PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slicelength) ==
- -1) {
+ if (PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slicelength) ==
+ -1) {
#else
- if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), length,
- &from, &to, &step, &slicelength) == -1) {
+ if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), length,
+ &from, &to, &step, &slicelength) == -1) {
#endif
- return nullptr;
+ return nullptr;
}
return_list = true;
} else {
PyErr_SetString(PyExc_TypeError, "list indices must be integers");
- return nullptr;
+ return nullptr;
}
if (!return_list) {
- return Item(pself, from);
+ return Item(pself, from);
}
PyObject* list = PyList_New(0);
- if (list == nullptr) {
- return nullptr;
+ if (list == nullptr) {
+ return nullptr;
}
if (from <= to) {
if (step < 0) {
@@ -319,7 +319,7 @@ static PyObject* Subscript(PyObject* pself, PyObject* slice) {
if (index < 0 || index >= length) {
break;
}
- ScopedPyObjectPtr s(Item(pself, index));
+ ScopedPyObjectPtr s(Item(pself, index));
PyList_Append(list, s.get());
}
} else {
@@ -330,7 +330,7 @@ static PyObject* Subscript(PyObject* pself, PyObject* slice) {
if (index < 0 || index >= length) {
break;
}
- ScopedPyObjectPtr s(Item(pself, index));
+ ScopedPyObjectPtr s(Item(pself, index));
PyList_Append(list, s.get());
}
}
@@ -339,92 +339,92 @@ static PyObject* Subscript(PyObject* pself, PyObject* slice) {
PyObject* Append(RepeatedScalarContainer* self, PyObject* item) {
cmessage::AssureWritable(self->parent);
- Message* message = self->parent->message;
+ Message* message = self->parent->message;
const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
const Reflection* reflection = message->GetReflection();
switch (field_descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
- GOOGLE_CHECK_GET_INT32(item, value, nullptr);
+ GOOGLE_CHECK_GET_INT32(item, value, nullptr);
reflection->AddInt32(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_INT64: {
- GOOGLE_CHECK_GET_INT64(item, value, nullptr);
+ GOOGLE_CHECK_GET_INT64(item, value, nullptr);
reflection->AddInt64(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_UINT32: {
- GOOGLE_CHECK_GET_UINT32(item, value, nullptr);
+ GOOGLE_CHECK_GET_UINT32(item, value, nullptr);
reflection->AddUInt32(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_UINT64: {
- GOOGLE_CHECK_GET_UINT64(item, value, nullptr);
+ GOOGLE_CHECK_GET_UINT64(item, value, nullptr);
reflection->AddUInt64(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_FLOAT: {
- GOOGLE_CHECK_GET_FLOAT(item, value, nullptr);
+ GOOGLE_CHECK_GET_FLOAT(item, value, nullptr);
reflection->AddFloat(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_DOUBLE: {
- GOOGLE_CHECK_GET_DOUBLE(item, value, nullptr);
+ GOOGLE_CHECK_GET_DOUBLE(item, value, nullptr);
reflection->AddDouble(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_BOOL: {
- GOOGLE_CHECK_GET_BOOL(item, value, nullptr);
+ GOOGLE_CHECK_GET_BOOL(item, value, nullptr);
reflection->AddBool(message, field_descriptor, value);
break;
}
case FieldDescriptor::CPPTYPE_STRING: {
- if (!CheckAndSetString(item, message, field_descriptor, reflection, true,
- -1)) {
- return nullptr;
+ if (!CheckAndSetString(item, message, field_descriptor, reflection, true,
+ -1)) {
+ return nullptr;
}
break;
}
case FieldDescriptor::CPPTYPE_ENUM: {
- GOOGLE_CHECK_GET_INT32(item, value, nullptr);
+ GOOGLE_CHECK_GET_INT32(item, value, nullptr);
if (reflection->SupportsUnknownEnumValues()) {
reflection->AddEnumValue(message, field_descriptor, value);
} else {
const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();
const EnumValueDescriptor* enum_value =
enum_descriptor->FindValueByNumber(value);
- if (enum_value != nullptr) {
+ if (enum_value != nullptr) {
reflection->AddEnum(message, field_descriptor, enum_value);
} else {
ScopedPyObjectPtr s(PyObject_Str(item));
- if (s != nullptr) {
+ if (s != nullptr) {
PyErr_Format(PyExc_ValueError, "Unknown enum value: %s",
PyString_AsString(s.get()));
}
- return nullptr;
+ return nullptr;
}
}
break;
}
default:
- PyErr_Format(PyExc_SystemError,
- "Adding value to a field of unknown type %d",
- field_descriptor->cpp_type());
- return nullptr;
+ PyErr_Format(PyExc_SystemError,
+ "Adding value to a field of unknown type %d",
+ field_descriptor->cpp_type());
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* AppendMethod(PyObject* self, PyObject* item) {
- return Append(reinterpret_cast<RepeatedScalarContainer*>(self), item);
-}
-
-static int AssSubscript(PyObject* pself, PyObject* slice, PyObject* value) {
- RepeatedScalarContainer* self =
- reinterpret_cast<RepeatedScalarContainer*>(pself);
-
+static PyObject* AppendMethod(PyObject* self, PyObject* item) {
+ return Append(reinterpret_cast<RepeatedScalarContainer*>(self), item);
+}
+
+static int AssSubscript(PyObject* pself, PyObject* slice, PyObject* value) {
+ RepeatedScalarContainer* self =
+ reinterpret_cast<RepeatedScalarContainer*>(pself);
+
Py_ssize_t from;
Py_ssize_t to;
Py_ssize_t step;
@@ -433,25 +433,25 @@ static int AssSubscript(PyObject* pself, PyObject* slice, PyObject* value) {
bool create_list = false;
cmessage::AssureWritable(self->parent);
- Message* message = self->parent->message;
- const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
+ Message* message = self->parent->message;
+ const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
#if PY_MAJOR_VERSION < 3
if (PyInt_Check(slice)) {
from = to = PyInt_AsLong(slice);
- } else // NOLINT
+ } else // NOLINT
#endif
- if (PyLong_Check(slice)) {
+ if (PyLong_Check(slice)) {
from = to = PyLong_AsLong(slice);
} else if (PySlice_Check(slice)) {
const Reflection* reflection = message->GetReflection();
length = reflection->FieldSize(*message, field_descriptor);
#if PY_MAJOR_VERSION >= 3
- if (PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slicelength) ==
- -1) {
+ if (PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slicelength) ==
+ -1) {
#else
- if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), length,
- &from, &to, &step, &slicelength) == -1) {
+ if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), length,
+ &from, &to, &step, &slicelength) == -1) {
#endif
return -1;
}
@@ -461,20 +461,20 @@ static int AssSubscript(PyObject* pself, PyObject* slice, PyObject* value) {
return -1;
}
- if (value == nullptr) {
- return cmessage::DeleteRepeatedField(self->parent, field_descriptor, slice);
+ if (value == nullptr) {
+ return cmessage::DeleteRepeatedField(self->parent, field_descriptor, slice);
}
if (!create_list) {
- return AssignItem(pself, from, value);
+ return AssignItem(pself, from, value);
}
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
return -1;
}
- ScopedPyObjectPtr new_list(Subscript(pself, full_slice.get()));
- if (new_list == nullptr) {
+ ScopedPyObjectPtr new_list(Subscript(pself, full_slice.get()));
+ if (new_list == nullptr) {
return -1;
}
if (PySequence_SetSlice(new_list.get(), from, to, value) < 0) {
@@ -491,52 +491,52 @@ PyObject* Extend(RepeatedScalarContainer* self, PyObject* value) {
if (value == Py_None) {
Py_RETURN_NONE;
}
- if ((Py_TYPE(value)->tp_as_sequence == nullptr) && PyObject_Not(value)) {
+ if ((Py_TYPE(value)->tp_as_sequence == nullptr) && PyObject_Not(value)) {
Py_RETURN_NONE;
}
ScopedPyObjectPtr iter(PyObject_GetIter(value));
- if (iter == nullptr) {
+ if (iter == nullptr) {
PyErr_SetString(PyExc_TypeError, "Value must be iterable");
- return nullptr;
+ return nullptr;
}
ScopedPyObjectPtr next;
- while ((next.reset(PyIter_Next(iter.get()))) != nullptr) {
- if (ScopedPyObjectPtr(Append(self, next.get())) == nullptr) {
- return nullptr;
+ while ((next.reset(PyIter_Next(iter.get()))) != nullptr) {
+ if (ScopedPyObjectPtr(Append(self, next.get())) == nullptr) {
+ return nullptr;
}
}
if (PyErr_Occurred()) {
- return nullptr;
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* Insert(PyObject* pself, PyObject* args) {
- RepeatedScalarContainer* self =
- reinterpret_cast<RepeatedScalarContainer*>(pself);
-
+static PyObject* Insert(PyObject* pself, PyObject* args) {
+ RepeatedScalarContainer* self =
+ reinterpret_cast<RepeatedScalarContainer*>(pself);
+
Py_ssize_t index;
PyObject* value;
if (!PyArg_ParseTuple(args, "lO", &index, &value)) {
- return nullptr;
+ return nullptr;
}
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- ScopedPyObjectPtr new_list(Subscript(pself, full_slice.get()));
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ ScopedPyObjectPtr new_list(Subscript(pself, full_slice.get()));
if (PyList_Insert(new_list.get(), index, value) < 0) {
- return nullptr;
+ return nullptr;
}
int ret = InternalAssignRepeatedField(self, new_list.get());
if (ret < 0) {
- return nullptr;
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* Remove(PyObject* pself, PyObject* value) {
+static PyObject* Remove(PyObject* pself, PyObject* value) {
Py_ssize_t match_index = -1;
- for (Py_ssize_t i = 0; i < Len(pself); ++i) {
- ScopedPyObjectPtr elem(Item(pself, i));
+ for (Py_ssize_t i = 0; i < Len(pself); ++i) {
+ ScopedPyObjectPtr elem(Item(pself, i));
if (PyObject_RichCompareBool(elem.get(), value, Py_EQ)) {
match_index = i;
break;
@@ -544,19 +544,19 @@ static PyObject* Remove(PyObject* pself, PyObject* value) {
}
if (match_index == -1) {
PyErr_SetString(PyExc_ValueError, "remove(x): x not in container");
- return nullptr;
+ return nullptr;
}
- if (AssignItem(pself, match_index, nullptr) < 0) {
- return nullptr;
+ if (AssignItem(pself, match_index, nullptr) < 0) {
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* ExtendMethod(PyObject* self, PyObject* value) {
- return Extend(reinterpret_cast<RepeatedScalarContainer*>(self), value);
-}
-
-static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
+static PyObject* ExtendMethod(PyObject* self, PyObject* value) {
+ return Extend(reinterpret_cast<RepeatedScalarContainer*>(self), value);
+}
+
+static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
if (opid != Py_EQ && opid != Py_NE) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
@@ -566,229 +566,229 @@ static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
// also a repeated scalar container, into Python lists so we can delegate
// to the list's compare method.
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
}
ScopedPyObjectPtr other_list_deleter;
if (PyObject_TypeCheck(other, &RepeatedScalarContainer_Type)) {
- other_list_deleter.reset(Subscript(other, full_slice.get()));
+ other_list_deleter.reset(Subscript(other, full_slice.get()));
other = other_list_deleter.get();
}
- ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
- if (list == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
+ if (list == nullptr) {
+ return nullptr;
}
return PyObject_RichCompare(list.get(), other, opid);
}
-PyObject* Reduce(PyObject* unused_self, PyObject* unused_other) {
- PyErr_Format(PickleError_class,
- "can't pickle repeated message fields, convert to list first");
- return nullptr;
+PyObject* Reduce(PyObject* unused_self, PyObject* unused_other) {
+ PyErr_Format(PickleError_class,
+ "can't pickle repeated message fields, convert to list first");
+ return nullptr;
}
-static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
+static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
// Support the old sort_function argument for backwards
// compatibility.
- if (kwds != nullptr) {
+ if (kwds != nullptr) {
PyObject* sort_func = PyDict_GetItemString(kwds, "sort_function");
- if (sort_func != nullptr) {
+ if (sort_func != nullptr) {
// Must set before deleting as sort_func is a borrowed reference
// and kwds might be the only thing keeping it alive.
- if (PyDict_SetItemString(kwds, "cmp", sort_func) == -1) return nullptr;
- if (PyDict_DelItemString(kwds, "sort_function") == -1) return nullptr;
+ if (PyDict_SetItemString(kwds, "cmp", sort_func) == -1) return nullptr;
+ if (PyDict_DelItemString(kwds, "sort_function") == -1) return nullptr;
}
}
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
}
- ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
- if (list == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
+ if (list == nullptr) {
+ return nullptr;
}
ScopedPyObjectPtr m(PyObject_GetAttrString(list.get(), "sort"));
- if (m == nullptr) {
- return nullptr;
+ if (m == nullptr) {
+ return nullptr;
}
ScopedPyObjectPtr res(PyObject_Call(m.get(), args, kwds));
- if (res == nullptr) {
- return nullptr;
+ if (res == nullptr) {
+ return nullptr;
}
- int ret = InternalAssignRepeatedField(
- reinterpret_cast<RepeatedScalarContainer*>(pself), list.get());
+ int ret = InternalAssignRepeatedField(
+ reinterpret_cast<RepeatedScalarContainer*>(pself), list.get());
if (ret < 0) {
- return nullptr;
+ return nullptr;
}
Py_RETURN_NONE;
}
-static PyObject* Reverse(PyObject* pself) {
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
- }
- ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
- if (list == nullptr) {
- return nullptr;
- }
- ScopedPyObjectPtr res(PyObject_CallMethod(list.get(), "reverse", nullptr));
- if (res == nullptr) {
- return nullptr;
- }
- int ret = InternalAssignRepeatedField(
- reinterpret_cast<RepeatedScalarContainer*>(pself), list.get());
- if (ret < 0) {
- return nullptr;
- }
- Py_RETURN_NONE;
-}
-
-static PyObject* Pop(PyObject* pself, PyObject* args) {
+static PyObject* Reverse(PyObject* pself) {
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
+ }
+ ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
+ if (list == nullptr) {
+ return nullptr;
+ }
+ ScopedPyObjectPtr res(PyObject_CallMethod(list.get(), "reverse", nullptr));
+ if (res == nullptr) {
+ return nullptr;
+ }
+ int ret = InternalAssignRepeatedField(
+ reinterpret_cast<RepeatedScalarContainer*>(pself), list.get());
+ if (ret < 0) {
+ return nullptr;
+ }
+ Py_RETURN_NONE;
+}
+
+static PyObject* Pop(PyObject* pself, PyObject* args) {
Py_ssize_t index = -1;
if (!PyArg_ParseTuple(args, "|n", &index)) {
- return nullptr;
+ return nullptr;
}
- PyObject* item = Item(pself, index);
- if (item == nullptr) {
- PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
- return nullptr;
+ PyObject* item = Item(pself, index);
+ if (item == nullptr) {
+ PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
+ return nullptr;
}
- if (AssignItem(pself, index, nullptr) < 0) {
- return nullptr;
+ if (AssignItem(pself, index, nullptr) < 0) {
+ return nullptr;
}
return item;
}
-static PyObject* ToStr(PyObject* pself) {
- ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
- if (full_slice == nullptr) {
- return nullptr;
+static PyObject* ToStr(PyObject* pself) {
+ ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
+ if (full_slice == nullptr) {
+ return nullptr;
}
- ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
- if (list == nullptr) {
- return nullptr;
+ ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
+ if (list == nullptr) {
+ return nullptr;
}
return PyObject_Repr(list.get());
}
-static PyObject* MergeFrom(PyObject* pself, PyObject* arg) {
- return Extend(reinterpret_cast<RepeatedScalarContainer*>(pself), arg);
-}
-
+static PyObject* MergeFrom(PyObject* pself, PyObject* arg) {
+ return Extend(reinterpret_cast<RepeatedScalarContainer*>(pself), arg);
+}
+
// The private constructor of RepeatedScalarContainer objects.
-RepeatedScalarContainer* NewContainer(
+RepeatedScalarContainer* NewContainer(
CMessage* parent, const FieldDescriptor* parent_field_descriptor) {
if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
- return nullptr;
+ return nullptr;
}
RepeatedScalarContainer* self = reinterpret_cast<RepeatedScalarContainer*>(
PyType_GenericAlloc(&RepeatedScalarContainer_Type, 0));
- if (self == nullptr) {
- return nullptr;
+ if (self == nullptr) {
+ return nullptr;
}
- Py_INCREF(parent);
+ Py_INCREF(parent);
self->parent = parent;
self->parent_field_descriptor = parent_field_descriptor;
- return self;
+ return self;
}
-PyObject* DeepCopy(PyObject* pself, PyObject* arg) {
- return reinterpret_cast<RepeatedScalarContainer*>(pself)->DeepCopy();
+PyObject* DeepCopy(PyObject* pself, PyObject* arg) {
+ return reinterpret_cast<RepeatedScalarContainer*>(pself)->DeepCopy();
}
-static void Dealloc(PyObject* pself) {
- reinterpret_cast<RepeatedScalarContainer*>(pself)->RemoveFromParentCache();
- Py_TYPE(pself)->tp_free(pself);
+static void Dealloc(PyObject* pself) {
+ reinterpret_cast<RepeatedScalarContainer*>(pself)->RemoveFromParentCache();
+ Py_TYPE(pself)->tp_free(pself);
}
static PySequenceMethods SqMethods = {
- Len, /* sq_length */
- nullptr, /* sq_concat */
- nullptr, /* sq_repeat */
- Item, /* sq_item */
- nullptr, /* sq_slice */
- AssignItem /* sq_ass_item */
+ Len, /* sq_length */
+ nullptr, /* sq_concat */
+ nullptr, /* sq_repeat */
+ Item, /* sq_item */
+ nullptr, /* sq_slice */
+ AssignItem /* sq_ass_item */
};
static PyMappingMethods MpMethods = {
- Len, /* mp_length */
- Subscript, /* mp_subscript */
- AssSubscript, /* mp_ass_subscript */
+ Len, /* mp_length */
+ Subscript, /* mp_subscript */
+ AssSubscript, /* mp_ass_subscript */
};
static PyMethodDef Methods[] = {
- {"__deepcopy__", DeepCopy, METH_VARARGS, "Makes a deep copy of the class."},
- {"__reduce__", Reduce, METH_NOARGS,
- "Outputs picklable representation of the repeated field."},
- {"append", AppendMethod, METH_O,
- "Appends an object to the repeated container."},
- {"extend", ExtendMethod, METH_O,
- "Appends objects to the repeated container."},
- {"insert", Insert, METH_VARARGS,
- "Inserts an object at the specified position in the container."},
- {"pop", Pop, METH_VARARGS,
- "Removes an object from the repeated container and returns it."},
- {"remove", Remove, METH_O,
- "Removes an object from the repeated container."},
- {"sort", reinterpret_cast<PyCFunction>(Sort), METH_VARARGS | METH_KEYWORDS,
- "Sorts the repeated container."},
- {"reverse", reinterpret_cast<PyCFunction>(Reverse), METH_NOARGS,
- "Reverses elements order of the repeated container."},
- {"MergeFrom", static_cast<PyCFunction>(MergeFrom), METH_O,
- "Merges a repeated container into the current container."},
- {nullptr, nullptr}};
+ {"__deepcopy__", DeepCopy, METH_VARARGS, "Makes a deep copy of the class."},
+ {"__reduce__", Reduce, METH_NOARGS,
+ "Outputs picklable representation of the repeated field."},
+ {"append", AppendMethod, METH_O,
+ "Appends an object to the repeated container."},
+ {"extend", ExtendMethod, METH_O,
+ "Appends objects to the repeated container."},
+ {"insert", Insert, METH_VARARGS,
+ "Inserts an object at the specified position in the container."},
+ {"pop", Pop, METH_VARARGS,
+ "Removes an object from the repeated container and returns it."},
+ {"remove", Remove, METH_O,
+ "Removes an object from the repeated container."},
+ {"sort", reinterpret_cast<PyCFunction>(Sort), METH_VARARGS | METH_KEYWORDS,
+ "Sorts the repeated container."},
+ {"reverse", reinterpret_cast<PyCFunction>(Reverse), METH_NOARGS,
+ "Reverses elements order of the repeated container."},
+ {"MergeFrom", static_cast<PyCFunction>(MergeFrom), METH_O,
+ "Merges a repeated container into the current container."},
+ {nullptr, nullptr}};
} // namespace repeated_scalar_container
PyTypeObject RepeatedScalarContainer_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
- ".RepeatedScalarContainer", // tp_name
- sizeof(RepeatedScalarContainer), // tp_basicsize
- 0, // tp_itemsize
- repeated_scalar_container::Dealloc, // tp_dealloc
-#if PY_VERSION_HEX >= 0x03080000
- 0, // tp_vectorcall_offset
-#else
- nullptr, // tp_print
-#endif
- nullptr, // tp_getattr
- nullptr, // tp_setattr
- nullptr, // tp_compare
- repeated_scalar_container::ToStr, // tp_repr
- nullptr, // tp_as_number
- &repeated_scalar_container::SqMethods, // tp_as_sequence
- &repeated_scalar_container::MpMethods, // tp_as_mapping
- PyObject_HashNotImplemented, // tp_hash
- nullptr, // tp_call
- nullptr, // tp_str
- nullptr, // tp_getattro
- nullptr, // tp_setattro
- nullptr, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "A Repeated scalar container", // tp_doc
- nullptr, // tp_traverse
- nullptr, // tp_clear
- repeated_scalar_container::RichCompare, // tp_richcompare
- 0, // tp_weaklistoffset
- nullptr, // tp_iter
- nullptr, // tp_iternext
- repeated_scalar_container::Methods, // tp_methods
- nullptr, // tp_members
- nullptr, // tp_getset
- nullptr, // tp_base
- nullptr, // tp_dict
- nullptr, // tp_descr_get
- nullptr, // tp_descr_set
- 0, // tp_dictoffset
- nullptr, // tp_init
+ PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
+ ".RepeatedScalarContainer", // tp_name
+ sizeof(RepeatedScalarContainer), // tp_basicsize
+ 0, // tp_itemsize
+ repeated_scalar_container::Dealloc, // tp_dealloc
+#if PY_VERSION_HEX >= 0x03080000
+ 0, // tp_vectorcall_offset
+#else
+ nullptr, // tp_print
+#endif
+ nullptr, // tp_getattr
+ nullptr, // tp_setattr
+ nullptr, // tp_compare
+ repeated_scalar_container::ToStr, // tp_repr
+ nullptr, // tp_as_number
+ &repeated_scalar_container::SqMethods, // tp_as_sequence
+ &repeated_scalar_container::MpMethods, // tp_as_mapping
+ PyObject_HashNotImplemented, // tp_hash
+ nullptr, // tp_call
+ nullptr, // tp_str
+ nullptr, // tp_getattro
+ nullptr, // tp_setattro
+ nullptr, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "A Repeated scalar container", // tp_doc
+ nullptr, // tp_traverse
+ nullptr, // tp_clear
+ repeated_scalar_container::RichCompare, // tp_richcompare
+ 0, // tp_weaklistoffset
+ nullptr, // tp_iter
+ nullptr, // tp_iternext
+ repeated_scalar_container::Methods, // tp_methods
+ nullptr, // tp_members
+ nullptr, // tp_getset
+ nullptr, // tp_base
+ nullptr, // tp_dict
+ nullptr, // tp_descr_get
+ nullptr, // tp_descr_set
+ 0, // tp_dictoffset
+ nullptr, // tp_init
};
} // namespace python
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_scalar_container.h b/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_scalar_container.h
index f9f0ea8f31..2d5952b192 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_scalar_container.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/repeated_scalar_container.h
@@ -38,14 +38,14 @@
#include <memory>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/pyext/message.h>
namespace google {
namespace protobuf {
namespace python {
-typedef struct RepeatedScalarContainer : public ContainerBase {
+typedef struct RepeatedScalarContainer : public ContainerBase {
} RepeatedScalarContainer;
extern PyTypeObject RepeatedScalarContainer_Type;
@@ -54,7 +54,7 @@ namespace repeated_scalar_container {
// Builds a RepeatedScalarContainer object, from a parent message and a
// field descriptor.
-extern RepeatedScalarContainer* NewContainer(
+extern RepeatedScalarContainer* NewContainer(
CMessage* parent, const FieldDescriptor* parent_field_descriptor);
// Appends the scalar 'item' to the end of the container 'self'.
@@ -72,6 +72,6 @@ PyObject* Extend(RepeatedScalarContainer* self, PyObject* value);
} // namespace repeated_scalar_container
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_SCALAR_CONTAINER_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/safe_numerics.h b/contrib/python/protobuf/py3/google/protobuf/pyext/safe_numerics.h
index 93ae640e8b..26ed54d5d6 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/safe_numerics.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/safe_numerics.h
@@ -34,8 +34,8 @@
#include <limits>
-#include <google/protobuf/stubs/logging.h>
-#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
namespace google {
namespace protobuf {
@@ -132,10 +132,10 @@ template <class Dest, class Source>
inline bool IsValidNumericCast(Source source) {
typedef std::numeric_limits<Source> SourceLimits;
typedef std::numeric_limits<Dest> DestLimits;
- static_assert(SourceLimits::is_specialized, "argument must be numeric");
- static_assert(SourceLimits::is_integer, "argument must be integral");
- static_assert(DestLimits::is_specialized, "result must be numeric");
- static_assert(DestLimits::is_integer, "result must be integral");
+ static_assert(SourceLimits::is_specialized, "argument must be numeric");
+ static_assert(SourceLimits::is_integer, "argument must be integral");
+ static_assert(DestLimits::is_specialized, "result must be numeric");
+ static_assert(DestLimits::is_integer, "result must be integral");
return IsValidNumericCastImpl<
sizeof(Dest) == sizeof(Source),
@@ -150,7 +150,7 @@ inline bool IsValidNumericCast(Source source) {
// checked_numeric_cast<> is analogous to static_cast<> for numeric types,
// except that it CHECKs that the specified numeric conversion will not
// overflow or underflow. Floating point arguments are not currently allowed
-// (this is static_asserted), though this could be supported if necessary.
+// (this is static_asserted), though this could be supported if necessary.
template <class Dest, class Source>
inline Dest checked_numeric_cast(Source source) {
GOOGLE_CHECK(IsValidNumericCast<Dest>(source));
@@ -159,6 +159,6 @@ inline Dest checked_numeric_cast(Source source) {
} // namespace python
} // namespace protobuf
-} // namespace google
+} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_CPP_SAFE_NUMERICS_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/scoped_pyobject_ptr.h b/contrib/python/protobuf/py3/google/protobuf/pyext/scoped_pyobject_ptr.h
index 6f7fc29813..9f3c1fc51d 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/scoped_pyobject_ptr.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/scoped_pyobject_ptr.h
@@ -33,7 +33,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__
-#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/common.h>
#include <Python.h>
namespace google {
@@ -77,7 +77,7 @@ class ScopedPythonPtr {
PyObject* as_pyobject() const { return reinterpret_cast<PyObject*>(ptr_); }
- // Increments the reference count of the current object.
+ // Increments the reference count of the current object.
// Should not be called when no object is held.
void inc() const { Py_INCREF(ptr_); }
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.cc
index deb86e6916..69ba22b850 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.cc
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.cc
@@ -1,358 +1,358 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <google/protobuf/pyext/unknown_fields.h>
-
-#include <Python.h>
-#include <set>
-#include <memory>
-
-#include <google/protobuf/message.h>
-#include <google/protobuf/pyext/message.h>
-#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
-#include <google/protobuf/unknown_field_set.h>
-#include <google/protobuf/wire_format_lite.h>
-
-#if PY_MAJOR_VERSION >= 3
- #define PyInt_FromLong PyLong_FromLong
-#endif
-
-namespace google {
-namespace protobuf {
-namespace python {
-
-namespace unknown_fields {
-
-static Py_ssize_t Len(PyObject* pself) {
- PyUnknownFields* self =
- reinterpret_cast<PyUnknownFields*>(pself);
- if (self->fields == NULL) {
- PyErr_Format(PyExc_ValueError,
- "UnknownFields does not exist. "
- "The parent message might be cleared.");
- return -1;
- }
- return self->fields->field_count();
-}
-
-void Clear(PyUnknownFields* self) {
- for (std::set<PyUnknownFields*>::iterator it =
- self->sub_unknown_fields.begin();
- it != self->sub_unknown_fields.end(); it++) {
- Clear(*it);
- }
- self->fields = NULL;
- self->sub_unknown_fields.clear();
-}
-
-PyObject* NewPyUnknownFieldRef(PyUnknownFields* parent,
- Py_ssize_t index);
-
-static PyObject* Item(PyObject* pself, Py_ssize_t index) {
- PyUnknownFields* self =
- reinterpret_cast<PyUnknownFields*>(pself);
- if (self->fields == NULL) {
- PyErr_Format(PyExc_ValueError,
- "UnknownFields does not exist. "
- "The parent message might be cleared.");
- return NULL;
- }
- Py_ssize_t total_size = self->fields->field_count();
- if (index < 0) {
- index = total_size + index;
- }
- if (index < 0 || index >= total_size) {
- PyErr_Format(PyExc_IndexError,
- "index (%zd) out of range",
- index);
- return NULL;
- }
-
- return unknown_fields::NewPyUnknownFieldRef(self, index);
-}
-
-PyObject* NewPyUnknownFields(CMessage* c_message) {
- PyUnknownFields* self = reinterpret_cast<PyUnknownFields*>(
- PyType_GenericAlloc(&PyUnknownFields_Type, 0));
- if (self == NULL) {
- return NULL;
- }
- // Call "placement new" to initialize PyUnknownFields.
- new (self) PyUnknownFields;
-
- Py_INCREF(c_message);
- self->parent = reinterpret_cast<PyObject*>(c_message);
- Message* message = c_message->message;
- const Reflection* reflection = message->GetReflection();
- self->fields = &reflection->GetUnknownFields(*message);
-
- return reinterpret_cast<PyObject*>(self);
-}
-
-PyObject* NewPyUnknownFieldRef(PyUnknownFields* parent,
- Py_ssize_t index) {
- PyUnknownFieldRef* self = reinterpret_cast<PyUnknownFieldRef*>(
- PyType_GenericAlloc(&PyUnknownFieldRef_Type, 0));
- if (self == NULL) {
- return NULL;
- }
-
- Py_INCREF(parent);
- self->parent = parent;
- self->index = index;
-
- return reinterpret_cast<PyObject*>(self);
-}
-
-static void Dealloc(PyObject* pself) {
- PyUnknownFields* self =
- reinterpret_cast<PyUnknownFields*>(pself);
- if (PyObject_TypeCheck(self->parent, &PyUnknownFields_Type)) {
- reinterpret_cast<PyUnknownFields*>(
- self->parent)->sub_unknown_fields.erase(self);
- } else {
- reinterpret_cast<CMessage*>(self->parent)->unknown_field_set = nullptr;
- }
- Py_CLEAR(self->parent);
- self->~PyUnknownFields();
- Py_TYPE(pself)->tp_free(pself);
-}
-
-static PySequenceMethods SqMethods = {
- Len, /* sq_length */
- 0, /* sq_concat */
- 0, /* sq_repeat */
- Item, /* sq_item */
- 0, /* sq_slice */
- 0, /* sq_ass_item */
-};
-
-} // namespace unknown_fields
-
-PyTypeObject PyUnknownFields_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- FULL_MODULE_NAME ".PyUnknownFields", // tp_name
- sizeof(PyUnknownFields), // tp_basicsize
- 0, // tp_itemsize
- unknown_fields::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- &unknown_fields::SqMethods, // tp_as_sequence
- 0, // tp_as_mapping
- PyObject_HashNotImplemented, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "unknown field set", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- 0, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
-};
-
-namespace unknown_field {
-static PyObject* PyUnknownFields_FromUnknownFieldSet(
- PyUnknownFields* parent, const UnknownFieldSet& fields) {
- PyUnknownFields* self = reinterpret_cast<PyUnknownFields*>(
- PyType_GenericAlloc(&PyUnknownFields_Type, 0));
- if (self == NULL) {
- return NULL;
- }
- // Call "placement new" to initialize PyUnknownFields.
- new (self) PyUnknownFields;
-
- Py_INCREF(parent);
- self->parent = reinterpret_cast<PyObject*>(parent);
- self->fields = &fields;
- parent->sub_unknown_fields.emplace(self);
-
- return reinterpret_cast<PyObject*>(self);
-}
-
-const UnknownField* GetUnknownField(PyUnknownFieldRef* self) {
- const UnknownFieldSet* fields = self->parent->fields;
- if (fields == NULL) {
- PyErr_Format(PyExc_ValueError,
- "UnknownField does not exist. "
- "The parent message might be cleared.");
- return NULL;
- }
- ssize_t total_size = fields->field_count();
- if (self->index >= total_size) {
- PyErr_Format(PyExc_ValueError,
- "UnknownField does not exist. "
- "The parent message might be cleared.");
- return NULL;
- }
- return &fields->field(self->index);
-}
-
-static PyObject* GetFieldNumber(PyUnknownFieldRef* self, void *closure) {
- const UnknownField* unknown_field = GetUnknownField(self);
- if (unknown_field == NULL) {
- return NULL;
- }
- return PyInt_FromLong(unknown_field->number());
-}
-
-using internal::WireFormatLite;
-static PyObject* GetWireType(PyUnknownFieldRef* self, void *closure) {
- const UnknownField* unknown_field = GetUnknownField(self);
- if (unknown_field == NULL) {
- return NULL;
- }
-
- // Assign a default value to suppress may-uninitialized warnings (errors
- // when built in some places).
- WireFormatLite::WireType wire_type = WireFormatLite::WIRETYPE_VARINT;
- switch (unknown_field->type()) {
- case UnknownField::TYPE_VARINT:
- wire_type = WireFormatLite::WIRETYPE_VARINT;
- break;
- case UnknownField::TYPE_FIXED32:
- wire_type = WireFormatLite::WIRETYPE_FIXED32;
- break;
- case UnknownField::TYPE_FIXED64:
- wire_type = WireFormatLite::WIRETYPE_FIXED64;
- break;
- case UnknownField::TYPE_LENGTH_DELIMITED:
- wire_type = WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
- break;
- case UnknownField::TYPE_GROUP:
- wire_type = WireFormatLite::WIRETYPE_START_GROUP;
- break;
- }
- return PyInt_FromLong(wire_type);
-}
-
-static PyObject* GetData(PyUnknownFieldRef* self, void *closure) {
- const UnknownField* field = GetUnknownField(self);
- if (field == NULL) {
- return NULL;
- }
- PyObject* data = NULL;
- switch (field->type()) {
- case UnknownField::TYPE_VARINT:
- data = PyInt_FromLong(field->varint());
- break;
- case UnknownField::TYPE_FIXED32:
- data = PyInt_FromLong(field->fixed32());
- break;
- case UnknownField::TYPE_FIXED64:
- data = PyInt_FromLong(field->fixed64());
- break;
- case UnknownField::TYPE_LENGTH_DELIMITED:
- data = PyBytes_FromStringAndSize(field->length_delimited().data(),
- field->GetLengthDelimitedSize());
- break;
- case UnknownField::TYPE_GROUP:
- data = PyUnknownFields_FromUnknownFieldSet(
- self->parent, field->group());
- break;
- }
- return data;
-}
-
-static void Dealloc(PyObject* pself) {
- PyUnknownFieldRef* self =
- reinterpret_cast<PyUnknownFieldRef*>(pself);
- Py_CLEAR(self->parent);
-}
-
-static PyGetSetDef Getters[] = {
- {"field_number", (getter)GetFieldNumber, NULL},
- {"wire_type", (getter)GetWireType, NULL},
- {"data", (getter)GetData, NULL},
- {NULL}
-};
-
-} // namespace unknown_field
-
-PyTypeObject PyUnknownFieldRef_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- FULL_MODULE_NAME ".PyUnknownFieldRef", // tp_name
- sizeof(PyUnknownFieldRef), // tp_basicsize
- 0, // tp_itemsize
- unknown_field::Dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- PyObject_HashNotImplemented, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "unknown field", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- 0, // tp_methods
- 0, // tp_members
- unknown_field::Getters, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
-};
-
-
-} // namespace python
-} // namespace protobuf
-} // namespace google
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <google/protobuf/pyext/unknown_fields.h>
+
+#include <Python.h>
+#include <set>
+#include <memory>
+
+#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+#include <google/protobuf/unknown_field_set.h>
+#include <google/protobuf/wire_format_lite.h>
+
+#if PY_MAJOR_VERSION >= 3
+ #define PyInt_FromLong PyLong_FromLong
+#endif
+
+namespace google {
+namespace protobuf {
+namespace python {
+
+namespace unknown_fields {
+
+static Py_ssize_t Len(PyObject* pself) {
+ PyUnknownFields* self =
+ reinterpret_cast<PyUnknownFields*>(pself);
+ if (self->fields == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "UnknownFields does not exist. "
+ "The parent message might be cleared.");
+ return -1;
+ }
+ return self->fields->field_count();
+}
+
+void Clear(PyUnknownFields* self) {
+ for (std::set<PyUnknownFields*>::iterator it =
+ self->sub_unknown_fields.begin();
+ it != self->sub_unknown_fields.end(); it++) {
+ Clear(*it);
+ }
+ self->fields = NULL;
+ self->sub_unknown_fields.clear();
+}
+
+PyObject* NewPyUnknownFieldRef(PyUnknownFields* parent,
+ Py_ssize_t index);
+
+static PyObject* Item(PyObject* pself, Py_ssize_t index) {
+ PyUnknownFields* self =
+ reinterpret_cast<PyUnknownFields*>(pself);
+ if (self->fields == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "UnknownFields does not exist. "
+ "The parent message might be cleared.");
+ return NULL;
+ }
+ Py_ssize_t total_size = self->fields->field_count();
+ if (index < 0) {
+ index = total_size + index;
+ }
+ if (index < 0 || index >= total_size) {
+ PyErr_Format(PyExc_IndexError,
+ "index (%zd) out of range",
+ index);
+ return NULL;
+ }
+
+ return unknown_fields::NewPyUnknownFieldRef(self, index);
+}
+
+PyObject* NewPyUnknownFields(CMessage* c_message) {
+ PyUnknownFields* self = reinterpret_cast<PyUnknownFields*>(
+ PyType_GenericAlloc(&PyUnknownFields_Type, 0));
+ if (self == NULL) {
+ return NULL;
+ }
+ // Call "placement new" to initialize PyUnknownFields.
+ new (self) PyUnknownFields;
+
+ Py_INCREF(c_message);
+ self->parent = reinterpret_cast<PyObject*>(c_message);
+ Message* message = c_message->message;
+ const Reflection* reflection = message->GetReflection();
+ self->fields = &reflection->GetUnknownFields(*message);
+
+ return reinterpret_cast<PyObject*>(self);
+}
+
+PyObject* NewPyUnknownFieldRef(PyUnknownFields* parent,
+ Py_ssize_t index) {
+ PyUnknownFieldRef* self = reinterpret_cast<PyUnknownFieldRef*>(
+ PyType_GenericAlloc(&PyUnknownFieldRef_Type, 0));
+ if (self == NULL) {
+ return NULL;
+ }
+
+ Py_INCREF(parent);
+ self->parent = parent;
+ self->index = index;
+
+ return reinterpret_cast<PyObject*>(self);
+}
+
+static void Dealloc(PyObject* pself) {
+ PyUnknownFields* self =
+ reinterpret_cast<PyUnknownFields*>(pself);
+ if (PyObject_TypeCheck(self->parent, &PyUnknownFields_Type)) {
+ reinterpret_cast<PyUnknownFields*>(
+ self->parent)->sub_unknown_fields.erase(self);
+ } else {
+ reinterpret_cast<CMessage*>(self->parent)->unknown_field_set = nullptr;
+ }
+ Py_CLEAR(self->parent);
+ self->~PyUnknownFields();
+ Py_TYPE(pself)->tp_free(pself);
+}
+
+static PySequenceMethods SqMethods = {
+ Len, /* sq_length */
+ 0, /* sq_concat */
+ 0, /* sq_repeat */
+ Item, /* sq_item */
+ 0, /* sq_slice */
+ 0, /* sq_ass_item */
+};
+
+} // namespace unknown_fields
+
+PyTypeObject PyUnknownFields_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ FULL_MODULE_NAME ".PyUnknownFields", // tp_name
+ sizeof(PyUnknownFields), // tp_basicsize
+ 0, // tp_itemsize
+ unknown_fields::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ &unknown_fields::SqMethods, // tp_as_sequence
+ 0, // tp_as_mapping
+ PyObject_HashNotImplemented, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "unknown field set", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ 0, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+};
+
+namespace unknown_field {
+static PyObject* PyUnknownFields_FromUnknownFieldSet(
+ PyUnknownFields* parent, const UnknownFieldSet& fields) {
+ PyUnknownFields* self = reinterpret_cast<PyUnknownFields*>(
+ PyType_GenericAlloc(&PyUnknownFields_Type, 0));
+ if (self == NULL) {
+ return NULL;
+ }
+ // Call "placement new" to initialize PyUnknownFields.
+ new (self) PyUnknownFields;
+
+ Py_INCREF(parent);
+ self->parent = reinterpret_cast<PyObject*>(parent);
+ self->fields = &fields;
+ parent->sub_unknown_fields.emplace(self);
+
+ return reinterpret_cast<PyObject*>(self);
+}
+
+const UnknownField* GetUnknownField(PyUnknownFieldRef* self) {
+ const UnknownFieldSet* fields = self->parent->fields;
+ if (fields == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "UnknownField does not exist. "
+ "The parent message might be cleared.");
+ return NULL;
+ }
+ ssize_t total_size = fields->field_count();
+ if (self->index >= total_size) {
+ PyErr_Format(PyExc_ValueError,
+ "UnknownField does not exist. "
+ "The parent message might be cleared.");
+ return NULL;
+ }
+ return &fields->field(self->index);
+}
+
+static PyObject* GetFieldNumber(PyUnknownFieldRef* self, void *closure) {
+ const UnknownField* unknown_field = GetUnknownField(self);
+ if (unknown_field == NULL) {
+ return NULL;
+ }
+ return PyInt_FromLong(unknown_field->number());
+}
+
+using internal::WireFormatLite;
+static PyObject* GetWireType(PyUnknownFieldRef* self, void *closure) {
+ const UnknownField* unknown_field = GetUnknownField(self);
+ if (unknown_field == NULL) {
+ return NULL;
+ }
+
+ // Assign a default value to suppress may-uninitialized warnings (errors
+ // when built in some places).
+ WireFormatLite::WireType wire_type = WireFormatLite::WIRETYPE_VARINT;
+ switch (unknown_field->type()) {
+ case UnknownField::TYPE_VARINT:
+ wire_type = WireFormatLite::WIRETYPE_VARINT;
+ break;
+ case UnknownField::TYPE_FIXED32:
+ wire_type = WireFormatLite::WIRETYPE_FIXED32;
+ break;
+ case UnknownField::TYPE_FIXED64:
+ wire_type = WireFormatLite::WIRETYPE_FIXED64;
+ break;
+ case UnknownField::TYPE_LENGTH_DELIMITED:
+ wire_type = WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
+ break;
+ case UnknownField::TYPE_GROUP:
+ wire_type = WireFormatLite::WIRETYPE_START_GROUP;
+ break;
+ }
+ return PyInt_FromLong(wire_type);
+}
+
+static PyObject* GetData(PyUnknownFieldRef* self, void *closure) {
+ const UnknownField* field = GetUnknownField(self);
+ if (field == NULL) {
+ return NULL;
+ }
+ PyObject* data = NULL;
+ switch (field->type()) {
+ case UnknownField::TYPE_VARINT:
+ data = PyInt_FromLong(field->varint());
+ break;
+ case UnknownField::TYPE_FIXED32:
+ data = PyInt_FromLong(field->fixed32());
+ break;
+ case UnknownField::TYPE_FIXED64:
+ data = PyInt_FromLong(field->fixed64());
+ break;
+ case UnknownField::TYPE_LENGTH_DELIMITED:
+ data = PyBytes_FromStringAndSize(field->length_delimited().data(),
+ field->GetLengthDelimitedSize());
+ break;
+ case UnknownField::TYPE_GROUP:
+ data = PyUnknownFields_FromUnknownFieldSet(
+ self->parent, field->group());
+ break;
+ }
+ return data;
+}
+
+static void Dealloc(PyObject* pself) {
+ PyUnknownFieldRef* self =
+ reinterpret_cast<PyUnknownFieldRef*>(pself);
+ Py_CLEAR(self->parent);
+}
+
+static PyGetSetDef Getters[] = {
+ {"field_number", (getter)GetFieldNumber, NULL},
+ {"wire_type", (getter)GetWireType, NULL},
+ {"data", (getter)GetData, NULL},
+ {NULL}
+};
+
+} // namespace unknown_field
+
+PyTypeObject PyUnknownFieldRef_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ FULL_MODULE_NAME ".PyUnknownFieldRef", // tp_name
+ sizeof(PyUnknownFieldRef), // tp_basicsize
+ 0, // tp_itemsize
+ unknown_field::Dealloc, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ PyObject_HashNotImplemented, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ "unknown field", // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ 0, // tp_methods
+ 0, // tp_members
+ unknown_field::Getters, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+};
+
+
+} // namespace python
+} // namespace protobuf
+} // namespace google
diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.h b/contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.h
index 94d55e148d..9e661866f3 100644
--- a/contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.h
+++ b/contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.h
@@ -1,90 +1,90 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
-#define GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
-
-#include <Python.h>
-
-#include <memory>
-#include <set>
-
-#include <google/protobuf/pyext/message.h>
-
-namespace google {
-namespace protobuf {
-
-class UnknownField;
-class UnknownFieldSet;
-
-namespace python {
-struct CMessage;
-
-typedef struct PyUnknownFields {
- PyObject_HEAD;
- // Strong pointer to the parent CMessage or PyUnknownFields.
- // The top PyUnknownFields holds a reference to its parent CMessage
- // object before release.
- // Sub PyUnknownFields holds reference to parent PyUnknownFields.
- PyObject* parent;
-
- // Pointer to the C++ UnknownFieldSet.
- // PyUnknownFields does not own this pointer.
- const UnknownFieldSet* fields;
-
- // Weak references to child unknown fields.
- std::set<PyUnknownFields*> sub_unknown_fields;
-} PyUnknownFields;
-
-typedef struct PyUnknownFieldRef {
- PyObject_HEAD;
- // Every Python PyUnknownFieldRef holds a reference to its parent
- // PyUnknownFields in order to keep it alive.
- PyUnknownFields* parent;
-
- // The UnknownField index in UnknownFields.
- Py_ssize_t index;
-} UknownFieldRef;
-
-extern PyTypeObject PyUnknownFields_Type;
-extern PyTypeObject PyUnknownFieldRef_Type;
-
-namespace unknown_fields {
-
-// Builds an PyUnknownFields for a specific message.
-PyObject* NewPyUnknownFields(CMessage *parent);
-void Clear(PyUnknownFields* self);
-
-} // namespace unknown_fields
-} // namespace python
-} // namespace protobuf
-} // namespace google
-
-#endif // GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
+#define GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
+
+#include <Python.h>
+
+#include <memory>
+#include <set>
+
+#include <google/protobuf/pyext/message.h>
+
+namespace google {
+namespace protobuf {
+
+class UnknownField;
+class UnknownFieldSet;
+
+namespace python {
+struct CMessage;
+
+typedef struct PyUnknownFields {
+ PyObject_HEAD;
+ // Strong pointer to the parent CMessage or PyUnknownFields.
+ // The top PyUnknownFields holds a reference to its parent CMessage
+ // object before release.
+ // Sub PyUnknownFields holds reference to parent PyUnknownFields.
+ PyObject* parent;
+
+ // Pointer to the C++ UnknownFieldSet.
+ // PyUnknownFields does not own this pointer.
+ const UnknownFieldSet* fields;
+
+ // Weak references to child unknown fields.
+ std::set<PyUnknownFields*> sub_unknown_fields;
+} PyUnknownFields;
+
+typedef struct PyUnknownFieldRef {
+ PyObject_HEAD;
+ // Every Python PyUnknownFieldRef holds a reference to its parent
+ // PyUnknownFields in order to keep it alive.
+ PyUnknownFields* parent;
+
+ // The UnknownField index in UnknownFields.
+ Py_ssize_t index;
+} UknownFieldRef;
+
+extern PyTypeObject PyUnknownFields_Type;
+extern PyTypeObject PyUnknownFieldRef_Type;
+
+namespace unknown_fields {
+
+// Builds an PyUnknownFields for a specific message.
+PyObject* NewPyUnknownFields(CMessage *parent);
+void Clear(PyUnknownFields* self);
+
+} // namespace unknown_fields
+} // namespace python
+} // namespace protobuf
+} // namespace google
+
+#endif // GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
diff --git a/contrib/python/protobuf/py3/google/protobuf/reflection.py b/contrib/python/protobuf/py3/google/protobuf/reflection.py
index 81e18859a8..711b78716c 100644
--- a/contrib/python/protobuf/py3/google/protobuf/reflection.py
+++ b/contrib/python/protobuf/py3/google/protobuf/reflection.py
@@ -48,23 +48,23 @@ this file*.
__author__ = 'robinson@google.com (Will Robinson)'
-from google.protobuf import message_factory
-from google.protobuf import symbol_database
+from google.protobuf import message_factory
+from google.protobuf import symbol_database
# The type of all Message classes.
# Part of the public interface, but normally only used by message factories.
-GeneratedProtocolMessageType = message_factory._GENERATED_PROTOCOL_MESSAGE_TYPE
+GeneratedProtocolMessageType = message_factory._GENERATED_PROTOCOL_MESSAGE_TYPE
MESSAGE_CLASS_CACHE = {}
-# Deprecated. Please NEVER use reflection.ParseMessage().
+# Deprecated. Please NEVER use reflection.ParseMessage().
def ParseMessage(descriptor, byte_str):
"""Generate a new Message instance from this Descriptor and a byte string.
- DEPRECATED: ParseMessage is deprecated because it is using MakeClass().
- Please use MessageFactory.GetPrototype() instead.
-
+ DEPRECATED: ParseMessage is deprecated because it is using MakeClass().
+ Please use MessageFactory.GetPrototype() instead.
+
Args:
descriptor: Protobuf Descriptor object
byte_str: Serialized protocol buffer byte string
@@ -78,18 +78,18 @@ def ParseMessage(descriptor, byte_str):
return new_msg
-# Deprecated. Please NEVER use reflection.MakeClass().
+# Deprecated. Please NEVER use reflection.MakeClass().
def MakeClass(descriptor):
"""Construct a class object for a protobuf described by descriptor.
- DEPRECATED: use MessageFactory.GetPrototype() instead.
+ DEPRECATED: use MessageFactory.GetPrototype() instead.
Args:
descriptor: A descriptor.Descriptor object describing the protobuf.
Returns:
The Message class object described by the descriptor.
"""
- # Original implementation leads to duplicate message classes, which won't play
- # well with extensions. Message factory info is also missing.
- # Redirect to message_factory.
- return symbol_database.Default().GetPrototype(descriptor)
+ # Original implementation leads to duplicate message classes, which won't play
+ # well with extensions. Message factory info is also missing.
+ # Redirect to message_factory.
+ return symbol_database.Default().GetPrototype(descriptor)
diff --git a/contrib/python/protobuf/py3/google/protobuf/service.py b/contrib/python/protobuf/py3/google/protobuf/service.py
index 5625246324..c67fc6294e 100644
--- a/contrib/python/protobuf/py3/google/protobuf/service.py
+++ b/contrib/python/protobuf/py3/google/protobuf/service.py
@@ -73,7 +73,7 @@ class Service(object):
In the blocking case, RpcException will be raised on error.
Preconditions:
-
+
* method_descriptor.service == GetDescriptor
* request is of the exact same classes as returned by
GetRequestClass(method).
@@ -83,7 +83,7 @@ class Service(object):
RpcChannel which the stub is using.
Postconditions:
-
+
* "done" will be called when the method is complete. This may be
before CallMethod() returns or it may be at some point in the future.
* If the RPC failed, the response value passed to "done" will be None.
diff --git a/contrib/python/protobuf/py3/google/protobuf/service_reflection.py b/contrib/python/protobuf/py3/google/protobuf/service_reflection.py
index 75c51ff322..d4ea3a413a 100644
--- a/contrib/python/protobuf/py3/google/protobuf/service_reflection.py
+++ b/contrib/python/protobuf/py3/google/protobuf/service_reflection.py
@@ -49,14 +49,14 @@ class GeneratedServiceType(type):
The protocol compiler currently uses this metaclass to create protocol service
classes at runtime. Clients can also manually create their own classes at
- runtime, as in this example::
-
- mydescriptor = ServiceDescriptor(.....)
- class MyProtoService(service.Service):
- __metaclass__ = GeneratedServiceType
- DESCRIPTOR = mydescriptor
- myservice_instance = MyProtoService()
- # ...
+ runtime, as in this example::
+
+ mydescriptor = ServiceDescriptor(.....)
+ class MyProtoService(service.Service):
+ __metaclass__ = GeneratedServiceType
+ DESCRIPTOR = mydescriptor
+ myservice_instance = MyProtoService()
+ # ...
"""
_DESCRIPTOR_KEY = 'DESCRIPTOR'
@@ -76,11 +76,11 @@ class GeneratedServiceType(type):
# when a service class is subclassed.
if GeneratedServiceType._DESCRIPTOR_KEY not in dictionary:
return
-
+
descriptor = dictionary[GeneratedServiceType._DESCRIPTOR_KEY]
service_builder = _ServiceBuilder(descriptor)
service_builder.BuildService(cls)
- cls.DESCRIPTOR = descriptor
+ cls.DESCRIPTOR = descriptor
class GeneratedServiceStubType(GeneratedServiceType):
@@ -108,7 +108,7 @@ class GeneratedServiceStubType(GeneratedServiceType):
# when a service stub is subclassed.
if GeneratedServiceStubType._DESCRIPTOR_KEY not in dictionary:
return
-
+
descriptor = dictionary[GeneratedServiceStubType._DESCRIPTOR_KEY]
service_stub_builder = _ServiceStubBuilder(descriptor)
service_stub_builder.BuildServiceStub(cls)
diff --git a/contrib/python/protobuf/py3/google/protobuf/symbol_database.py b/contrib/python/protobuf/py3/google/protobuf/symbol_database.py
index fdcf8cf06c..e9bc68bf64 100644
--- a/contrib/python/protobuf/py3/google/protobuf/symbol_database.py
+++ b/contrib/python/protobuf/py3/google/protobuf/symbol_database.py
@@ -34,7 +34,7 @@ SymbolDatabase is the MessageFactory for messages generated at compile time,
and makes it easy to create new instances of a registered type, given only the
type's protocol buffer symbol name.
-Example usage::
+Example usage::
db = symbol_database.SymbolDatabase()
@@ -58,7 +58,7 @@ Example usage::
"""
-from google.protobuf.internal import api_implementation
+from google.protobuf.internal import api_implementation
from google.protobuf import descriptor_pool
from google.protobuf import message_factory
@@ -72,8 +72,8 @@ class SymbolDatabase(message_factory.MessageFactory):
Calls to GetSymbol() and GetMessages() will return messages registered here.
Args:
- message: A :class:`google.protobuf.message.Message` subclass (or
- instance); its descriptor will be registered.
+ message: A :class:`google.protobuf.message.Message` subclass (or
+ instance); its descriptor will be registered.
Returns:
The provided message.
@@ -88,46 +88,46 @@ class SymbolDatabase(message_factory.MessageFactory):
"""Registers the given message descriptor in the local database.
Args:
- message_descriptor (Descriptor): the message descriptor to add.
+ message_descriptor (Descriptor): the message descriptor to add.
"""
- if api_implementation.Type() == 'python':
- # pylint: disable=protected-access
- self.pool._AddDescriptor(message_descriptor)
+ if api_implementation.Type() == 'python':
+ # pylint: disable=protected-access
+ self.pool._AddDescriptor(message_descriptor)
def RegisterEnumDescriptor(self, enum_descriptor):
"""Registers the given enum descriptor in the local database.
Args:
- enum_descriptor (EnumDescriptor): The enum descriptor to register.
+ enum_descriptor (EnumDescriptor): The enum descriptor to register.
Returns:
- EnumDescriptor: The provided descriptor.
+ EnumDescriptor: The provided descriptor.
"""
- if api_implementation.Type() == 'python':
- # pylint: disable=protected-access
- self.pool._AddEnumDescriptor(enum_descriptor)
+ if api_implementation.Type() == 'python':
+ # pylint: disable=protected-access
+ self.pool._AddEnumDescriptor(enum_descriptor)
return enum_descriptor
def RegisterServiceDescriptor(self, service_descriptor):
"""Registers the given service descriptor in the local database.
Args:
- service_descriptor (ServiceDescriptor): the service descriptor to
- register.
+ service_descriptor (ServiceDescriptor): the service descriptor to
+ register.
"""
- if api_implementation.Type() == 'python':
- # pylint: disable=protected-access
- self.pool._AddServiceDescriptor(service_descriptor)
+ if api_implementation.Type() == 'python':
+ # pylint: disable=protected-access
+ self.pool._AddServiceDescriptor(service_descriptor)
def RegisterFileDescriptor(self, file_descriptor):
"""Registers the given file descriptor in the local database.
Args:
- file_descriptor (FileDescriptor): The file descriptor to register.
+ file_descriptor (FileDescriptor): The file descriptor to register.
"""
- if api_implementation.Type() == 'python':
- # pylint: disable=protected-access
- self.pool._InternalAddFileDescriptor(file_descriptor)
+ if api_implementation.Type() == 'python':
+ # pylint: disable=protected-access
+ self.pool._InternalAddFileDescriptor(file_descriptor)
def GetSymbol(self, symbol):
"""Tries to find a symbol in the local database.
@@ -136,7 +136,7 @@ class SymbolDatabase(message_factory.MessageFactory):
may be extended in future to support other symbol types.
Args:
- symbol (str): a protocol buffer symbol.
+ symbol (str): a protocol buffer symbol.
Returns:
A Python class corresponding to the symbol.
@@ -157,7 +157,7 @@ class SymbolDatabase(message_factory.MessageFactory):
messages, but does not register any message extensions.
Args:
- files (list[str]): The file names to extract messages from.
+ files (list[str]): The file names to extract messages from.
Returns:
A dictionary mapping proto names to the message classes.
diff --git a/contrib/python/protobuf/py3/google/protobuf/text_format.py b/contrib/python/protobuf/py3/google/protobuf/text_format.py
index 9c4ca90ee6..e8c0477b4b 100644
--- a/contrib/python/protobuf/py3/google/protobuf/text_format.py
+++ b/contrib/python/protobuf/py3/google/protobuf/text_format.py
@@ -30,7 +30,7 @@
"""Contains routines for printing protocol messages in text format.
-Simple usage example::
+Simple usage example::
# Create a proto object and serialize it to a text proto string.
message = my_proto_pb2.MyMessage(foo='bar')
@@ -42,32 +42,32 @@ Simple usage example::
__author__ = 'kenton@google.com (Kenton Varda)'
-# TODO(b/129989314) Import thread contention leads to test failures.
-import encodings.raw_unicode_escape # pylint: disable=unused-import
-import encodings.unicode_escape # pylint: disable=unused-import
+# TODO(b/129989314) Import thread contention leads to test failures.
+import encodings.raw_unicode_escape # pylint: disable=unused-import
+import encodings.unicode_escape # pylint: disable=unused-import
import io
-import math
+import math
import re
import six
-from google.protobuf.internal import decoder
-from google.protobuf.internal import type_checkers
-from google.protobuf import descriptor
-from google.protobuf import text_encoding
-
+from google.protobuf.internal import decoder
+from google.protobuf.internal import type_checkers
+from google.protobuf import descriptor
+from google.protobuf import text_encoding
+
if six.PY3:
long = int # pylint: disable=redefined-builtin,invalid-name
# pylint: disable=g-import-not-at-top
-__all__ = ['MessageToString', 'Parse', 'PrintMessage', 'PrintField',
- 'PrintFieldValue', 'Merge', 'MessageToBytes']
+__all__ = ['MessageToString', 'Parse', 'PrintMessage', 'PrintField',
+ 'PrintFieldValue', 'Merge', 'MessageToBytes']
_INTEGER_CHECKERS = (type_checkers.Uint32ValueChecker(),
type_checkers.Int32ValueChecker(),
type_checkers.Uint64ValueChecker(),
type_checkers.Int64ValueChecker())
-_FLOAT_INFINITY = re.compile('-?inf(?:inity)?f?$', re.IGNORECASE)
-_FLOAT_NAN = re.compile('nanf?$', re.IGNORECASE)
+_FLOAT_INFINITY = re.compile('-?inf(?:inity)?f?$', re.IGNORECASE)
+_FLOAT_NAN = re.compile('nanf?$', re.IGNORECASE)
_QUOTES = frozenset(("'", '"'))
_ANY_FULL_TYPE_NAME = 'google.protobuf.Any'
@@ -120,80 +120,80 @@ class TextWriter(object):
return self._writer.getvalue()
-def MessageToString(
- message,
- as_utf8=False,
- as_one_line=False,
- use_short_repeated_primitives=False,
- pointy_brackets=False,
- use_index_order=False,
- float_format=None,
- double_format=None,
- use_field_number=False,
- descriptor_pool=None,
- indent=0,
- message_formatter=None,
- print_unknown_fields=False,
- force_colon=False):
- # type: (...) -> str
+def MessageToString(
+ message,
+ as_utf8=False,
+ as_one_line=False,
+ use_short_repeated_primitives=False,
+ pointy_brackets=False,
+ use_index_order=False,
+ float_format=None,
+ double_format=None,
+ use_field_number=False,
+ descriptor_pool=None,
+ indent=0,
+ message_formatter=None,
+ print_unknown_fields=False,
+ force_colon=False):
+ # type: (...) -> str
"""Convert protobuf message to text format.
- Double values can be formatted compactly with 15 digits of
+ Double values can be formatted compactly with 15 digits of
precision (which is the most that IEEE 754 "double" can guarantee)
- using double_format='.15g'. To ensure that converting to text and back to a
- proto will result in an identical value, double_format='.17g' should be used.
+ using double_format='.15g'. To ensure that converting to text and back to a
+ proto will result in an identical value, double_format='.17g' should be used.
Args:
message: The protocol buffers message.
- as_utf8: Return unescaped Unicode for non-ASCII characters.
- In Python 3 actual Unicode characters may appear as is in strings.
- In Python 2 the return value will be valid UTF-8 rather than only ASCII.
+ as_utf8: Return unescaped Unicode for non-ASCII characters.
+ In Python 3 actual Unicode characters may appear as is in strings.
+ In Python 2 the return value will be valid UTF-8 rather than only ASCII.
as_one_line: Don't introduce newlines between fields.
- use_short_repeated_primitives: Use short repeated format for primitives.
+ use_short_repeated_primitives: Use short repeated format for primitives.
pointy_brackets: If True, use angle brackets instead of curly braces for
nesting.
- use_index_order: If True, fields of a proto message will be printed using
- the order defined in source code instead of the field number, extensions
- will be printed at the end of the message and their relative order is
- determined by the extension number. By default, use the field number
- order.
- float_format (str): If set, use this to specify float field formatting
- (per the "Format Specification Mini-Language"); otherwise, shortest float
- that has same value in wire will be printed. Also affect double field
- if double_format is not set but float_format is set.
- double_format (str): If set, use this to specify double field formatting
- (per the "Format Specification Mini-Language"); if it is not set but
- float_format is set, use float_format. Otherwise, use ``str()``
+ use_index_order: If True, fields of a proto message will be printed using
+ the order defined in source code instead of the field number, extensions
+ will be printed at the end of the message and their relative order is
+ determined by the extension number. By default, use the field number
+ order.
+ float_format (str): If set, use this to specify float field formatting
+ (per the "Format Specification Mini-Language"); otherwise, shortest float
+ that has same value in wire will be printed. Also affect double field
+ if double_format is not set but float_format is set.
+ double_format (str): If set, use this to specify double field formatting
+ (per the "Format Specification Mini-Language"); if it is not set but
+ float_format is set, use float_format. Otherwise, use ``str()``
use_field_number: If True, print field numbers instead of names.
- descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
- indent (int): The initial indent level, in terms of spaces, for pretty
- print.
- message_formatter (function(message, indent, as_one_line) -> unicode|None):
- Custom formatter for selected sub-messages (usually based on message
- type). Use to pretty print parts of the protobuf for easier diffing.
- print_unknown_fields: If True, unknown fields will be printed.
- force_colon: If set, a colon will be added after the field name even if the
- field is a proto message.
+ descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
+ indent (int): The initial indent level, in terms of spaces, for pretty
+ print.
+ message_formatter (function(message, indent, as_one_line) -> unicode|None):
+ Custom formatter for selected sub-messages (usually based on message
+ type). Use to pretty print parts of the protobuf for easier diffing.
+ print_unknown_fields: If True, unknown fields will be printed.
+ force_colon: If set, a colon will be added after the field name even if the
+ field is a proto message.
Returns:
- str: A string of the text formatted protocol buffer message.
+ str: A string of the text formatted protocol buffer message.
"""
out = TextWriter(as_utf8)
- printer = _Printer(
- out,
- indent,
- as_utf8,
- as_one_line,
- use_short_repeated_primitives,
- pointy_brackets,
- use_index_order,
- float_format,
- double_format,
- use_field_number,
- descriptor_pool,
- message_formatter,
- print_unknown_fields=print_unknown_fields,
- force_colon=force_colon)
+ printer = _Printer(
+ out,
+ indent,
+ as_utf8,
+ as_one_line,
+ use_short_repeated_primitives,
+ pointy_brackets,
+ use_index_order,
+ float_format,
+ double_format,
+ use_field_number,
+ descriptor_pool,
+ message_formatter,
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintMessage(message)
result = out.getvalue()
out.close()
@@ -202,16 +202,16 @@ def MessageToString(
return result
-def MessageToBytes(message, **kwargs):
- # type: (...) -> bytes
- """Convert protobuf message to encoded text format. See MessageToString."""
- text = MessageToString(message, **kwargs)
- if isinstance(text, bytes):
- return text
- codec = 'utf-8' if kwargs.get('as_utf8') else 'ascii'
- return text.encode(codec)
-
-
+def MessageToBytes(message, **kwargs):
+ # type: (...) -> bytes
+ """Convert protobuf message to encoded text format. See MessageToString."""
+ text = MessageToString(message, **kwargs)
+ if isinstance(text, bytes):
+ return text
+ codec = 'utf-8' if kwargs.get('as_utf8') else 'ascii'
+ return text.encode(codec)
+
+
def _IsMapEntry(field):
return (field.type == descriptor.FieldDescriptor.TYPE_MESSAGE and
field.message_type.has_options and
@@ -223,29 +223,29 @@ def PrintMessage(message,
indent=0,
as_utf8=False,
as_one_line=False,
- use_short_repeated_primitives=False,
+ use_short_repeated_primitives=False,
pointy_brackets=False,
use_index_order=False,
float_format=None,
- double_format=None,
+ double_format=None,
use_field_number=False,
descriptor_pool=None,
- message_formatter=None,
- print_unknown_fields=False,
- force_colon=False):
- printer = _Printer(
- out=out, indent=indent, as_utf8=as_utf8,
- as_one_line=as_one_line,
- use_short_repeated_primitives=use_short_repeated_primitives,
- pointy_brackets=pointy_brackets,
- use_index_order=use_index_order,
- float_format=float_format,
- double_format=double_format,
- use_field_number=use_field_number,
- descriptor_pool=descriptor_pool,
- message_formatter=message_formatter,
- print_unknown_fields=print_unknown_fields,
- force_colon=force_colon)
+ message_formatter=None,
+ print_unknown_fields=False,
+ force_colon=False):
+ printer = _Printer(
+ out=out, indent=indent, as_utf8=as_utf8,
+ as_one_line=as_one_line,
+ use_short_repeated_primitives=use_short_repeated_primitives,
+ pointy_brackets=pointy_brackets,
+ use_index_order=use_index_order,
+ float_format=float_format,
+ double_format=double_format,
+ use_field_number=use_field_number,
+ descriptor_pool=descriptor_pool,
+ message_formatter=message_formatter,
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintMessage(message)
@@ -255,21 +255,21 @@ def PrintField(field,
indent=0,
as_utf8=False,
as_one_line=False,
- use_short_repeated_primitives=False,
+ use_short_repeated_primitives=False,
pointy_brackets=False,
use_index_order=False,
float_format=None,
- double_format=None,
- message_formatter=None,
- print_unknown_fields=False,
- force_colon=False):
+ double_format=None,
+ message_formatter=None,
+ print_unknown_fields=False,
+ force_colon=False):
"""Print a single field name/value pair."""
- printer = _Printer(out, indent, as_utf8, as_one_line,
- use_short_repeated_primitives, pointy_brackets,
- use_index_order, float_format, double_format,
- message_formatter=message_formatter,
- print_unknown_fields=print_unknown_fields,
- force_colon=force_colon)
+ printer = _Printer(out, indent, as_utf8, as_one_line,
+ use_short_repeated_primitives, pointy_brackets,
+ use_index_order, float_format, double_format,
+ message_formatter=message_formatter,
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintField(field, value)
@@ -279,21 +279,21 @@ def PrintFieldValue(field,
indent=0,
as_utf8=False,
as_one_line=False,
- use_short_repeated_primitives=False,
+ use_short_repeated_primitives=False,
pointy_brackets=False,
use_index_order=False,
float_format=None,
- double_format=None,
- message_formatter=None,
- print_unknown_fields=False,
- force_colon=False):
+ double_format=None,
+ message_formatter=None,
+ print_unknown_fields=False,
+ force_colon=False):
"""Print a single field value (not including name)."""
- printer = _Printer(out, indent, as_utf8, as_one_line,
- use_short_repeated_primitives, pointy_brackets,
- use_index_order, float_format, double_format,
- message_formatter=message_formatter,
- print_unknown_fields=print_unknown_fields,
- force_colon=force_colon)
+ printer = _Printer(out, indent, as_utf8, as_one_line,
+ use_short_repeated_primitives, pointy_brackets,
+ use_index_order, float_format, double_format,
+ message_formatter=message_formatter,
+ print_unknown_fields=print_unknown_fields,
+ force_colon=force_colon)
printer.PrintFieldValue(field, value)
@@ -322,94 +322,94 @@ def _BuildMessageFromTypeName(type_name, descriptor_pool):
return message_type()
-# These values must match WireType enum in google/protobuf/wire_format.h.
-WIRETYPE_LENGTH_DELIMITED = 2
-WIRETYPE_START_GROUP = 3
-
-
+# These values must match WireType enum in google/protobuf/wire_format.h.
+WIRETYPE_LENGTH_DELIMITED = 2
+WIRETYPE_START_GROUP = 3
+
+
class _Printer(object):
"""Text format printer for protocol message."""
- def __init__(
- self,
- out,
- indent=0,
- as_utf8=False,
- as_one_line=False,
- use_short_repeated_primitives=False,
- pointy_brackets=False,
- use_index_order=False,
- float_format=None,
- double_format=None,
- use_field_number=False,
- descriptor_pool=None,
- message_formatter=None,
- print_unknown_fields=False,
- force_colon=False):
+ def __init__(
+ self,
+ out,
+ indent=0,
+ as_utf8=False,
+ as_one_line=False,
+ use_short_repeated_primitives=False,
+ pointy_brackets=False,
+ use_index_order=False,
+ float_format=None,
+ double_format=None,
+ use_field_number=False,
+ descriptor_pool=None,
+ message_formatter=None,
+ print_unknown_fields=False,
+ force_colon=False):
"""Initialize the Printer.
- Double values can be formatted compactly with 15 digits of precision
- (which is the most that IEEE 754 "double" can guarantee) using
- double_format='.15g'. To ensure that converting to text and back to a proto
- will result in an identical value, double_format='.17g' should be used.
+ Double values can be formatted compactly with 15 digits of precision
+ (which is the most that IEEE 754 "double" can guarantee) using
+ double_format='.15g'. To ensure that converting to text and back to a proto
+ will result in an identical value, double_format='.17g' should be used.
Args:
out: To record the text format result.
- indent: The initial indent level for pretty print.
- as_utf8: Return unescaped Unicode for non-ASCII characters.
- In Python 3 actual Unicode characters may appear as is in strings.
- In Python 2 the return value will be valid UTF-8 rather than ASCII.
+ indent: The initial indent level for pretty print.
+ as_utf8: Return unescaped Unicode for non-ASCII characters.
+ In Python 3 actual Unicode characters may appear as is in strings.
+ In Python 2 the return value will be valid UTF-8 rather than ASCII.
as_one_line: Don't introduce newlines between fields.
- use_short_repeated_primitives: Use short repeated format for primitives.
+ use_short_repeated_primitives: Use short repeated format for primitives.
pointy_brackets: If True, use angle brackets instead of curly braces for
nesting.
use_index_order: If True, print fields of a proto message using the order
defined in source code instead of the field number. By default, use the
field number order.
- float_format: If set, use this to specify float field formatting
- (per the "Format Specification Mini-Language"); otherwise, shortest
- float that has same value in wire will be printed. Also affect double
- field if double_format is not set but float_format is set.
- double_format: If set, use this to specify double field formatting
- (per the "Format Specification Mini-Language"); if it is not set but
- float_format is set, use float_format. Otherwise, str() is used.
+ float_format: If set, use this to specify float field formatting
+ (per the "Format Specification Mini-Language"); otherwise, shortest
+ float that has same value in wire will be printed. Also affect double
+ field if double_format is not set but float_format is set.
+ double_format: If set, use this to specify double field formatting
+ (per the "Format Specification Mini-Language"); if it is not set but
+ float_format is set, use float_format. Otherwise, str() is used.
use_field_number: If True, print field numbers instead of names.
descriptor_pool: A DescriptorPool used to resolve Any types.
message_formatter: A function(message, indent, as_one_line): unicode|None
to custom format selected sub-messages (usually based on message type).
Use to pretty print parts of the protobuf for easier diffing.
- print_unknown_fields: If True, unknown fields will be printed.
- force_colon: If set, a colon will be added after the field name even if
- the field is a proto message.
+ print_unknown_fields: If True, unknown fields will be printed.
+ force_colon: If set, a colon will be added after the field name even if
+ the field is a proto message.
"""
self.out = out
self.indent = indent
self.as_utf8 = as_utf8
self.as_one_line = as_one_line
- self.use_short_repeated_primitives = use_short_repeated_primitives
+ self.use_short_repeated_primitives = use_short_repeated_primitives
self.pointy_brackets = pointy_brackets
self.use_index_order = use_index_order
self.float_format = float_format
- if double_format is not None:
- self.double_format = double_format
- else:
- self.double_format = float_format
+ if double_format is not None:
+ self.double_format = double_format
+ else:
+ self.double_format = float_format
self.use_field_number = use_field_number
self.descriptor_pool = descriptor_pool
self.message_formatter = message_formatter
- self.print_unknown_fields = print_unknown_fields
- self.force_colon = force_colon
+ self.print_unknown_fields = print_unknown_fields
+ self.force_colon = force_colon
def _TryPrintAsAnyMessage(self, message):
"""Serializes if message is a google.protobuf.Any field."""
- if '/' not in message.type_url:
- return False
+ if '/' not in message.type_url:
+ return False
packed_message = _BuildMessageFromTypeName(message.TypeName(),
self.descriptor_pool)
if packed_message:
packed_message.MergeFromString(message.value)
- colon = ':' if self.force_colon else ''
- self.out.write('%s[%s]%s ' % (self.indent * ' ', message.type_url, colon))
+ colon = ':' if self.force_colon else ''
+ self.out.write('%s[%s]%s ' % (self.indent * ' ', message.type_url, colon))
self._PrintMessageFieldValue(packed_message)
self.out.write(' ' if self.as_one_line else '\n')
return True
@@ -440,12 +440,12 @@ class _Printer(object):
return
fields = message.ListFields()
if self.use_index_order:
- fields.sort(
- key=lambda x: x[0].number if x[0].is_extension else x[0].index)
+ fields.sort(
+ key=lambda x: x[0].number if x[0].is_extension else x[0].index)
for field, value in fields:
if _IsMapEntry(field):
for key in sorted(value):
- # This is slow for maps with submessage entries because it copies the
+ # This is slow for maps with submessage entries because it copies the
# entire tree. Unfortunately this would take significant refactoring
# of this file to work around.
#
@@ -453,77 +453,77 @@ class _Printer(object):
entry_submsg = value.GetEntryClass()(key=key, value=value[key])
self.PrintField(field, entry_submsg)
elif field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
- if (self.use_short_repeated_primitives
- and field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE
- and field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_STRING):
- self._PrintShortRepeatedPrimitivesValue(field, value)
- else:
- for element in value:
- self.PrintField(field, element)
+ if (self.use_short_repeated_primitives
+ and field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE
+ and field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_STRING):
+ self._PrintShortRepeatedPrimitivesValue(field, value)
+ else:
+ for element in value:
+ self.PrintField(field, element)
else:
self.PrintField(field, value)
- if self.print_unknown_fields:
- self._PrintUnknownFields(message.UnknownFields())
-
- def _PrintUnknownFields(self, unknown_fields):
- """Print unknown fields."""
- out = self.out
- for field in unknown_fields:
- out.write(' ' * self.indent)
- out.write(str(field.field_number))
- if field.wire_type == WIRETYPE_START_GROUP:
- if self.as_one_line:
- out.write(' { ')
- else:
- out.write(' {\n')
- self.indent += 2
-
- self._PrintUnknownFields(field.data)
-
- if self.as_one_line:
- out.write('} ')
- else:
- self.indent -= 2
- out.write(' ' * self.indent + '}\n')
- elif field.wire_type == WIRETYPE_LENGTH_DELIMITED:
- try:
- # If this field is parseable as a Message, it is probably
- # an embedded message.
- # pylint: disable=protected-access
- (embedded_unknown_message, pos) = decoder._DecodeUnknownFieldSet(
- memoryview(field.data), 0, len(field.data))
- except Exception: # pylint: disable=broad-except
- pos = 0
-
- if pos == len(field.data):
- if self.as_one_line:
- out.write(' { ')
- else:
- out.write(' {\n')
- self.indent += 2
-
- self._PrintUnknownFields(embedded_unknown_message)
-
- if self.as_one_line:
- out.write('} ')
- else:
- self.indent -= 2
- out.write(' ' * self.indent + '}\n')
- else:
- # A string or bytes field. self.as_utf8 may not work.
- out.write(': \"')
- out.write(text_encoding.CEscape(field.data, False))
- out.write('\" ' if self.as_one_line else '\"\n')
- else:
- # varint, fixed32, fixed64
- out.write(': ')
- out.write(str(field.data))
- out.write(' ' if self.as_one_line else '\n')
-
- def _PrintFieldName(self, field):
- """Print field name."""
+ if self.print_unknown_fields:
+ self._PrintUnknownFields(message.UnknownFields())
+
+ def _PrintUnknownFields(self, unknown_fields):
+ """Print unknown fields."""
out = self.out
+ for field in unknown_fields:
+ out.write(' ' * self.indent)
+ out.write(str(field.field_number))
+ if field.wire_type == WIRETYPE_START_GROUP:
+ if self.as_one_line:
+ out.write(' { ')
+ else:
+ out.write(' {\n')
+ self.indent += 2
+
+ self._PrintUnknownFields(field.data)
+
+ if self.as_one_line:
+ out.write('} ')
+ else:
+ self.indent -= 2
+ out.write(' ' * self.indent + '}\n')
+ elif field.wire_type == WIRETYPE_LENGTH_DELIMITED:
+ try:
+ # If this field is parseable as a Message, it is probably
+ # an embedded message.
+ # pylint: disable=protected-access
+ (embedded_unknown_message, pos) = decoder._DecodeUnknownFieldSet(
+ memoryview(field.data), 0, len(field.data))
+ except Exception: # pylint: disable=broad-except
+ pos = 0
+
+ if pos == len(field.data):
+ if self.as_one_line:
+ out.write(' { ')
+ else:
+ out.write(' {\n')
+ self.indent += 2
+
+ self._PrintUnknownFields(embedded_unknown_message)
+
+ if self.as_one_line:
+ out.write('} ')
+ else:
+ self.indent -= 2
+ out.write(' ' * self.indent + '}\n')
+ else:
+ # A string or bytes field. self.as_utf8 may not work.
+ out.write(': \"')
+ out.write(text_encoding.CEscape(field.data, False))
+ out.write('\" ' if self.as_one_line else '\"\n')
+ else:
+ # varint, fixed32, fixed64
+ out.write(': ')
+ out.write(str(field.data))
+ out.write(' ' if self.as_one_line else '\n')
+
+ def _PrintFieldName(self, field):
+ """Print field name."""
+ out = self.out
out.write(' ' * self.indent)
if self.use_field_number:
out.write(str(field.number))
@@ -541,34 +541,34 @@ class _Printer(object):
# For groups, use the capitalized name.
out.write(field.message_type.name)
else:
- out.write(field.name)
+ out.write(field.name)
- if (self.force_colon or
- field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE):
+ if (self.force_colon or
+ field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE):
# The colon is optional in this case, but our cross-language golden files
- # don't include it. Here, the colon is only included if force_colon is
- # set to True
- out.write(':')
-
- def PrintField(self, field, value):
- """Print a single field name/value pair."""
- self._PrintFieldName(field)
- self.out.write(' ')
+ # don't include it. Here, the colon is only included if force_colon is
+ # set to True
+ out.write(':')
+
+ def PrintField(self, field, value):
+ """Print a single field name/value pair."""
+ self._PrintFieldName(field)
+ self.out.write(' ')
self.PrintFieldValue(field, value)
- self.out.write(' ' if self.as_one_line else '\n')
-
- def _PrintShortRepeatedPrimitivesValue(self, field, value):
- """"Prints short repeated primitives value."""
- # Note: this is called only when value has at least one element.
- self._PrintFieldName(field)
- self.out.write(' [')
- for i in six.moves.range(len(value) - 1):
- self.PrintFieldValue(field, value[i])
- self.out.write(', ')
- self.PrintFieldValue(field, value[-1])
- self.out.write(']')
- self.out.write(' ' if self.as_one_line else '\n')
-
+ self.out.write(' ' if self.as_one_line else '\n')
+
+ def _PrintShortRepeatedPrimitivesValue(self, field, value):
+ """"Prints short repeated primitives value."""
+ # Note: this is called only when value has at least one element.
+ self._PrintFieldName(field)
+ self.out.write(' [')
+ for i in six.moves.range(len(value) - 1):
+ self.PrintFieldValue(field, value[i])
+ self.out.write(', ')
+ self.PrintFieldValue(field, value[-1])
+ self.out.write(']')
+ self.out.write(' ' if self.as_one_line else '\n')
+
def _PrintMessageFieldValue(self, value):
if self.pointy_brackets:
openb = '<'
@@ -578,11 +578,11 @@ class _Printer(object):
closeb = '}'
if self.as_one_line:
- self.out.write('%s ' % openb)
+ self.out.write('%s ' % openb)
self.PrintMessage(value)
self.out.write(closeb)
else:
- self.out.write('%s\n' % openb)
+ self.out.write('%s\n' % openb)
self.indent += 2
self.PrintMessage(value)
self.indent -= 2
@@ -608,12 +608,12 @@ class _Printer(object):
out.write(str(value))
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_STRING:
out.write('\"')
- if isinstance(value, six.text_type) and (six.PY2 or not self.as_utf8):
- out_value = value.encode('utf-8')
- else:
- out_value = value
+ if isinstance(value, six.text_type) and (six.PY2 or not self.as_utf8):
+ out_value = value.encode('utf-8')
+ else:
+ out_value = value
if field.type == descriptor.FieldDescriptor.TYPE_BYTES:
- # We always need to escape all binary data in TYPE_BYTES fields.
+ # We always need to escape all binary data in TYPE_BYTES fields.
out_as_utf8 = False
else:
out_as_utf8 = self.as_utf8
@@ -624,17 +624,17 @@ class _Printer(object):
out.write('true')
else:
out.write('false')
- elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
- if self.float_format is not None:
- out.write('{1:{0}}'.format(self.float_format, value))
- else:
- if math.isnan(value):
- out.write(str(value))
- else:
- out.write(str(type_checkers.ToShortestFloat(value)))
- elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_DOUBLE and
- self.double_format is not None):
- out.write('{1:{0}}'.format(self.double_format, value))
+ elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
+ if self.float_format is not None:
+ out.write('{1:{0}}'.format(self.float_format, value))
+ else:
+ if math.isnan(value):
+ out.write(str(value))
+ else:
+ out.write(str(type_checkers.ToShortestFloat(value)))
+ elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_DOUBLE and
+ self.double_format is not None):
+ out.write('{1:{0}}'.format(self.double_format, value))
else:
out.write(str(value))
@@ -643,108 +643,108 @@ def Parse(text,
message,
allow_unknown_extension=False,
allow_field_number=False,
- descriptor_pool=None,
- allow_unknown_field=False):
+ descriptor_pool=None,
+ allow_unknown_field=False):
"""Parses a text representation of a protocol message into a message.
NOTE: for historical reasons this function does not clear the input
message. This is different from what the binary msg.ParseFrom(...) does.
- If text contains a field already set in message, the value is appended if the
- field is repeated. Otherwise, an error is raised.
-
- Example::
+ If text contains a field already set in message, the value is appended if the
+ field is repeated. Otherwise, an error is raised.
+ Example::
+
a = MyProto()
a.repeated_field.append('test')
b = MyProto()
- # Repeated fields are combined
+ # Repeated fields are combined
text_format.Parse(repr(a), b)
text_format.Parse(repr(a), b) # repeated_field contains ["test", "test"]
- # Non-repeated fields cannot be overwritten
- a.singular_field = 1
- b.singular_field = 2
- text_format.Parse(repr(a), b) # ParseError
-
+ # Non-repeated fields cannot be overwritten
+ a.singular_field = 1
+ b.singular_field = 2
+ text_format.Parse(repr(a), b) # ParseError
+
# Binary version:
b.ParseFromString(a.SerializeToString()) # repeated_field is now "test"
Caller is responsible for clearing the message as needed.
Args:
- text (str): Message text representation.
- message (Message): A protocol buffer message to merge into.
+ text (str): Message text representation.
+ message (Message): A protocol buffer message to merge into.
allow_unknown_extension: if True, skip over missing extensions and keep
parsing
allow_field_number: if True, both field number and field name are allowed.
- descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
- allow_unknown_field: if True, skip over unknown field and keep
- parsing. Avoid to use this option if possible. It may hide some
- errors (e.g. spelling error on field name)
+ descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
+ allow_unknown_field: if True, skip over unknown field and keep
+ parsing. Avoid to use this option if possible. It may hide some
+ errors (e.g. spelling error on field name)
Returns:
- Message: The same message passed as argument.
+ Message: The same message passed as argument.
Raises:
ParseError: On text parsing problems.
"""
- return ParseLines(text.split(b'\n' if isinstance(text, bytes) else u'\n'),
+ return ParseLines(text.split(b'\n' if isinstance(text, bytes) else u'\n'),
message,
allow_unknown_extension,
allow_field_number,
- descriptor_pool=descriptor_pool,
- allow_unknown_field=allow_unknown_field)
+ descriptor_pool=descriptor_pool,
+ allow_unknown_field=allow_unknown_field)
def Merge(text,
message,
allow_unknown_extension=False,
allow_field_number=False,
- descriptor_pool=None,
- allow_unknown_field=False):
+ descriptor_pool=None,
+ allow_unknown_field=False):
"""Parses a text representation of a protocol message into a message.
Like Parse(), but allows repeated values for a non-repeated field, and uses
- the last one. This means any non-repeated, top-level fields specified in text
- replace those in the message.
+ the last one. This means any non-repeated, top-level fields specified in text
+ replace those in the message.
Args:
- text (str): Message text representation.
- message (Message): A protocol buffer message to merge into.
+ text (str): Message text representation.
+ message (Message): A protocol buffer message to merge into.
allow_unknown_extension: if True, skip over missing extensions and keep
parsing
allow_field_number: if True, both field number and field name are allowed.
- descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
- allow_unknown_field: if True, skip over unknown field and keep
- parsing. Avoid to use this option if possible. It may hide some
- errors (e.g. spelling error on field name)
+ descriptor_pool (DescriptorPool): Descriptor pool used to resolve Any types.
+ allow_unknown_field: if True, skip over unknown field and keep
+ parsing. Avoid to use this option if possible. It may hide some
+ errors (e.g. spelling error on field name)
Returns:
- Message: The same message passed as argument.
+ Message: The same message passed as argument.
Raises:
ParseError: On text parsing problems.
"""
return MergeLines(
- text.split(b'\n' if isinstance(text, bytes) else u'\n'),
+ text.split(b'\n' if isinstance(text, bytes) else u'\n'),
message,
allow_unknown_extension,
allow_field_number,
- descriptor_pool=descriptor_pool,
- allow_unknown_field=allow_unknown_field)
+ descriptor_pool=descriptor_pool,
+ allow_unknown_field=allow_unknown_field)
def ParseLines(lines,
message,
allow_unknown_extension=False,
allow_field_number=False,
- descriptor_pool=None,
- allow_unknown_field=False):
+ descriptor_pool=None,
+ allow_unknown_field=False):
"""Parses a text representation of a protocol message into a message.
- See Parse() for caveats.
-
+ See Parse() for caveats.
+
Args:
lines: An iterable of lines of a message's text representation.
message: A protocol buffer message to merge into.
@@ -752,9 +752,9 @@ def ParseLines(lines,
parsing
allow_field_number: if True, both field number and field name are allowed.
descriptor_pool: A DescriptorPool used to resolve Any types.
- allow_unknown_field: if True, skip over unknown field and keep
- parsing. Avoid to use this option if possible. It may hide some
- errors (e.g. spelling error on field name)
+ allow_unknown_field: if True, skip over unknown field and keep
+ parsing. Avoid to use this option if possible. It may hide some
+ errors (e.g. spelling error on field name)
Returns:
The same message passed as argument.
@@ -764,8 +764,8 @@ def ParseLines(lines,
"""
parser = _Parser(allow_unknown_extension,
allow_field_number,
- descriptor_pool=descriptor_pool,
- allow_unknown_field=allow_unknown_field)
+ descriptor_pool=descriptor_pool,
+ allow_unknown_field=allow_unknown_field)
return parser.ParseLines(lines, message)
@@ -773,12 +773,12 @@ def MergeLines(lines,
message,
allow_unknown_extension=False,
allow_field_number=False,
- descriptor_pool=None,
- allow_unknown_field=False):
+ descriptor_pool=None,
+ allow_unknown_field=False):
"""Parses a text representation of a protocol message into a message.
- See Merge() for more details.
-
+ See Merge() for more details.
+
Args:
lines: An iterable of lines of a message's text representation.
message: A protocol buffer message to merge into.
@@ -786,9 +786,9 @@ def MergeLines(lines,
parsing
allow_field_number: if True, both field number and field name are allowed.
descriptor_pool: A DescriptorPool used to resolve Any types.
- allow_unknown_field: if True, skip over unknown field and keep
- parsing. Avoid to use this option if possible. It may hide some
- errors (e.g. spelling error on field name)
+ allow_unknown_field: if True, skip over unknown field and keep
+ parsing. Avoid to use this option if possible. It may hide some
+ errors (e.g. spelling error on field name)
Returns:
The same message passed as argument.
@@ -798,8 +798,8 @@ def MergeLines(lines,
"""
parser = _Parser(allow_unknown_extension,
allow_field_number,
- descriptor_pool=descriptor_pool,
- allow_unknown_field=allow_unknown_field)
+ descriptor_pool=descriptor_pool,
+ allow_unknown_field=allow_unknown_field)
return parser.MergeLines(lines, message)
@@ -809,12 +809,12 @@ class _Parser(object):
def __init__(self,
allow_unknown_extension=False,
allow_field_number=False,
- descriptor_pool=None,
- allow_unknown_field=False):
+ descriptor_pool=None,
+ allow_unknown_field=False):
self.allow_unknown_extension = allow_unknown_extension
self.allow_field_number = allow_field_number
self.descriptor_pool = descriptor_pool
- self.allow_unknown_field = allow_unknown_field
+ self.allow_unknown_field = allow_unknown_field
def ParseLines(self, lines, message):
"""Parses a text representation of a protocol message into a message."""
@@ -838,14 +838,14 @@ class _Parser(object):
Raises:
ParseError: On text parsing problems.
"""
- # Tokenize expects native str lines.
- if six.PY2:
- str_lines = (line if isinstance(line, str) else line.encode('utf-8')
- for line in lines)
- else:
- str_lines = (line if isinstance(line, str) else line.decode('utf-8')
- for line in lines)
- tokenizer = Tokenizer(str_lines)
+ # Tokenize expects native str lines.
+ if six.PY2:
+ str_lines = (line if isinstance(line, str) else line.encode('utf-8')
+ for line in lines)
+ else:
+ str_lines = (line if isinstance(line, str) else line.decode('utf-8')
+ for line in lines)
+ tokenizer = Tokenizer(str_lines)
while not tokenizer.AtEnd():
self._MergeField(tokenizer, message)
@@ -860,33 +860,33 @@ class _Parser(object):
ParseError: In case of text parsing problems.
"""
message_descriptor = message.DESCRIPTOR
- if (message_descriptor.full_name == _ANY_FULL_TYPE_NAME and
- tokenizer.TryConsume('[')):
- type_url_prefix, packed_type_name = self._ConsumeAnyTypeUrl(tokenizer)
- tokenizer.Consume(']')
- tokenizer.TryConsume(':')
- if tokenizer.TryConsume('<'):
- expanded_any_end_token = '>'
- else:
- tokenizer.Consume('{')
- expanded_any_end_token = '}'
- expanded_any_sub_message = _BuildMessageFromTypeName(packed_type_name,
- self.descriptor_pool)
- if not expanded_any_sub_message:
- raise ParseError('Type %s not found in descriptor pool' %
- packed_type_name)
- while not tokenizer.TryConsume(expanded_any_end_token):
- if tokenizer.AtEnd():
- raise tokenizer.ParseErrorPreviousToken('Expected "%s".' %
- (expanded_any_end_token,))
- self._MergeField(tokenizer, expanded_any_sub_message)
- deterministic = False
-
- message.Pack(expanded_any_sub_message,
- type_url_prefix=type_url_prefix,
- deterministic=deterministic)
- return
-
+ if (message_descriptor.full_name == _ANY_FULL_TYPE_NAME and
+ tokenizer.TryConsume('[')):
+ type_url_prefix, packed_type_name = self._ConsumeAnyTypeUrl(tokenizer)
+ tokenizer.Consume(']')
+ tokenizer.TryConsume(':')
+ if tokenizer.TryConsume('<'):
+ expanded_any_end_token = '>'
+ else:
+ tokenizer.Consume('{')
+ expanded_any_end_token = '}'
+ expanded_any_sub_message = _BuildMessageFromTypeName(packed_type_name,
+ self.descriptor_pool)
+ if not expanded_any_sub_message:
+ raise ParseError('Type %s not found in descriptor pool' %
+ packed_type_name)
+ while not tokenizer.TryConsume(expanded_any_end_token):
+ if tokenizer.AtEnd():
+ raise tokenizer.ParseErrorPreviousToken('Expected "%s".' %
+ (expanded_any_end_token,))
+ self._MergeField(tokenizer, expanded_any_sub_message)
+ deterministic = False
+
+ message.Pack(expanded_any_sub_message,
+ type_url_prefix=type_url_prefix,
+ deterministic=deterministic)
+ return
+
if tokenizer.TryConsume('['):
name = [tokenizer.ConsumeIdentifier()]
while tokenizer.TryConsume('.'):
@@ -900,8 +900,8 @@ class _Parser(object):
# pylint: disable=protected-access
field = message.Extensions._FindExtensionByName(name)
# pylint: enable=protected-access
-
-
+
+
if not field:
if self.allow_unknown_extension:
field = None
@@ -941,7 +941,7 @@ class _Parser(object):
field.message_type.name != name):
field = None
- if not field and not self.allow_unknown_field:
+ if not field and not self.allow_unknown_field:
raise tokenizer.ParseErrorPreviousToken(
'Message type "%s" has no field named "%s".' %
(message_descriptor.full_name, name))
@@ -969,18 +969,18 @@ class _Parser(object):
if (field.label == descriptor.FieldDescriptor.LABEL_REPEATED and
tokenizer.TryConsume('[')):
# Short repeated format, e.g. "foo: [1, 2, 3]"
- if not tokenizer.TryConsume(']'):
- while True:
- merger(tokenizer, message, field)
- if tokenizer.TryConsume(']'):
- break
- tokenizer.Consume(',')
+ if not tokenizer.TryConsume(']'):
+ while True:
+ merger(tokenizer, message, field)
+ if tokenizer.TryConsume(']'):
+ break
+ tokenizer.Consume(',')
else:
merger(tokenizer, message, field)
else: # Proto field is unknown.
- assert (self.allow_unknown_extension or self.allow_unknown_field)
+ assert (self.allow_unknown_extension or self.allow_unknown_field)
_SkipFieldContents(tokenizer)
# For historical reasons, fields may optionally be separated by commas or
@@ -988,7 +988,7 @@ class _Parser(object):
if not tokenizer.TryConsume(','):
tokenizer.TryConsume(';')
-
+
def _ConsumeAnyTypeUrl(self, tokenizer):
"""Consumes a google.protobuf.Any type URL and returns the type name."""
# Consume "type.googleapis.com/".
@@ -1023,7 +1023,7 @@ class _Parser(object):
tokenizer.Consume('{')
end_token = '}'
- if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
+ if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
if field.is_extension:
sub_message = message.Extensions[field].add()
elif is_map_entry:
@@ -1032,20 +1032,20 @@ class _Parser(object):
sub_message = getattr(message, field.name).add()
else:
if field.is_extension:
- if (not self._allow_multiple_scalars and
- message.HasExtension(field)):
- raise tokenizer.ParseErrorPreviousToken(
- 'Message type "%s" should not have multiple "%s" extensions.' %
- (message.DESCRIPTOR.full_name, field.full_name))
+ if (not self._allow_multiple_scalars and
+ message.HasExtension(field)):
+ raise tokenizer.ParseErrorPreviousToken(
+ 'Message type "%s" should not have multiple "%s" extensions.' %
+ (message.DESCRIPTOR.full_name, field.full_name))
sub_message = message.Extensions[field]
else:
- # Also apply _allow_multiple_scalars to message field.
- # TODO(jieluo): Change to _allow_singular_overwrites.
- if (not self._allow_multiple_scalars and
- message.HasField(field.name)):
- raise tokenizer.ParseErrorPreviousToken(
- 'Message type "%s" should not have multiple "%s" fields.' %
- (message.DESCRIPTOR.full_name, field.name))
+ # Also apply _allow_multiple_scalars to message field.
+ # TODO(jieluo): Change to _allow_singular_overwrites.
+ if (not self._allow_multiple_scalars and
+ message.HasField(field.name)):
+ raise tokenizer.ParseErrorPreviousToken(
+ 'Message type "%s" should not have multiple "%s" fields.' %
+ (message.DESCRIPTOR.full_name, field.name))
sub_message = getattr(message, field.name)
sub_message.SetInParent()
@@ -1058,7 +1058,7 @@ class _Parser(object):
value_cpptype = field.message_type.fields_by_name['value'].cpp_type
if value_cpptype == descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
value = getattr(message, field.name)[sub_message.key]
- value.CopyFrom(sub_message.value)
+ value.CopyFrom(sub_message.value)
else:
getattr(message, field.name)[sub_message.key] = sub_message.value
@@ -1118,8 +1118,8 @@ class _Parser(object):
getattr(message, field.name).append(value)
else:
if field.is_extension:
- if (not self._allow_multiple_scalars and
- not self._IsProto3Syntax(message) and
+ if (not self._allow_multiple_scalars and
+ not self._IsProto3Syntax(message) and
message.HasExtension(field)):
raise tokenizer.ParseErrorPreviousToken(
'Message type "%s" should not have multiple "%s" extensions.' %
@@ -1127,16 +1127,16 @@ class _Parser(object):
else:
message.Extensions[field] = value
else:
- duplicate_error = False
- if not self._allow_multiple_scalars:
- if self._IsProto3Syntax(message):
- # Proto3 doesn't represent presence so we try best effort to check
- # multiple scalars by compare to default values.
- duplicate_error = bool(getattr(message, field.name))
- else:
- duplicate_error = message.HasField(field.name)
-
- if duplicate_error:
+ duplicate_error = False
+ if not self._allow_multiple_scalars:
+ if self._IsProto3Syntax(message):
+ # Proto3 doesn't represent presence so we try best effort to check
+ # multiple scalars by compare to default values.
+ duplicate_error = bool(getattr(message, field.name))
+ else:
+ duplicate_error = message.HasField(field.name)
+
+ if duplicate_error:
raise tokenizer.ParseErrorPreviousToken(
'Message type "%s" should not have multiple "%s" fields.' %
(message.DESCRIPTOR.full_name, field.name))
@@ -1176,7 +1176,7 @@ def _SkipField(tokenizer):
tokenizer.ConsumeIdentifier()
tokenizer.Consume(']')
else:
- tokenizer.ConsumeIdentifierOrNumber()
+ tokenizer.ConsumeIdentifierOrNumber()
_SkipFieldContents(tokenizer)
@@ -1243,9 +1243,9 @@ class Tokenizer(object):
r'[a-zA-Z_][0-9a-zA-Z_+-]*', # an identifier
r'([0-9+-]|(\.[0-9]))[0-9a-zA-Z_.+-]*', # a number
] + [ # quoted str for each quote mark
- # Avoid backtracking! https://stackoverflow.com/a/844267
- r'{qt}[^{qt}\n\\]*((\\.)+[^{qt}\n\\]*)*({qt}|\\?$)'.format(qt=mark)
- for mark in _QUOTES
+ # Avoid backtracking! https://stackoverflow.com/a/844267
+ r'{qt}[^{qt}\n\\]*((\\.)+[^{qt}\n\\]*)*({qt}|\\?$)'.format(qt=mark)
+ for mark in _QUOTES
]))
_IDENTIFIER = re.compile(r'[^\d\W]\w*')
@@ -1474,11 +1474,11 @@ class Tokenizer(object):
Raises:
ParseError: If a string value couldn't be consumed.
"""
- the_bytes = self.ConsumeByteString()
- try:
- return six.text_type(the_bytes, 'utf-8')
- except UnicodeDecodeError as e:
- raise self._StringParseError(e)
+ the_bytes = self.ConsumeByteString()
+ try:
+ return six.text_type(the_bytes, 'utf-8')
+ except UnicodeDecodeError as e:
+ raise self._StringParseError(e)
def ConsumeByteString(self):
"""Consumes a byte array value.
@@ -1542,8 +1542,8 @@ class Tokenizer(object):
def ParseError(self, message):
"""Creates and *returns* a ParseError for the current token."""
- return ParseError('\'' + self._current_line + '\': ' + message,
- self._line + 1, self._column + 1)
+ return ParseError('\'' + self._current_line + '\': ' + message,
+ self._line + 1, self._column + 1)
def _StringParseError(self, e):
return self.ParseError('Couldn\'t parse string: ' + str(e))
@@ -1717,12 +1717,12 @@ def _ParseAbstractInteger(text, is_long=False):
ValueError: Thrown Iff the text is not a valid integer.
"""
# Do the actual parsing. Exception handling is propagated to caller.
- orig_text = text
- c_octal_match = re.match(r'(-?)0(\d+)$', text)
- if c_octal_match:
- # Python 3 no longer supports 0755 octal syntax without the 'o', so
- # we always use the '0o' prefix for multi-digit numbers starting with 0.
- text = c_octal_match.group(1) + '0o' + c_octal_match.group(2)
+ orig_text = text
+ c_octal_match = re.match(r'(-?)0(\d+)$', text)
+ if c_octal_match:
+ # Python 3 no longer supports 0755 octal syntax without the 'o', so
+ # we always use the '0o' prefix for multi-digit numbers starting with 0.
+ text = c_octal_match.group(1) + '0o' + c_octal_match.group(2)
try:
# We force 32-bit values to int and 64-bit values to long to make
# alternate implementations where the distinction is more significant
@@ -1732,7 +1732,7 @@ def _ParseAbstractInteger(text, is_long=False):
else:
return int(text, 0)
except ValueError:
- raise ValueError('Couldn\'t parse integer: %s' % orig_text)
+ raise ValueError('Couldn\'t parse integer: %s' % orig_text)
def ParseFloat(text):
@@ -1814,11 +1814,11 @@ def ParseEnum(field, value):
(enum_descriptor.full_name, value))
else:
# Numeric value.
- if hasattr(field.file, 'syntax'):
- # Attribute is checked for compatibility.
- if field.file.syntax == 'proto3':
- # Proto3 accept numeric unknown enums.
- return number
+ if hasattr(field.file, 'syntax'):
+ # Attribute is checked for compatibility.
+ if field.file.syntax == 'proto3':
+ # Proto3 accept numeric unknown enums.
+ return number
enum_value = enum_descriptor.values_by_number.get(number, None)
if enum_value is None:
raise ValueError('Enum type "%s" has no value with number %d.' %
diff --git a/contrib/python/protobuf/py3/ya.make b/contrib/python/protobuf/py3/ya.make
index 28099779e1..36cfdf70f4 100644
--- a/contrib/python/protobuf/py3/ya.make
+++ b/contrib/python/protobuf/py3/ya.make
@@ -1,95 +1,95 @@
-# Generated by devtools/yamaker.
-
-PY3_LIBRARY()
-
-LICENSE(BSD-3-Clause)
-
-LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
-
-OWNER(
- g:cpp-committee
- g:cpp-contrib
-)
-
-VERSION(3.17.3)
-
-ORIGINAL_SOURCE(https://github.com/protocolbuffers/protobuf/archive/v3.17.3.tar.gz)
-
-PEERDIR(
- contrib/libs/protobuf
- contrib/libs/protobuf/builtin_proto/protos_from_protobuf
- contrib/libs/protobuf/builtin_proto/protos_from_protoc
- contrib/python/six
-)
-
-ADDINCL(
- contrib/python/protobuf/py3
-)
-
-NO_COMPILER_WARNINGS()
-
-NO_LINT()
-
-CFLAGS(
- -DPYTHON_PROTO2_CPP_IMPL_V2
-)
-
-SRCS(
- google/protobuf/internal/api_implementation.cc
- google/protobuf/pyext/descriptor.cc
- google/protobuf/pyext/descriptor_containers.cc
- google/protobuf/pyext/descriptor_database.cc
- google/protobuf/pyext/descriptor_pool.cc
- google/protobuf/pyext/extension_dict.cc
- google/protobuf/pyext/field.cc
- google/protobuf/pyext/map_container.cc
- google/protobuf/pyext/message.cc
- google/protobuf/pyext/message_factory.cc
- google/protobuf/pyext/message_module.cc
- google/protobuf/pyext/repeated_composite_container.cc
- google/protobuf/pyext/repeated_scalar_container.cc
- google/protobuf/pyext/unknown_fields.cc
-)
-
-PY_REGISTER(
- google.protobuf.internal._api_implementation
- google.protobuf.pyext._message
-)
-
-PY_SRCS(
- TOP_LEVEL
- google/__init__.py
- google/protobuf/__init__.py
- google/protobuf/compiler/__init__.py
- google/protobuf/descriptor.py
- google/protobuf/descriptor_database.py
- google/protobuf/descriptor_pool.py
- google/protobuf/internal/__init__.py
- google/protobuf/internal/_parameterized.py
- google/protobuf/internal/api_implementation.py
- google/protobuf/internal/containers.py
- google/protobuf/internal/decoder.py
- google/protobuf/internal/encoder.py
- google/protobuf/internal/enum_type_wrapper.py
- google/protobuf/internal/extension_dict.py
- google/protobuf/internal/message_listener.py
- google/protobuf/internal/python_message.py
- google/protobuf/internal/type_checkers.py
- google/protobuf/internal/well_known_types.py
- google/protobuf/internal/wire_format.py
- google/protobuf/json_format.py
- google/protobuf/message.py
- google/protobuf/message_factory.py
- google/protobuf/proto_builder.py
- google/protobuf/pyext/__init__.py
- google/protobuf/pyext/cpp_message.py
- google/protobuf/reflection.py
- google/protobuf/service.py
- google/protobuf/service_reflection.py
- google/protobuf/symbol_database.py
- google/protobuf/text_encoding.py
- google/protobuf/text_format.py
- google/protobuf/util/__init__.py
-)
-
-END()
+# Generated by devtools/yamaker.
+
+PY3_LIBRARY()
+
+LICENSE(BSD-3-Clause)
+
+LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
+
+OWNER(
+ g:cpp-committee
+ g:cpp-contrib
+)
+
+VERSION(3.17.3)
+
+ORIGINAL_SOURCE(https://github.com/protocolbuffers/protobuf/archive/v3.17.3.tar.gz)
+
+PEERDIR(
+ contrib/libs/protobuf
+ contrib/libs/protobuf/builtin_proto/protos_from_protobuf
+ contrib/libs/protobuf/builtin_proto/protos_from_protoc
+ contrib/python/six
+)
+
+ADDINCL(
+ contrib/python/protobuf/py3
+)
+
+NO_COMPILER_WARNINGS()
+
+NO_LINT()
+
+CFLAGS(
+ -DPYTHON_PROTO2_CPP_IMPL_V2
+)
+
+SRCS(
+ google/protobuf/internal/api_implementation.cc
+ google/protobuf/pyext/descriptor.cc
+ google/protobuf/pyext/descriptor_containers.cc
+ google/protobuf/pyext/descriptor_database.cc
+ google/protobuf/pyext/descriptor_pool.cc
+ google/protobuf/pyext/extension_dict.cc
+ google/protobuf/pyext/field.cc
+ google/protobuf/pyext/map_container.cc
+ google/protobuf/pyext/message.cc
+ google/protobuf/pyext/message_factory.cc
+ google/protobuf/pyext/message_module.cc
+ google/protobuf/pyext/repeated_composite_container.cc
+ google/protobuf/pyext/repeated_scalar_container.cc
+ google/protobuf/pyext/unknown_fields.cc
+)
+
+PY_REGISTER(
+ google.protobuf.internal._api_implementation
+ google.protobuf.pyext._message
+)
+
+PY_SRCS(
+ TOP_LEVEL
+ google/__init__.py
+ google/protobuf/__init__.py
+ google/protobuf/compiler/__init__.py
+ google/protobuf/descriptor.py
+ google/protobuf/descriptor_database.py
+ google/protobuf/descriptor_pool.py
+ google/protobuf/internal/__init__.py
+ google/protobuf/internal/_parameterized.py
+ google/protobuf/internal/api_implementation.py
+ google/protobuf/internal/containers.py
+ google/protobuf/internal/decoder.py
+ google/protobuf/internal/encoder.py
+ google/protobuf/internal/enum_type_wrapper.py
+ google/protobuf/internal/extension_dict.py
+ google/protobuf/internal/message_listener.py
+ google/protobuf/internal/python_message.py
+ google/protobuf/internal/type_checkers.py
+ google/protobuf/internal/well_known_types.py
+ google/protobuf/internal/wire_format.py
+ google/protobuf/json_format.py
+ google/protobuf/message.py
+ google/protobuf/message_factory.py
+ google/protobuf/proto_builder.py
+ google/protobuf/pyext/__init__.py
+ google/protobuf/pyext/cpp_message.py
+ google/protobuf/reflection.py
+ google/protobuf/service.py
+ google/protobuf/service_reflection.py
+ google/protobuf/symbol_database.py
+ google/protobuf/text_encoding.py
+ google/protobuf/text_format.py
+ google/protobuf/util/__init__.py
+)
+
+END()
diff --git a/contrib/python/protobuf/ya.make b/contrib/python/protobuf/ya.make
index 50b64e36b1..b5737a1c10 100644
--- a/contrib/python/protobuf/ya.make
+++ b/contrib/python/protobuf/ya.make
@@ -1,18 +1,18 @@
-PY23_LIBRARY()
-
-LICENSE(Service-Py23-Proxy)
-
-OWNER(g:devtools-contrib)
-
-IF (PYTHON2)
- PEERDIR(contrib/python/protobuf/py2)
-ELSE()
- PEERDIR(contrib/python/protobuf/py3)
-ENDIF()
-
-END()
-
-RECURSE(
- py2
- py3
-)
+PY23_LIBRARY()
+
+LICENSE(Service-Py23-Proxy)
+
+OWNER(g:devtools-contrib)
+
+IF (PYTHON2)
+ PEERDIR(contrib/python/protobuf/py2)
+ELSE()
+ PEERDIR(contrib/python/protobuf/py3)
+ENDIF()
+
+END()
+
+RECURSE(
+ py2
+ py3
+)
diff --git a/contrib/python/s3transfer/ya.make b/contrib/python/s3transfer/ya.make
index bf4a234edb..780dabd388 100644
--- a/contrib/python/s3transfer/ya.make
+++ b/contrib/python/s3transfer/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/setuptools/ya.make b/contrib/python/setuptools/ya.make
index 535a2d61fa..745ad30808 100644
--- a/contrib/python/setuptools/ya.make
+++ b/contrib/python/setuptools/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/tornado/ya.make b/contrib/python/tornado/ya.make
index 85a91fb7c1..34dcf30285 100644
--- a/contrib/python/tornado/ya.make
+++ b/contrib/python/tornado/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/traitlets/ya.make b/contrib/python/traitlets/ya.make
index 3156aae8c5..64151acd34 100644
--- a/contrib/python/traitlets/ya.make
+++ b/contrib/python/traitlets/ya.make
@@ -1,6 +1,6 @@
PY23_LIBRARY()
-LICENSE(Service-Py23-Proxy)
+LICENSE(Service-Py23-Proxy)
OWNER(g:python-contrib)
diff --git a/contrib/python/ya.make b/contrib/python/ya.make
index d01ced9f3a..de91fe9791 100644
--- a/contrib/python/ya.make
+++ b/contrib/python/ya.make
@@ -57,7 +57,7 @@ RECURSE(
apispec-flask-restful
appdirs
APScheduler
- apsw
+ apsw
aresponses
argcomplete
argon2-cffi
@@ -70,7 +70,7 @@ RECURSE(
asn1crypto
astroid
asttokens
- astunparse
+ astunparse
async-generator
async-lru
async-timeout
@@ -428,7 +428,7 @@ RECURSE(
furl
future
futures
- gast
+ gast
gcovr
GDAL
gemfileparser
@@ -450,7 +450,7 @@ RECURSE(
google-auth-httplib2
google-auth-oauthlib
google-cloud-speech
- google-pasta
+ google-pasta
googleads
gpxpy
GPy
@@ -571,7 +571,7 @@ RECURSE(
jupytext
kaitaistruct
kazoo
- Keras-Preprocessing
+ Keras-Preprocessing
kiwisolver
kombu
korean-lunar-calendar
@@ -689,7 +689,7 @@ RECURSE(
opentracing
opentracing-async-instrumentation
opentracing-instrumentation
- opt-einsum
+ opt-einsum
option
ordered-set
orderedmultidict
@@ -753,7 +753,7 @@ RECURSE(
plyvel
polib
portalocker
- portpicker
+ portpicker
ppdeep
pq
pql
@@ -769,8 +769,8 @@ RECURSE(
promise
prompt-toolkit
prophet
- protobuf
- protobuf_std
+ protobuf
+ protobuf_std
protobuf_to_dict
psutil
psycogreen
@@ -1053,14 +1053,14 @@ RECURSE(
tblib
Telethon
tenacity
- tensorflow-estimator
+ tensorflow-estimator
termcolor
terminado
terminaltables
testpath
text-unidecode
textdata
- texttable
+ texttable
textwrap3
thinc
threadloop
@@ -1204,7 +1204,7 @@ IF (OS_LINUX)
pyroute2
)
- IF (OS_SDK != "ubuntu-12")
+ IF (OS_SDK != "ubuntu-12")
RECURSE(
cysystemd
)