o
    b`                  I   @   s  d dl Z d dlm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Zd dlmZ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Zd dl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'm(Z( d dl)m*Z* d dl+Z+d dl,m-Z-m.Z.m/Z/ d dl,m0Z0 d dl1m2Z2m3Z3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9m:Z:m;Z; d dl<m=Z= d dl>m?Z?m@Z@ d dl>mAZAmBZBmCZC d dlDmEZEmFZFmGZGmHZHmIZI d dlJmKZKmLZLmMZM d dlNmOZOmPZPmQZQmRZRmSZSmTZT d dlUmVZVmWZWmXZX d dlYmZZZm[Z[m\Z\ d dlYm]Z]m^Z^m_Z_ d dlYm`Z` d dlambZb d dlamcZcmdZdmeZe d dlfmgZgmhZhmiZimjZjmkZkmlZl d dlmmnZnmoZo d dlpmqZq d d lrmsZt euZveuZweuZxG d!d" d"eZye?Zzd#e+j{d$e+j|d%e#eu d&e#eu fd'd(Z}d)e+j{d*e(e+j~e+j|f d+e'eud,f d&e!e@ fd-d.Zd/eud&e$eu fd0d1Zd#e+j{d$e+j|d%e#eu d&e#e$ fd2d3Ze+jed4d5gd6d7e+jd8d9eud:d;e+jd<d=ee-d>d?d@e+jdAdBe+dCdD e@D ed?dEdFe+jdGd?dHdIe+jdJd?dKdIe+jdLdMd?dNdIe+jdOdPd?dQdIe+jdRd?d?dSdTe+jdUd?dVdIe+jdWd?dXdIe+jdYd?dZdIe+jd[d?d\dIe+jd]eud^d;e+jd_eue.ed`d?dae+jdbeuedce/ dddedfe+jdgeuedhdie+jdjeuedkdie+jdleudmd;e+jdndod?dpdIe+jdqdrd?dsdIe+jetd e+jdtdue+jd?d?d?d?d?dvd?dwdxe+jdye+jd?d?ded?deeudzd?e}d{d|e+jd#e+j{d}e#eu d~ede!e@ dedededededededededededeude$de#e$ de#e$ de#e$ de#eu dte'eud,f de#eu d&df0ddZd#e+j{dte'eud,f dedede$eu de#e$eu  de#e$eu  de#e$eu  ddde#eu d&e%e fddZdte&deudeded#e+j{d&dfddZdeudedeyde?deVd&dfddZdtededeyde?ddd&dfddZde%e dedeyde?ddd&dfddZde%e dedeyde?ddde jded&dfddZeyjdfdtedede?deyded&efddZdeyjddede#eu deyde?d&ef
ddZdeudeude?d&dfddZdeudede?d&evfddZdteud&dfddZdteudede?d&eufddZde"euef d&dfddZdeudede?d&evfddZdeude?d&evfddZdted&e'evewexf fddZdend&e%eA fddĄZdend&e%e@ fddƄZdend&e%eu fddȄZddʜdteudeuded&dfdd΄Zdteudeude?d&dfddЄZe	d&e d fdd҄ZdddԄZdddքZedkr[e  dS dS )    N)JSONDecodeError)ExecutorThreadPoolExecutorProcessPoolExecutor)contextmanager)datetime)Enum)Managerfreeze_support)Path)GitWildMatchPatternError)AnyDict	GeneratorIteratorListMutableMappingOptionalPatternSetSizedTupleUnion)replace)DEFAULT_LINE_LENGTHDEFAULT_INCLUDESDEFAULT_EXCLUDES)STDIN_PLACEHOLDER)STARSsymsis_simple_decorator_expression)LineEmptyLineTracker)transform_lineLineGeneratorLN)normalize_fmt_off)ModeTargetVersion)Featuresupports_featureVERSION_TO_FEATURES)
read_cachewrite_cacheget_cache_infofilter_cachedCache)cancelshutdownmaybe_install_uvloop)dump_to_file
ipynb_diffdiff
color_diffouterr)ReportChangedNothingChanged)find_project_rootfind_pyproject_tomlparse_pyproject_toml)gen_python_filesget_gitignorenormalize_path_maybe_ignore)wrap_stream_for_windows)InvalidInput)lib2to3_parse	parse_aststringify_ast)	mask_cellunmask_cellremove_trailing_semicolonput_trailing_semicolon_backTRANSFORMED_MAGICS"jupyter_dependencies_are_installed)NodeLeaf)token)versionc                
   @   sD   e Zd ZdZdZdZdZdZeddde	d	e	d
