ó
æNXc           @  s¿   d  Z  d d l m Z d d l Z d d l Z d d l 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	 Z d
 Z d e f d „  ƒ  YZ d „  Z d S(   st   sys.excepthook for IPython itself, leaves a detailed report on disk.

Authors:

* Fernando Perez
* Brian E. Granger
iÿÿÿÿ(   t   print_functionN(   t   pformat(   t   ultratb(   t   author_email(   t   sys_info(   t   inputt   getcwds-  Oops, {app_name} crashed. We do our best to make it stable, but...

A crash report was automatically generated with the following information:
  - A verbatim copy of the crash traceback.
  - A copy of your input history during this session.
  - Data on your current {app_name} configuration.

It was left in the file named:
	'{crash_report_fname}'
If you can email this file to the developers, the information in it will help
them in understanding and correcting the problem.

You can mail it to: {contact_name} at {contact_email}
with the subject '{app_name} Crash Report'.

If you want to do it now, the following command will work (under Unix):
mail -s '{app_name} Crash Report' {contact_email} < {crash_report_fname}

To ensure accurate tracking of this issue, please file a report about it at:
{bug_tracker}
sz  
If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at {email}

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    {config}Application.verbose_crash=True
t   CrashHandlerc           B  sP   e  Z d  Z e Z d d d d Z d d d e e d „ Z	 d „  Z
 d „  Z RS(   sý   Customizable crash handlers for IPython applications.

    Instances of this class provide a :meth:`__call__` method which can be
    used as a ``sys.excepthook``.  The :meth:`__call__` signature is::

        def __call__(self, etype, evalue, etb)
    s   

t   *iK   c         C  s_   d | j  |  _ | |  _ | |  _ | |  _ t d | j  d | d | d | d |  j ƒ |  _ d S(   sq  Create a new crash handler

        Parameters
        ----------
        app :  Application
            A running :class:`Application` instance, which will be queried at
            crash time for internal information.

        contact_name : str
            A string with the name of the person to contact.

        contact_email : str
            A string with the email address of the contact.

        bug_tracker : str
            A string with the URL for your project's bug tracker.

        show_crash_traceback : bool
            If false, don't print the crash traceback on stderr, only generate
            the on-disk report

        Non-argument instance attributes:

        These instances contain some non-argument attributes which allow for
        further customization of the crash handler's behavior. Please see the
        source for further details.
        s   Crash_report_%s.txtt   app_namet   contact_namet   contact_emailt   bug_trackert   crash_report_fnameN(   t   nameR   t   appt   call_pdbt   show_crash_tracebackt   dictt   info(   t   selfR   R
   R   R   R   R   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/crashhandler.pyt   __init__V   s    			c   
      C  s¦  t  j t  _ d } y |  j j } Wn t ƒ  } n X| d k sT t j j	 | ƒ r` t ƒ  } n  t j j
 | |  j ƒ } | |  _ | |  j d <t j d | d d d |  j ƒ } |  j rÌ | | | | ƒ d S| j | | | d d	 ƒ} |  j rt | d
 t  j ƒn  y t | d ƒ }	 Wn t d d
 t  j ƒd SXt d d d d d
 t  j ƒt |  j j |  j   d
 t  j ƒ|	 j |  j | ƒ ƒ |	 j ƒ  t d ƒ d S(   s<   Handle an exception, call for compatible with sys.excepthookt   NoColorR   t   color_schemet   long_headeri   R   Nt   contexti   t   filet   ws&   Could not create crash report on disk.s   
R   iF   s.   Hit <Enter> to quit (your terminal may close):(   t   syst   __excepthook__t
   excepthookR   t   ipython_dirR   t   Nonet   ost   patht   isdirt   joinR   R   R   t	   VerboseTBR   t   textR   t   printt   stderrt   opent   message_templatet   formatt   writet   make_reportt   closeR   (
   R   t   etypet   evaluet   etbR   t   rptdirt   report_namet	   TBhandlert	   tracebackt   report(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/crashhandler.pyt   __call__   s>    				"
c         C  s¢   |  j  } d d d d g } | j } | t ƒ  ƒ yE t |  j j ƒ } | | ƒ | d |  j ƒ | d ƒ | | ƒ Wn n X| | d | ƒ d j | ƒ S(	   s*   Return a string containing a crash report.R   iK   s   

s   IPython post-mortem report

s   Application name: %s

s'   Current user configuration structure:

s   Crash traceback:

t    (   t   section_sept   appendR   R   R   t   configR	   R$   (   R   R5   t   sec_sepR6   t   rpt_addR;   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/crashhandler.pyR-   ¶   s    		

N(   t   __name__t
   __module__t   __doc__t   _default_message_templateR*   R9   R    t   Truet   FalseR   R7   R-   (    (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/crashhandler.pyR   J   s   (	7c         C  sg   t  j |  | | ƒ d d l m } | j ƒ  r8 d } n d } t t j d t d | ƒ d t	 j
 ƒd S(	   sA   a light excepthook, adding a small message to the usual tracebackiÿÿÿÿ(   t   InteractiveShells   %config s   c.t   emailR;   R   N(   R5   t   print_exceptiont   IPython.core.interactiveshellRD   t   initializedR'   t   _lite_message_templateR+   R   R   R(   (   R/   R0   t   tbRD   R;   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/crashhandler.pyt   crash_handler_liteÌ   s    	(   R@   t
   __future__R    R!   R   R5   t   pprintR   t   IPython.coreR   t   IPython.core.releaseR   t   IPython.utils.sysinfoR   t   IPython.utils.py3compatR   R   RA   RI   t   objectR   RK   (    (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/crashhandler.pyt   <module>   s   ‚