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_renders_404_with_csp(self, pyramid_config):
renderer = pyramid_config.testing_add_renderer("404.html")
csp = {}
services = {"csp": pretend.stub(merge=csp.update)}
context = HTTPNotFound()
request = pretend.stub(find_service=lambda name: services[name], path="")
response = httpexception_view(context, request)
assert response.status_code == 404
assert response.status == "404 Not Found"
assert csp == {
"frame-src": ["https://www.youtube-nocookie.com"],
"script-src": ["https://www.youtube.com", "https://s.ytimg.com"],
}
renderer.assert_()
def response_error(context, request):
if context.response.status_code == 404:
error_msg = "Handled in tests/testapp/views.py"
return httpexceptions.HTTPNotFound(body=error_msg)
raise context
.order_by(expr.desc(func.sum(PlayerGameStat.score)))\
.group_by(Player.nick)\
.group_by(Player.player_id)
if self.last:
top_scorers_q = top_scorers_q.offset(self.last)
if self.limit:
top_scorers_q = top_scorers_q.limit(self.limit)
top_scorers = top_scorers_q.all()
return top_scorers
except Exception as e:
log.debug(e)
raise HTTPNotFound
def object_exists_or_404(request, resource_name, object_id, parent_id=""):
storage = request.registry.storage
try:
return storage.get(resource_name=resource_name, parent_id=parent_id, object_id=object_id)
except exceptions.ObjectNotFoundError:
# XXX: We gave up putting details about parent id here (See #53).
details = {"id": object_id, "resource_name": resource_name}
response = http_error(HTTPNotFound(), errno=ERRORS.MISSING_RESOURCE, details=details)
raise response
def user_view(request):
login = request.matchdict['login']
user = USERS.get(login)
if not user:
raise HTTPNotFound()
pages = [p for (t, p) in PAGES.items() if p.owner == login]
return {
'user': user,
'pages': pages,
}
def check_annotation_enabled(request):
if not request.env.webmap.settings['annotation']:
raise HTTPNotFound()
def add_page(request):
"""
Add a page to the database
:param request: a request object
:return: a redirect to the translation_read URL
"""
if request.authenticated_userid is None:
raise exc.HTTPNotFound()
name = request.matchdict["language_name"]
page_id = urllib.unquote(urllib.unquote(request.matchdict["page_url"]))
public_group_id = request.matchdict["public_group_id"]
language = annotran.languages.models.Language.get_by_name(name)
page = annotran.pages.models.Page.get_by_uri(page_id)
if not page:
page = annotran.pages.models.Page(uri=page_id)
request.db.add(page)
request.db.flush()
url = request.route_url('translation_read', public_language_id=language.pubid, public_group_id=public_group_id)
return exc.HTTPSeeOther(url)
package = self.context
root = package.root
if self.repository is not root:
self.repository.name = root.name
rfiles = [
rfile for rel in self.repository[package.name]
for rfile in rel
]
context = {
'objects': (self.format_release_file(rfile) for rfile in rfiles)
}
transaction.abort()
if len(rfiles):
return context
elif self.stop:
return HTTPNotFound()
else:
return not_found(self.request)
def test_error_view(request):
ctx = get_default_context(request)
tp = request.matchdict.get('type', None)
if not tp:
return HTTPNotFound()
tp = tp[0]
from pyramid_jinja2 import IJinja2Environment
jinja_env = request.registry.queryUtility(
IJinja2Environment, name='.jinja2')
if tp == 'unauthorized':
template = jinja_env.get_template('react_unauthorized.jinja2')
body = template.render(ctx)
return Response(body, 401)
slug=slug).first()
if not discussion:
raise HTTPNotFound("No discussion named %s" % (slug,))
return discussion
if getattr(request, "context", None) and isinstance(
request.context, TraversalContext):
discussion_id = request.context.get_discussion_id()
if discussion_id:
return Discussion.get(discussion_id)
if request.session.get("discussion", None):
slug = request.session["discussion"]
session = get_session_maker()()
discussion = session.query(Discussion).filter_by(
slug=slug).first()
if not discussion:
raise HTTPNotFound("No discussion named %s" % (slug,))
return discussion