Skip to content

Commit 7912616

Browse files
committed
change: Use byte literals where possible
1 parent 990d567 commit 7912616

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

bottle.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ def _iter_body(self, read, bufsize):
12581258
@staticmethod
12591259
def _iter_chunked(read, bufsize):
12601260
err = HTTPError(400, 'Error while parsing chunked transfer body.')
1261-
rn, sem, bs = tob('\r\n'), tob(';'), tob('')
1261+
rn, sem, bs = b'\r\n', b';', b''
12621262
while True:
12631263
header = read(1)
12641264
while header[-2:] != rn:
@@ -1814,7 +1814,7 @@ def set_cookie(self, name, value, secret=None, digestmod=hashlib.sha256, **optio
18141814
encoded = base64.b64encode(pickle.dumps([name, value], -1))
18151815
sig = base64.b64encode(hmac.new(tob(secret), encoded,
18161816
digestmod=digestmod).digest())
1817-
value = touni(tob('!') + sig + tob('?') + encoded)
1817+
value = touni(b'!' + sig + b'?' + encoded)
18181818
elif not isinstance(value, basestring):
18191819
raise TypeError('Secret key required for non-string cookies.')
18201820

@@ -2992,7 +2992,7 @@ def cookie_encode(data, key, digestmod=None):
29922992
digestmod = digestmod or hashlib.sha256
29932993
msg = base64.b64encode(pickle.dumps(data, -1))
29942994
sig = base64.b64encode(hmac.new(tob(key), msg, digestmod=digestmod).digest())
2995-
return tob('!') + sig + tob('?') + msg
2995+
return b'!' + sig + b'?' + msg
29962996

29972997

29982998
def cookie_decode(data, key, digestmod=None):
@@ -3001,7 +3001,7 @@ def cookie_decode(data, key, digestmod=None):
30013001
"Do not use this API directly.")
30023002
data = tob(data)
30033003
if cookie_is_encoded(data):
3004-
sig, msg = data.split(tob('?'), 1)
3004+
sig, msg = data.split(b'?', 1)
30053005
digestmod = digestmod or hashlib.sha256
30063006
hashed = hmac.new(tob(key), msg, digestmod=digestmod).digest()
30073007
if _lscmp(sig[1:], base64.b64encode(hashed)):
@@ -3013,7 +3013,7 @@ def cookie_is_encoded(data):
30133013
""" Return True if the argument looks like a encoded cookie."""
30143014
depr(0, 13, "cookie_is_encoded() will be removed soon.",
30153015
"Do not use this API directly.")
3016-
return bool(data.startswith(tob('!')) and tob('?') in data)
3016+
return bool(data.startswith(b'!') and b'?' in data)
30173017

30183018

30193019
def html_escape(string):

0 commit comments

Comments
 (0)