e	dd fddZ
dS )	WriteBackr               F)colorcheckr6   rW   returnc                C   s,   |r|s| j S |r|r| jS |r| jS | jS N)CHECK
COLOR_DIFFDIFFYES)clsrX   r6   rW    r`   M/var/www/secure340b-portal/env/lib/python3.10/site-packages/black/__init__.pyfrom_configurationR   s
   zWriteBack.from_configurationN)__name__
__module____qualname__NOr^   r]   r[   r\   classmethodboolrb   r`   r`   r`   ra   rR   K   s"    rR   ctxparamvaluerY   c              
   C   s   |st | jdd}|du rdS zt|}W n ttfy/ } z
tj|d| dd}~ww |s4dS dd | D }|d}|durQt	|t
sQtd	d
i }| jr\|| j || || _|S )zInject Black configuration from "pyproject.toml" into defaults in `ctx`.

    Returns the path to a successfully found and read configuration file, None
    otherwise.
    srcr`   Nz"Error reading configuration file: )filenamehintc                 S   s,   i | ]\}}|t |ttfst|n|qS r`   )
isinstancelistdictstr).0kvr`   r`   ra   
<dictcomp>}   s    z'read_pyproject_toml.<locals>.<dictcomp>target_versionztarget-versionz(Config key target-version must be a list)r>   paramsgetr?   OSError
ValueErrorclickZ	FileErroritemsro   rp   ZBadOptionUsagedefault_mapupdate)ri   rj   rk   configerw   r~   r`   r`   ra   read_pyproject_tomlc   s8   


r   cpru   .c                 C   s   dd |D S )zCompute the target versions from a --target-version flag.

    This is its own function because mypy couldn't infer the type correctly
    when it was a lambda, causing mypyc trouble.
    c                 S   s   g | ]}t |  qS r`   )r(   upper)rs   valr`   r`   ra   
<listcomp>   s    z2target_version_option_callback.<locals>.<listcomp>r`   )r   r   ru   r`   r`   ra   target_version_option_callback   s   r   regexc                 C   s   d| v rd|  } t | }|S )zdCompile a regular expression string in `regex`.

    If it contains newlines, use verbose mode.
    
z(?x))recompile)r   compiledr`   r`   ra   re_compile_maybe_verbose   s   
r   c                 C   s4   z|d ur
t |W S d W S  tjy   tdw )NzNot a valid regular expression)r   r   errorr|   ZBadParameter)ri   rj   rk   r`   r`   ra   validate_regex   s
   
