Ñò
ÎÑAHc           @   sò   d  Z  d Z d d k Z d d k Z d e f d „  ƒ  YZ d d „ Z e i	 d ƒ Z
 e i	 d ƒ Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e i	 d ƒ Z e i	 d ƒ Z d „  Z d S(   sõ   
Classes and functions for prefiltering (transforming) a line of user input.
This module is responsible, primarily, for breaking the line up into useful
pieces and triggering the appropriate handlers in iplib to do the actual
transforming work.
s   restructuredtext eniÿÿÿÿNt   LineInfoc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s  A single line of input and associated info.

    Includes the following as properties: 

    line
      The original, raw line
    
    continue_prompt
      Is this line a continuation in a sequence of multiline input?
    
    pre
      The initial esc character or whitespace.
    
    preChar
      The escape character(s) in pre or the empty string if there isn't one.
      Note that '!!' is a possible value for preChar.  Otherwise it will
      always be a single character.
    
    preWhitespace
      The leading whitespace from pre if it exists.  If there is a preChar,
      this is just ''.
    
    iFun
      The 'function part', which is basically the maximal initial sequence
      of valid python identifiers and the '.' character.  This is what is
      checked for alias and magic transformations, used for auto-calling,
      etc.
    
    theRest
      Everything else on the line.
    c         C   sr   | |  _  | |  _ t | ƒ \ |  _ |  _ |  _ |  i i ƒ  |  _ |  i o d |  _ n |  i |  _ d  |  _
 d  S(   Nt    (   t   linet   continue_promptt   splitUserInputt   pret   iFunt   theRestt   stript   preChart   preWhitespacet   Nonet   _oinfo(   t   selfR   R   (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyt   __init__-   s    		
c         C   s*   |  i  p | i |  i ƒ |  _  n |  i  S(   s  Do a full, attribute-walking lookup of the iFun in the various
        namespaces for the given IPython InteractiveShell instance.

        Return a dict with keys: found,obj,ospace,ismagic

        Note: can cause state changes because of calling getattr, but should
        only be run if autocall is on and if the line hasn't matched any
        other, less dangerous handlers.

        Does cache the results of the call, so can be called multiple times
        without worrying about *further* damaging state.
        (   R   t   _ofindR   (   R   t   ip(    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyt   ofind:   s    
c         C   s   d |  i  |  i |  i f S(   Ns   Lineinfo [%s|%s|%s](   R   R   R   (   R   (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyt   __str__J   s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR       s   		c      	   C   sñ   | p
 t  } n | i |  ƒ } | p_ y |  i d d ƒ \ } } Wn  t j
 o |  d } } n Xt i d |  ƒ i ƒ  d } n | i ƒ  \ } } } y | i d ƒ } Wn' t j
 o | d | } d } n X| | i	 ƒ  | i
 ƒ  f S(	   s¸   Split user input into pre-char/whitespace, function part and rest.

    Mostly internal to this module, but also used by iplib.expand_aliases,
    which passes in a shell pattern.
    i   R   s
   ^(\s*)(.*)i    t   asciiu    u    N(   t
   line_splitt   matcht   splitR   t
   ValueErrort   ret   groupst   encodet   UnicodeEncodeErrorR   t   lstrip(   R   t   patternR   R   R   R   (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR   M   s     
 s(   ^([,;/%?]|!!?|\s*)\s*([\w\.]+)(\s+.*$|$)s   ^(\s*)(\S*\s*)(.*$)c      
   C   s]   xM t  t t t t t t t t t	 g
 D]' } | |  | ƒ } | o | |  ƒ Sq% W| i
 |  ƒ S(   sµ   Call one of the passed-in InteractiveShell's handler preprocessors,
    depending on the form of the line.  Return the results, which must be a
    value, even if it's a blank ('').(   t
   checkEmacst   checkShellEscapet   checkIPyAutocallt   checkMultiLineMagict   checkEscCharst   checkAssignmentt   checkAutomagict
   checkAliast   checkPythonOpst   checkAutocallt   handle_normal(   t	   line_infoR   t   checkt   handler(    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyt	   prefilter…   s     c         C   s(   |  i  i ƒ  i | i ƒ o | i Sd  S(   N(   R   R   t
   startswitht	   ESC_SHELLt   handle_shell_escape(   t   l_infoR   (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR"   §   s    c         C   s#   |  i  i d ƒ o | i Sd Sd S(   s,   Emacs ipython-mode tags certain input lines.s   # PYTHON-MODEN(   R   t   endswitht   handle_emacsR   (   R3   R   (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR!   «   s    c         C   sN   | i  i |  i d ƒ } t | t i i ƒ o | i | i	 ƒ | i
 Sd Sd S(   s>   Instances of IPyAutocall in user_ns get autocalled immediatelyN(   t   user_nst   getR   R   t
   isinstancet   IPythont   ipapit   IPyAutocallt   set_ipt   apit   handle_auto(   R3   R   t   obj(    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR#   ²   s
    c         C   sA   |  i  o/ | i i o" |  i i | i ƒ o | i Sn d Sd S(   sD   Allow ! and !! in multi-line statements if multi_line_specials is onN(   R   t   rct   multi_line_specialsR   R0   t	   ESC_MAGICt   handle_magicR   (   R3   R   (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR$   ¼   s
    
c         C   so   |  i  d | i j o. |  i | i j o |  i | i j o | i S|  i | i j o | i |  i Sd Sd S(   sl   Check for escape character and return either a handler to handle it,
    or None if there is no escape char.iÿÿÿÿN(   R   t   ESC_HELPR	   R1   t
   ESC_SH_CAPt   handle_helpt   esc_handlersR   (   R3   R   (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR%   È   s    c         C   s.   |  i  o |  i  d d j o | i Sd Sd S(   sP  Check to see if user is assigning to a var for the first time, in
    which case we want to avoid any sort of automagic / autocall games.
    
    This allows users to assign to either alias or magic names true python
    variables (the magic/alias systems always take second seat to true
    python code).  E.g. ls='hi', or ls,that=1,2i    s   =,N(   R   R+   R   (   R3   R   (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR&   ×   s    c         C   s}   | i  i p t | d |  i ƒ o d S|  i o | i  i o d S|  i i d d ƒ d } t | | ƒ o d S| i	 S(   s7  If the iFun is magic, and automagic is on, run it.  Note: normal,
    non-auto magic would already have been triggered via '%' in
    check_esc_chars. This just checks for automagic.  Also, before
    triggering the magic handler, make sure that there is nothing in the
    user namespace which could shadow it.t   magic_t   .i   i    N(
   R@   t	   automagict   hasattrR   R   R   RA   R   t
   isShadowedRC   (   R3   R   t   head(    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR'   ä   s    &c         C   sX   |  i  i d d ƒ d } |  i  | i j p  | | i j p t | | ƒ o d S| i S(   s9   Check if the initital identifier on the line is an alias.RI   i   i    N(   R   R   t   alias_tableRL   R   t   handle_alias(   R3   R   RM   (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR(   ø   s    c         C   s.   |  i  o |  i  d d j o | i Sd Sd S(   s  If the 'rest' of the line begins with a function call or pretty much
    any python operator, we should simply execute the line (regardless of
    whether or not there's a possible autocall expansion).  This avoids
    spurious (and very confusing) geattr() accesses.i    s   !=()<>,+*/%^&|N(   R   R+   R   (   R3   R   (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR)     s    c         C   sy   | i  i p d S|  i | ƒ } | d p d St | d ƒ o/ t i |  i ƒ o t i |  i	 ƒ o | i
 Sd Sd S(   sB   Check if the initial word/function is callable and autocall is on.t   foundR?   N(   R@   t   autocallR   R   t   callablet   re_exclude_autoR   R   t   re_fun_nameR   R>   (   R3   R   t   oinfo(    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyR*     s    s   [a-zA-Z_]([a-zA-Z0-9_.]*) *$s)   ^[,&^\|\*/\+-]|^is |^not |^in |^and |^or c         C   s1   |  | i  j p! |  | i j p |  | i d j S(   sÊ   Is the given identifier defined in one of the namespaces which shadow
    the alias and magic namespaces?  Note that an identifier is different
    than iFun, because it can not contain a '.' character.t   builtin(   R6   t   internal_nst   ns_table(   t
   identifierR   (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyRL   8  s    (   R   t   __docformat__R   t   IPython.ipapiR9   t   objectR    R   R   t   compileR   t   shell_line_splitR/   R"   R!   R#   R$   R%   R&   R'   R(   R)   R*   RT   RS   RL   (    (    (    sI   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/prefilter.pyt   <module>   s*   @2	"			
							
