3 SLjR @s|dZyddlmZWn ek r4ddlmZYnXddlZddlZddlmZddlm Z ddZ d dd Z d d Z dS) zDynamic Protobuf class creator.) OrderedDictN)descriptor_pb2)message_factorycCs|jj|}|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 #/usr/lib/python3.6/proto_builder.py_GetMessageFromFactory,s  r c Cstj|d}|dk r8yt||}|Stk r6YnX|j}t|tsRt|}tj }x4|D],\}}|j |j d|j t |j dq`W|j d} |dkrd|j }yt||}|Stk rYnX|jjt| ||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 isinstancersortedhashlibZsha1updateencodestrZ hexdigestrZAdd_MakeFileDescriptorProto) Zfieldsrrrr field_itemsZ fields_hashf_namef_typeproto_file_namer r r MakeSimpleProtoClass<s4      rc Cs|jdd\}}tj}tjj|jdd||_||_|j j }||_x@t |dD]2\}\}} |j j } || _|| _ tjj| _| | _qRW|S)zAPopulate FileDescriptorProto for MessageFactory's DescriptorPool../)rsplitrZFileDescriptorProtoospathjoinreplacenamepackageZ message_typeadd enumerateZfieldZnumberZFieldDescriptorProtoZLABEL_OPTIONALZlabeltype) rrrr#r"Z file_protoZ desc_protoZf_numberrrZ field_protor r r rts    r)NN) __doc__ collectionsr ImportErrorZ ordereddictrrZgoogle.protobufrrr rrr r r r s   8