r   z-hz--help)Zhelp_option_names)Zcontext_settingsz-cz--codez&Format the code passed in as a string.)typehelpz-lz--line-lengthz&How many characters per line to allow.T)r   defaultr   show_defaultz-tz--target-versionc                 C   s   g | ]}|j  qS r`   )namelower)rs   ru   r`   r`   ra   r      s    r   z^Python versions that should be supported by Black's output. [default: per-file auto-detection])r   callbackmultipler   z--pyiztFormat all input files like typing stubs regardless of file extension (useful when piping source on standard input).)is_flagr   z--ipynbzyFormat all input files like Jupyter Notebooks regardless of file extension (useful when piping source on standard input).z-Sz--skip-string-normalizationz*Don't normalize string quotes or prefixes.z-Cz--skip-magic-trailing-commaz5Don't use trailing commas as a reason to split lines.z --experimental-string-processingz}Experimental option that performs more normalization on string literals. Currently disabled because it leads to some crashes.)r   hiddenr   z--checkzDon't write the files back, just return the status. Return code 0 means nothing would change. Return code 1 means some files would be reformatted. Return code 123 means there was an internal error.z--diffzGDon't write the files back, just output a diff for each file on stdout.z--color/--no-colorz7Show colored diff. Only applies when `--diff` is given.z--fast/--safez@If --fast given, skip temporary sanity checks. [default: --safe]z--required-versionzRequire a specific version of Black to be running (useful for unifying results across many environments e.g. with a pyproject.toml file).z	--includea"  A regular expression that matches files and directories that should be included on recursive searches. An empty value means all files are included regardless of the name. Use forward slashes for directories on all platforms (Windows, too). Exclusions are calculated first, inclusions later.)r   r   r   r   r   z	--excludea  A regular expression that matches files and directories that should be excluded on recursive searches. An empty value means no paths are excluded. Use forward slashes for directories on all platforms (Windows, too). Exclusions are calculated first, inclusions later. [default: ]F)r   r   r   r   z--extend-excludezLike --exclude, but adds additional files and directories on top of the excluded ones. (Useful if you simply want to add to the default))r   r   r   z--force-excludezLike --exclude, but files and directories matching this regex will be excluded even when they are passed explicitly as arguments.z--stdin-filenamezThe name of the file when passing it through stdin. Useful to make sure Black will respect --force-exclude option on some editors that rely on using stdin.z-qz--quietzbDon't emit non-error messages to stderr. Errors are still emitted; silence those with 2>/dev/null.z-vz	--verboseziAlso emit messages to stderr about files that were not changed or were ignored due to exclusion patterns.rl   )exists	file_okaydir_okayreadable
allow_dashzSRC ...)nargsr   is_eagermetavarz--config)r   r   r   r   r   	path_typez"Read configuration from FILE path.)r   r   r   r   codeline_lengthrw   rX   r6   rW   fastpyiipynbskip_string_normalizationskip_magic_trailing_commaexperimental_string_processingquietverboserequired_versionincludeexcludeextend_excludeforce_excludestdin_filenamer   c                 C   s  |r|rt d| dddd d}|r)|tkr)t| d| dt d	 | d
 |	r6|r6td | d
 tj|||d}|rEt|}nt }t||||	|
 | |d}|dur[d}t||||d}|durqt	|||||d nBzt
| |||||||||d
}W n ty   | d
 Y nw t|d|||  t|d
krt| ||||d n	t|||||d |s|st |jr|nd |du rtjt|dd | |j dS )z"The uncompromising code formatter.zUsing configuration from .Fblue)boldfgu   Oh no! 💥 💔 💥z The required version `z&` does not match the running version `z`!rS   z)Cannot pass both `pyi` and `ipynb` flags!)rX   r6   rW   )target_versionsr   is_pyiis_ipynbZstring_normalizationZmagic_trailing_commar   NT)rX   r6   r   r   )contentr   
write_backmodereport)
ri   rl   r   r   r   r   r   r   r   r   u?   No Python files are present to be formatted. Nothing to do 😴)rl   r   r   r   r   )sourcesr   r   r   r   u   All done! ✨ 🍰 ✨)r9   )r8   __version__r9   exitrR   rb   setr'   r:   reformat_codeget_sourcesr   
path_emptylenreformat_onepopreformat_manyZreturn_coder|   Zechorr   )ri   r   r   rw   rX   r6   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rl   r   	error_msgr   versionsr   r   r   r`   r`   ra   main   s    U





r   r   r:   c        
         C   sX  t |}
t }t|d|||  |du rtt}t|
}nd}|D ]}|dkr/|	r/t|	}d}nt|}d}|s;| rt||
|}|du rFq d| }|rR|	|}nd}|rb|
drb||d q |rntt t| }|jd	krzt||d
szq || q | r|t| |
||||||||d

 q |dkr|| q td|  q |S )z)Compute the set of files to be formatted.u$   No Path provided. Nothing to do 😴N-TF/r   z.matches the --force-exclude regular expression.ipynb)r   r   zinvalid path: )r=   r   r   r   r   rA   r   is_filerB   searchgroupZpath_ignoredr   rr   suffixrM   addis_dirr   r@   iterdirr9   )ri   rl   r   r   r   r   r   r   r   r   rootr   Z	gitignoresr   is_stdinZnormalized_pathZforce_exclude_matchr`   r`   ra   r     sd   
r   msgc                 C   s&   | s|s|s
t | |d dS dS )z;
    Exit if there is no `src` provided for formatting
    r   N)r8   r   )rl   r   r   r   ri   r`   r`   ra   r   /  s
   r   r   r   r   c              
   C   s|   t d}ztj}t| |||drtj}||| W dS  ty= } z|jr*t	  |
|t| W Y d}~dS d}~ww )a  
    Reformat and print out `content` without spawning child processes.
    Similar to `reformat_one`, but for string content.

    `fast`, `write_back`, and `mode` options are passed to
    :func:`format_file_in_place` or :func:`format_stdin_to_stdout`.
    z<string>)r   r   r   r   N)r   r;   rf   format_stdin_to_stdoutr^   done	Exceptionr   	traceback	print_excfailedrr   )r   r   r   r   r   pathchangedexcr`   r`   ra   r   ;  s   
r   c              
   C   s  zt j}t| dkrd}nt| tr#d}tt| ttd } nd}|rI| jdkr3t|dd}n| jdkr>t|dd}t	|||d	rHt j
}nPi }|tjtjfvrnt|}|  }t|}	|	|v rn||	 t|krnt j}|t jur~t| |||d	r~t j
}|tj
u r|t jus|tju r|t ju rt|| g| || | W dS  ty }
 z|jrt  || t|
 W Y d}
~
dS d}
~
ww )
zReformat a single file under `src` without spawning child processes.

    `fast`, `write_back`, and `mode` options are passed to
    :func:`format_file_in_place` or :func:`format_stdin_to_stdout`.
    r   TNF.pyir   r   r   )r   r   r   )r;   rf   rr   
startswithr   r   r   r   r   r   r^   rR   r]   r\   r,   resolver.   CACHEDformat_file_in_placer[   r-   r   r   r   r   r   r   )rl   r   r   r   r   r   r   cacheZres_srcZ	res_src_sr   r`   r`   ra   r   S  sP   

r   r   c                 C   s   t  }t }tjdkrt|d}zt|d}W n tt	fy)   t
dd}Y nw z|t| ||||||d W t| |durH|  dS dS t| |durW|  w w )z4Reformat multiple files using a ProcessPoolExecutor.win32<   )max_workersrS   )r   r   r   r   r   loopexecutorN)asyncioget_event_loopos	cpu_countsysplatformminr   ImportErrorrz   r   run_until_completeschedule_formattingr2   )r   r   r   r   r   r   Zworker_countr   r`   r`   ra   r     s:   


r   r   r   c                    s  i }t jt jfvr$t}t|| \} }t|D ]	}	||	tj q| s(dS g }
g }dt jt jfv r=t	 }|
  fddt| D }| }ztjt| tjt| W n	 tyl   Y nw |rtj|tjdI dH \}}|D ]D}||}	| r|
| q~| r||	t|  q~| rtjntj}t ju st ju r|tju r||	 ||	| q~|so|
rtj|
ddI dH  |rt || dS dS )zRun formatting of `sources` in parallel using the provided `executor`.

    (Use ProcessPoolExecutors for actual parallelism.)

    `write_back`, `fast`, and `mode` options are passed to
    :func:`format_file_in_place`.
    Nc                    s*   i | ]}t  t||qS r`   )r   ensure_futurerun_in_executorr   )rs   rl   r   r   lockr   r   r   r`   ra   rv     s    z'schedule_formatting.<locals>.<dictcomp>)return_whenT)r   return_exceptions)!rR   r]   r\   r,   r/   sortedr   r;   r   r	   Lockkeysadd_signal_handlersignalSIGINTr1   SIGTERMNotImplementedErrorr   waitFIRST_COMPLETEDr   	cancelledappend	exceptionr   rr   resultr^   rf   r[   gatherr-   )r   r   r   r   r   r   r   r   cachedrl   r  Zsources_to_cachemanagertaskspendingr   _taskr   r`   r   ra   r     s^   


