Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_exception_repr(self):
exc = exceptions.NotFound()
self.assert_equal(str(exc), '404: Not Found')
self.assert_equal(repr(exc), "")
exc = exceptions.NotFound('Not There')
self.assert_equal(str(exc), '404: Not There')
self.assert_equal(repr(exc), "")
def test_trapping_of_all_http_exceptions(self):
app = flask.Flask(__name__)
app.testing = True
app.config['TRAP_HTTP_EXCEPTIONS'] = True
@app.route('/fail')
def fail():
flask.abort(404)
c = app.test_client()
try:
c.get('/fail')
except NotFound, e:
pass
else:
self.fail('Expected exception')
try:
f('../__init__.py')
except NotFound:
pass
else:
self.assert_true(0, 'expected exception')
# testcase for a security issue that may exist on windows systems
import os
import ntpath
old_path = os.path
os.path = ntpath
try:
try:
f('..\\__init__.py')
except NotFound:
pass
else:
self.assert_true(0, 'expected exception')
finally:
os.path = old_path
def _get_object_from_path(repo, tree, path):
path_segments = path.split("/")
ctree = tree
for i, path_seg in enumerate(path_segments):
if ctree.type != GIT_OBJ_TREE:
raise NotFound("invalid path; traversal unexpectedly encountered a non-tree")
if not path_seg and i == len(path_segments) - 1: # allow trailing slash in paths to directories
continue
try:
ctree = repo[ctree[path_seg].oid]
except KeyError:
raise NotFound("invalid path; no such object")
return ctree
"""
request = werkzeug.wrappers.Request(environ)
request.parameter_storage_class = werkzeug.datastructures.ImmutableDict
if request.path == '/':
params = urllib.urlencode(request.args)
return werkzeug.utils.redirect(self.root + '?' + params, 301)(
environ, start_response)
elif request.path == '/mobile' or ('#' in request.path):
return werkzeug.utils.redirect(
'/web_mobile/static/src/web_mobile.html', 301)(environ, start_response)
handler = self.find_handler(*(request.path.split('/')[1:]))
if not handler:
response = werkzeug.exceptions.NotFound()
else:
with session_context(request, self.session_storage, self.session_cookie) as session:
result = handler( request, self.config)
if isinstance(result, basestring):
headers=[('Content-Type', 'text/html; charset=utf-8'), ('Content-Length', len(result))]
response = werkzeug.wrappers.Response(result, headers=headers)
else:
response = result
if hasattr(response, 'set_cookie'):
response.set_cookie(self.session_cookie, session.sid)
return response(environ, start_response)
return render_template(
"data/summary.html",
metadata=recording_info,
youtube_query=_get_youtube_query(recording_info),
submission_count=submission_count,
position=offset + 1,
previous=offset - 1 if offset > 0 else None,
next=offset + 1 if offset < submission_count - 1 else None,
offset=offset,
data=summary_data,
)
elif recording_info:
return render_template("data/summary-missing.html", metadata=recording_info,
youtube_query=_get_youtube_query(recording_info)), 404
else: # Recording doesn't exist in MusicBrainz
raise NotFound(
"""MusicBrainz does not have data for this track.
If the recording has been recently added to MusicBrainz,
pages = (
Page.query
.filter_by(ghost='')
.order_by(ordering)
.paginate(page, 20, False)
)
try:
return render_template(
'akamatsu/dashboard/page/index.html',
pages=pages,
order_key=order_key,
order_dir=order_dir
)
except NotFound:
# Show a 'no pages found' notice instead of a 404 error
return render_template('akamatsu/dashboard/page/index.html')
web application for improved performance.
.. versionadded:: 0.5
:param directory: the directory where all the files are stored.
:param filename: the filename relative to that directory to
download.
:param options: optional keyword arguments that are directly
forwarded to :func:`send_file`.
"""
filename = safe_join(directory, filename)
if not os.path.isabs(filename):
filename = os.path.join(current_app.root_path, filename)
try:
if not os.path.isfile(filename):
raise NotFound()
except (TypeError, ValueError):
raise BadRequest()
options.setdefault('conditional', True)
return send_file(filename, **options)
redirect_url = rule.redirect_to(self, **rv)
raise RequestRedirect(str(url_join('%s://%s%s%s' % (
self.url_scheme or 'http',
self.subdomain and self.subdomain + '.' or '',
self.server_name,
self.script_name
), redirect_url)))
if return_rule:
return rule, rv
else:
return rule.endpoint, rv
if have_match_for:
raise MethodNotAllowed(valid_methods=list(have_match_for))
raise NotFound()
def to_python(self, value):
result = request.env[self.model].browse(
map(lambda x: x[0], request.env[self.model].sudo().name_search(
value.replace('+', ' '), operator='=ilike', limit=1)))
if not result:
raise werkzeug.exceptions.NotFound()
return result