classification
Title: os.path.abspath with unicode argument should call os.getcwdu
Type: behavior Stage:
Components: Unicode Versions: Python 2.7, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, ezio.melotti, saturn_mimas (3)
Priority: normal Keywords

Created on 2008-07-22 14:32 by saturn_mimas, last changed 2009-07-04 03:06 by ezio.melotti.

Messages (3)
msg70148 - (view) Author: Christian Häggström (saturn_mimas) Date: 2008-07-22 14:32
If current working directory contains non-ascii characters, calling
os.path.abspath(u".") will result in an error. I expect it to call the
underlying os.getcwdu() in this case.

>>> import os
>>> os.path.abspath(u".")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/home/packages/python-2.5.1/x86-linux/lib/python2.5/posixpath.py", line
403, in abspath
    path = join(os.getcwd(), path)
  File
"/home/packages/python-2.5.1/x86-linux/lib/python2.5/posixpath.py", line
65, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 29:
ordinal not in range(128)

It works if I do it manually, using os.getcwdu():

>>> os.path.join(os.getcwdu(), u".")
u'/disk1/chn_local/work/test/sk\xe4rg\xe5rds\xf6-latin1/.'
msg70151 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) Date: 2008-07-22 15:52
Well, os.path.supports_unicode_filenames is False on posix platforms.
So os.path.abspath is not supposed to work with unicode values.

I was about to close the issue, but python 3.0 also defines
supports_unicode_filenames to False! In addition, os.getcwd() fails when
the current dir has non-ascii characters. Should we drop its
implementation, and use os.getcwdu instead?
msg90101 - (view) Author: Ezio Melotti (ezio.melotti) Date: 2009-07-04 03:06
This seems to work fine with Py 3.0 and 3.1 on Linux, it still fails
with Py 2.6 and 2.7.
History
Date User Action Args
2009-07-04 03:06:28ezio.melottisetpriority: normal
versions: + Python 2.6, Python 2.7, - Python 2.5, Python 2.4, Python 3.0
nosy: + ezio.melotti

messages: + msg90101
2008-07-22 15:52:32amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg70151
versions: + Python 3.0
2008-07-22 14:32:13saturn_mimascreate