[ python-Bugs-846133 ] os.chmod does not work with a unicode
filename
SourceForge.net
noreply at sourceforge.net
Thu Nov 20 19:07:20 EST 2003
Bugs item #846133, was opened at 2003-11-21 06:27
Message generated for change (Comment added) made by quiver
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=846133&group_id=5470
Category: Unicode
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Eric Meyer (meyeet)
Assigned to: M.-A. Lemburg (lemburg)
Summary: os.chmod does not work with a unicode filename
Initial Comment:
I have a filename that contains Kanji characters and I'm
trying change the permissions on the file.
I am running Python 2.3.1 on Windows 2000. Also I
have the japanese language pack installed so that I can
view the kanji characters in Windows explorer.
>>> part
u'\u5171\u6709\u3055\u308c\u308b.txt'
>>> os.chmod(part, 0777)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OSError: [Errno 22] Invalid argument: '?????.txt'
>>>
I attached the above named file for you to test against.
Thanks.
----------------------------------------------------------------------
Comment By: George Yoshida (quiver)
Date: 2003-11-21 09:07
Message:
Logged In: YES
user_id=671362
I'm running Python in almost the same environment.
I guess this results from the different bihavior of u'' and
unicode('').
If you convert a multi-byte character to a unicode
character,
u'' and unicode('') don't return the same string.
unicode'' works as intended but u'' doesn't.
This is probably caused by the bug of Japanese codecs
package.
Eric, please try the session below and tell me what
happens.
NOTE: Japanese codecs needs to be installed to test the
code below.
Otherwise, UnicodeDecodeError will be raised.
---
>>> import os
>>> os.listdir('.')
[]
>>> lst = ['\x82', '\xa0'] # japanese character
>>> u1 = unicode('\x82\xa0')
>>> u2 = u'\x82\xa0'
>>> u1 == u2
False
>>> u1, u2
(u'\u3042', u'\x82\xa0') # u2 is odd
>>> print >> file(u1, 'w'), "hello world"
>>> os.listdir('.')
['あ']
>>> os.chmod(u1, 0777)
>>> os.chmod(u2, 0777)
Traceback (most recent call last):
File "<pyshell#179>", line 1, in -toplevel-
os.chmod(u2, 0777)
OSError: [Errno 22] Invalid argument: '??'
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=846133&group_id=5470
More information about the Python-bugs-list
mailing list