o
    ¨Ýj&  ã                   @  s–   d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 dZejdd	�G d
d„ dƒƒZejdd	�G dd„ dƒƒZejdd	�G dd„ dƒƒZdS )z!Support for alias configurations.é    )ÚannotationsN)ÚCallable)ÚAnyÚLiteral)ÚPydanticUndefined)ÚAliasGeneratorÚ	AliasPathÚAliasChoicesT)Úslotsc                   @  s8   e Zd ZU dZded< dd
d„Zddd„Zddd„ZdS )r   a  !!! abstract "Usage Documentation"
        [`AliasPath` and `AliasChoices`](../concepts/alias.md#aliaspath-and-aliaschoices)

    A data class used by `validation_alias` as a convenience to create aliases.

    Attributes:
        path: A list of string or integer aliases.
    zlist[int | str]ÚpathÚ	first_argÚstrÚargsú	str | intÚreturnÚNonec                 G  ó   |gt |ƒ | _d S ©N)Úlistr   )Úselfr   r   © r   úK/var/www/html/chatgpt/venv/lib/python3.10/site-packages/pydantic/aliases.pyÚ__init__   ó   zAliasPath.__init__úlist[str | int]c                 C  s   | j S )zvConverts arguments to a list of string or integer aliases.

        Returns:
            The list of aliases.
        )r   )r   r   r   r   Úconvert_to_aliases   s   zAliasPath.convert_to_aliasesÚdÚdictr   c                 C  sR   |}| j D ]!}t|tƒrt  S z|| }W q tttfy&   t Y   S w |S )z³Searches a dictionary for the path specified by the alias.

        Returns:
            The value at the specified path, or `PydanticUndefined` if the path is not found.
        )r   Ú
isinstancer   r   ÚKeyErrorÚ
IndexErrorÚ	TypeError)r   r   ÚvÚkr   r   r   Úsearch_dict_for_path&   s   

ÿzAliasPath.search_dict_for_pathN)r   r   r   r   r   r   )r   r   )r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r$   r   r   r   r   r      s   
 	

r   c                   @  s.   e Zd ZU dZded< ddd	„Zddd„ZdS )r	   a  !!! abstract "Usage Documentation"
        [`AliasPath` and `AliasChoices`](../concepts/alias.md#aliaspath-and-aliaschoices)

    A data class used by `validation_alias` as a convenience to create aliases.

    Attributes:
        choices: A list containing a string or `AliasPath`.
    zlist[str | AliasPath]ÚchoicesÚfirst_choiceústr | AliasPathr   r   c                 G  r   r   )r   r*   )r   r+   r*   r   r   r   r   E   r   zAliasChoices.__init__úlist[list[str | int]]c                 C  s:   g }| j D ]}t|tƒr| | ¡ ¡ q| |g¡ q|S )z‡Converts arguments to a list of lists containing string or integer aliases.

        Returns:
            The list of aliases.
        )r*   r   r   Úappendr   )r   ÚaliasesÚcr   r   r   r   H   s   

zAliasChoices.convert_to_aliasesN)r+   r,   r*   r,   r   r   )r   r-   )r%   r&   r'   r(   r)   r   r   r   r   r   r   r	   8   s
   
 	
r	   c                   @  sJ   e Zd ZU dZdZded< dZded< dZded< ddd„Zddd„Z	dS )r   aÿ  !!! abstract "Usage Documentation"
        [Using an `AliasGenerator`](../concepts/alias.md#using-an-aliasgenerator)

    A data class used by `alias_generator` as a convenience to create various aliases.

    Attributes:
        alias: A callable that takes a field name and returns an alias for it.
        validation_alias: A callable that takes a field name and returns a validation alias for it.
        serialization_alias: A callable that takes a field name and returns a serialization alias for it.
    NzCallable[[str], str] | NoneÚaliasz6Callable[[str], str | AliasPath | AliasChoices] | NoneÚvalidation_aliasÚserialization_aliasÚ
alias_kindú;Literal['alias', 'validation_alias', 'serialization_alias']Úallowed_typesú<tuple[type[str] | type[AliasPath] | type[AliasChoices], ...]Ú
field_namer   r   ú%str | AliasPath | AliasChoices | Nonec                 C  sP   d}t | |ƒ}|dur&||ƒ}|dur&t||ƒs&td|› d|› d|› d�ƒ‚|S )z·Generate an alias of the specified kind. Returns None if the alias generator is None.

        Raises:
            TypeError: If the alias generator produces an invalid type.
        Nz	Invalid `z	` type. `z!` generator must produce one of `ú`)Úgetattrr   r!   )r   r4   r6   r8   r1   Zalias_generatorr   r   r   Ú_generate_aliash   s   
ÿzAliasGenerator._generate_aliasúDtuple[str | None, str | AliasPath | AliasChoices | None, str | None]c                 C  s>   |   dtf|¡}|   dtttf|¡}|   dtf|¡}|||fS )z´Generate `alias`, `validation_alias`, and `serialization_alias` for a field.

        Returns:
            A tuple of three aliases - alias, validation, and serialization.
        r1   r2   r3   )r<   r   r	   r   )r   r8   r1   r2   r3   r   r   r   Úgenerate_aliases~   s   
zAliasGenerator.generate_aliases)r4   r5   r6   r7   r8   r   r   r9   )r8   r   r   r=   )
r%   r&   r'   r(   r1   r)   r2   r3   r<   r>   r   r   r   r   r   W   s   
 
r   )r(   Ú
__future__r   ÚdataclassesÚcollections.abcr   Útypingr   r   Zpydantic_corer   Ú__all__Ú	dataclassr   r	   r   r   r   r   r   Ú<module>   s    

)
