protorpc.messages package provides the following positional utility function:
- find_definition(name, relative_to=None)
Find definition by name in module-space.
The find algorithm finds definitions by name relative to a message definition or by fully qualified name. If no definition is found relative to the
relative_toparameter, it searches against the container of
relative_tois a nested Message, it searches its message_definition(). If that message has no message_definition(), it searches its module. If
relative_tois a module, the find algorithm searches for the containing module and searches relative to it. If the module is a top-level module, the find algorithm searches for the a message using a fully qualified name. If it still finds no message, the search fails and the method raises a DefinitionNotFoundError.
For example, when looking for any definition
foo.bar.ADefinitionrelative to an actual message definition
The arguments to this method follow a pattern similar to a search for fully qualified names:
abc.xyz.SomeMessage. foo.bar.ADefinition abc.xyz. foo.bar.ADefinition abc. foo.bar.ADefinition foo.bar.ADefinition
When resolving the name relative to Message definitions and modules, the algorithm searches any Messages or sub-modules found in its path, ignoring non-Message values.
A name that begins with
'.'is considered to be a fully qualified name. The find algorithm begins searching from the topmost package. For example, assume two message types:
abc.xyz.SomeMessage. For this kind of name, the relative_to parameter is effectively ignored and always set to None.
For more information about package name resolution, please see the Protocol Buffers Package specifier.
- Name of a definition to find. May be fully qualified or relative.
- Searches for a definition relative to the message definition or module. If None, causes a fully qualified name search.
raises a DefinitionNotFoundError if no definition is found in any search path.