o
    i{A                     @  s  d dl m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 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 d dlmZmZ erxd dlmZmZmZ d dlmZ d dl m!Z!m"Z" d dl#m$Z$ d dl%m&Z& dZ'eG dd dZ(edddZddZ)e	d[ddd d\d(d)Z*e	d[dddddddd*dd*dd*d*d+d]d>d?Z+e	d[dddddddddd*dd*d*d+d]d@dAZ,eddddddddBd^dEdFZ-edddddddddGd_dJdKZ.d*dLd`dPdQZ/dadRdSZ0dd*dTdbdXdYZ1dS )c    )annotationsN)contextmanager)	dataclass)invalidate_caches)Path)dedent)TYPE_CHECKING)inspect)visit)LinesCollection)load)ModuleObject)IteratorMappingSequence)ModulesCollection)DocstringOptionsDocstringStyle)Parser)
Extensionsgriffe_c                   @  s:   e Zd ZU dZded< 	 ded< 	 ded< 	 dd	d
ZdS )
TmpPackagezA temporary package.

    The `tmpdir` and `path` parameters can be passed as relative path.
    They will be resolved to absolute paths after initialization.
    r   tmpdirstrnamepathreturnNonec                 C  s   | j  | _ | j | _d S N)r   resolver   )self r"   \/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/griffe/_internal/tests.py__post_init__0   s   zTmpPackage.__post_init__N)r   r   )__name__
__module____qualname____doc____annotations__r$   r"   r"   r"   r#   r   !   s   
 r   modulemodule_namecoder   r,   r   Iterator[tuple[str, Path]]c                c  sb    t jtd }t|| d }|jt| dd ||fV  W d   dS 1 s*w   Y  dS )aB  Create a Python file containing the given code in a temporary directory.

    Parameters:
        code: The code to write to the temporary file.
        module_name: The name of the temporary module.

    Yields:
        module_name: The module name, as to dynamically import it.
        module_path: The module path.
    prefix.pyutf8encodingN)tempfileTemporaryDirectory_TMPDIR_PREFIXr   
