
    h9                        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\  r	 d dl Z n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e0e
e,f   fd       Z1	 d=de0e,df   dee,   dee,   fdZ2 ed      de,de-e,ef   fd       Z3de-e,ef   dee4e&      fd Z5d!e,dee4e&      fd"Z6d!e,dee4e&      fd#Z7d$edefd%Z8ede
fd&       Z9ed'e
defd(       Z:	 d=de
d'e
d)ee*   de;fd*Z<de
d'e
de
fd+Z=d,e,d'e
d-e-e
ef   de;fd.Z>d/e,d0eee,      de;fd1Z?d2ee
   d'e
d3ee,   d4ee,   d5eee,      d6eee,      d)e*d-ee-e
ef      d7e;d8e;dee
   fd9Z@d:e j                  dee j                  d;f   fd<ZBy# e!$ r
 esd dl"Z Y w xY w)>    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                 p    t        | d      5 }t        j                  |      cd d d        S # 1 sw Y   y xY w)Nrb)opentomllibload)r   fs     >/var/www/html/immo/lib/python3.12/site-packages/black/files.py
_load_tomlr$   #   s.    	dD	 Q||A  s   ,5c                 "    | j                         S N)resolver   s    r#   _cached_resolver)   )   s    <<>    srcsstdin_filenamec           	         t        fd| D              } | s't        t        t        j                                     g} | D cg c])  }t        t        t        j                         |            + }}|D cg c]-  }t        |j                        |j                         r|gng z   / }}t        t        j                  d |D         d       }|g|j                  D ]p  }|dz  j                         r|dfc S |dz  j                         r|dfc S |d	z  j                         sIt        |d	z        }d
|j                  di       v sl|d	fc S  dfS c c}w c c}w )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.
    c              3   0   K   | ]  }|d k(  rn|  yw)-N ).0sr,   s     r#   	<genexpr>z$find_project_root.<locals>.<genexpr>B   s     E1qCx^Q6Es   c              3   2   K   | ]  }t        |        y wr&   )set)r1   parentss     r#   r3   z$find_project_root.<locals>.<genexpr>O   s     CG3w<C   c                     | j                   S r&   )partsr(   s    r#   <lambda>z#find_project_root.<locals>.<lambda>P   s
     r*   )keyz.gitz.git directoryz.hgz.hg directorypyproject.tomlblacktoolzfile system root)tuplestrr)   r   cwdlistr6   is_dirmaxr5   intersectionexistsis_filer$   get)	r+   r,   src	path_srcsr   src_parentscommon_base	directorypyproject_tomls	    `       r#   find_project_rootrO   .   sj   & !EEEODHHJ/01CGHCdhhj#!67HIH
 LUCGT\\tf2>K  C{CD#K
 "8K$7$78 
3	&&(...%%'o--((113'	4D(DEN.,,VR88 "222
3 (((3 Is   .E92Epath_search_start.c                    t        | |      \  }}|dz  }|j                         rt        |      S 	 t               }|j                         rt        |      S dS # t        t
        f$ r}t        d|       Y d}~yd}~ww xY w)z;Find the absolute filepath to a pyproject.toml if it existsr<   Nz-Ignoring user configuration directory due to )rO   rG   r@   find_user_pyproject_tomlPermissionErrorRuntimeErrorr   )rP   r,   path_project_root_path_pyproject_tomlpath_user_pyproject_tomles          r#   find_pyproject_tomlrZ   b   s     -->Oq+.>>""$&''
#;#=  (//1 ()	
 	

 \* ;A5ABs   $A A A?'A::A?T)	patchablepath_configc                 t   t        |       }|j                  di       j                  di       }|j                         D ci c](  \  }}|j                  dd      j                  dd      |* }}}d|vr8t	        |      }|+|D cg c]  }|j
                  j                          c}|d<   |S c c}}w c c}w )zParse a pyproject toml file, pulling out relevant parts for Black.

    If parsing fails, will raise a tomllib.TOMLDecodeError.
    r>   r=   z-- r/   rV   target_version)r$   rH   itemsreplaceinfer_target_versionnamelower)r\   rN   configkvinferred_target_versions         r#   parse_pyproject_tomlri   x   s      ,N+//;??LFCI<<>R41aaiib!))#s3Q6RFRv%"6~"F".@W'X1'XF#$M S
 (Ys   -B/!B5rN   c                     | j                  di       }|j                  dd      }|	 t        |      S y# t        $ r Y nw xY w	 t        |      S # t        t        f$ r Y yw xY w)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)rH   parse_req_python_versionr   parse_req_python_specifierr   )rN   project_metadatarequires_pythons      r#   rb   rb      s     &)))R8&**+<dCO"	+O<<   			-o>> .1 		s    
4 	A A 
A A! A!ro   c                     t        |       }|j                  d   dk7  ry	 t        |j                  d         gS # t        t        f$ r Y y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)ro   versions     r#   rl   rl      sU     o&GqQgooa0122
# s   9 A
Ac                     t        t        |             }|syt        D ci c]  }d|j                   | }}t	        |j                  |            }|r|D cg c]  }||   	 c}S yc c}w c c}w )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.
    Nz3.)strip_specifier_setr   r   valuerB   filter)ro   specifier_setrg   target_version_mapcompatible_versionss        r#   rm   rm      s|     (_(EFM5BCBqwwi.!+CC%)-*>*>?Q*R%S/BC!"1%CC	 D Ds   A)A.rz   c                 j   g }| D ]  }dt        |      v r|j                  |       #|j                  dv rWt        |j                        }t        |j                   |j                   d|j                         }|j                  |       |j                  dk(  rdt        |j                        }t        |j                        dkD  r%t        d|j                   d|j                         }|j                  |       |j                  |        t        dj                  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   2   K   | ]  }t        |        y wr&   )r@   )r1   r2   s     r#   r3   z&strip_specifier_set.<locals>.<genexpr>   s      <AQ <r7   )r@   appendoperatorr   ru   r   majorminorlenrr   r   join)rz   
specifiersr2   ru   strippeds        r#   rw   rw      s    J !#a&=a ZZ44aii(G AJJ<a!OPHh'ZZ3aii(G7??#a'7==/7==/BCa a !  < <<==r*   c                      t         j                  dk(  r"t        j                         dz  } t        |       S t        j
                  j                  dd      }t        |      j                         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	~/.configr=   )	sysplatformr   homeosenvironrH   
expanduserr)   )user_config_pathconfig_roots     r#   rR   rR      sk     ||w99;1 +,, jjnn%6D,779GC+,,r*   rootc                    | dz  }g }|j                         r+|j                  d      5 }|j                         }ddd       	 t        j                  d|      S # 1 sw Y    xY w# 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: )rG   r   	readlinesr   
from_linesr   r   )r   	gitignorelinesgfrY   s        r#   get_gitignorer      s     |#IE^^W^- 	#LLNE	#"">599	# 	# $ ykA3/0s#   AA& A#&	B/BBreportc                     	 t        |       }	 |j                  |       y# t        $ r!}|r|j                  | d|        Y d}~yd}~ww xY w# t        $ r |r|j                  | d|        Y yw xY 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_tort   )r   r   r   resolved_pathrY   s        r#   $resolves_outside_root_or_cannot_statr      s    '-
!!$'
   (?s&CD  (OPTv&VWs%     A 	A
AA
 A0/A0c                     	 | j                         j                        S # t        $ r Y nw xY wt        fd| j                  D        d       }|| j                  |      S t        |       j                        S )Nc              3   @   K   | ]  }t        |      k(  s|  y wr&   )r)   )r1   pr   s     r#   r3   z,best_effort_relative_path.<locals>.<genexpr>  s     Na?13E3MNs   )absoluter   rt   nextr6   r)   )r   r   root_parents    ` r#   best_effort_relative_pathr     su    }}**400 N4<<NPTUK,,4 ,,T22s   " 	..root_relative_pathgitignore_dictc                     || z  }|j                         D ]M  \  }}	 |j                  |      j                         }|j                         r|dz   }|j                  |      sM y y# t        $ r Y  yw xY w)N/TF)r`   r   as_posixrC   rt   
