3 SLjR @ s| d Z yddlmZ W n ek r4 ddlmZ Y nX ddlZddlZddlmZ ddlm Z dd Z ddd Zd d ZdS ) zDynamic Protobuf class creator. )OrderedDictN)descriptor_pb2)message_factoryc C s | j j|}| j|}|S )a8 Get 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. )poolZFindMessageTypeByNameZGetPrototype)factory full_nameZproto_descriptor proto_cls r #/usr/lib/python3.6/proto_builder.py_GetMessageFromFactory, s r c C s t j|d}|dk r8yt||}|S tk r6 Y nX | j }t| tsRt|}tj }x4|D ],\}}|j |jd |j t|jd q`W |j d } |dkrd|j }yt||}|S tk r Y nX |jjt| || 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. )r Nzutf-8z.protoz6net.proto2.python.public.proto_builder.AnonymousProto_)r ZMessageFactoryr KeyErroritems isinstancer sortedhashlibZsha1updateencodestrZ hexdigestr ZAdd_MakeFileDescriptorProto) Zfieldsr r r r field_itemsZfields_hashf_namef_typeproto_file_namer r r MakeSimpleProtoClass<