def setup_request_environment(request): pyramid_request = pyramid.testing.DummyRequest() pyramid_request.set_property(middleware.pg_connection_request_property, name='pg_connection', reify=True) pyramid_request.set_property(middleware.userid_request_property, name='userid', reify=True) pyramid_request.web_input = middleware.web_input_request_method pyramid_request.environ['HTTP_X_FORWARDED_FOR'] = '127.0.0.1' pyramid_request.client_addr = '127.0.0.1' setup_routes_and_views(pyramid.testing.setUp(request=pyramid_request)) def tear_down(): pyramid_request.pg_connection.close() pyramid.testing.tearDown() request.addfinalizer(tear_down)
config.add_tween("weasyl.middleware.session_tween_factory") config.add_tween("weasyl.middleware.db_timer_tween_factory") config.add_tween("weasyl.middleware.cache_clear_tween_factory") config.add_tween("pyramid.tweens.excview_tween_factory") # Required to catch exceptions thrown in tweens. # Set up some exception handling and all our views. def weasyl_404(request): userid = d.get_userid() return Response(d.errorpage(userid, "**404!** The page you requested could not be found."), status="404 Not Found") config.add_notfound_view(view=weasyl_404, append_slash=True) config.add_view(view=mw.weasyl_exception_view, context=Exception) setup_routes_and_views(config) # Setup properties and methods for request objects. config.add_request_method(mw.pg_connection_request_property, name='pg_connection', reify=True) config.add_request_method(mw.userid_request_property, name='userid', reify=True) config.add_request_method(mw.log_exc_request_method, name='log_exc') config.add_request_method(mw.web_input_request_method, name='web_input') config.add_request_method(mw.set_cookie_on_response) config.add_request_method(mw.delete_cookie_on_response) wsgi_app = config.make_wsgi_app() wsgi_app = mw.InputWrapMiddleware(wsgi_app) wsgi_app = mw.URLSchemeFixingMiddleware(wsgi_app) if d.config_read_bool('profile_responses', section='backend'):
config.add_tween("pyramid.tweens.excview_tween_factory" ) # Required to catch exceptions thrown in tweens. # Set up some exception handling and all our views. def weasyl_404(request): userid = d.get_userid() return Response(d.errorpage( userid, "**404!** The page you requested could not be found."), status="404 Not Found") config.add_notfound_view(view=weasyl_404, append_slash=True) config.add_view(view=mw.weasyl_exception_view, context=Exception) setup_routes_and_views(config) # Setup properties and methods for request objects. config.add_request_method(mw.pg_connection_request_property, name='pg_connection', reify=True) config.add_request_method(mw.userid_request_property, name='userid', reify=True) config.add_request_method(mw.log_exc_request_method, name='log_exc') config.add_request_method(mw.web_input_request_method, name='web_input') config.add_request_method(mw.set_cookie_on_response) config.add_request_method(mw.delete_cookie_on_response) wsgi_app = config.make_wsgi_app() wsgi_app = mw.InputWrapMiddleware(wsgi_app)