[ python-Bugs-1283895 ] os.path.abspath() / os.chdir() buggy with unicode paths

SourceForge.net noreply at sourceforge.net
Fri Sep 9 15:08:17 CEST 2005


Bugs item #1283895, was opened at 2005-09-07 22:30
Message generated for change (Comment added) made by nyamatongwe
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1283895&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Windows
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Antoine Pitrou (pitrou)
Assigned to: Nobody/Anonymous (nobody)
Summary: os.path.abspath() / os.chdir() buggy with unicode paths

Initial Comment:
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'
>>>


----------------------------------------------------------------------

Comment By: Neil Hodgson (nyamatongwe)
Date: 2005-09-09 23:08

Message:
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))

----------------------------------------------------------------------

Comment By: Antoine Pitrou (pitrou)
Date: 2005-09-07 22:36

Message:
Logged In: YES 
user_id=133955

> "C:\Mes Documents\&#12467;&#12500;&#12540; &#65374;
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).


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1283895&group_id=5470


More information about the Python-bugs-list mailing list