###--------------------------------------------------------------------------
### Utilities.
-from cStringIO import StringIO; BytesIO = StringIO
-def bin(x): return x
-def text(x): return x
-def bytechr(x): return chr(x)
-def byteord(x): return ord(x)
+import sys as _SYS
+_PYVER = _SYS.version_info
+if _PYVER >= (3,):
+ _FSENC = _SYS.getfilesystemencoding()
+ if _PYVER >= (3, 1): _FSENCERR = "surrogateescape"
+ else: _FSENCERR = "strict"
+ from io import BytesIO, StringIO
+ def bin(x): return x.encode(_FSENC, _FSENCERR)
+ def text(x): return x.decode(_FSENC, _FSENCERR)
+ def bytechr(x): return bytes([x])
+ def byteord(x): return x
+else:
+ from cStringIO import StringIO; BytesIO = StringIO
+ def bin(x): return x
+ def text(x): return x
+ def bytechr(x): return chr(x)
+ def byteord(x): return ord(x)
def excval(): return exc_info()[1]
QUIS = OS.path.basename(argv[0])