Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.support.werkzeug.debug.DebuggedApplication Class Reference

List of all members.

Public Member Functions

def __init__
def debug_application
def execute_command
def display_console
def paste_traceback
def get_source
def get_resource
def __call__

Public Attributes

 app
 evalex
 frames
 tracebacks
 request_key
 console_path
 console_init_func
 show_hidden_frames

Detailed Description

Enables debugging support for a given application::

    from werkzeug.debug import DebuggedApplication
    from myapp import app
    app = DebuggedApplication(app, evalex=True)

The `evalex` keyword argument allows evaluating expressions in a
traceback's frame context.

:param app: the WSGI application to run debugged.
:param evalex: enable exception evaluation feature (interactive
               debugging).  This requires a non-forking server.
:param request_key: The key that points to the request object in ths
                    environment.  This parameter is ignored in current
                    versions.
:param console_path: the URL for a general purpose console.
:param console_init_func: the function that is executed before starting
                          the general purpose console.  The return value
                          is used as initial namespace.
:param show_hidden_frames: by default hidden traceback frames are skipped.
                           You can show them by setting this parameter
                           to `True`.

Definition at line 30 of file __init__.py.


Constructor & Destructor Documentation

def MoinMoin.support.werkzeug.debug.DebuggedApplication.__init__ (   self,
  app,
  evalex = False,
  request_key = 'werkzeug.request',
  console_path = '/console',
  console_init_func = None,
  show_hidden_frames = False 
)

Definition at line 57 of file __init__.py.

00057 
00058                  show_hidden_frames=False):
00059         if not console_init_func:
00060             console_init_func = dict
00061         self.app = app
00062         self.evalex = evalex
00063         self.frames = {}
00064         self.tracebacks = {}
00065         self.request_key = request_key
00066         self.console_path = console_path
00067         self.console_init_func = console_init_func
00068         self.show_hidden_frames = show_hidden_frames


Member Function Documentation

def MoinMoin.support.werkzeug.debug.DebuggedApplication.__call__ (   self,
  environ,
  start_response 
)
Dispatch the requests.

Definition at line 140 of file __init__.py.

00140 
00141     def __call__(self, environ, start_response):
00142         """Dispatch the requests."""
00143         # important: don't ever access a function here that reads the incoming
00144         # form data!  Otherwise the application won't have access to that data
00145         # any more!
00146         request = Request(environ)
00147         response = self.debug_application
00148         if self.evalex and self.console_path is not None and \
00149            request.path == self.console_path:
00150             response = self.display_console(request)
00151         elif request.path.rstrip('/').endswith('/__debugger__'):
00152             cmd = request.args.get('cmd')
00153             arg = request.args.get('f')
00154             traceback = self.tracebacks.get(request.args.get('tb', type=int))
00155             frame = self.frames.get(request.args.get('frm', type=int))
00156             if cmd == 'resource' and arg:
00157                 response = self.get_resource(request, arg)
00158             elif cmd == 'paste' and traceback is not None:
00159                 response = self.paste_traceback(request, traceback)
00160             elif cmd == 'source' and frame:
00161                 response = self.get_source(request, frame)
00162             elif self.evalex and cmd is not None and frame is not None:
00163                 response = self.execute_command(request, cmd, frame)
00164         return response(environ, start_response)

Here is the call graph for this function:

def MoinMoin.support.werkzeug.debug.DebuggedApplication.debug_application (   self,
  environ,
  start_response 
)
Run the application and conserve the traceback frames.

Definition at line 69 of file __init__.py.

00069 
00070     def debug_application(self, environ, start_response):
00071         """Run the application and conserve the traceback frames."""
00072         app_iter = None
00073         try:
00074             app_iter = self.app(environ, start_response)
00075             for item in app_iter:
00076                 yield item
00077             if hasattr(app_iter, 'close'):
00078                 app_iter.close()
00079         except:
00080             if hasattr(app_iter, 'close'):
00081                 app_iter.close()
00082             traceback = get_current_traceback(skip=1, show_hidden_frames=
00083                                               self.show_hidden_frames,
00084                                               ignore_system_exceptions=True)
00085             for frame in traceback.frames:
00086                 self.frames[frame.id] = frame
00087             self.tracebacks[traceback.id] = traceback
00088 
00089             try:
00090                 start_response('500 INTERNAL SERVER ERROR', [
00091                     ('Content-Type', 'text/html; charset=utf-8')
00092                 ])
00093             except:
00094                 # if we end up here there has been output but an error
00095                 # occurred.  in that situation we can do nothing fancy any
00096                 # more, better log something into the error log and fall
00097                 # back gracefully.
00098                 environ['wsgi.errors'].write(
00099                     'Debugging middleware catched exception in streamed '
00100                     'response at a point where response headers were already '
00101                     'sent.\n')
00102             else:
00103                 yield traceback.render_full(evalex=self.evalex) \
00104                                .encode('utf-8', 'replace')
00105 
00106             traceback.log(environ['wsgi.errors'])

Here is the call graph for this function:

Here is the caller graph for this function:

Display a standalone shell.

Definition at line 111 of file __init__.py.

00111 
00112     def display_console(self, request):
00113         """Display a standalone shell."""
00114         if 0 not in self.frames:
00115             self.frames[0] = _ConsoleFrame(self.console_init_func())
00116         return Response(render_template('console.html'), mimetype='text/html')

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.debug.DebuggedApplication.execute_command (   self,
  request,
  command,
  frame 
)
Execute a command in a console.

Definition at line 107 of file __init__.py.

00107 
00108     def execute_command(self, request, command, frame):
00109         """Execute a command in a console."""
00110         return Response(frame.console.eval(command), mimetype='text/html')

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.debug.DebuggedApplication.get_resource (   self,
  request,
  filename 
)
Return a static resource from the shared folder.

Definition at line 127 of file __init__.py.

00127 
00128     def get_resource(self, request, filename):
00129         """Return a static resource from the shared folder."""
00130         filename = join(dirname(__file__), 'shared', basename(filename))
00131         if isfile(filename):
00132             mimetype = mimetypes.guess_type(filename)[0] \
00133                 or 'application/octet-stream'
00134             f = file(filename, 'rb')
00135             try:
00136                 return Response(f.read(), mimetype=mimetype)
00137             finally:
00138                 f.close()
00139         return Response('Not Found', status=404)

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.debug.DebuggedApplication.get_source (   self,
  request,
  frame 
)
Render the source viewer.

Definition at line 123 of file __init__.py.

00123 
00124     def get_source(self, request, frame):
00125         """Render the source viewer."""
00126         return Response(frame.render_source(), mimetype='text/html')

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.debug.DebuggedApplication.paste_traceback (   self,
  request,
  traceback 
)
Paste the traceback and return a JSON response.

Definition at line 117 of file __init__.py.

00117 
00118     def paste_traceback(self, request, traceback):
00119         """Paste the traceback and return a JSON response."""
00120         paste_id = traceback.paste()
00121         return Response('{"url": "http://paste.pocoo.org/show/%s/", "id": %s}'
00122                         % (paste_id, paste_id), mimetype='application/json')

Here is the caller graph for this function:


Member Data Documentation

Definition at line 60 of file __init__.py.

Definition at line 66 of file __init__.py.

Definition at line 65 of file __init__.py.

Definition at line 61 of file __init__.py.

Definition at line 62 of file __init__.py.

Definition at line 64 of file __init__.py.

Definition at line 67 of file __init__.py.

Definition at line 63 of file __init__.py.


The documentation for this class was generated from the following file: