
    yIfI9                        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m	Z	m
Z
mZmZmZmZ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    r	 d dl!Z!n# e"$ r	 esd dl#Z!Y nw xY 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rd dl,Z,edeee-f         de
e-e	f         fd            Z.ededefd            Z/e	 d;dee-         dee-         deee-f         fd            Z0	 d;dee-df         dee-         dee-         fdZ1 ed          de-de
e-e	f         fd            Z2de
e-e	f         deee'                  fdZ3de-deee'                  fd Z4de-deee'                  fd!Z5d"edefd#Z6edefd$            Z7ed%edefd&            Z8	 d;ded%ed'ee+         de9fd(Z:ded%edefd)Z;d*e-d%ed+e
eef         de9fd,Z<d-e-d.eee-                  de9fd/Z=d0ee         d%ed1ee-         d2ee-         d3eee-                  d4eee-                  d'e+d+ee
eef                  d5e9d6e9dee         fd7Z>d8e j?        dee j?        d9f         fd:Z@dS )<    N)	lru_cache)Path)TYPE_CHECKINGAnyDictIterableIteratorListOptionalPatternSequenceTupleUnion)
mypyc_attr)InvalidSpecifier	SpecifierSpecifierSet)InvalidVersionVersion)PathSpec)GitWildMatchPatternError)      )"jupyter_dependencies_are_installed)TargetVersion)err)Reportpathreturnc                 ~    t          | d          5 }t          j        |          cd d d            S # 1 swxY w Y   d S )Nrb)opentomllibload)r   fs     ?/var/www/piapp/venv/lib/python3.11/site-packages/black/files.py
_load_tomlr'   -   s~    	dD		 Q|A                 s   266c                 *    |                                  S N)resolver   s    r&   _cached_resolver,   3   s    <<>>    srcsstdin_filenamec                 D   t          fd| D                       } | s.t          t          t          j                                        g} d | D             }d |D             }t          t          j        d |D              d           }|g|j        R D ]}|dz  	                                r|d	fc S |d
z  
                                r|dfc S |dz                                  r0t          |dz            }d|                    di           v r|dfc S |dfS )a  Return a directory containing .git, .hg, or pyproject.toml.

    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   ,   K   | ]}|d k    rn|V  dS )-N ).0sr/   s     r&   	<genexpr>z$find_project_root.<locals>.<genexpr>I   s/      EE1qCxx^^QEEEEEEr-   c                 j    g | ]0}t          t          t          j                    |                    1S r3   )r,   r   cwd)r4   srcs     r&   
<listcomp>z%find_project_root.<locals>.<listcomp>M   s0    HHHCdhjj#!6!677HHHr-   c                 j    g | ]0}t          |j                  |                                r|gng z   1S r3   )listparentsis_dir)r4   r   s     r&   r:   z%find_project_root.<locals>.<listcomp>Q   sG       CGT\=tff2>  r-   c              3   4   K   | ]}t          |          V  d S r)   )set)r4   r=   s     r&   r6   z$find_project_root.<locals>.<genexpr>V   s(      CCG3w<<CCCCCCr-   c                     | j         S r)   )partsr+   s    r&   <lambda>z#find_project_root.<locals>.<lambda>W   s     r-   )keyz.gitz.git directoryz.hgz.hg directorypyproject.tomlblacktoolzfile system root)tuplestrr,   r   r8   maxr@   intersectionr=   existsr>   is_filer'   get)r.   r/   	path_srcssrc_parentscommon_base	directorypyproject_tomls    `     r&   find_project_rootrT   8   s     !EEEEEEEEE 2ODHJJ//001HH4HHHI KT  K CC{CCCD##  K
 "8K$788 
