aboutsummaryrefslogtreecommitdiffhomepage
path: root/python/google/protobuf/symbol_database.py
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2015-10-05 11:59:43 -0700
committerGravatar Jisi Liu <jisi.liu@gmail.com>2015-10-05 11:59:43 -0700
commit46e8ff63cb67a6520711da5317aaaef04d0414d0 (patch)
tree64370726fe469f8dfca7b14f8b8cb80b6cc856f6 /python/google/protobuf/symbol_database.py
parent0087da9d4775f79c67362cc89c653f3a33a9bae2 (diff)
Down-integrate from google internal.
Diffstat (limited to 'python/google/protobuf/symbol_database.py')
-rw-r--r--python/google/protobuf/symbol_database.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/python/google/protobuf/symbol_database.py b/python/google/protobuf/symbol_database.py
index 4c70b393..b81ef4d7 100644
--- a/python/google/protobuf/symbol_database.py
+++ b/python/google/protobuf/symbol_database.py
@@ -60,6 +60,7 @@ Example usage:
"""
+from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool
@@ -72,6 +73,31 @@ class SymbolDatabase(object):
buffer types used within a program.
"""
+ # pylint: disable=protected-access
+ if _descriptor._USE_C_DESCRIPTORS:
+
+ def __new__(cls):
+ raise TypeError("Instances of SymbolDatabase cannot be created")
+
+ @classmethod
+ def _CreateDefaultDatabase(cls):
+ self = object.__new__(cls) # Bypass the __new__ above.
+ # Don't call __init__() and initialize here.
+ self._symbols = {}
+ self._symbols_by_file = {}
+ # As of today all descriptors are registered and retrieved from
+ # _message.default_pool (see FileDescriptor.__new__), so it's not
+ # necessary to use another pool.
+ self.pool = _descriptor._message.default_pool
+ return self
+ # pylint: enable=protected-access
+
+ else:
+
+ @classmethod
+ def _CreateDefaultDatabase(cls):
+ return cls()
+
def __init__(self):
"""Constructor."""
@@ -177,7 +203,7 @@ class SymbolDatabase(object):
result.update(self._symbols_by_file[f])
return result
-_DEFAULT = SymbolDatabase()
+_DEFAULT = SymbolDatabase._CreateDefaultDatabase()
def Default():