summaryrefslogtreecommitdiff
path: root/compat.py
diff options
context:
space:
mode:
Diffstat (limited to 'compat.py')
-rw-r--r--compat.py32
1 files changed, 15 insertions, 17 deletions
diff --git a/compat.py b/compat.py
index 0ddf81c..86b4dad 100644
--- a/compat.py
+++ b/compat.py
@@ -37,28 +37,28 @@ except NameError:
result.add(val)
return result
__add__ = __or__
-
+
def __and__(self, other):
result = self.__class__()
for val in other:
if val in self._data:
result.add(val)
return result
-
+
def __sub__(self, other):
result = self.__class__(self._data.keys())
for val in other:
if val in self._data:
result.remove(val)
return result
-
+
def __cmp__(self, other):
keys = self._data.keys()
okeys = other._data.keys()
keys.sort()
okeys.sort()
return cmp(keys, okeys)
-
+
def __len__(self):
return len(self._data)
@@ -75,7 +75,7 @@ except NameError:
def __init__(self, values=()):
super(frozenset, self).__init__(values)
self._hashcode = None
-
+
def _compute_hash(self):
"""taken from python stdlib (sets.py)"""
# Calculate hash code for a set by xor'ing the hash codes of
@@ -87,14 +87,14 @@ except NameError:
for elt in self:
result ^= hash(elt)
return result
-
+
def __hash__(self):
"""taken from python stdlib (sets.py)"""
if self._hashcode is None:
self._hashcode = self._compute_hash()
return self._hashcode
-
+
class set(_baseset):
"""mutable set"""
def add(self, value):
@@ -131,7 +131,7 @@ except ImportError:
for it in iterables:
for element in it:
yield element
-
+
def imap(function, *iterables):
iterables = map(iter, iterables)
while True:
@@ -139,7 +139,7 @@ except ImportError:
if function is None:
yield tuple(args)
else:
- yield function(*args)
+ yield function(*args)
try:
sum = sum
enumerate = enumerate
@@ -161,7 +161,7 @@ try:
sorted = sorted
reversed = reversed
except NameError:
-
+
def sorted(iterable, cmp=None, key=None, reverse=False):
original = list(iterable)
if key:
@@ -174,7 +174,7 @@ except NameError:
if key:
return [original[index] for elt, index in l2]
return l2
-
+
def reversed(l):
l2 = list(l)
l2.reverse()
@@ -199,13 +199,13 @@ except TypeError:
items = iter(args[0])
else:
items = iter(args)
-
+
try:
best_item = items.next()
best_value = key(best_item)
except StopIteration:
raise ValueError("max() arg is an empty sequence")
-
+
for item in items:
value = key(item)
if value > best_value:
@@ -215,9 +215,6 @@ except TypeError:
return best_item
-
-
-
# Python2.5 builtins
try:
any = any
@@ -232,7 +229,7 @@ except NameError:
if elt:
return True
return False
-
+
def all(iterable):
"""all(iterable) -> bool
@@ -243,6 +240,7 @@ except NameError:
return False
return True
+
# Python2.5 subprocess added functions and exceptions
from subprocess import Popen
class CalledProcessError(Exception):