o
    {j6hF                      @   s   d Z dZddlZddlmZ ddlmZ ddlmZ e dkr'ddlm	Z
 ndd	lmZ
 e
jZd
d Zdd Zdd ZG dd deZdddZdS )ao  Provides a factory class for generating dynamic messages.

The easiest way to use this class is if you have access to the FileDescriptor
protos containing the messages you want to create you can just do the following:

message_classes = message_factory.GetMessages(iterable_of_file_descriptors)
my_proto_instance = message_classes['some.proto.package.MessageName']()
z"matthewtoia@google.com (Matt Toia)    N)descriptor_pool)message)api_implementationpython)python_message)cpp_messagec                 C   s   t | dd}|r
|S t| S )a7  Obtains a proto2 message class based on the passed in descriptor.

  Passing a descriptor with a fully qualified name matching a previous
  invocation will cause the same class to be returned.

  Args:
    descriptor: The descriptor to build from.

  Returns:
    A class describing the passed in descriptor.
  _concrete_classN)getattr_InternalCreateMessageClass)
descriptorconcrete_class r   n/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/google/protobuf/message_factory.pyGetMessageClass#   s   r   c                 C   s   i }| D ]?}| |}|j D ]	}t|||j< q|j D ]#}t|j}t dkr:||	|j|j
ur:td|jrBt|j qq|S )ae  Gets all the messages from specified files.

  This will find and resolve dependencies, failing if the descriptor
  pool cannot satisfy them.

  Args:
    files: The file names to extract messages from.
    pool: The descriptor pool to find the files including the dependent files.

  Returns:
    A dictionary mapping proto names to the message classes.
  r   !Double registration of Extensions)FindFileByNamemessage_types_by_namevaluesr   	full_nameextensions_by_namecontaining_typer   TypeFindExtensionByNumbernumber
ValueErrormessage_type)filespoolresult	file_name	file_descdesc	extension_r   r   r   GetMessageClassesForFiles5   s"   


r$   c                 C   s   | j }t|tjf| dd}| jD ]
}|jrt|j q|jjD ](}t|j	}t
 dkr@|j	jj}|||j	|jur@td|jrHt|j q |S )zBuilds a proto2 message class based on the passed in descriptor.

  Args:
    descriptor: The descriptor to build from.

  Returns:
    A class describing the passed in descriptor.
  N)
DESCRIPTOR
__module__r   r   )name _GENERATED_PROTOCOL_MESSAGE_TYPEr   Messagefieldsr   r   r%   
extensionsr   r   r   filer   r   r   r   )r   descriptor_nameresult_classfieldr"   extended_classr   r   r   r   r
   b   s0   	
	



r
   c                   @   s2   e Zd ZdZdddZdd Zdd Zd	d
 ZdS )MessageFactoryz@Factory for creating Proto2 messages from descriptors in a pool.Nc                 C   s   |pt  | _dS )zInitializes a new factory.N)r   DescriptorPoolr   )selfr   r   r   r   __init__   s   zMessageFactory.__init__c                 C      t jddd t|S )aE  Obtains a proto2 message class based on the passed in descriptor.

    Passing a descriptor with a fully qualified name matching a previous
    invocation will cause the same class to be returned.

    Args:
      descriptor: The descriptor to build from.

    Returns:
      A class describing the passed in descriptor.
    zMessageFactory class is deprecated. Please use GetMessageClass() instead of MessageFactory.GetPrototype. MessageFactory class will be removed after 2024.   
stacklevel)warningswarnr   r3   r   r   r   r   GetPrototype   
   zMessageFactory.GetPrototypec                 C   r5   )a,  Builds a proto2 message class based on the passed in descriptor.

    Don't call this function directly, it always creates a new class. Call
    GetMessageClass() instead.

    Args:
      descriptor: The descriptor to build from.

    Returns:
      A class describing the passed in descriptor.
    zDirectly call CreatePrototype is wrong. Please use GetMessageClass() method instead. Directly use CreatePrototype will raise error after July 2023.r6   r7   )r9   r:   r
   r;   r   r   r   CreatePrototype   r=   zMessageFactory.CreatePrototypec                 C   s   t jddd t|| jS )a  Gets all the messages from a specified file.

    This will find and resolve dependencies, failing if the descriptor
    pool cannot satisfy them.

    Args:
      files: The file names to extract messages from.

    Returns:
      A dictionary mapping proto names to the message classes. This will include
      any dependent messages as well as any messages defined in the same file as
      a specified message.
    zMessageFactory class is deprecated. Please use GetMessageClassesForFiles() instead of MessageFactory.GetMessages(). MessageFactory class will be removed after 2024.r6   r7   )r9   r:   r$   r   )r3   r   r   r   r   GetMessages   s
   zMessageFactory.GetMessagesN)__name__r&   __qualname____doc__r4   r<   r>   r?   r   r   r   r   r1      s    
r1   c                    sV   |pt  dd | D  fdd r!  d  stdd | D S )a  Builds a dictionary of all the messages available in a set of files.

  Args:
    file_protos: Iterable of FileDescriptorProto to build messages out of.
    pool: The descriptor pool to add the file protos.

  Returns:
    A dictionary mapping proto names to the message classes. This will include
    any dependent messages as well as any messages defined in the same file as
    a specified message.
  c                 S   s   i | ]}|j |qS r   r'   .0
file_protor   r   r   
<dictcomp>   s    zGetMessages.<locals>.<dictcomp>c                    s0   | j D ]}|v r | q|  d S r@   )
dependencypopAdd)rG   rI   _AddFiledes_poolfile_by_namer   r   rM      s
   
zGetMessages.<locals>._AddFile   c                 S   s   g | ]}|j qS r   rD   rE   r   r   r   
<listcomp>   s    zGetMessages.<locals>.<listcomp>)r   r2   popitemr$   )file_protosr   r   rL   r   r?      s   r?   r@   )rC   
__author__r9   google.protobufr   r   google.protobuf.internalr   r   r   message_implgoogle.protobuf.pyextr   GeneratedProtocolMessageTyper(   r   r$   r
   objectr1   r?   r   r   r   r   <module>   s   	-(G