From: Ned Deily Date: Thu, 6 Oct 2011 21:19:08 +0000 (-0700) Subject: Issue #7367: Fix pkgutil.walk_paths to skip directories whose X-Git-Tag: v3.2.3rc1~522 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ed27df7aaa844d124d8ee25aa93ef74dfac5b191;p=thirdparty%2FPython%2Fcpython.git Issue #7367: Fix pkgutil.walk_paths to skip directories whose contents cannot be read. --- diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py index 2d885683e022..51da0b1bb526 100644 --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -191,8 +191,11 @@ class ImpImporter: yielded = {} import inspect - - filenames = os.listdir(self.path) + try: + filenames = os.listdir(self.path) + except OSError: + # ignore unreadable directories like import does + filenames = [] filenames.sort() # handle packages before same-named modules for fn in filenames: @@ -205,7 +208,12 @@ class ImpImporter: if not modname and os.path.isdir(path) and '.' not in fn: modname = fn - for fn in os.listdir(path): + try: + dircontents = os.listdir(path) + except OSError: + # ignore unreadable directories like import does + dircontents = [] + for fn in dircontents: subname = inspect.getmodulename(fn) if subname=='__init__': ispkg = True