Mercurial > p > roundup > code
changeset 7228:07ce4e4110f5
flake8 fixes: whitespace, remove unused imports
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 18 Mar 2023 14:16:31 -0400 |
| parents | 1e004afe87bb |
| children | 1dd48b540b35 |
| files | roundup/admin.py roundup/anypy/cookie_.py roundup/anypy/http_.py roundup/anypy/random_.py roundup/anypy/ssl_.py roundup/anypy/time_.py roundup/anypy/urllib_.py roundup/cgi/KeywordsExpr.py roundup/cgi/TranslationService.py roundup/cgi/apache.py roundup/cgi/client.py roundup/cgi/engine_jinja2.py roundup/cgi/timestamp.py roundup/cgi/wsgi_handler.py roundup/dehtml.py roundup/i18n.py roundup/init.py roundup/instance.py roundup/password.py roundup/token_r.py |
| diffstat | 20 files changed, 56 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/roundup/admin.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/admin.py Sat Mar 18 14:16:31 2023 -0400 @@ -653,7 +653,7 @@ tx_Source='cli') except OptionUnsetError as e: raise UsageError("In %(tracker_home)s/config.ini - %(error)s" % { - 'error': str(e), 'tracker_home': tracker_home }) + 'error': str(e), 'tracker_home': tracker_home}) return 0 @@ -1739,12 +1739,12 @@ into the habit. """ if self.db.db_version_updated: - print(_('Tracker updated to schema version %s.') % + print(_('Tracker updated to schema version %s.') % self.db.database_schema['version']) self.db_uncommitted = True else: print(_('No migration action required. At schema version %s.') % - self.db.database_schema['version']) + self.db.database_schema['version']) return 0 def do_perftest(self, args): @@ -1763,14 +1763,13 @@ """ from roundup.anypy.time_ import perf_counter - props = { "rounds": self.db.config.PASSWORD_PBKDF2_DEFAULT_ROUNDS, - "scheme": password.Password.known_schemes[0] - } + props = {"rounds": self.db.config.PASSWORD_PBKDF2_DEFAULT_ROUNDS, + "scheme": password.Password.known_schemes[0]} print_supported_schemes = lambda: print( - "Supported schemes (default is first, case " - "sensitive):\n %s." % - ", ".join(password.Password.known_schemes)) + "Supported schemes (default is first, case " + "sensitive):\n %s." % + ", ".join(password.Password.known_schemes)) if (args[0].find("=") != -1): args.insert(0, 'password') @@ -1780,7 +1779,7 @@ if args[0] == "password": try: # convert 10,000,000 or 10.000.000 to 10000000 - r = int(re.sub('[,.]','',props['rounds'])) + r = int(re.sub('[,.]', '', props['rounds'])) if r < 1000: print(_("Invalid 'rounds'. Must be larger than 999.")) return @@ -1789,7 +1788,7 @@ print(_("Invalid 'rounds'. It must be an integer not: %s") % props['rounds']) return - if props['scheme'] == None: + if props['scheme'] is None: print_supported_schemes() return
--- a/roundup/anypy/cookie_.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/anypy/cookie_.py Sat Mar 18 14:16:31 2023 -0400 @@ -6,5 +6,5 @@ from http.cookies import _getdate as get_cookie_date except ImportError: # Python 2.5-2.7 - from Cookie import CookieError, BaseCookie, SimpleCookie - from Cookie import _getdate as get_cookie_date + from Cookie import CookieError, BaseCookie, SimpleCookie # noqa: F401 + from Cookie import _getdate as get_cookie_date # noqa: F401
--- a/roundup/anypy/http_.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/anypy/http_.py Sat Mar 18 14:16:31 2023 -0400 @@ -4,5 +4,5 @@ server.DEFAULT_ERROR_MESSAGE except (ImportError, AttributeError): # Python 2.5-2.7 - import httplib as client - import BaseHTTPServer as server + import httplib as client # noqa: F401 + import BaseHTTPServer as server # noqa: F401
--- a/roundup/anypy/random_.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/anypy/random_.py Sat Mar 18 14:16:31 2023 -0400 @@ -20,7 +20,8 @@ # don't completely throw away the existing state, but add some # more random state to the existing state def seed(v=None): - import os, time + import os + import time _r.seed((_r.getstate(), v, hasattr(os, 'getpid') and os.getpid(),
--- a/roundup/anypy/ssl_.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/anypy/ssl_.py Sat Mar 18 14:16:31 2023 -0400 @@ -3,4 +3,4 @@ from ssl import SSLError except (ImportError, AttributeError): # Python 2.5-2.7 - from socket import sslerror as SSLError + from socket import sslerror as SSLError # noqa: F401
--- a/roundup/anypy/time_.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/anypy/time_.py Sat Mar 18 14:16:31 2023 -0400 @@ -3,4 +3,4 @@ from time import perf_counter except (ImportError, AttributeError): # Python 2.5-2.7 - from time import clock as perf_counter + from time import clock as perf_counter # noqa: F401
--- a/roundup/anypy/urllib_.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/anypy/urllib_.py Sat Mar 18 14:16:31 2023 -0400 @@ -6,6 +6,6 @@ from urllib.request import urlopen except ImportError: # Python 2.5-2.7 - from urllib import quote, unquote, urlencode - from urllib2 import urlopen - from urlparse import urlparse, parse_qs, urlunparse + from urllib import quote, unquote, urlencode # noqa: F401 + from urllib2 import urlopen # noqa: F401 + from urlparse import urlparse, parse_qs, urlunparse # noqa: F401
--- a/roundup/cgi/KeywordsExpr.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/cgi/KeywordsExpr.py Sat Mar 18 14:16:31 2023 -0400 @@ -47,7 +47,7 @@ this.brackets = false; this.infix = function() { - return this.x.brackets + return this.x.brackets ? "NOT(" + this.x.infix() + ")" : "NOT " + this.x.infix(); } @@ -126,7 +126,7 @@ out += '>'; out += '<option value="-1"><\/option>'; for (var i = 0; i < KEYWORDS.length; ++i) { - out += '<option value="' + KEYWORDS[i][0] + + out += '<option value="' + KEYWORDS[i][0] + '">' + KEYWORDS[i][1] + "<\/option>"; } out += '<\/select>'; @@ -175,7 +175,7 @@ } function undo_clicked() { - current = undo.length > 0 + current = undo.length > 0 ? undo.pop() : original; set_content();
--- a/roundup/cgi/TranslationService.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/cgi/TranslationService.py Sat Mar 18 14:16:31 2023 -0400 @@ -26,7 +26,7 @@ def translate(self, domain, msgid, mapping=None, context=None, target_language=None, default=None): _msg = self.gettext(msgid) - #print ("TRANSLATE", msgid, _msg, mapping, context) + # print ("TRANSLATE", msgid, _msg, mapping, context) _msg = TALInterpreter.interpolate(_msg, mapping) return _msg
--- a/roundup/cgi/apache.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/cgi/apache.py Sat Mar 18 14:16:31 2023 -0400 @@ -149,7 +149,7 @@ _env["CGI_SHOW_TIMING"] = _timing _form = cgi.FieldStorage(req, environ=_env) _client = _tracker.Client(_tracker, Request(req), _env, _form, - translator=TranslationService.get_translation(_lang, + translator=TranslationService.get_translation(_lang, tracker_home=_home)) _client.main() return apache.OK
--- a/roundup/cgi/client.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/cgi/client.py Sat Mar 18 14:16:31 2023 -0400 @@ -632,7 +632,7 @@ # Call rest library to handle the pre-flight request handler = rest.RestfulInstance(self, self.db) output = handler.dispatch(self.env['REQUEST_METHOD'], - self.path, self.form) + self.path, self.form) if self.response_code == 204: self.write("") @@ -682,9 +682,9 @@ return # Handle CORS preflight request. We know rest is enabled - # because handle_rest is called. Preflight requests + # because handle_rest is called. Preflight requests # are unauthenticated, so no need to check permissions. - if ( self.is_cors_preflight() ): + if (self.is_cors_preflight()): self.handle_preflight() return elif not self.db.security.hasPermission('Rest Access', self.userid): @@ -1318,13 +1318,13 @@ # Living spec doesn't address Origin value's case or # how to compare it. So implement case sensitive.... if origin in allowed_origins: - return True + return True # Block use of * when origin match is used for # allowing credentials. See: # https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS # under Credentials Requests and Wildcards - if ( allowed_origins and allowed_origins[0] == '*' - and not credentials): + if (allowed_origins and allowed_origins[0] == '*' + and not credentials): return True return False
--- a/roundup/cgi/engine_jinja2.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/cgi/engine_jinja2.py Sat Mar 18 14:16:31 2023 -0400 @@ -31,7 +31,6 @@ from __future__ import print_function import jinja2 -import gettext import mimetypes import sys
--- a/roundup/cgi/timestamp.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/cgi/timestamp.py Sat Mar 18 14:16:31 2023 -0400 @@ -2,7 +2,11 @@ form submission for cgi actions. ''' -import time, struct, binascii, base64 +import base64 +import binascii +import struct +import time + from roundup.cgi.exceptions import FormError from roundup.i18n import _ from roundup.anypy.strings import b2s, s2b
--- a/roundup/cgi/wsgi_handler.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/cgi/wsgi_handler.py Sat Mar 18 14:16:31 2023 -0400 @@ -46,7 +46,7 @@ class Writer(object): '''Perform a start_response if need be when we start writing.''' def __init__(self, request): - self.request = request #weakref.ref(request) + self.request = request # weakref.ref(request) def write(self, data): f = self.request.get_wfile() @@ -80,10 +80,11 @@ self.home = home self.debug = debug self.timing = timing - self.feature_flags= feature_flags or {} + self.feature_flags = feature_flags or {} self.tracker = None if lang: - self.translator = TranslationService.get_translation(lang, + self.translator = TranslationService.get_translation( + lang, tracker_home=home) else: self.translator = None @@ -125,12 +126,12 @@ if "cache_tracker" in self.feature_flags: client = self.tracker.Client(self.tracker, request, environ, form, - self.translator) + self.translator) try: client.main() except roundup.cgi.client.NotFound: request.start_response([('Content-Type', 'text/html')], 404) - request.wfile.write(s2b('Not found: %s' % + request.wfile.write(s2b('Not found: %s' % html_escape(client.path))) else: with self.get_tracker() as tracker: @@ -140,7 +141,7 @@ client.main() except roundup.cgi.client.NotFound: request.start_response([('Content-Type', 'text/html')], 404) - request.wfile.write(s2b('Not found: %s' % + request.wfile.write(s2b('Not found: %s' % html_escape(client.path))) # all body data has been written using wfile
--- a/roundup/dehtml.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/dehtml.py Sat Mar 18 14:16:31 2023 -0400 @@ -5,6 +5,7 @@ import sys _pyver = sys.version_info[0] + class dehtml: def __init__(self, converter): if converter == "none":
--- a/roundup/i18n.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/i18n.py Sat Mar 18 14:16:31 2023 -0400 @@ -64,7 +64,7 @@ # os.prefix should be /usr, /usr/local or root of virtualenv # strip leading / to make os.path.join work right. path = __file__ -for N in 1, 2: +for _N in 1, 2: path = os.path.dirname(path) # path is /usr/local/lib/python3.10/site-packages _ldir = os.path.join(path, sys.prefix[1:], 'share', 'locale')
--- a/roundup/init.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/init.py Sat Mar 18 14:16:31 2023 -0400 @@ -22,7 +22,7 @@ import email.parser import errno -import os +import os from roundup import install_util
--- a/roundup/instance.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/instance.py Sat Mar 18 14:16:31 2023 -0400 @@ -40,7 +40,6 @@ import os import sys -import warnings from roundup import configuration, mailgw from roundup import hyperdb, backends, actions
--- a/roundup/password.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/password.py Sat Mar 18 14:16:31 2023 -0400 @@ -43,9 +43,11 @@ _bempty = b"" _bjoin = _bempty.join + class ConfigNotSet(RoundupException): pass + def bchr(c): if bytes == str: # Python 2. @@ -127,9 +129,9 @@ block = xor_bytes(block, tmp) out += block return out[:keylen] - + def _pbkdf2_sha512(password, salt, rounds, keylen): - return _pbkdf2(password, salt, rounds, keylen, sha=sha512) + return _pbkdf2(password, salt, rounds, keylen, sha=sha512) def ssha(password, salt): @@ -172,6 +174,7 @@ raise ValueError("rounds must be positive number") return _pbkdf2_sha512(password, salt, rounds, keylen) + def pbkdf2(password, salt, rounds, keylen): """pkcs#5 password-based key derivation v2.0 @@ -237,7 +240,7 @@ rounds = config.PASSWORD_PBKDF2_DEFAULT_ROUNDS # if we are testing - if ("pytest" in sys.modules and + if ("pytest" in sys.modules and "PYTEST_CURRENT_TEST" in os.environ): if ("PYTEST_USE_CONFIG" in os.environ): rounds = config.PASSWORD_PBKDF2_DEFAULT_ROUNDS @@ -265,7 +268,7 @@ if sys.version_info[0] > 2: logger.critical( "encodePassword called without config.", - stack_info = True) + stack_info=True) else: import inspect, traceback where = inspect.currentframe()
--- a/roundup/token_r.py Thu Mar 16 16:34:11 2023 -0400 +++ b/roundup/token_r.py Sat Mar 18 14:16:31 2023 -0400 @@ -54,8 +54,8 @@ while 1: # end of string, finish off the current token if pos == length: - if state == QUOTE: raise ValueError - elif state == TOKEN: l.append(token) + if state == QUOTE: raise ValueError # noqa: E701 + elif state == TOKEN: l.append(token) # noqa: E701 break c = s[pos] if state == NEWTOKEN:
