Ë
    #´˜jN.  ã                   ó’   — 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y)z
Main program for 2to3.
é    )Úwith_statementÚprint_functionNé   )Úrefactorc           	      óz   — | j                  «       } |j                  «       }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      úlib/python3.12/lib2to3/main.pyÚ
diff_textsr      s;   € à	�‰‹€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.
    c	                 óÞ   •— || _         || _        |r2|j                  t        j                  «      s|t        j                  z  }|| _        || _        || _        t        t        | �+  |||«       y)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__$   sa   ø€ ð( #ˆŒØ$ˆŒÙ .×"9Ñ"9¼"¿&¹&Ô"AØœbŸf™fÑ$ˆNØ-ˆÔØ%ˆÔØ+ˆÔÜÔ# TÑ3°F¸GÀXÕNr   c                 ó€   — | j                   j                  |||f«        | j                  j                  |g|¢­i |¤Ž y ©N)ÚerrorsÚappendÚloggerÚerror)r    ÚmsgÚargsÚkwargss       r   Ú	log_errorzStdoutRefactoringTool.log_errorA   s9   € Ø�‰×Ñ˜C  vÐ.Ô/Øˆ�‰×Ñ˜#Ð/ Ò/¨Ó/r   c                 ó  •— |}| j                   rw|j                  | j                  «      rAt        j                  j                  | j                   |t        | j                  «      d  «      }nt        d|›d| j                  ›�«      ‚| j                  r|| j                  z  }||k7  rht        j                  j                  |«      }t        j                  j                  |«      s|rt        j                  |«       | j                  d||«       | j                  sQ|dz   }t        j                  j                  |«      r	 t        j                  |«       	 t        j"                  ||«       t$        t&        | �R  } |||||«       | j                  st+        j,                  |«       ||k7  rt+        j,                  ||«       y y # t         $ r | j                  d|«       Y ŒŒw xY w# t         $ r | j                  d||«       Y Œ—w xY w)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   s¾  ø€ Ø ˆØ×ÒØ×"Ñ" 4×#7Ñ#7Ô8ÜŸ7™7Ÿ<™<¨×(8Ñ(8Ø(0´°T×5IÑ5IÓ1JÐ1KÐ(LóN‘õ !â)1°4×3GÒ3Gð"Ió Jð Jð ×ÒØ˜×+Ñ+Ñ+ˆHØ˜HÒ$ÜŸ™Ÿ™¨Ó2ˆJÜ—7‘7—=‘= Ô,±Ü—‘˜JÔ'Ø×ÑÐ:¸MØ%ô'à�~Š~à Ñ&ˆFÜ�w‰w�‰˜vÔ&ðGÜ—I‘I˜fÔ%ðLÜ—	‘	˜( FÔ+ô Ô+¨TÑ=ˆÙˆh˜ (¨HÔ5Ø�~Š~Ü�O‰O˜F HÔ-Ø˜HÒ$ä�O‰O˜M¨8Õ4ð %øô ò GØ×$Ñ$Ð%=¸vÖFðGûô ò LØ× Ñ Ð!8¸(ÀFÖKðLús$   Å G ÅG% ÇG"Ç!G"Ç%HÈHc                 ó¤  — |r| j                  d|«       y | j                  d|«       | j                  rst        |||«      }	 | j                  �F| j                  5  |D ]  }t	        |«       Œ t
        j                  j                  «        d d d «       y |D ]  }t	        |«       Œ y y # 1 sw Y   y xY w# t        $ r t        d|›d�«       Y y w xY w)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Ø�ŠÜ'¨¨S°(Ó;�
ðØ×'Ñ'Ð3Ø!×-Ó-Û(2 Ü % d¥ð )3äŸJ™J×,Ñ,Ô.÷ .Ð-ó
 %/˜DÜ! $�Kñ %/ð ÷ .Ð-ûô *ò ÝÚ"ð%ô &áðús6   ÁB4 Á1B(ÂB4 ÂB4 Â(B1Â-B4 Â1B4 Â4CÃC)r   r   r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r1   r@   rV   Ú__classcell__)r'   s   @r   r   r      s%   ø„ ñð BDõOò:0ô%5öNr   r   c                 ó@   — t        d| ›�t        j                  ¬«       y )Nz	WARNING: ©Úfile)rK   rL   Ústderr)r.   s    r   rP   rP   �   s   € Ý	™3Ð
 ¤s§z¡zÖ2r   c           
      ó¾  ‡ — t        j                  d¬«      }|j                  dddd¬«       |j                  dd	d
g d¬«       |j                  dddddd¬«       |j                  ddd
g d¬«       |j                  dddd¬«       |j                  dddd¬«       |j                  dddd¬«       |j                  d d!dd"¬«       |j                  d#dd$¬«       |j                  d%d&dd'¬«       |j                  d(d)dd*d+¬«       |j                  d,d-dd.d/d0¬1«       |j                  d2d3dd4¬«       |j                  d5dd.d/d6¬1«       d*}i }|j                  |«      \  }}|j                  r#d7|d8<   |j
                  st        d9«       d7|_        |j                  r|j                  s|j                  d:«       |j                  r|j                  s|j                  d;«       |j
                  s|j                  rt        d<«       |j
                  s|j                  r|j                  d=«       |j                  r3t        d>«       t        j                  ‰ «      D ]  }t        |«       Œ |sy?|s7t        d@t         j"                  ¬A«       t        dBt         j"                  ¬A«       yCdD|v r*d7}|j
                  rt        dEt         j"                  ¬A«       yC|j$                  rd7|dF<   |j&                  rd7|dG<   |j(                  rt*        j,                  nt*        j.                  }t+        j0                  dH|¬I«       t+        j2                  dJ«      }t5        t        j6                  ‰ «      «      }	t5        ˆ fdK„|j8                  D «       «      }
t5        «       }|j:                  rHd*}|j:                  D ]!  }|dLk(  rd7}Œ|j=                  ‰ dMz   |z   «       Œ# |r|	j?                  |«      n|}n|	j?                  |«      }|jA                  |
«      }tB        jD                  jG                  |«      }|r]|jI                  tB        jJ                  «      s>tB        jD                  jM                  |«      stB        jD                  jO                  |«      }|j                  r<|jQ                  tB        jJ                  «      }|jS                  dN|j                  |«       tU        tW        |«      |tW        |«      |j                  |j                   ||j                  |j                  ¬O«      }|jX                  sV|r|j[                  «        n3	 |j                  ||j
                  |j\                  |j^                  «       |jc                  «        te        tg        |jX                  «      «      S # t        j`                  $ r/ |j^                  dkD  sJ ‚t        dPt         j"                  ¬A«       Y yw xY w)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   –— Œ y­w)ú.fix_N© )Ú.0ÚfixÚ	fixer_pkgs     €r   Ú	<genexpr>zmain.<locals>.<genexpr>â   s   øè ø€ ÐL¹m°s˜ WÑ,¨sÕ2¹mùs   ƒÚ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Ÿ   …   so  ø€ ô ×"Ñ"Ð)FÔG€FØ
×Ñ�dÐ-°lØ1ð ô 3à
×Ñ�d˜G¨H¸bØNð ô Pà
×Ñ�d˜M°'À1Ø Ð'>ð ô @à
×Ñ�d˜I¨hÀØDð ô Fà
×Ñ�d˜N°<Ø;ð ô =à
×Ñ�dÐ.°|ØMð ô Oà
×Ñ�dÐ-°lØLð ô Nà
×Ñ�d˜K°Ø1ð ô 3à
×Ñ�l¨<Ø@ð ô Bà
×Ñ�d˜I¨lØ6ð ô 8à
×Ñ�d˜M°,ÈØCð ô Eà
×Ñ�d˜N°7ÀØ ð (Nð ô Oð ×Ñ�dÐ5¸lðAð ô Bð ×Ñ�n¨W¸5È"ðGð ô Hð €NØ€EØ×%Ñ% dÓ+�M€GˆTØ×$Ò$Ø)-ˆÐ%Ñ&Ø�}Š}ÜÐ9Ô:ØˆŒð ×Ò '×"3Ò"3Ø�‰Ð<Ô=Ø×Ò '×"3Ò"3Ø�‰Ð9Ô:à�=Š=˜W×-Ò-ÜÐOÔPØ�=Š=˜W×.Ò.Ø�‰Ð.Ô/Ø×ÒÜÐBÔCÜ×1Ñ1°)Ö<ˆGÜ�'�Nð =áØÙÜÐAÌÏ
É
ÕSÜÐ)´·
±
Õ;ØØ
ˆd�{ØˆØ�=Š=ÜÐ)´·
±
Õ;ØØ×ÒØ"&ˆÐÑà×ÒØ!%ˆˆoÑð %Ÿ_š_ŒG�MŠM´'·,±,€EÜ×ÑÐ6¸eÕDÜ×Ñ˜~Ó.€Fô ”h×6Ñ6°yÓAÓB€KÜÓL¸g¿mºmÓLÓL€NÜ‹u€HØ‡{‚{ØˆØ—;”;ˆCØ�eŠ|Ø"‘à—‘˜Y¨Ñ0°3Ñ6Õ7ð	 ñ
 4?�K×%Ñ% hÔ/ÀH‰	à×%Ñ% hÓ/ˆ	Ø×&Ñ& ~Ó6€KÜ—W‘W×)Ñ)¨$Ó/€NÙ˜~×6Ñ6´r·v±vÔ>Ü—‘—‘˜nÔ-ô Ÿ™Ÿ™¨Ó8ˆØ×ÒØ'×.Ñ.¬r¯v©vÓ6ˆØ�‰ÐMØ×&Ñ&¨ô	8ä	Ü�;Ó ¬¨xÓ(8Ø×Ñ 7×#3Ñ#3Ð3Ø)Ø×)Ñ)Ø!×,Ñ,ô
.€Bð �9Š9ÙØ×ÑÕðØ—‘˜D '§-¡-°×1FÑ1FØ#×-Ñ-ô/ð 	�‰Œô Œt�B—I‘I‹ÓÐøô ×6Ñ6ò Ø×(Ñ(¨1Ò,Ð,Ð,ÜÐCÜŸ:™:õ'áð	ús   Ô:2V Ö?W×Wr)   )rZ   Ú
__future__r   r   rL   r   r   r�   rA   rx   r   r   r   ÚMultiprocessRefactoringToolr   rP   rŸ   rr   r   r   Ú<module>r¢      sI   ðñ÷ 6ã 
Û 	Û Û Û Û å ò-ôe˜H×@Ñ@ô eòN3ôL r   