Python google.protobuf.internal.api_implementation.Version() Examples

The following are code examples for showing how to use google.protobuf.internal.api_implementation.Version(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: weilai   Author: cherrishes   File: descriptor.py    Apache License 2.0 6 votes vote down vote up
def __init__(self, name, package, options=None, serialized_pb=None,
               dependencies=None):
    """Constructor."""
    super(FileDescriptor, self).__init__(options, 'FileOptions')

    self.message_types_by_name = {}
    self.name = name
    self.package = package
    self.serialized_pb = serialized_pb

    self.enum_types_by_name = {}
    self.extensions_by_name = {}
    self.dependencies = (dependencies or [])

    if (api_implementation.Type() == 'cpp' and
        self.serialized_pb is not None):
      if api_implementation.Version() == 2:
        # pylint: disable=protected-access
        _message.Message._BuildFile(self.serialized_pb)
        # pylint: enable=protected-access
      else:
        cpp_message.BuildFile(self.serialized_pb) 
Example 2
Project: weilai   Author: cherrishes   File: descriptor.py    Apache License 2.0 6 votes vote down vote up
def __init__(self, name, package, options=None, serialized_pb=None,
               dependencies=None):
    """Constructor."""
    super(FileDescriptor, self).__init__(options, 'FileOptions')

    self.message_types_by_name = {}
    self.name = name
    self.package = package
    self.serialized_pb = serialized_pb

    self.enum_types_by_name = {}
    self.extensions_by_name = {}
    self.dependencies = (dependencies or [])

    if (api_implementation.Type() == 'cpp' and
        self.serialized_pb is not None):
      if api_implementation.Version() == 2:
        # pylint: disable=protected-access
        _message.Message._BuildFile(self.serialized_pb)
        # pylint: enable=protected-access
      else:
        cpp_message.BuildFile(self.serialized_pb) 
Example 3
Project: bigquerylayers   Author: smandaric   File: message_test.py    GNU General Public License v3.0 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example 4
Project: FUTU_Stop_Loss   Author: BigtoC   File: message_test.py    MIT License 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example 5
Project: FUTU_Stop_Loss   Author: BigtoC   File: unknown_fields_test.py    MIT License 5 votes vote down vote up
def SkipCheckUnknownFieldIfCppImplementation(func):
  return unittest.skipIf(
      api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
      'Addtional test for pure python involved protect members')(func) 
Example 6
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: message_test.py    MIT License 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example 7
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: unknown_fields_test.py    MIT License 5 votes vote down vote up
def SkipIfCppImplementation(func):
  return unittest.skipIf(
      api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
      'C++ implementation does not expose unknown fields to Python')(func) 
Example 8
Project: chrome_os_updater   Author: MuntashirAkon   File: message_test.py    GNU General Public License v3.0 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example 9
Project: poker   Author: surgebiswas   File: message_test.py    MIT License 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example 10
Project: poker   Author: surgebiswas   File: unknown_fields_test.py    MIT License 5 votes vote down vote up
def SkipIfCppImplementation(func):
  return unittest.skipIf(
      api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
      'C++ implementation does not expose unknown fields to Python')(func) 
Example 11
Project: syndicate-core   Author: syndicate-storage   File: message_test.py    Apache License 2.0 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example 12
Project: syndicate-core   Author: syndicate-storage   File: unknown_fields_test.py    Apache License 2.0 5 votes vote down vote up
def SkipIfCppImplementation(func):
  return unittest.skipIf(
      api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
      'C++ implementation does not expose unknown fields to Python')(func) 
Example 13
Project: Emotion-Evaluator   Author: Attriumph   File: message_test.py    MIT License 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example 14
Project: geofire-python   Author: ininex   File: message_test.py    MIT License 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example 15
Project: geofire-python   Author: ininex   File: unknown_fields_test.py    MIT License 5 votes vote down vote up
def SkipIfCppImplementation(func):
  return unittest.skipIf(
      api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
      'C++ implementation does not expose unknown fields to Python')(func) 
Example 16
Project: go2mapillary   Author: enricofer   File: message_test.py    GNU General Public License v3.0 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example 17
Project: go2mapillary   Author: enricofer   File: unknown_fields_test.py    GNU General Public License v3.0 5 votes vote down vote up
def SkipIfCppImplementation(func):
  return unittest.skipIf(
      api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
      'C++ implementation does not expose unknown fields to Python')(func) 
Example 18
Project: kastodi   Author: kharts   File: message_test.py    GNU General Public License v2.0 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example 19
Project: kastodi   Author: kharts   File: unknown_fields_test.py    GNU General Public License v2.0 5 votes vote down vote up
def SkipIfCppImplementation(func):
  return unittest.skipIf(
      api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
      'C++ implementation does not expose unknown fields to Python')(func) 
Example 20
Project: Burp-Addons   Author: SofianeHamlaoui   File: descriptor.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, name, full_name, index, number, type, cpp_type, label,
               default_value, message_type, enum_type, containing_type,
               is_extension, extension_scope, options=None,
               has_default_value=True):
    """The arguments are as described in the description of FieldDescriptor
    attributes above.

    Note that containing_type may be None, and may be set later if necessary
    (to deal with circular references between message types, for example).
    Likewise for extension_scope.
    """
    super(FieldDescriptor, self).__init__(options, 'FieldOptions')
    self.name = name
    self.full_name = full_name
    self.index = index
    self.number = number
    self.type = type
    self.cpp_type = cpp_type
    self.label = label
    self.has_default_value = has_default_value
    self.default_value = default_value
    self.containing_type = containing_type
    self.message_type = message_type
    self.enum_type = enum_type
    self.is_extension = is_extension
    self.extension_scope = extension_scope
    if api_implementation.Type() == 'cpp':
      if is_extension:
        if api_implementation.Version() == 2:
          self._cdescriptor = _message.GetExtensionDescriptor(full_name)
        else:
          self._cdescriptor = cpp_message.GetExtensionDescriptor(full_name)
      else:
        if api_implementation.Version() == 2:
          self._cdescriptor = _message.GetFieldDescriptor(full_name)
        else:
          self._cdescriptor = cpp_message.GetFieldDescriptor(full_name)
    else:
      self._cdescriptor = None 
Example 21
Project: Burp-Addons   Author: SofianeHamlaoui   File: descriptor.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, name, package, options=None, serialized_pb=None):
    """Constructor."""
    super(FileDescriptor, self).__init__(options, 'FileOptions')

    self.message_types_by_name = {}
    self.name = name
    self.package = package
    self.serialized_pb = serialized_pb
    if (api_implementation.Type() == 'cpp' and
        self.serialized_pb is not None):
      if api_implementation.Version() == 2:
        _message.BuildFile(self.serialized_pb)
      else:
        cpp_message.BuildFile(self.serialized_pb) 
Example 22
Project: lambda-tensorflow-object-detection   Author: mikylucky   File: message_test.py    GNU General Public License v3.0 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example 23
Project: aliyun-tablestore-tutorials   Author: aexleader   File: descriptor.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, name, full_name, index, number, type, cpp_type, label,
               default_value, message_type, enum_type, containing_type,
               is_extension, extension_scope, options=None,
               has_default_value=True):
    """The arguments are as described in the description of FieldDescriptor
    attributes above.

    Note that containing_type may be None, and may be set later if necessary
    (to deal with circular references between message types, for example).
    Likewise for extension_scope.
    """
    super(FieldDescriptor, self).__init__(options, 'FieldOptions')
    self.name = name
    self.full_name = full_name
    self.index = index
    self.number = number
    self.type = type
    self.cpp_type = cpp_type
    self.label = label
    self.has_default_value = has_default_value
    self.default_value = default_value
    self.containing_type = containing_type
    self.message_type = message_type
    self.enum_type = enum_type
    self.is_extension = is_extension
    self.extension_scope = extension_scope
    if api_implementation.Type() == 'cpp':
      if is_extension:
        if api_implementation.Version() == 2:
          self._cdescriptor = _message.GetExtensionDescriptor(full_name)
        else:
          self._cdescriptor = cpp_message.GetExtensionDescriptor(full_name)
      else:
        if api_implementation.Version() == 2:
          self._cdescriptor = _message.GetFieldDescriptor(full_name)
        else:
          self._cdescriptor = cpp_message.GetFieldDescriptor(full_name)
    else:
      self._cdescriptor = None 
