From 46e8ff63cb67a6520711da5317aaaef04d0414d0 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Mon, 5 Oct 2015 11:59:43 -0700 Subject: Down-integrate from google internal. --- python/google/protobuf/symbol_database.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'python/google/protobuf/symbol_database.py') 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(): -- cgit v1.2.3