U
    ڲg                     @   s   d dl 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lm	Z	 e
dZG dd de dd	d
ddddgZdS )    N)descriptor_pb2)descriptor_pool)message)
reflection)MessageRule	_FileInfoc                   @   s^   e Zd Zi Zedd Zedd Zdd Zdd Z	d	d
 Z
dddZdd Zedd ZdS )r   c                 C   sF   | j |}|sB| tj||ddt t |i i d }| j |< |S )NZproto3)namepackageZsyntax)
descriptorenumsmessagesr   nestednested_enum)registrygetr   ZFileDescriptorProtocollectionsOrderedDict)clsfilenamer	   r
    r   4/tmp/pip-unpacked-wheel-zasgy6sz/proto/_file_info.pymaybe_add_descriptor%   s    z_FileInfo.maybe_add_descriptorc                 C   s   d | ddS )Nz	{0}.proto./)formatreplacer   r   r   r   proto_file_name8   s    z_FileInfo.proto_file_namec                 C   s&   t |}t|dr t|jjS t S )N__protobuf__)inspect	getmodulehasattr	frozensetr   manifest)self	new_classmoduler   r   r   _get_manifest<   s    

z_FileInfo._get_manifestc                 C   s   |  ||jh S N)r'   __name__)r$   r%   r   r   r   _get_remaining_manifestC   s    z!_FileInfo._get_remaining_manifestc                 C   sP   |  |}|r6|j|kr6tdjt|j|jd |j|krDdS |pJd S )NzPproto-plus module {module} has a declared manifest but {class_name} is not in it)r&   
class_name )r'   r)   logwarningr   r   r    lower)r$   r%   fallbackr#   r   r   r   _calculate_saltF   s    

z_FileInfo._calculate_saltr,   c                 C   s0  t  }| ||}djd| jjdd |gdd| j_|| j | j	
 D ]\}}||}t|jtjf|dd}||j_|jj|t|| |jj D ]F}	|	jrt|	jtr| j	|	j |	_q|	jrt|	jtr| j|	j |	_qqV| j
 D ]\}}
||}||
j_q | j| j dS )a  Generate the descriptors for all protos in the file.

        This method takes the file descriptor attached to the parent
        message and generates the immutable descriptors for all of the
        messages in the file descriptor. (This must be done in one fell
        swoop for immutability and to resolve proto cross-referencing.)

        This is run automatically when the last proto in the file is
        generated, as determined by the module's __all__ tuple.
        z{name}.proto_Nir   )Z
DESCRIPTOR
__module__)r   ZDefaultr1   r   joinr
   r   rstripZAddr   itemsZFindMessageTypeByNamer   ZGeneratedProtocolMessageTyper   Message_metaZ_pbmarshalregisterr   fieldsvalues
isinstancestrenumr   ZFindEnumTypeByNameZpbr   pop)r$   r%   Zfallback_saltpoolZsaltZ	full_nameproto_plus_messager
   Z
pb_messagefieldZproto_plus_enumr   r   r   generate_file_pbR   s6    

 
z_FileInfo.generate_file_pbc                    sx   t | jst | jrdS | jD ].}|jr4|j| jksF|jr|j| jkr dS qt	| | 
|}t fdd|D S )ak  Return True if a file descriptor may added, False otherwise.

        This determine if all the messages that we plan to create have been
        created, as best as we are able.

        Since messages depend on one another, we create descriptor protos
        (which reference each other using strings) and wait until we have
        built everything that is going to be in the module, and then
        use the descriptor protos to instantiate the actual descriptors in
        one fell swoop.

        Args:
            new_class (~.MessageMeta): The new class currently undergoing
                creation.
        Fc                 3   s   | ]}t  |V  qd S r(   )r!   ).0ir&   r   r   	<genexpr>   s     z"_FileInfo.ready.<locals>.<genexpr>)lenr   r   unresolved_fieldsr   r   r?   r   r   r    r*   all)r$   r%   rC   r#   r   rG   r   ready   s    



z_FileInfo.readyc                 c   sP   | j  D ]@}|jj D ].}|jr0t|jtsB|jrt|jtr|V  qq
dS )z8Return fields with referencing message types as strings.N)r   r<   r8   r;   r   r=   r>   r?   )r$   rB   rC   r   r   r   rJ      s    
z_FileInfo.unresolved_fieldsN)r,   )r)   r3   __qualname__r   classmethodr   staticmethodr   r'   r*   r1   rD   rL   propertyrJ   r   r   r   r   r      s   


A)r
   r   r   r   r   r   )r   r   loggingZgoogle.protobufr   r   r   r   Zproto.marshal.rules.messager   	getLoggerr-   
namedtupler   r   r   r   r   <module>   s   

