1119
1119
raise errors.IllegalPath(path)
1122
_WIN32_ERROR_DIRECTORY = 267 # Similar to errno.ENOTDIR
1124
def _is_error_enotdir(e):
1125
"""Check if this exception represents ENOTDIR.
1127
Unfortunately, python is very inconsistent about the exception
1128
here. The cases are:
1129
1) Linux, Mac OSX all versions seem to set errno == ENOTDIR
1130
2) Windows, Python2.4, uses errno == ERROR_DIRECTORY (267)
1131
which is the windows error code.
1132
3) Windows, Python2.5 uses errno == EINVAL and
1133
winerror == ERROR_DIRECTORY
1135
:param e: An Exception object (expected to be OSError with an errno
1136
attribute, but we should be able to cope with anything)
1137
:return: True if this represents an ENOTDIR error. False otherwise.
1139
en = getattr(e, 'errno', None)
1140
if (en == errno.ENOTDIR
1141
or (sys.platform == 'win32'
1142
and (en == _WIN32_ERROR_DIRECTORY
1143
or (en == errno.EINVAL
1144
and getattr(e, 'winerror', None) == _WIN32_ERROR_DIRECTORY)
1122
1150
def walkdirs(top, prefix=""):
1123
1151
"""Yield data about all the directories in a tree.
1172
1200
names = sorted(_listdir(top))
1173
1201
except OSError, e:
1174
if getattr(e, 'errno', None) == errno.ENOTDIR:
1175
# We have been asked to examine a file, this is fine.
1202
if not _is_error_enotdir(e):
1180
1205
for name in names: