def make_application(skype, options): dispatcher = webdispatch.URLDispatcher() dispatcher.add_url("main", "/", dec.wsgify(main.Main(skype))) dispatcher.add_url("chatlist", "/chats/", dec.wsgify(chat.ChatList(skype))) dispatcher.add_url("chat", "/chats/*", dec.wsgify(chat.Chat(skype))) return dispatcher
def test_wsgify_app_returns_unicode(self): def test_app(req): return text_("some text") test_app = wsgify(test_app) resp = self._testit(test_app, "/a url") self.assertEqual(resp.body, b"some text")
def test_wsgify_app_returns_unicode(self): def test_app(req): return text_('some text') test_app = wsgify(test_app) resp = self._testit(test_app, '/a url') self.assertEqual(resp.body, b'some text')
def __init__(self, nodepool, port=8005, cache_expiry=1): threading.Thread.__init__(self) self.nodepool = nodepool self.port = port self.cache = Cache(cache_expiry) self.cache_expiry = cache_expiry self.daemon = True self.server = httpserver.serve(dec.wsgify(self.app), host='0.0.0.0', port=self.port, start_loop=False)
def test_wsgify_call_args_override(self): resp_str = "args: %s, kwargs: %s" def show_vars(req, *args, **kwargs): return bytes_(resp_str % (sorted(args), sorted(kwargs.items()))) app = wsgify(show_vars, args=("foo", "bar"), kwargs={"a": 1, "b": 2}) resp = app(Request.blank("/"), "qux", c=3) self.assertEqual(resp, bytes_(resp_str % ("['qux']", "[('c', 3)]")))
def __init__(self, scheduler, port=8001, cache_expiry=1): threading.Thread.__init__(self) self.scheduler = scheduler self.port = port self.cache_expiry = cache_expiry self.cache_time = 0 self.cache = None self.daemon = True self.server = httpserver.serve(dec.wsgify(self.app), host='0.0.0.0', port=self.port, start_loop=False)
def test_wsgify_call_args_override(self): resp_str = "args: %s, kwargs: %s" def show_vars(req, *args, **kwargs): return bytes_(resp_str % (sorted(args), sorted(kwargs.items()))) app = wsgify(show_vars, args=('foo', 'bar'), kwargs={'a': 1, 'b': 2}) resp = app(Request.blank('/'), 'qux', c=3) self.assertEqual(resp, bytes_(resp_str % ("['qux']", "[('c', 3)]")))
def test_wsgify_no___get__(self): # use a class instance instead of a fn so we wrap something w/ # no __get__ class TestApp(object): def __call__(self, req): return 'nothing to see here' test_app = wsgify(TestApp()) resp = self._testit(test_app, '/a url') self.assertEqual(resp.body, b'nothing to see here') self.assertTrue(test_app.__get__(test_app) is test_app)
def test_wsgify_no___get__(self): # use a class instance instead of a fn so we wrap something w/ # no __get__ class TestApp(object): def __call__(self, req): return 'nothing to see here' test_app = wsgify(TestApp()) resp = self._testit(test_app, '/a url') self.assertEqual(resp.body, 'nothing to see here') self.assert_(test_app.__get__(test_app) is test_app)
def test_wsgify_no___get__(self): # use a class instance instead of a fn so we wrap something w/ # no __get__ class TestApp: def __call__(self, req): return "nothing to see here" test_app = wsgify(TestApp()) resp = self._testit(test_app, "/a url") self.assertEqual(resp.body, b"nothing to see here") self.assertTrue(test_app.__get__(test_app) is test_app)
def test_wsgify_call_args(self): resp_str = "args: %s, kwargs: %s" def show_vars(req, *args, **kwargs): return bytes_(resp_str % (sorted(args), sorted(kwargs.items()))) app = wsgify(show_vars, args=("foo", "bar"), kwargs={"a": 1, "b": 2}) resp = app(Request.blank("/")) self.assertEqual( resp, bytes_(resp_str % ("['bar', 'foo']", "[('a', 1), ('b', 2)]")) )
def load_controller(string): module_name, func_name = string.split(':', 1) if module_name: __import__(module_name) else: file_path = sys._getframe(2).f_code.co_filename.replace('.py', '') module_name = os.path.basename(file_path) __import__(module_name) module = sys.modules[module_name] func = getattr(module, func_name) func = wsgify(func) return func
def test_classapp(self): class HostMap(dict): @wsgify def __call__(self, req): return self[req.host.split(':')[0]] app = HostMap() app['example.com'] = Response('1') app['other.com'] = Response('2') resp = Request.blank('http://example.com/').get_response(wsgify(app)) self.assertEqual(resp.content_type, 'text/html') self.assertEqual(resp.charset, 'UTF-8') self.assertEqual(resp.content_length, 1) self.assertEqual(resp.body, '1')
def test_classapp(self): class HostMap(dict): @wsgify def __call__(self, req): return self[req.host.split(':')[0]] app = HostMap() app['example.com'] = Response('1') app['other.com'] = Response('2') resp = Request.blank('http://example.com/').get_response(wsgify(app)) self.assertEqual(resp.content_type, 'text/html') self.assertEqual(resp.charset, 'UTF-8') self.assertEqual(resp.content_length, 1) self.assertEqual(resp.body, b'1')
def test_classapp(self): class HostMap(dict): @wsgify def __call__(self, req): return self[req.host.split(":")[0]] app = HostMap() app["example.com"] = Response("1") app["other.com"] = Response("2") resp = Request.blank("http://example.com/").get_response(wsgify(app)) self.assertEqual(resp.content_type, "text/html") self.assertEqual(resp.charset, "UTF-8") self.assertEqual(resp.content_length, 1) self.assertEqual(resp.body, b"1")
def __init__(self, scheduler, port=8001, cache_expiry=1, listen_address='0.0.0.0'): threading.Thread.__init__(self) self.scheduler = scheduler self.listen_address = listen_address self.port = port self.cache_expiry = cache_expiry self.cache_time = 0 self.cache = None self.daemon = True self.routes = {} self._init_default_routes() self.server = httpserver.serve(dec.wsgify(self.app), host=self.listen_address, port=self.port, start_loop=False)
def test_wsgify_empty_repr(self): self.assertEqual('%r' % (wsgify(),), 'wsgify()')
def test_wsgify_empty_repr(self): self.assertTrue('wsgify at' in repr(wsgify()))
def test_wsgify_undecorated(self): def test_app(req): return Response('whoa') wrapped_test_app = wsgify(test_app) self.assertTrue(wrapped_test_app.undecorated is test_app)
def test_wsgify_args_no_func(self): test_app = wsgify(None, args=(1, )) self.assertRaises(TypeError, self._testit, test_app, '/a url')
def decorator(view): view = wsgify(view) self.add_route(rule, controller=view, **options) return view
def wsgiapp(self): """Returns a wsgi application""" from webob.dec import wsgify return wsgify(self._handle_request)
def __init__(self, assets): super(Application, self).__init__() self.assets = assets self.add_url('top', '/', wsgify(views.index))
def add_url(self, name, pattern, view): application = wsgify(view, RequestClass=MyRequest) super(WebObDispatcher, self).add_url(name, pattern, application)
def test_wsgify_args_no_func(self): test_app = wsgify(None, args=(1,)) self.assertRaises(TypeError, self._testit, test_app, '/a url')
from webob import Response from webob.dec import wsgify from weiwei.bundler import bundle_decorators from weiwei.request import Request from weiwei.web import schema as web_schema from weiwei.web import models as web_models from weiwei.web import views as web_views from weiwei.web.page import apply_page_resource @bundle_decorators( wsgify(RequestClass=Request), ) def login_dispatch(request): return web_views.login_view(request) @bundle_decorators( wsgify(RequestClass=Request), apply_page_resource, ) def page_dispatch(request): if request.method == 'GET': if request.GET.get('edit') is not None: return web_views.page_edit_view(request) elif request.page: return web_views.page_view(request) else: return web_views.page_not_found_view(request) elif request.method == 'POST':
def make_application(): return dec.wsgify(search.make_app())
def load_app(self): return get_request_metrics(wsgify(app, args=(self.status_code,)))