[Python-checkins] cpython (3.2): Issue #12802: the Windows error ERROR_DIRECTORY (numbered 267) is now

antoine.pitrou python-checkins at python.org
Thu Sep 1 21:41:13 CEST 2011


http://hg.python.org/cpython/rev/385c2ec78f16
changeset: 72163:385c2ec78f16
branch: 3.2
parent: 72160:106c57d52b47
user: Antoine Pitrou <solipsis at pitrou.net>
date: Thu Sep 01 21:37:43 2011 +0200
summary:
 Issue #12802: the Windows error ERROR_DIRECTORY (numbered 267) is now
mapped to POSIX errno ENOTDIR (previously EINVAL).
files:
 Lib/test/test_exceptions.py | 8 ++++++++
 Misc/NEWS | 3 +++
 PC/errmap.h | 1 +
 PC/generrmap.c | 21 +++++++++++++++------
 4 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -5,6 +5,7 @@
 import unittest
 import pickle
 import weakref
+import errno
 
 from test.support import (TESTFN, unlink, run_unittest, captured_output,
 gc_collect, cpython_only)
@@ -849,6 +850,13 @@
 self.fail("RuntimeError not raised")
 self.assertEqual(wr(), None)
 
+ def test_errno_ENOTDIR(self):
+ # Issue #12802: "not a directory" errors are ENOTDIR even on Windows
+ with self.assertRaises(OSError) as cm:
+ os.listdir(__file__)
+ self.assertEqual(cm.exception.errno, errno.ENOTDIR, cm.exception)
+
+
 def test_main():
 run_unittest(ExceptionTests)
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #12802: the Windows error ERROR_DIRECTORY (numbered 267) is now
+ mapped to POSIX errno ENOTDIR (previously EINVAL).
+
 - Accept bytes for the AST string type. This is temporary until a proper fix in
 3.3.
 
diff --git a/PC/errmap.h b/PC/errmap.h
--- a/PC/errmap.h
+++ b/PC/errmap.h
@@ -72,6 +72,7 @@
 case 202: return 8;
 case 206: return 2;
 case 215: return 11;
+ case 267: return 20;
 case 1816: return 12;
 default: return EINVAL;
 }
diff --git a/PC/generrmap.c b/PC/generrmap.c
--- a/PC/generrmap.c
+++ b/PC/generrmap.c
@@ -1,3 +1,6 @@
+#include <windows.h>
+#include <fcntl.h>
+#include <io.h>
 #include <stdio.h>
 #include <errno.h>
 
@@ -6,15 +9,21 @@
 int main()
 {
 int i;
+ _setmode(fileno(stdout), O_BINARY);
 printf("/* Generated file. Do not edit. */\n");
 printf("int winerror_to_errno(int winerror)\n");
- printf("{\n\tswitch(winerror) {\n");
+ printf("{\n switch(winerror) {\n");
 for(i=1; i < 65000; i++) {
 _dosmaperr(i);
- if (errno == EINVAL)
- continue;
- printf("\t\tcase %d: return %d;\n", i, errno);
+ if (errno == EINVAL) {
+ /* Issue #12802 */
+ if (i == ERROR_DIRECTORY)
+ errno = ENOTDIR;
+ else
+ continue;
+ }
+ printf(" case %d: return %d;\n", i, errno);
 }
- printf("\t\tdefault: return EINVAL;\n");
- printf("\t}\n}\n");
+ printf(" default: return EINVAL;\n");
+ printf(" }\n}\n");
 }
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /