o
    ïT·j–  ã                   @   sn   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lm	Z	 dd	„ Z
dd
d„Zdd„ ZdS )zDynamic Protobuf class creator.é    )ÚOrderedDictN)Ú
descriptor)Údescriptor_pb2)Ú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.
  )ÚFindMessageTypeByNamer   ÚGetMessageClass)ÚpoolÚ	full_nameÚproto_descriptorÚ	proto_cls© r   ú`/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/google/protobuf/proto_builder.pyÚ_GetMessageFromFactory   s   

r   c           
      C   sð   |pt  ¡ }|durzt||ƒ}|W S  ty   Y nw |  ¡ }t| tƒs)t|ƒ}tj	dd�}|D ]\}}| 
| d¡¡ | 
t|ƒ d¡¡ q1| ¡ d }	|du rjd| ¡  }zt||ƒ}|W S  tyi   Y nw | 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.
  NF)Úusedforsecurityzutf-8z.protoz6net.proto2.python.public.proto_builder.AnonymousProto_)r   ÚDescriptorPoolr   ÚKeyErrorÚitemsÚ
isinstancer   ÚsortedÚhashlibÚsha1ÚupdateÚencodeÚstrÚ	hexdigestÚAddÚ_MakeFileDescriptorProto)
Úfieldsr
   r	   Úpool_instancer   Úfield_itemsÚfields_hashÚf_nameÚf_typeÚproto_file_namer   r   r   ÚMakeSimpleProtoClass$   s>   
þ
ÿÿ
þ
ÿ
r%   c                 C   s¬   |  dd¡\}}t ¡ }tj | dd¡| ¡|_||_|j	 
¡ }||_t|dƒD ]+\}\}}	|j 
¡ }
||
_|tjjkrH|tjjtjj d 7 }||
_tjj|
_|	|
_q(|S )zAPopulate FileDescriptorProto for MessageFactory's DescriptorPool.Ú.é   ú/)Úrsplitr   ÚFileDescriptorProtoÚosÚpathÚjoinÚreplaceÚnameÚpackageÚmessage_typeÚaddÚ	enumerateÚfieldr   ÚFieldDescriptorÚFIRST_RESERVED_FIELD_NUMBERÚLAST_RESERVED_FIELD_NUMBERÚnumberÚFieldDescriptorProtoÚLABEL_OPTIONALÚlabelÚtype)r$   r
   r    r0   r/   Ú
file_protoÚ
desc_protoÚf_numberr"   r#   Úfield_protor   r   r   r   _   s*   

ÿþÿ
r   )NN)Ú__doc__Úcollectionsr   r   r+   Úgoogle.protobufr   r   r   r   r   r%   r   r   r   r   r   Ú<module>   s   
;