
    5'h?                       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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r"d dlmZmZmZ d dlm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z& dZ'e G d d             Z(eddd)d       Z)e	 d*ddd	 	 	 	 	 	 	 	 	 d+d       Z*e	 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       Z,edddddddd 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d-d!       Z-eddddddddd"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d.d#       Z.dd$d/d%Z/d0d&Z0ddd'd1d(Z1y)2    )annotationsN)contextmanager)	dataclass)invalidate_caches)Path)dedent)TYPE_CHECKINGAny)inspect)visit)LinesCollection)load)ModuleObject)IteratorMappingSequence)ModulesCollection)DocstringStyle)Parser)
Extensionsgriffe_c                  >    e Zd ZU dZded<   	 ded<   	 ded<   	 d	dZy)

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pathc                    | j                   j                         | _         | j                  j                         | _        y N)r   resolver   )selfs    T/home/kushmeetdev/Regenta/Chatbot/venv/lib/python3.12/site-packages/_griffe/tests.py__post_init__zTmpPackage.__post_init__0   s*    kk))+II%%'	    N)returnNone)__name__
__module____qualname____doc____annotations__r$    r%   r#   r   r   !   s&     L9
I8
J(r%   r   modulemodule_namec             #     K   t        j                  t              5 }t        |      | dz  }|j	                  t        |              ||f ddd       y# 1 sw Y   yxY ww)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.pyN)tempfileTemporaryDirectory_TMPDIR_PREFIXr   
write_textr   )coder0   r   tmpfiles       r#   temporary_pyfiler;   5   s^      
	$	$N	; #vv,K=!446$<(7""# # #s   A$2A	A$A!A$Tinitinitsc             #    K   |xs i }t        |t              rt        j                  |d      }ddd}t	        j
                  t              5 }t        |      }dj                  t        |       j                        }|| z  } |j                  d	i | |r|j                  d      j                          |j                         D ]  \  }	}
|}t        |	      j                  D ]v  }|j                  d      r*|j                  |      j                  t!        |
             >||z  } |j                  d	i | |sX|j                  d      j                          x  t#        |||       ddd       y# 1 sw Y   yxY ww)
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_okr2   .__init__.py)r4   z.pyiNr-   )
isinstancelistdictfromkeysr5   r6   r7   r   joinpartsmkdirjoinpathtouchitemsendswithr8   r   r   )packagemodulesr=   r>   mkdir_kwargsr   
tmpdirpathpackage_namepackage_pathr0   module_contentscurrent_pathparts                r#   temporary_pypackagerY   G   sd    2 mG'4 --,#6L		$	$N	; Av&\
xxW 3 34!G+*\*!!-0668,3MMO 		E(K'L[)// E==1 ))$/::6/;RS D(L&L&&66$--m<BBDE		E \<@@#A A As%   AFC,E6;2E6-	F6E?;FF)r=   r>   
extensionsdocstring_parserdocstring_optionslines_collectionmodules_collectionallow_inspectionstore_sourceresolve_aliasesresolve_externalresolve_implicitc             #     K   t        | |||      5 }t        |j                  |j                  g||||||	|
|||d       ddd       y# 1 sw Y   yxY ww)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: Additional 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.

    Yields:
        A module.
    r<   Fsearch_pathsrZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   force_inspectionN)rY   r   r   r   )rP   rQ   r=   r>   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   tmp_packages                  r#   temporary_visited_packageri   x   sp     ^ 
WgD	F 
+%,,-!-/-1-%+--"
 	

 
 
s   A0A	AAAc             #    K   t        | |||      5 }	 t        |j                  |j                  g||||||	|
|||d       t	        t
        j                  j                               D ]<  }|| k(  s|j                  |  d      st
        j                  j                  |d       > t                	 ddd       y# t	        t
        j                  j                               D ]<  }|| k(  s|j                  |  d      st
        j                  j                  |d       > t                w xY w# 1 sw Y   yxY ww)ab  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: Additional 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.

    Yields:
        A module.
    r<   Tre   rC   N)rY   r   r   r   tuplesysrQ   keys
startswithpopr   )rP   rQ   r=   r>   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rh   r   s                   r#   temporary_inspected_packagerp      s&    ^ 
WgD	F  +	   )001%!1"3!1#5!1) /!1!1!%   ckk..01 07?doo	m&DKKOOD$/0 +   $ ckk..01 07?doo	m&DKKOOD$/0 +   sA   D>D2/B=AD2,D24	D>=AD/-D//D22D;7D>)r0   rZ   parentr[   r\   r]   r^   c             #     K   t        |       } t        | |      5 \  }}	|xs
 t               }| j                         ||	<   t	        ||	| ||||||	      }