r   r   c                 C   s  | j dkrt|dd}n| j dkrt|dd}t|  j}t| d}t| \}}}	W d   n1 s8w   Y  z	t	|||d}
W n t
yP   Y d	S  ty^   td
|  dw |tjkrt| d||	d}||
 W d   dS 1 s}w   Y  dS |tjtjfv rt }|  d| d}|  d| d}|jrt||
||}nt||
||}|tjkrt|}|pt ! tjtjj||	dd}t|}|| |  W d   dS 1 sw   Y  dS )zFormat file under `src` path. Return True if changed.

    If `write_back` is DIFF, write a diff to stdout. If it is YES, write reformatted
    code to the file.
    `mode` and `fast` options are passed to :func:`format_file_contents`.
    r   Tr   r   r   rbNr   r   FzFile 'z-' cannot be parsed as valid Jupyter notebook.w)encodingnewline	 +0000r  r  write_through)r   r   r   utcfromtimestampstatst_mtimeopendecode_bytesreadformat_file_contentsr<   r   r{   rR   r^   writer]   r\   utcnowr   r5   r6   r7   nullcontextioTextIOWrapperr   stdoutbufferrC   detach)rl   r   r   r   r   thenbufsrc_contentsr  r  dst_contentsfnowsrc_namedst_nameZdiff_contentsr`   r`   ra   r     sZ   







