symbol_database
A database of Python protocol buffer generated symbols.
SymbolDatabase is the MessageFactory for messages generated at compile time, and makes it easy to create new instances of a registered type, given only the type's protocol buffer symbol name.
Example usage::
db = symbol_database.SymbolDatabase()
# Register symbols of interest, from one or multiple files. db.RegisterFileDescriptor(my_proto_pb2.DESCRIPTOR) db.RegisterMessage(my_proto_pb2.MyMessage) db.RegisterEnumDescriptor(my_proto_pb2.MyEnum.DESCRIPTOR)
# The database can be used as a MessageFactory, to generate types based on # their name: types = db.GetMessages(['my_proto.proto']) my_message_instance = types'MyMessage'
# The database's underlying descriptor pool can be queried, so it's not # necessary to know a type's filename to be able to generate it: filename = db.pool.FindFileContainingSymbol('MyMessage') my_message_instance = db.GetMessages([filename])'MyMessage'
# This functionality is also provided directly via a convenience method: my_message_instance = db.GetSymbol('MyMessage')()
SymbolDatabase
Bases: MessageFactory
A database of Python generated symbols.
Source code in client/ayon_nuke/vendor/google/protobuf/symbol_database.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
GetMessages(files)
Gets all registered messages from a specified file.
Only messages already created and registered will be returned; (this is the case for imported _pb2 modules) But unlike MessageFactory, this version also returns already defined nested messages, but does not register any message extensions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
files | list[str] | The file names to extract messages from. | required |
Returns:
Type | Description |
---|---|
A dictionary mapping proto names to the message classes. |
Raises:
Type | Description |
---|---|
KeyError | if a file could not be found. |
Source code in client/ayon_nuke/vendor/google/protobuf/symbol_database.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
GetSymbol(symbol)
Tries to find a symbol in the local database.
Currently, this method only returns message.Message instances, however, if may be extended in future to support other symbol types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbol | str | a protocol buffer symbol. | required |
Returns:
Type | Description |
---|---|
A Python class corresponding to the symbol. |
Raises:
Type | Description |
---|---|
KeyError | if the symbol could not be found. |
Source code in client/ayon_nuke/vendor/google/protobuf/symbol_database.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
RegisterEnumDescriptor(enum_descriptor)
Registers the given enum descriptor in the local database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enum_descriptor | EnumDescriptor | The enum descriptor to register. | required |
Returns:
Name | Type | Description |
---|---|---|
EnumDescriptor | The provided descriptor. |
Source code in client/ayon_nuke/vendor/google/protobuf/symbol_database.py
97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
RegisterFileDescriptor(file_descriptor)
Registers the given file descriptor in the local database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_descriptor | FileDescriptor | The file descriptor to register. | required |
Source code in client/ayon_nuke/vendor/google/protobuf/symbol_database.py
122 123 124 125 126 127 128 129 130 |
|
RegisterMessage(message)
Registers the given message type in the local database.
Calls to GetSymbol() and GetMessages() will return messages registered here.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message | A :class: | required |
Returns:
Type | Description |
---|---|
The provided message. |
Source code in client/ayon_nuke/vendor/google/protobuf/symbol_database.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
RegisterMessageDescriptor(message_descriptor)
Registers the given message descriptor in the local database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message_descriptor | Descriptor | the message descriptor to add. | required |
Source code in client/ayon_nuke/vendor/google/protobuf/symbol_database.py
87 88 89 90 91 92 93 94 95 |
|
RegisterServiceDescriptor(service_descriptor)
Registers the given service descriptor in the local database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service_descriptor | ServiceDescriptor | the service descriptor to register. | required |
Source code in client/ayon_nuke/vendor/google/protobuf/symbol_database.py
111 112 113 114 115 116 117 118 119 120 |
|
Default()
Returns the default SymbolDatabase.
Source code in client/ayon_nuke/vendor/google/protobuf/symbol_database.py
192 193 194 |
|