K idZdZddlZddlmZddlmZddlmZejdk(rddlm Z ndd l m Z e jZd Zd Zd ZGd deZddZy)aoProvides a factory class for generating dynamic messages. The easiest way to use this class is if you have access to the FileDescriptor protos containing the messages you want to create you can just do the following: message_classes = message_factory.GetMessages(iterable_of_file_descriptors) my_proto_instance = message_classes['some.proto.package.MessageName']() z"matthewtoia@google.com (Matt Toia)N)descriptor_pool)message)api_implementationpython)python_message) cpp_messagec:t|dd}|r|St|S)a7Obtains a proto2 message class based on the passed in descriptor. Passing a descriptor with a fully qualified name matching a previous invocation will cause the same class to be returned. Args: descriptor: The descriptor to build from. Returns: A class describing the passed in descriptor. _concrete_classN)getattr_InternalCreateMessageClass) descriptorconcrete_classs e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/google/protobuf/message_factory.pyGetMessageClassr#s':'8$?.  $Z 00ci}|D]}|j|}|jjD]}t|||j<|j jD]}t|j }tjdk7r3||j|j |jur td|jsot|j|S)aGets all the messages from specified files. This will find and resolve dependencies, failing if the descriptor pool cannot satisfy them. This will not return the classes for nested types within those classes, for those, use GetMessageClass() on the nested types within their containing messages. For example, for the message: message NestedTypeMessage { message NestedType { string data = 1; } NestedType nested = 1; } NestedTypeMessage will be in the result, but not NestedTypeMessage.NestedType. Args: files: The file names to extract messages from. pool: The descriptor pool to find the files including the dependent files. Returns: A dictionary mapping proto names to the message classes. r!Double registration of Extensions) FindFileByNamemessage_types_by_namevaluesr full_nameextensions_by_namecontaining_typerTypeFindExtensionByNumbernumber ValueError message_type)filespoolresult file_name file_descdesc extension_s rGetMessageClassesForFilesr'5s: &0i##I.I//6685.t4fT^^51188: 0 )33 4a  "h . D66  % %y'7'7  >? ?    ../ 008 -rc:|j}t|tjf|dd}|jD]$}|j st |j &|jjD]}t |j}tjdk7rS|jjj}||j|j|jur t!d|j st |j |S)zBuilds a proto2 message class based on the passed in descriptor. Args: descriptor: The descriptor to build from. Returns: A class describing the passed in descriptor. N) DESCRIPTOR __module__rr)name _GENERATED_PROTOCOL_MESSAGE_TYPErMessagefieldsrrr) extensionsrrrfiler rrr)r descriptor_name result_classfieldr%extended_classr s rr r rsOO/1",  *e e(()* **55 .i$Y%>%>?N H, & & + + 0 0d $44  # #Y%5%5 <==i,,- . rceZdZdZddZy)MessageFactoryz@Factory for creating Proto2 messages from descriptors in a pool.Nc>|xstj|_y)zInitializes a new factory.N)rDescriptorPoolr )selfr s r__init__zMessageFactory.__init__s8668DIrN)__name__r* __qualname____doc__r:rrr6r6s H9rr6c|xstj|Dcic]}|j|c}fdrjdrt |Dcgc]}|jc}Scc}wcc}w)aBuilds a dictionary of all the messages available in a set of files. Args: file_protos: Iterable of FileDescriptorProto to build messages out of. pool: The descriptor pool to add the file protos. Returns: A dictionary mapping proto names to the message classes. This will include any dependent messages as well as any messages defined in the same file as a specified message. c|jD]}|vsj| j|yr;) dependencypopAdd) file_protorB_AddFiledes_pool file_by_names rrFzGetMessages.._AddFilesA ++/ | #!!*-./ LLr)rr8r+popitemr') file_protosr rErFrGrHs @@@r GetMessagesrLs 5_335(@KL**//:-L,  \ ! ! #A &'  ")45:z5x M6s B%Br;)r> __author__warningsgoogle.protobufrrgoogle.protobuf.internalrrr message_implgoogle.protobuf.pyextrGeneratedProtocolMessageTyper,rr'r objectr6rLr?rrrUsg2 +#7(E?$0#L#L 1$:z#P9V9r