U Xzf_Rã@s|dZzddlmZWn ek r4ddlmZYnXddlZddlZddlmZddlm Z dd„Z d dd „Z d d „Z dS) zDynamic Protobuf class creator.é)Ú OrderedDictN)Údescriptor_pb2)Úmessage_factorycCs|j |¡}| |¡}|S)a8Get a proto class from the MessageFactory by name. Args: factory: a MessageFactory instance. full_name: str, the fully qualified name of the proto type. Returns: A class, for the type identified by full_name. Raises: KeyError, if the proto is not found in the factory's descriptor pool. )ÚpoolZFindMessageTypeByNameZ GetPrototype)ÚfactoryÚ full_nameZproto_descriptorÚ proto_cls©r úu/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-3cr5c46n/google/protobuf/proto_builder.pyÚ_GetMessageFromFactory,s  r c Csòtj|d�}|dk r:zt||ƒ}|WStk r8YnX| ¡}t|tƒsTt|ƒ}t  ¡}|D],\}}|  |  d¡¡|  t |ƒ  d¡¡q`|  ¡d} |dkrÔd|  ¡}zt||ƒ}|WStk rÒYnX|j t| ||ƒ¡t||ƒS)aêCreate a Protobuf class whose fields are basic types. Note: this doesn't validate field names! Args: fields: dict of {name: field_type} mappings for each field in the proto. If this is an OrderedDict the order will be maintained, otherwise the fields will be sorted by name. full_name: optional str, the fully-qualified name of the proto type. pool: optional DescriptorPool instance. Returns: a class, the new protobuf class with a FileDescriptor. )rNzutf-8z.protoz6net.proto2.python.public.proto_builder.AnonymousProto_)rZMessageFactoryr ÚKeyErrorÚitemsÚ isinstancerÚsortedÚhashlibÚsha1ÚupdateÚencodeÚstrÚ hexdigestrZAddÚ_MakeFileDescriptorProto) ÚfieldsrrrrÚ field_itemsZ fields_hashÚf_nameÚf_typeÚproto_file_namer r r ÚMakeSimpleProtoClass<s8     ÿ  ÿrc Csˆ| dd¡\}}t ¡}tj | dd¡|¡|_||_|j   ¡}||_t |dƒD]2\}\}} |j   ¡} || _|| _ tjj| _| | _qP|S)zAPopulate FileDescriptorProto for MessageFactory's DescriptorPool.Ú.éú/)ÚrsplitrZFileDescriptorProtoÚosÚpathÚjoinÚreplaceÚnameÚpackageZ message_typeÚaddÚ enumerateÚfieldÚnumberZFieldDescriptorProtoZLABEL_OPTIONALÚlabelÚtype) rrrr&r%Z file_protoZ desc_protoZf_numberrrZ field_protor r r rts   r)NN) Ú__doc__Ú collectionsrÚ ImportErrorZ ordereddictrr!Zgoogle.protobufrrr rrr r r r Ús   8