o
    ^i9                     @   sn  d dl Z d dlZd dlZ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mZmZmZ d dlmZ d dlmZmZmZ d d	lmZmZ d d
lmZ d dlmZ ejdkrszd dl Z W n e!yr   espd dl"Z Y nw d dl"Z d dl#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z* erd dl+Z+edee
e,f de-e,ef fddZ.ede
de
fddZ/e	dNdee, dee, de0e
e,f fddZ1	dNde0e,df dee, dee, fddZ2edd d!e,de-e,ef fd"d#Z3d$e-e,ef dee4e&  fd%d&Z5d'e,dee4e&  fd(d)Z6d'e,dee4e&  fd*d+Z7d,edefd-d.Z8ede
fd/d0Z9ed1e
defd2d3Z:	dNde
d1e
d4ee* de;fd5d6Z<de
d1e
de
fd7d8Z=d9e,d1e
d:e-e
ef de;fd;d<Z>d=e,d>eee,  de;fd?d@Z?dAee
 d1e
dBee, dCee, dDeee,  dEeee,  d4e*d:ee-e
ef  dFe;dGe;dee
 fdHdIZ@dJe jAdee jAdKf fdLdMZBdS )O    N)IterableIteratorSequence)	lru_cache)Path)Pattern)TYPE_CHECKINGAnyOptionalUnion)
mypyc_attr)InvalidSpecifier	SpecifierSpecifierSet)InvalidVersionVersion)PathSpec)GitWildMatchPatternError)      )"jupyter_dependencies_are_installed)TargetVersion)err)Reportpathreturnc                 C   s8   t | d}t|W  d    S 1 sw   Y  d S )Nrb)opentomllibload)r   f r!   P/var/www/html/stock_analysis/be/venv/lib/python3.10/site-packages/black/files.py
_load_toml#   s   $r#   c                 C   s   |   S N)resolver   r!   r!   r"   _cached_resolve)   s   r'   srcsstdin_filenamec                    s    durt  fdd| D } | sttt g} dd | D }dd |D }ttjdd |D  dd	 d
}|g|jR D ]4}|d 	 rM|df  S |d 
 rY|df  S |d  rst|d }d|di v rs|df  S q?|dfS )aQ  Return a directory containing .git, .hg, or pyproject.toml.

    pyproject.toml files are only considered if they contain a [tool.black]
    section and are ignored otherwise.

    That directory will be a common parent of all files and directories
    passed in `srcs`.

    If no directory in the tree contains a marker that would specify it's the
    project root, the root of the file system is returned.

    Returns a two-tuple with the first element as the project root path and
    the second element as a string describing the method by which the
    project root was discovered.
    Nc                 3   s     | ]}|d kr
 n|V  qdS )-Nr!   .0sr)   r!   r"   	<genexpr>B       z$find_project_root.<locals>.<genexpr>c                 S   s   g | ]}t tt |qS r!   )r'   r   cwd)r,   srcr!   r!   r"   
<listcomp>F   s    z%find_project_root.<locals>.<listcomp>c                 S   s(   g | ]}t |j| r|gng  qS r!   )listparentsis_dir)r,   r   r!   r!   r"   r3   J   s    c                 s       | ]}t |V  qd S r$   )set)r,   r5   r!   r!   r"   r/   O       c                 S   s   | j S r$   )partsr&   r!   r!   r"   <lambda>P   s    z#find_project_root.<locals>.<lambda>)keyz.gitz.git directoryz.hgz.hg directorypyproject.tomlblacktoolzfile system root)tuplestrr'   r   r1   maxr8   intersectionr5   existsr6   is_filer#   get)r(   r)   	path_srcssrc_parentscommon_base	directorypyproject_tomlr!   r.   r"   find_project_root.   s.   rL   path_search_start.c              
   C   s~   t | |\}}|d }| rt|S zt }| r t|W S dW S  ttfy> } ztd| W Y d}~dS d}~ww )z;Find the absolute filepath to a pyproject.toml if it existsr=   Nz-Ignoring user configuration directory due to )rL   rE   rA   find_user_pyproject_tomlPermissionErrorRuntimeErrorr   )rM   r)   path_project_root_path_pyproject_tomlpath_user_pyproject_tomler!   r!   r"   find_pyproject_tomlb   s    rV   T)	patchablepath_configc                 C   s\   t | }|di di }dd | D }d|vr,t|}|dur,dd |D |d< |S )	zParse a pyproject toml file, pulling out relevant parts for Black.

    If parsing fails, will raise a tomllib.TOMLDecodeError.
    r?   r>   c                 S   s&   i | ]\}}| d d dd|qS )z-- r*   rR   )replace)r,   kvr!   r!   r"   