|
|
j
                  |<   |
 ddd       y# 1 sw Y   yxY ww)aS  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: Additional docstring parsing options.
        lines_collection: A collection of source code lines.
        modules_collection: A collection of modules.

    Yields:
        The visited module.
    r/   )filepathr9   rZ   rq   r[   r\   r]   r^   N)r   r;   r   
splitlinesr   r^   )r9   r0   rZ   rq   r[   r\   r]   r^   _r   r.   s              r#   temporary_visited_modulerv      s     6 $<D	$K	8 IQ+@/@!%!2!-/-1

 28!!+.  s   A<AA0'	A<0A95A<)r0   import_pathsrZ   rq   r[   r\   r]   r^   c             #    K   t        | |      5 \  }	}
|xs
 t               }| j                         ||
<   	 t        ||
|||||||	      }||j                  |<   | |t
        j                  v rt
        j                  |= t                	 ddd       y# |t
        j                  v rt
        j                  |= t                w xY w# 1 sw Y   yxY ww)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: Additional docstring parsing options.
        lines_collection: A collection of source code lines.
        modules_collection: A collection of modules.

    Yields:
        The inspected module.
    r/   )rs   rw   rZ   rq   r[   r\   r]   r^   N)r;   r   rt   r   r^   rl   rQ   r   )r9   r0   rw   rZ   rq   r[   r\   r]   r^   ru   r   r.   s               r#   temporary_inspected_modulery   .  s     : 
$K	8  IQ+@/@!%!2	 )%!1"3!1#5
F 6<F%%k2Lckk)KK,)   $ ckk)KK,)   s3   C%C'B-C	C/CCCC)return_leafc                    |st        d      |d   }|}|dd D ]   }|j                  |j                  |       |}" | 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   )rz   objectstopleafobjs        r#   vtreer   b  s\     ?@@
!*CDqr{ #& 4'C'r%   c                 v    | st        d      | d   }| dd D ]  }|j                  |j                  |         |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   s      r#   htreer   y  sH     ?@@
!*Cqr{ &sxx%&Jr%   )leaf_packagerz   c                  | j                  d      }t        |      D cg c]   \  }}t        |t        g |d| d       " }}}|s+|d   j                  j                  |d         }||d   _        t        |d|iS c c}}w )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.
    rC   NrD   )rs   rz   )split	enumerater   r   rs   	with_stem	_filepathr   )r   r   rz   rJ   indexr   rQ   rs   s           r#   module_vtreer     s     JJsOE]fgl]mnkeUYvdT%H5%=%H-%HInGn2;''11%)< ('3{33	 os   %B )r9   r   r0   r   r&   zIterator[tuple[str, Path]]r    )
rP   r   rQ   (Sequence[str] | Mapping[str, str] | Noner=   boolr>   r   r&   zIterator[TmpPackage])rP   r   rQ   r   r=   r   r>   r   rZ   Extensions | Noner[   DocstringStyle | Parser | Noner\   dict[str, Any] | Noner]   LinesCollection | Noner^   ModulesCollection | Noner_   r   r`   r   ra   r   rb   zbool | Nonerc   r   r&   Iterator[Module])r9   r   r0   r   rZ   r   rq   Module | Noner[   r   r\   r   r]   r   r^   r   r&   r   )r9   r   r0   r   rw   zlist[Path] | NonerZ   r   rq   r   r[   r   r\   r   r]   r   r^   r   r&   r   )r   r   rz   r   r&   r   )r   r   r&   r   )r   r   r   r   rz   r   r&   r   )2
__future__r   rl   r5   
contextlibr   dataclassesr   	importlibr   pathlibr   textwrapr   typingr	   r
   _griffe.agents.inspectorr   _griffe.agents.visitorr   _griffe.collectionsr   _griffe.loaderr   _griffe.modelsr   r   collections.abcr   r   r   r   _griffe.docstrings.parsersr   _griffe.enumerationsr   _griffe.extensions.baser   r7   r   r;   rY   ri   rp   rv   ry   r   r   r   r-   r%   r#   <module>r      s  
 # 
  % ! '   % , ( /  );;59+2 ( ( (& 6> # #"  9=-A -A-A5-A 	-A
 -A -A -A`  9==
 $(7;/3/337"!$("=
=
5=
 	=

 =
 "=
 5=
 -=
 -=
 1=
 =
 =
 =
 "=
 =
  !=
 =
@  9=C  $(7;/3/337!!$("C C 5C  	C 
 C  "C  5C  -C  -C  1C  C  C  C  "C  C   !C  C L   $( 7;/3/337*
* * "	*
 * 5* -* -* 1* * *Z   &*$( 7;/3/3370 
0  0  $	0 
 "0  0  50  -0  -0  10  0  0 f 16 (.( 59e 4r%   