B @`R@s|dZyddlmZWn 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 A/tmp/pip-unpacked-wheel-3chbcimp/google/protobuf/proto_builder.py_GetMessageFromFactory,s  r c Cstj|d}|dk r8yt||}|Stk r6YnX|}t|tsRt|}t }x4|D],\}}| | d| t | dq`W| d} |dkrd| }yt||}|Stk 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<s4      rc Cs|dd\}}t}tj|dd||_||_|j }||_x@t |dD]2\}\}} |j } || _|| _ tjj| _| | _qRW|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