module documentation
Utilities for deriving Python-friendly names from protobuf identifiers.
| Exception | |
Raised when a name cannot be converted into a valid Python identifier. |
| Function | enum |
Return a Python enum name from a protobuf enum name. |
| Function | enum |
Return a Python constant name for an enum value. |
| Function | field |
Return a Python attribute name for a message field. |
| Function | first |
Return the first non-underscore character or an empty string. |
| Function | is |
Return True if s is a Python keyword or soft keyword. |
| Function | message |
Return a Python message name from a protobuf message name. |
| Function | method |
Return a Python method name for a service method. |
| Function | one |
Return a Python attribute name for a oneof declaration. |
| Function | pascal |
Convert a PascalCase string to snake_case. |
| Function | service |
Return a Python service class name from a protobuf service name. |
| Variable | logger |
Undocumented |
| Variable | pep8 |
Undocumented |
| Variable | pep8 |
Undocumented |
| Variable | pep8 |
Undocumented |
| Variable | pep8 |
Undocumented |
| Function | _class |
Resolve a Python class name from a protobuf full name. |
| Function | _modify |
Adjust a proposed name to avoid reserved words and conflicts. |
def enum(full_enum_name:
str, annotated_name: str = '', full_proto_name: str = '') -> str:
(source)
¶
Return a Python enum name from a protobuf enum name.
| Parameters | |
fullstr | Fully qualified proto enum name. |
annotatedstr | Optional explicit name from annotations. |
fullstr | Fully qualified proto name for warnings. |
| Returns | |
str | Valid Python enum class name. |
| Raises | |
NameError | If the annotated name is invalid. |
def enum_value(value_name:
str, enum_name: str, annotated_name: str = '', full_proto_name: str = '') -> str:
(source)
¶
Return a Python constant name for an enum value.
| Parameters | |
valuestr | Enum value name in proto. |
enumstr | Containing enum name. |
annotatedstr | Optional explicit name from annotations. |
fullstr | Fully qualified proto name for warnings. |
| Returns | |
str | Valid Python constant name. |
| Raises | |
NameError | If the annotated name is invalid. |
def field(field_name:
str, message_name: str, annotated_name: str = '', full_proto_name: str = '') -> str:
(source)
¶
Return a Python attribute name for a message field.
| Parameters | |
fieldstr | Field name in proto. |
messagestr | Containing message name. |
annotatedstr | Optional explicit name from annotations. |
fullstr | Fully qualified proto name for warnings. |
| Returns | |
str | Valid Python attribute name. |
| Raises | |
NameError | If the annotated name is invalid. |
def method(method_name:
str, service_name: str, annotated_name: str = '', full_proto_name: str = '') -> str:
(source)
¶
Return a Python method name for a service method.
| Parameters | |
methodstr | Proto method name. |
servicestr | Containing service name. |
annotatedstr | Optional explicit name from annotations. |
fullstr | Fully qualified proto name for warnings. |
| Returns | |
str | Valid Python method name. |
| Raises | |
NameError | If the annotated name is invalid. |
def one_of(field_name:
str, message_name: str, annotated_name: str = '', full_proto_name: str = '') -> str:
(source)
¶
Return a Python attribute name for a oneof declaration.
| Parameters | |
fieldstr | Oneof field name. |
messagestr | Containing message name. |
annotatedstr | Optional explicit name from annotations. |
fullstr | Fully qualified proto name for warnings. |
| Returns | |
str | Valid Python attribute name. |
| Raises | |
NameError | If the annotated name is invalid. |
def _modify_name(suggested_name:
str, container_name: str, *, lower: bool = True, full_proto_name: str = '') -> str:
(source)
¶
Adjust a proposed name to avoid reserved words and conflicts.
| Parameters | |
suggestedstr | Initial candidate name. |
containerstr | Enclosing scope name used for conflict prefixes. |
lower:bool | Whether to lower the prefix letter. |
fullstr | Fully qualified proto name for warnings. |
| Returns | |
str | Adjusted name. |