write_textr   )r-   r,   r   tmpfiler"   r"   r#   temporary_pyfile5   s   "r:   Tinitinitspackagemodules(Sequence[str] | Mapping[str, str] | Noner<   boolr=   Iterator[TmpPackage]c                c  s    |pi }t |trt|d}ddd}tjtdk}t|}dt| j	}||  }|j
di | |r=|d  | D ]5\}	}
|}t|	j	D ])}|dr`||jt|
dd	 qL|| }|j
di | |ru|d  qLqAt|||V  W d
   d
S 1 sw   Y  d
S )a(  Create a package containing the given modules in a temporary directory.

    Parameters:
        package: The package name. Example: `"a"` gives
            a package named `a`, while `"a/b"` gives a namespace package
            named `a` with a package inside named `b`.
            If `init` is false, then `b` is also a namespace package.
        modules: Additional modules to create in the package.
            If a list, simply touch the files: `["b.py", "c/d.py", "e/f"]`.
            If a dict, keys are the file names and values their contents:
            `{"b.py": "b = 1", "c/d.py": "print('hey from c')"}`.
        init: Whether to create an `__init__` module in the top package.
        inits: Whether to create `__init__` modules in subpackages.

    Yields:
        A temporary package.
     T)parentsexist_okr/   .__init__.py)r1   z.pyir2   r3   Nr"   )
isinstancelistdictfromkeysr5   r6   r7   r   joinpartsmkdirjoinpathtouchitemsendswithr8   r   r   )r>   r?   r<   r=   mkdir_kwargsr   
tmpdirpathpackage_namepackage_pathr,   module_contentscurrent_pathpartr"   r"   r#   temporary_pypackageG   s2   


"rZ   F)r<   r=   
extensionsdocstring_parserdocstring_optionslines_collectionmodules_collectionallow_inspectionstore_sourceresolve_aliasesresolve_externalresolve_implicitsearch_sys_pathr[   Extensions | Noner\   DocstringStyle | Parser | Noner]   DocstringOptions | Noner^   LinesCollection | Noner_   ModulesCollection | Noner`   ra   rb   rc   bool | Nonerd   re   Iterator[Module]c                c  st    |rt jng }t| |||d }t|j|jg|||||||	|
|||ddV  W d   dS 1 s3w   Y  dS )a  Create and visit a temporary package.

    Parameters:
        package: The package name. Example: `"a"` gives
            a package named `a`, while `"a/b"` gives a namespace package
            named `a` with a package inside named `b`.
            If `init` is false, then `b` is also a namespace package.
        modules: Additional modules to create in the package.
            If a list, simply touch the files: `["b.py", "c/d.py", "e/f"]`.
            If a dict, keys are the file names and values their contents:
            `{"b.py": "b = 1", "c/d.py": "print('hey from c')"}`.
        init: Whether to create an `__init__` module in the top package.
        inits: Whether to create `__init__` modules in subpackages.
        extensions: The extensions to use.
        docstring_parser: The docstring parser to use. By default, no parsing is done.
        docstring_options: Docstring parsing options.
        lines_collection: A collection of source code lines.
        modules_collection: A collection of modules.
        allow_inspection: Whether to allow inspecting modules when visiting them is not possible.
        store_source: Whether to store code source in the lines collection.
        resolve_aliases: Whether to resolve aliases.
        resolve_external: Whether to try to load unspecified modules to resolve aliases.
            Default value (`None`) means to load external modules only if they are the private sibling
            or the origin module (for example when `ast` imports from `_ast`).
        resolve_implicit: When false, only try to resolve an alias if it is explicitly exported.
        search_sys_path: Whether to search the system paths for the package.

    Yields:
        A module.
    r;   Fsearch_pathsr[   r\   r]   r^   r_   r`   ra   rb   rc   rd   force_inspectionN)sysr   rZ   r   r   r   )r>   r?   r<   r=   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rn   tmp_packager"   r"   r#   temporary_visited_packagex   s&   1

"rr   c                c  s    |rt jng }t| |||dd}z9t|j|jg|||||||	|
|||ddV  W tt j D ]}|| ks?|	|  drFt j
|d q1t  n!tt j D ]}|| ks`|	|  drgt j
|d qRt  w W d   dS 1 sww   Y  dS )a  Create and inspect a temporary package.

    Parameters:
        package: The package name. Example: `"a"` gives
            a package named `a`, while `"a/b"` gives a namespace package
            named `a` with a package inside named `b`.
            If `init` is false, then `b` is also a namespace package.
        modules: Additional modules to create in the package.
            If a list, simply touch the files: `["b.py", "c/d.py", "e/f"]`.
            If a dict, keys are the file names and values their contents:
            `{"b.py": "b = 1", "c/d.py": "print('hey from c')"}`.
        init: Whether to create an `__init__` module in the top package.
        inits: Whether to create `__init__` modules in subpackages.
        extensions: The extensions to use.
        docstring_parser: The docstring parser to use. By default, no parsing is done.
        docstring_options: Docstring parsing options.
        lines_collection: A collection of source code lines.
        modules_collection: A collection of modules.
        allow_inspection: Whether to allow inspecting modules.
        store_source: Whether to store code source in the lines collection.
        resolve_aliases: Whether to resolve aliases.
        resolve_external: Whether to try to load unspecified modules to resolve aliases.
            Default value (`None`) means to load external modules only if they are the private sibling
            or the origin module (for example when `ast` imports from `_ast`).
        resolve_implicit: When false, only try to resolve an alias if it is explicitly exported.
        search_sys_path: Whether to search the system paths for the package.

    Yields:
        A module.
    r;   Trm   rF   N)rp   r   rZ   r   r   r   tupler?   keys
startswithpopr   )r>   r?   r<   r=   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rn   rq   r   r"   r"   r#   temporary_inspected_package   s<   1


"rw   )r,   r[   parentr\   r]   r^   r_   rx   Module | Nonec                c  s    t | } t| |d+\}}	|pt }|  ||	< t||	| ||||||d	}
|
|
j|< |
V  W d   dS 1 s9w   Y  dS )aH  Create and visit a temporary module with the given code.

    Parameters:
        code: The code of the module.
        module_name: The name of the temporary module.
        extensions: The extensions to use when visiting the AST.
        parent: The optional parent of this module.
        docstring_parser: The docstring parser to use. By default, no parsing is done.
        docstring_options: Docstring parsing options.
        lines_collection: A collection of source code lines.
        modules_collection: A collection of modules.

    Yields:
        The visited module.
    r+   )filepathr-   r[   rx   r\   r]   r^   r_   N)r   r:   r   
