o
    #if                     @   s  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	Z	d dl
mZ d dlmZ d dl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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* d dl m+Z+ d dl m,Z, d dl-Z-d dl.Z.d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 dZ5e+d ed!Z6eeeefZ7d"Z8d#e9d$e:fd%d&Z;d'e6d$e6fd(d)Z<d*e'e"d+e!f  d'e=d,e,e>e)e*e> e>e'ej? f f d-ed$e:f
d.d/Z@d'ed$efd0d1ZAd'e=d$e=fd2d3ZBd'ed$dfd4d5ZCd6ed7e=d$e%d8 fd9d:ZDd;e$d8 d7e=d$e%e= fd<d=ZEd6ed7e=d$e%e= fd>d?ZFd@e=d$eGfdAdBZHd6edCe,e=ef dDe,e=ef d$dfdEdFZIdd6ed7e=dHeGd$efdIdJZJdKed$efdLdMZKe jLfdNedOe!d$e!fdPdQZMd'ed$dfdRdSZNd'edTeOd$e:fdUdVZPd'edTeOd$dfdWdXZQd6ed7e=dYeGd$e%e fdZd[ZRd6ed$dfd\d]ZSd6ed7e=dYeGdTeOd$df
d^d_ZTd6ed7e=dYeGd`eOdHeGd$efdadbZUdce=dded$efdedfZVdge=d'e,e=dhf d$e:fdidjZWdke=d$e(e= fdldmZXdne,dhe=f doe,dhe=f dpe!d$dfdqdrZYG dsdt dteZZG dudv dve[Z\eZj]dwd'e,e=dhf dHe,e=eZf d6edxe:d$ef
dydzZ^d{e=d|ed}ed~e:d$e'e f
ddZ_de'e d|ed$e:fddZ`ejabdrde=de=d$e:fddZcnde=de=d$e:fddZcd'ed6ed$e=fddZdde#e=ef d{e=d$dfddZed'ed$e'e fddZfddd'edxe:d$e)ee=f fddZgd{e=d|ed$e:fddZhd6ed|ed$e'e= fddZiG dd de9Zjdd fd'e,e=dhf de"d8gekf d$e&d8 fddZld'e,e=dhf de"d8ge:f d$e%d8 fddZmd'dd$efddZndeded$e'e fddZodeded$e=fddZpdKed$e:fddZqdS )    N)Enum)EBADF)ELOOP)ENOENT)ENOTDIR)partial)
ModuleSpec)
expanduser)
expandvars)isabs)sep)Path)PurePath)
ModuleType)Any)Callable)Dict)Iterable)Iterator)List)Optional)Set)Tuple)Type)TypeVar)Union)assert_never)skip)PytestWarningi _AnyPurePath)bound)   i  	exceptionreturnc                 C   s    t | dd tv pt | dd tv S )Nerrnowinerror)getattr_IGNORED_ERRORS_IGNORED_WINERRORS)r"    r)   H/var/www/html/corbot_env/lib/python3.10/site-packages/_pytest/pathlib.py_ignore_error>   s   r+   pathc                 C   s
   |  dS )Nz.lock)joinpathr,   r)   r)   r*   get_lock_pathE   s   
r/   func.excinfo
start_pathc                   s  t |tr|}n|d }t |trdS t |ts,ttd| dt| d|  dS | tj	tj
tjfvrS| tjfvrQttd|  d| dt| d|  dS d	d
l dtdd
f fdd}t|}| r||jD ]}|t| ||kr{ nqm|t| | | dS )zhHandle known read-only errors during rmtree.

    The returned value is used only by our own tests.
       Fz(rm_rf) error removing 
z: z(rm_rf) unknown function z when removing z:
r   Npr#   c                    s(   t | j}t | | jB  jB  d S N)osstatst_modechmodS_IRUSRS_IWUSR)r5   moder8   r)   r*   chmod_rws   s   z on_rm_rf_error.<locals>.chmod_rwT)
isinstanceBaseExceptionFileNotFoundErrorPermissionErrorwarningswarnr   typer7   rmdirremoveunlinkopenr8   strr   is_fileparents)r0   r,   r1   r2   excr?   r5   parentr)   r>   r*   on_rm_rf_errorI   s<   



