hfdZddlZddlmZddlmZddlmZGddZeejZ d ZdS) aSA 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')() N)api_implementation)descriptor_pool)message_factorycZeZdZdZiZddZdZdZdZdZ dZ d Z d Z d Z d Zd ZdS)SymbolDatabasez'A database of Python generated symbols.Nc:|ptj|_dS)z!Initializes a new SymbolDatabase.N)rDescriptorPoolpool)selfr s /builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/google/protobuf/symbol_database.py__init__zSymbolDatabase.__init__Is8688DIIIcRtjdtj|S)NzSymbolDatabase.GetPrototype() is deprecated. Please use message_factory.GetMessageClass() instead. SymbolDatabase.GetPrototype() will be removed soon.)warningswarnrGetMessageClassr descriptors r GetPrototypezSymbolDatabase.GetPrototypeMs2 MHIII  *: 6 66rcRtjdtj|S)NzDirectly call CreatePrototype() is wrong. Please use message_factory.GetMessageClass() instead. SymbolDatabase.CreatePrototype() will be removed soon.)rrr_InternalCreateMessageClassrs r CreatePrototypezSymbolDatabase.CreatePrototypeSs2 MKLLL  6z B BBrc^tjdtj||jS)NzSymbolDatabase.GetMessages() is deprecated. Please use message_factory.GetMessageClassedForFiles() instead. SymbolDatabase.GetMessages() will be removed soon.)rrrGetMessageClassedForFilesr )r filess r GetMessageszSymbolDatabase.GetMessagesYs6 MGHHH  4UDI F FFrcR|j}||j|<|||S)a@Registers the given message type in the local database. Calls to GetSymbol() and GetMessages() will return messages registered here. Args: message: A :class:`google.protobuf.message.Message` subclass (or instance); its descriptor will be registered. Returns: The provided message. ) DESCRIPTOR_classesRegisterMessageDescriptor)r messagedescs r RegisterMessagezSymbolDatabase.RegisterMessage_s1  D!DM$""4((( Nrcltjdkr|j|dSdS)zRegisters the given message descriptor in the local database. Args: message_descriptor (Descriptor): the message descriptor to add. pythonN)rTyper _AddDescriptor)r message_descriptors r r z(SymbolDatabase.RegisterMessageDescriptorqs=   H,, i122222-,rchtjdkr|j||S)zRegisters the given enum descriptor in the local database. Args: enum_descriptor (EnumDescriptor): The enum descriptor to register. Returns: EnumDescriptor: The provided descriptor. r%)rr&r _AddEnumDescriptor)r enum_descriptors r RegisterEnumDescriptorz%SymbolDatabase.RegisterEnumDescriptor{s4  H,, i""?333 rcltjdkr|j|dSdS)zRegisters the given service descriptor in the local database. Args: service_descriptor (ServiceDescriptor): the service descriptor to register. r%N)rr&r _AddServiceDescriptor)r service_descriptors r RegisterServiceDescriptorz(SymbolDatabase.RegisterServiceDescriptors=  H,, i%%&899999-,rcltjdkr|j|dSdS)zRegisters the given file descriptor in the local database. Args: file_descriptor (FileDescriptor): The file descriptor to register. r%N)rr&r _InternalAddFileDescriptor)r file_descriptors r RegisterFileDescriptorz%SymbolDatabase.RegisterFileDescriptors<   H,, i**?;;;;;-,rcL|j|j|S)awTries 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. Args: symbol (str): a protocol buffer symbol. Returns: A Python class corresponding to the symbol. Raises: KeyError: if the symbol could not be found. )rr FindMessageTypeByName)r symbols r GetSymbolzSymbolDatabase.GetSymbols! =88@@ AArcfdi}|D]l}|j|}|jD]6}|D](} |j|||j<#t $rY%wxYw7m|S)aGets 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. Args: files (list[str]): The file names to extract messages from. Returns: A dictionary mapping proto names to the message classes. Raises: KeyError: if a file could not be found. c3LK|V|jD]}|D]}|VdS)zCWalk a message Descriptor and recursively yields all message names.N) nested_types)r"msg_desc nested_desc_GetAllMessagess r r>z3SymbolDatabase.GetMessages.._GetAllMessagessY jjj'(*?844  K     r)r FindFileByNamemessage_types_by_namevaluesr full_nameKeyError)r rresult file_name file_descr<r"r>s @r rzSymbolDatabase.GetMessagess&F )**955i5<<>>(#OH--  D %)]4%8F4> " "    D   MsA&& A3 2A3 )N)__name__ __module__ __qualname____doc__rr rrrr#r r,r0r4r8rr rrCs//(9999777 CCC GGG $333    : : :<<<BBB$$$$$$rr)r ctS)z#Returns the default SymbolDatabase.)_DEFAULTrKrr DefaultrNs /r) rJrgoogle.protobuf.internalrgoogle.protobufrrrrNrMrKrr rQs>:777777++++++++++++QQQQQQQQh >6688 9 9 9r