3 
3	&&(( 	/.....%%'' 	.o----((1133 	3'	4D(DEEN.,,VR8888 "22222(((r-   path_search_start.c                 B   t          | |          \  }}|dz  }|                                rt          |          S 	 t                      }|                                rt          |          ndS # t          t
          f$ r}t          d|           Y d}~dS d}~ww xY w)z;Find the absolute filepath to a pyproject.toml if it existsrE   Nz-Ignoring user configuration directory due to )rT   rM   rI   find_user_pyproject_tomlPermissionErrorRuntimeErrorr   )rU   r/   path_project_root_path_pyproject_tomlpath_user_pyproject_tomles          r&   find_pyproject_tomlr_   i   s     -->OOq+.>>""$$ (&'''
#;#=#=  (//11C()))	

 \*   AAAABBBttttts   2A0 0BBBT)	patchablepath_configc                     t          |           }|                    di                               di           }d |                                D             }d|vr t          |          }|d |D             |d<   |S )zParse a pyproject toml file, pulling out relevant parts for Black.

    If parsing fails, will raise a tomllib.TOMLDecodeError.
    rG   rF   c                 j    i | ]0\  }}|                     d d                               dd          |1S )z-- r2   r[   )replace)r4   kvs      r&   
<dictcomp>z(parse_pyproject_toml.<locals>.<dictcomp>   s<    RRR41aaiib!!))#s33QRRRr-   target_versionNc                 @    g | ]}|j                                         S r3   )namelowerr4   rg   s     r&   r:   z(parse_pyproject_toml.<locals>.<listcomp>   s"    'X'X'X1'X'X'Xr-   )r'   rN   itemsinfer_target_version)ra   rS   configinferred_target_versions       r&   parse_pyproject_tomlrr      s      ,,N+//;;??LLFRR6<<>>RRRFv%%"6~"F"F".'X'X@W'X'X'XF#$Mr-   rS   c                     |                      di           }|                     dd          }|G	 t          |          S # t          $ r Y nw xY w	 t          |          S # t          t          f$ r Y nw xY 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)rN   parse_req_python_versionr   parse_req_python_specifierr   )rS   project_metadatarequires_pythons      r&   ro   ro      s     &)))R88&**+<dCCO"	+O<<< 	 	 	D		-o>>> .1 	 	 	D	 4s!   ? 
AAA A32A3rx   c                     t          |           }|j        d         dk    rdS 	 t          |j        d                   gS # t          t          f$ r Y dS w xY 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)rx   versions     r&   ru   ru      sl     o&&GqQtgoa01122
#   tts   ? AAc                     t          t          |                     }|sdS d t          D             t          |                                        }|rf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                 $    i | ]}d |j          |S )z3.)valuerm   s     r&   rh   z.parse_req_python_specifier.<locals>.<dictcomp>   s"    CCC.qw..!CCCr-   c                      g | ]
}|         S r3   r3   )r4   rg   target_version_maps     r&   r:   z.parse_req_python_specifier.<locals>.<listcomp>   s    CCC!"1%CCCr-   )strip_specifier_setr   r   r<   filter)rx   specifier_setcompatible_versionsr   s      @r&   rv   rv      s     (_(E(EFFM tCC]CCC%)-*>*>?Q*R*R%S%S DCCCC/BCCCC4r-   r   c                 l   g }| D ]}dt          |          v r|                    |           *|j        dv rOt          |j                  }t          |j         |j         d|j                   }|                    |           |j        dk    rat          |j                  }t          |j	                  dk    rt          d|j         d|j                   }|                    |           |                    |           t          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===.>   r   ,c              3   4   K   | ]}t          |          V  d S r)   )rI   )r4   r5   s     r&   r6   z&strip_specifier_set.<locals>.<genexpr>   s(       < <AQ < < < < < <r-   )rI   appendoperatorr   r~   r   majorminorlenr{   r   join)r   
specifiersr5   r~   strippeds        r&   r   r      sB    J ! !#a&&==a    Z444ai((G AJ!O!O!O!O!OPPHh''''Z3ai((G7?##a''B7=BB7=BBCCa    a     < < < < <<<===r-   c                      t           j        dk    rt          j                    dz  } nDt          j                            dd          }t          |                                          dz  } 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	~/.configrF   )	sysplatformr   homeosenvironrN   
expanduserr,   )user_config_pathconfig_roots     r&   rW   rW      si     |w9;;1jnn%6DD,,7799GC+,,,r-   rootc                 8   | dz  }g }|                                 rB|                    d          5 }|                                }ddd           n# 1 swxY w Y   	 t          j        d|          S # t
          $ r}t          d| d|             d}~ww xY w)z8Return a PathSpec matching gitignore content if present.z