rP   c                 C   s(   t jdr|  } ttt| } | S )a0  Get the extended-length version of a path (Windows).

    On Windows, by default, the maximum length of a path (MAX_PATH) is 260
    characters, and operations on paths longer than that fail. But it is possible
    to overcome this by converting the path to "extended-length" form before
    performing the operation:
    https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation

    On Windows, this function returns the extended-length absolute version of path.
    On other platforms it returns path unchanged.
    win32)sysplatform
startswithresolver   get_extended_length_path_strrK   r.   r)   r)   r*   ensure_extended_length_path   s   rW   c                 C   s<   d}d}|  ||fr| S |  dr|| dd  S ||  S )z1Convert a path to a Windows extended length path.z\\?\z\\?\UNC\z\\   N)rT   )r,   long_path_prefixunc_long_path_prefixr)   r)   r*   rV      s   
rV   c                 C   sJ   t | } tt| d}tjdkrtjt| |d dS tjt| |d dS )zNRemove the path contents recursively, even if some elements
    are read-only.)r2   )      )onexc)onerrorN)rW   r   rP   rR   version_infoshutilrmtreerK   )r,   r^   r)   r)   r*   rm_rf   s
   
rb   rootprefixzos.DirEntry[str]c                 c   s4    |  }t| D ]}|j  |r|V  q
dS )zGFind all elements in root that begin with the prefix, case-insensitive.N)lowerr7   scandirnamerT   )rc   rd   l_prefixxr)   r)   r*   find_prefixed   s   rj   iterc                 c   s(    t |}| D ]
}|j|d V  qdS )zReturn the parts of the paths following the prefix.

    :param iter: Iterator over path names.
    :param prefix: Expected prefix of the path names.
    N)lenrg   )rk   rd   p_lenentryr)   r)   r*   extract_suffixes   s
   ro   c                 C   s   t t| ||S )z+Combine find_prefixes and extract_suffixes.)ro   rj   )rc   rd   r)   r)   r*   find_suffixes   s   rp   	maybe_numc                 C   s    zt | W S  ty   Y dS w )z0Parse number path suffixes, returns -1 on error.)int
ValueError)rq   r)   r)   r*   	parse_num   s
   
ru   targetlink_toc                 C   sP   |  |}z|  W n	 ty   Y nw z|| W dS  ty'   Y dS w )a  Helper to create the current symlink.

    It's full of race conditions that are reasonably OK to ignore
    for the context of best effort linking to the latest test run.

    The presumption being that in case of much parallelism
    the inaccuracy is going to be acceptable.
    N)r-   rI   OSError
symlink_to	Exception)rc   rv   rw   current_symlinkr)   r)   r*   _force_symlink   s   
r|     r=   c              	   C   s   t dD ]8}tttt| |dd}|d }| | | }z|j|d W n	 ty0   Y qw t| |d | |  S t	d| d|  d	)
zKCreate a directory with an increased number as suffix for the given prefix.
   rr   defaultr3   r=   currentz*could not create numbered dir with prefix z in z after 10 tries)
rangemaxmapru   rp   r-   mkdirrz   r|   rx   )rc   rd   r=   imax_existing
new_numbernew_pathr)   r)   r*   make_numbered_dir   s$   r   r5   c              
   C   s   t | }ztt|tjtjB tjB d}W n ty* } ztd|  |d}~ww t	 }t|
 }t|| t| | sHtd|S )z2Create a lock to prevent premature folder cleanup.i  zcannot create lockfile in Nz/lock path got renamed after successful creation)r/   r7   rJ   rK   O_WRONLYO_CREATO_EXCLFileExistsErrorrx   getpidencodewritecloserL   )r5   	lock_pathfdepidspidr)   r)   r*   create_cleanup_lock   s   $
