a
    !fi                     @   s,  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dl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	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.m/Z/ d dl0m1Z1 dZ2e*dedZ3eeeefZ4d Z5d!d" Z6e3e3d#d$d%Z7e8e+e9e(e)e9 e9e&e	j: f f ee;d&d'd(Z<eed#d)d*Z=e8e8d#d+d,Z>edd#d-d.Z?ee8e$e d/d0d1Z@e#e e8e$e8 d2d3d4ZAee8e$e8 d/d5d6ZBeCd7d8d9ZDee+e8ef e+e8ef dd:d;d<ZEdee8eCed>d?d@ZFeedAdBdCZGe jHfedDdEdFZIedd#dGdHZJeeKe;dIdJdKZLeeKddIdLdMZMee8eCe$e dNdOdPZNedQdRdSZOee8eCeKddTdUdVZPee8eCeKeCedWdXdYZQe8eedZd[d\ZRe8e+e8d]f e;d^d_d`ZSe8e'e8 dadbdcZTddde ZUG dfdg dgeZVG dhdi dieWZXeVjYdje+e8d]f e+e8eVf eedkdldmZZej[\dnr0e8e8e;dodpdqZ]ne8e8e;dodrdqZ]eee8dsdtduZ^e"e8ef e8ddvdwdxZ_ee&e d#dydzZ`e+e8d]f e%d{ d#d|d}Zae+e8d]f e!d{ge;f e$d{ d~ddZbe+ee8f ed#ddZceee&e dddZdeee8dddZeeeddddZfee;dAddZgdS )    N)Enum)EBADF)ELOOP)ENOENT)ENOTDIR)partial)
expanduser)
expandvars)isabs)sep)Path)PurePath)
ModuleType)Callable)Dict)Iterable)Iterator)List)Optional)Set)Tuple)Type)TypeVar)Union)assert_never)skip)PytestWarningi _AnyPurePath)bound)   i  c                 C   s    t | dd tv pt | dd tv S )Nerrnowinerror)getattr_IGNORED_ERRORS_IGNORED_WINERRORS)	exception r&   P/var/www/html/python-backend/venv/lib/python3.9/site-packages/_pytest/pathlib.py_ignore_error;   s    r(   )pathreturnc                 C   s
   |  dS )Nz.lock)joinpathr)   r&   r&   r'   get_lock_pathB   s    r-   )r)   excinfo
start_pathr*   c             	      s  t |tr|}n|d }t |tr&dS t |tsXttd| dt| d|  dS | tj	tj
tjfvr| tjfvrttd| |t|| dS ddl tdd	 fd
d}t|}| r|jD ]}|t| ||kr qq|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: z4(rm_rf) unknown function {} when removing {}:
{}: {}r   Npr*   c                    s(   t | j}t | | jB  jB  d S N)osstatst_modechmodS_IRUSRS_IWUSR)r3   moder6   r&   r'   chmod_rwr   s    z on_rm_rf_error.<locals>.chmod_rwT)
isinstanceBaseExceptionFileNotFoundErrorPermissionErrorwarningswarnr   typer5   rmdirremoveunlinkopenformatr6   strr   is_fileparents)funcr)   r.   r/   excr=   r3   parentr&   r<   r'   on_rm_rf_errorF   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_strrJ   r,   r&   r&   r'   ensure_extended_length_path   s    rW   c                 C   s<   d}d}|  ||fr| S |  dr4|| dd  S ||  S )z1Convert a path to a Windows extended length path.z\\?\z\\?\UNC\z\\   N)rT   )r)   Zlong_path_prefixZunc_long_path_prefixr&   r&   r'   rV      s    
rV   c                 C   sH   t | } tt| d}tjdkr2tjt| |d ntjt| |d dS )zNRemove the path contents recursively, even if some elements
    are read-only.)r/   )      )Zonexc)onerrorN)rW   r   rP   rR   version_infoshutilrmtreerJ   )r)   r[   r&   r&   r'   rm_rf   s
    
r_   )rootprefixr*   c                 c   s0   |  }|  D ]}|j  |r|V  qdS )zGFind all elements in root that begin with the prefix, case insensitive.N)loweriterdirnamerT   )r`   ra   Zl_prefixxr&   r&   r'   find_prefixed   s    rf   )iterra   r*   c                 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)lenrd   )rg   ra   Zp_lenr3   r&   r&   r'   extract_suffixes   s    ri   c                 C   s   t t| ||S )z+Combine find_prefixes and extract_suffixes.)ri   rf   )r`   ra   r&   r&   r'   find_suffixes   s    rj   )r*   c                 C   s$   z
t | W S  ty   Y dS 0 dS )z0Parse number path suffixes, returns -1 on error.N)int
ValueError)Z	maybe_numr&   r&   r'   	parse_num   s    
rn   )r`   targetlink_tor*   c                 C   sP   |  |}z|  W n ty(   Y n0 z|| W n tyJ   Y n0 dS )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+   rG   OSError
symlink_to	Exception)r`   ro   rp   Zcurrent_symlinkr&   r&   r'   _force_symlink   s    
rt     )r`   ra   r;   r*   c              	   C   s   t dD ]r}tttt| |dd}|d }| | | }z|j|d W n ty`   Y q0 t| |d | |  S qt	dj
|| dd	S )
zKCreate a directory with an increased number as suffix for the given prefix.
   rk   defaultr0   r;   currentzKcould not create numbered dir with prefix {prefix} in {root} after 10 tries)ra   r`   N)rangemaxmaprn   rj   r+   mkdirrs   rt   rq   rI   )r`   ra   r;   imax_existingZ
new_numbernew_pathr&   r&   r'   make_numbered_dir   s    
r   r2   c              
   C   s   t | }z$tt|tjtjB tjB d}W n4 ty` } ztd|  |W Y d}~nHd}~0 0 t	 }t|
 }t|| t| | std|S 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-   r5   rH   rJ   O_WRONLYO_CREATO_EXCLFileExistsErrorrq   getpidencodewritecloserK   )r3   	lock_pathfdepidZspidr&   r&   r'   create_cleanup_lock   s    $&
r   )r   c                 C   s(   t  }| |fttdddd}||S )zFRegister a cleanup function for removing a lock, by default on atexit.N)r   original_pidr*   c                 S   s8   t  }||krd S z|   W n ty2   Y n0 d S r4   )r5   r   rG   rq   )r   r   Zcurrent_pidr&   r&   r'   cleanup_on_exit  s    z6register_cleanup_lock_removal.<locals>.cleanup_on_exit)r5   r   r   rl   )r   registerr   r   r&   r&   r'   register_cleanup_lock_removal
  s    
r   c                 C   s   t | } d}zz8t| }| j}|dt  }| | t| W n> ty   Y W |durz|	  W n ty~   Y n0 dS 0 W |durz|	  W q ty   Y q0 n*|durz|	  W n ty   Y n0 0 dS )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renamer_   rq   rG   )r)   r   rO   garbager&   r&   r'   maybe_delete_a_numbered_dir  s4    
r   )r)   $consider_lock_dead_if_created_beforer*   c                 C   s   |   rdS t| }z| s$W dS W n ty:   Y dS 0 z| j}W n ty^   Y dS 0 ||k rtt |	  W d   dS 1 s0    Y  dS dS )zGCheck if `path` is deletable based on whether the lock file is expired.FTN)

is_symlinkr-   rK   rq   r6   st_mtimers   
contextlibsuppressrG   )r)   r   lockZ	lock_timer&   r&   r'   ensure_deletable7  s"    
 r   c                 C   s   t | |rt|  dS )z8Try to cleanup a folder if we can ensure it's deletable.N)r   r   )r)   r   r&   r&   r'   try_cleanupS  s    
r   )r`   ra   keepr*   c           
      c   sn   t ttt| |dd}|| }t| |}t|\}}ttt||}t||D ]\}}	|	|krR|V  qRdS )zIList candidates for numbered directories to be removed - follows py.path.rk   rw   N)	r|   r}   rn   rj   rf   	itertoolsteeri   zip)