r   )r   r   c                C   s  t  }|du rttjj \}}}n|dd}}}|}zzbt|| |d}W W tj	tj
j||dd}	|tjkrK|rE|d dkrE|d7 }|	| n1|tjtjfv r|t  }
d	| d
}d|
 d
}t||||}|tjkrwt|}t|	}	|	| |	  dS  ty   Y W tj	tj
j||dd}	|tjkr|r|d dkr|d7 }|	| n1|tjtjfv rt  }
d	| d
}d|
 d
}t||||}|tjkrt|}t|	}	|	| |	  dS w tj	tj
j||dd}	|tjkr	|r|d dkr|d7 }|	| n3|tjtjfv r<t  }
d	| d
}d|
 d
}t||||}|tjkr7t|}t|	}	|	| |	  w )a  Format file on stdin. Return True if changed.

    If content is None, it's read from sys.stdin.

    If `write_back` is YES, write reformatted code back to stdout. If it is DIFF,
    write a diff to stdout. The `mode` argument is passed to
    :func:`format_file_contents`.
    Nzutf-8 r  Tr  r   r   zSTDIN	r  zSTDOUT	F)r   r)  r%  r   stdinr.  r&  r'  r+  r,  r-  rR   r^   r(  r]   r\   r6   r7   rC   r/  r<   )r   r   r   r   r0  rl   r  r  dstr4  r5  r6  r7  dr`   r`   ra   r   +  s|   







r   r2  r3  c                C   sF   t | | t||d}||kr!|}t | |dd t| ||d dS dS )zPerform stability and equivalence checks.

    Raise AssertionError if source and destination contents are not
    equivalent, or if a second pass of the formatter would format the
    content differently.
    r   rT   pass_numN)assert_equivalent
format_strassert_stable)r2  r3  r   Zdst_contents_pass2r`   r`   ra   check_stability_and_equivalence^  s   
	rB  c                C   sV   |   st|jrt| ||d}nt| |d}| |krt|s)|js)t| ||d |S )a   Reformat contents of a file and return new contents.

    If `fast` is False, additionally confirm that the reformatted code is
    valid by calling :func:`assert_equivalent` and :func:`assert_stable` on it.
    `mode` is passed to :func:`format_str`.
    r  r<  )stripr<   r   format_ipynb_stringr@  rB  )r2  r   r   r3  r`   r`   ra   r'  u  s   
r'  c                    s   t  fddtD rtdS )a  Check that cell does not already contain TransformerManager transformations.

    If a cell contains ``!ls``, then it'll be transformed to
    ``get_ipython().system('ls')``. However, if the cell originally contained
    ``get_ipython().system('ls')``, then it would get transformed in the same way:

        >>> TransformerManager().transform_cell("get_ipython().system('ls')")
        "get_ipython().system('ls')
"
        >>> TransformerManager().transform_cell("!ls")
        "get_ipython().system('ls')
"

    Due to the impossibility of safely roundtripping in such situations, cells
    containing transformed magics will be ignored.
    c                 3   s    | ]}| v V  qd S rZ   r`   )rs   Ztransformed_magicrl   r`   ra   	<genexpr>  s    z validate_cell.<locals>.<genexpr>N)anyrL   r<   rE  r`   rE  ra   validate_cell  s   rH  c          
      C   s   t |  t| \}}zt|\}}W n	 ty   tw t||d}|s+t|||d t||}t||}	|		d}	|	| kr@t|	S )a  Format code in given cell of Jupyter notebook.

    General idea is:

      - if cell has trailing semicolon, remove it;
      - if cell has IPython magics, mask them;
      - format cell;
      - reinstate IPython magics;
      - reinstate trailing semicolon (if originally present);
      - strip trailing newlines.

    Cells with syntax errors will not be processed, as they
    could potentially be automagics or multi-line magics, which
    are currently not supported.
    r<  r   )
rH  rJ   rH   SyntaxErrorr<   r@  rB  rI   rK   rstrip)
rl   r   r   Zsrc_without_trailing_semicolonZhas_trailing_semicolonZ
masked_srcreplacementsZ
masked_dstZdst_without_trailing_semicolonr:  r`   r`   ra   format_cell  s(   

rL  nbc                 C   s8   |  di  di  dd}|dur|dkrtdS dS )zIf notebook is marked as non-Python, don't format it.

    All notebook metadata fields are optional, see
    https://nbformat.readthedocs.io/en/latest/format_description.html. So
    if a notebook has empty metadata, we will try to parse it anyway.
    metadataZlanguage_infor   Npython)ry   r<   )rM  languager`   r`   ra   validate_metadata  s   rQ  c          
   	   C   s   | d dk}d}t | }t| |d D ].}|dddkrCzd|d	 }t|||d
}W n	 ty8   Y qw |jdd|d	< d}q|rVt j|ddd}	|rT|	d }	|	S t)zFormat Jupyter notebook.

    Operate cell-by-cell, only on code cells, only for Python notebooks.
    If the ``.ipynb`` originally had a trailing newline, it'll be preserved.
    r   r   FcellsZ	cell_typeNr   r8  sourcer  T)keependsrS   )indentensure_ascii)	jsonloadsrQ  ry   joinrL  r<   
splitlinesdumps)
r2  r   r   Ztrailing_newlinemodifiedrM  cellrl   r:  r3  r`   r`   ra   rD    s*   
rD  c                   s   t |  |j}g }t|}|jr|j nt| t| t|d|v p(t tj	d}t
|jd}t|d}d} fddtjtjhD }	||D ],}
|t||  ||
\}}|t||  t|
||	dD ]	}|t| qlqJd	|S )
a  Reformat a string and return new contents.

    `mode` determines formatting options, such as how many characters per line are
    allowed.  Example:

    >>> import black
    >>> print(black.format_str("def f(arg:str='')->None:...", mode=black.Mode()))
    def f(arg: str = "") -> None:
        ...

    A more complex example:

    >>> print(
    ...   black.format_str(
    ...     "def f(arg:str='')->None: hey",
    ...     mode=black.Mode(
    ...       target_versions={black.TargetVersion.PY36},
    ...       line_length=10,
    ...       string_normalization=False,
    ...       is_pyi=False,
    ...     ),
    ...   ),
    ... )
    def f(
        arg: str = '',
    ) -> None:
        hey

    unicode_literals)r   Zremove_u_prefixr   r<  r   c                    s   h | ]	}t  |r|qS r`   )r*   )rs   featurer   r`   ra   	<setcomp>  s    zformat_str.<locals>.<setcomp>)r   featuresr8  )rE   lstripr   get_future_importsdetect_target_versionsr&   r$   r*   r)   ZUNICODE_LITERALSr"   r   r!   TRAILING_COMMA_IN_CALLTRAILING_COMMA_IN_DEFvisitr  rr   Zmaybe_empty_linesr#   rY  )r2  r   Zsrc_noder3  Zfuture_importslineseltZ
empty_lineafterZsplit_line_featurescurrent_linebeforeliner`   r`  ra   r@    s8   





r@  c                 C   s   t | }t|j\}}|sd|dfS d|d dd kr dnd}|d t ||}| ||fW  d   S 1 s?w   Y  dS )zReturn a tuple of (decoded_contents, encoding, newline).

    `newline` is either CRLF or LF but `decoded_contents` is decoded with
    universal newlines (i.e. only contains LF).
    r8  r   s   
r   Nz
)r+  BytesIOtokenizedetect_encodingreadlineseekr,  r&  )rl   Zsrcbufr  ri  r  Ztiowr`   r`   ra   r%  +  s   


$r%  nodec                 C   s  t  }|  D ]}|jtjkr!|jdd }|dv r |tj q|jtj	kr3d|jv r2|tj
 q|jtjkrM|jrL|jjtjtjhv rL|tj q|jtjkrZ|tj q|jtjkrut|jdkrtt|jd st|tj q|jtjtjhv r|jr|jd jtjkr|jtjkrtj}ntj}|jD ]"}|jtv r|| |jtjkr|jD ]}|jtv r|| qqq|S )ac  Return a set of (relatively) new Python features used in this file.

    Currently looking for:
    - f-strings;
    - underscores in numeric literals;
    - trailing commas after * or ** in function signatures and calls;
    - positional only arguments in function signatures and lambdas;
    - assignment expression;
    - relaxed decorator syntax;
    NrT   >   FRRFF"F'f"f'frrfr  rS   r   )r   Z	pre_orderr   rP   STRINGrk   r   r)   Z	F_STRINGSNUMBERZNUMERIC_UNDERSCORESSLASHparentr   ZtypedargslistZarglistZPOS_ONLY_ARGUMENTS
COLONEQUALZASSIGNMENT_EXPRESSIONS	decoratorr   childrenr    ZRELAXED_DECORATORSCOMMArg  rf  r   argument)ru  rb  nZ
value_headr_  chZargchr`   r`   ra   get_features_used<  sR   






r  c                    s   t |   fddtD S )z5Detect the version to target based on the nodes used.c                    s   h | ]
} t | kr|qS r`   )r+   )rs   rQ   rb  r`   ra   ra  x  s
    z)detect_target_versions.<locals>.<setcomp>)r  r(   )ru  r`   r  ra   re  u  s   