r   r   registerc                 C   s,   t  }| |fdtdtddfdd}||S )zFRegister a cleanup function for removing a lock, by default on atexit.r   original_pidr#   Nc                 S   s8   t  }||kr
d S z|   W d S  ty   Y d S w r6   )r7   r   rI   rx   )r   r   current_pidr)   r)   r*   cleanup_on_exit  s   z6register_cleanup_lock_removal.<locals>.cleanup_on_exit)r7   r   r   rs   )r   r   r   r   r)   r)   r*   register_cleanup_lock_removal  s   
r   c                 C   s   t | } d}zWzt| }| j}|dt  }| | t| W n! tyD   Y W |durBz|	  W dS  tyA   Y dS w dS w W |dur\z|	  W dS  ty[   Y dS w dS |durrz|	  W w  tyq   Y w w w )z^Remove a numbered directory if its lock can be obtained and it does
    not seem to be in use.Nzgarbage-)
rW   r   rO   r-   uuiduuid4renamerb   rx   rI   )r,   r   rO   garbager)   r)   r*   maybe_delete_a_numbered_dir  s@   

r   $consider_lock_dead_if_created_beforec                 C   s   |   rdS t| }z	| sW dS W n
 ty   Y dS w z| j}W n
 ty/   Y dS w ||k rOtt |	  	 W d   dS 1 sJw   Y  dS )zGCheck if `path` is deletable based on whether the lock file is expired.FTN)

is_symlinkr/   rL   rx   r8   st_mtimerz   
contextlibsuppressrI   )r,   r   lock	lock_timer)   r)   r*   ensure_deletable:  s*    r   c                 C   s   t | |rt|  dS dS )z8Try to cleanup a folder if we can ensure it's deletable.N)r   r   )r,   r   r)   r)   r*   try_cleanupV  s   
r   keepc           
      c   st    t ttt| |dd}|| }t| |}t|\}}ttt||}t||D ]\}}	|	|kr7t	|V  q*dS )zIList candidates for numbered directories to be removed - follows py.path.rr   r   N)
r   r   ru   rp   rj   	itertoolsteero   zipr   )
rc   rd   r   r   
max_deleteentriesentries2numbersrn   numberr)   r)   r*   cleanup_candidates\  s   

r   c                 C   s.   |   D ]}| r|  s|  qd S r6   )iterdirr   rU   existsrI   )rc   left_dirr)   r)   r*   cleanup_dead_symlinksh  s   r   c                 C   sN   |   sdS t| ||D ]}t|| q| dD ]}t|| qt|  dS )z-Cleanup for lock driven numbered directories.Nz	garbage-*)r   r   r   globr   )rc   rd   r   r   r,   r)   r)   r*   cleanup_numbered_diro  s   r   lock_timeoutc                 C   s   d}t dD ]>}zt| ||}|dkrt|}t| W n ty0 }	 z|	}W Y d}	~	qd}	~	ww | j| }
tt	| |||
 |  S |dusKJ |)z>Create a numbered dir with a cleanup lock and remove old ones.Nr~   r   )
r   r   r   r   rz   r8   r   atexitr   r   )rc   rd   r   r   r=   r   r   r5   r   rN   r   r)   r)   r*   make_numbered_dir_with_cleanup}  s.   r   inputrootpathc                 C   s*   t | } t| } t| rt| S || S r6   )r	   r
   r   r   r-   )r   r   r)   r)   r*   resolve_from_str  s
   
r   patternzos.PathLike[str]c                 C   s|   t |}tjd}|rt| vrt| v r| tt} t| vr"|j}nt|}|	 r8t
j| s8dt
j |  } t|| S )a  A port of FNMatcher from py.path.common which works with PurePath() instances.

    The difference between this algorithm and PurePath.match() is that the
    latter matches "**" glob expressions for each part of the path, while
    this algorithm uses the whole path instead.

    For example:
        "tests/foo/bar/doc/test_foo.py" matches pattern "tests/**/doc/test*.py"
        with this algorithm, but not with PurePath.match().

    This algorithm was ported to keep backward-compatibility with existing
    settings which assume paths match according this logic.

    References:
    * https://bugs.python.org/issue29249
    * https://bugs.python.org/issue34731
    win*)r   rR   rS   rT   r   	posix_sepreplacerg   rK   is_absoluter7   r,   r   fnmatch)r   r,   iswin32rg   r)   r)   r*   