match_file)r   r   r   r   gitignore_pathpatternrelative_paths          r#   _path_is_ignoredr   $  s    
 $$D $2#7#7#9 	 ,,^<EEGM{{} - 3 m, 	  	 		s   4A''	A43A4normalized_pathr   c                 h    |r|j                  |       nd }t        |xr |j                  d            S )Nr   )searchboolgroup)r   r   matchs      r#   path_is_excludedr   8  s.     07GNN?+DE(%++a.))r*   pathsincludeexcludeextend_excludeforce_excludeverbosequietc             #   T  K   |j                         s
J d|        | D ]  }
|
j                         sJ |
j                  |      j                         }|r t        |||      r|j	                  |
d       Wd|z   }|
j                         r|dz  }t        ||      r|j	                  |
d       t        ||      r|j	                  |
d       t        ||      r|j	                  |
d       t        |
||      r|
j                         rF|i |||
z  t        |
      i}nd}t        |
j                         |||||||||	
      E d{    2|
j                         sD|
j                  d	k(  rt        |xs |	 
      sf|r|j                  |      nd}|s|
  y7 [w)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   rC   r   r   r   gen_python_filesiterdirrG   suffixr   r   )r   r   r   r   r   r   r   r   r   r   childr   new_gitignore_dictinclude_matchs                 r#   r   r   @  s    , W!PQUPVWW ?  """"..t4==? .n
 'JK !#55<<>#%.8'QR.?H .>'WX/tVD<<> )&$&5L-"6&"
 &*"'"   ]]_||x'0R)E	1 BIGNN+=>tM?Vs   EF(
F&F(#9F(	F(r"   zcolorama.AnsiToWin32c                 L    	 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     s6    U3
 1d%5tTT	  s    ##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   coloramar@   dictr$   r)   r?   rO   rZ   ri   rB   rb   rl   rm   rw   rR   r   r   r   r   r   r   r   TextIOWrapperr   r0   r*   r#   <module>r      s   	 	 
 8 8    6 6 & J J 5  Cw$  H $   U49% $sCx.  
 $ 4   9=0)
3-0))1#0)
490) 0)h IMS#X8@c], dc d38n  "cNd=!"2c htM?R6S  mAT8U ">| > >2 -$ - -&    "  $

 V 
	0
3D 
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rU	U
2334UM  $#$s   )G' 'G65G6