summaryrefslogtreecommitdiff
path: root/urwid/compat.py
diff options
context:
space:
mode:
Diffstat (limited to 'urwid/compat.py')
-rw-r--r--urwid/compat.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/urwid/compat.py b/urwid/compat.py
index 686d703..de0bf7a 100644
--- a/urwid/compat.py
+++ b/urwid/compat.py
@@ -20,6 +20,8 @@
#
# Urwid web site: http://excess.org/urwid/
+from __future__ import division, print_function
+
import sys
try: # python 2.4 and 2.5 compat
@@ -39,10 +41,34 @@ if PYTHON3:
chr2 = lambda x: bytes([x])
B = lambda x: x.encode('iso8859-1')
bytes3 = bytes
+ text_type = str
+ xrange = range
+ text_types = (str,)
else:
ord2 = ord
chr2 = chr
B = lambda x: x
bytes3 = lambda x: bytes().join([chr(c) for c in x])
+ text_type = unicode
+ xrange = xrange
+ text_types = (str, unicode)
+
+
+def with_metaclass(meta, *bases):
+ """
+ Create a base class with a metaclass.
+ Taken from "six" library (https://pythonhosted.org/six/).
+ """
+ # This requires a bit of explanation: the basic idea is to make a dummy
+ # metaclass for one level of class instantiation that replaces itself with
+ # the actual metaclass.
+ class metaclass(type):
+
+ def __new__(cls, name, this_bases, d):
+ return meta(name, bases, d)
+ @classmethod
+ def __prepare__(cls, name, this_bases):
+ return meta.__prepare__(name, bases)
+ return type.__new__(metaclass, 'temporary_class', (), {})