|
8 | 8 | import codecs |
9 | 9 | import email.utils |
10 | 10 | import errno |
11 | | -import hashlib |
12 | 11 | import logging |
13 | 12 | import mimetypes |
14 | 13 | import os |
15 | | -import quopri |
16 | 14 | import re |
17 | 15 | import socket |
18 | 16 | import stat |
19 | 17 | import sys |
20 | 18 | import time |
21 | 19 |
|
22 | | -from email.mime.base import MIMEBase |
23 | 20 | from email.mime.multipart import MIMEMultipart |
24 | | -from email.mime.text import MIMEText |
25 | 21 | from traceback import format_exc |
26 | 22 | try: |
27 | 23 | from OpenSSL.SSL import SysCallError |
28 | 24 | except ImportError: |
29 | 25 | class SysCallError(Exception): |
30 | 26 | pass |
31 | 27 |
|
32 | | -import roundup.anypy.email_ |
| 28 | +import roundup.anypy.email_ # noqa: F401 -- patches for email library code |
33 | 29 | import roundup.anypy.random_ as random_ # quality of random checked below |
34 | 30 |
|
35 | | -from roundup import date, hyperdb, password, rest, roundupdb, xmlrpc |
| 31 | +from roundup import hyperdb, rest, xmlrpc |
36 | 32 |
|
37 | 33 | from roundup.anypy import http_, urllib_, xmlrpc_ |
38 | | -from roundup.anypy.cookie_ import BaseCookie, CookieError, get_cookie_date, \ |
| 34 | +from roundup.anypy.cookie_ import BaseCookie, CookieError, get_cookie_date, \ |
39 | 35 | SimpleCookie |
40 | 36 | from roundup.anypy.html import html_escape |
41 | 37 | from roundup.anypy.strings import s2b, b2s, bs2b, uchr, is_us |
@@ -76,7 +72,8 @@ def initialiseSecurity(security): |
76 | 72 | description="User may access the rest interface") |
77 | 73 | security.addPermissionToRole('Admin', p) |
78 | 74 |
|
79 | | - p = security.addPermission(name="Xmlrpc Access", |
| 75 | + p = security.addPermission( |
| 76 | + name="Xmlrpc Access", |
80 | 77 | description="User may access the xmlrpc interface") |
81 | 78 | security.addPermissionToRole('Admin', p) |
82 | 79 |
|
@@ -600,7 +597,7 @@ def handle_xmlrpc(self): |
600 | 597 | # It will return True if everything is ok, |
601 | 598 | # raises exception on check failure. |
602 | 599 | csrf_ok = self.handle_csrf(api=True) |
603 | | - except (Unauthorised, UsageError) as msg: |
| 600 | + except (Unauthorised, UsageError): |
604 | 601 | # report exception back to server |
605 | 602 | exc_type, exc_value, exc_tb = sys.exc_info() |
606 | 603 | output = xmlrpc_.client.dumps( |
@@ -639,7 +636,8 @@ def handle_rest(self): |
639 | 636 | return |
640 | 637 |
|
641 | 638 | # allow preflight request even if unauthenticated |
642 | | - if (self.env['REQUEST_METHOD'] == "OPTIONS" |
| 639 | + if ( |
| 640 | + self.env['REQUEST_METHOD'] == "OPTIONS" |
643 | 641 | and self.request.headers.get("Access-Control-Request-Headers") |
644 | 642 | and self.request.headers.get("Access-Control-Request-Method") |
645 | 643 | and self.request.headers.get("Origin") |
@@ -681,7 +679,7 @@ def handle_rest(self): |
681 | 679 | except (Unauthorised, UsageError) as msg: |
682 | 680 | # FIXME should return what the client requests |
683 | 681 | # via accept header. |
684 | | - output = s2b('{ "error": { "status": 400, "msg": "%s"}}' % |
| 682 | + output = s2b('{ "error": { "status": 400, "msg": "%s"}}' % |
685 | 683 | str(msg)) |
686 | 684 | self.response_code = 400 |
687 | 685 | self.setHeader("Content-Length", str(len(output))) |
@@ -885,7 +883,8 @@ def inner_main(self): |
885 | 883 | self.response_code = 404 |
886 | 884 | self.template = '404' |
887 | 885 | try: |
888 | | - cl = self.db.getclass(self.classname) |
| 886 | + # generates keyerror if class does not exist |
| 887 | + self.db.getclass(self.classname) |
889 | 888 | self.write_html(self.renderContext()) |
890 | 889 | except KeyError: |
891 | 890 | # we can't map the URL to a class we know about |
@@ -913,7 +912,7 @@ def inner_main(self): |
913 | 912 | else: |
914 | 913 | # in debug mode, only write error to screen. |
915 | 914 | self.write_html(e.html) |
916 | | - except Exception as e: |
| 915 | + except Exception as e: # noqa: F841 |
917 | 916 | # Something has gone badly wrong. Therefore, we should |
918 | 917 | # make sure that the response code indicates failure. |
919 | 918 | if self.response_code == http_.client.OK: |
@@ -984,7 +983,7 @@ def determine_charset(self): |
984 | 983 | codecs.lookup(charset) |
985 | 984 | except LookupError: |
986 | 985 | self.add_error_message(self._('Unrecognized charset: %r') % |
987 | | - charset) |
| 986 | + charset) |
988 | 987 |
|
989 | 988 | charset_parameter = 0 |
990 | 989 | else: |
@@ -1150,7 +1149,7 @@ def determine_user(self): |
1150 | 1149 | self.make_user_anonymous() |
1151 | 1150 | login = self.get_action_class('login')(self) |
1152 | 1151 | login.verifyLogin(username, password) |
1153 | | - except LoginError as err: |
| 1152 | + except LoginError: |
1154 | 1153 | self.make_user_anonymous() |
1155 | 1154 | raise |
1156 | 1155 | user = username |
@@ -2205,12 +2204,12 @@ def get_action_class(self, action_name): |
2205 | 2204 | # tracker-defined action |
2206 | 2205 | action_klass = self.instance.cgi_actions[action_name] |
2207 | 2206 | else: |
2208 | | - # go with a default |
2209 | | - for name, action_klass in self.actions: |
| 2207 | + # go with a default, action_klass used after end of loop |
| 2208 | + for name, action_klass in self.actions: # noqa: B007 |
2210 | 2209 | if name == action_name: |
2211 | 2210 | break |
2212 | 2211 | else: |
2213 | | - raise ValueError('No such action "%s"' % |
| 2212 | + raise ValueError('No such action "%s"' % |
2214 | 2213 | html_escape(action_name)) |
2215 | 2214 | return action_klass |
2216 | 2215 |
|
|
0 commit comments