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.
1170
1198
append = dirblock.append
1172
1200
names = sorted(_listdir(top))
1173
except EnvironmentError, e:
1174
# Py 2.4 and earlier will set errno to EINVAL to
1175
# ERROR_DIRECTORY (267). Later versions set it to
1176
# EINVAL and winerror gets set to ERROR_DIRECTORY.
1177
en = getattr(e, 'errno', None)
1178
if (en == errno.ENOTDIR or
1179
(sys.platform=='win32' and en in (267, errno.EINVAL))):
1180
# We have been asked to examine a file, this is fine.
1202
if not _is_error_enotdir(e):
1185
1205
for name in names: