diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-03-13 20:12:05 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-03-13 20:12:05 -0500 |
commit | 78e2e6eb38d229cfcd4d0202f27761cd5bab2495 (patch) | |
tree | 93866af62ea60710682aaa5a6e709b55cd29b69b /coverage/backward.py | |
parent | 543ff12a09952b132abd9aa863d4170c4e2523f4 (diff) | |
parent | a5e4aa218a749f9ea73bccea4cac92bd35387451 (diff) | |
download | python-coveragepy-78e2e6eb38d229cfcd4d0202f27761cd5bab2495.tar.gz |
Merged Ben Finney's use-os-path-module fixes (again?)
Diffstat (limited to 'coverage/backward.py')
-rw-r--r-- | coverage/backward.py | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/coverage/backward.py b/coverage/backward.py index 66cfbb9..425bcc6 100644 --- a/coverage/backward.py +++ b/coverage/backward.py @@ -14,7 +14,6 @@ try: except NameError: from sets import Set as set - # Python 2.3 doesn't have `sorted`. try: sorted = sorted @@ -26,7 +25,6 @@ except NameError: return lst # Pythons 2 and 3 differ on where to get StringIO - try: from cStringIO import StringIO BytesIO = StringIO @@ -34,39 +32,42 @@ except ImportError: from io import StringIO, BytesIO # What's a string called? - try: string_class = basestring except NameError: string_class = str # Where do pickles come from? - try: import cPickle as pickle except ImportError: import pickle # range or xrange? - try: range = xrange except NameError: range = range # Exec is a statement in Py2, a function in Py3 - -if sys.hexversion > 0x03000000: - def exec_function(source, filename, global_map): +if sys.version_info >= (3, 0): + def exec_code_object(code, global_map): """A wrapper around exec().""" - exec(compile(source, filename, "exec"), global_map) + exec(code, global_map) else: # OK, this is pretty gross. In Py2, exec was a statement, but that will # be a syntax error if we try to put it in a Py3 file, even if it is never # executed. So hide it inside an evaluated string literal instead. - eval(compile("""\ -def exec_function(source, filename, global_map): - exec compile(source, filename, "exec") in global_map -""", - "<exec_function>", "exec" - )) + eval( + compile( + "def exec_code_object(code, global_map):\n" + " exec code in global_map\n", + "<exec_function>", "exec" + ) + ) + +# ConfigParser was renamed to the more-standard configparser +try: + import configparser +except ImportError: + import ConfigParser as configparser |