ó
è¾bc           @€  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 „  Z d e
 j f d „  ƒ  YZ d	 „  Z d d
 „ Z d S(   s   
Main program for 2to3.
iÿÿÿÿ(   t   with_statementNi   (   t   refactorc      	   C€  s:   |  j  ƒ  }  | j  ƒ  } t j |  | | | d d d d ƒS(   s%   Return a unified diff of two strings.s
   (original)s   (refactored)t   linetermt    (   t
   splitlinest   difflibt   unified_diff(   t   at   bt   filename(    (    s"   /usr/lib/python2.7/lib2to3/main.pyt
   diff_texts   s
    	t   StdoutRefactoringToolc           B€  s;   e  Z d  Z d d d d „ Z d „  Z d „  Z d „  Z RS(   s2  
    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	   	      C€  sv   | |  _  | |  _ | r; | j t j ƒ r; | t j 7} n  | |  _ | |  _ | |  _ t t	 |  ƒ j
 | | | ƒ d S(   sF  
        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(   t	   nobackupst
   show_diffst   endswitht   ost   sept   _input_base_dirt   _output_dirt   _append_suffixt   superR   t   __init__(	   t   selft   fixerst   optionst   explicitR   R   t   input_base_dirt
   output_dirt   append_suffix(    (    s"   /usr/lib/python2.7/lib2to3/main.pyR   $   s    					c         O€  s3   |  j  j | | | f ƒ |  j j | | | Ž d  S(   N(   t   errorst   appendt   loggert   error(   R   t   msgt   argst   kwargs(    (    s"   /usr/lib/python2.7/lib2to3/main.pyt	   log_errorA   s    c   
      C€  sÝ  | } |  j  re | j |  j ƒ rI t j j |  j  | t |  j ƒ ƒ } qe 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 sy| d } t j j | ƒ r6y t j | ƒ Wq6t j k
 r2} |  j d | ƒ q6Xn  y t j | | ƒ Wqyt j k
 ru} |  j d | | ƒ qyXn  t t |  ƒ j }	 |	 | | | | ƒ |  j sºt j | | ƒ n  | | k rÙt j | | ƒ n  d  S(   Ns5   filename %s does not start with the input_base_dir %ss   Writing converted %s to %s.s   .baks   Can't remove backup %ss   Can't rename %s to %s(   R   t
   startswithR   R   t   patht   joint   lent
   ValueErrorR   t   dirnamet   isdirt   makedirst   log_messageR   t   lexistst   removeR    t   renameR   R   t
   write_filet   shutilt   copymode(
   R   t   new_textR	   t   old_textt   encodingt   orig_filenameR   t   backupt   errt   write(    (    s"   /usr/lib/python2.7/lib2to3/main.pyR1   E   s@    		
	
	c         C€  sÐ   | r |  j  d | ƒ n³ |  j  d | ƒ |  j rÌ t | | | ƒ } y_ |  j d  k	 rŒ |  j ( x | D] } | GHqg Wt j j ƒ  Wd  QXn x | D] } | GHq“ WWqÌ t k
 rÈ t	 d | f ƒ d  SXn  d  S(   Ns   No changes to %ss   Refactored %ss+   couldn't encode %s's diff for your terminal(
   R-   R   R
   t   output_lockt   Nonet   syst   stdoutt   flusht   UnicodeEncodeErrort   warn(   R   t   oldt   newR	   t   equalt
   diff_linest   line(    (    s"   /usr/lib/python2.7/lib2to3/main.pyt   print_outputl   s"    	
	(   t   __name__t
   __module__t   __doc__R   R$   R1   RG   (    (    (    s"   /usr/lib/python2.7/lib2to3/main.pyR      s
   		'c         C€  s   t  j d |  f IJd  S(   Ns   WARNING: %s(   R=   t   stderr(   R!   (    (    s"   /usr/lib/python2.7/lib2to3/main.pyRA   ‚   s    c         €  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& d' d d d t d d( ƒ| j d) d* d d d d+ d d, d d- ƒ| j d. d/ d d d d0 ƒ| j d1 d d d d+ d d, d d2 ƒt } i  } | j | ƒ \ } } | j rt | d3 <| j søt d4 ƒ n  t | _ n  | j	 r'| j
 r'| j d5 ƒ n  | j rJ| j
 rJ| j d6 ƒ n  | j rj| j rjt d7 ƒ n  | j r| j
 r| j d8 ƒ n  | j rÇd9 GHx t j ˆ  ƒ D] } | GHq«W| sÇd: Sn  | sët j d; IJt j d< IJd= Sd> | k rt } | j rt j d? IJd= Sn  | j r0t | d@ <n  | j rBt j n t j } t j dA dB dC | ƒ t j dD ƒ } t t j ˆ  ƒ ƒ }	 t ‡  f dE †  | j Dƒ ƒ }
 t ƒ  } | j rt } x; | j D]0 } | dF k rát } qÆ| j ˆ  dG | ƒ qÆW| r|	 j | ƒ n | } n |	 j | ƒ } | j  |
 ƒ } t! j" j# | ƒ } | r‰| j$ t! j% ƒ r‰t! j" j& | ƒ r‰t! j" j' | ƒ } n  | j	 r½| j( t! j% ƒ } | j) dH | j	 | ƒ n  t* t+ | ƒ | t+ | ƒ | j
 | j dI | dJ | j	 dK | j ƒ} | j, s†| r| j- ƒ  n] y# | j | | j | j. | j/ ƒ Wn7 t j0 k
 rx| j/ d k sgt1 ‚ t j dL IJd SX| j2 ƒ  n  t3 t4 | j, ƒ ƒ S(M   sþ   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).
    t   usages   2to3 [options] file|dir ...s   -ds   --doctests_onlyt   actiont
   store_truet   helps   Fix up doctests onlys   -fs   --fixR   t   defaults1   Each FIX specifies a transformation; default: alls   -js   --processest   storei   t   typet   ints   Run 2to3 concurrentlys   -xs   --nofixs'   Prevent a transformation from being runs   -ls   --list-fixess   List available transformationss   -ps   --print-functions0   Modify the grammar so that print() is a functions   -vs	   --verboses   More verbose loggings
   --no-diffss#   Don't show diffs of the refactorings   -ws   --writes   Write back modified filess   -ns   --nobackupss&   Don't write backups for modified filess   -os   --output-dirt   strR   sX   Put output files in this directory instead of overwriting the input files.  Requires -n.s   -Ws   --write-unchanged-filessY   Also write files even if no changes were required (useful with --output-dir); implies -w.s   --add-suffixsu   Append this string to all output filenames. Requires -n if non-empty.  ex: --add-suffix='3' will generate .py3 files.t   write_unchanged_filess&   --write-unchanged-files/-W implies -w.s%   Can't use --output-dir/-o without -n.s"   Can't use --add-suffix without -n.s@   not writing files and not printing diffs; that's not very usefuls   Can't use -n without -ws2   Available transformations for the -f/--fix option:i    s1   At least one file or directory argument required.s   Use --help to show usage.i   t   -s   Can't write to stdin.t   print_functiont   formats   %(name)s: %(message)st   levels   lib2to3.mainc         3€  s   |  ] } ˆ  d  | Vq d S(   s   .fix_N(    (   t   .0t   fix(   t	   fixer_pkg(    s"   /usr/lib/python2.7/lib2to3/main.pys	   <genexpr>Þ   s    t   alls   .fix_s7   Output in %r will mirror the input directory %r layout.R   R   R   s+   Sorry, -j isn't supported on this platform.(5   t   optparset   OptionParsert
   add_optiont   Falset
   parse_argsRU   t   TrueR:   RA   R   R   R    t
   add_suffixt   no_diffst
   list_fixesR   t   get_all_fix_namesR=   RK   RW   t   verboset   loggingt   DEBUGt   INFOt   basicConfigt	   getLoggert   sett   get_fixers_from_packaget   nofixR[   t   addt   uniont
   differenceR   R&   t   commonprefixR   R   R+   R*   t   rstript   infoR   t   sortedR   t   refactor_stdint   doctests_onlyt	   processest   MultiprocessingUnsupportedt   AssertionErrort	   summarizeRS   t   bool(   R\   R"   t   parserRx   t   flagsR   t   fixnameRY   R   t   avail_fixest   unwanted_fixesR   t   all_presentR[   t	   requestedt   fixer_namesR   t   rt(    (   R\   s"   /usr/lib/python2.7/lib2to3/main.pyt   main†   sÊ    	
												(   RJ   t
   __future__R    R=   R   R   Ri   R2   R^   R   R   R
   t   MultiprocessRefactoringToolR   RA   R<   Rˆ   (    (    (    s"   /usr/lib/python2.7/lib2to3/main.pyt   <module>   s   		h	