§
    ZQdN.  ã                   ó�   — d Z ddlmZ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	Z	ddl
mZ d„ Z G d„ dej        ¦  «        Zd	„ Zdd
„ZdS )z
Main program for 2to3.
é    )Úwith_statementÚprint_functionNé   )Úrefactorc           	      óˆ   — |                       ¦   «         } |                      ¦   «         }t          j        | |||ddd¬¦  «        S )z%Return a unified diff of two strings.z
(original)z(refactored)Ú )Úlineterm)Ú
splitlinesÚdifflibÚunified_diff)ÚaÚbÚfilenames      ú#/usr/lib/python3.11/lib2to3/main.pyÚ
diff_textsr      sF   € à	�Š‰Œ€AØ	�Š‰Œ€AÝÔ  1 h°Ø ,¨nØ)+ð-ñ -ô -ð -ó    c                   ó<   ‡ — e Zd ZdZ	 dˆ fd„	Zd„ Zˆ fd„Zd„ Zˆ xZS )ÚStdoutRefactoringToola2  
    A refactoring tool that can avoid overwriting its input files.
    Prints output to stdout.

    Output files can optionally be written to a different directory and or
    have an extra file suffix appended to their name for use in situations
    where you do not want to replace the input files.
    r   c	                 ó  •— || _         || _        |r.|                     t          j        ¦  «        s|t          j        z  }|| _        || _        || _        t          t          | ¦  «         
                    |||¦  «         dS )aF  
        Args:
            fixers: A list of fixers to import.
            options: A dict with RefactoringTool configuration.
            explicit: A list of fixers to run even if they are explicit.
            nobackups: If true no backup '.bak' files will be created for those
                files that are being refactored.
            show_diffs: Should diffs of the refactoring be printed to stdout?
            input_base_dir: The base directory for all input files.  This class
                will strip this path prefix off of filenames before substituting
                it with output_dir.  Only meaningful if output_dir is supplied.
                All files processed by refactor() must start with this path.
            output_dir: If supplied, all converted files will be written into
                this directory tree instead of input_base_dir.
            append_suffix: If supplied, all files output by this tool will have
                this appended to their filename.  Useful for changing .py to
                .py3 for example by passing append_suffix='3'.
        N)Ú	nobackupsÚ
show_diffsÚendswithÚosÚsepÚ_input_base_dirÚ_output_dirÚ_append_suffixÚsuperr   Ú__init__)
ÚselfÚfixersÚoptionsÚexplicitr   r   Úinput_base_dirÚ
output_dirÚappend_suffixÚ	__class__s
            €r   r   zStdoutRefactoringTool.__init__$   s   ø€ ð( #ˆŒØ$ˆŒØð 	% .×"9Ò"9½"¼&Ñ"AÔ"Að 	%Ø�bœfÑ$ˆNØ-ˆÔØ%ˆÔØ+ˆÔÝÕ# TÑ*Ô*×3Ò3°F¸GÀXÑNÔNÐNÐNÐNr   c                 ól   — | j                              |||f¦  «          | j        j        |g|¢R i |¤Ž d S ©N)ÚerrorsÚappendÚloggerÚerror)r    ÚmsgÚargsÚkwargss       r   Ú	log_errorzStdoutRefactoringTool.log_errorA   sJ   € ØŒ×Ò˜C  vÐ.Ñ/Ô/Ð/ØˆŒÔ˜#Ð/ Ð/Ð/Ð/¨Ð/Ð/Ð/Ð/Ð/r   c                 ó  •— |}| j         rt|                     | j        ¦  «        r@t          j                             | j         |t          | j        ¦  «        d …         ¦  «        }nt          d|›d| j        ›�¦  «        ‚| j        r
|| j        z  }||k    rkt          j         	                    |¦  «        }t          j         
                    |¦  «        s|rt          j        |¦  «         |                      d||¦  «         | j        sž|dz   }t          j                             |¦  «        r<	 t          j        |¦  «         n&# t           $ r |                      d|¦  «         Y nw xY w	 t          j        ||¦  «         n'# t           $ r |                      d||¦  «         Y nw xY wt%          t&          | ¦  «        j        } |||||¦  «         | j        st+          j        ||¦  «         ||k    rt+          j        ||¦  «         d S d S )Nz	filename z( does not start with the input_base_dir zWriting converted %s to %s.z.bakzCan't remove backup %szCan't rename %s to %s)r   Ú
