
    Ji{A                       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r$d 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             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,d       Z+e	 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!       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)inspect)visit)LinesCollection)load)ModuleObject)IteratorMappingSequence)ModulesCollection)DocstringOptions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    h/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/griffe/_internal/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        |       d       ||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.pyutf8encodingN)tempfileTemporaryDirectory_TMPDIR_PREFIXr   
write_textr   )coder0   r   tmpfiles       r#   temporary_pyfiler>   5   sc      
	$	$N	; #vv,K=!446$<&97""# # #s   A&4A	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 ]x  }|j                  d      r,|j                  |      j                  t!        |
      d	       @||z  } |j                  di | |sZ|j                  d      j                          z  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.pyir5   r6   Nr-   )
isinstancelistdictfromkeysr8   r9   r:   r   joinpartsmkdirjoinpathtouchitemsendswithr;   r   r   )packagemodulesr@   rA   mkdir_kwargsr   
tmpdirpathpackage_namepackage_pathr0   module_contentscurrent_pathparts                r#   temporary_pypackager\   G   sj    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]c:d D(L&L&&66$--m<BBDE		E \<@@#A A As%   AFC.E8=2E8/	F8F=FF)r@   rA   
extensionsdocstring_parserdocstring_optionslines_collectionmodules_collectionallow_inspectionstore_sourceresolve_aliasesresolve_externalresolve_implicitsearch_sys_pathc             #     K   |rt         j                  ng }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: 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`   ra   rb   rc   rd   re   rf   force_inspectionN)sysr   r\   r   r   r   )rS   rT   r@   rA   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rj   tmp_packages                    r#   temporary_visited_packagern   x   s     b  /388BL	WgD	F 
+%,,<|<!-/-1-%+--"
 	

 
 
s   $A-2A!	A-!A*&A-c             #    K   |rt         j                  ng }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)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?   Tri   rF   N)rl   r   r\   r   r   r   tuplerT   keys
startswithpopr   )rS   rT   r@   rA   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rj   rm   r   s                     r#   temporary_inspected_packagert      s8    b  /388BL	WgD	F  +	   )00@<@%!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   $EE1CAE,E
	EAE-EEEE)r0   r]   parentr^   r_   r`   ra   c             #     K   t        |       } t        | |      5 \  }}	|xs
 t               }| j                         ||	<   t	        ||	| ||||||	      }
|
|
j
                  |<   |
 ddd       y# 1 sw Y   yxY ww)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]   ru   r^   r_   r`   ra   N)r   r>   r   
splitlinesr   ra   )r<   r0   r]   ru   r^   r_   r`   ra   _r   r.   s              r#   temporary_visited_modulerz     s     6 $<D	$K	8 IQ+@/@!%!2!-/-1

 28!!+.  s   A<AA0'	A<0A95A<)r0   import_pathsr]   ru   r^   r_   r`   ra   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: Docstring parsing options.
        lines_collection: A collection of source code lines.
        modules_collection: A collection of modules.

    Yields:
        The inspected module.
    r/   )rw   r{   r]   ru   r^   r_   r`   ra   N)r>   r   rx   r
   ra   rl   rT   r   )r<   r0   r{   r]   ru   r^   r_   r`   ra   ry   r   r.   s               r#   temporary_inspected_moduler}   4  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   )r~   objectstopleafobjs        r#   vtreer   h  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     sH     ?@@
!*Cqr{ &sxx%&Jr%   )leaf_packager~   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.
    rF   NrG   )rw   r~   )split	enumerater   r   rw   	with_stem	_filepathr   )r   r   r~   rM   indexr   rT   rw   s           r#   module_vtreer     s     JJsOE]fgl]mnkeUYvdT%H5%=%H-%HInGn2;''11%)< ('3{33	 os   %B )r<   r   r0   r   r&   zIterator[tuple[str, Path]]r    )
rS   r   rT   (Sequence[str] | Mapping[str, str] | Noner@   boolrA   r   r&   zIterator[TmpPackage]) rS   r   rT   r   r@   r   rA   r   r]   Extensions | Noner^   DocstringStyle | Parser | Noner_   DocstringOptions | Noner`   LinesCollection | Nonera   ModulesCollection | Nonerb   r   rc   r   rd   r   re   zbool | Nonerf   r   rg   r   r&   Iterator[Module])r<   r   r0   r   r]   r   ru   Module | Noner^   r   r_   r   r`   r   ra   r   r&   r   )r<   r   r0   r   r{   zlist[Path] | Noner]   r   ru   r   r^   r   r_   r   r`   r   ra   r   r&   r   )r   r   r~   r   r&   r   )r   r   r&   r   )r   r   r   r   r~   r   r&   r   )2
__future__r   rl   r8   
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   r:   r   r>   r\   rn   rt   rz   r}   r   r   r   r-   r%   r#   <module>r      s  
 # 
  % ! '     5 1 8 ( 2;;>T4; ( ( (& 6> # #"  9=-A -A-A5-A 	-A
 -A -A -A`  9=@
 $(7;15/337"!$("!!@
@
5@
 	@

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