Skip to content

Commit

Permalink
change: Use byte literals where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
defnull committed Sep 16, 2024
1 parent ba52622 commit 2489e6c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ def _iter_body(self, read, bufsize):
@staticmethod
def _iter_chunked(read, bufsize):
err = HTTPError(400, 'Error while parsing chunked transfer body.')
rn, sem, bs = tob('\r\n'), tob(';'), tob('')
rn, sem, bs = b'\r\n', b';', b''
while True:
header = read(1)
while header[-2:] != rn:
Expand Down Expand Up @@ -1813,7 +1813,7 @@ def set_cookie(self, name, value, secret=None, digestmod=hashlib.sha256, **optio
encoded = base64.b64encode(pickle.dumps([name, value], -1))
sig = base64.b64encode(hmac.new(tob(secret), encoded,
digestmod=digestmod).digest())
value = touni(tob('!') + sig + tob('?') + encoded)
value = touni(b'!' + sig + b'?' + encoded)
elif not isinstance(value, basestring):
raise TypeError('Secret key required for non-string cookies.')

Expand Down Expand Up @@ -2991,7 +2991,7 @@ def cookie_encode(data, key, digestmod=None):
digestmod = digestmod or hashlib.sha256
msg = base64.b64encode(pickle.dumps(data, -1))
sig = base64.b64encode(hmac.new(tob(key), msg, digestmod=digestmod).digest())
return tob('!') + sig + tob('?') + msg
return b'!' + sig + b'?' + msg


def cookie_decode(data, key, digestmod=None):
Expand All @@ -3000,7 +3000,7 @@ def cookie_decode(data, key, digestmod=None):
"Do not use this API directly.")
data = tob(data)
if cookie_is_encoded(data):
sig, msg = data.split(tob('?'), 1)
sig, msg = data.split(b'?', 1)
digestmod = digestmod or hashlib.sha256
hashed = hmac.new(tob(key), msg, digestmod=digestmod).digest()
if _lscmp(sig[1:], base64.b64encode(hashed)):
Expand All @@ -3012,7 +3012,7 @@ def cookie_is_encoded(data):
""" Return True if the argument looks like a encoded cookie."""
depr(0, 13, "cookie_is_encoded() will be removed soon.",
"Do not use this API directly.")
return bool(data.startswith(tob('!')) and tob('?') in data)
return bool(data.startswith(b'!') and b'?' in data)


def html_escape(string):
Expand Down

0 comments on commit 2489e6c

Please sign in to comment.