Issue #15478: Raising an OSError doesn't decode or encode the filename anymore

Pass the original filename argument to OSError constructor, instead of trying
to encode it to or decode it from the filesystem encoding. This change avoids
an additionnal UnicodeDecodeError on Windows if the filename cannot be decoded
from the filesystem encoding (ANSI code page).
This commit is contained in:
Victor Stinner 2012-10-30 02:17:38 +01:00
parent 76df43de30
commit 292c835548
5 changed files with 199 additions and 108 deletions

View file

@ -647,6 +647,17 @@ elif sys.platform != 'darwin':
# the byte 0xff. Skip some unicode filename tests.
pass
# TESTFN_UNDECODABLE is a filename (bytes type) that should *not* be able to be
# decoded from the filesystem encoding (in strict mode). It can be None if we
# cannot generate such filename.
TESTFN_UNDECODABLE = None
for name in (b'abc\xff', b'\xe7w\xf0'):
try:
os.fsdecode(name)
except UnicodeDecodeErorr:
TESTFN_UNDECODABLE = name
break
# Save the initial cwd
SAVEDCWD = os.getcwd()