
NXc           @  s,  d  Z  d d l m 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
 Z
 d d l Z d d l Z d d l Z d d l Z y e j Z Wn e k
 r e j Z n Xd d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d d l m Z d d l m Z d d l m  Z  d d	 l! m" Z" d d
 l# m$ Z$ d d l# m% Z% d d l# m& Z& d d l# m' Z( d d l# m) Z) d d l# m* Z* d d l+ m, Z, d d l- m. Z. m/ Z/ d Z0 d Z1 d   Z2 d   Z3 d   Z4 d   Z5 e4 d d d   Z6 e$ j7   Z8 e9 e9 d  Z: d e; f d     YZ< d e< f d     YZ= d  e< f d!     YZ> d" e> e= f d#     YZ? d$ e? f d%     YZ@ d& e? f d'     YZA d( e= f d)     YZB d*   ZC eC d+  ZD eC d,  ZE eF d- k r(d.   ZG d d/  ZH eI   d0  ZJ eK d1  eK d2  y eK eG d d3 d4 f   Wn e jL   n XeK d1  eA   ZM eK d5  y eK eG d d3 d4 f   Wn eM e
 jN     n XeK d1  e>   ZM eK d6  y eK eG d d3 d4 f   Wn eM e
 jN     n XeK d1  n  d S(7   uQ
  
Verbose and colourful traceback formatting.

**ColorTB**

I've always found it a bit hard to visually parse tracebacks in Python.  The
ColorTB class is a solution to that problem.  It colors the different parts of a
traceback in a manner similar to what you would expect from a syntax-highlighting
text editor.

Installation instructions for ColorTB::

    import sys,ultratb
    sys.excepthook = ultratb.ColorTB()

**VerboseTB**

I've also included a port of Ka-Ping Yee's "cgitb.py" that produces all kinds
of useful info when a traceback occurs.  Ping originally had it spit out HTML
and intended it for CGI programmers, but why should they have all the fun?  I
altered it to spit out colored text to the terminal.  It's a bit overwhelming,
but kind of neat, and maybe useful for long-running programs that you believe
are bug-free.  If a crash *does* occur in that type of program you want details.
Give it a shot--you'll love it or you'll hate it.

.. note::

  The Verbose mode prints the variables currently visible where the exception
  happened (shortening their strings if too long). This can potentially be
  very slow, if you happen to have a huge data structure whose string
  representation is complex to compute. Your computer may appear to freeze for
  a while with cpu usage at 100%. If this occurs, you can cancel the traceback
  with Ctrl-C (maybe hitting it more than once).

  If you encounter this kind of situation often, you may want to use the
  Verbose_novars mode instead of the regular Verbose, which avoids formatting
  variables (but otherwise includes the information and context given by
  Verbose).


Installation instructions for VerboseTB::

    import sys,ultratb
    sys.excepthook = ultratb.VerboseTB()

Note:  Much of the code in this module was lifted verbatim from the standard
library module 'traceback.py' and Ka-Ping Yee's 'cgitb.py'.

Color schemes
-------------

The colors are defined in the class TBTools through the use of the
ColorSchemeTable class. Currently the following exist:

  - NoColor: allows all of this module to be used in any terminal (the color
    escapes are just dummy blank strings).

  - Linux: is meant to look good in a terminal like the Linux console (black
    or very dark background).

  - LightBG: similar to Linux but swaps dark/light colors to be more readable
    in light background terminals.

You can implement other color schemes easily, the syntax is fairly
self-explanatory. Please send back new schemes you develop to the author for
possible inclusion in future releases.

Inheritance diagram:

.. inheritance-diagram:: IPython.core.ultratb
   :parts: 3
i(   t   unicode_literals(   t   print_functionN(
   t   getsourcefilet   getfilet	   getmodulet   ismodulet   isclasst   ismethodt
   isfunctiont   istracebackt   isframet   iscode(   t   get_ipython(   t   debugger(   t   DisplayTrap(   t   exception_colors(   t
   PyColorize(   t   io(   t   openpy(   t   path(   t	   py3compat(   t
   ulinecache(   t   uniq_stable(   t   infot   errori   u   NoColorc           C  s   t  d  d S(   uY   Print a message about internal inspect errors.

    These are unfortunately quite common.u^   Internal Python error in the inspect module.
Below is the traceback from this internal error.
N(   R   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   inspect_error   s    c         C  sv  t  |   p t |   } d } t j |   r9 |  j } n! t |  |  } | rZ | j } n  t j	 | |  } | s t
 d   n  t |   r | d f St |   rm|  j } t j d | d  } g  } xp t t |   D]\ } | j | |  }	 |	 r | | d d k r| | f S| j |	 j d  | f  q q W| r^| j   | | d d f St
 d   n  t |   r|  j }  n  t |   r|  j }  n  t |   r|  j }  n  t |   r|  j }  n  t |   rft |  d  st
 d	   n  t j d
  } | j }
 t |  j  t |   d } x. | d k r[|
 | |  rNPn  | d 8} q.W| | f St
 d   d S(   u  Return the entire source file and starting line number for an object.

    The argument may be a module, class, method, function, traceback, frame,
    or code object.  The source code is returned as a list of all the lines
    in the file and the line number indexes a line in that list.  An IOError
    is raised if the source code cannot be retrieved.

    FIXED version with which we monkeypatch the stdlib to work around a bug.u   could not get source codei    u   ^(\s*)class\s*u   \bu   ci   u   could not find class definitionu   co_firstlinenou"   could not find function definitionu+   ^(\s*def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)u   could not find code objectN(!   R   R   t   Nonet   inspectR
   t	   f_globalsR   t   __dict__t	   linecachet   getlinest   IOErrorR   R   t   __name__t   ret   compilet   ranget   lent   matcht   appendt   groupt   sortR   t   __func__R   t   __code__R	   t   tb_framet   f_codeR   t   hasattrt   mint   co_firstlineno(   t   objectt   filet   globals_dictt   modulet   linest   namet   patt
   candidatest   iR&   t   pmatcht   lnum(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt
   findsource   s\    

	
#
	 
c           s     f d   } | S(   u/   decorator for monkeypatching inspect.findsourcec            s4   t  j } t t  _ z   |  |   SWd  | t  _ Xd  S(   N(   R   R<   (   t   argst   kwargst   save_findsource(   t   f(    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   wrapped   s
    		(    (   R@   RA   (    (   R@   sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   with_patch_inspect   s    c   	      C  s   g  } x |  D] \ } } } } } } t  j | d  } | j d  sv | j j d d  } t | t  rv | } qv n  | j | | | | | | f  q W| S(   u   Try to fix the filenames in each record from inspect.getinnerframes().

    Particularly, modules loaded from within zip files have useless filenames
    attached to their code object, and inspect.getinnerframes() just uses it.
    u   utf-8u   .pyxu   .pxdu   .pxiu   __file__(   u   .pyxu   .pxdu   .pxiN(	   R   t   cast_unicode_py2t   endswithR   t   getR   t
   isinstancet   strR'   (	   t   recordst   fixed_recordst   framet   filenamet   line_not	   func_nameR5   t   indext	   better_fn(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   fix_frame_records_filenames   s    #i   i    c         C  sj  d \ } } } t  t j |  |   } | | } y1 | d d } | d k s] | j d  ra | SWn t k
 ru n Xt j |   }	 t |  t |	  k s t  x t	 t
 t |   |	  D] \ }
 \ } } } } | d | d } t | d  } | | } t j |  | | !} t | |
  } | | | <| d | | | <| | | <t |  | |
 <q W| | S(	   Ni   i   i   i    i   u   <ipython console>u   <string>(   i   i   i   (   RP   R   t   getinnerframesRD   t
   IndexErrort	   tracebackt
   extract_tbR%   t   AssertionErrort   zipR$   t   maxR   R   t   listt   tuple(   t   etbt   contextt	   tb_offsett   LNUM_POSt	   LINES_POSt	   INDEX_POSRH   t	   rec_checkt   rnamet   auxR9   R2   R;   t   _t
   maybeStartt   startt   endR5   t   buf(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   _fixed_getinnerframes  s,    
4


c         C  s  t  d } g  } |  | } | d  k rP t   }	 |	 d  k	 rG |	 j } qP t } n  t j }
 xU| D]M} t j |  } |
 | d |  \ } } | s | } n  | |  k rD| t	 t
 |   } | d k r d | d d } n0 | d k r d } n | d k r	d } n d	 } | t
 |  } d
 | j | | j | | j f } n, d | | f } d | j | | j | f } | j |  | r| |  k r| j | d  n  | d } q` W| S(   Ni   u   stri   u   -u   -> i   u   > u   >u    u   %s%s%s %s%su   %*su	   %s%s%s %su   
(   t   INDENT_SIZER   R   t   colorst   DEFAULT_SCHEMEt   _parsert   format2R   t   cast_unicodeR%   RG   t   linenoEmt   linet   Normalt   linenoR'   (   R;   RN   R5   t   Colorst   lvalst   schemet   numbers_widtht   resR9   t   ipinstt   _line_formatRp   t   new_linet   errt   padt   markert   num(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   _format_traceback_lines-  sD    

			 			t   TBToolsc           B  s   e  Z d  Z d Z d e d d  Z d   Z d   Z e	 e e  Z
 d   Z d   Z d   Z d d	 d
  Z d d	 d d  Z RS(   u2   Basic tools used by all traceback printer classes.i    u   NoColorc         C  sb   | |  _  | |  _ t   |  _ |  j |  | |  _ | rU t j |  j j  |  _	 n	 d  |  _	 d  S(   N(   t   call_pdbt   _ostreamR   t   color_scheme_tablet
   set_colorst
   old_schemeR   t   Pdbt   active_scheme_namet   pdbR   (   t   selft   color_schemeR   t   ostream(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   __init__d  s    				c         C  s   |  j  d k r t j S|  j  S(   ur  Output stream that exceptions are written to.

        Valid values are:

        - None: the default, which means that IPython will dynamically resolve
          to io.stdout.  This ensures compatibility with most tools, including
          Windows (where plain stdout doesn't recognize ANSI escapes).

        - Any object with 'write' and 'flush' attributes.
        N(   R   R   R   t   stdout(   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   _get_ostream}  s    c         C  s=   | d  k s0 t | d  r* t | d  s0 t  | |  _ d  S(   Nu   writeu   flush(   R   R.   RU   R   (   R   t   val(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   _set_ostream  s    0c         O  sZ   |  j  j | |   |  j  j |  _ t |  d  rV |  j d k	 rV |  j j | |   n  d S(   u;   Shorthand access to the color table scheme selector method.u   pdbN(   R   t   set_active_schemet   active_colorsRs   R.   R   R   R   (   R   R=   t   kw(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    c         C  si   |  j  j d k r7 |  j  j |  j  |  j  j |  _ n. |  j  j |  _ |  j  j d  |  j  j |  _ d S(   u=   Toggle between the currently active color scheme and NoColor.u   NoColorN(   R   R   R   R   R   Rs   (   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   color_toggle  s    c         C  s   d j  |  S(   u4   Convert a structured traceback (a list) to a string.u   
(   t   join(   R   t   stb(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   stb2text  s    i   c         C  s(   |  j  | | | | |  } |  j |  S(   ug   Return formatted traceback.

        Subclasses may override this if they add extra arguments.
        (   t   structured_tracebackR   (   R   t   etypet   valuet   tbR\   R[   t   tb_list(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   text  s    c         C  s   t     d S(   uW   Return a list of traceback frames.

        Must be implemented by each class.
        N(   t   NotImplementedError(   R   R   t   evalueR   R\   R[   t   mode(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    N(   R!   t
   __module__t   __doc__R\   t   FalseR   R   R   R   t   propertyR   R   R   R   R   R   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR   ^  s   						t   ListTBc           B  se   e  Z d  Z d e d d  Z d   Z d d d  Z d   Z d   Z	 d   Z
 d	   Z d
   Z RS(   un  Print traceback information from a traceback list, with optional color.

    Calling requires 3 arguments: (etype, evalue, elist)
    as would be obtained by::
    
      etype, evalue, tb = sys.exc_info()
      if tb:
        elist = traceback.extract_tb(tb)
      else:
        elist = None

    It can thus be used by programs which need to process the traceback before
    printing (such as console replacements based on the code module from the
    standard library).

    Because they are meant to be called without a full traceback (only a
    list), instances of this class can't call the interactive pdb debugger.u   NoColorc         C  s#   t  j |  d | d | d | d  S(   NR   R   R   (   R   R   (   R   R   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    c         C  s@   |  j  j   |  j  j |  j | | |   |  j  j d  d  S(   Nu   
(   R   t   flusht   writeR   (   R   R   R   t   elist(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   __call__  s    i   c   	      C  s   | d k r |  j n | } |  j } g  } | r | rU t |  | k rU | | } n  | j d | j | j f d  | j |  j |   n  d j	 |  j
 | |   } | j |  | S(   u  Return a color formatted string with the traceback info.

        Parameters
        ----------
        etype : exception type
          Type of the exception raised.

        value : object
          Data stored in the exception

        elist : list
          List of frames, see class docstring for details.

        tb_offset : int, optional
          Number of frames in the traceback to skip.  If not given, the
          instance value is used (set in constructor).

        context : int, optional
          Number of lines of context information to print.

        Returns
        -------
        String with formatted exception.
        u&   Traceback %s(most recent call last)%s:u   
u    N(   R   R\   Rs   R%   R'   t   normalEmRq   t   extendt   _format_listR   t   _format_exception_only(	   R   R   R   R   R\   R[   Rs   t   out_listR5   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    		c   	      C  sW  |  j  } g  } x | d  D] \ } } } } d | j t j | d  | j | j | | j | j t j | d  | j f	 } | r | d | j   7} n  | j |  q W| d \ } } } } d | j	 | j
 t j | d  | j	 | j | | j	 | j t j | d  | j	 | j f } | rF| d | j | j   | j f 7} n  | j |  | S(   u   Format a list of traceback entry tuples for printing.

        Given a list of tuples as returned by extract_tb() or
        extract_stack(), return a list of strings ready for printing.
        Each string in the resulting list corresponds to the item with the
        same index in the argument list.  Each string ends in a newline;
        the strings may contain internal newlines as well, for those items
        whose source text line is not None.

        Lifted almost verbatim from traceback.py
        iu(     File %s"%s"%s, line %s%d%s, in %s%s%s
u   utf-8u       %s
u,   %s  File %s"%s"%s, line %s%d%s, in %s%s%s%s
u   %s    %s%s
(   Rs   RK   R   RC   Rq   Rr   R6   t   stripR'   R   t
   filenameEmRo   t   nameEmRp   (	   R   t   extracted_listRs   RX   RK   Rr   R6   Rp   t   item(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s,    	"c      	   C  s  t  } |  j } g  } | j | j | j } | d k rU | j t j |  d  n,t	 | t
  rt } | j s d | _ n  | j r | j } t j | j | j  } n d } d } | j d | j | j t j | j  | j | j | | j f  | d k rt j | j d  } n  | d k	 rd }	 x0 |	 t |  k  ra| |	 j   ra|	 d 7}	 q2W| j d	 | j | j   | j f  | j d k	 rd
 }
 x? | |	 | j d !D]) } | j   r|
 | 7}
 q|
 d 7}
 qW| j d | j |
 | j f  qqn  y | j }
 Wn  t k
 r7|  j |  }
 n X|
 rj| j d t |  | j | j |
 f  n | j d t |   | rt   } | d k	 r| j j  | j | j d  qn  | S(   uT  Format the exception part of a traceback.

        The arguments are the exception type and value such as given by
        sys.exc_info()[:2]. The return value is a list of strings, each ending
        in a newline.  Normally, the list contains a single string; however,
        for SyntaxError exceptions, it contains several lines that (when
        printed) display detailed information about where the syntax error
        occurred.  The message indicating which exception occurred is the
        always last string in the list.

        Also lifted nearly verbatim from traceback.py
        u   
u   <string>u   unknownu    u   %s  File %s"%s"%s, line %s%s%s
u   utf-8i    i   u   %s    %s%s
u       u    u   %s%s^%s
u   %s%s:%s %s
u   %s
N(!   R   Rs   t   excNameR!   Rq   R   R'   R   Rn   t
   issubclasst   SyntaxErrort   TrueRK   Rr   R   t   getlineR   R   Ro   R   R%   t   isspaceRp   R   t   offsett   carett   msgt	   Exceptiont	   _some_strRG   R   t   hookst   synchronize_with_editor(   R   R   R   t   have_filedataRs   RX   t   stypeRr   t   textlineR9   t   st   cRx   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR   3  sb    		 			%		"c         C  s   t  j |  | | g   S(   u   Only print the exception type and message, without a traceback.

        Parameters
        ----------
        etype : exception type
        value : exception value
        (   R   R   (   R   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   get_exception_only{  s    c         C  sC   |  j  } | j   | j d j |  j | |    | j   d S(   u   Only print the exception type and message, without a traceback.

        Parameters
        ----------
        etype : exception type
        value : exception value
        u   
N(   R   R   R   R   R   (   R   R   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   show_exception_only  s    
	
"c         C  s*   y t  |  SWn d t |  j SXd  S(   Nu   <unprintable %s object>(   RG   t   typeR!   (   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    N(   R!   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s   	4	%	H	
	t	   VerboseTBc           B  s   e  Z d  Z d e d d e e d d  Z d   Z d   Z e d  Z	 d   Z
 d   Z d	   Z d
   Z d d d  Z e d  Z d d  Z d d d d  Z RS(   u;  A port of Ka-Ping Yee's cgitb.py module that outputs color text instead
    of HTML.  Requires inspect and pydoc.  Crazy, man.

    Modified version which optionally strips the topmost entries from the
    traceback, to be used with alternate interpreters (because their own code
    would appear in the traceback).u   Linuxi    c         C  s_   t  j |  d | d | d | | |  _ | |  _ | |  _ | d k rR t j } n  | |  _ d S(   uW  Specify traceback offset, headers and color scheme.

        Define how many frames to drop from the tracebacks. Calling it with
        tb_offset=1 allows use of this handler in interpreters which will have
        their own code at the top of the traceback (VerboseTB will first
        remove that frame before printing the traceback info).R   R   R   N(	   R   R   R\   t   long_headert   include_varsR   R   t
   checkcachet   check_cache(   R   R   R   R   R\   R   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    				c   3      C  s  |  j  } | j } |  j j } d t } d | j | | f } d | j | f } g  } d | j | f }	 d | j | j | f }
 d | j | j | f } d | j | f } d | j | | j | f } d | j | f } d	 | j	 | f } d
 | j
 | j | f } t j j } x| D]\ } } } } } } | sDd } n | j t d   rq| j t d   rqn~ t j j |  sxi t j D][ } yA t j j | |  } t j j |  rt j j |  } Pn  Wqt k
 rqXqWn  t j | t j  } |	 | } t j |  \ } } } } | d k r>d } n_ |  j rMt pPt }  y, |
 | t j  | | | | d |  f } Wn t! k
 r| | } n X| j d  r| j" d | | f  qn! | j d  rt# j$ |  } n  | | g t% j& d  }! y g  }" t' }# x t( |!  D] \ }$ }% }& }' }( |$ t) j* k r|% t+ j, k r|# ry |" d j" |%  Wn! t- k
 r|" j" |% g  n Xt' }# q|" j" |% g  q|% d k rt. }# q|$ t) j/ k rPqqWWnC t- t0 t1 f k
 rn* t) j2 k
 r}) d |) }* t3 |*  n Xg  |" D] }+ d j |+  ^ q&}" t4 |"  }, g  }- |  j rHx |, D] }. |. j5 d d  d }/ |/ | j6 j7 k r|/ | k ry t8 t9 |. |   }0 Wq| }0 qXn | }0 | |. }1 nN |/ | j: k ry t8 t9 |. | j:   }0 Wq | }0 q Xn | }0 | |. }1 |- j" | |1 |0 f  qcWn  |- rjd | | j |-  f }- n d }- d | | f }2 | d  k r| j" |2  q| j" d |2 d j t< | | | | |- |   f  qW| S(   Nu    u   %s
%s%su   %sundefined%su   %s%%s%su   in %s%%s%s%%s%su.   in %s%%s%s(***failed resolving arguments***)%su   %sglobal%s %s%%s%su   %%s %s= %%s%su   %s%%s%s %%su   %s%%s%s %%s%su   ?u   <u   >u    t   formatvalueu   .sou   .pydu   .dllu   %s %s
u   .pycu   .pyoc         S  s'   | |  | d  } | d c d 7<| S(   Ni    i   (    (   R2   R;   R   Rp   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt
   linereader  s    iu   .u   An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: %s
i   i    u   %s%s(   u   .sou   .pydu   .dll(   u   .pycu   .pyo(=   Rs   Rq   R   R   Ri   t   valEmt   emR   t   vNameRr   Ro   Rp   t   osR   t   abspatht
   startswithRG   RD   t   isabst   sysR   t   isfileR   R   Rn   t	   util_patht   fs_encodingR   t   getargvaluesR   t   eqreprt   nullreprt   formatargvaluest   KeyErrorR'   R   t   source_from_cacheR   R   R   t   generate_tokenst   tokenizet   NAMEt   keywordt   kwlistRR   R   t   NEWLINEt   UnicodeDecodeErrorR   t
   TokenErrorR   R   t   splitR-   t   co_varnamest   reprt   evalR   R   R   (3   R   RH   Rs   t   ColorsNormalt
   col_schemet   indentt	   em_normalt	   undefinedt   framest   tpl_linkt   tpl_callt   tpl_call_failt   tpl_local_vart   tpl_global_vart   tpl_name_valt   tpl_linet   tpl_line_emR   RJ   R2   R;   t   funcR5   RN   t   dirnamet   fullnamet   linkR=   t   varargst   varkwt   localst   callt   var_reprR   t   namest	   name_contt
   token_typet   tokenRe   Rf   Rp   R   t   _mt   nt   unique_namesRt   t	   name_fullt	   name_baseR   R6   t   level(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   format_records  s    		


	*
	"		"	
c         C  s1   d } d } | r! | g g } n | g g } | S(   NuF   
The above exception was the direct cause of the following exception:
uE   
During handling of the above exception, another exception occurred:
(    (   R   t   causet   direct_causet   exception_during_handlingt   message(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt!   prepare_chained_exception_messagek  s    c   	   
   C  s   |  j  } | j } d | j | | f } | r d t j j   d d t j } t j t j    } d | j	 d d | | d d t
 t |   t
 |  | | j d  f } | d	 7} n) d
 | d j d t
 t |    f } | S(   Nu   %s%s%su   Python i    u   : u   %s%s%s
%s%s%s
%su   -iK   u    u   
A problem occurred executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.u   %s%su!   Traceback (most recent call last)(   Rs   Rq   R   R   t   versionR   t
   executablet   timet   ctimet   toplineR%   RG   t   rjust(	   R   R   t   long_versionRj   t   colorsnormalt   exct   pyvert   datet   head(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   prepare_headeru  s    		"$c         C  s  |  j  } | j } d t } y t t | | f  \ } } Wn9 t t j   d  } } t t | | f  \ } } n Xd | j | | t j	 |  f g } t j
 rt |  t j k ry5 g  t |  D] }	 t |	 t j  r |	 ^ q }
 Wnu d } | j | | j | f  t t t j   d   \ } } | j d | j | | t j	 |  f  g  }
 n Xx@ |
 D]5 } t t | |   } | j d | | | f  qoWn  | S(   Nu    i   u
   %s%s%s: %su9   %sException reporting error (object with broken dir())%s:u
   
%s%s = %s(   Rs   Rq   Ri   t   mapRG   R   t   exc_infoR   R   Rn   t   PY3R   t   typest   InstanceTypet   dirRF   t   string_typesR'   t	   text_reprt   getattr(   R   R   R   Rj   R  R   t	   etype_strt
   evalue_strt	   exceptiont   wR  R  R6   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   format_exception  s0    		
5
!c         C  s  y | j  } Wn t k
 r  n X| d  k r6 |  j n | } |  j | |  j  } |  j | | |  } |  j |  } | d  k r d S|  j | |  }	 | r | d d d !\ }
 } t	 j
 j |
  }
 t   } | d  k	 r | j j |
 | d  q n  | g | d j |	 d  g g S(   Nu    ii   i   i    (   R!   t   AttributeErrorR   R\   R   R   t   get_recordsR  R.  R   R   R   R   R   R   R   (   R   R   R   RZ   t   number_of_lines_of_contextR\   R  RH   R   t   formatted_exceptiont   filepathR;   Rx   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   format_exception_as_a_whole  s$    	c         C  sG   y t  | | |  SWn, t   t j d |  j  t d  d  SXd  S(   NR2   u@   
Unfortunately, your original traceback can not be constructed.
(   Rh   R   RS   t	   print_excR   R   R   (   R   RZ   R1  R\   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR0    s    
c         C  s2   d   } | |  } | r. | j  | | j f Sd  S(   Nc         S  sB   t  |  d d   } | r | St  |  d t  r2 d  St  |  d d   S(   Nu	   __cause__u   __suppress_context__u   __context__(   R)  R   R   (   t   exception_valueR  (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   get_chained_exception  s    (   t	   __class__t   __traceback__(   R   R   R7  t   chained_evalue(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   get_parts_of_chained_exception  s    	i   c         C  sS  |  j  | | | | |  } |  j } | j } d | j d d | f }	 |	 g }
 t j rAd } d } | } |  j |  } | r | |  j | j  7} | \ } } } n d } xl | r| |  j  | | | | |  7} |  j |  } | r| |  j | j  7} | \ } } } q d } q Wx/ t
 |  D] } |
 | 7}
 q*Wn |
 | d 7}
 |
 S(   u5   Return a nice text document describing the traceback.u   %s%s%su   -iK   i    i   N(   R4  Rs   Rq   R  R   R#  R;  R  t	   __cause__R   t   reversed(   R   R   R   RZ   R\   R1  R2  Rj   R  R  t   structured_traceback_partst   chained_exceptions_tb_offsett   lines_of_contextt   formatted_exceptionsR,  (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s6    						

c         C  s;  | s |  j  r|  j d k r9 t j |  j j  |  _ n  t d t j	  } |  |  j j
   t |  d  r |  j d k	 r |  j } n t j } |  _ x4 |  j d k	 r |  j j d k	 r |  j j |  _ q W| r | j r | j } n  | j |  j _ |  j j |  j j |  j  Wd QXn  t |  d  r7|  ` n  d S(   u4  Call up the pdb debugger if desired, always clean up the tb
        reference.

        Keywords:

          - force(False): by default, this routine checks the instance call_pdb
            flag and does not actually invoke the debugger if the flag is false.
            The 'force' option forces the debugger to activate even if the flag
            is false.

        If the call_pdb flag is set, the pdb interactive debugger is
        invoked. In all cases, the self.tb reference to the current traceback
        is deleted to prevent lingering references which hamper memory
        management.

        Note that each call to pdb() does an 'import readline', so if your app
        requires a special setup for the readline completers, you'll have to
        fix that by hand after invoking the exception handler.t   hooku   tbN(   R   R   R   R   R   R   R   R   R   t   __displayhook__t   resetR.   R   t   last_tracebackt   tb_nextR,   t   botframet   interaction(   R   t   forcet   display_trapRZ   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s$    $%c         C  sn   | p t  j   \ } } } | |  _ |  j } | j   | j |  j | | |   | j d  | j   d  S(   Nu   
(   R   R"  R   R   R   R   R   (   R   R   R   R   RZ   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   handler:  s    		
c         C  s_   | d k r |  j   n |  j | | | f  y |  j   Wn t k
 rZ t d  n Xd S(   u@   This hook can replace sys.excepthook (for Python 2.1 or higher).u   
KeyboardInterruptN(   R   RK  R   t   KeyboardInterruptt   print(   R   R   R   RZ   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR   E  s    N(   R!   R   R   R   R   R   R   R  R  R   R.  R4  R0  R;  R   R   RK  R   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    				
	"			(,t   FormattedTBc        	   B  sw   e  Z d  Z d d e d d e e d d  Z d   Z d d d  Z d   Z d d	  Z	 d
   Z
 d   Z d   Z RS(   u  Subclass ListTB but allow calling with a traceback.

    It can thus be used as a sys.excepthook for Python > 2.1.

    Also adds 'Context' and 'Verbose' modes, not available in ListTB.

    Allows a tb_offset to be specified. This is useful for situations where
    one needs to remove a number of topmost frames from the traceback (such as
    occurs with python programs that themselves execute other python code,
    like Python shells).  u   Plainu   Linuxi    c	   	      C  s   d d d g |  _  |  j  d d !|  _ t j |  d | d | d | d	 | d
 | d | d | t d d d d d d  |  _ |  j |  d  S(   Nu   Plainu   Contextu   Verbosei   i   R   R   R   R\   R   R   R   t   Plainu    t   Contextu   
t   Verbose(   t   valid_modest   verbose_modesR   R   t   dictt   _join_charst   set_mode(	   R   R   R   R   R   R\   R   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR   ^  s    c         C  s   | r t  j |  Sd  Sd  S(   N(   RS   RT   R   (   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   _extract_tbr  s    i   c         C  s   | d  k r |  j n | } |  j } | |  j k rO t j |  | | | | |  S|  j   |  j |  } t j |  | | | | |  Sd  S(   N(	   R   R\   R   RS  R   R   R   RW  R   (   R   R   R   R   R\   R1  R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR   x  s    	
c         C  s   |  j  j |  S(   u4   Convert a structured traceback (a list) to a string.(   t   tb_join_charR   (   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    c         C  s   | s? |  j  j |  j  d t |  j   } |  j  | |  _ n< | |  j  k rr t d | d t |  j     n	 | |  _ |  j |  j  d k |  _ |  j |  j |  _ d S(   ub   Switch to the desired mode.

        If mode is not specified, cycles through the available modes.i   u#   Unrecognized mode in FormattedTB: <u   >
Valid modes: i   N(	   RR  RN   R   R%   t
   ValueErrorRG   R   RU  RX  (   R   R   t   new_idx(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyRV    s    !	c         C  s   |  j  |  j d  d  S(   Ni    (   RV  RR  (   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   plain  s    c         C  s   |  j  |  j d  d  S(   Ni   (   RV  RR  (   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR[     s    c         C  s   |  j  |  j d  d  S(   Ni   (   RV  RR  (   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   verbose  s    N(   R!   R   R   R   R   R   RW  R   R   RV  R[  R[   R\  (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyRN  R  s   
						t   AutoFormattedTBc           B  s>   e  Z d  Z d d d d d d  Z d d d d d d  Z RS(   uG  A traceback printer which can be called on the fly.

    It will find out about exceptions by itself.

    A brief example::

        AutoTB = AutoFormattedTB(mode = 'Verbose',color_scheme='Linux')
        try:
          ...
        except:
          AutoTB()  # or AutoTB(out=logfile) where logfile is an open file object
    c         C  s   | d k r |  j } n  | j   | j |  j | | | |   | j d  | j   y |  j   Wn t k
 r t d  n Xd S(   uK  Print out a formatted exception traceback.

        Optional arguments:
          - out: an open file-like object to direct output to.

          - tb_offset: the number of frames to skip over in the stack, on a
          per-call basis (this overrides temporarily the instance's tb_offset
          given at initialization time.  u   
u   
KeyboardInterruptN(   R   R   R   R   R   R   RL  RM  (   R   R   R   RZ   t   outR\   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    

i   c         C  sI   | d  k r$ t j   \ } } } n  | |  _ t j |  | | | | |  S(   N(   R   R   R"  R   RN  R   (   R   R   R   R   R\   R1  (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s
    	N(   R!   R   R   R   R   R   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR]    s
   		t   ColorTBc           B  s   e  Z d  Z d d d  Z RS(   u;   Shorthand to initialize a FormattedTB in Linux colors mode.u   Linuxi    c         C  s   t  j |  d | d | d  S(   NR   R   (   RN  R   (   R   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    (   R!   R   R   R   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR_    s   t   SyntaxTBc           B  sD   e  Z d  Z d d  Z d   Z d d d  Z d   Z d   Z RS(	   u:   Extension which holds some state: the last exception valueu   NoColorc         C  s   t  j |  |  d  |  _ d  S(   N(   R   R   R   t   last_syntax_error(   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    c         C  s#   | |  _  t j |  | | |  d  S(   N(   Ra  R   R   (   R   R   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    	i   c      
   C  s   t  | t  rs t  | j t j  rs t  | j t  rs t j | j  t	 j
 | j | j  } | rs | | _ qs n  t t |   j | | | d | d | S(   NR\   R[   (   RF   R   RK   R   R'  Rr   t   intR   R   R   R   R   t   superR`  R   (   R   R   R   R   R\   R[   t   newtext(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR     s    c         C  s   |  j  } d |  _  | S(   u+   Return the current error state and clear itN(   Ra  R   (   R   t   e(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   clear_err_state  s    		c         C  s   d j  |  S(   u4   Convert a structured traceback (a list) to a string.u    (   R   (   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR   	  s    N(	   R!   R   R   R   R   R   R   Rf  R   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR`    s   		c         C  s   y t  j j |   SWn t k
 r*   n y t |   SWq t k
 rQ   q yL t |  d d  } | ry t |  St |  d d  } | r d t |  SWq t k
 r   q d SXq Xn Xd S(   u(   Hopefully pretty robust repr equivalent.u   __name__u	   __class__u   %s instanceu   UNRECOVERABLE REPR FAILUREN(   t   pydocR   R   RL  R)  R   R(  (   R   R6   t   klass(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR(    s*    
c         C  s   d | |   S(   Nu   =%s(    (   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR   ,  s    c         C  s   d S(   Nu    (    (   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyR   0  s    u   __main__c         C  s1   | \ } } |  | } |  | } t  | |  d  S(   N(   t   foo(   R   t   d_et   dRe  t   xt   y(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   spam8  s    

c         C  s   t  |  | |  d  S(   N(   t   eggs(   t   at   bt   bar(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyRi  >  s    c         C  s   |  | } |  | } | | S(   N(    (   R@   t   gt   zt   hR9   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyRo  A  s    

u    u   *** Before ***i   i   u   *** ColorTB ***u   *** VerboseTB ***(O   R   t
   __future__R    R   R   R   R   R   Rg  R"   R   R  R   RS   R$  R   R/  R   R   R   R   R   R   R   R	   R
   R   t   IPythonR   t   IPython.coreR   t   IPython.core.display_trapR   t   IPython.core.excolorsR   t   IPython.utilsR   R   R   R   R   R   R   t   IPython.utils.dataR   t   IPython.utils.warnR   R   Ri   Rk   R   R<   RB   RP   Rh   t   ParserRl   R   R   R1   R   R   R   RN  R]  R_  R`  R(  R   R   R!   Rn  Ri  t   globalsRo  RM  R5  RK  R"  (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/ultratb.pyt   <module>I   s   
F		M		"1_ \2'		


	

	