<dictcomp>   s   & z(parse_pyproject_toml.<locals>.<dictcomp>target_versionNc                 S   s   g | ]}|j  qS r!   )namelowerr,   r\   r!   r!   r"   r3      s    z(parse_pyproject_toml.<locals>.<listcomp>)r#   rF   itemsinfer_target_version)rX   rK   configinferred_target_versionr!   r!   r"   parse_pyproject_tomlx   s   rf   rK   c              	   C   sf   |  di }| dd}|dur1zt|W S  ty   Y nw zt|W S  ttfy0   Y dS w dS )a#  Infer Black's target version from the project metadata in pyproject.toml.

    Supports the PyPA standard format (PEP 621):
    https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#requires-python

    If the target version cannot be inferred, returns None.
    projectzrequires-pythonN)rF   parse_req_python_versionr   parse_req_python_specifierr   )rK   project_metadatarequires_pythonr!   r!   r"   rc      s   


rc   rk   c              	   C   sF   t | }|jd dkrdS z	t|jd gW S  ttfy"   Y dS w )zParse a version string (i.e. ``"3.7"``) to a list of TargetVersion.

    If parsing fails, will raise a packaging.version.InvalidVersion error.
    If the parsed version cannot be mapped to a valid TargetVersion, returns None.
    r   r   N   )r   releaser   
IndexError
ValueError)rk   versionr!   r!   r"   rh      s   rh   c                    sJ   t t| }|s
dS dd tD  t| }|r# fdd|D S dS )zParse a specifier string (i.e. ``">=3.7,<3.10"``) to a list of TargetVersion.

    If parsing fails, will raise a packaging.specifiers.InvalidSpecifier error.
    If the parsed specifier cannot be mapped to a valid TargetVersion, returns None.
    Nc                 S   s   i | ]	}d |j  |qS )z3.)valuera   r!   r!   r"   r]      s    z.parse_req_python_specifier.<locals>.<dictcomp>c                    s   g | ]} | qS r!   r!   ra   target_version_mapr!   r"   r3      s    z.parse_req_python_specifier.<locals>.<listcomp>)strip_specifier_setr   r   r4   filter)rk   specifier_setcompatible_versionsr!   rr   r"   ri      s   ri   rv   c                 C   s   g }| D ]T}dt |v r|| q|jdv r0t|j}t|j |j d|j }|| q|jdkrSt|j}t|j	dkrMtd|j d|j }|| q|| qt
ddd	 |D S )
zStrip minor versions for some specifiers in the specifier set.

    For background on version specifiers, see PEP 440:
    https://peps.python.org/pep-0440/#version-specifiers
    *)z~=z==>=z===.>   ry   ,c                 s   r7   r$   )rA   r+   r!   r!   r"   r/      r9   z&strip_specifier_set.<locals>.<genexpr>)rA   appendoperatorr   rp   r   majorminorlenrm   r   join)rv   
specifiersr-   rp   strippedr!   r!   r"   rt      s   



rt   c                  C   sD   t jdkrt d } t| S tjdd}t| d } t| S )a:  Return the path to the top-level user configuration for black.

    This looks for ~\.black on Windows and ~/.config/black on Linux and other
    Unix systems.

    May raise:
    - RuntimeError: if the current user has no homedir
    - PermissionError: if the current process cannot access the user's homedir
    win32z.blackXDG_CONFIG_HOMEz	~/.configr>   )	sysplatformr   homeosenvironrF   
expanduserr'   )user_config_pathconfig_rootr!   r!   r"   rN      s   
rN   rootc              
   C   s   | d }g }|  r$|jdd}| }W d   n1 sw   Y  ztd|W S  tyB } ztd| d|   d}~ww )z8Return a PathSpec matching gitignore content if present.z