Example 24
Project: aliyun-tablestore-tutorials   Author: aexleader   File: descriptor.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, name, package, options=None, serialized_pb=None):
    """Constructor."""
    super(FileDescriptor, self).__init__(options, 'FileOptions')

    self.message_types_by_name = {}
    self.name = name
    self.package = package
    self.serialized_pb = serialized_pb
    if (api_implementation.Type() == 'cpp' and
        self.serialized_pb is not None):
      if api_implementation.Version() == 2:
        _message.BuildFile(self.serialized_pb)
      else:
        cpp_message.BuildFile(self.serialized_pb) 
Example 25
Project: aliyun-tablestore-tutorials   Author: aexleader   File: descriptor.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, name, full_name, index, number, type, cpp_type, label,
               default_value, message_type, enum_type, containing_type,
               is_extension, extension_scope, options=None,
               has_default_value=True):
    """The arguments are as described in the description of FieldDescriptor
    attributes above.

    Note that containing_type may be None, and may be set later if necessary
    (to deal with circular references between message types, for example).
    Likewise for extension_scope.
    """
    super(FieldDescriptor, self).__init__(options, 'FieldOptions')
    self.name = name
    self.full_name = full_name
    self.index = index
    self.number = number
    self.type = type
    self.cpp_type = cpp_type
    self.label = label
    self.has_default_value = has_default_value
    self.default_value = default_value
    self.containing_type = containing_type
    self.message_type = message_type
    self.enum_type = enum_type
    self.is_extension = is_extension
    self.extension_scope = extension_scope
    if api_implementation.Type() == 'cpp':
      if is_extension:
        if api_implementation.Version() == 2:
          self._cdescriptor = _message.GetExtensionDescriptor(full_name)
        else:
          self._cdescriptor = cpp_message.GetExtensionDescriptor(full_name)
      else:
        if api_implementation.Version() == 2:
          self._cdescriptor = _message.GetFieldDescriptor(full_name)
        else:
          self._cdescriptor = cpp_message.GetFieldDescriptor(full_name)
    else:
      self._cdescriptor = None 
Example 26
Project: aliyun-tablestore-tutorials   Author: aexleader   File: descriptor.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, name, package, options=None, serialized_pb=None):
    """Constructor."""
    super(FileDescriptor, self).__init__(options, 'FileOptions')

    self.message_types_by_name = {}
    self.name = name
    self.package = package
    self.serialized_pb = serialized_pb
    if (api_implementation.Type() == 'cpp' and
        self.serialized_pb is not None):
      if api_implementation.Version() == 2:
        _message.BuildFile(self.serialized_pb)
      else:
        cpp_message.BuildFile(self.serialized_pb) 
Example 27
Project: weilai   Author: cherrishes   File: message_factory_cpp2_test.py    Apache License 2.0 5 votes vote down vote up
def testImplementationSetting(self):
    self.assertEqual('cpp', api_implementation.Type())
    self.assertEqual(2, api_implementation.Version()) 
Example 28
Project: weilai   Author: cherrishes   File: descriptor_cpp2_test.py    Apache License 2.0 5 votes vote down vote up
def testImplementationSetting(self):
    self.assertEqual('cpp', api_implementation.Type())
    self.assertEqual(2, api_implementation.Version()) 
Example 29
Project: weilai   Author: cherrishes   File: reflection_cpp2_generated_test.py    Apache License 2.0 5 votes vote down vote up
def testImplementationSetting(self):
    self.assertEqual('cpp', api_implementation.Type())
    self.assertEqual(2, api_implementation.Version()) 
Example 30
Project: weilai   Author: cherrishes   File: message_factory_cpp2_test.py    Apache License 2.0 5 votes vote down vote up
def testImplementationSetting(self):
    self.assertEqual('cpp', api_implementation.Type())
    self.assertEqual(2, api_implementation.Version()) 
