o
    ¨i*  ã                   @   s‚   d dl Z d dlmZmZ d dlmZ d dlmZ d dlm	Z	m
Z
 ddeB ee B deedf fd	d
„Ze	ddG dd„ dƒƒZdS )é    N)ÚIterableÚSequence)ÚAny)Úfield)ÚfrozenÚto_tuple_converterÚvalueÚreturn.c                 C   s   t dd„ t| ƒD ƒƒS )Nc                 s   s    | ]
}|  ¡  d ¡V  qdS )Ú.N)ÚlowerÚlstrip)Ú.0Úe© r   ú_/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/cyclopts/validators/_path.pyÚ	<genexpr>   s   € z ext_converter.<locals>.<genexpr>)Útupler   )r   r   r   r   Úext_converter
   s   r   T)Úkw_onlyc                   @   st   e Zd ZU dZdZeed< 	 dZeed< 	 dZeed< 	 e	de
dZeee B ed	< 	 d
d„ Zdedefdd„ZdS )ÚPathu  Assertions on properties of :class:`pathlib.Path`.

    Example Usage:

    .. code-block:: python

        from cyclopts import App, Parameter, validators
        from pathlib import Path
        from typing import Annotated

        app = App()


        @app.default
        def main(
            # ``src`` must be a file that exists.
            src: Annotated[Path, Parameter(validator=validators.Path(exists=True, dir_okay=False))],
            # ``dst`` must be a path that does **not** exist.
            dst: Annotated[Path, Parameter(validator=validators.Path(dir_okay=False, file_okay=False))],
        ):
            "Copies src->dst."
            dst.write_bytes(src.read_bytes())


        app()

    .. code-block:: console

        $ my-script foo.bin bar.bin  # if foo.bin does not exist
        â•­â”€ Error â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â•®
        â”‚ Invalid value "foo.bin" for "SRC". "foo.bin" does not exist.  â”‚
        â•°â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â•¯

        $ my-script foo.bin bar.bin  # if bar.bin exists
        â•­â”€ Error â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â•®
        â”‚ Invalid value "bar.bin" for "DST". "bar.bin" already exists.  â”‚
        â•°â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â•¯
    FÚexistsTÚ	file_okayÚdir_okayN)ÚdefaultÚ	converterÚextc                 C   s&   | j r| js| jstdƒ‚d S d S d S )NzK(exists=True, file_okay=False, dir_okay=False) is an invalid configuration.)r   r   r   Ú
ValueError)Úselfr   r   r   Ú__attrs_post_init__W   s   ÿzPath.__attrs_post_init__Útype_Úpathc                 C   sL  t |tƒrt |tƒrt‚|D ]}| ||ƒ qd S t |tjƒs d S | jr]|j ¡  	d¡| jvr]t
| jƒdkrCtd|› d| jd › dƒ‚dd d	d
„ | jD ƒ¡ d }td|› d|› dƒ‚| ¡ r™| js{| ¡ r{| jrstd|› dƒ‚td|› dƒ‚| js•| ¡ r—| jrtd|› dƒ‚td|› dƒ‚d S d S | jr¤td|› dƒ‚d S )Nr
   é   ú"z" must have extension "r   z".Ú{z, c                 s   s    | ]	}d |› d V  qdS )r"   Nr   )r   Úxr   r   r   r   j   s   € z Path.__call__.<locals>.<genexpr>Ú}z-" does not match one of supported extensions z Only directory is allowed, but "z" is a file.z" already exists.zOnly file is allowed, but "z" is a directory.z" does not exist.)Ú
isinstancer   ÚstrÚ	TypeErrorÚpathlibr   r   Úsuffixr   r   Úlenr   Újoinr   r   Úis_filer   Úis_dir)r   r   r    ÚpÚ
pretty_extr   r   r   Ú__call__[   s4   

ÿüÿzPath.__call__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   r   r   r'   r   r   r   r1   r   r   r   r   r      s   
 '
r   )r)   Úcollections.abcr   r   Útypingr   Úattrsr   Úcyclopts.utilsr   r   r   r'   r   r   r   r   r   r   Ú<module>   s    &