
NXc           @  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 m	 Z	 d d l
 m Z m Z d d l
 m Z m Z m Z d d l m Z d d l m Z e Z d	 Z d
 e j k r*y: d d l Z e e j d  re j d k re Z n  Wq*e k
 r&e d  q*Xn  e rId d l m Z d Z n d d l  m Z d d  Z" d d  Z# d e$ f d     YZ% d d  Z& d   Z' d e f d     YZ d S(   s  
Pdb debugger class.

Modified from the standard pdb.Pdb class to avoid including readline, so that
the command line completion of other programs which include this isn't
damaged.

In the future, this class will be expanded with improvements over the standard
pdb.

The code in this file is mainly lifted out of cmd.py in Python 2.2, with minor
changes. Licensing should therefore be under the standard Python terms.  For
details on the PSF (Python Software Foundation) standard license, see:

http://www.python.org/2.2.3/license.htmli(   t   print_functionN(   t   get_ipython(   t
   PyColorizet
   ulinecache(   t	   coloransit   iot	   py3compat(   t   exception_colors(   t   skip_doctests   ipdb> s   --pydbt   runls   1.17sH   Pydb (http://bashdb.sourceforge.net/pydb/) does not seem to be available(   t   Pdbs   ipydb> c         C  sR   |  t  j k r t d  n2 | d k	 r; | |  | |  n t j |  | |  d S(   s   Exception hook which handles `BdbQuit` exceptions.

    All other exceptions are processed using the `excepthook`
    parameter.
    s   Exiting Debugger.N(   t   bdbt   BdbQuitt   printt   Nonet   BdbQuit_excepthookt   excepthook_ori(   t   ett   evt   tbt
   excepthook(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyR   A   s
    c         C  s   t  d  d  S(   Ns   Exiting Debugger.(   R   (   t   selfR   R   R   t	   tb_offset(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   BdbQuit_IPython_excepthookO   s    t   Tracerc           B  s)   e  Z d  Z e d d   Z d   Z RS(   s3  Class for local debugging, similar to pdb.set_trace.

    Instances of this class, when called, behave like pdb.set_trace, but
    providing IPython's enhanced capabilities.

    This is implemented as a class which must be initialized in your own code
    and not as a standalone function because we need to detect at runtime
    whether IPython is already active or not.  That detection is done in the
    constructor, ensuring that this code plays nicely with a running IPython,
    while functioning acceptably (though with limitations) if outside of it.
    c         C  s  t    } | d k rj t j t d t j t _ d } y d d l } | j d  Wq t	 k
 rf q Xn | j
 } | j t j f t  | d k r | } n  yE y d d l m } Wn! t	 k
 r d d l m } n Xd | _ Wn d d l } | j   n Xt |  |  _ d S(   s:  Create a local debugger instance.

        Parameters
        ----------

        colors : str, optional
            The name of the color scheme to use, it must be one of IPython's
            valid color schemes.  If not given, the function will default to
            the current IPython scheme when running inside IPython, and to
            'NoColor' otherwise.

        Examples
        --------
        ::

            from IPython.core.debugger import Tracer; debug_here = Tracer()

        Later in your code::
        
            debug_here()  # -> will open up the debugger at that point.

        Once the debugger activates, you can use all of its regular commands to
        step through code, set breakpoints, etc.  See the pdb documentation
        from the Python standard library for usage details.
        R   t   NoColoriNs   tab: complete(   t   aRepriP   (   R   R   t	   functoolst   partialR   t   sysR   t   readlinet   parse_and_bindt   ImportErrort   colorst   set_custom_excR   R   R   t   reprlibR   t   reprt	   maxstringt	   tracebackt	   print_excR
   t   debugger(   R   R!   t   ipt
   def_colorsR   R   R&   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   __init__`   s0    			c         C  s   |  j  j t j   j  d S(   s   Starts an interactive debugger at the point where called.

        This is similar to the pdb.set_trace() function from the std lib, but
        using IPython's enhanced debugger.N(   R(   t	   set_traceR   t	   _getframet   f_back(   R   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   __call__   s    N(   t   __name__t
   __module__t   __doc__R   R   R+   R/   (    (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyR   S   s   Ct    c           s/     f d   } | j  r+ | j  | | _  n  | S(   s   Make new_fn have old_fn's doc string. This is particularly useful
    for the ``do_...`` commands that hook into the help system.
    Adapted from from a comp.lang.python posting
    by Duncan Booth.c            s     |  |   S(   N(    (   t   argst   kw(   t   new_fn(    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   wrapper   s    (   R2   (   R6   t   old_fnt   additional_textR7   (    (   R6   sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   decorate_fn_with_doc   s    	c         C  sC   y t  |   } Wn t k
 r$ g  SX| j   } | j   | Sd S(   s   Return the contents of a named file as a list of lines.

    This function never raises an IOError exception: if the file can't be
    read, it simply returns an empty list.N(   t   opent   IOErrort	   readlinest   close(   t   fnamet   outfilet   out(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   _file_lines   s    
R
   c           B  sO  e  Z d  Z d d d d d  Z d   Z d   Z d   Z e e e	 j
  Z Z
 d   Z e e e	 j  Z Z d   Z d   Z e e e	 j  Z Z d	   Z d
   Z d   Z d d d  Z d d d  Z e d  Z d   Z d   Z d   Z e Z d   Z d   Z e Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& RS(   s+   Modified Pdb class, does not load readline.R   c           s  t  r1 | d  k r1 t j   d | d t j n t j   | | |  t   _ t    _ t     _	   j	 d  k r d d l
 m } | j     _	 n    j r8d d  l     f d     _ d    _   j   _   j	 j j   _   j   j	 j _ t   j t j    _   j   _ t   j t j    _ n  i    _ t     _ t j }   j } | j  | d j! _" | j  | d j! _# | j$ | d j! _" | j% | d j! _# | j$ | d j! _" | j% | d j! _#   j& |  t' j(     _) d  S(	   Nt   stdint   stdouti(   t   TerminalInteractiveShellc           s    j  j   |  |  S(   N(   t   fnst	   checkline(   t   filenamet   lineno(   R   t   pydb(    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   <lambda>   s    R   t   Linuxt   LightBG(*   t   has_pydbR   t   OldPdbR+   R   RD   t   promptt   is_pydbR   t   shellt!   IPython.terminal.interactiveshellRE   t   instancet   pydb.fnsRG   t   curframet   new_do_restartt
   do_restartt	   Completert   all_completionst   old_all_completionsR:   t   list_command_pydbt   do_listt   do_lt   new_do_framet   do_framet   aliasesR   t   color_scheme_tableR   t
   TermColorsR   R!   t   breakpoint_enabledt   breakpoint_disabledt   LightRedt   Redt
   set_colorsR   t   Parsert   parser(   R   t   color_schemet   completekeyRC   RD   RE   t   Ct   cst(    (   R   RJ   sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyR+      sB    									c         C  s   |  j  j |  d S(   s;   Shorthand access to the color table scheme selector method.N(   Rb   t   set_active_scheme(   R   t   scheme(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyRh     s    c         C  sk   |  j  j |  xT t rf y t j |  | |  Wn/ t k
 ra |  j  j d |  j  j    Pq XPq Wd  S(   Ns   
(   RR   t   set_completer_framet   TrueRO   t   interactiont   KeyboardInterruptt   writet   get_exception_only(   R   t   frameR&   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyRs     s    	c         C  s'   t  j |  |  |  j j |  j  d  S(   N(   RO   t   do_upRR   Rq   RV   (   R   t   arg(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt	   new_do_up  s    c         C  s'   t  j |  |  |  j j |  j  d  S(   N(   RO   t   do_downRR   Rq   RV   (   R   Ry   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   new_do_down#  s    c         C  s'   t  j |  |  |  j j |  j  d  S(   N(   RO   R`   RR   Rq   RV   (   R   Ry   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyR_   )  s    c         C  sb   t  |  d  r$ |  j |  j j _ n  |  j j d  k	 rR |  j j j |  j j  n  t	 j
 |  |  S(   NR[   (   t   hasattrR[   RR   RY   RZ   R   R   t   set_completer_delimst   readline_delimsRO   t   do_quit(   R   Ry   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   new_do_quit-  s
    c         C  s   |  j  d  |  j |  S(   s\   Restart command. In the context of ipython this is exactly the same
        thing as 'quit'.s6   Restart doesn't make sense here. Using 'quit' instead.(   t   msgR   (   R   Ry   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyRW   :  s    c         C  s   |  j  j d   d  S(   N(   RR   Rq   R   (   R   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   postloop@  s    c         C  sC   y+ x$ |  j  D] } |  j | d d q WWn t k
 r> n Xd  S(   Nt   contexti   (   t   stackt   print_stack_entryRt   (   R   t   frame_lineno(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   print_stack_traceC  s
    s   
-> i   c         C  sW   t  |  j | d |  d t j | \ } } | j j } |  j j j | | d  d  S(   NR3   t   filei    (	   R   t   format_stack_entryR   RD   t   f_codet   co_filenameRR   t   hookst   synchronize_with_editor(   R   R   t   prompt_prefixR   Rw   RI   RH   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyR   J  s    "s   : c         C  s  y d d  l  } Wn t k
 r/ d d  l } n Xg  } |  j j } | j } d | j | f } d | j | j | f }	 d | j	 | f }
 d | j
 | j | f } | \ } } d } d | j k r | j d } | | j |  d 7} n  | j |  |  j | j j  } | t j |  } | j j r;| j j } n d	 } d } | d
 k rd | j k r{| j | j d  } n d } |	 | | f } n  | |  j k r| j d  n | j d  | j d | | | f  | d | d } t j |  } t | t |  |  } t | d  } | | | | !} x| t |  D]n \ } } | d | | k } | |  j k sv| r|| p|
 } | j |  j | | | d | | d |  qAWd j |  S(   Niu   %s%%s%su   %s%%s%s%%s%su   %%s%s%%s %s%%su   %%s%s%%s %s%%s%sR3   t
   __return__s   
s   <lambda>t   ?t   __args__s   ()s   > s     u	   %s(%s)%s
i   i   i    t   arrow(   R#   R    R$   Rb   t   active_colorst   Normalt
   filenameEmt   vNamet   valEmRI   t   linenoEmt   linet   f_localst   appendt   canonicR   R   R   t   cast_unicodet   co_nameRV   R   t   getlinest   mint   lent   maxt	   enumeratet   _Pdb__format_linet   join(   R   R   t   lprefixR   R#   t   rett   Colorst   ColorsNormalt   tpl_linkt   tpl_callt   tpl_linet   tpl_line_emRw   RI   t   return_valuet   rvRH   t   linkt   funct   callR4   t   startt   linest   iR   t
   show_arrowt   linetpl(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyR   U  s^    	
c         C  s  d } d } |  j  j } |  j j | d |  \ }	 }
 |
 sE |	 } n  d  } | |  j |  k r |  j | |  } | d } n  | r |  j  j } t | j	  } | j
 } | j s | j } q n  d } | rn| t t |   t |  } | d k rd | d d } n0 | d k r#d	 } n | d
 k r8d } n d } d | t |  f } | | | | | f } n7 d | t |  t |  f } | | | | | f } | S(   NR3   t   strii   i   t   -s   -> i   s   > i   t   >s   %s%ss   %*s(   Rb   t   active_scheme_nameRj   t   format2R   t   get_file_breakst
   get_breaksR   R   t   numberRd   t   enabledRe   R   (   R   R   RH   RI   R   R   t   bp_markt   bp_mark_colorRp   t   new_linet   errt   bpt   bpsR   t   numbers_widtht   padt   markert   num(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   __format_line  s>     			 		 c         C  sA   t  j |  |  \ } } } | d k	 r= |  j | | |  n  d S(   s5   List command to use if we have a newer pydb installedN(   RO   t   parse_list_cmdR   t   print_list_lines(   R   Ry   RH   t   firstt   last(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyR\     s    c      	   C  sG  y/|  j  j } | j } d | j | f } d | j | j | f } g  } | d k rq t |  d  rq |  j } n  x t | | d  D] }	 t	 j
 | |	  }
 |
 s Pn  |	 |  j j k r |  j | | |	 |
 d t }
 n |  j | | |	 |
 d t }
 | j |
  |	 |  _ q Wt d j |  d t j Wn t k
 rBn Xd	 S(
   sI   The printing (as opposed to the parsing part of a 'list'
        command.s   %%s%s%%s %s%%ss   %%s%s%%s %s%%s%ss   <string>t   _exec_filenamei   R   R3   R   N(   Rb   R   R   RI   R   R   R}   R   t   rangeR   t   getlineRV   t   f_linenoR   Rr   t   FalseR   R   R   R   RD   Rt   (   R   RH   R   R   R   R   R   R   t   srcRI   R   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyR     s(    	! c         C  s\  d |  _  d  } | r y t | i  i   } t |  t d  k r | \ } } t |  } t |  } | | k  r | | } q n t d t |  d  } Wq t d t |   d  SXn8 |  j d  k r t d |  j	 j
 d  } n |  j d } | d  k r| d } n  |  j |  j	 j j | |  | } |  j	 j j } |  j j j | | d  d  S(   Nt   listi   i   s   *** Error in argument:i
   i    (    (   t   lastcmdR   t   evalt   typet   intR   R   R$   RI   RV   R   R   R   R   RR   R   R   (   R   Ry   R   t   xR   RI   RH   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyR]     s0    	c         C  st   t  j |  \ } } t  j |  r@ | j | j k r@ | d f St  j |  rY | d f St  j | |  | d f S(   Ni   (   t   inspectt
   findsourcet   isframet	   f_globalsR   t   ismodulet   getblock(   R   t   objR   RI   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   getsourcelines  s    !

c         C  s   d |  _  |  j j j } |  j |  } y |  j |  j  \ } } Wn! t k
 rf } |  j |  d  SX| t |  } |  j	 |  j j j | |  d  S(   Nt   longlist(
   R   RV   R   R   R   R   t   OSErrort   errorR   R   (   R   Ry   RH   t	   breaklistR   RI   R   R   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   do_longlist  s    	c         C  sD   d |  j  j f d |  j  j f g } |  j j d  | d | d S(   sZ   Print the call signature for any callable object.

        The debugger interface to %pdeft   Localst   Globalst   pdeft
   namespacesN(   RV   R   R   RR   t   find_line_magic(   R   Ry   R   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   do_pdef  s    c         C  sD   d |  j  j f d |  j  j f g } |  j j d  | d | d S(   sL   Print the docstring for an object.

        The debugger interface to %pdoc.R   R   t   pdocR   N(   RV   R   R   RR   R   (   R   Ry   R   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   do_pdoc#  s    c         C  sD   d |  j  j f d |  j  j f g } |  j j d  | d | d S(   su   Print (or run through pager) the file where an object is defined.

        The debugger interface to %pfile.
        R   R   t   pfileR   N(   RV   R   R   RR   R   (   R   Ry   R   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   do_pfile+  s    c         C  sD   d |  j  j f d |  j  j f g } |  j j d  | d | d S(   sd   Provide detailed information about an object.

        The debugger interface to %pinfo, i.e., obj?.R   R   t   pinfoR   N(   RV   R   R   RR   R   (   R   Ry   R   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   do_pinfo4  s    c         C  sD   d |  j  j f d |  j  j f g } |  j j d  | d | d S(   sl   Provide extra detailed information about an object.

        The debugger interface to %pinfo2, i.e., obj??.R   R   t   pinfo2R   N(   RV   R   R   RR   R   (   R   Ry   R   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt	   do_pinfo2<  s    c         C  sD   d |  j  j f d |  j  j f g } |  j j d  | d | d S(   s;   Print (or run through pager) the source code for an object.R   R   t   psourceR   N(   RV   R   R   RR   R   (   R   Ry   R   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt
   do_psourceD  s    N('   R0   R1   R2   R   R+   Rh   Rs   Rz   R:   RO   Rx   t   do_uR|   R{   t   do_dR_   R   R   t   do_qRW   R   R   R   R   R   R   R\   R   R]   R^   R   R   t   do_llR   R   R   R   R   R   (    (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyR
      s@   B									
B(			 									((   R2   t
   __future__R    R   R   R   t	   linecacheR   t   IPythonR   t   IPython.utilsR   R   R   R   R   t   IPython.core.excolorsR   t   IPython.testing.skipdoctestR   R   RN   RP   t   argvRJ   R}   t   versionRr   R    R   R
   RO   t   pdbR   R   R   t   objectR   R:   RB   (    (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/debugger.pyt   <module>   s<   !	Z	