當前位置: 首頁>>代碼示例>>Python>>正文


Python UrlDispatcher.add_patch方法代碼示例

本文整理匯總了Python中aiohttp.web.UrlDispatcher.add_patch方法的典型用法代碼示例。如果您正苦於以下問題:Python UrlDispatcher.add_patch方法的具體用法?Python UrlDispatcher.add_patch怎麽用?Python UrlDispatcher.add_patch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在aiohttp.web.UrlDispatcher的用法示例。


在下文中一共展示了UrlDispatcher.add_patch方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestUrlDispatcher

# 需要導入模塊: from aiohttp.web import UrlDispatcher [as 別名]
# 或者: from aiohttp.web.UrlDispatcher import add_patch [as 別名]

#.........這裏部分代碼省略.........
        self.assertIs(handler, info.handler)
        self.assertIsNone(info.route.name)

    def test_add_route_with_add_get_shortcut(self):
        handler = self.make_handler()
        self.router.add_get('/handler/to/path', handler)
        req = self.make_request('GET', '/handler/to/path')
        info = self.loop.run_until_complete(self.router.resolve(req))
        self.assertIsNotNone(info)
        self.assertEqual(0, len(info))
        self.assertIs(handler, info.handler)
        self.assertIsNone(info.route.name)

    def test_add_route_with_add_post_shortcut(self):
        handler = self.make_handler()
        self.router.add_post('/handler/to/path', handler)
        req = self.make_request('POST', '/handler/to/path')
        info = self.loop.run_until_complete(self.router.resolve(req))
        self.assertIsNotNone(info)
        self.assertEqual(0, len(info))
        self.assertIs(handler, info.handler)
        self.assertIsNone(info.route.name)

    def test_add_route_with_add_put_shortcut(self):
        handler = self.make_handler()
        self.router.add_put('/handler/to/path', handler)
        req = self.make_request('PUT', '/handler/to/path')
        info = self.loop.run_until_complete(self.router.resolve(req))
        self.assertIsNotNone(info)
        self.assertEqual(0, len(info))
        self.assertIs(handler, info.handler)
        self.assertIsNone(info.route.name)

    def test_add_route_with_add_patch_shortcut(self):
        handler = self.make_handler()
        self.router.add_patch('/handler/to/path', handler)
        req = self.make_request('PATCH', '/handler/to/path')
        info = self.loop.run_until_complete(self.router.resolve(req))
        self.assertIsNotNone(info)
        self.assertEqual(0, len(info))
        self.assertIs(handler, info.handler)
        self.assertIsNone(info.route.name)

    def test_add_route_with_add_delete_shortcut(self):
        handler = self.make_handler()
        self.router.add_delete('/handler/to/path', handler)
        req = self.make_request('DELETE', '/handler/to/path')
        info = self.loop.run_until_complete(self.router.resolve(req))
        self.assertIsNotNone(info)
        self.assertEqual(0, len(info))
        self.assertIs(handler, info.handler)
        self.assertIsNone(info.route.name)

    def test_add_with_name(self):
        handler = self.make_handler()
        self.router.add_route('GET', '/handler/to/path', handler,
                              name='name')
        req = self.make_request('GET', '/handler/to/path')
        info = self.loop.run_until_complete(self.router.resolve(req))
        self.assertIsNotNone(info)
        self.assertEqual('name', info.route.name)

    def test_add_with_tailing_slash(self):
        handler = self.make_handler()
        self.router.add_route('GET', '/handler/to/path/', handler)
        req = self.make_request('GET', '/handler/to/path/')
開發者ID:drgarcia1986,項目名稱:aiohttp,代碼行數:70,代碼來源:test_urldispatch.py


注:本文中的aiohttp.web.UrlDispatcher.add_patch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。