Add DescriptorPool-level opt-out for new JSON field name handling.

PiperOrigin-RevId: 502959921
pull/11557/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 978e989998
commit 3aaaf7d7ce
  1. 12
      python/google/protobuf/descriptor_pool.py
  2. 17
      python/google/protobuf/pyext/descriptor_pool.cc

@ -120,11 +120,13 @@ class DescriptorPool(object):
if _USE_C_DESCRIPTORS: if _USE_C_DESCRIPTORS:
def __new__(cls, descriptor_db=None): def __new__(cls, descriptor_db=None):
# pylint: disable=protected-access # pylint: disable=protected-access
return descriptor._message.DescriptorPool(descriptor_db) return descriptor._message.DescriptorPool(descriptor_db)
def __init__(self, descriptor_db=None): def __init__(
self, descriptor_db=None, use_deprecated_legacy_json_field_conflicts=False
):
"""Initializes a Pool of proto buffs. """Initializes a Pool of proto buffs.
The descriptor_db argument to the constructor is provided to allow The descriptor_db argument to the constructor is provided to allow
@ -135,6 +137,8 @@ class DescriptorPool(object):
Args: Args:
descriptor_db: A secondary source of file descriptors. descriptor_db: A secondary source of file descriptors.
use_deprecated_legacy_json_field_conflicts: Unused, for compatibility with
C++.
""" """
self._internal_db = descriptor_database.DescriptorDatabase() self._internal_db = descriptor_database.DescriptorDatabase()

@ -155,20 +155,26 @@ static PyDescriptorPool* PyDescriptorPool_NewWithUnderlay(
} }
static PyDescriptorPool* PyDescriptorPool_NewWithDatabase( static PyDescriptorPool* PyDescriptorPool_NewWithDatabase(
DescriptorDatabase* database) { DescriptorDatabase* database,
bool use_deprecated_legacy_json_field_conflicts) {
PyDescriptorPool* cpool = _CreateDescriptorPool(); PyDescriptorPool* cpool = _CreateDescriptorPool();
if (cpool == nullptr) { if (cpool == nullptr) {
return nullptr; return nullptr;
} }
DescriptorPool* pool;
if (database != nullptr) { if (database != nullptr) {
cpool->error_collector = new BuildFileErrorCollector(); cpool->error_collector = new BuildFileErrorCollector();
cpool->pool = new DescriptorPool(database, cpool->error_collector); pool = new DescriptorPool(database, cpool->error_collector);
cpool->is_mutable = false; cpool->is_mutable = false;
cpool->database = database; cpool->database = database;
} else { } else {
cpool->pool = new DescriptorPool(); pool = new DescriptorPool();
cpool->is_mutable = true; cpool->is_mutable = true;
} }
if (use_deprecated_legacy_json_field_conflicts) {
pool->UseDeprecatedLegacyJsonFieldConflicts();
}
cpool->pool = pool;
cpool->is_owned = true; cpool->is_owned = true;
if (!descriptor_pool_map->insert(std::make_pair(cpool->pool, cpool)).second) { if (!descriptor_pool_map->insert(std::make_pair(cpool->pool, cpool)).second) {
@ -183,6 +189,7 @@ static PyDescriptorPool* PyDescriptorPool_NewWithDatabase(
// The public DescriptorPool constructor. // The public DescriptorPool constructor.
static PyObject* New(PyTypeObject* type, static PyObject* New(PyTypeObject* type,
PyObject* args, PyObject* kwargs) { PyObject* args, PyObject* kwargs) {
int use_deprecated_legacy_json_field_conflicts = 0;
static const char* kwlist[] = {"descriptor_db", nullptr}; static const char* kwlist[] = {"descriptor_db", nullptr};
PyObject* py_database = nullptr; PyObject* py_database = nullptr;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O",
@ -193,8 +200,8 @@ static PyObject* New(PyTypeObject* type,
if (py_database && py_database != Py_None) { if (py_database && py_database != Py_None) {
database = new PyDescriptorDatabase(py_database); database = new PyDescriptorDatabase(py_database);
} }
return reinterpret_cast<PyObject*>( return reinterpret_cast<PyObject*>(PyDescriptorPool_NewWithDatabase(
PyDescriptorPool_NewWithDatabase(database)); database, use_deprecated_legacy_json_field_conflicts));
} }
static void Dealloc(PyObject* pself) { static void Dealloc(PyObject* pself) {

Loading…
Cancel
Save