3 SÉLjR ã @ 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| tƒsRt|ƒ}tj ƒ }x4|D ],\}}|j |jdƒƒ |j t|ƒjdƒƒ q`W |j ƒ d } |dkrÔd|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 ÚKeyErrorÚitemsÚ isinstancer ÚsortedÚhashlibZsha1ÚupdateÚencodeÚstrZ hexdigestr ZAddÚ_MakeFileDescriptorProto) Zfieldsr r r r Úfield_itemsZfields_hashÚf_nameÚf_typeÚproto_file_namer r r ÚMakeSimpleProtoClass<