Skip to content

Commit

Permalink
chore(ruff): use names not magic numbers.
Browse files Browse the repository at this point in the history
This one names the 32 chars as being equivalent to 256 bytes

Also adds the missing http_.client.TOO_MANY_REQUESTS under python 2 to
http_. It allows me to use a symbolic name and not have to touch
client.py code when I remove python2 support from http_.

Also the prior checkin had a bogus commit message. Sigh, time to step
away from the computer today 8-). It replaced a magic number with
MAX_MIME_EXTENSION_LENGTH which was set to a better magic number
derived by parsing extensions in /etc/mime.types.
  • Loading branch information
rouilj committed Dec 11, 2024
1 parent 2331ab5 commit 7c9247d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions roundup/anypy/http_.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
# Python 2.5-2.7
import BaseHTTPServer as server # noqa: F401
import httplib as client # noqa: F401
client.TOO_MANY_REQUESTS = 429
8 changes: 4 additions & 4 deletions roundup/cgi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,8 @@ def handle_rest(self):
return
except RateLimitExceeded as err:
output = s2b("%s" % str(err))
# PYTHON2:FIXME http_.client.TOO_MANY_REQUESTS missing
# python2 so use numeric code.
self.reject_request(output, status=429)
self.reject_request(output,
status=http_.client.TOO_MANY_REQUESTS)
return

# verify Origin is allowed on all requests including GET.
Expand Down Expand Up @@ -1156,7 +1155,8 @@ def authenticate_bearer_token(self, challenge):
# If second or later tokens are < 32 chars, the config system
# stops the tracker from starting so insecure tokens can not
# be used.
if len(self.db.config.WEB_JWT_SECRET[0]) < 32:
CHARS_FOR_256_BIT_KEY = 32
if len(self.db.config.WEB_JWT_SECRET[0]) < CHARS_FOR_256_BIT_KEY:
# no support for jwt, this is fine.
self.setHeader("WWW-Authenticate", "Basic")
raise LoginError('Support for jwt disabled by admin.')
Expand Down

0 comments on commit 7c9247d

Please sign in to comment.