re  c                    s   t  }dtt dttddf f fdd | jD ]W}|jtjkr# |S |jd }t	|t
rGt|jdkrD|jtjkrD|jd jtjkrDq |S |jtjkrm|jd }t	|t
r\|jd	kr_ |S |t  |jd
d O }q |S |S )z/Return a set of __future__ imports in the file.r  rY   Nc                 3   s    | D ]G}t |tr|jtjkr|jV  q|jtjkr8|jd }t |ts)J d|jtjks3J d|jV  q|jtj	krG |jE d H  qt
dd S )Nr   zInvalid syntax parsing imports)ro   rO   r   rP   NAMErk   r   Zimport_as_namer  Zimport_as_namesAssertionError)r  childZ	orig_nameget_imports_from_childrenr`   ra   r    s   


z5get_future_imports.<locals>.get_imports_from_childrenr   rT   rS   
__future__rU   )r   r   r%   r   rr   r  r   r   Zsimple_stmtro   rO   r   rP   r~  NEWLINEZimport_fromrk   )ru  Zimportsr  Zfirst_childmodule_namer`   r  ra   rd  }  s2   $




rd  rS   r=  r:  r>  c          	   
   C   s   zt | }W n ty } ztd| d}~ww zt |}W n& tyF } ztdt|j|}td| d| d| dd}~ww dt|}dt|}||krmtt	||dd	}td
