示例#1
0
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
示例#2
0
文件: test_dec.py 项目: B-Rich/webob
    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")
示例#3
0
    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')
示例#4
0
    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")
示例#5
0
 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)
示例#6
0
    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)]")))
示例#7
0
文件: test_dec.py 项目: Pylons/webob
    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)]")))
示例#8
0
文件: webapp.py 项目: jlehtnie/zuul
 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)
示例#9
0
    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)]")))
示例#10
0
 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)
示例#11
0
文件: test_dec.py 项目: dholth/webob
 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)
示例#12
0
 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)
示例#13
0
    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)]")))
示例#14
0
    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)
示例#15
0
文件: test_dec.py 项目: Pylons/webob
    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)]"))
        )
示例#16
0
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
示例#17
0
    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)]"))
        )
示例#18
0
文件: test_dec.py 项目: dholth/webob
 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')
示例#19
0
 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')
示例#20
0
    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")
示例#21
0
文件: test_dec.py 项目: B-Rich/webob
    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")
示例#22
0
 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)
示例#23
0
文件: test_dec.py 项目: dholth/webob
 def test_wsgify_empty_repr(self):
     self.assertEqual('%r' % (wsgify(),), 'wsgify()')
示例#24
0
 def test_wsgify_empty_repr(self):
     self.assertTrue('wsgify at' in repr(wsgify()))
示例#25
0
 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)
示例#26
0
 def test_wsgify_args_no_func(self):
     test_app = wsgify(None, args=(1, ))
     self.assertRaises(TypeError, self._testit, test_app, '/a url')
示例#27
0
 def decorator(view):
     view = wsgify(view)
     self.add_route(rule, controller=view, **options)
     return view
示例#28
0
 def test_wsgify_empty_repr(self):
     self.assertTrue('wsgify at' in repr(wsgify()))
示例#29
0
    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)
示例#30
0
 def wsgiapp(self):
     """Returns a wsgi application"""
     from webob.dec import wsgify
     return wsgify(self._handle_request)
示例#31
0
 def __init__(self, assets):
     super(Application, self).__init__()
     self.assets = assets
     self.add_url('top', '/', wsgify(views.index))
示例#32
0
 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')
示例#33
0
 def add_url(self, name, pattern, view):
     application = wsgify(view, RequestClass=MyRequest)
     super(WebObDispatcher, self).add_url(name, pattern, application)
示例#34
0
 def test_wsgify_args_no_func(self):
     test_app = wsgify(None, args=(1,))
     self.assertRaises(TypeError, self._testit, test_app, '/a url')
示例#35
0
 def wsgiapp(self):
     """Returns a wsgi application"""
     from webob.dec import wsgify
     return wsgify(self._handle_request)
示例#36
0
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':
示例#37
0
def make_application():

    return dec.wsgify(search.make_app())
示例#38
0
def make_application():

    return dec.wsgify(search.make_app())
 def load_app(self):
     return get_request_metrics(wsgify(app,
                                       args=(self.status_code,)))