Python web 模块,notfound() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用web.notfound()

项目:jd-crawler    作者:qiaofei32    | 项目源码 | 文件源码
def GET(self, *args):
        dir, name = args[-2:]
        dir_path = 'templates/%s/' %dir
        ext = name.split(".")[-1]
        cType = {
            "css": "text/css",
            "png": "images/png",
            "jpg": "images/jpeg",
            "gif": "images/gif",
            "ico": "images/x-icon",
            "js" : "text/javascrip",
        }
        if name in os.listdir(dir_path):
            web.header("Content-Type", cType[ext])
            file_path = '%s/%s' %(dir_path, name)
            return open(file_path, "rb").read()
        else:
            raise web.notfound()
项目:py-script    作者:xiaoxiamin    | 项目源码 | 文件源码
def testUnload(self):
        x = web.storage(a=0)

        urls = (
            "/foo", "foo",
            "/bar", "bar"
        )
        class foo:
            def GET(self):
                return "foo"
        class bar:
            def GET(self):
                raise web.notfound()

        app = web.application(urls, locals())
        def unload():
            x.a += 1
        app.add_processor(web.unloadhook(unload))

        app.request('/foo')
        self.assertEquals(x.a, 1)

        app.request('/bar')
        self.assertEquals(x.a, 2)
项目:jd-crawler    作者:qiaofei32    | 项目源码 | 文件源码
def notfound():
    return web.notfound("Sorry, the page you were looking for was not found.")
项目:Desert-Fireball-Maintainence-GUI    作者:CPedersen3245    | 项目源码 | 文件源码
def not_found():
    return web.notfound("The requested file(s) could not be found.")
项目:webapi    作者:IntPassion    | 项目源码 | 文件源码
def notfound():
    return web.notfound("Sorry, the page you were looking for was not found.")

    # You can use template result like below, either is ok:
    #return web.notfound(render.notfound())
    #return web.notfound(str(render.notfound()))
项目:layman    作者:CCSS-CZ    | 项目源码 | 文件源码
def _setReturnCode(self, code):
        """Set the return code

        :param: code
        :type code: integer or string
        returns success: [True|False]
        """
        success = False

        if code in (200, "200", "ok"):
            web.ok()
            success = True
        elif code in (201, "201", "created"):
            web.created()
            success = True
        elif code in (400, "400", "badrequest"):
            web.badrequest()
        elif code in (401, "401", "unauthorized"):
            web.unauthorized()
        elif code in (404, "404", "notfound"):
            web.notfound()
        elif code in (409, "409", "conflict"):
            web.conflict()
        elif code in (500, "500", "internalerror"):
            web.internalerror()
        elif code in (501, "501", "notimplemented"):
            # web.notimplemented() # not implemented
            # TODO - set 501 code manually
            web.internalerror()

        if success:
            logging.debug("[LayMan][_setReturnCode] Code: '%s'" % code)
        else:
            logging.error("[LayMan][_setReturnCode] Code: '%s'" % code)

        return success
项目:smartthings-monitor    作者:CNG    | 项目源码 | 文件源码
def notfound():
    """Handle 404 not found errors.

    Requires `app.notfound = notfound` following definition.
    """

    return web.notfound(render.error(404))
项目:py-script    作者:xiaoxiamin    | 项目源码 | 文件源码
def testCustomNotFound(self):
        urls_a = ("/", "a")
        urls_b = ("/", "b")

        app_a = web.application(urls_a, locals())
        app_b = web.application(urls_b, locals())

        app_a.notfound = lambda: web.HTTPError("404 Not Found", {}, "not found 1")

        urls = (
            "/a", app_a,
            "/b", app_b
        )
        app = web.application(urls, locals())

        def assert_notfound(path, message):
            response = app.request(path)
            self.assertEquals(response.status.split()[0], "404")
            self.assertEquals(response.data, message)

        assert_notfound("/a/foo", "not found 1")
        assert_notfound("/b/foo", "not found")

        app.notfound = lambda: web.HTTPError("404 Not Found", {}, "not found 2")
        assert_notfound("/a/foo", "not found 1")
        assert_notfound("/b/foo", "not found 2")
项目:optf2    作者:Lagg    | 项目源码 | 文件源码
def notfound():
    return web.notfound(template.errors.generic("The page you were looking for couldn't be found."))
项目:opennumber    作者:opennumber    | 项目源码 | 文件源码
def handler_notfound():
    return web.notfound("page not found")
项目:optf2    作者:Lagg    | 项目源码 | 文件源码
def main():
    """ Main setup function """

    def urlr(exp):
        return virtual_root + exp + "/*"

    # Redirect workarounds if enabled
    if config.ini.getboolean("cgi", "redirect-workaround"):
        os.environ["SCRIPT_NAME"] = ''
        os.environ["REAL_SCRIPT_NAME"] = ''

    web.config.debug = config.ini.getboolean("cgi", "web-debug-mode")
    web.config.session_parameters["timeout"] = config.ini.getint("http", "session-timeout")
    web.config.session_parameters["cookie_name"] = config.ini.get("http", "session-cookie-name")

    if config.ini.getboolean("cgi", "fastcgi"):
        web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)

    steam.api.key.set(config.ini.get("steam", "api-key"))

    # Cache file stuff
    cache_dir = config.ini.get("resources", "cache-dir")
    if not os.path.exists(cache_dir):
        os.makedirs(cache_dir)

    urls = (
        virtual_root + "api", api_views.subapplication,
        urlr("inv/(?:user/)?(.+)"), "optf2.inventory_views.sim_selector",
        urlr(""), "optf2.views.index",
        urlr("about"), "optf2.views.about",
        urlr("(\w+)/items"), "optf2.schema_views.items",
        urlr("(\w+)/attributes/?(\d*)"), "optf2.schema_views.attributes",
        urlr("(\w+)/particles"), "optf2.schema_views.particles",
        urlr("(\w+)/item/(-?\d+)"), "optf2.inventory_views.item",
        urlr("(\w+)/item/(\w+)/(-?\d+)"), "optf2.inventory_views.live_item",
        urlr("(\w+)/loadout/(\w+)/?(\d*)"), "optf2.inventory_views.loadout",
        urlr("(\w+)/feed/(.+)"), "optf2.inventory_views.feed",
        urlr("(\w+)/(?:user/)?(.+)"), "optf2.inventory_views.fetch"
        )

    application = web.application(urls, globals())

    application.notfound = notfound
    if not config.ini.getboolean("cgi", "web-debug-mode"):
        application.internalerror = internalerror

    application.add_processor(web.loadhook(lang_hook))
    application.add_processor(web.loadhook(motd_hook))
    application.add_processor(web.loadhook(conf_hook))

    return application