summaryrefslogtreecommitdiff
path: root/coverage/backward.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/backward.py')
-rw-r--r--coverage/backward.py41
1 files changed, 35 insertions, 6 deletions
diff --git a/coverage/backward.py b/coverage/backward.py
index 637a5976..54e46254 100644
--- a/coverage/backward.py
+++ b/coverage/backward.py
@@ -24,6 +24,31 @@ except NameError:
lst.sort()
return lst
+# Python 2.3 doesn't have `reversed`.
+try:
+ reversed = reversed
+except NameError:
+ def reversed(iterable):
+ """A 2.3-compatible implementation of `reversed`."""
+ lst = list(iterable)
+ return lst[::-1]
+
+# rpartition is new in 2.5
+try:
+ "".rpartition
+except AttributeError:
+ def rpartition(s, sep):
+ """Implement s.rpartition(sep) for old Pythons."""
+ i = s.rfind(sep)
+ if i == -1:
+ return ('', '', s)
+ else:
+ return (s[:i], sep, s[i+len(sep):])
+else:
+ def rpartition(s, sep):
+ """A common interface for new Pythons."""
+ return s.rpartition(sep)
+
# Pythons 2 and 3 differ on where to get StringIO
try:
from cStringIO import StringIO
@@ -49,6 +74,16 @@ try:
except NameError:
range = range
+# A function to iterate listlessly over a dict's items.
+if "iteritems" in dir({}):
+ def iitems(d):
+ """Produce the items from dict `d`."""
+ return d.iteritems()
+else:
+ def iitems(d):
+ """Produce the items from dict `d`."""
+ return d.items()
+
# Exec is a statement in Py2, a function in Py3
if sys.version_info >= (3, 0):
def exec_code_object(code, global_map):
@@ -66,12 +101,6 @@ else:
)
)
-# ConfigParser was renamed to the more-standard configparser
-try:
- import configparser
-except ImportError:
- import ConfigParser as configparser
-
# Reading Python source and interpreting the coding comment is a big deal.
if sys.version_info >= (3, 0):
# Python 3.2 provides `tokenize.open`, the best way to open source files.