Issue1283895
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2005-09-07 12:30 by pitrou, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (6) | |||
---|---|---|---|
msg26228 - (view) | Author: Antoine Pitrou (pitrou) * | Date: 2005-09-07 12:30 | |
Hi, Under Windows Explorer, one can create directory names using characters not belonging to the user locale. For example, one of our users created a directory named "C:\Mes Documents\³Ôü ^ solipsis_svn". Unfortunately, when trying to manipulate such a pathname, os.path.abspath() and os.chdir() don't work hand in hand. os.path.abspath() uses the garbled directory name as displayed by the command prompt and then os.chdir() refuses the path: C:\>cd "C:\Mes Documents\??? ~ solipsis_svn" C:\Mes Documents\??? ~ solipsis_svn>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import os >>> os.curdir '.' >>> os.path.abspath(os.curdir) 'C:\\Mes Documents\\??? ~ solipsis_svn' >>> os.chdir(os.path.abspath(os.curdir)) Traceback (most recent call last): File "<stdin>", line 1, in ? OSError: [Errno 22] Invalid argument: 'C:\\Mes Documents\\??? ~ solipsis_svn' >>> |
|||
msg26229 - (view) | Author: Antoine Pitrou (pitrou) * | Date: 2005-09-07 12:36 | |
Logged In: YES user_id=133955 > "C:\Mes Documents\³Ôü ^ solipsis_svn" Gasp. Sourceforge escapes HTML entities instead of showing the real characters... These are Japanese characters, btw. It's easy to copy/paste some Japanese characters from a Web site and paste them into Windows Explorer to create a directory (at least it works with Mozilla Firefox). |
|||
msg26230 - (view) | Author: Neil Hodgson (nyamatongwe) | Date: 2005-09-09 13:08 | |
Logged In: YES user_id=12579 This is using byte string arguments causing byte string processing rather than unicode calls with unicode processing. Windows code that may encounter file paths outside the default locale should stick to unicode for paths. Try converting os.curdir to unicode before calling other functions: os.path.abspath(unicode(os.curdir)) |
|||
msg26231 - (view) | Author: Martin v. Löwis (loewis) * | Date: 2006-07-24 13:02 | |
Logged In: YES user_id=21627 This is not a bug. You need to use Unicode path names to operate on files with names outside of the system code page. |
|||
msg26232 - (view) | Author: Antoine Pitrou (pitrou) * | Date: 2006-07-24 13:10 | |
Logged In: YES user_id=133955 Then why doesn't abspath() throw an exception instead of silently returning a bogus result? Its behaviour is counter-intuitive and produces hard-to-find bugs. |
|||
msg26233 - (view) | Author: Martin v. Löwis (loewis) * | Date: 2006-07-24 20:01 | |
Logged In: YES user_id=21627 abspath invokes getcwd() for a relative string; this, in turn, invokes the C library function getcwd(); this, in turn, invokes GetCurrentDirectoryA(); this, in turn, already returns a bogus response. So it is Windows that returns a bogus response; there is nothing Python can do here. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:12 | admin | set | github: 42349 |
2005-09-07 12:30:46 | pitrou | create |