|
@@ -11,13 +11,15 @@
|
|
from __future__ import absolute_import
|
|
from __future__ import absolute_import
|
|
|
|
|
|
__all__ = ['Counter', 'reload', 'UserList', 'UserDict', 'Queue', 'Empty',
|
|
__all__ = ['Counter', 'reload', 'UserList', 'UserDict', 'Queue', 'Empty',
|
|
- 'zip_longest', 'StringIO', 'BytesIO', 'map', 'string', 'string_t',
|
|
|
|
|
|
+ 'zip_longest', 'map', 'string', 'string_t',
|
|
'long_t', 'text_t', 'range', 'int_types', 'items', 'keys', 'values',
|
|
'long_t', 'text_t', 'range', 'int_types', 'items', 'keys', 'values',
|
|
'nextfun', 'reraise', 'WhateverIO', 'with_metaclass',
|
|
'nextfun', 'reraise', 'WhateverIO', 'with_metaclass',
|
|
'OrderedDict', 'THREAD_TIMEOUT_MAX', 'format_d',
|
|
'OrderedDict', 'THREAD_TIMEOUT_MAX', 'format_d',
|
|
'class_property', 'reclassmethod', 'create_module',
|
|
'class_property', 'reclassmethod', 'create_module',
|
|
'recreate_module', 'monotonic']
|
|
'recreate_module', 'monotonic']
|
|
|
|
|
|
|
|
+import io
|
|
|
|
+
|
|
try:
|
|
try:
|
|
from collections import Counter
|
|
from collections import Counter
|
|
except ImportError: # pragma: no cover
|
|
except ImportError: # pragma: no cover
|
|
@@ -53,7 +55,6 @@ if PY3: # pragma: no cover
|
|
|
|
|
|
from queue import Queue, Empty
|
|
from queue import Queue, Empty
|
|
from itertools import zip_longest
|
|
from itertools import zip_longest
|
|
- from io import StringIO, BytesIO
|
|
|
|
|
|
|
|
map = map
|
|
map = map
|
|
string = str
|
|
string = str
|
|
@@ -62,6 +63,7 @@ if PY3: # pragma: no cover
|
|
text_t = str
|
|
text_t = str
|
|
range = range
|
|
range = range
|
|
int_types = (int, )
|
|
int_types = (int, )
|
|
|
|
+ _byte_t = bytes
|
|
|
|
|
|
open_fqdn = 'builtins.open'
|
|
open_fqdn = 'builtins.open'
|
|
|
|
|
|
@@ -84,24 +86,17 @@ if PY3: # pragma: no cover
|
|
raise value.with_traceback(tb)
|
|
raise value.with_traceback(tb)
|
|
raise value
|
|
raise value
|
|
|
|
|
|
- class WhateverIO(StringIO):
|
|
|
|
-
|
|
|
|
- def write(self, data):
|
|
|
|
- if isinstance(data, bytes):
|
|
|
|
- data = data.encode()
|
|
|
|
- StringIO.write(self, data)
|
|
|
|
-
|
|
|
|
else:
|
|
else:
|
|
import __builtin__ as builtins # noqa
|
|
import __builtin__ as builtins # noqa
|
|
from Queue import Queue, Empty # noqa
|
|
from Queue import Queue, Empty # noqa
|
|
from itertools import imap as map, izip_longest as zip_longest # noqa
|
|
from itertools import imap as map, izip_longest as zip_longest # noqa
|
|
- from StringIO import StringIO # noqa
|
|
|
|
string = unicode # noqa
|
|
string = unicode # noqa
|
|
string_t = basestring # noqa
|
|
string_t = basestring # noqa
|
|
- text_t = unicode
|
|
|
|
|
|
+ text_t = unicode # noqa
|
|
long_t = long # noqa
|
|
long_t = long # noqa
|
|
- range = xrange
|
|
|
|
- int_types = (int, long)
|
|
|
|
|
|
+ range = xrange # noqa
|
|
|
|
+ int_types = (int, long) # noqa
|
|
|
|
+ _byte_t = (str, bytes) # noqa
|
|
|
|
|
|
open_fqdn = '__builtin__.open'
|
|
open_fqdn = '__builtin__.open'
|
|
|
|
|
|
@@ -131,8 +126,6 @@ else:
|
|
|
|
|
|
exec_("""def reraise(tp, value, tb=None): raise tp, value, tb""")
|
|
exec_("""def reraise(tp, value, tb=None): raise tp, value, tb""")
|
|
|
|
|
|
- BytesIO = WhateverIO = StringIO # noqa
|
|
|
|
-
|
|
|
|
|
|
|
|
def with_metaclass(Type, skip_attrs=set(['__dict__', '__weakref__'])):
|
|
def with_metaclass(Type, skip_attrs=set(['__dict__', '__weakref__'])):
|
|
"""Class decorator to set metaclass.
|
|
"""Class decorator to set metaclass.
|
|
@@ -385,3 +378,16 @@ def get_origins(defs):
|
|
for module, attrs in items(defs):
|
|
for module, attrs in items(defs):
|
|
origins.update(dict((attr, module) for attr in attrs))
|
|
origins.update(dict((attr, module) for attr in attrs))
|
|
return origins
|
|
return origins
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+_SIO_write = io.StringIO.write
|
|
|
|
+_SIO_init = io.StringIO.__init__
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class WhateverIO(io.StringIO):
|
|
|
|
+
|
|
|
|
+ def __init__(self, v=None, *a, **kw):
|
|
|
|
+ _SIO_init(self, v.decode() if isinstance(v, _byte_t) else v, *a, **kw)
|
|
|
|
+
|
|
|
|
+ def write(self, data):
|
|
|
|
+ _SIO_write(self, data.decode() if isinstance(data, _byte_t) else data)
|