Ńň
*nJc           @   sŢ   d  Z  d Z d Z d Z d d k Z d d k Z d d k Z d d k Z d d k	 l
 Z
 l Z d d d     YZ d	 d d
     YZ d   Z d d d     YZ d e i e f d     YZ d d  Z d   Z d   Z d S(   sá  
rlcompleter_ng
==============

This module represents an alternative to rlcompleter and rlcompleter2,
for those who don't like their default behaviour.

There are two main differences between stdlib's rlcompleter and
rlcompleter_ng:

  - when doing something like a.b.c.<TAB>, rlcompleter prepends a.b.c
    to all the completions it finds; rlcompleter_ng displays only the
    attributes, making the screen less cluttered;

  - you can use the <TAB> key both to indent (when the current line is
    blank) or to complete (when it's not blank);

  - more important, rlcompleter_ng prints the various attributes found
    in different colors depending on their type.

Unfortunately, the default version of libreadline don't support
colored completions, so you need to patch it to fully exploid
rlcompleter_ng capabilities.

You can find the patch here:
http://codespeak.net/svn/user/antocuni/hack/readline-escape.patch

Alternatively, you can download the Ubuntu Hardy i386 package from here (thanks
to Alexander Schremmer):
http://antosreadlineforhardy.alexanderweb.de/libreadline5_5.2-3build1pypy_i386.deb

Installation
------------

Simply put the file rlcompleter_ng.py in a directory which is in your
PYTHONPATH.

Configuration
-------------

Since it requires a patched version of libreadline, coloured
completions are disabled by default.

To customize the configuration of rlcompleter_ng, you need to put a
file named .rlcompleter_ngrc.py in your home directory.  The file must
contain a class named ``Config`` inheriting from ``DefaultConfig`` and
overridding the desired values.

You can find a sample configuration file, which enables colors, here:
http://codespeak.net/svn/user/antocuni/hack/rlcompleter_ngrc.py

Usage
-----

From the interactive prompt, import rlcompleter_ng and call setup():

>>> import rlcompleter_ng
>>> rlcompleter_ng.setup()

Alternatively, you can put these lines in some file that it's
referenced by the PYTHONSTARTUP environment variable, so that
completions is always enabled.
s   0.1s"   Antonio Cuni <anto.cuni@gmail.com>s=   http://codespeak.net/svn/user/antocuni/hack/rlcompleter_ng.pyi˙˙˙˙N(   t   izipt   countt   colorsc           B   sh   e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d Z
 d	 Z d
 Z d Z d Z d Z d Z d Z RS(   t   30t   31t   32t   33t   34t   35t   36t   37s   30;01s   31;01s   32;01s   33;01s   34;01s   35;01s   36;01s   37;01(   t   __name__t
   __module__t   blackt   darkredt	   darkgreent   brownt   darkbluet   purplet   tealt	   lightgrayt   darkgrayt   redt   greent   yellowt   bluet   fuchsiat	   turquoiset   white(    (    (    s'   /home/wolever/.python/rlcompleter_ng.pyR   L   s    t   DefaultConfigc           B   s  e  Z e Z e Z h e i e i	 6e i e i	 6e i e i
 6e i e d  i  6e i e e i  6e i e e i  6e i e i 6e i e i 6e i e i 6e i e 6e i e i 6e i e i 6e i e 6e i e 6e i e 6e i e 6e i e 6e i e 6Z RS(   i*   (    R   R   t   Truet   consider_getitemst   Falset
   use_colorsR   R   t   typest   BuiltinMethodTypet
   MethodTypet   typet   __add__t   intt   strt   replaceR   t   FunctionTypet   BuiltinFunctionTypeR   t	   ClassTypeR   t
   ModuleTypeR   t   NoneTypeR   t   unicodeR   t   floatt   complext   boolt   color_by_type(    (    (    s'   /home/wolever/.python/rlcompleter_ng.pyR   _   s*   





c         C   s   d | |  f S(   Ns   [%sm%s[00m(    (   t   st   color(    (    s'   /home/wolever/.python/rlcompleter_ng.pyt   setcolor   s    t   ConfigurableClassc           B   s   e  Z d Z d Z d    Z RS(   c         C   s   | d  j	 o |   Sd |  i } t i i |  } t i i |  oM h  } y t | |  | d   SWq t j
 o } d | | f GHq Xn |  i   S(   Ns   ~/t   Configs!   ** error when importing %s: %s **(	   t   Nonet   config_filenamet   ost   patht
   expandusert   existst   execfilet	   ExceptionR   (   t   selfR8   t   filenamet   rcfilet   mydictt   e(    (    s'   /home/wolever/.python/rlcompleter_ng.pyt
   get_config   s    N(   R   R   R9   R   R:   RF   (    (    (    s'   /home/wolever/.python/rlcompleter_ng.pyR7      s   t	   Completerc           B   sM   e  Z d  Z e Z d Z d d d  Z d   Z d   Z d   Z	 d   Z
 RS(   sŰ   
    When doing someting like a.b.<TAB>, display only the attributes of
    b instead of the full a.b.attr string.
    
    Optionally, display the various completions in different colors
    depending on the type.
    s   .rlcompleter_ngrc.pyc         C   s   t  i i |  |  |  i |  |  _ |  i i o t i d  n |  i i oA t i	   } | i
 d d  } | i
 d d  } t i |  n d  S(   Ns   set dont-escape-ctrl-chars ont   [t    t   ](   t   rlcompleterRG   t   __init__RF   t   configR!   t   readlinet   parse_and_bindR   t   get_completer_delimsR)   t   set_completer_delims(   RA   t	   namespaceR8   t   delims(    (    s'   /home/wolever/.python/rlcompleter_ng.pyRL   ¤   s    c         C   s6   | d j o d d g | St i i |  | |  Sd S(   se   
        stolen from:
        http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496812
        RI   s   	N(   R9   RK   RG   t   complete(   RA   t   textt   state(    (    s'   /home/wolever/.python/rlcompleter_ng.pyRT   Ż   s    c      
   C   s÷   d d  k  } t i i |  |  } t |  } | o | | j o | g S| i   g  } xH | D]@ } | | i j o | i d   q` | i t	 | |  i
   q` Wg  } t t   | |  D]% \ } } }	 | |  i | | |	  qž ~ }
 |
 d g S(   Ni˙˙˙˙t    (   t   keywordRK   RG   t   global_matchest   commonprefixt   sortt   kwlistt   appendR9   t   evalRR   R    R   t   color_for_obj(   RA   RU   RX   t   namest   prefixt   valuest   namet   _[1]t   it   objt   matches(    (    s'   /home/wolever/.python/rlcompleter_ng.pyRY   š   s    
 Ac      
   C   sh  d d  k  } | i d d  \ } } d | j p d | j o d  St | |  i  } g  } g  } t |  } xs t |  D]e }	 |	 |  | j oN |	 d j oA | i |	  y t | |	  }
 Wn d  }
 n X| i |
  qz qz Wt	 |  } | o | | j o d | | f g Sg  } t
 t   | |  D]% \ } } }
 | |  i | | |
  q/~ } | d g S(	   Ni˙˙˙˙t   .i   t   (t   )t   __builtins__s   %s.%sRW   (   t   ret   rsplitR^   RR   t   lent   dirR]   t   getattrR9   RZ   R    R   R_   (   RA   RU   Rl   t   exprt   attrt   objectR`   Rb   t   nt   wordt   valueRa   Rd   Re   Rc   Rg   (    (    s'   /home/wolever/.python/rlcompleter_ng.pyt   attr_matchesĚ   s.     
Ac         C   sK   |  i  i p | St |  } |  i  i i | d  } d | t | |  S(   Nt   00s
   [%03d;00m(   RM   R!   R%   R3   t   getR6   (   RA   Re   Rc   Rv   t   tR5   (    (    s'   /home/wolever/.python/rlcompleter_ng.pyR_   ç   s
    N(   R   R   t   __doc__R   R:   R9   RL   RT   RY   Rw   R_   (    (    (    s'   /home/wolever/.python/rlcompleter_ng.pyRG      s   	
		RI   c         C   sB   d   } | o% t  | d  |   }  |  p d Sn t | |   S(   sB    return the common prefix of all 'names' starting with 'base'
    c         S   s&   x | i  |   p |  d  }  q W|  S(   Ni˙˙˙˙(   t
   startswith(   t   s1t   s2(    (    s'   /home/wolever/.python/rlcompleter_ng.pyt
   commonfuncő   s     c         S   s   |  i  |  S(    (   R|   (   t   xt   base(    (    s'   /home/wolever/.python/rlcompleter_ng.pyt   <lambda>ű   s    RI   (   t   filtert   reduce(   R`   R   R   (    (    s'   /home/wolever/.python/rlcompleter_ng.pyRZ   ň   s    		c          C   sx   d d  k  }  d d  k } | i d j o t Sd t i } |  i |  \ } } | d j o t |  d j o t St S(   Ni˙˙˙˙t   darwins   otool -L %s | grep libediti    (	   t   commandst   syst   platformR    RN   t   __file__t   getstatusoutputRn   R   (   R   R   t   cmdt   statust   result(    (    s'   /home/wolever/.python/rlcompleter_ng.pyt   has_leopard_libedit   s     c          C   sE   t    }  t   o t i d  n t i d  t i |  i  d  S(   Ns   bind ^I rl_completes   tab: complete(   RG   R   RN   RO   t   set_completerRT   (   t	   completer(    (    s'   /home/wolever/.python/rlcompleter_ng.pyt   setup  s
    	
(    (    (    (   R{   t   __version__t
   __author__t   __url__RN   RK   R"   t   os.pathR;   t	   itertoolsR    R   R   R   R6   R7   RG   RZ   R   R   (    (    (    s'   /home/wolever/.python/rlcompleter_ng.pyt   <module>?   s    !	Z	
