Skip to content

Commit 3d5d52f

Browse files
committed
Add a 'b()' utility for forcing encoding to bytes.
In Python2, the 'bytes()' builtin doesn't take an encoding argument.
1 parent 17880b6 commit 3d5d52f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

oauth2/_compat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
except NameError: #pragma NO COVER Py3k
44
TEXT = str
55
STRING_TYPES = (str, bytes)
6+
def b(x, encoding='ascii'):
7+
return bytes(x, encoding)
68
else: #pragma NO COVER Python2
79
STRING_TYPES = (unicode, bytes)
10+
def b(x, encoding='ascii'):
11+
if isinstance(x, unicode):
12+
x = x.encode(encoding)
13+
return x
814

915
def u(x, encoding='ascii'):
1016
if isinstance(x, TEXT): #pragma NO COVER

0 commit comments

Comments
 (0)