From 7f34f6b89c5d44f96856adfcea30a47d525f4c64 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 26 Sep 2012 14:13:04 -0400 Subject: wrote docs for Bcfg2.Compat --- src/lib/Bcfg2/Compat.py | 55 ++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) (limited to 'src') 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 -- cgit v1.2.3-1-g7c22