os.access giving incorrect results on Windows

Tim Golden mail at timgolden.me.uk
Tue May 24 10:40:53 EDT 2011


On 20/05/2011 12:26, Ayaskanta Swain wrote:
 > Thanks for the reply and suggestions. I followed the patch provided by
 > you in issue 2528, but the code looks very tricky to me.

OK, first a summary of the discussion on the python-dev thread.
Essentially it was felt that os.access was sufficiently shaky
and unuseful on Windows that it was better to deprecate it and
to discourage its use. So I'll be making that change when I
can get round to it.

As to your particular problem here...

Does my_dir already exist? If it does then os.open won't be able
to create it. If it doesn't then I can't see any reason why the
code should fail there. I just ran it myself and it fails, as
expected on an unpatched Python, on the assert on line 17 where
the check is made for the result of os.access for W_OK.

I don't have the time right now but if no-one else gets there
first I hope to be able to post back with a standalone example
of the AccessCheck API

TJG

Anyways I wrote
 > my Test.py script & tried only the def test_access_w(self): test case
 > which is defined under class FileTests(unittest.TestCase) by providing
 > my own directory path to check the write permissions on it.
 >
 > I executed my But it failed with the following errors –
 >
 > *> python Test.py C:\temp\my_dir*
 >
 > test_access_w (__main__.FileTests) ... ERROR
 >
 > ======================================================================
 >
 > ERROR: test_access_w (__main__.FileTests)
 >
 > ----------------------------------------------------------------------
 >
 > Traceback (most recent call last):
 >
 > File "Test.py", line 14, in test_access_w
 >
 > f = os.open(dirpath, os.O_CREAT)
 >
 > OSError: [Errno 13] Permission denied: 'C:\\temp\\my_dir'
 >
 > ----------------------------------------------------------------------
 >
 > Ran 1 test in 0.000s
 >
 > FAILED (errors=1)
 >
 > Basically the os.open() function is failing to open a directory (In this
 > case my_dir). The directory has write permissions for the user. Attached
 > herewith is my Test script. Can you please suggest some simple python
 > code which checks the write permissions of a directory in a straight
 > forward way (Not by using unit tests)
 >
 > Thanks
 >
 > Ayaskant-
 >
 > Bangalore
 >




More information about the Python-list mailing list