.gitignorezutf-8)encodingNgitwildmatchzCould not parse z: )rE   r   	readlinesr   
from_linesr   r   )r   	gitignorelinesgfrU   r!   r!   r"   get_gitignore   s   
r   reportc              
   C   s   zt | }W n ty$ } z|r|| d|  W Y d}~dS d}~ww z|| W dS  tyB   |r?|| d|  Y dS w )z
    Returns whether the path is a symbolic link that points outside the
    root directory. Also returns True if we failed to resolve the path.
    zcannot be read because NTz'is a symbolic link that points outside F)r'   OSErrorpath_ignoredrelative_toro   )r   r   r   resolved_pathrU   r!   r!   r"   $resolves_outside_root_or_cannot_stat   s    	r   c                    s^   z|    W S  ty   Y nw t fdd| jD d }|d ur(| |S t|  S )Nc                 3   s     | ]}t | kr|V  qd S r$   )r'   )r,   pr   r!   r"   r/     r0   z,best_effort_relative_path.<locals>.<genexpr>)absoluter   ro   nextr5   r'   )r   r   root_parentr!   r   r"   best_effort_relative_path  s   
r   root_relative_pathgitignore_dictc              	   C   sh   ||  }|  D ])\}}z|| }| r|d }W n ty(   Y  dS w ||r1 dS qdS )N/TF)rb   r   as_posixr6   ro   
match_file)r   r   r   r   gitignore_pathpatternrelative_pathr!   r!   r"   _path_is_ignored$  s   
r   normalized_pathr   c                 C   s$   |r| | nd }t|o|dS )Nr   )searchboolgroup)r   r   matchr!   r!   r"   path_is_excluded8  s   r   pathsincludeexcludeextend_excludeforce_excludeverbosequietc                c   sb   |  sJ d| | D ]}
|
  sJ |
| }|r,t|||r,||
d qd| }|
 r8|d7 }t||rD||
d qt||rP||
d qt||r\||
d qt|
||rcq|
 r|durxi |||
 t|
i}nd}t	|

 |||||||||	d
E dH  q|
 r|
jd	krt|p|	 d
sq|r||nd}|r|
V  qdS )a7  Generate all files under `path` whose paths are not excluded by the
    `exclude_regex`, `extend_exclude`, or `force_exclude` regexes,
    but are included by the `include` regex.

    Symbolic links pointing outside of the `root` directory are ignored.

    `report` is where output about exclusions goes.
    z/INTERNAL ERROR: `root` must be absolute but is z!matches a .gitignore file contentr   z(matches the --exclude regular expressionz/matches the --extend-exclude regular expressionz.matches the --force-exclude regular expressionN)r   r   z.ipynb)warnT)is_absoluter   r   r   r   r6   r   r   r   gen_python_filesiterdirrE   suffixr   r   )r   r   r   r   r   r   r   r   r   r   childr   new_gitignore_dictinclude_matchr!   r!   r"   r   @  sp   


r   r    zcolorama.AnsiToWin32c                 C   s:   zddl m} W n ty   |  Y S w || dddddS )at  
    Wrap stream with colorama's wrap_stream so colors are shown on Windows.

    If `colorama` is unavailable, the original stream is returned unmodified.
    Otherwise, the `wrap_stream()` function determines whether the stream needs
    to be wrapped for a Windows environment and will accordingly either return
    an `AnsiToWin32` wrapper or the original stream.
    r   )wrap_streamNFT)convertstrip	autoresetwrap)colorama.initialiser   ImportError)r    r   r!   r!   r"   wrap_stream_for_windows  s   r   r$   )Cior   r   collections.abcr   r   r   	functoolsr   pathlibr   rer   typingr   r	   r
   r   mypy_extensionsr   packaging.specifiersr   r   r   packaging.versionr   r   pathspecr   pathspec.patterns.gitwildmatchr   version_infor   r   tomliblack.handle_ipynb_magicsr   
black.moder   black.outputr   black.reportr   coloramarA   dictr#   r'   r@   rL   rV   rf   r4   rc   rh   ri   rt   rN   r   r   r   r   r   r   r   TextIOWrapperr   r!   r!   r!   r"   <module>   s    
$
4













Y