def test_unbound_middleware_no_app(self): unbound = wsgify.middleware(None, None) from webob.dec import _UnboundMiddleware self.assert_(unbound.__class__ is _UnboundMiddleware) self.assertEqual(unbound.kw, dict()) self.assertEqual('%r' % (unbound,), "wsgify.middleware()")
def test_unbound_middleware(self): @wsgify def test_app(req): return Response('Say wha!?') unbound = wsgify.middleware(None, test_app, some='thing') from webob.dec import _UnboundMiddleware self.assertTrue(unbound.__class__ is _UnboundMiddleware) self.assertEqual(unbound.kw, dict(some='thing')) @unbound def middle(req, app, **kw): return app(req) self.assertTrue(middle.__class__ is wsgify) self.assertTrue('test_app' in repr(unbound))
def test_unbound_middleware(self): @wsgify def test_app(req): return Response('Say wha!?') unbound = wsgify.middleware(None, test_app, some='thing') from webob.dec import _UnboundMiddleware self.assert_(unbound.__class__ is _UnboundMiddleware) self.assertEqual(unbound.kw, dict(some='thing')) self.assertEqual('%r' % (unbound,), "wsgify.middleware(wsgify(tests.test_dec.test_app), " "some='thing')") @unbound def middle(req, app, **kw): return app(req) self.assert_(middle.__class__ is wsgify) self.assertEqual('%r' % (middle,), "wsgify.middleware(tests.test_dec.middle)" "(wsgify(tests.test_dec.test_app), some='thing')")
#: Usage:: #: #: from your_app import wsgi_app #: #: wsgi_app = user_agent_middleware(wsgi_app) #: #: For example, in Flask, the middleware can be applied like this:: #: #: from flask import Flask #: #: app = Flask(__name__) #: app.wsgi_app = user_agent_middleware(app) #: #: app.run() #: #: In Django, you can apply the middleware like this:: #: #: from django.core.wsgi import get_wsgi_application #: #: application = user_agent_middleware(get_wsgi_application()) #: #: For more information see #: `Django docs <https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/>`_. #: #: .. warning:: #: #: The middleware slows down requests by calling :meth:`time.sleep()` #: (in the time frame when requests with invalid user-agent are being delayed). #: This can increase worker busyness which can overload a service. user_agent_middleware = wsgify.middleware(_validate_user_agent)