ž ¬ÿfh- c @ s² d 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 Z d d l m Z d d „ Z Gd d „ d e j ƒ Z d d „ Z d d d „ Z d S( u Main program for 2to3. i ( u with_statementNi ( u refactorc C s: | j ƒ } | j ƒ } t j | | | | d d d d ƒS( u% Return a unified diff of two strings.u (original)u (refactored)u linetermu ( u splitlinesu difflibu unified_diff( u au bu filename( ( u1 /opt/alt/python33/lib64/python3.3/lib2to3/main.pyu diff_texts s u diff_textsc s_ | Ee Z d Z d Z d d d ‡ f d d † Z d d „ Z ‡ f d d † Z d d „ Z ‡ S( u StdoutRefactoringToolu2 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. u c sv | | _ | | _ | r; | j t j ƒ r; | t j 7} n | | _ | | _ | | _ t t | ƒ j | | | ƒ d S( uF 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( u nobackupsu show_diffsu endswithu osu sepu _input_base_diru _output_diru _append_suffixu superu StdoutRefactoringToolu __init__( u selfu fixersu optionsu explicitu nobackupsu show_diffsu input_base_diru output_diru append_suffix( u __class__( u1 /opt/alt/python33/lib64/python3.3/lib2to3/main.pyu __init__$ s u StdoutRefactoringTool.__init__c O s3 | j j | | | f ƒ | j j | | | Ž d S( N( u errorsu appendu loggeru error( u selfu msgu argsu kwargs( ( u1 /opt/alt/python33/lib64/python3.3/lib2to3/main.pyu log_errorA s u StdoutRefactoringTool.log_errorc ! s | } | j rk | j | j ƒ rO t j j | j | t | j ƒ d … ƒ } qk t d | | j f ƒ ‚ n | j r„ | | j 7} n | | k rÚ t j j | ƒ } t j j | ƒ sÄ t j | ƒ n | j d | | ƒ n | j s£| d } t j j | ƒ rNy t j | ƒ WqNt j k rJ} z | j d | ƒ WYd d } ~ XqNXn y t j | | ƒ Wq£t j k rŸ} z | j d | | ƒ WYd d } ~ Xq£Xn t t | ƒ j } | | | | | ƒ | j sät j | | ƒ n | | k rt j | | ƒ n d S( Nu5 filename %s does not start with the input_base_dir %su Writing converted %s to %s.u .baku Can't remove backup %su Can't rename %s to %s( u _output_diru startswithu _input_base_diru osu pathu joinu lenu ValueErroru _append_suffixu dirnameu isdiru makedirsu log_messageu nobackupsu lexistsu removeu erroru renameu superu StdoutRefactoringToolu write_fileu shutilu copymode( u selfu new_textu filenameu old_textu encodingu orig_filenameu output_diru backupu erru write( u __class__( u1 /opt/alt/python33/lib64/python3.3/lib2to3/main.pyu write_fileE s@ &) u StdoutRefactoringTool.write_filec C sÞ | r | j d | ƒ nÁ | j d | ƒ | j rÚ t | | | ƒ } yi | j d k r‘ | j - x | D] } t | ƒ qg Wt j j ƒ Wd QXn x | D] } t | ƒ q˜ WWqÚ t k rÖ t d | f ƒ d SYqÚ Xn d S( Nu No changes to %su Refactored %su+ couldn't encode %s's diff for your terminal( u log_messageu show_diffsu diff_textsu output_locku Noneu printu sysu stdoutu flushu UnicodeEncodeErroru warn( u selfu oldu newu filenameu equalu diff_linesu line( ( u1 /opt/alt/python33/lib64/python3.3/lib2to3/main.pyu print_outputl s" u" StdoutRefactoringTool.print_output( u __name__u __module__u __qualname__u __doc__u __init__u log_erroru write_fileu print_output( u __locals__( ( u __class__u1 /opt/alt/python33/lib64/python3.3/lib2to3/main.pyu StdoutRefactoringTool s 'u StdoutRefactoringToolc C s t d | f d t j ƒd S( Nu WARNING: %su file( u printu sysu stderr( u msg( ( u1 /opt/alt/python33/lib64/python3.3/lib2to3/main.pyu warn s u warnc s t j d d ƒ } | j d d d d d d ƒ| j d d d d d g d d ƒ| j d d d d d d d d d d ƒ| j d d d d d g d d ƒ| j d d d d d d ƒ| j d d d d d d ƒ| j d d d d d d ƒ| j d! d d d d" ƒ| j d# d$ d d d d% ƒ| j d&