startswithr   r   ÚpathÚjoinÚlenÚ
ValueErrorr   ÚdirnameÚisdirÚmakedirsÚlog_messager   ÚlexistsÚremoveÚOSErrorÚrenamer   r   Ú
write_fileÚshutilÚcopymode)
r    Únew_textr   Úold_textÚencodingÚorig_filenamer%   ÚbackupÚwriter'   s
            €r   r@   z StdoutRefactoringTool.write_fileE   sd  ø€ Ø ˆØÔð 	JØ×"Ò" 4Ô#7Ñ8Ô8ð JÝœ7Ÿ<š<¨Ô(8Ø(0µ°TÔ5IÑ1JÔ1JÐ1KÐ1KÔ(LñNô N��õ !�jà)1¨¨°4Ô3GÐ3Gð"Iñ Jô Jð Jð Ôð 	,Ø˜Ô+Ñ+ˆHØ˜HÒ$Ð$ÝœŸš¨Ñ2Ô2ˆJÝ”7—=’= Ñ,Ô,ð (°ð (Ý”˜JÑ'Ô'Ð'Ø×ÒÐ:¸MØ%ñ'ô 'ð 'àŒ~ð 	Là Ñ&ˆFÝŒw�Š˜vÑ&Ô&ð GðGÝ”I˜fÑ%Ô%Ð%Ð%øÝð Gð Gð GØ×$Ò$Ð%=¸vÑFÔFÐFÐFÐFðGøøøðLÝ”	˜( FÑ+Ô+Ð+Ð+øÝð Lð Lð LØ× Ò Ð!8¸(ÀFÑKÔKÐKÐKÐKðLøøøõ Õ+¨TÑ2Ô2Ô=ˆØˆˆh˜ (¨HÑ5Ô5Ð5ØŒ~ð 	.ÝŒO˜F HÑ-Ô-Ð-Ø˜HÒ$Ð$åŒO˜M¨8Ñ4Ô4Ð4Ð4Ð4ð %Ð$s$   Ä-E Å E%Å$E%Å)E? Å?!F#Æ"F#c                 óÄ  — |r|                       d|¦  «         d S |                       d|¦  «         | j        r¨t          |||¦  «        }	 | j        �U| j        5  |D ]}t	          |¦  «         Œt
          j                             ¦   «          d d d ¦  «         n# 1 swxY w Y   d S d S |D ]}t	          |¦  «         Œd S # t          $ r t          d|›d�¦  «         Y d S w xY wd S )NzNo changes to %szRefactored %szcouldn't encode z's diff for your terminal)