r`   ra   r   r   Z
max_deletepathsZpaths2numbersr)   numberr&   r&   r'   cleanup_candidatesY  s    
r   )r`   c                 C   s.   |   D ] }| r|  s|  qd S r4   )rc   r   rU   existsrG   )r`   Zleft_dirr&   r&   r'   cleanup_dead_symlinkse  s    r   )r`   ra   r   r   r*   c                 C   sN   |   sdS t| ||D ]}t|| q| dD ]}t|| q2t|  dS )z-Cleanup for lock driven numbered directories.Nz	garbage-*)r   r   r   globr   )r`   ra   r   r   r)   r&   r&   r'   cleanup_numbered_dirl  s    r   )r`   ra   r   lock_timeoutr;   r*   c                 C   s   d}t dD ]~}z(t| ||}|dkr6t|}t| W n( ty` }	 z|	}W Y d}	~	qd}	~	0 0 | j| }
tt	| |||
 |  S q|dusJ |dS )z>Create a numbered dir with a cleanup lock and remove old ones.Nrv   r   )
r{   r   r   r   rs   r6   r   atexitr   r   )r`   ra   r   r   r;   r   r   r3   r   rN   r   r&   r&   r'   make_numbered_dir_with_cleanupz  s(    
r   )inputrootpathr*   c                 C   s.   t | } t| } t| r t| S || S d S r4   )r   r	   r
   r   r+   )r   r   r&   r&   r'   resolve_from_str  s
    r   zos.PathLike[str])patternr)   r*   c                 C   s|   t |}tjd}|r4t| vr4t| v r4| tt} t| vrD|j}n,t|}|	 rpt
j| spd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replacerd   rJ   is_absoluter5   r)   r
   fnmatch)r   r)   Ziswin32rd   r&   r&   r'   
fnmatch_ex  s    r   )sr*   c                    s$   |  t  fddtt D S )Nc                    s&   h | ]}t  d |d  p t qS )Nr0   )r   join).0r   partsr&   r'   	<setcomp>      zparts.<locals>.<setcomp>)splitr   r{   rh   )r   r&   r   r'   r     s    
r   c              
   K   sX   z t jt| t|fi | W n2 tyR } ztd|  W Y d}~n
d}~0 0 dS )zDMake a symlink, or skip the test in case symlinks are not supported.zsymlinks not supported: N)r5   symlinkrJ   rq   r   )srcdstkwargsr   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                   @   s   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     s   r   ry   )r3   r;   r`   r*   c                C   s  t |}t| }| s t||t ju  rt||}tt t	j
| W  d   S 1 s`0    Y  t	jD ]$}||t|jg}|durp qqptj|t|}|du rtd| d| tj|}|t	j
|< |j| tt	j
| |S t|}|durF|j}	t|d|	j}
|
d dkr:|
  d|
}n|j}	|j}|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 rt(||||)dr,|dd }|)t$j*d	 rV|dt+t$j*d	   }zt,t||}W n t-y   d}Y n0 |st(||||S )a  Import and return a module from the given path, which can be a file (a module) or
    a directory (a package).

    The import mechanism used is controlled by the `mode` parameter:

    * `mode == 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`.

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

    * `mode == 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``.

    :raises ImportPathMismatchError:
        If after importing the given `path` and the module `__file__`
        are different. Only raised in `prepend` and `append` modes.
    NzCan't find module z at location  rk   __init__.r   __init__.pyZPY_IGNORE_IMPORTMISMATCH1)z.pycz.pyoF).r   r   r   ImportErrorr   module_name_from_pathr   r   KeyErrorrR   modules	meta_path	find_specrJ   rO   utilspec_from_file_locationmodule_from_specloaderexec_moduleinsert_missing_modulesresolve_package_pathlistwith_suffixrelative_tor   popr   stemr   r)   r   insertr   import_modulerd   r5   environget__file__r   endswithr   rh   _is_samer@   )r3   r;   r`   r)   module_nameZmeta_importerspecmodZpkg_pathZpkg_rootnamesignoreZmodule_fileZis_samer&   r&   r'   import_path  sp    
