def test_full_pipeline(): app = Application(mock_endpoint, extensions=[DebugExtension()]) req = Request.blank('/') response = req.get_response(app) assert response.status_int == 500 assert 'by zero' in response.text
def test_debug_extension_console(): ext = DebugExtension() req = Request.blank('/__console__') ctx = Context() app = ext(ctx, mock_app) response = req.get_response(app) assert 'debugger.js' in response.text
def test_inline_console(): ctx = Context() ctx.request = Request.blank('/') ext = DebugExtension() ext(ctx, mock_app) con = Console(ctx) result = con() assert 'CONSOLE_MODE = true' in result.text
def test_debug_extension_catches(): ext = DebugExtension() req = Request.blank('/') ctx = Context() app = ext(ctx, mock_app) response = req.get_response(app) assert 'CONSOLE_MODE = false' in response.text assert 'by zero' in response.text
value = String(default=None) class Root(object): def __init__(self, context): self._ctx = context def get(self): return repr(self._ctx.session.__data__) def set(self, value): self._ctx.session.value = value return "OK" app = Application( Root, extensions=[ DebugExtension(), DatabaseExtension( session=MongoDBConnection('mongodb://localhost/test')), SessionExtension( secret='xyzzy', expires=24 * 90, default=MongoSession(Session, database='session'), ), ]) if __name__ == "__main__": app.serve('wsgiref', host='0.0.0.0', port=8080)
from web.ext.annotation import AnnotationExtension # Built-in to WebCore. from web.ext.debug import DebugExtension from web.ext.serialize import SerializationExtension # New in 2.0.3! from web.ext.db import DatabaseExtension # From external dependency: web.db # Get a reference to our database connection adapter. from web.db.mongo import MongoDBConnection # From extenral dependency: marrow.mongo # Get a reference to our Wiki root object. from web.app.wiki.root import Wiki # This is our WSGI application instance. app = Application( Wiki, extensions=[ # Extensions that are always enabled. AnnotationExtension( ), # Allows us to use Python 3 function annotations. SerializationExtension( ), # Allows the return of mappings from endpoints, transformed to JSON. DatabaseExtension(MongoDBConnection("mongodb://localhost/test")), ] + ([ # Extensions that are only enabled in development or testing environments. DebugExtension( ) # Interactive traceback debugger, but gives remote code execution access. ] if __debug__ else [])) # If we're run as the "main script", serve our application over HTTP. if __name__ == "__main__": app.serve('wsgiref')
def serve(root): Application(root, extensions=[DebugExtension()]).serve('waitress')
# encoding: utf-8 """A one-function WebCore 2 demonstration application. Applications can be as simple or as complex and layered as your needs dictate. """ def basic(context, name="world"): 1 / 0 return "Hello {name}.".format(name=name) if __name__ == '__main__': from web.core import Application from web.ext.debug import DebugExtension Application(basic, extensions=[DebugExtension()]).serve('waitress')