r;   r   r   Úoutput_lockÚprintÚsysÚstdoutÚflushÚUnicodeEncodeErrorÚwarn)r    ÚoldÚnewr   ÚequalÚ
diff_linesÚlines          r   Úprint_outputz"StdoutRefactoringTool.print_outputl   s|  € Øð 	Ø×ÒÐ/°Ñ:Ô:Ð:Ð:Ð:à×Ò˜_¨hÑ7Ô7Ð7ØŒð Ý'¨¨S°(Ñ;Ô;�
ðØÔ'Ð3Ø!Ô-ð /ð /Ø(2ð ,ð , Ý % d¡¤  ÝœJ×,Ò,Ñ.Ô.Ð.ð/ð /ð /ñ /ô /ð /ð /ð /ð /ð /ð /øøøð /ð /ð /ð /ð /ð /ð /ð /ð
 %/ð (ð (˜DÝ! $™KœK˜K˜Kð(ð (øå)ð ð ð Ý�DØ"˜(˜(ð%ñ &ô &ð &à�F�Fðøøøðð s<   Á
B< Á3BÂB< ÂBÂB< ÂBÂB< Â&B< Â<CÃC)r   r   r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r1   r@   rV   Ú__classcell__)r'   s   @r   r   r      sŒ   ø€ € € € € ðð ð BDðOð Oð Oð Oð Oð Oð:0ð 0ð 0ð%5ð %5ð %5ð %5ð %5ðNð ð ð ð ð ð r   r   c                 óB   — t          d| ›�t          j        ¬¦  «         d S )Nz	WARNING: ©Úfile)rK   rL   Ústderr)r.   s    r   rP   rP   �   s$   € Ý	€E˜3˜3Ð
 ¥s¤zÐ2Ñ2Ô2Ð2Ð2Ð2r   c           
      ó¬  ‡ — t          j        d¬¦  «        }|                     dddd¬¦  «         |                     dd	d
g d¬¦  «         |                     dddddd¬¦  «         |                     ddd
g d¬¦  «         |                     dddd¬¦  «         |                     dddd¬¦  «         |                     dddd¬¦  «         |                     d d!dd"¬¦  «         |                     d#dd$¬¦  «         |                     d%d&dd'¬¦  «         |                     d(d)dd*d+¬¦  «         |                     d,d-dd.d/d0¬1¦  «         |                     d2d3dd4¬¦  «         |                     d5dd.d/d6¬1¦  «         d*}i }|                     |¦  «        \  }}|j        r"d7|d8<   |j        st          d9¦  «         d7|_        |j        r|j        s| 	                    d:¦  «         |j
        r|j        s| 	                    d;¦  «         |j        s|j        rt          d<¦  «         |j        s|j        r| 	                    d=¦  «         |j        r9t          d>¦  «         t          j        ‰ ¦  «        D ]}t          |¦  «         Œ|sd?S |s8t          d@t           j        ¬A¦  «         t          dBt           j        ¬A¦  «         dCS dD|v r&d7}|j        rt          dEt           j        ¬A¦  «         dCS |j        rd7|dF<   |j        rd7|dG<   |j        rt*          j        nt*          j        }t+          j        dH|¬I¦  «         t+          j        dJ¦  «        }t5          t          j        ‰ ¦  «        ¦  «        }	t5          ˆ fdK„|j        D ¦   «         ¦  «        }
t5          ¦   «         }|j        rJd*}|j        D ]&}|dLk    rd7}Œ|                     ‰ dMz   |z   ¦  «         Œ'|r|	                     |¦  «        n|}n|	                     |¦  «        }|                      |
¦  «        }tB          j"         #                    |¦  «        }|r]| $                    tB          j%        ¦  «        s>tB          j"         &                    |¦  «        stB          j"         '                    |¦  «        }|j        r;| (                    tB          j%        ¦  «        }| )                    dN|j        |¦  «         tU          tW          |¦  «        |tW          |¦  «        |j        |j         ||j        |j
        ¬O¦  «        }|j,        s’|r| -                    ¦   «          ng	 |                     ||j        |j.        |j/        ¦  «         n># t          j0        $ r, |j/        dk    sJ ‚t          dPt           j        ¬A¦  «         Y dS w xY w| 1                    ¦   «          te          tg          |j,        ¦  «        ¦  «        S )QzþMain program.

    Args:
        fixer_pkg: the name of a package where the fixers are located.
        args: optional; a list of command line arguments. If omitted,
              sys.argv[1:] is used.

    Returns a suggested exit status (0, 1, 2).
    z2to3 [options] file|dir ...)Úusagez-dz--doctests_onlyÚ
