Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/pyramid/exceptions.py : 52%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from pyramid.httpexceptions import HTTPBadRequest, HTTPNotFound, HTTPForbidden
3NotFound = HTTPNotFound # bw compat
4Forbidden = HTTPForbidden # bw compat
7class BadCSRFOrigin(HTTPBadRequest):
8 """
9 This exception indicates the request has failed cross-site request forgery
10 origin validation.
11 """
13 title = "Bad CSRF Origin"
14 explanation = (
15 "Access is denied. This server can not verify that the origin or "
16 "referrer of your request matches the current site. Either your "
17 "browser supplied the wrong Origin or Referrer or it did not supply "
18 "one at all."
19 )
22class BadCSRFToken(HTTPBadRequest):
23 """
24 This exception indicates the request has failed cross-site request
25 forgery token validation.
26 """
28 title = 'Bad CSRF Token'
29 explanation = (
30 'Access is denied. This server can not verify that your cross-site '
31 'request forgery token belongs to your login session. Either you '
32 'supplied the wrong cross-site request forgery token or your session '
33 'no longer exists. This may be due to session timeout or because '
34 'browser is not supplying the credentials required, as can happen '
35 'when the browser has cookies turned off.'
36 )
39class PredicateMismatch(HTTPNotFound):
40 """
41 This exception is raised by multiviews when no view matches
42 all given predicates.
44 This exception subclasses the :class:`HTTPNotFound` exception for a
45 specific reason: if it reaches the main exception handler, it should
46 be treated as :class:`HTTPNotFound`` by any exception view
47 registrations. Thus, typically, this exception will not be seen
48 publicly.
50 However, this exception will be raised if the predicates of all
51 views configured to handle another exception context cannot be
52 successfully matched. For instance, if a view is configured to
53 handle a context of ``HTTPForbidden`` and the configured with
54 additional predicates, then :class:`PredicateMismatch` will be
55 raised if:
57 * An original view callable has raised :class:`HTTPForbidden` (thus
58 invoking an exception view); and
59 * The given request fails to match all predicates for said
60 exception view associated with :class:`HTTPForbidden`.
62 The same applies to any type of exception being handled by an
63 exception view.
64 """
67class URLDecodeError(UnicodeDecodeError):
68 """
69 This exception is raised when :app:`Pyramid` cannot
70 successfully decode a URL or a URL path segment. This exception
71 behaves just like the Python builtin
72 :exc:`UnicodeDecodeError`. It is a subclass of the builtin
73 :exc:`UnicodeDecodeError` exception only for identity purposes,
74 mostly so an exception view can be registered when a URL cannot be
75 decoded.
76 """
79class ConfigurationError(Exception):
80 """ Raised when inappropriate input values are supplied to an API
81 method of a :term:`Configurator`"""
84class ConfigurationConflictError(ConfigurationError):
85 """ Raised when a configuration conflict is detected during action
86 processing"""
88 def __init__(self, conflicts):
89 self._conflicts = conflicts
91 def __str__(self):
92 r = ["Conflicting configuration actions"]
93 for discriminator, infos in self._conflicts.items():
94 r.append(" For: %s" % (discriminator,))
95 for info in infos:
96 for line in str(info).rstrip().split('\n'):
97 r.append(" " + line)
99 return '\n'.join(r)
102class ConfigurationExecutionError(ConfigurationError):
103 """An error occurred during execution of a configuration action
104 """
106 def __init__(self, etype, evalue, info):
107 self.etype, self.evalue, self.info = etype, evalue, info
109 def __str__(self):
110 return "%s: %s\n in:\n %s" % (self.etype, self.evalue, self.info)
113class CyclicDependencyError(Exception):
114 """ The exception raised when the Pyramid topological sorter detects a
115 cyclic dependency."""
117 def __init__(self, cycles):
118 self.cycles = cycles
120 def __str__(self):
121 L = []
122 cycles = self.cycles
123 for cycle in cycles:
124 dependent = cycle
125 dependees = cycles[cycle]
126 L.append('%r sorts before %r' % (dependent, dependees))
127 msg = 'Implicit ordering cycle:' + '; '.join(L)
128 return msg