File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -116,12 +116,18 @@ def _format_char(char):
116116_utf32_codec = {'little' : 'utf-32le' , 'big' : 'utf-32le' }[_sys .byteorder ]
117117
118118def _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
You can’t perform that action at this time.
0 commit comments