summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2020-03-09 11:49:40 -0700
committerWilliam Deegan <bill@baddogconsulting.com>2020-04-09 13:47:31 -0700
commitf293a449ea7f9d036a85e4d880a2ba7da4751c6a (patch)
treec48f17948a492a997d34453d9e516f5344f91f5f /bin
parentbc94c4e8179b992a2449e06bb6b9a82508f9f6b8 (diff)
downloadscons-git-f293a449ea7f9d036a85e4d880a2ba7da4751c6a.tar.gz
Remove python27 code
Diffstat (limited to 'bin')
-rw-r--r--bin/SConsDoc.py68
1 files changed, 19 insertions, 49 deletions
diff --git a/bin/SConsDoc.py b/bin/SConsDoc.py
index e560a4451..1e88c5b64 100644
--- a/bin/SConsDoc.py
+++ b/bin/SConsDoc.py
@@ -115,8 +115,6 @@ import re
import sys
import copy
-PY2 = sys.version_info[0] == 2
-
# Do we have libxml2/libxslt/lxml?
has_libxml2 = True
try:
@@ -312,20 +310,14 @@ if not has_libxml2:
@staticmethod
def writeGenTree(root, fp):
dt = DoctypeDeclaration()
- try:
- encfun = unicode # PY2
- except NameError:
- encfun = str
+ encfun = str
fp.write(etree.tostring(root, encoding=encfun,
pretty_print=True,
doctype=dt.createDoctype()))
@staticmethod
def writeTree(root, fpath):
- try:
- encfun = unicode # PY2
- except NameError:
- encfun = "utf-8"
+ encfun = "utf-8"
with open(fpath, 'wb') as fp:
fp.write(etree.tostring(root, encoding=encfun,
pretty_print=True))
@@ -859,45 +851,23 @@ class SConsDocHandler(object):
# Parse it
self.parseDomtree(t.root, t.xpath_context, t.nsmap)
-# lifted from Ka-Ping Yee's way cool pydoc module.
-if PY2:
- def importfile(path):
- """Import a Python source file or compiled file given its path."""
- import imp
- magic = imp.get_magic()
- with open(path, 'r') as ifp:
- if ifp.read(len(magic)) == magic:
- kind = imp.PY_COMPILED
- else:
- kind = imp.PY_SOURCE
- filename = os.path.basename(path)
- name, ext = os.path.splitext(filename)
- with open(path, 'r') as ifp:
- try:
- module = imp.load_module(name, ifp, path, (ext, 'r', kind))
- except ImportError as e:
- sys.stderr.write("Could not import %s: %s\n" % (path, e))
- return None
- return module
-
-else: # PY3 version, from newer pydoc
- def importfile(path):
- """Import a Python source file or compiled file given its path."""
- from importlib.util import MAGIC_NUMBER
- with open(path, 'rb') as ifp:
- is_bytecode = MAGIC_NUMBER == ifp.read(len(MAGIC_NUMBER))
- filename = os.path.basename(path)
- name, ext = os.path.splitext(filename)
- if is_bytecode:
- loader = importlib._bootstrap_external.SourcelessFileLoader(name, path)
- else:
- loader = importlib._bootstrap_external.SourceFileLoader(name, path)
- # XXX We probably don't need to pass in the loader here.
- spec = importlib.util.spec_from_file_location(name, path, loader=loader)
- try:
- return importlib._bootstrap._load(spec)
- except ImportError:
- raise ErrorDuringImport(path, sys.exc_info())
+def importfile(path):
+ """Import a Python source file or compiled file given its path."""
+ from importlib.util import MAGIC_NUMBER
+ with open(path, 'rb') as ifp:
+ is_bytecode = MAGIC_NUMBER == ifp.read(len(MAGIC_NUMBER))
+ filename = os.path.basename(path)
+ name, ext = os.path.splitext(filename)
+ if is_bytecode:
+ loader = importlib._bootstrap_external.SourcelessFileLoader(name, path)
+ else:
+ loader = importlib._bootstrap_external.SourceFileLoader(name, path)
+ # XXX We probably don't need to pass in the loader here.
+ spec = importlib.util.spec_from_file_location(name, path, loader=loader)
+ try:
+ return importlib._bootstrap._load(spec)
+ except ImportError:
+ raise ErrorDuringImport(path, sys.exc_info())
# Local Variables:
# tab-width:4