U Xzf_R@s|dZzddlmZWn ek r4ddlmZYnXddlZddlZddlmZddlm Z ddZ 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_clsr u/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-3cr5c46n/google/protobuf/proto_builder.py_GetMessageFromFactory,s  r c Cstj|d}|dk r:zt||}|WStk r8YnX|}t|tsTt|}t }|D],\}}| | d| t | dq`| d} |dkrd| }zt||}|WStk rYnX|jt| ||t||S)aCreate 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 KeyErroritems isinstancersortedhashlibsha1updateencodestr hexdigestrZAdd_MakeFileDescriptorProto) fieldsrrrr field_itemsZ fields_hashf_namef_typeproto_file_namer r r MakeSimpleProtoClass<s8       rc Cs|dd\}}t}tj|dd||_||_|j }||_t |dD]2\}\}} |j } || _|| _ tjj| _| | _qP|S)zAPopulate FileDescriptorProto for MessageFactory's DescriptorPool../)rsplitrZFileDescriptorProtoospathjoinreplacenamepackageZ message_typeadd enumeratefieldnumberZFieldDescriptorProtoZLABEL_OPTIONALlabeltype) 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