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:
def __new__(cls, descriptor_db=None):
# pylint: disable=protected-access
return descriptor._message.DescriptorPool(descriptor_db)
def __new__(cls, descriptor_db=None):
# pylint: disable=protected-access
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.
The descriptor_db argument to the constructor is provided to allow
@ -135,6 +137,8 @@ class DescriptorPool(object):
Args:
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()

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

Loading…
Cancel
Save