summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Jehannet <julien.jehannet@logilab.fr>2010-09-28 19:26:39 +0200
committerJulien Jehannet <julien.jehannet@logilab.fr>2010-09-28 19:26:39 +0200
commitfc9595aa552e6b0f24a76ab7c07d301d206f6824 (patch)
treec45f5b1dd8d3c810611d6ab0c57f7d8761618942
parent2bdda99f2a51296bff1a93f263974d0db27f08cf (diff)
downloadlogilab-common-fc9595aa552e6b0f24a76ab7c07d301d206f6824.tar.gz
[compat] add compat import + update docstring
-rw-r--r--compat.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/compat.py b/compat.py
index cc55532..ad18834 100644
--- a/compat.py
+++ b/compat.py
@@ -18,6 +18,12 @@
# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
"""Wrappers around some builtins introduced in python 2.3, 2.4 and
2.5, making them available in for earlier versions of python.
+
+See another compatibility snippets from other projects:
+
+ :mod:`lib2to3.fixes`
+ :mod:`coverage.backward`
+ :mod:``unittest2.compatibility
"""
from __future__ import generators
@@ -57,13 +63,21 @@ if sys.version_info < (3, 0):
else:
raw_input = input
+# Pythons 2 and 3 differ on where to get StringIO
if sys.version_info < (3, 0):
+ from cStringIO import StringIO
FileIO = file
+ BytesIO = StringIO
else:
- import io
- FileIO = io.FileIO
- del io
+ from io import FileIO, BytesIO, StringIO
+
+# Where do pickles come from?
+try:
+ import cPickle as pickle
+except ImportError:
+ import pickle
+# Python 2.3 doesn't have `set`
try:
set = set
frozenset = frozenset
@@ -371,4 +385,15 @@ else:
obj = set.__new__(cls, *new_args)
obj.__init__(*args, **kwargs)
return obj
-
+
+# range or xrange?
+try:
+ range = xrange
+except NameError:
+ range = range
+
+# ConfigParser was renamed to the more-standard configparser
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser