Python google.protobuf.descriptor.OneofDescriptor() Examples
The following are 19 code examples for showing how to use google.protobuf.descriptor.OneofDescriptor(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
google.protobuf.descriptor
, or try the search function
.
Example 1
Project: luci-py Author: luci File: descriptor_pool.py License: Apache License 2.0 | 6 votes |
def FindOneofByName(self, full_name): """Loads the named oneof descriptor from the pool. Args: full_name (str): The full name of the oneof descriptor to load. Returns: OneofDescriptor: The oneof descriptor for the named oneof. Raises: KeyError: if the oneof cannot be found in the pool. """ full_name = _NormalizeFullyQualifiedName(full_name) message_name, _, oneof_name = full_name.rpartition('.') message_descriptor = self.FindMessageTypeByName(message_name) return message_descriptor.oneofs_by_name[oneof_name]
Example 2
Project: luci-py Author: luci File: descriptor_pool.py License: Apache License 2.0 | 6 votes |
def FindOneofByName(self, full_name): """Loads the named oneof descriptor from the pool. Args: full_name (str): The full name of the oneof descriptor to load. Returns: OneofDescriptor: The oneof descriptor for the named oneof. Raises: KeyError: if the oneof cannot be found in the pool. """ full_name = _NormalizeFullyQualifiedName(full_name) message_name, _, oneof_name = full_name.rpartition('.') message_descriptor = self.FindMessageTypeByName(message_name) return message_descriptor.oneofs_by_name[oneof_name]
Example 3
Project: luci-py Author: luci File: descriptor_pool.py License: Apache License 2.0 | 6 votes |
def FindOneofByName(self, full_name): """Loads the named oneof descriptor from the pool. Args: full_name (str): The full name of the oneof descriptor to load. Returns: OneofDescriptor: The oneof descriptor for the named oneof. Raises: KeyError: if the oneof cannot be found in the pool. """ full_name = _NormalizeFullyQualifiedName(full_name) message_name, _, oneof_name = full_name.rpartition('.') message_descriptor = self.FindMessageTypeByName(message_name) return message_descriptor.oneofs_by_name[oneof_name]
Example 4
Project: luci-py Author: luci File: descriptor_pool.py License: Apache License 2.0 | 6 votes |
def FindOneofByName(self, full_name): """Loads the named oneof descriptor from the pool. Args: full_name (str): The full name of the oneof descriptor to load. Returns: OneofDescriptor: The oneof descriptor for the named oneof. Raises: KeyError: if the oneof cannot be found in the pool. """ full_name = _NormalizeFullyQualifiedName(full_name) message_name, _, oneof_name = full_name.rpartition('.') message_descriptor = self.FindMessageTypeByName(message_name) return message_descriptor.oneofs_by_name[oneof_name]
Example 5
Project: luci-py Author: luci File: descriptor_pool.py License: Apache License 2.0 | 6 votes |
def FindOneofByName(self, full_name): """Loads the named oneof descriptor from the pool. Args: full_name (str): The full name of the oneof descriptor to load. Returns: OneofDescriptor: The oneof descriptor for the named oneof. Raises: KeyError: if the oneof cannot be found in the pool. """ full_name = _NormalizeFullyQualifiedName(full_name) message_name, _, oneof_name = full_name.rpartition('.') message_descriptor = self.FindMessageTypeByName(message_name) return message_descriptor.oneofs_by_name[oneof_name]
Example 6
Project: luci-py Author: luci File: descriptor_pool.py License: Apache License 2.0 | 6 votes |
def FindOneofByName(self, full_name): """Loads the named oneof descriptor from the pool. Args: full_name (str): The full name of the oneof descriptor to load. Returns: OneofDescriptor: The oneof descriptor for the named oneof. Raises: KeyError: if the oneof cannot be found in the pool. """ full_name = _NormalizeFullyQualifiedName(full_name) message_name, _, oneof_name = full_name.rpartition('.') message_descriptor = self.FindMessageTypeByName(message_name) return message_descriptor.oneofs_by_name[oneof_name]
Example 7
Project: lambda-packs Author: ryfeus File: python_message.py License: MIT License | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _Proto3HasError if is_proto3 else _Proto2HasError hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field if not is_proto3: # Fields inside oneofs are never repeated (enforced by the compiler). for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 8
Project: auto-alt-text-lambda-api Author: abhisuri97 File: python_message.py License: MIT License | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _Proto3HasError if is_proto3 else _Proto2HasError hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field if not is_proto3: # Fields inside oneofs are never repeated (enforced by the compiler). for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 9
Project: sklearn-theano Author: sklearn-theano File: python_message.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _Proto3HasError if is_proto3 else _Proto2HasError hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field if not is_proto3: # Fields inside oneofs are never repeated (enforced by the compiler). for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 10
Project: botchallenge Author: katharosada File: python_message.py License: MIT License | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" singular_fields = {} for field in message_descriptor.fields: if field.label != _FieldDescriptor.LABEL_REPEATED: singular_fields[field.name] = field # Fields inside oneofs are never repeated (enforced by the compiler). for field in message_descriptor.oneofs: singular_fields[field.name] = field def HasField(self, field_name): try: field = singular_fields[field_name] except KeyError: raise ValueError( 'Protocol message has no singular "%s" field.' % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 11
Project: coremltools Author: apple File: python_message.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _Proto3HasError if is_proto3 else _Proto2HasError hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field if not is_proto3: # Fields inside oneofs are never repeated (enforced by the compiler). for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 12
Project: go2mapillary Author: enricofer File: python_message.py License: GNU General Public License v3.0 | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _Proto3HasError if is_proto3 else _Proto2HasError hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field if not is_proto3: # Fields inside oneofs are never repeated (enforced by the compiler). for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 13
Project: luci-py Author: luci File: python_message.py License: Apache License 2.0 | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _PROTO3_ERROR_TEMPLATE if is_proto3 else _PROTO2_ERROR_TEMPLATE hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field # Has methods are supported for oneof descriptors. for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % (message_descriptor.full_name, field_name)) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 14
Project: luci-py Author: luci File: python_message.py License: Apache License 2.0 | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _PROTO3_ERROR_TEMPLATE if is_proto3 else _PROTO2_ERROR_TEMPLATE hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field # Has methods are supported for oneof descriptors. for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % (message_descriptor.full_name, field_name)) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 15
Project: luci-py Author: luci File: python_message.py License: Apache License 2.0 | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _PROTO3_ERROR_TEMPLATE if is_proto3 else _PROTO2_ERROR_TEMPLATE hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field # Has methods are supported for oneof descriptors. for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % (message_descriptor.full_name, field_name)) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 16
Project: luci-py Author: luci File: python_message.py License: Apache License 2.0 | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _PROTO3_ERROR_TEMPLATE if is_proto3 else _PROTO2_ERROR_TEMPLATE hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field # Has methods are supported for oneof descriptors. for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % (message_descriptor.full_name, field_name)) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 17
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda Author: PacktPublishing File: python_message.py License: MIT License | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _Proto3HasError if is_proto3 else _Proto2HasError hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field if not is_proto3: # Fields inside oneofs are never repeated (enforced by the compiler). for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 18
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda Author: PacktPublishing File: python_message.py License: MIT License | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _Proto3HasError if is_proto3 else _Proto2HasError hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field if not is_proto3: # Fields inside oneofs are never repeated (enforced by the compiler). for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField
Example 19
Project: keras-lambda Author: sunilmallya File: python_message.py License: MIT License | 5 votes |
def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" is_proto3 = (message_descriptor.syntax == "proto3") error_msg = _Proto3HasError if is_proto3 else _Proto2HasError hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and not field.containing_oneof): continue hassable_fields[field.name] = field if not is_proto3: # Fields inside oneofs are never repeated (enforced by the compiler). for oneof in message_descriptor.oneofs: hassable_fields[oneof.name] = oneof def HasField(self, field_name): try: field = hassable_fields[field_name] except KeyError: raise ValueError(error_msg % field_name) if isinstance(field, descriptor_mod.OneofDescriptor): try: return HasField(self, self._oneofs[field].name) except KeyError: return False else: if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: value = self._fields.get(field) return value is not None and value._is_present_in_parent else: return field in self._fields cls.HasField = HasField