Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handler_404(request):
raise NotFound("OK")
def _get_experiment(project, experiment_sequence):
try:
return Experiment.objects.get(project=project, sequence=experiment_sequence)
except (Experiment.DoesNotExist, ValidationError):
raise exceptions.NotFound('Experiment was not found')
@app.exception(NotFound)
async def not_found(request, exception):
return sanic.response.json({'error': 'Not found'}, 404)
async def precache_manifest(request, manifest_id):
path = os.path.join(
BASE_DIR, f"../client/dist/precache-manifest.{manifest_id}.js"
)
if os.path.exists(path):
return await file_stream(path)
else:
raise NotFound(f"{path} not found")
# Do early method checking
if match and method in route.methods:
break
else:
# Lastly, check against all regex routes that cannot be hashed
for route in self.routes_always_check:
match = route.pattern.match(url)
route_found |= match is not None
# Do early method checking
if match and method in route.methods:
break
else:
# Route was found but the methods didn't match
if route_found:
raise method_not_supported
raise NotFound("Requested URL {} not found".format(url))
kwargs = {
p.name: p.cast(value)
for value, p in zip(match.groups(1), route.parameters)
}
route_handler = route.handler
if hasattr(route_handler, "handlers"):
route_handler = route_handler.handlers[method]
return route_handler, [], kwargs, route.uri, route.name
@bp.exception(NotFound)
def returnNotFound (request, exception):
return fail(request.url + '没有找到', 404)
@app.exception(exceptions.NotFound)
async def ignore_404s(request, exception):
return response.text("Page not found: {}".format(request.url))
async def wrapper(request, *args, **kwargs):
user = await User.find_one(dict(name=kwargs["user"].lower()))
if not user:
raise exceptions.NotFound("User not found")
kwargs["user"] = user
return await handler(request, *args, **kwargs)
return wrapper
def _get(self, url, method):
# url "normalization", there is no strict slashes for mental sakeness
url = url.strip()
if url.count("/") > 1 and url[-1] == "/":
url = url[:-1] # yes, yes yes and yes! (:
route, middlewares, params = self._tree.get(url, method)
if route is self._tree.sentinel:
raise MethodNotSupported(
"Method {} not allowed for URL {}".format(method, url),
method=method,
allowed_methods=self.get_supported_methods(url),
)
elif route is None:
raise NotFound("Requested URL {} not found".format(url))
# ------------------------------------------------------------------- #
# code taken and adapted from the Sanic router
# ------------------------------------------------------------------- #
route_handler = route.handler
if hasattr(route_handler, "handlers"): # noqa
# W-W-WHY ?! I don't even know what this is or why is it here
route_handler = route_handler.handlers[method]
return route_handler, middlewares, params, route.uri