31 """Determine which implementation of the protobuf API is used in this process.
43 _api_version = _api_implementation.api_version
44 _proto_extension_modules_exist_in_build =
True
47 _proto_extension_modules_exist_in_build =
False
50 raise ValueError(
'api_version=1 is no longer supported.')
59 if not _use_fast_cpp_protos:
60 raise ImportError(
'_use_fast_cpp_protos import succeeded but was None')
61 del _use_fast_cpp_protos
77 _default_implementation_type = (
78 'python' if _api_version <= 0
else 'cpp')
84 _implementation_type = os.getenv(
'PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION',
85 _default_implementation_type)
87 if _implementation_type !=
'python':
88 _implementation_type =
'cpp'
90 if 'PyPy' in sys.version
and _implementation_type ==
'cpp':
91 warnings.warn(
'PyPy does not work yet with cpp protocol buffers. '
92 'Falling back to the python implementation.')
93 _implementation_type =
'python'
99 _implementation_version_str = os.getenv(
100 'PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION',
'2')
102 if _implementation_version_str !=
'2':
104 'unsupported PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION: "' +
105 _implementation_version_str +
'" (supported versions: 2)'
108 _implementation_version = int(_implementation_version_str)
127 _python_deterministic_proto_serialization =
True
129 _python_deterministic_proto_serialization =
False
137 return _implementation_type
141 """Never use! Only for protobuf benchmark."""
142 global _implementation_type
143 _implementation_type = implementation_type
148 return _implementation_version
153 return _python_deterministic_proto_serialization