[py23] define BytesIO, StringIO and 'UnicodeIO' to disambiguate bytes vs unicode in-memory streams
This commit is contained in:
parent
852e4e6593
commit
2e058808fe
@ -90,10 +90,18 @@ except NameError:
|
|||||||
def byteord(c):
|
def byteord(c):
|
||||||
return c if isinstance(c, int) else ord(c)
|
return c if isinstance(c, int) else ord(c)
|
||||||
|
|
||||||
|
|
||||||
|
# the 'io' module provides the same I/O interface on both 2 and 3.
|
||||||
|
# here we define an alias of io.StringIO to disambiguate it eternally...
|
||||||
|
from io import BytesIO
|
||||||
|
from io import StringIO as UnicodeIO
|
||||||
try:
|
try:
|
||||||
|
# in python 2, by 'StringIO' we still mean a stream of *byte* strings
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from io import BytesIO as StringIO
|
# in Python 3, we mean instead a stream of *unicode* strings
|
||||||
|
StringIO = UnicodeIO
|
||||||
|
|
||||||
|
|
||||||
def strjoin(iterable, joiner=''):
|
def strjoin(iterable, joiner=''):
|
||||||
return tostr(joiner).join(iterable)
|
return tostr(joiner).join(iterable)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user