3
Šãde‚  ã               @   sb   d Z ddlmZ ddlZddlZddlmZ ddlmZ ddlmZ dd„ Z	dd	d
„Z
dd„ ZdS )zDynamic Protobuf class creator.é    )ÚOrderedDictN)Údescriptor_pb2)Ú
descriptor)Ú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.
  )ÚpoolZFindMessageTypeByNameZGetPrototype)ÚfactoryÚ	full_nameZproto_descriptorÚ	proto_cls© r
   úT/var/www/agendate/envp3/lib/python3.6/site-packages/google/protobuf/proto_builder.pyÚ_GetMessageFromFactory*   s    
r   c       
      C   sò   t j|d�}|dk	r8yt||ƒ}|S  tk
r6   Y nX | jƒ }t| tƒsRt|ƒ}tj	ƒ }x4|D ],\}}|j
|jdƒƒ |j
t|ƒjdƒƒ q`W |jƒ d }	|dkrÔd|jƒ  }yt||ƒ}|S  tk
rÒ   Y nX |jj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.
  )r   Nzutf-8z.protoz6net.proto2.python.public.proto_builder.AnonymousProto_)r   ZMessageFactoryr   ÚKeyErrorÚitemsÚ
isinstancer   ÚsortedÚhashlibÚsha1ÚupdateÚencodeÚstrÚ	hexdigestr   ÚAddÚ_MakeFileDescriptorProto)
Úfieldsr   r   r   r	   Úfield_itemsZfields_hashÚf_nameÚf_typeÚproto_file_namer
   r
   r   ÚMakeSimpleProtoClass:   s4    



r   c             C   s°   |j ddƒ\}}tjƒ }tjj|jddƒ| ƒ|_||_|j	j
ƒ }||_xdt|dƒD ]V\}\}}	|jj
ƒ }
||
_|tjjkr’|tjjtjj d 7 }||
_tjj|
_|	|
_qRW |S )zAPopulate FileDescriptorProto for MessageFactory's DescriptorPool.Ú.é   ú/)Úrsplitr   ZFileDescriptorProtoÚosÚpathÚjoinÚreplaceÚnameÚpackageZmessage_typeÚaddÚ	enumerateÚfieldr   ZFieldDescriptorZFIRST_RESERVED_FIELD_NUMBERZLAST_RESERVED_FIELD_NUMBERÚnumberZFieldDescriptorProtoZLABEL_OPTIONALÚlabelÚtype)r   r   r   r(   r'   Z
file_protoZ
desc_protoZf_numberr   r   Zfield_protor
   r
   r   r   r   s     



r   )NN)Ú__doc__Úcollectionsr   r   r#   Zgoogle.protobufr   r   r   r   r   r   r
   r
   r
   r   Ú<module>   s   
8