fnmatch_ex  s   r   sc                    s$   |  t  fddtt D S )Nc                    s&   h | ]}t  d |d  pt qS )Nr3   )r   join).0r   partsr)   r*   	<setcomp>  s   & zparts.<locals>.<setcomp>)splitr   r   rl   )r   r)   r   r*   r     s   
r   srcdstkwargsc              
   K   sP   zt j| |fi | W dS  ty' } ztd|  W Y d}~dS d}~ww )zDMake a symlink, or skip the test in case symlinks are not supported.zsymlinks not supported: N)r7   symlinkrx   r   )r   r   r   r   r)   r)   r*   symlink_or_skip  s   r   c                   @   s   e Zd ZdZdZdZdZdS )
ImportModez6Possible values for `mode` parameter of `import_path`.prependappend	importlibN)__name__
__module____qualname____doc__r   r   r   r)   r)   r)   r*   r     s
    r   c                   @      e Zd ZdZdS )ImportPathMismatchErrora  Raised on import_path() if there is a mismatch of __file__'s.

    This can happen when `import_path` is called multiple times with different filenames that has
    the same basename but reside in packages
    (for example "/tests1/test_foo.py" and "/tests2/test_foo.py").
    Nr   r   r   r   r)   r)   r)   r*   r         r   r   consider_namespace_packagesc          
      C   s  t | } t|}|  st| |tju rz
t| |d\}}W n	 ty(   Y n)w tt	 t
j| W  d   S 1 s>w   Y  t|| |dd}|durQ|S t| |}tt	 t
j| W  d   S 1 skw   Y  t|| | jdd}|du rtd| d|  |S z
t| |d\}}W n ty   | j| j}}Y nw |tju rt|t
jvrt
jt| n|tju rt|t
jd krt
jdt| nt| t| t
j| }| jd	kr|S tjd
d}|dkr?|j}|du rt||| |dr|dd }|tjd	 r |dttjd	   }z	t t| |}	W n t!y5   d}	Y nw |	s?t||| |S )aq  
    Import and return a module from the given path, which can be a file (a module) or
    a directory (a package).

    :param path:
        Path to the file to import.

    :param mode:
        Controls the underlying import mechanism that will be used:

        * ImportMode.prepend: the directory containing the module (or package, taking
          `__init__.py` files into account) will be put at the *start* of `sys.path` before
          being imported with `importlib.import_module`.

        * ImportMode.append: same as `prepend`, but the directory will be appended
          to the end of `sys.path`, if not already in `sys.path`.

        * ImportMode.importlib: uses more fine control mechanisms provided by `importlib`
          to import the module, which avoids having to muck with `sys.path` at all. It effectively
          allows having same-named test modules in different places.

    :param root:
        Used as an anchor when mode == ImportMode.importlib to obtain
        a unique name for the module being imported so it can safely be stored
        into ``sys.modules``.

    :param consider_namespace_packages:
        If True, consider namespace packages when resolving module names.

    :raises ImportPathMismatchError:
        If after importing the given `path` and the module `__file__`
        are different. Only raised in `prepend` and `append` modes.
    r   NFinsert_modulesTzCan't find module z at location r   __init__.pyPY_IGNORE_IMPORTMISMATCH 1)z.pycz.pyorr   )"r   r   r   ImportErrorr    resolve_pkg_root_and_module_nameCouldNotResolvePathErrorr   r   KeyErrorrR   modules_import_module_using_specmodule_name_from_pathrO   stemr   rK   r,   r   insertr   import_modulerg   r7   environget__file__r   endswithr   rl   _is_samerB   )
