Skip to content

Commit bf9f44d

Browse files
committed
clear up draw_str issues with non-Unicode on Python 2
1 parent 4a86e1d commit bf9f44d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

tdl/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,18 @@ def _format_char(char):
116116
_utf32_codec = {'little': 'utf-32le', 'big': 'utf-32le'}[_sys.byteorder]
117117

118118
def _format_str(string):
119-
if isinstance(string, str):
120-
array = _array.array('I')
119+
"""Attempt fast string handing by decoding directly into an array."""
120+
if isinstance(string, _STRTYPES):
121121
if _IS_PYTHON3:
122+
array = _array.array('I')
122123
array.frombytes(string.encode(_utf32_codec))
123-
else:
124-
array.fromstring(string.encode(_utf32_codec))
124+
else: # Python 2
125+
if isinstance(string, unicode):
126+
array = _array.array(b'I')
127+
array.fromstring(string.encode(_utf32_codec))
128+
else:
129+
array = _array.array(b'B')
130+
array.fromstring(string)
125131
return array
126132
return string
127133

0 commit comments

Comments
 (0)