(







r   r   )f1f2r*   c                 C   s   t | t |kptj| |S r4   )r   r5   r)   samefiler   r   r&   r&   r'   r   W  s    r   c                 C   s   t j| |S r4   )r5   r)   r   r   r&   r&   r'   r   \  s    )r)   r`   r*   c                 C   sn   |  d} z| |}W n  ty8   | jdd }Y n0 |j}t|dkrd|d dkrd|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   r0   NrX   rk   r   r   )r   r   rm   r   rh   r   )r)   r`   relative_path
path_partsr&   r&   r'   r   `  s    
r   )r   r   r*   c                 C   s   | d}d}d}d}|r|| vr\ztjs.tt|}W qd tyX   t|dd}Y qd0 n| | }|rt||st||| || |< ||	dd  }}|
d d|}q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   Nr   z6Empty module created by pytest's importmode=importlib.)docrk   )r   rR   r   ModuleNotFoundErrorr   r   r   hasattrsetattr
rpartitionr   r   )r   r   module_partsZchild_modulemoduleZ
child_namer&   r&   r'   r   z  s.    


r   c                 C   sJ   d}t | f| jD ]0}| r|d s2 qF|j s@ qF|}q|S )zReturn the Python package path by looking for the last
    directory upwards which still contains an __init__.py.

    Returns None if it can not be determined.
    Nr   )r   chainrL   is_dirr+   rK   rd   isidentifier)r)   resultrO   r&   r&   r'   r     s    
r   zos.DirEntry[str]c                 C   s   g }t | l}|D ]V}z|  W n: ty^ } z"t|rHW Y d}~q W Y d}~n
d}~0 0 || qW d   n1 s0    Y  |jdd d |S )z`Scan a directory recursively, in breadth-first order.

    The returned entries are sorted.
    Nc                 S   s   | j S r4   )rd   entryr&   r&   r'   <lambda>  r   zscandir.<locals>.<lambda>)key)r5   scandirrK   rq   r(   r   sort)r)   entriesr   r  errr&   r&   r'   r
    s    *r
  )r)   recurser*   c                 c   sB   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)r
  r  visitr)   )r)   r  r  r  r&   r&   r'   r    s
    	
r  c                 C   s   t tjt| 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   r5   r)   abspathrJ   r,   r&   r&   r'   absolutepath  s    r  )path1path2r*   c                 C   s8   zt tjt| t|fW S  ty2   Y dS 0 dS )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   r5   r)   
commonpathrJ   rm   )r  r  r&   r&   r'   r    s    r  )	directorydestr*   c                 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   r5   curdirr  rJ   r   r)   r   pardirrh   r   )r  r  baseZreldirectoryZreldestr&   r&   r'   bestrelpath  s    


r  )sourcero   r*   c                 C   s   |   sJ t| dd dD ]p}t|}|| }|| }|jjdd | rb|t	| q|
 rxt|| q|  r|jdd qdS )z.Recursively copy a source directory to target.c                 S   s
   |    S r4   )r   r  r&   r&   r'   r    r   zcopytree.<locals>.<lambda>)r  T)exist_okN)r  r  r   r   rO   r~   r   rr   r5   readlinkrK   r]   copyfile)r  ro   r  re   relpathZnewxr&   r&   r'   copytree  s    
r   c              	   C   s(   z
|   W S  ttfy"   Y dS 0 dS )zTLike Path.exists(), but account for input arguments that might be too long (#11394).FN)r   rm   rq   )r3   r&   r&   r'   safe_exists  s    
r!  )ru   )hr   r   r   importlib.utilr   r   r5   r]   rR   typesr   rB   enumr   r    r   r   r   r   	functoolsr   os.pathr   r	   r
   r   pathlibr   r   	posixpathr   r   typingr   r   r   r   r   r   r   r   r   r   r   Z_pytest.compatr   Z_pytest.outcomesr   Z_pytest.warning_typesr   ZLOCK_TIMEOUTr   r#   r$   r(   r-   rJ   r?   TracebackTypeboolrP   rW   rV   r_   rf   ri   rj   rl   rn   rt   r   r   r   r   r   floatr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rS   rT   r   r   r   r   r
  r  r  r  r  r   r!  r&   r&   r&   r'   <module>   s   ?	!	$

o)	