summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Compat.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-26 14:13:04 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-26 14:13:04 -0400
commit7f34f6b89c5d44f96856adfcea30a47d525f4c64 (patch)
tree43364bbe2c23497ea113c1a8d8f2cf8c35854dc7 /src/lib/Bcfg2/Compat.py
parent552fa7b683dcdcbbc58dc2871e31f54d8db14a64 (diff)
downloadbcfg2-7f34f6b89c5d44f96856adfcea30a47d525f4c64.tar.gz
bcfg2-7f34f6b89c5d44f96856adfcea30a47d525f4c64.tar.bz2
bcfg2-7f34f6b89c5d44f96856adfcea30a47d525f4c64.zip
wrote docs for Bcfg2.Compat
Diffstat (limited to 'src/lib/Bcfg2/Compat.py')
-rw-r--r--src/lib/Bcfg2/Compat.py55
1 files changed, 20 insertions, 35 deletions
diff --git a/src/lib/Bcfg2/Compat.py b/src/lib/Bcfg2/Compat.py
index 635c49a49..9399fc440 100644
--- a/src/lib/Bcfg2/Compat.py
+++ b/src/lib/Bcfg2/Compat.py
@@ -13,22 +13,14 @@ except ImportError:
# urllib imports
try:
from urlparse import urljoin, urlparse
- from urllib2 import HTTPBasicAuthHandler
- from urllib2 import HTTPPasswordMgrWithDefaultRealm
- from urllib2 import build_opener
- from urllib2 import install_opener
- from urllib2 import urlopen
- from urllib2 import HTTPError
- from urllib2 import URLError
+ from urllib2 import HTTPBasicAuthHandler, \
+ HTTPPasswordMgrWithDefaultRealm, build_opener, install_opener, \
+ urlopen, HTTPError, URLError
except ImportError:
from urllib.parse import urljoin, urlparse
- from urllib.request import HTTPBasicAuthHandler
- from urllib.request import HTTPPasswordMgrWithDefaultRealm
- from urllib.request import build_opener
- from urllib.request import install_opener
- from urllib.request import urlopen
- from urllib.error import HTTPError
- from urllib.error import URLError
+ from urllib.request import HTTPBasicAuthHandler, \
+ HTTPPasswordMgrWithDefaultRealm, build_opener, install_opener, urlopen
+ from urllib.error import HTTPError, URLError
try:
from cStringIO import StringIO
@@ -69,12 +61,10 @@ try:
except ImportError:
import http.client as httplib
-# py3k compatibility
-if sys.hexversion >= 0x03000000:
- unicode = str
-else:
+try:
unicode = unicode
-
+except NameError:
+ unicode = str
def u_str(string, encoding=None):
""" print to file compatibility """
@@ -89,11 +79,6 @@ def u_str(string, encoding=None):
else:
return unicode(string)
-try:
- unicode = unicode
-except NameError:
- unicode = str
-
# base64 compat
if sys.hexversion >= 0x03000000:
from base64 import b64encode as _b64encode, b64decode as _b64decode
@@ -119,8 +104,9 @@ except ImportError:
class CmpMixin(object):
- """ in py3k __cmp__ is no longer magical, so this mixin can be
- used to define the rich comparison operators from __cmp__ """
+ """ In Py3K, :meth:`object.__cmp__` is no longer magical, so this
+ mixin can be used to define the rich comparison operators from
+ ``__cmp__`` -- i.e., it makes ``__cmp__`` magical again. """
def __lt__(self, other):
return self.__cmp__(other) < 0
@@ -184,15 +170,14 @@ except ImportError:
import os
def walk_packages(path=None, prefix='', onerror=None):
- """ imperfect, incomplete implementation of
- walk_packages() for python 2.4. Differences:
-
- * requires a full path, not a path relative to something
- in sys.path. anywhere we care about that shouldn't be
- an issue
-
- * the first element of each tuple is None instead of an
- importer object
+ """ Imperfect, incomplete implementation of
+ :func:`pkgutil.walk_packages` for python 2.4. Differences:
+
+ * Requires a full path, not a path relative to something
+ in sys.path. Anywhere we care about that shouldn't be
+ an issue.
+ * The first element of each tuple is None instead of an
+ importer object.
"""
if path is None:
path = sys.path