summaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
authormikeos <mike.osipov@gmail.com>2013-07-18 20:55:53 +0400
committermikeos <mike.osipov@gmail.com>2013-07-18 20:55:53 +0400
commit5aaf7bd127ee70b90f26dd3dfbb8feea2d9c0c89 (patch)
tree60ef625fca42b42ffb44a8234dd4a5751b08d47d /utils.py
parent3ff3ddd16357d96987026e770ffe197ab7286ede (diff)
add config file support
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/utils.py b/utils.py
new file mode 100644
index 0000000..bc312ed
--- /dev/null
+++ b/utils.py
@@ -0,0 +1,32 @@
+import sys
+
+if sys.version_info.major == 2:
+ def is_python_v2():
+ return True
+
+ def to_unicode(buf):
+ if type(buf) is unicode:
+ return buf
+ return buf.decode("utf-8")
+
+ class Encoded:
+ def __init__(self, stream):
+ self.stream = stream
+
+ def write(self, msg):
+ if type(msg) is unicode:
+ self.stream.write(msg.encode("utf-8"))
+ else:
+ self.stream.write(msg)
+
+ def __getattr__(self, attr):
+ return getattr(self.stream, attr)
+
+ sys.stdout = Encoded(sys.stdout)
+ sys.stderr = Encoded(sys.stderr)
+else:
+ def is_python_v2():
+ return False
+
+ def to_unicode(buf):
+ return buf