store_truezFix up doctests only)ÚactionÚhelpz-fz--fixr+   z1Each FIX specifies a transformation; default: all)rc   Údefaultrd   z-jz--processesÚstorer   ÚintzRun 2to3 concurrently)rc   re   Útyperd   z-xz--nofixz'Prevent a transformation from being runz-lz--list-fixeszList available transformationsz-pz--print-functionz0Modify the grammar so that print() is a functionz-ez--exec-functionz/Modify the grammar so that exec() is a functionz-vz	--verbosezMore verbose loggingz
--no-diffsz#Don't show diffs of the refactoringz-wz--writezWrite back modified filesz-nz--nobackupsFz&Don't write backups for modified filesz-oz--output-dirÚstrr   zXPut output files in this directory instead of overwriting the input files.  Requires -n.)rc   rh   re   rd   z-Wz--write-unchanged-fileszYAlso write files even if no changes were required (useful with --output-dir); implies -w.z--add-suffixzuAppend this string to all output filenames. Requires -n if non-empty.  ex: --add-suffix='3' will generate .py3 files.TÚwrite_unchanged_filesz&--write-unchanged-files/-W implies -w.z%Can't use --output-dir/-o without -n.z"Can't use --add-suffix without -n.z@not writing files and not printing diffs; that's not very usefulzCan't use -n without -wz2Available transformations for the -f/--fix option:r   z1At least one file or directory argument required.r]   zUse --help to show usage.é   ú-zCan't write to stdin.r   Úexec_functionz%(name)s: %(message)s)ÚformatÚlevelzlib2to3.mainc              3   ó(   •K  — | ]}‰d z   |z   V — ŒdS )ú.fix_N© )Ú.0ÚfixÚ	fixer_pkgs     €r   ú	<genexpr>zmain.<locals>.<genexpr>â   s-   øè è € ÐLÐL°s˜ WÑ,¨sÑ2ÐLÐLÐLÐLÐLÐLr   Úallrq   z7Output in %r will mirror the input directory %r layout.)r$   r%   r&   z+Sorry, -j isn't supported on this platform.)4ÚoptparseÚOptionParserÚ
add_optionÚ
parse_argsrj   rH   rP   r%   r   r-   Ú
add_suffixÚno_diffsÚ
list_fixesrK   r   Úget_all_fix_namesrL   r_   r   rm   ÚverboseÚloggingÚDEBUGÚINFOÚbasicConfigÚ	getLoggerÚsetÚget_fixers_from_packageÚnofixrt   ÚaddÚunionÚ
differencer   r4   Úcommonprefixr   r   r9   r8   ÚrstripÚinfor   Úsortedr*   Úrefactor_stdinÚdoctests_onlyÚ	processesÚMultiprocessingUnsupportedÚ	summarizerg   Úbool)ru   r/   Úparserr�   Úflagsr"   Úfixnamero   r,   Úavail_fixesÚunwanted_fixesr#   Úall_presentrt   Ú	requestedÚfixer_namesr$   Úrts   `                 r   ÚmainrŸ   …   s!  ø€ õ Ô"Ð)FÐGÑGÔG€FØ
×Ò�dÐ-°lØ1ð ñ 3ô 3ð 3à
×Ò�d˜G¨H¸bØNð ñ Pô Pð Pà
×Ò�d˜M°'À1Ø Ð'>ð ñ @ô @ð @à
×Ò�d˜I¨hÀØDð ñ Fô Fð Fà
×Ò�d˜N°<Ø;ð ñ =ô =ð =à
×Ò�dÐ.°|ØMð ñ Oô Oð Oà
×Ò�dÐ-°lØLð ñ Nô Nð Nà
×Ò�d˜K°Ø1ð ñ 3ô 3ð 3à
×Ò�l¨<Ø@ð ñ Bô Bð Bà
×Ò�d˜I¨lØ6ð ñ 8ô 8ð 8à
×Ò�d˜M°,ÈØCð ñ Eô Eð Eà
×Ò�d˜N°7ÀØ ð (Nð ñ Oô Oð Oð ×Ò�dÐ5¸lðAð ñ Bô Bð Bð ×Ò�n¨W¸5È"ðGð ñ Hô Hð Hð €NØ€EØ×%Ò% dÑ+Ô+�M€GˆTØÔ$ð Ø)-ˆÐ%Ñ&ØŒ}ð 	;ÝÐ9Ñ:Ô:Ð:ØˆŒð Ôð > 'Ô"3ð >Ø�ŠÐ<Ñ=Ô=Ð=ØÔð ; 'Ô"3ð ;Ø�ŠÐ9Ñ:Ô:Ð:àŒ=ð Q˜WÔ-ð QÝÐOÑPÔPÐPØŒ=ð 0˜WÔ.ð 0Ø�ŠÐ.Ñ/Ô/Ð/ØÔð ÝÐBÑCÔCÐCÝÔ1°)Ñ<Ô<ð 	ð 	ˆGÝ�'‰NŒNˆNˆNØð 	Ø�1Øð ÝÐAÍÌ
ÐSÑSÔSÐSÝÐ)µ´
Ð;Ñ;Ô;Ð;ØˆqØ
ˆd€{€{ØˆØŒ=ð 	ÝÐ)µ´
Ð;Ñ;Ô;Ð;Ø�1ØÔð 'Ø"&ˆÐÑàÔð &Ø!%ˆˆoÑð %œ_Ð>�GŒMˆMµ'´,€EÝÔÐ6¸eÐDÑDÔDÐDÝÔ˜~Ñ.Ô.€Fõ •hÔ6°yÑAÔAÑBÔB€KÝÐLÐLÐLÐL¸g¼mÐLÑLÔLÑLÔL€NÝ‰uŒu€HØ„{ð 	0ØˆØ”;ð 	8ð 	8ˆCØ�eŠ|ˆ|Ø"��à—’˜Y¨Ñ0°3Ñ6Ñ7Ô7Ð7Ð7Ø3>ÐL�K×%Ò% hÑ/Ô/Ð/ÀHˆ	ˆ	à×%Ò% hÑ/Ô/ˆ	Ø×&Ò& ~Ñ6Ô6€KÝ”W×)Ò)¨$Ñ/Ô/€NØð 9˜~×6Ò6µr´vÑ>Ô>ð 9Ý”—’˜nÑ-Ô-ð9õ
 œŸš¨Ñ8Ô8ˆØÔð 8Ø'×.Ò.­r¬vÑ6Ô6ˆØ�ŠÐMØÔ&¨ñ	8ô 	8ð 	8å	Ý�;ÑÔ ­¨xÑ(8Ô(8ØÔ 7Ô#3Ð3Ø)ØÔ)Ø!Ô,ð
.ñ 
.ô 
.€Bð Œ9ð Øð 
	Ø×ÒÑÔÐÐðØ—’˜D '¤-°Ô1FØ#Ô-ñ/ô /ð /ð /øåÔ6ð ð ð ØÔ(¨1Ò,Ð,Ð,Ð,ÝÐCÝœ:ð'ñ 'ô 'ð 'à�q�qð	øøøð
 	�Š‰Œˆõ �t�B”I‰ŒÑÔÐs   Ô;'U# Õ#7VÖVr)   )rZ   Ú
__future__r   r   rL   r   r   r�   rA   rx   r   r   r   ÚMultiprocessRefactoringToolr   rP   rŸ   rr   r   r   ú<module>r¢      sé   ððð ð 6Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5à 
€
€
€
Ø 	€	€	€	Ø €€€Ø €€€Ø €€€Ø €€€à Ð Ð Ð Ð Ð ð-ð -ð -ðeð eð eð eð e˜HÔ@ñ eô eð eðN3ð 3ð 3ðL ð L ð L ð L ð L ð L r   