r,   r=   rc   r   pkg_rootmodule_namemodignoremodule_fileis_samer)   r)   r*   import_path  s   (
 
 






r  r   module_pathmodule_locationr   c                C   s  t jD ]}|| t|g}t||r n
qtj| t|}t||r|dus*J | d\}}}d}	|r`t j	
|}	|	du r`|jdkrI|jjn|j}
|
d  rV|
d n|
}t|||
|d}	tj|}|t j	| < |j| |	dur{t|	|| |rtt j	|  |S dS )a9  
    Tries to import a module by its canonical name, path to the .py file, and its
    parent location.

    :param insert_modules:
        If True, will call insert_missing_modules to create empty intermediate modules
        for made-up module names (when importing test files not reachable from sys.path).
    N.r   r   )rR   	meta_path	find_specrK   spec_matches_module_pathr   utilspec_from_file_location
rpartitionr   r   rg   rO   rL   r   module_from_specloaderexec_modulesetattrinsert_missing_modules)r   r  r  r   meta_importerspecparent_module_name_rg   parent_module
parent_dirparent_module_pathr   r)   r)   r*   r   k  sH   






r   module_specc                 C   s$   | du s	| j du rdS t| j |kS )zPReturn true if the given ModuleSpec can be used to import the given module path.NF)originr   )r  r  r)   r)   r*   r    s   r  r   f1f2c                 C   s   t | t |kptj| |S r6   )r   r7   r,   samefiler  r  r)   r)   r*   r     s   r   c                 C   s   t j| |S r6   )r7   r,   r  r  r)   r)   r*   r     s   c                 C   s   |  d} z| |}W n ty   | jdd }Y nw |j}t|dkr2|d dkr2|dd }tdd |D }d	|S )
z
    Return a dotted module name based on the given path, anchored on root.

    For example: path="projects/src/tests/test_foo.py" and root="/projects", the
    resulting module name will be "src.tests.test_foo".
    r   r3   NrX   rr   __init__c                 s   s    | ]	}| d dV  qdS )r  r  N)r   )r   ri   r)   r)   r*   	<genexpr>  s    z(module_name_from_path.<locals>.<genexpr>r  )with_suffixrelative_tort   r   rl   tupler   )r,   rc   relative_path
path_partsr)   r)   r*   r     s   

r   r   c                 C   s   | d}|rU|d\}}}|rG| |}|du r:ztjs tt|}W n ty5   t|dd}Y nw || |< t	||sGt
||| |  |d d|}|sdS dS )aM  
    Used by ``import_path`` to create intermediate modules when using mode=importlib.

    When we want to import a module as "src.tests.test_foo" for example, we need
    to create empty modules "src" and "src.tests" after inserting "src.tests.test_foo",
    otherwise "src.tests.test_foo" is not importable by ``__import__``.
    r  Nz6Empty module created by pytest's importmode=importlib.)docrr   )r   r
  r   rR   r  ModuleNotFoundErrorr   r   r   hasattrr  popr   )r   r   module_partsr  r  
child_namer  r)   r)   r*   r    s,   





r  c                 C   sL   d}t | f| jD ]}| r#|d  s |S |j s! |S |}q
|S )zReturn the Python package path by looking for the last
    directory upwards which still contains an __init__.py.

    Returns None if it cannot be determined.
    Nr   )r   chainrM   is_dirrL   rg   isidentifier)r,   resultrO   r)   r)   r*   resolve_package_path  s   
r.  Fr   c                C   s   d}t | }|dur|j}|r2|dur|n| j}|g|jR D ]}t|| }|r1t|| r1|} nq|durAt|| }|rA||fS td|  )a  
    Return the path to the directory of the root package that contains the
    given Python file, and its module name:

        src/
            app/
                __init__.py
                core/
                    __init__.py
                    models.py

    Passing the full path to `models.py` will yield Path("src") and "app.core.models".

    If consider_namespace_packages is True, then we additionally check upwards in the hierarchy
    for namespace packages:

    https://packaging.python.org/en/latest/guides/packaging-namespace-packages

    Raises CouldNotResolvePathError if the given path does not belong to a package (missing any __init__.py files).
    NzCould not resolve for )r.  rO   rM   compute_module_nameis_importabler   )r,   r   r   pkg_pathstart	candidater   r)   r)   r*   r     s"   

