Ticket #15249: inline-debug.diff

File inline-debug.diff, 3.0 KB (added by Sameer Rahmani, 13 years ago)
  • django/conf/global_settings.py

     
    583583# Make sure to use a trailing slash.
    584584# Examples: "http://foo.com/static/admin/", "/static/admin/".
    585585ADMIN_MEDIA_PREFIX = '/static/admin/'
     586
     587# Run ipython or python interactive shell when
     588# an uncaught exception occure, if set to "interactive"
     589# run pdb debugger when an uncaught exception raised,
     590# if set to "pdb"
     591# any other value is not valid
     592
     593INLINE_DEBUGGER = None
  • django/core/handlers/base.py

     
    99logger = getLogger('django.request')
    1010
    1111
     12class WrongValue (Exception):
     13    pass
     14
     15
    1216class BaseHandler(object):
    1317    # Changes that are always applied to a response (in this order).
    1418    response_fixes = [
     
    199203            raise
    200204
    201205        if settings.DEBUG:
     206            # Run an interactive shell or pdb when an uncaught exception
     207            # raised. if INLINE_DEBUGGER defined.
     208            if not exc_info[0] == SyntaxError:
     209                if settings.INLINE_DEBUGGER:
     210                    if settings.INLINE_DEBUGGER == "interactive":
     211                        tbtmp = exc_info[-1]
     212                        tb = None
     213                        while tbtmp:
     214                            tbtmp = tbtmp.tb_next
     215                            if tbtmp is not None:
     216                                tb = tbtmp
     217                        import traceback
     218                        print
     219                        traceback.print_exception(*exc_info)
     220
     221                        try:
     222                            from IPython import Shell
     223                            ipshell = Shell.start()
     224                            ipshell.IP.api.to_user_ns(tb.tb_frame.f_locals)
     225                            ipshell.IP.api.to_user_ns(tb.tb_frame.f_globals)
     226                            ipshell.mainloop()
     227
     228                        except ImportError:
     229                            import code
     230                            shell = code.InteractiveConsole(tb.tb_frame.f_locals)
     231                            shell.interact()
     232
     233                    elif settings.INLINE_DEBUGGER == "pdb":
     234                        import pdb
     235                        import traceback
     236                        print
     237                        traceback.print_exception(*exc_info)
     238                        pdb.post_mortem(exc_info[-1])
     239                    else:
     240                        exception = WrongValue("'%s'is invalid value for'setting.INLINE_DEBUGGER'. Use 'pdb' or 'interactive' instead." % \
     241                                               settings.INLINE_DEBUGGER)
     242                        exc_info = (type(exception), exception, None)
     243
     244
    202245            from django.views import debug
    203246            return debug.technical_500_response(request, *exc_info)
    204247
Back to Top