本文整理汇总了Python中klein.Klein.execute_endpoint方法的典型用法代码示例。如果您正苦于以下问题:Python Klein.execute_endpoint方法的具体用法?Python Klein.execute_endpoint怎么用?Python Klein.execute_endpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类klein.Klein
的用法示例。
在下文中一共展示了Klein.execute_endpoint方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stackedRoute
# 需要导入模块: from klein import Klein [as 别名]
# 或者: from klein.Klein import execute_endpoint [as 别名]
def test_stackedRoute(self):
"""
L{Klein.route} can be stacked to create multiple endpoints of
a single function.
"""
app = Klein()
@app.route("/foo")
@app.route("/bar", endpoint="bar")
def foobar(request):
return "foobar"
self.assertEqual(len(app.endpoints), 2)
c = app.url_map.bind("foo")
self.assertEqual(c.match("/foo"), ("foobar", {}))
self.assertEqual(app.execute_endpoint("foobar", DummyRequest(1)), "foobar")
self.assertEqual(c.match("/bar"), ("bar", {}))
self.assertEqual(app.execute_endpoint("bar", DummyRequest(2)), "foobar")
示例2: test_route
# 需要导入模块: from klein import Klein [as 别名]
# 或者: from klein.Klein import execute_endpoint [as 别名]
def test_route(self):
"""
L{Klein.route} adds functions as routable endpoints.
"""
app = Klein()
@app.route("/foo")
def foo(request):
return "foo"
c = app.url_map.bind("foo")
self.assertEqual(c.match("/foo"), ("foo", {}))
self.assertEqual(len(app.endpoints), 1)
self.assertEqual(app.execute_endpoint("foo", DummyRequest(1)), "foo")
示例3: test_submountedRoute
# 需要导入模块: from klein import Klein [as 别名]
# 或者: from klein.Klein import execute_endpoint [as 别名]
def test_submountedRoute(self):
"""
L{Klein.subroute} adds functions as routable endpoints.
"""
app = Klein()
with app.subroute("/sub") as app:
@app.route("/prefixed_uri")
def foo_endpoint(request):
return b"foo"
c = app.url_map.bind("sub/prefixed_uri")
self.assertEqual(
c.match("/sub/prefixed_uri"), ("foo_endpoint", {}))
self.assertEqual(
len(app.endpoints), 1)
self.assertEqual(
app.execute_endpoint("foo_endpoint", DummyRequest(1)), b"foo")
示例4: test_copy
# 需要导入模块: from klein import Klein [as 别名]
# 或者: from klein.Klein import execute_endpoint [as 别名]
def test_copy(self):
"""
L{Klein.__copy__} returns a new L{Klein} with all the registered endpoints
"""
app = Klein()
@app.route("/foo")
def foo(request):
return "foo"
app_copy = copy.copy(app)
@app.route('/bar')
def bar(request):
return 'bar'
dr1 = DummyRequest(1)
dr2 = DummyRequest(2)
dr3 = DummyRequest(3)
self.assertEquals(app.execute_endpoint('foo', dr1), 'foo')
self.assertEquals(app.execute_endpoint('bar', dr2), 'bar')
self.assertRaises(KeyError, app_copy.execute_endpoint, 'bar', dr3)