U
    nËjÖ  ã                   @  s    d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	 ddl
mZ dZejf ejŽG d	d
„ d
ƒƒZejf ejŽG dd„ dƒƒZejf ejŽG dd„ dƒƒZdS )z!Support for alias configurations.é    )ÚannotationsN)ÚAnyÚCallableÚLiteral)ÚPydanticUndefinedé   )Ú_internal_dataclass)ÚAliasGeneratorÚ	AliasPathÚAliasChoicesc                   @  sJ   e Zd ZU dZded< ddddœdd	„Zd
dœdd„Zdddœdd„ZdS )r
   zîUsage docs: https://docs.pydantic.dev/2.10/concepts/alias#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Ústrz	str | intÚNone)Ú	first_argÚargsÚreturnc                 G  s   |gt |ƒ | _d S ©N)Úlistr   )Úselfr   r   © r   ú4/tmp/pip-unpacked-wheel-zvl9l234/pydantic/aliases.pyÚ__init__   s    zAliasPath.__init__zlist[str | int]©r   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Údictr   )Údr   c                 C  sV   |}| j D ]F}t|tƒr t  S z|| }W q
 tttfk
rN   t Y   S X q
|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)Ú__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dœdd„Zd	d
œdd„ZdS )r   z÷Usage docs: https://docs.pydantic.dev/2.10/concepts/alias#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]Úchoiceszstr | AliasPathr   )Úfirst_choicer(   r   c                 G  s   |gt |ƒ | _d S r   )r   r(   )r   r)   r(   r   r   r   r   D   s    zAliasChoices.__init__zlist[list[str | int]]r   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   G   s    

zAliasChoices.convert_to_aliasesN)r#   r$   r%   r&   r'   r   r   r   r   r   r   r   8   s   
r   c                   @  sZ   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
ddœdd„Zd
ddœdd„Z	dS )r	   aÜ  Usage docs: https://docs.pydantic.dev/2.10/concepts/alias#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_aliasz=Literal[('alias', 'validation_alias', 'serialization_alias')]z<tuple[type[str] | type[AliasPath] | type[AliasChoices], ...]r   z%str | AliasPath | AliasChoices | None)Ú
alias_kindÚallowed_typesÚ
field_namer   c                 C  sH   d}t | |ƒ }rD||ƒ}|rDt||ƒsDt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   r0   r1   r2   r-   Zalias_generatorr   r   r   Ú_generate_aliasf   s    ÿzAliasGenerator._generate_aliaszDtuple[str | None, str | AliasPath | AliasChoices | None, str | None])r2   r   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 - validation, alias, and serialization.
        r-   r.   r/   )r5   r   r   r
   )r   r2   r-   r.   r/   r   r   r   Úgenerate_aliasesz   s    zAliasGenerator.generate_aliases)
r#   r$   r%   r&   r-   r'   r.   r/   r5   r6   r   r   r   r   r	   V   s   

r	   )r&   Ú
__future__r   ZdataclassesÚtypingr   r   r   Zpydantic_corer   Ú	_internalr   Ú__all__Z	dataclassZ
slots_truer
   r   r	   r   r   r   r   Ú<module>   s   (