3
���hX � @ 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 t| j� �}t| t�sVt|�}t j
� }x4|D ],\}}|j|jd�� |jt
|�jd�� qdW |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�list�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<