[ python-Bugs-846133 ] os.chmod does not work with a unicode
filename
SourceForge.net
noreply at sourceforge.net
Mon Nov 24 17:21:45 EST 2003
Bugs item #846133, was opened at 2003-11-20 22:27
Message generated for change (Comment added) made by loewis
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: Martin v. Löwis (loewis)
Date: 2003-11-24 23:21
Message:
Logged In: YES
user_id=21627
If you look at the source of os.chmod, it is not at all
surprising that it does not work for characters outside the
file system encoding: it is simply not implemented. Patches
are welcome.
----------------------------------------------------------------------
Comment By: George Yoshida (quiver)
Date: 2003-11-22 01:51
Message:
Logged In: YES
user_id=671362
Hi, Eric.
My previous post was maybe wrong.
This is the problem of os.chmod.
I've confirmed two kinds of exceptions are raised when
using os.chmod for unicode filenames.
The first one is [Errno 22] Invalid argument.
You can read/write a file but cannot use os.chmod.
The second one is [Errno 2] No such file or directory.
Although there exists a file, Python complains "No such
file or directory"
test.test_codecs has a bunch of international unicode
characters, so I borrowed them for testing.
>>> import os
>>> from test.test_codecs import punycode_testcases
>>> def unicode_test(name):
try:
f = file(name, 'w')
f.close()
except IOError, e:
print e
return
try:
os.chmod(name, 0777)
except OSError, e:
print e
>>> for i, (uni, puny) in enumerate
(punycode_testcases):
print i
unicode_test(uni)
I ran this script on Windows 2000(Japanese edition)
using Python 2.3 and got "[Errno 22]" for
0,1,2,3,4,5,7,10 and "[Errno 2]" for 9.
----------------------------------------------------------------------
Comment By: Eric Meyer (meyeet)
Date: 2003-11-21 17:18
Message:
Logged In: YES
user_id=913976
George,
I tried the following but I had to specify one of the japanese
codecs during the unicode() call. What is your default
encoding set to? Below are my results.
>>> import os
>>> os.listdir('.')
[]
>>> u1 = unicode('\x82\xa0', 'cp932')
>>> u2 = u'\x82\xa0'
>>> u1, u2
(u'\u3042', u'\x82\xa0')
>>> print >> file(u1, 'w'), "hello world"
>>> os.listdir('.')
['?']
>>> os.chmod(u1, 0777)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OSError: [Errno 22] Invalid argument: '?'
----------------------------------------------------------------------
Comment By: George Yoshida (quiver)
Date: 2003-11-21 01: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