splitlinesr
   r_   )r-   r,   r[   rx   r\   r]   r^   r_   _r   r*   r"   r"   r#   temporary_visited_module  s&   

"r}   )r,   import_pathsr[   rx   r\   r]   r^   r_   r~   list[Path] | Nonec                c  s    t | |dG\}	}
|pt }|  ||
< z#t||
|||||||d	}||j|< |V  W |tjv r5tj|= t  n|tjv rBtj|= t  w W d   dS 1 sQw   Y  dS )a  Create and inspect a temporary module with the given code.

    Parameters:
        code: The code of the module.
        module_name: The name of the temporary module.
        import_paths: Paths to import the module from.
        extensions: The extensions to use when visiting the AST.
        parent: The optional parent of this module.
        docstring_parser: The docstring parser to use. By default, no parsing is done.
        docstring_options: Docstring parsing options.
        lines_collection: A collection of source code lines.
        modules_collection: A collection of modules.

    Yields:
        The inspected module.
    r+   )rz   r~   r[   rx   r\   r]   r^   r_   N)r:   r   r{   r	   r_   rp   r?   r   )r-   r,   r~   r[   rx   r\   r]   r^   r_   r|   r   r*   r"   r"   r#   temporary_inspected_module4  s2   




"r   )return_leafobjectsr   r   c                 G  sH   |st d|d }|}|dd D ]}||j| |}q| r"|S |S )a<  Link objects together, vertically.

    Parameters:
        *objects: A sequence of objects. The first one is at the top of the tree.
        return_leaf: Whether to return the leaf instead of the root.

    Raises:
        ValueError: When no objects are provided.

    Returns:
        The top or leaf object.
    $At least one object must be providedr      N
ValueError
set_memberr   )r   r   topleafobjr"   r"   r#   vtreeh  s   r   c                  G  s8   | st d| d }| dd D ]	}||j| q|S )a=  Link objects together, horizontally.

    Parameters:
        *objects: A sequence of objects. All objects starting at the second become members of the first.

    Raises:
        ValueError: When no objects are provided.

    Returns:
        The first given object, with all the other objects as members of it.
    r   r   r   Nr   )r   r   r   r"   r"   r#   htree  s   r   )leaf_packager   r   r   r   c                  sP   |  d  fddt D }|s!|d j d }||d _t|d|iS )ao  Link objects together, vertically.

    Parameters:
        path: The complete module path, like `"a.b.c.d"`.
        leaf_package: Whether the deepest module should also be a package.
        return_leaf: Whether to return the leaf instead of the root.

    Raises:
        ValueError: When no objects are provided.

    Returns:
        The top or leaf module.
    rF   c              	     s2   g | ]\}}t |tg  d | dR  dqS )NrG   )rz   )r   r   ).0indexr   rM   r"   r#   
<listcomp>  s   2 z module_vtree.<locals>.<listcomp>r   )split	enumeraterz   	with_stem	_filepathr   )r   r   r   r?   rz   r"   r   r#   module_vtree  s   

r   )r-   r   r,   r   r   r.   r   )
r>   r   r?   r@   r<   rA   r=   rA   r   rB   ) r>   r   r?   r@   r<   rA   r=   rA   r[   rf   r\   rg   r]   rh   r^   ri   r_   rj   r`   rA   ra   rA   rb   rA   rc   rk   rd   rA   re   rA   r   rl   )r-   r   r,   r   r[   rf   rx   ry   r\   rg   r]   rh   r^   ri   r_   rj   r   rl   )r-   r   r,   r   r~   r   r[   rf   rx   ry   r\   rg   r]   rh   r^   ri   r_   rj   r   rl   )r   r   r   rA   r   r   )r   r   r   r   )r   r   r   rA   r   rA   r   r   )2
__future__r   rp   r5   
contextlibr   dataclassesr   	importlibr   pathlibr   textwrapr   typingr   !griffe._internal.agents.inspectorr	   griffe._internal.agents.visitorr
   griffe._internal.collectionsr   griffe._internal.loaderr   griffe._internal.modelsr   r   collections.abcr   r   r   r   #griffe._internal.docstrings.parsersr   r   griffe._internal.enumerationsr    griffe._internal.extensions.baser   r7   r   r:   rZ   rr   rw   r}   r   r   r   r   r"   r"   r"   r#   <module>   s   0CI-3