| d| ddS )z:Raise AssertionError if `src` and `dst` aren't equivalent.zScannot use --safe with this file; failed to parse source file.  AST error message: Nr8  z4INTERNAL ERROR: Black produced invalid code on pass z: ze. Please report a bug on https://github.com/psf/black/issues.  This invalid output might be helpful: r   rl   r:  zQINTERNAL ERROR: Black produced code that is not equivalent to the source on pass z\.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: )
rF   r   r  r4   rY  r   	format_tb__traceback__rG   r6   )	rl   r:  r>  Zsrc_astr   Zdst_astlogZsrc_ast_strZdst_ast_strr`   r`   ra   r?    sJ   r?  c                 C   sL   t ||d}||kr$tt|t| |ddt||dd}td| ddS )zDRaise AssertionError if `dst` reformats differently the second time.r<  rS  z
first passzsecond passzINTERNAL ERROR: Black produced different code on the second pass of the formatter.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: N)r@  r4   rr   r6   r  )rl   r:  r   Znewdstr  r`   r`   ra   rA    s   rA  c                   c   s    dV  dS )zWReturn an empty context manager.

    To be used like `nullcontext` in Python 3.7.
    Nr`   r`   r`   r`   ra   r*    s   
r*  c                  C   sl   zddl m}  ddl m} W n
 ty   Y dS w | |fD ]}t|dr)dd |_t|dr3d	d |_qdS )
a  Make Click not crash on Python 3.6 with LANG=C.

    On certain misconfigured environments, Python 3 selects the ASCII encoding as the
    default which restricts paths that it can access during the lifetime of the
    application.  Click refuses to work in this scenario by raising a RuntimeError.

    In case of Black the likelihood that non-ASCII characters are going to be used in
    file paths is minimal since it's Python source code.  Moreover, this crash was
    spurious on Python 3.7 thanks to PEP 538 and PEP 540.
    r   )core)_unicodefunN_verify_python3_envc                   S      d S rZ   r`   r`   r`   r`   ra   <lambda>      zpatch_click.<locals>.<lambda>_verify_python_envc                   S   r  rZ   r`   r`   r`   r`   ra   r    r  )r|   r  r  ModuleNotFoundErrorhasattrr  r  )r  r  moduler`   r`   ra   patch_click  s   



r  c                   C   s   t   t  t  t  d S rZ   )r3   r
   r  r   r`   r`   r`   ra   patched_main  s   
r  __main__)rY   N)r   Zjson.decoderr   rW  concurrent.futuresr   r   r   
contextlibr   r   enumr   r+  multiprocessingr	   r
   r   pathlibr   Zpathspec.patterns.gitwildmatchr   r   r   r  r   rq  r   typingr   r   r   r   r   r   r   r   r   r   r   r   dataclassesr   r|   Zblack.constr   r   r   r   Zblack.nodesr   r   r    Zblack.linesr!   r"   Zblack.linegenr#   r$   r%   Zblack.commentsr&   Z
black.moder'   r(   r)   r*   r+   Zblack.cacher,   r-   r.   r/   r0   Zblack.concurrencyr1   r2   r3   Zblack.outputr4   r5   r6   r7   r8   r9   Zblack.reportr:   r;   r<   Zblack.filesr=   r>   r?   r@   rA   rB   rC   Zblack.parsingrD   rE   rF   rG   Zblack.handle_ipynb_magicsrH   rI   rJ   rK   rL   rM   Zblib2to3.pytreerN   rO   Zblib2to3.pgen2rP   Z_black_versionrQ   r   rr   ZFileContentEncodingNewLinerR   ZFileModeContext	Parameterr   Optionr   r   r   commandrq   optionintZChoiceZversion_optionr  Zpass_contextrh   r   r   r   r   r   r   AbstractEventLoopr   rf   r   r   rB  r'  rH  rL  rQ  rD  r@  bytesr%  r  re  rd  r?  rA  r*  r  r  rc   r`   r`   r`   ra   <module>   s:   8  
.


						
	
		

<t



	

O


3
%
K
<
3
%>9 2



