File: //opt/cppython/lib/python3.8/site-packages/google/protobuf/__pycache__/proto_builder.cpython-38.pyc
U
ID�gk � @ sn d Z ddlmZ ddlZddlZddlmZ ddlmZ ddlmZ ddlm Z dd � Z
dd
d�Zdd
� ZdS )zDynamic Protobuf class creator.� )�OrderedDictN)�descriptor_pb2)�
descriptor)�descriptor_pool)�message_factoryc C s | � |�}t�|�}|S )a- Get a proto class from the MessageFactory by name.
Args:
pool: a descriptor pool.
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.
)ZFindMessageTypeByNamer ZGetMessageClass)�pool� full_nameZproto_descriptor� proto_cls� r
�J/opt/cppython/lib/python3.8/site-packages/google/protobuf/proto_builder.py�_GetMessageFromFactory s
r c
C s� |p
t �� }|dk r:zt||�}|W S tk
r8 Y nX | �� }t| t�sTt|�}t� � }|D ],\}}|�
|�d�� |�
t|��d�� q`|�
� d } |dkr�d|�
� }zt||�}|W S tk
r� Y nX |�t| ||�� 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.
Nzutf-8z.protoz6net.proto2.python.public.proto_builder.AnonymousProto_)r ZDescriptorPoolr �KeyError�items�
isinstancer �sorted�hashlib�sha1�update�encode�str� hexdigest�Add�_MakeFileDescriptorProto)
�fieldsr r Z
pool_instancer �field_itemsZfields_hash�f_name�f_type�proto_file_namer
r
r �MakeSimpleProtoClass$ s8
�
�r c C s� |� dd�\}}t�� }tj�|�dd�| �|_||_|j �
� }||_t|d�D ]V\}\}} |j�
� }
||
_|t
jjkr�|t
jjt
jj d 7 }||
_tjj|
_| |
_qP|S )zAPopulate FileDescriptorProto for MessageFactory's DescriptorPool.�.� �/)�rsplitr ZFileDescriptorProto�os�path�join�replace�name�packageZmessage_type�add� enumerate�fieldr ZFieldDescriptorZFIRST_RESERVED_FIELD_NUMBERZLAST_RESERVED_FIELD_NUMBER�numberZFieldDescriptorProtoZLABEL_OPTIONAL�label�type)r r r r( r'