Example 31
Project: weilai   Author: cherrishes   File: descriptor_cpp2_test.py    Apache License 2.0 5 votes vote down vote up
def testImplementationSetting(self):
    self.assertEqual('cpp', api_implementation.Type())
    self.assertEqual(2, api_implementation.Version()) 
Example 32
Project: weilai   Author: cherrishes   File: reflection_cpp2_generated_test.py    Apache License 2.0 5 votes vote down vote up
def testImplementationSetting(self):
    self.assertEqual('cpp', api_implementation.Type())
    self.assertEqual(2, api_implementation.Version()) 
Example 33
Project: weilai   Author: cherrishes   File: descriptor.py    Apache License 2.0 4 votes vote down vote up
def __init__(self, name, full_name, index, number, type, cpp_type, label,
               default_value, message_type, enum_type, containing_type,
               is_extension, extension_scope, options=None,
               has_default_value=True, containing_oneof=None):
    """The arguments are as described in the description of FieldDescriptor
    attributes above.

    Note that containing_type may be None, and may be set later if necessary
    (to deal with circular references between message types, for example).
    Likewise for extension_scope.
    """
    super(FieldDescriptor, self).__init__(options, 'FieldOptions')
    self.name = name
    self.full_name = full_name
    self.index = index
    self.number = number
    self.type = type
    self.cpp_type = cpp_type
    self.label = label
    self.has_default_value = has_default_value
    self.default_value = default_value
    self.containing_type = containing_type
    self.message_type = message_type
    self.enum_type = enum_type
    self.is_extension = is_extension
    self.extension_scope = extension_scope
    self.containing_oneof = containing_oneof
    if api_implementation.Type() == 'cpp':
      if is_extension:
        if api_implementation.Version() == 2:
          # pylint: disable=protected-access
          self._cdescriptor = (
              _message.Message._GetExtensionDescriptor(full_name))
          # pylint: enable=protected-access
        else:
          self._cdescriptor = cpp_message.GetExtensionDescriptor(full_name)
      else:
        if api_implementation.Version() == 2:
          # pylint: disable=protected-access
          self._cdescriptor = _message.Message._GetFieldDescriptor(full_name)
          # pylint: enable=protected-access
        else:
          self._cdescriptor = cpp_message.GetFieldDescriptor(full_name)
    else:
      self._cdescriptor = None 
Example 34
Project: weilai   Author: cherrishes   File: descriptor.py    Apache License 2.0 4 votes vote down vote up
def __init__(self, name, full_name, index, number, type, cpp_type, label,
               default_value, message_type, enum_type, containing_type,
               is_extension, extension_scope, options=None,
               has_default_value=True, containing_oneof=None):
    """The arguments are as described in the description of FieldDescriptor
    attributes above.

    Note that containing_type may be None, and may be set later if necessary
    (to deal with circular references between message types, for example).
    Likewise for extension_scope.
    """
    super(FieldDescriptor, self).__init__(options, 'FieldOptions')
    self.name = name
    self.full_name = full_name
    self.index = index
    self.number = number
    self.type = type
    self.cpp_type = cpp_type
    self.label = label
    self.has_default_value = has_default_value
    self.default_value = default_value
    self.containing_type = containing_type
    self.message_type = message_type
    self.enum_type = enum_type
    self.is_extension = is_extension
    self.extension_scope = extension_scope
    self.containing_oneof = containing_oneof
    if api_implementation.Type() == 'cpp':
      if is_extension:
        if api_implementation.Version() == 2:
          # pylint: disable=protected-access
          self._cdescriptor = (
              _message.Message._GetExtensionDescriptor(full_name))
          # pylint: enable=protected-access
        else:
          self._cdescriptor = cpp_message.GetExtensionDescriptor(full_name)
      else:
        if api_implementation.Version() == 2:
          # pylint: disable=protected-access
          self._cdescriptor = _message.Message._GetFieldDescriptor(full_name)
          # pylint: enable=protected-access
        else:
          self._cdescriptor = cpp_message.GetFieldDescriptor(full_name)
    else:
      self._cdescriptor = None