diff options
author | mikhnenko <mikhnenko@yandex-team.com> | 2024-05-29 09:32:09 +0300 |
---|---|---|
committer | mikhnenko <mikhnenko@yandex-team.com> | 2024-05-29 09:44:22 +0300 |
commit | 641d8332d02a38f849b08161a53860b221667e14 (patch) | |
tree | b3bf28f8c3479ccd8885156b33ae6692ff34f64b | |
parent | 40cb8b5d92db0a64bded46434571f268068954ba (diff) | |
download | ydb-641d8332d02a38f849b08161a53860b221667e14.tar.gz |
Update py-protobuf to 3.19.0
dda7c66445e788f38ea676a1713aeca30e370f6a
23 files changed, 173 insertions, 693 deletions
diff --git a/contrib/python/protobuf/py3/.dist-info/METADATA b/contrib/python/protobuf/py3/.dist-info/METADATA index 788d8931c3..79a3401f13 100644 --- a/contrib/python/protobuf/py3/.dist-info/METADATA +++ b/contrib/python/protobuf/py3/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: protobuf -Version: 3.18.1 +Version: 3.19.0 Summary: Protocol Buffers Home-page: https://developers.google.com/protocol-buffers/ Download-URL: https://github.com/protocolbuffers/protobuf/releases @@ -10,11 +10,12 @@ License: 3-Clause BSD License Platform: UNKNOWN Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.3 -Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: 3.8 +Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 Requires-Python: >=3.5 License-File: LICENSE diff --git a/contrib/python/protobuf/py3/google/protobuf/__init__.py b/contrib/python/protobuf/py3/google/protobuf/__init__.py index b8122e82ae..68087e5501 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.18.1' +__version__ = '3.19.0' diff --git a/contrib/python/protobuf/py3/google/protobuf/descriptor.py b/contrib/python/protobuf/py3/google/protobuf/descriptor.py index 0f7bd17443..61c242f9df 100644 --- a/contrib/python/protobuf/py3/google/protobuf/descriptor.py +++ b/contrib/python/protobuf/py3/google/protobuf/descriptor.py @@ -951,7 +951,7 @@ class FileDescriptor(DescriptorBase): 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`. + to their :class:`Descriptor`. enum_types_by_name (dict(str, EnumDescriptor)): Mapping from enum names to their :class:`EnumDescriptor`. extensions_by_name (dict(str, FieldDescriptor)): Mapping from extension diff --git a/contrib/python/protobuf/py3/google/protobuf/descriptor_pool.py b/contrib/python/protobuf/py3/google/protobuf/descriptor_pool.py index de9100b09c..a6955ce81e 100644 --- a/contrib/python/protobuf/py3/google/protobuf/descriptor_pool.py +++ b/contrib/python/protobuf/py3/google/protobuf/descriptor_pool.py @@ -207,13 +207,18 @@ class DescriptorPool(object): Args: serialized_file_desc_proto (bytes): A bytes string, serialization of the :class:`FileDescriptorProto` to add. + + Returns: + FileDescriptor: Descriptor for the added file. """ # pylint: disable=g-import-not-at-top from google.protobuf import descriptor_pb2 file_desc_proto = descriptor_pb2.FileDescriptorProto.FromString( serialized_file_desc_proto) - self.Add(file_desc_proto) + file_desc = self._ConvertFileProtoToFileDescriptor(file_desc_proto) + file_desc.serialized_pb = serialized_file_desc_proto + return file_desc # Add Descriptor to descriptor pool is dreprecated. Please use Add() # or AddSerializedFile() to add a FileDescriptorProto instead. @@ -808,7 +813,6 @@ class DescriptorPool(object): self._MakeServiceDescriptor(service_proto, index, scope, file_proto.package, file_descriptor)) - self.Add(file_proto) self._file_descriptors[file_proto.name] = file_descriptor # Add extensions to the pool @@ -865,11 +869,17 @@ class DescriptorPool(object): for index, extension in enumerate(desc_proto.extension)] oneofs = [ # 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) - for index, desc in enumerate(desc_proto.oneof_decl)] + descriptor.OneofDescriptor( + desc.name, + '.'.join((desc_name, desc.name)), + index, + None, + [], + _OptionsOrNone(desc), + # 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: is_extendable = True @@ -987,6 +997,11 @@ class DescriptorPool(object): else: full_name = field_proto.name + if field_proto.json_name: + json_name = field_proto.json_name + else: + json_name = None + return descriptor.FieldDescriptor( name=field_proto.name, full_name=full_name, @@ -1003,6 +1018,7 @@ class DescriptorPool(object): is_extension=is_extension, extension_scope=None, options=_OptionsOrNone(field_proto), + json_name=json_name, file=file_desc, # pylint: disable=protected-access create_key=descriptor._internal_create_key) @@ -1107,6 +1123,8 @@ class DescriptorPool(object): 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_GROUP: + field_desc.default_value = None else: # All other types are of the "int" type. field_desc.default_value = 0 diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/__init__.py b/contrib/python/protobuf/py3/google/protobuf/internal/__init__.py index 7d2e571a14..e69de29bb2 100644 --- a/contrib/python/protobuf/py3/google/protobuf/internal/__init__.py +++ b/contrib/python/protobuf/py3/google/protobuf/internal/__init__.py @@ -1,30 +0,0 @@ -# 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/api_implementation.cc b/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.cc index 2a7f41d2d6..6532a81405 100644 --- a/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.cc +++ b/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.cc @@ -77,7 +77,6 @@ static const char kModuleDocstring[] = "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, @@ -87,38 +86,22 @@ static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT, NULL, NULL, NULL}; -#define INITFUNC PyInit__api_implementation -#define INITFUNC_ERRORVAL NULL -#else -#define INITFUNC init_api_implementation -#define INITFUNC_ERRORVAL -#endif extern "C" { -PyMODINIT_FUNC INITFUNC() { -#if PY_MAJOR_VERSION >= 3 +PyMODINIT_FUNC PyInit__api_implementation() { PyObject* module = PyModule_Create(&_module); -#else - PyObject* module = Py_InitModule3(const_cast<char*>(kModuleName), NULL, - const_cast<char*>(kModuleDocstring)); -#endif if (module == NULL) { - return INITFUNC_ERRORVAL; + return NULL; } // Adds the module variable "api_version". if (PyModule_AddIntConstant(module, const_cast<char*>(kImplVersionName), - kImplVersion)) -#if PY_MAJOR_VERSION < 3 - return; -#else - { + kImplVersion)) { Py_DECREF(module); return NULL; } return module; -#endif } } 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 a3667318c1..7fef237670 100644 --- a/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.py +++ b/contrib/python/protobuf/py3/google/protobuf/internal/api_implementation.py @@ -41,46 +41,15 @@ try: # The compile-time constants in the _api_implementation module can be used to # switch to a certain implementation of the Python API at build time. _api_version = _api_implementation.api_version - _proto_extension_modules_exist_in_build = True except ImportError: _api_version = -1 # Unspecified by compiler flags. - _proto_extension_modules_exist_in_build = False if _api_version == 1: raise ValueError('api_version=1 is no longer supported.') -if _api_version < 0: # Still unspecified? - try: - # The presence of this module in a build allows the proto implementation to - # be upgraded merely via build deps rather than a compiler flag or the - # runtime environment variable. - # pylint: disable=g-import-not-at-top - from google.protobuf import _use_fast_cpp_protos - # Work around a known issue in the classic bootstrap .par import hook. - if not _use_fast_cpp_protos: - 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...') - 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 - -_default_implementation_type = ('python' if _api_version <= 0 else 'cpp') + + +_default_implementation_type = ('cpp' if _api_version > 0 else 'python') + # This environment variable can be used to switch to a certain implementation # of the Python API, overriding the compile-time constants in the @@ -97,21 +66,6 @@ if 'PyPy' in sys.version and _implementation_type == 'cpp': 'Falling back to the python implementation.') _implementation_type = 'python' -# This environment variable can be used to switch between the two -# 'cpp' implementations, overriding the compile-time constants in the -# _api_implementation module. Right now only '2' is supported. Any other -# value will cause an error to be raised. -_implementation_version_str = os.getenv( - 'PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION', '2') - -if _implementation_version_str != '2': - raise ValueError( - 'unsupported PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION: "' + - _implementation_version_str + '" (supported versions: 2)' - ) - -_implementation_version = int(_implementation_version_str) - # Detect if serialization should be deterministic by default try: @@ -150,7 +104,7 @@ def _SetType(implementation_type): # See comment on 'Type' above. def Version(): - return _implementation_version + return 2 # For internal use only diff --git a/contrib/python/protobuf/py3/google/protobuf/internal/containers.py b/contrib/python/protobuf/py3/google/protobuf/internal/containers.py index 92793490bb..f0c06df8dd 100644 --- a/contrib/python/protobuf/py3/google/protobuf/internal/containers.py +++ b/contrib/python/protobuf/py3/google/protobuf/internal/containers.py @@ -42,149 +42,7 @@ are: __author__ = 'petar@google.com (Petar Petrov)' -import sys -try: - # This fallback applies for all versions of Python before 3.3 - import collections.abc as collections_abc -except ImportError: - import collections as collections_abc - -if sys.version_info[0] < 3: - # We would use collections_abc.MutableMapping all the time, but in Python 2 - # it doesn't define __slots__. This causes two significant problems: - # - # 1. we can't disallow arbitrary attribute assignment, even if our derived - # classes *do* define __slots__. - # - # 2. we can't safely derive a C type from it without __slots__ defined (the - # interpreter expects to find a dict at tp_dictoffset, which we can't - # robustly provide. And we don't want an instance dict anyway. - # - # So this is the Python 2.7 definition of Mapping/MutableMapping functions - # verbatim, except that: - # 1. We declare __slots__. - # 2. We don't declare this as a virtual base class. The classes defined - # in collections_abc are the interesting base classes, not us. - # - # Note: deriving from object is critical. It is the only thing that makes - # this a true type, allowing us to derive from it in C++ cleanly and making - # __slots__ properly disallow arbitrary element assignment. - - class Mapping(object): - __slots__ = () - - def get(self, key, default=None): - try: - return self[key] - except KeyError: - return default - - def __contains__(self, key): - try: - self[key] - except KeyError: - return False - else: - return True - - def iterkeys(self): - return iter(self) - - def itervalues(self): - for key in self: - yield self[key] - - def iteritems(self): - for key in self: - yield (key, self[key]) - - def keys(self): - return list(self) - - def items(self): - return [(key, self[key]) for key in self] - - def values(self): - return [self[key] for key in self] - - # Mappings are not hashable by default, but subclasses can change this - __hash__ = None - - def __eq__(self, other): - if not isinstance(other, collections_abc.Mapping): - return NotImplemented - return dict(self.items()) == dict(other.items()) - - def __ne__(self, other): - return not (self == other) - - class MutableMapping(Mapping): - __slots__ = () - - __marker = object() - - def pop(self, key, default=__marker): - try: - value = self[key] - except KeyError: - if default is self.__marker: - raise - return default - else: - del self[key] - return value - - def popitem(self): - try: - key = next(iter(self)) - except StopIteration: - raise KeyError - value = self[key] - del self[key] - return key, value - - def clear(self): - try: - while True: - self.popitem() - except KeyError: - pass - - def update(*args, **kwds): - if len(args) > 2: - raise TypeError("update() takes at most 2 positional " - "arguments ({} given)".format(len(args))) - elif not args: - raise TypeError("update() takes at least 1 argument (0 given)") - self = args[0] - other = args[1] if len(args) >= 2 else () - - if isinstance(other, Mapping): - for key in other: - self[key] = other[key] - elif hasattr(other, "keys"): - for key in other.keys(): - self[key] = other[key] - else: - for key, value in other: - self[key] = value - for key, value in kwds.items(): - self[key] = value - - def setdefault(self, key, default=None): - try: - return self[key] - except KeyError: - self[key] = default - return default - - collections_abc.Mapping.register(Mapping) - collections_abc.MutableMapping.register(MutableMapping) - -else: - # In Python 3 we can just use MutableMapping directly, because it defines - # __slots__. - MutableMapping = collections_abc.MutableMapping +import collections.abc class BaseContainer(object): @@ -235,7 +93,7 @@ class BaseContainer(object): self._values.reverse() -collections_abc.MutableSequence.register(BaseContainer) +collections.abc.MutableSequence.register(BaseContainer) class RepeatedScalarFieldContainer(BaseContainer): @@ -458,7 +316,7 @@ class RepeatedCompositeFieldContainer(BaseContainer): return self._values == other._values -class ScalarMap(MutableMapping): +class ScalarMap(collections.abc.MutableMapping): """Simple, type-checked, dict-like container for holding repeated scalars.""" @@ -548,7 +406,7 @@ class ScalarMap(MutableMapping): return self._entry_descriptor._concrete_class -class MessageMap(MutableMapping): +class MessageMap(collections.abc.MutableMapping): """Simple, type-checked, dict-like container for with submessage values.""" 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 8af0665abc..e7c059fde1 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 @@ -41,16 +41,10 @@ This files defines well known classes which need extra maintenance including: __author__ = 'jieluo@google.com (Jie Luo)' import calendar +import collections.abc from datetime import datetime from datetime import timedelta -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' @@ -806,7 +800,7 @@ class Struct(object): for key, value in dictionary.items(): _SetStructValue(self.fields[key], value) -collections_abc.MutableMapping.register(Struct) +collections.abc.MutableMapping.register(Struct) class ListValue(object): @@ -852,7 +846,7 @@ class ListValue(object): list_value.Clear() return list_value -collections_abc.MutableSequence.register(ListValue) +collections.abc.MutableSequence.register(ListValue) WKTBASES = { diff --git a/contrib/python/protobuf/py3/google/protobuf/message.py b/contrib/python/protobuf/py3/google/protobuf/message.py index 224d2fc491..ee46d0e4c9 100644 --- a/contrib/python/protobuf/py3/google/protobuf/message.py +++ b/contrib/python/protobuf/py3/google/protobuf/message.py @@ -359,6 +359,14 @@ class Message(object): """ raise NotImplementedError + @classmethod + def FromString(cls, s): + raise NotImplementedError + + @staticmethod + def RegisterExtension(extension_handle): + raise NotImplementedError + def _SetListener(self, message_listener): """Internal method used by the protocol message implementation. Clients should not call this directly. diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.cc index 4ffca06add..0712abc068 100644 --- a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.cc +++ b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor.cc @@ -49,22 +49,12 @@ #include <google/protobuf/pyext/scoped_pyobject_ptr.h> #include <google/protobuf/stubs/hash.h> -#if PY_MAJOR_VERSION >= 3 - #define PyString_FromStringAndSize PyUnicode_FromStringAndSize - #define PyString_Check PyUnicode_Check - #define PyString_InternFromString PyUnicode_InternFromString - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #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))) -#endif #if PY_VERSION_HEX < 0x030900B1 && !defined(PYPY_VERSION) static PyCodeObject* PyFrame_GetCode(PyFrameObject *frame) @@ -110,7 +100,7 @@ namespace python { std::unordered_map<const void*, PyObject*>* interned_descriptors; PyObject* PyString_FromCppString(const TProtoStringType& str) { - return PyString_FromStringAndSize(str.c_str(), str.size()); + return PyUnicode_FromStringAndSize(str.c_str(), str.size()); } // Check that the calling Python code is the global scope of a _pb2.py module. @@ -617,8 +607,8 @@ static PyObject* GetExtensionRanges(PyBaseDescriptor *self, void *closure) { for (int i = 0; i < descriptor->extension_range_count(); i++) { const Descriptor::ExtensionRange* range = descriptor->extension_range(i); - PyObject* start = PyInt_FromLong(range->start); - PyObject* end = PyInt_FromLong(range->end); + PyObject* start = PyLong_FromLong(range->start); + PyObject* end = PyLong_FromLong(range->end); PyList_SetItem(range_list, i, PyTuple_Pack(2, start, end)); } @@ -692,7 +682,7 @@ static PyObject* EnumValueName(PyBaseDescriptor *self, PyObject *args) { } static PyObject* GetSyntax(PyBaseDescriptor *self, void *closure) { - return PyString_InternFromString( + return PyUnicode_InternFromString( FileDescriptor::SyntaxName(_GetDescriptor(self)->file()->syntax())); } @@ -819,23 +809,23 @@ static PyObject* GetFile(PyBaseDescriptor *self, void *closure) { } static PyObject* GetType(PyBaseDescriptor *self, void *closure) { - return PyInt_FromLong(_GetDescriptor(self)->type()); + return PyLong_FromLong(_GetDescriptor(self)->type()); } static PyObject* GetCppType(PyBaseDescriptor *self, void *closure) { - return PyInt_FromLong(_GetDescriptor(self)->cpp_type()); + return PyLong_FromLong(_GetDescriptor(self)->cpp_type()); } static PyObject* GetLabel(PyBaseDescriptor *self, void *closure) { - return PyInt_FromLong(_GetDescriptor(self)->label()); + return PyLong_FromLong(_GetDescriptor(self)->label()); } static PyObject* GetNumber(PyBaseDescriptor *self, void *closure) { - return PyInt_FromLong(_GetDescriptor(self)->number()); + return PyLong_FromLong(_GetDescriptor(self)->number()); } static PyObject* GetIndex(PyBaseDescriptor *self, void *closure) { - return PyInt_FromLong(_GetDescriptor(self)->index()); + return PyLong_FromLong(_GetDescriptor(self)->index()); } static PyObject* GetID(PyBaseDescriptor *self, void *closure) { @@ -861,7 +851,7 @@ static PyObject* GetDefaultValue(PyBaseDescriptor *self, void *closure) { switch (_GetDescriptor(self)->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: { int32_t value = _GetDescriptor(self)->default_value_int32(); - result = PyInt_FromLong(value); + result = PyLong_FromLong(value); break; } case FieldDescriptor::CPPTYPE_INT64: { @@ -871,7 +861,7 @@ static PyObject* GetDefaultValue(PyBaseDescriptor *self, void *closure) { } case FieldDescriptor::CPPTYPE_UINT32: { uint32_t value = _GetDescriptor(self)->default_value_uint32(); - result = PyInt_FromSize_t(value); + result = PyLong_FromSsize_t(value); break; } case FieldDescriptor::CPPTYPE_UINT64: { @@ -902,7 +892,7 @@ static PyObject* GetDefaultValue(PyBaseDescriptor *self, void *closure) { case FieldDescriptor::CPPTYPE_ENUM: { const EnumValueDescriptor* value = _GetDescriptor(self)->default_value_enum(); - result = PyInt_FromLong(value->number()); + result = PyLong_FromLong(value->number()); break; } case FieldDescriptor::CPPTYPE_MESSAGE: { @@ -1274,11 +1264,11 @@ static PyObject* GetName(PyBaseDescriptor *self, void *closure) { } static PyObject* GetNumber(PyBaseDescriptor *self, void *closure) { - return PyInt_FromLong(_GetDescriptor(self)->number()); + return PyLong_FromLong(_GetDescriptor(self)->number()); } static PyObject* GetIndex(PyBaseDescriptor *self, void *closure) { - return PyInt_FromLong(_GetDescriptor(self)->index()); + return PyLong_FromLong(_GetDescriptor(self)->index()); } static PyObject* GetType(PyBaseDescriptor *self, void *closure) { @@ -1470,7 +1460,7 @@ static int SetSerializedOptions(PyFileDescriptor *self, PyObject *value, } static PyObject* GetSyntax(PyFileDescriptor *self, void *closure) { - return PyString_InternFromString( + return PyUnicode_InternFromString( FileDescriptor::SyntaxName(_GetDescriptor(self)->syntax())); } @@ -1602,7 +1592,7 @@ static PyObject* GetFullName(PyBaseDescriptor* self, void *closure) { } static PyObject* GetIndex(PyBaseDescriptor *self, void *closure) { - return PyInt_FromLong(_GetDescriptor(self)->index()); + return PyLong_FromLong(_GetDescriptor(self)->index()); } static PyObject* GetFields(PyBaseDescriptor* self, void *closure) { @@ -1728,7 +1718,7 @@ static PyObject* GetFile(PyBaseDescriptor *self, void *closure) { } static PyObject* GetIndex(PyBaseDescriptor *self, void *closure) { - return PyInt_FromLong(_GetDescriptor(self)->index()); + return PyLong_FromLong(_GetDescriptor(self)->index()); } static PyObject* GetMethods(PyBaseDescriptor* self, void *closure) { @@ -1851,7 +1841,7 @@ static PyObject* GetFullName(PyBaseDescriptor* self, void *closure) { } static PyObject* GetIndex(PyBaseDescriptor *self, void *closure) { - return PyInt_FromLong(_GetDescriptor(self)->index()); + return PyLong_FromLong(_GetDescriptor(self)->index()); } static PyObject* GetContainingService(PyBaseDescriptor *self, void *closure) { @@ -1942,7 +1932,7 @@ static bool AddEnumValues(PyTypeObject *type, const EnumDescriptor* enum_descriptor) { for (int i = 0; i < enum_descriptor->value_count(); ++i) { const EnumValueDescriptor* value = enum_descriptor->value(i); - ScopedPyObjectPtr obj(PyInt_FromLong(value->number())); + ScopedPyObjectPtr obj(PyLong_FromLong(value->number())); if (obj == NULL) { return false; } @@ -1955,7 +1945,7 @@ static bool AddEnumValues(PyTypeObject *type, } static bool AddIntConstant(PyTypeObject *type, const char* name, int value) { - ScopedPyObjectPtr obj(PyInt_FromLong(value)); + ScopedPyObjectPtr obj(PyLong_FromLong(value)); if (PyDict_SetItemString(type->tp_dict, name, obj.get()) < 0) { return false; } 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..fe85b2e351 100644 --- a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.cc +++ b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_containers.cc @@ -57,20 +57,12 @@ #include <google/protobuf/pyext/descriptor.h> #include <google/protobuf/pyext/scoped_pyobject_ptr.h> -#if PY_MAJOR_VERSION >= 3 - #define PyString_FromStringAndSize PyUnicode_FromStringAndSize - #define PyString_FromFormat PyUnicode_FromFormat - #define PyInt_FromLong PyLong_FromLong - #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))) -#endif namespace google { namespace protobuf { @@ -232,18 +224,18 @@ static PyObject* _NewKey_ByIndex(PyContainer* self, Py_ssize_t index) { case PyContainer::KIND_BYNAME: { const TProtoStringType& name(self->container_def->get_item_name_fn(item)); - return PyString_FromStringAndSize(name.c_str(), name.size()); + return PyUnicode_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()); + return PyUnicode_FromStringAndSize(name.c_str(), name.size()); } case PyContainer::KIND_BYNUMBER: { int value = self->container_def->get_item_number_fn(item); - return PyInt_FromLong(value); + return PyLong_FromLong(value); } default: PyErr_SetNone(PyExc_NotImplementedError); @@ -320,8 +312,8 @@ static PyObject* ContainerRepr(PyContainer* self) { kind = "mapping by number"; break; } - return PyString_FromFormat( - "<%s %s>", self->container_def->mapping_name, kind); + return PyUnicode_FromFormat("<%s %s>", self->container_def->mapping_name, + kind); } extern PyTypeObject DescriptorMapping_Type; @@ -678,7 +670,7 @@ static PyObject* Index(PyContainer* self, PyObject* item) { PyErr_SetNone(PyExc_ValueError); return NULL; } else { - return PyInt_FromLong(position); + return PyLong_FromLong(position); } } // Implements "list.__contains__()": is the object in the sequence. @@ -696,9 +688,9 @@ static int SeqContains(PyContainer* self, PyObject* item) { static PyObject* Count(PyContainer* self, PyObject* item) { int position = Find(self, item); if (position < 0) { - return PyInt_FromLong(0); + return PyLong_FromLong(0); } else { - return PyInt_FromLong(1); + return PyLong_FromLong(1); } } 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 1cd3d98eac..1ba01d55d8 100644 --- a/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.cc +++ b/contrib/python/protobuf/py3/google/protobuf/pyext/descriptor_pool.cc @@ -43,18 +43,12 @@ #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))) -#endif namespace google { namespace protobuf { 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..b36c723266 100644 --- a/contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.cc +++ b/contrib/python/protobuf/py3/google/protobuf/pyext/extension_dict.cc @@ -49,17 +49,12 @@ #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))) -#endif namespace google { namespace protobuf { diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/field.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/field.cc index 1afd4583b3..5eab3ef2bc 100644 --- a/contrib/python/protobuf/py3/google/protobuf/pyext/field.cc +++ b/contrib/python/protobuf/py3/google/protobuf/pyext/field.cc @@ -34,10 +34,6 @@ #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 { @@ -45,8 +41,8 @@ namespace python { namespace field { static PyObject* Repr(PyMessageFieldProperty* self) { - return PyString_FromFormat("<field property '%s'>", - self->field_descriptor->full_name().c_str()); + return PyUnicode_FromFormat("<field property '%s'>", + self->field_descriptor->full_name().c_str()); } static PyObject* DescrGet(PyMessageFieldProperty* self, PyObject* obj, @@ -74,8 +70,8 @@ static PyObject* GetDescriptor(PyMessageFieldProperty* self, void* closure) { } static PyObject* GetDoc(PyMessageFieldProperty* self, void* closure) { - return PyString_FromFormat("Field %s", - self->field_descriptor->full_name().c_str()); + return PyUnicode_FromFormat("Field %s", + self->field_descriptor->full_name().c_str()); } static PyGetSetDef Getters[] = { 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 58760e0b01..94a5e2dad9 100644 --- a/contrib/python/protobuf/py3/google/protobuf/pyext/map_container.cc +++ b/contrib/python/protobuf/py3/google/protobuf/pyext/map_container.cc @@ -46,11 +46,6 @@ #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 - #define PyInt_FromSize_t PyLong_FromSize_t -#endif - namespace google { namespace protobuf { namespace python { @@ -177,11 +172,11 @@ static PyObject* MapKeyToPython(MapContainer* self, const MapKey& key) { self->parent_field_descriptor->message_type()->map_key(); switch (field_descriptor->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: - return PyInt_FromLong(key.GetInt32Value()); + return PyLong_FromLong(key.GetInt32Value()); case FieldDescriptor::CPPTYPE_INT64: return PyLong_FromLongLong(key.GetInt64Value()); case FieldDescriptor::CPPTYPE_UINT32: - return PyInt_FromSize_t(key.GetUInt32Value()); + return PyLong_FromSize_t(key.GetUInt32Value()); case FieldDescriptor::CPPTYPE_UINT64: return PyLong_FromUnsignedLongLong(key.GetUInt64Value()); case FieldDescriptor::CPPTYPE_BOOL: @@ -203,11 +198,11 @@ PyObject* MapValueRefToPython(MapContainer* self, const MapValueRef& value) { self->parent_field_descriptor->message_type()->map_value(); switch (field_descriptor->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: - return PyInt_FromLong(value.GetInt32Value()); + return PyLong_FromLong(value.GetInt32Value()); case FieldDescriptor::CPPTYPE_INT64: return PyLong_FromLongLong(value.GetInt64Value()); case FieldDescriptor::CPPTYPE_UINT32: - return PyInt_FromSize_t(value.GetUInt32Value()); + return PyLong_FromSize_t(value.GetUInt32Value()); case FieldDescriptor::CPPTYPE_UINT64: return PyLong_FromUnsignedLongLong(value.GetUInt64Value()); case FieldDescriptor::CPPTYPE_FLOAT: @@ -219,7 +214,7 @@ PyObject* MapValueRefToPython(MapContainer* self, const MapValueRef& value) { case FieldDescriptor::CPPTYPE_STRING: return ToStringObject(field_descriptor, value.GetStringValue()); case FieldDescriptor::CPPTYPE_ENUM: - return PyInt_FromLong(value.GetEnumValue()); + return PyLong_FromLong(value.GetEnumValue()); default: PyErr_Format( PyExc_SystemError, "Couldn't convert type %d to value", @@ -553,73 +548,21 @@ static PyMethodDef ScalarMapMethods[] = { {NULL, NULL}, }; -PyTypeObject *ScalarMapContainer_Type; -#if PY_MAJOR_VERSION >= 3 - static PyType_Slot ScalarMapContainer_Type_slots[] = { - {Py_tp_dealloc, (void *)ScalarMapDealloc}, - {Py_mp_length, (void *)MapReflectionFriend::Length}, - {Py_mp_subscript, (void *)MapReflectionFriend::ScalarMapGetItem}, - {Py_mp_ass_subscript, (void *)MapReflectionFriend::ScalarMapSetItem}, - {Py_tp_methods, (void *)ScalarMapMethods}, - {Py_tp_iter, (void *)MapReflectionFriend::GetIterator}, - {Py_tp_repr, (void *)MapReflectionFriend::ScalarMapToStr}, - {0, 0}, - }; - - PyType_Spec ScalarMapContainer_Type_spec = { - FULL_MODULE_NAME ".ScalarMapContainer", - sizeof(MapContainer), - 0, - Py_TPFLAGS_DEFAULT, - ScalarMapContainer_Type_slots - }; -#else - static PyMappingMethods ScalarMapMappingMethods = { - MapReflectionFriend::Length, // mp_length - MapReflectionFriend::ScalarMapGetItem, // mp_subscript - MapReflectionFriend::ScalarMapSetItem, // mp_ass_subscript - }; - - PyTypeObject _ScalarMapContainer_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - FULL_MODULE_NAME ".ScalarMapContainer", // tp_name - sizeof(MapContainer), // tp_basicsize - 0, // tp_itemsize - ScalarMapDealloc, // tp_dealloc - 0, // tp_print - 0, // tp_getattr - 0, // tp_setattr - 0, // tp_compare - MapReflectionFriend::ScalarMapToStr, // tp_repr - 0, // tp_as_number - 0, // tp_as_sequence - &ScalarMapMappingMethods, // 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 container", // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - MapReflectionFriend::GetIterator, // tp_iter - 0, // tp_iternext - ScalarMapMethods, // 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 - }; -#endif +PyTypeObject* ScalarMapContainer_Type; +static PyType_Slot ScalarMapContainer_Type_slots[] = { + {Py_tp_dealloc, (void*)ScalarMapDealloc}, + {Py_mp_length, (void*)MapReflectionFriend::Length}, + {Py_mp_subscript, (void*)MapReflectionFriend::ScalarMapGetItem}, + {Py_mp_ass_subscript, (void*)MapReflectionFriend::ScalarMapSetItem}, + {Py_tp_methods, (void*)ScalarMapMethods}, + {Py_tp_iter, (void*)MapReflectionFriend::GetIterator}, + {Py_tp_repr, (void*)MapReflectionFriend::ScalarMapToStr}, + {0, 0}, +}; +PyType_Spec ScalarMapContainer_Type_spec = { + FULL_MODULE_NAME ".ScalarMapContainer", sizeof(MapContainer), 0, + Py_TPFLAGS_DEFAULT, ScalarMapContainer_Type_slots}; // MessageMap ////////////////////////////////////////////////////////////////// @@ -825,72 +768,20 @@ static PyMethodDef MessageMapMethods[] = { {NULL, NULL}, }; -PyTypeObject *MessageMapContainer_Type; -#if PY_MAJOR_VERSION >= 3 - static PyType_Slot MessageMapContainer_Type_slots[] = { - {Py_tp_dealloc, (void *)MessageMapDealloc}, - {Py_mp_length, (void *)MapReflectionFriend::Length}, - {Py_mp_subscript, (void *)MapReflectionFriend::MessageMapGetItem}, - {Py_mp_ass_subscript, (void *)MapReflectionFriend::MessageMapSetItem}, - {Py_tp_methods, (void *)MessageMapMethods}, - {Py_tp_iter, (void *)MapReflectionFriend::GetIterator}, - {Py_tp_repr, (void *)MapReflectionFriend::MessageMapToStr}, - {0, 0} - }; - - PyType_Spec MessageMapContainer_Type_spec = { - FULL_MODULE_NAME ".MessageMapContainer", - sizeof(MessageMapContainer), - 0, - Py_TPFLAGS_DEFAULT, - MessageMapContainer_Type_slots - }; -#else - static PyMappingMethods MessageMapMappingMethods = { - MapReflectionFriend::Length, // mp_length - MapReflectionFriend::MessageMapGetItem, // mp_subscript - MapReflectionFriend::MessageMapSetItem, // mp_ass_subscript - }; - - PyTypeObject _MessageMapContainer_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - FULL_MODULE_NAME ".MessageMapContainer", // tp_name - sizeof(MessageMapContainer), // tp_basicsize - 0, // tp_itemsize - MessageMapDealloc, // tp_dealloc - 0, // tp_print - 0, // tp_getattr - 0, // tp_setattr - 0, // tp_compare - MapReflectionFriend::MessageMapToStr, // tp_repr - 0, // tp_as_number - 0, // tp_as_sequence - &MessageMapMappingMethods, // 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 map container for message", // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - MapReflectionFriend::GetIterator, // tp_iter - 0, // tp_iternext - MessageMapMethods, // 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 - }; -#endif +PyTypeObject* MessageMapContainer_Type; +static PyType_Slot MessageMapContainer_Type_slots[] = { + {Py_tp_dealloc, (void*)MessageMapDealloc}, + {Py_mp_length, (void*)MapReflectionFriend::Length}, + {Py_mp_subscript, (void*)MapReflectionFriend::MessageMapGetItem}, + {Py_mp_ass_subscript, (void*)MapReflectionFriend::MessageMapSetItem}, + {Py_tp_methods, (void*)MessageMapMethods}, + {Py_tp_iter, (void*)MapReflectionFriend::GetIterator}, + {Py_tp_repr, (void*)MapReflectionFriend::MessageMapToStr}, + {0, 0}}; + +PyType_Spec MessageMapContainer_Type_spec = { + FULL_MODULE_NAME ".MessageMapContainer", sizeof(MessageMapContainer), 0, + Py_TPFLAGS_DEFAULT, MessageMapContainer_Type_slots}; // MapIterator ///////////////////////////////////////////////////////////////// @@ -1007,20 +898,18 @@ PyTypeObject MapIterator_Type = { bool InitMapContainers() { // ScalarMapContainer_Type derives from our MutableMapping type. - ScopedPyObjectPtr containers(PyImport_ImportModule( - "google.protobuf.internal.containers")); - if (containers == NULL) { + ScopedPyObjectPtr abc(PyImport_ImportModule("collections.abc")); + if (abc == NULL) { return false; } ScopedPyObjectPtr mutable_mapping( - PyObject_GetAttrString(containers.get(), "MutableMapping")); + PyObject_GetAttrString(abc.get(), "MutableMapping")); if (mutable_mapping == NULL) { return false; } Py_INCREF(mutable_mapping.get()); -#if PY_MAJOR_VERSION >= 3 ScopedPyObjectPtr bases(PyTuple_Pack(1, mutable_mapping.get())); if (bases == NULL) { return false; @@ -1028,35 +917,13 @@ bool InitMapContainers() { ScalarMapContainer_Type = reinterpret_cast<PyTypeObject*>( PyType_FromSpecWithBases(&ScalarMapContainer_Type_spec, bases.get())); -#else - _ScalarMapContainer_Type.tp_base = - reinterpret_cast<PyTypeObject*>(mutable_mapping.get()); - - if (PyType_Ready(&_ScalarMapContainer_Type) < 0) { - return false; - } - - ScalarMapContainer_Type = &_ScalarMapContainer_Type; -#endif if (PyType_Ready(&MapIterator_Type) < 0) { return false; } -#if PY_MAJOR_VERSION >= 3 MessageMapContainer_Type = reinterpret_cast<PyTypeObject*>( PyType_FromSpecWithBases(&MessageMapContainer_Type_spec, bases.get())); -#else - Py_INCREF(mutable_mapping.get()); - _MessageMapContainer_Type.tp_base = - reinterpret_cast<PyTypeObject*>(mutable_mapping.get()); - - if (PyType_Ready(&_MessageMapContainer_Type) < 0) { - return false; - } - - MessageMapContainer_Type = &_MessageMapContainer_Type; -#endif return true; } diff --git a/contrib/python/protobuf/py3/google/protobuf/pyext/message.cc b/contrib/python/protobuf/py3/google/protobuf/pyext/message.cc index 291af9e817..3254be8a21 100644 --- a/contrib/python/protobuf/py3/google/protobuf/pyext/message.cc +++ b/contrib/python/protobuf/py3/google/protobuf/pyext/message.cc @@ -77,27 +77,14 @@ #include <google/protobuf/port_def.inc> // clang-format on -#if PY_MAJOR_VERSION >= 3 - #define PyInt_AsLong PyLong_AsLong - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #define PyString_Check PyUnicode_Check - #define PyString_FromString PyUnicode_FromString - #define PyString_FromStringAndSize PyUnicode_FromStringAndSize - #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_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 -#endif namespace google { namespace protobuf { @@ -110,9 +97,10 @@ class MessageReflectionFriend { const std::vector<const FieldDescriptor*>& fields) { lhs->GetReflection()->UnsafeShallowSwapFields(lhs, rhs, fields); } - static bool IsLazyField(const Reflection* reflection, + static bool IsLazyField(const Reflection* reflection, const Message& message, const FieldDescriptor* field) { - return reflection->IsLazyField(field); + return reflection->IsLazyField(field) || + reflection->IsLazyExtension(message, field); } }; @@ -124,8 +112,6 @@ static PyObject* WKT_classes = NULL; namespace message_meta { -static int InsertEmptyWeakref(PyTypeObject* base); - namespace { // Copied over from internal 'google/protobuf/stubs/strutil.h'. inline void LowerString(TProtoStringType* s) { @@ -171,8 +157,8 @@ static int AddDescriptors(PyObject* cls, const Descriptor* descriptor) { for (int j = 0; j < enum_descriptor->value_count(); ++j) { const EnumValueDescriptor* enum_value_descriptor = enum_descriptor->value(j); - ScopedPyObjectPtr value_number(PyInt_FromLong( - enum_value_descriptor->number())); + ScopedPyObjectPtr value_number( + PyLong_FromLong(enum_value_descriptor->number())); if (value_number == NULL) { return -1; } @@ -282,13 +268,6 @@ static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) { } CMessageClass* newtype = reinterpret_cast<CMessageClass*>(result.get()); - // Insert the empty weakref into the base classes. - if (InsertEmptyWeakref( - reinterpret_cast<PyTypeObject*>(PythonMessage_class)) < 0 || - InsertEmptyWeakref(CMessage_Type) < 0) { - return NULL; - } - // Cache the descriptor, both as Python object and as C++ pointer. const Descriptor* descriptor = PyMessageDescriptor_AsDescriptor(py_descriptor); @@ -343,32 +322,6 @@ static int GcClear(PyObject* pself) { 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. -// -// This eliminates a O(n^2) behaviour in the internal add_subclass -// routine. -static int InsertEmptyWeakref(PyTypeObject *base_type) { -#if PY_MAJOR_VERSION >= 3 - // Python 3.4 has already included the fix for the issue that this - // hack addresses. For further background and the fix please see - // 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 - PyObject *subclasses = base_type->tp_subclasses; - if (subclasses && PyList_CheckExact(subclasses)) { - return PyList_Append(subclasses, kEmptyWeakref); - } -#endif // !Py_DEBUG - return 0; -#endif // PY_MAJOR_VERSION >= 3 -} - // 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) { @@ -421,7 +374,7 @@ static PyObject* GetExtensionsByNumber(CMessageClass *self, void *closure) { if (extension == NULL) { return NULL; } - ScopedPyObjectPtr number(PyInt_FromLong(extensions[i]->number())); + ScopedPyObjectPtr number(PyLong_FromLong(extensions[i]->number())); if (number == NULL) { return NULL; } @@ -459,7 +412,7 @@ static PyObject* GetClassAttribute(CMessageClass *self, PyObject* name) { self->message_descriptor->FindExtensionByLowercaseName(field_name); } if (field) { - return PyInt_FromLong(field->number()); + return PyLong_FromLong(field->number()); } } PyErr_SetObject(PyExc_AttributeError, name); @@ -612,20 +565,6 @@ bool VerifyIntegerCastAndRange(PyObject* arg, ValueType value) { 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))) { - *value = static_cast<T>(int_result); - return true; - } else { - OutOfRangeError(arg); - return false; - } - } -#endif // This effectively defines an integer as "an object that can be cast as // an integer and can be used as an ordinal number". // This definition includes everything that implements numbers.Integral @@ -715,7 +654,7 @@ bool CheckAndGetFloat(PyObject* arg, float* value) { } bool CheckAndGetBool(PyObject* arg, bool* value) { - long long_value = PyInt_AsLong(arg); + long long_value = PyLong_AsLong(arg); // NOLINT if (long_value == -1 && PyErr_Occurred()) { FormatTypeError(arg, "int, long, bool"); return false; @@ -972,7 +911,7 @@ const FieldDescriptor* GetExtensionDescriptor(PyObject* extension) { // descriptor, otherwise simply return value. Always returns a new reference. static PyObject* GetIntegerEnumValue(const FieldDescriptor& descriptor, PyObject* value) { - if (PyString_Check(value) || PyUnicode_Check(value)) { + if (PyUnicode_Check(value)) { const EnumDescriptor* enum_descriptor = descriptor.enum_type(); if (enum_descriptor == NULL) { PyErr_SetString(PyExc_TypeError, "not an enum field"); @@ -989,7 +928,7 @@ static PyObject* GetIntegerEnumValue(const FieldDescriptor& descriptor, PyErr_Format(PyExc_ValueError, "unknown enum label \"%s\"", enum_label); return NULL; } - return PyInt_FromLong(enum_value_descriptor->number()); + return PyLong_FromLong(enum_value_descriptor->number()); } Py_INCREF(value); return value; @@ -1011,15 +950,7 @@ int DeleteRepeatedField( if (PySlice_Check(slice)) { from = to = step = slice_length = 0; -#if PY_MAJOR_VERSION < 3 - PySlice_GetIndicesEx( - reinterpret_cast<PySliceObject*>(slice), - length, &from, &to, &step, &slice_length); -#else - PySlice_GetIndicesEx( - slice, - length, &from, &to, &step, &slice_length); -#endif + PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slice_length); if (from < to) { min = from; max = to - 1; @@ -1116,7 +1047,7 @@ 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 (!(PyUnicode_Check(name))) { PyErr_SetString(PyExc_ValueError, "Field name must be a string"); return -1; } @@ -1391,7 +1322,7 @@ PyObject* IsInitialized(CMessage* self, PyObject* args) { if (initialization_errors == NULL) { return NULL; } - ScopedPyObjectPtr extend_name(PyString_FromString("extend")); + ScopedPyObjectPtr extend_name(PyUnicode_FromString("extend")); if (extend_name == NULL) { return NULL; } @@ -1464,16 +1395,10 @@ bool CheckHasPresence(const FieldDescriptor* field_descriptor, bool in_oneof) { PyObject* HasField(CMessage* self, PyObject* arg) { char* field_name; Py_ssize_t size; -#if PY_MAJOR_VERSION < 3 - if (PyString_AsStringAndSize(arg, &field_name, &size) < 0) { - return NULL; - } -#else field_name = const_cast<char*>(PyUnicode_AsUTF8AndSize(arg, &size)); if (!field_name) { return NULL; } -#endif Message* message = self->message; bool is_in_oneof; @@ -1741,7 +1666,7 @@ static PyObject* InternalSerializeToString( if (errors == NULL) { return NULL; } - ScopedPyObjectPtr comma(PyString_FromString(",")); + ScopedPyObjectPtr comma(PyUnicode_FromString(",")); if (comma == NULL) { return NULL; } @@ -1867,7 +1792,7 @@ static PyObject* ToStr(CMessage* self) { PyErr_SetString(PyExc_ValueError, "Unable to convert message to str"); return NULL; } - return PyString_FromString(output.c_str()); + return PyUnicode_FromString(output.c_str()); } PyObject* MergeFrom(CMessage* self, PyObject* arg) { @@ -1990,7 +1915,9 @@ static PyObject* MergeFromString(CMessage* self, PyObject* arg) { // 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"); + PyErr_Format( + DecodeError_class, "Error parsing message with type '%s'", + self->GetMessageClass()->message_descriptor->full_name().c_str()); return NULL; } // ctx has an explicit limit set (length of string_view), so we have to @@ -1999,7 +1926,7 @@ static PyObject* MergeFromString(CMessage* self, PyObject* arg) { PyErr_Format(DecodeError_class, "Unexpected end-group tag: Not all data was converted"); return nullptr; } - return PyInt_FromLong(data.len); + return PyLong_FromLong(data.len); } static PyObject* ParseFromString(CMessage* self, PyObject* arg) { @@ -2064,7 +1991,7 @@ static PyObject* WhichOneof(CMessage* self, PyObject* arg) { Py_RETURN_NONE; } else { const TProtoStringType& name = field_in_oneof->name(); - return PyString_FromStringAndSize(name.c_str(), name.size()); + return PyUnicode_FromStringAndSize(name.c_str(), name.size()); } } @@ -2164,8 +2091,8 @@ PyObject* FindInitializationErrors(CMessage* self) { } for (size_t i = 0; i < errors.size(); ++i) { const TProtoStringType& error = errors[i]; - PyObject* error_string = PyString_FromStringAndSize( - error.c_str(), error.length()); + PyObject* error_string = + PyUnicode_FromStringAndSize(error.c_str(), error.length()); if (error_string == NULL) { Py_DECREF(error_list); return NULL; @@ -2221,7 +2148,7 @@ PyObject* InternalGetScalar(const Message* message, switch (field_descriptor->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: { int32_t value = reflection->GetInt32(*message, field_descriptor); - result = PyInt_FromLong(value); + result = PyLong_FromLong(value); break; } case FieldDescriptor::CPPTYPE_INT64: { @@ -2231,7 +2158,7 @@ PyObject* InternalGetScalar(const Message* message, } case FieldDescriptor::CPPTYPE_UINT32: { uint32_t value = reflection->GetUInt32(*message, field_descriptor); - result = PyInt_FromSize_t(value); + result = PyLong_FromSsize_t(value); break; } case FieldDescriptor::CPPTYPE_UINT64: { @@ -2264,7 +2191,7 @@ PyObject* InternalGetScalar(const Message* message, case FieldDescriptor::CPPTYPE_ENUM: { const EnumValueDescriptor* enum_value = message->GetReflection()->GetEnum(*message, field_descriptor); - result = PyInt_FromLong(enum_value->number()); + result = PyLong_FromLong(enum_value->number()); break; } default: @@ -2299,7 +2226,8 @@ CMessage* InternalGetSubMessage( cmsg->parent_field_descriptor = field_descriptor; if (reflection->HasField(*self->message, field_descriptor)) { // Force triggering MutableMessage to set the lazy message 'Dirty' - if (MessageReflectionFriend::IsLazyField(reflection, field_descriptor)) { + if (MessageReflectionFriend::IsLazyField(reflection, *self->message, + field_descriptor)) { Message* sub_message = reflection->MutableMessage( self->message, field_descriptor, factory->message_factory); cmsg->read_only = false; @@ -2453,7 +2381,7 @@ PyObject* ToUnicode(CMessage* self) { if (text_format == NULL) { return NULL; } - ScopedPyObjectPtr method_name(PyString_FromString("MessageToString")); + ScopedPyObjectPtr method_name(PyUnicode_FromString("MessageToString")); if (method_name == NULL) { return NULL; } @@ -2464,11 +2392,7 @@ PyObject* ToUnicode(CMessage* self) { if (encoded == NULL) { return NULL; } -#if PY_MAJOR_VERSION < 3 - PyObject* decoded = PyString_AsDecodedObject(encoded.get(), "utf-8", NULL); -#else PyObject* decoded = PyUnicode_FromEncodedObject(encoded.get(), "utf-8", NULL); -#endif if (decoded == NULL) { return NULL; } @@ -2958,7 +2882,7 @@ 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 // also be freed and reset to NULL during finalization. - kDESCRIPTOR = PyString_FromString("DESCRIPTOR"); + kDESCRIPTOR = PyUnicode_FromString("DESCRIPTOR"); PyObject *dummy_obj = PySet_New(NULL); kEmptyWeakref = PyWeakref_NewRef(dummy_obj, NULL); @@ -3027,11 +2951,7 @@ bool InitProto2MessageModule(PyObject *m) { reinterpret_cast<PyObject*>(&RepeatedCompositeContainer_Type)); // Register them as MutableSequence. -#if PY_MAJOR_VERSION >= 3 ScopedPyObjectPtr collections(PyImport_ImportModule("collections.abc")); -#else - ScopedPyObjectPtr collections(PyImport_ImportModule("collections")); -#endif if (collections == NULL) { return false; } 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 8915071f87..5483c56061 100644 --- a/contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.cc +++ b/contrib/python/protobuf/py3/google/protobuf/pyext/message_factory.cc @@ -38,17 +38,12 @@ #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*>( \ +#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 + : PyBytes_AsStringAndSize(ob, (charpp), (sizep))) namespace google { namespace protobuf { 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 4125dd73a1..971d2bad70 100644 --- a/contrib/python/protobuf/py3/google/protobuf/pyext/message_module.cc +++ b/contrib/python/protobuf/py3/google/protobuf/pyext/message_module.cc @@ -95,7 +95,6 @@ static PyMethodDef ModuleMethods[] = { // 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, @@ -105,27 +104,17 @@ static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT, NULL, NULL, NULL}; -#define INITFUNC PyInit__message -#define INITFUNC_ERRORVAL NULL -#else // Python 2 -#define INITFUNC init_message -#define INITFUNC_ERRORVAL -#endif -PyMODINIT_FUNC INITFUNC() { +PyMODINIT_FUNC PyInit__message() { PyObject* m; -#if PY_MAJOR_VERSION >= 3 m = PyModule_Create(&_module); -#else - m = Py_InitModule3("_message", ModuleMethods, module_docstring); -#endif if (m == NULL) { - return INITFUNC_ERRORVAL; + return NULL; } if (!google::protobuf::python::InitProto2MessageModule(m)) { Py_DECREF(m); - return INITFUNC_ERRORVAL; + return NULL; } // Adds the C++ API @@ -137,10 +126,8 @@ PyMODINIT_FUNC INITFUNC() { })) { PyModule_AddObject(m, "proto_API", api); } else { - return INITFUNC_ERRORVAL; + return NULL; } -#if PY_MAJOR_VERSION >= 3 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..2e8ff4b425 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 @@ -48,12 +48,6 @@ #include <google/protobuf/reflection.h> #include <google/protobuf/stubs/map_util.h> -#if PY_MAJOR_VERSION >= 3 - #define PyInt_Check PyLong_Check - #define PyInt_AsLong PyLong_AsLong - #define PyInt_FromLong PyLong_FromLong -#endif - namespace google { namespace protobuf { namespace python { @@ -246,13 +240,8 @@ PyObject* Subscript(RepeatedCompositeContainer* self, PyObject* 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) { -#else - if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(item), - length, &from, &to, &step, &slicelength) == -1) { -#endif + if (PySlice_GetIndicesEx(item, length, &from, &to, &step, &slicelength) == + -1) { return nullptr; } 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..c7ebcbbf00 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 @@ -46,15 +46,8 @@ #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 -#endif namespace google { namespace protobuf { @@ -210,7 +203,7 @@ static PyObject* Item(PyObject* pself, Py_ssize_t index) { case FieldDescriptor::CPPTYPE_INT32: { int32_t value = reflection->GetRepeatedInt32(*message, field_descriptor, index); - result = PyInt_FromLong(value); + result = PyLong_FromLong(value); break; } case FieldDescriptor::CPPTYPE_INT64: { @@ -253,7 +246,7 @@ static PyObject* Item(PyObject* pself, Py_ssize_t index) { const EnumValueDescriptor* enum_value = message->GetReflection()->GetRepeatedEnum(*message, field_descriptor, index); - result = PyInt_FromLong(enum_value->number()); + result = PyLong_FromLong(enum_value->number()); break; } case FieldDescriptor::CPPTYPE_STRING: { @@ -279,22 +272,12 @@ static PyObject* Subscript(PyObject* pself, PyObject* slice) { Py_ssize_t length; Py_ssize_t slicelength; bool return_list = false; -#if PY_MAJOR_VERSION < 3 - if (PyInt_Check(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); -#if PY_MAJOR_VERSION >= 3 if (PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slicelength) == -1) { -#else - if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), length, - &from, &to, &step, &slicelength) == -1) { -#endif return nullptr; } return_list = true; @@ -436,23 +419,13 @@ static int AssSubscript(PyObject* pself, PyObject* slice, PyObject* value) { 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 -#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) { -#else - if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(slice), length, - &from, &to, &step, &slicelength) == -1) { -#endif return -1; } create_list = true; 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..7f4fb23edf 100644 --- a/contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.cc +++ b/contrib/python/protobuf/py3/google/protobuf/pyext/unknown_fields.cc @@ -40,10 +40,6 @@ #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 { @@ -237,7 +233,7 @@ static PyObject* GetFieldNumber(PyUnknownFieldRef* self, void *closure) { if (unknown_field == NULL) { return NULL; } - return PyInt_FromLong(unknown_field->number()); + return PyLong_FromLong(unknown_field->number()); } using internal::WireFormatLite; @@ -267,7 +263,7 @@ static PyObject* GetWireType(PyUnknownFieldRef* self, void *closure) { wire_type = WireFormatLite::WIRETYPE_START_GROUP; break; } - return PyInt_FromLong(wire_type); + return PyLong_FromLong(wire_type); } static PyObject* GetData(PyUnknownFieldRef* self, void *closure) { @@ -278,13 +274,13 @@ static PyObject* GetData(PyUnknownFieldRef* self, void *closure) { PyObject* data = NULL; switch (field->type()) { case UnknownField::TYPE_VARINT: - data = PyInt_FromLong(field->varint()); + data = PyLong_FromLong(field->varint()); break; case UnknownField::TYPE_FIXED32: - data = PyInt_FromLong(field->fixed32()); + data = PyLong_FromLong(field->fixed32()); break; case UnknownField::TYPE_FIXED64: - data = PyInt_FromLong(field->fixed64()); + data = PyLong_FromLong(field->fixed64()); break; case UnknownField::TYPE_LENGTH_DELIMITED: data = PyBytes_FromStringAndSize(field->length_delimited().data(), diff --git a/contrib/python/protobuf/py3/ya.make b/contrib/python/protobuf/py3/ya.make index 18b4d2a00a..7850737cdc 100644 --- a/contrib/python/protobuf/py3/ya.make +++ b/contrib/python/protobuf/py3/ya.make @@ -9,9 +9,9 @@ LICENSE( LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -VERSION(3.18.1) +VERSION(3.19.0) -ORIGINAL_SOURCE(mirror://pypi/p/protobuf/protobuf-3.18.1.tar.gz) +ORIGINAL_SOURCE(mirror://pypi/p/protobuf/protobuf-3.19.0.tar.gz) PEERDIR( contrib/libs/protobuf |