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