annotate roundup/cgi/exceptions.py @ 8407:700424ba015c

Doc: add docstrings to http exceptions
author John Rouillard <rouilj@ieee.org>
date Sun, 10 Aug 2025 20:57:57 -0400
parents a1cffeef5f87
children e882a5d52ae5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4083
bbab97f8ffb2 XMLRPC improvements:
Stefan Seefeld <stefan@seefeld.name>
parents: 2924
diff changeset
1 """Exceptions for use in Roundup's web interface.
bbab97f8ffb2 XMLRPC improvements:
Stefan Seefeld <stefan@seefeld.name>
parents: 2924
diff changeset
2 """
2129
3fd672293712 add and use Reject exception [SF#700265]
Richard Jones <richard@users.sourceforge.net>
parents: 2062
diff changeset
3
3fd672293712 add and use Reject exception [SF#700265]
Richard Jones <richard@users.sourceforge.net>
parents: 2062
diff changeset
4 __docformat__ = 'restructuredtext'
3fd672293712 add and use Reject exception [SF#700265]
Richard Jones <richard@users.sourceforge.net>
parents: 2062
diff changeset
5
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
6 from roundup.exceptions import LoginError, Unauthorised # noqa: F401
5800
1a835db41674 Call cgi.escape only on python 2. Replace with html.escapeif it can be
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
7
5837
883c9e90b403 Fix problem with cgi.escape being depricated a different way. This way
John Rouillard <rouilj@ieee.org>
parents: 5800
diff changeset
8 from roundup.anypy.html import html_escape
2062
f6d7ccce8d96 cgi exceptions fix
Richard Jones <richard@users.sourceforge.net>
parents: 2052
diff changeset
9
6123
c177e7128dc9 issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents: 6039
diff changeset
10 from roundup.exceptions import RoundupException
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
11
6973
a1cffeef5f87 flak8 spacing fixes.
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
12
6123
c177e7128dc9 issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents: 6039
diff changeset
13 class RoundupCGIException(RoundupException):
c177e7128dc9 issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents: 6039
diff changeset
14 pass
c177e7128dc9 issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents: 6039
diff changeset
15
6973
a1cffeef5f87 flak8 spacing fixes.
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
16
6123
c177e7128dc9 issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents: 6039
diff changeset
17 class HTTPException(RoundupCGIException):
8407
700424ba015c Doc: add docstrings to http exceptions
John Rouillard <rouilj@ieee.org>
parents: 6973
diff changeset
18 """Base exception for all HTTP error codes."""
2004
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
19 pass
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
20
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
21
2004
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
22 class Redirect(HTTPException):
8407
700424ba015c Doc: add docstrings to http exceptions
John Rouillard <rouilj@ieee.org>
parents: 6973
diff changeset
23 """HTTP 302 status code"""
2004
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
24 pass
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
25
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
26
2004
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
27 class NotFound(HTTPException):
8407
700424ba015c Doc: add docstrings to http exceptions
John Rouillard <rouilj@ieee.org>
parents: 6973
diff changeset
28 """HTTP 404 status code unless self.response_code is set to
700424ba015c Doc: add docstrings to http exceptions
John Rouillard <rouilj@ieee.org>
parents: 6973
diff changeset
29 400 prior to raising exception.
700424ba015c Doc: add docstrings to http exceptions
John Rouillard <rouilj@ieee.org>
parents: 6973
diff changeset
30 """
2004
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
31 pass
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
32
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
33
2004
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
34 class NotModified(HTTPException):
8407
700424ba015c Doc: add docstrings to http exceptions
John Rouillard <rouilj@ieee.org>
parents: 6973
diff changeset
35 """HTTP 304 status code"""
2004
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
36 pass
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
37
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
38
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
39 class PreconditionFailed(HTTPException):
8407
700424ba015c Doc: add docstrings to http exceptions
John Rouillard <rouilj@ieee.org>
parents: 6973
diff changeset
40 """HTTP 412 status code"""
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
41 pass
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5264
diff changeset
42
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
43
6123
c177e7128dc9 issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents: 6039
diff changeset
44 class DetectorError(RoundupException):
5079
65fef7858606 issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents: 4083
diff changeset
45 """Raised when a detector throws an exception.
65fef7858606 issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents: 4083
diff changeset
46 Contains details of the exception."""
65fef7858606 issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents: 4083
diff changeset
47 def __init__(self, subject, html, txt):
65fef7858606 issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents: 4083
diff changeset
48 self.subject = subject
65fef7858606 issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents: 4083
diff changeset
49 self.html = html
65fef7858606 issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents: 4083
diff changeset
50 self.txt = txt
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
51 BaseException.__init__(self, subject + ' ' + txt)
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
52
5079
65fef7858606 issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents: 4083
diff changeset
53
2004
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
54 class FormError(ValueError):
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
55 """An 'expected' exception occurred during form parsing.
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
56
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
57 That is, something we know can go wrong, and don't want to alarm the user
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
58 with.
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
59
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
60 We trap this at the user interface level and feed back a nice error to the
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
61 user.
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
62
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
63 """
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
64 pass
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
65
6973
a1cffeef5f87 flak8 spacing fixes.
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
66
6588
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6123
diff changeset
67 class IndexerQueryError(RoundupException):
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6123
diff changeset
68 """Raised to handle errors from FTS searches due to query
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6123
diff changeset
69 syntax errors.
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6123
diff changeset
70 """
91ab3e0ffcd0 Summary: Add test cases for sqlite fts
John Rouillard <rouilj@ieee.org>
parents: 6123
diff changeset
71 pass
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
72
6973
a1cffeef5f87 flak8 spacing fixes.
John Rouillard <rouilj@ieee.org>
parents: 6588
diff changeset
73
6123
c177e7128dc9 issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents: 6039
diff changeset
74 class SendFile(RoundupException):
2004
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
75 """Send a file from the database."""
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
76
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
77
6123
c177e7128dc9 issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents: 6039
diff changeset
78 class SendStaticFile(RoundupException):
2004
1782fe36e7b8 Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff changeset
79 """Send a static file from the instance html directory."""
2052
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
80
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
81
6123
c177e7128dc9 issue2551083 Replace BaseException and Exception with RoundupException
John Rouillard <rouilj@ieee.org>
parents: 6039
diff changeset
82 class SeriousError(RoundupException):
2052
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
83 """Raised when we can't reasonably display an error message on a
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
84 templated page.
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
85
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
86 The exception value will be displayed in the error page, HTML
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
87 escaped.
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
88 """
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
89 def __str__(self):
4083
bbab97f8ffb2 XMLRPC improvements:
Stefan Seefeld <stefan@seefeld.name>
parents: 2924
diff changeset
90 return """
2052
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
91 <html><head><title>Roundup issue tracker: An error has occurred</title>
2278
93bd8c4d43ef in HTML produced by SeriousError.__str__():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2129
diff changeset
92 <link rel="stylesheet" type="text/css" href="@@file/style.css">
2052
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
93 </head>
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
94 <body class="body" marginwidth="0" marginheight="0">
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
95 <p class="error-message">%s</p>
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
96 </body></html>
6039
0dc1e0222353 flake8 whitespace changes, suppress unused import warning
John Rouillard <rouilj@ieee.org>
parents: 5877
diff changeset
97 """ % html_escape(self.args[0])
2052
78e6a1e4984e forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents: 2004
diff changeset
98
2924
df4a3355ee8f added LoginError; fix vim modeline
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2278
diff changeset
99 # vim: set filetype=python sts=4 sw=4 et si :

Roundup Issue Tracker: http://roundup-tracker.org/