r   c              
   C   s6   zt j| }W n tttfy   Y dS w t||S )a  
    Return if the given module path could be imported normally by Python, akin to the user
    entering the REPL and importing the corresponding module name directly, and corresponds
    to the module_path specified.

    :param module_name:
        Full module name that we want to check if is importable.
        For example, "app.models".

    :param module_path:
        Full path to the python module/package we want to check if is importable.
        For example, "/projects/src/app/models.py".
    F)r   r  r  r   rt   ImportWarningr  )r   r  r  r)   r)   r*   r0  D  s   
r0  c                 C   sx   z| d}W n
 ty   Y dS w z|| }W n
 ty#   Y dS w t|j}|s-dS |d dkr7|  d|S )z8Compute a module name based on a path and a root anchor.r   Nrr   r  r  )r  rt   r   listr   r'  r   )rc   r  path_without_suffixrelativenamesr)   r)   r*   r/  ^  s    

r/  c                   @   r   )r   z<Custom exception raised by resolve_pkg_root_and_module_name.Nr   r)   r)   r)   r*   r   r  r   r   c                 C   s   | j S r6   )rg   )rn   r)   r)   r*   <lambda>x  s    r9  sort_keyc                 C   s   g }t | 0}|D ]%}z|  W n ty) } zt|r$W Y d}~q
 d}~ww || q
W d   n1 s:w   Y  |j|d |S )zScan a directory recursively, in breadth-first order.

    The returned entries are sorted according to the given key.
    The default is to sort by name.
    N)key)r7   rf   rL   rx   r+   r   sort)r,   r:  r   r   rn   errr)   r)   r*   rf   v  s    	rf   recursec                 c   sD    t | }|E dH  |D ]}| r||rt|j|E dH  qdS )zWalk a directory recursively, in breadth-first order.

    The `recurse` predicate determines whether a directory is recursed.

    Entries at each directory level are sorted.
    N)rf   r+  visitr,   )r,   r>  r   rn   r)   r)   r*   r?    s   	
r?  zUnion[str, os.PathLike[str]]c                 C   s   t tj| S )zConvert a path to an absolute path using os.path.abspath.

    Prefer this over Path.resolve() (see #6523).
    Prefer this over Path.absolute() (not public, doesn't normalize).
    )r   r7   r,   abspathr.   r)   r)   r*   absolutepath  s   rA  path1path2c                 C   s4   zt tjt| t|fW S  ty   Y dS w )zReturn the common part shared with the other path, or None if there is
    no common part.

    If one path is relative and one is absolute, returns None.
    N)r   r7   r,   
commonpathrK   rt   )rB  rC  r)   r)   r*   rD    s
   rD  	directorydestc                 C   sz   t | tsJ t |tsJ || krtjS t| |}|s t|S | |}||}tjjg tj	gt
|j |jR  S )zReturn a string which is a relative path from directory to dest such
    that directory/bestrelpath == dest.

    The paths must be either both absolute or both relative.

    If no such path can be determined, returns dest.
    )r@   r   r7   curdirrD  rK   r   r,   r   pardirrl   r   )rE  rF  basereldirectoryreldestr)   r)   r*   bestrelpath  s   


rL  c              	   C   s$   z|   W S  ttfy   Y dS w )zTLike Path.exists(), but account for input arguments that might be too long (#11394).F)r   rt   rx   )r5   r)   r)   r*   safe_exists  s
   
rM  )r}   )rr   r   enumr   r$   r   r   r   r   r   	functoolsr   importlib.machineryr   importlib.utilr   r   r7   os.pathr	   r
   r   r   pathlibr   r   	posixpathr   r`   rR   typesr   typingr   r   r   r   r   r   r   r   r   r   r   r   r   rD   _pytest.compatr   _pytest.outcomesr   _pytest.warning_typesr   LOCK_TIMEOUTr   r'   r(   rz   boolr+   r/   rK   rA   TracebackTyperP   rW   rV   rb   rj   ro   rp   rs   ru   r|   r   r   r   r   r   floatr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  rS   rT   r   r   r  r.  r   r0  r/  r   objectrf   r?  rA  rD  rL  rM  r)   r)   r)   r*   <module>   s   	
=





!	$





~
@
&

,



	