summaryrefslogtreecommitdiffstats
path: root/Lib/pkgutil.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/pkgutil.py')
-rw-r--r--Lib/pkgutil.py19
1 files changed, 7 insertions, 12 deletions
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index ce072ec..51da0b1 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -1,8 +1,5 @@
"""Utilities to support packages."""
-# NOTE: This module must remain compatible with Python 2.3, as it is shared
-# by setuptools for distribution with Python 2.3 and up.
-
import os
import sys
import imp
@@ -252,7 +249,8 @@ class ImpLoader:
return mod
def get_data(self, pathname):
- return open(pathname, "rb").read()
+ with open(pathname, "rb") as file:
+ return file.read()
def _reopen(self):
if self.file and self.file.closed:
@@ -329,8 +327,7 @@ try:
from zipimport import zipimporter
def iter_zipimport_modules(importer, prefix=''):
- dirlist = zipimport._zip_directory_cache[importer.archive].keys()
- dirlist.sort()
+ dirlist = sorted(zipimport._zip_directory_cache[importer.archive])
_prefix = importer.prefix
plen = len(_prefix)
yielded = {}
@@ -518,15 +515,13 @@ def extend_path(path, name):
return path
pname = os.path.join(*name.split('.')) # Reconstitute as relative path
- # Just in case os.extsep != '.'
- sname = os.extsep.join(name.split('.'))
- sname_pkg = sname + os.extsep + "pkg"
- init_py = "__init__" + os.extsep + "py"
+ sname_pkg = name + ".pkg"
+ init_py = "__init__.py"
path = path[:] # Start with a copy of the existing path
for dir in sys.path:
- if not isinstance(dir, basestring) or not os.path.isdir(dir):
+ if not isinstance(dir, str) or not os.path.isdir(dir):
continue
subdir = os.path.join(dir, pname)
# XXX This may still add duplicate entries to path on
@@ -540,7 +535,7 @@ def extend_path(path, name):
if os.path.isfile(pkgfile):
try:
f = open(pkgfile)
- except IOError, msg:
+ except IOError as msg:
sys.stderr.write("Can't open %s: %s\n" %
(pkgfile, msg))
else: