ó
8Þ	Pc           @€  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€  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s"   
    Prints output to stdout.
    c         C€  s2   | |  _  | |  _ t t |  ƒ j | | | ƒ d  S(   N(   t	   nobackupst
   show_diffst   superR   t   __init__(   t   selft   fixerst   optionst   explicitR   R   (    (    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_error$   s    c         C€  sê   |  j  s¥ | d } t j j | ƒ rb y t j | ƒ Wqb t j k
 r^ } |  j d | ƒ qb Xn  y t j | | ƒ Wq¥ t j k
 r¡ } |  j d | | ƒ q¥ Xn  t t	 |  ƒ j
 } | | | | | ƒ |  j  sæ t j | | ƒ n  d  S(   Ns   .baks   Can't remove backup %ss   Can't rename %s to %s(   R   t   ost   patht   lexistst   removeR   t   log_messaget   renameR   R   t
   write_filet   shutilt   copymode(   R   t   new_textR	   t   old_textt   encodingt   backupt   errt   write(    (    s"   /usr/lib/python2.7/lib2to3/main.pyR"   (   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_output;   s"    	
	(   t   __name__t
   __module__t   __doc__R   R   R"   R7   (    (    (    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.pyR1   Q   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( ƒt } i  } | j | ƒ \ } } | j r†| j r†t d) ƒ n  | j r©| j r©| j	 d* ƒ n  | j
 rãd+ GHx t j ˆ  ƒ D] } | GHqÇW| sãd, Sn  | st j d- IJt j d. IJd/ Sd0 | k r6t } | j r6t j d1 IJd/ Sn  | j rLt | d2 <n  | j r^t j n t j } t j d3 d4 d5 | ƒ t t j ˆ  ƒ ƒ } t ‡  f d6 †  | j Dƒ ƒ }	 t ƒ  }
 | j r%t } x; | j D]0 } | d7 k rît } qÓ|
 j ˆ  d8 | ƒ qÓW| r| j |
 ƒ n |
 } n | j |
 ƒ } | j |	 ƒ } t t | ƒ | t |
 ƒ | j | j ƒ } | j sô| rŠ| j  ƒ  n] y# | j | | j | j! | j" ƒ Wn7 t j# k
 ræ| j" d k sÕt$ ‚ t j d9 IJd SX| j% ƒ  n  t& t' | j ƒ ƒ S(:   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@   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   levelc         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_s+   Sorry, -j isn't supported on this platform.((   t   optparset   OptionParsert
   add_optiont   Falset
   parse_argsR*   t   no_diffsR1   R   R   t
   list_fixesR   t   get_all_fix_namesR-   R;   t   TrueRE   t   verboset   loggingt   DEBUGt   INFOt   basicConfigt   sett   get_fixers_from_packaget   nofixRI   t   addt   uniont
   differenceR   t   sortedR   t   refactor_stdint   doctests_onlyt	   processest   MultiprocessingUnsupportedt   AssertionErrort	   summarizeRC   t   bool(   RJ   R   t   parserRa   t   flagsR   t   fixnameRG   t   avail_fixest   unwanted_fixesR   t   all_presentRI   t	   requestedt   fixer_namest   rt(    (   RJ   s"   /usr/lib/python2.7/lib2to3/main.pyt   mainU   s’    								(   R:   t
   __future__R    R-   R   R   RV   R#   RL   R   R   R
   t   MultiprocessRefactoringToolR   R1   R,   Rq   (    (    (    s"   /usr/lib/python2.7/lib2to3/main.pyt   <module>   s   		7	