.gitignorezutf-8)encodingNgitwildmatchzCould not parse z: )rM   r"   	readlinesr   
from_linesr   r   )r   	gitignorelinesgfr^   s        r&   get_gitignorer      s     |#IE #^^W^-- 	#LLNNE	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#">5999#   /y//A//000s)   AAAA4 4
B>BBreportc                 \   	 t           j        dk     r|                                 } t          |           }n3# t          $ r&}|r|                    | d|            Y d}~dS d}~ww xY w	 |                    |           n,# t          $ r |r|                    | d|            Y dS w xY wdS )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.
    )r         zcannot be read because NTz'is a symbolic link that points outside F)r   version_infoabsoluter,   OSErrorpath_ignoredrelative_tor}   )r   r   r   resolved_pathr^   s        r&   $resolves_outside_root_or_cannot_statr     s    i''==??D'--    	E&C&C&CDDDttttt!!$''''    	X&VPT&V&VWWWtt 5s'   36 
A& A!!A&*B   %B)(B)c                 (   	 |                                                                S # t          $ r Y nw xY wt          fd| j        D             d           }||                     |          S t          |                                         S )Nc              3   B   K   | ]}t          |          k    |V  d S r)   )r,   )r4   pr   s     r&   r6   z,best_effort_relative_path.<locals>.<genexpr>&  s5      NNa?13E3E3M3M3M3M3M3MNNr-   )r   r   r}   nextr=   r,   )r   r   root_parents    ` r&   best_effort_relative_pathr      s    }}**4000   NNNN4<NNNPTUUK,,,4  ,,T222s   &* 
77root_relative_pathgitignore_dictc                     || z  }|                                 D ]W\  }}	 |                    |                                          }n# t          $ r Y  nw xY w|                    |          r dS XdS )NTF)rn   r   as_posixr}   
match_file)r   r   r   r   gitignore_pathpatternrelative_paths          r&   _path_is_ignoredr   -  s    
 $$D $2#7#7#9#9  	 ,,^<<EEGGMM 	 	 	EE	m,, 	44	5s   'A
AAnormalized_pathr   c                 |    |r|                     |           nd }t          |o|                    d                    S )Nr   )searchboolgroup)r   r   matchs      r&   path_is_excludedr   ?  s<     07@GNN?+++DE(%++a..)))r-   pathsincludeexcludeextend_excludeforce_excludeverbosequietc             #     K   |                                 sJ d|             | D ]}
|
                                 sJ |
                    |                                          }|r(t          |||          r|                    |
d           jd|z   }|
                                r|dz  }t          ||          r|                    |
d           t          ||          r|                    |
d           t          ||          r|                    |
d           t          |
||          r|
                                rP|i |||
z  t          |
          i}nd}t          |

                                |||||||||	
  
        E d{V  t|
                                r?|
j        d	k    rt          |p|	 
          s|r|                    |          nd}|r|
V  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 content/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   r>   r   r   r   gen_python_filesiterdirrM   suffixr   r   )r   r   r   r   r   r   r   r   r   r   childr   new_gitignore_dictinclude_matchs                 r&   r   r   G  s     , WWWQUWWWWW ? ?  """"""..t44==??  	.n
 
 	 'JKKK !#55<<>> 	&#%.88 	'QRRR.?? 	H   .>> 	'WXXX/tVDD 	<<>> 	 )&$&5L-"6"6& &""
 &*"'"           ]]__ 	|x''0R)E	1 1 1' BISGNN+=>>>tM ? ?r-   r%   zcolorama.AnsiToWin32c                 T    	 ddl m}  || dddd          S # t          $ r | cY S w xY w)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   s     r&   wrap_stream_for_windowsr     s]    U333333
 {1d%5tTTTT	    s    ''r)   )Aior   r   	functoolsr   pathlibr   typingr   r   r   r   r	   r
   r   r   r   r   r   mypy_extensionsr   packaging.specifiersr   r   r   packaging.versionr   r   pathspecr   pathspec.patterns.gitwildmatchr   r   r#   r   tomliblack.handle_ipynb_magicsr   
black.moder   black.outputr   black.reportr   coloramarI   r'   r,   rT   r_   rr   ro   ru   rv   r   rW   r   r   r   r   r   r   r   TextIOWrapperr   r3   r-   r&   <module>r      s'   				 				 



                                      ' & & & & & J J J J J J J J J J 5 5 5 5 5 5 5 5       C C C C C Cw$ $ $ $ 	$####$
  H H H H H H $ $ $ $ $ $             OOO U49% $sCx.    
 $ 4     9=-) -)
3--))1#-)
49-) -) -) -)b IM S#X8@c]   , dc d38n    "cNd=!"   2c htM?R6S     mAT8U    ">| > > > > >2 -$ - - - -&      "  $ 

 V 
	   4
3D 
3 
3 
3 
3 
3 
3
 x( 
	   $**gcl#* 
* * * *VD>V
V S\V S\	V
 WS\*V GCL)V V T$.12V V V d^V V V VrU	U
2334U U U U U Us   #A( (A65A6