Title: open fails on write-only files
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: dcoles, santa4nt, zyasoft
Priority: Keywords: patch

Created on 2013-08-29.21:17:59 by dcoles, last changed 2015-01-28.19:15:47 by zyasoft.

File name Uploaded Description Edit Remove
issue2081.patch santa4nt, 2013-09-03.21:05:59
issue2081.patch santa4nt, 2015-01-21.06:46:51 Patch refresh, with unit test
msg8096 (view) Author: David Coles (dcoles) Date: 2013-08-29.21:17:58
Jython can't open files with write-only permission (write-bit is set, but read-bit is not set).

This appears to be due to using which only supports "r" or "rw" modes. The same file can be opened from Jython by using Java's

How to reproduce:

  $ touch /tmp/write-only-file
  $ chmod 200 /tmp/write-only-file
  $ jython2.7 --version
  Jython 2.7b1+
  $ jython2.7 -c 'f = open("/tmp/write-only-file", "w"); print(f)'
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  IOError: [Errno 13] Permission denied: '/tmp/write-only-file'

Expected behavior:

  $ python -c 'f = open("/tmp/write-only-file", "w"); print(f)'
  <_io.TextIOWrapper name='/tmp/write-only-file' mode='w' encoding='ANSI_X3.4-1968'>

It seems like also has the same problem:

  $ jython2.7 -c 'import os; fd ="/tmp/write-only-file", os.O_WRONLY); print(fd)'
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  IOError: [Errno 13] Permission denied: '/tmp/write-only-file'
msg8097 (view) Author: David Coles (dcoles) Date: 2013-08-29.21:27:15
This is probably the cause of issue1856 since the file they attempted to open has the same write-only permissions.

$ ls -l /sys/block/sdc/device/delete 
--w------- 1 root root 4096 Aug 29 14:01 /sys/block/sdc/device/delete
msg8098 (view) Author: Santoso Wijaya (santa4nt) Date: 2013-09-03.21:05:59
This is because the underlying FileIO object uses Java's RandomAccessFile object to open the file, which cannot open files in write-only mode.

Attaching a possible quickfix.
msg9421 (view) Author: Jim Baker (zyasoft) Date: 2015-01-18.16:08:02
Santoso, can you follow up on your patch? I assume we just need a test here.
msg9422 (view) Author: Santoso Wijaya (santa4nt) Date: 2015-01-18.19:40:37
Ah, completely forgot about this. Will do!

On Sun, Jan 18, 2015, 8:08 AM Jim Baker <> wrote:

> Jim Baker added the comment:
> Santoso, can you follow up on your patch? I assume we just need a test
> here.
> _______________________________________
> Jython tracker <>
> <>
> _______________________________________
msg9433 (view) Author: Santoso Wijaya (santa4nt) Date: 2015-01-21.06:46:51
Updated the patch, plus unit test.
msg9435 (view) Author: Jim Baker (zyasoft) Date: 2015-01-21.17:33:20
+1, looks good to me. We might be able to figure out how to test on platforms that don't support chmod AND support write-only (assuming there is even such a platform), but regardless we should have correct logic given what we have from Java.

Santoso, please do commit this patch.
msg9436 (view) Author: Santoso Wijaya (santa4nt) Date: 2015-01-21.17:38:30
Done. Check-in 62f6e0189460.
Date User Action Args
2015-01-28 19:15:47zyasoftsetstatus: pending -> closed
2015-01-21 17:39:17zyasoftsetstatus: open -> pending
resolution: fixed
2015-01-21 17:38:30santa4ntsetmessages: + msg9436
2015-01-21 17:33:21zyasoftsetmessages: + msg9435
2015-01-21 06:46:52santa4ntsetfiles: + issue2081.patch
messages: + msg9433
2015-01-20 18:47:23santa4ntsetfiles: - unnamed
2015-01-18 19:40:37santa4ntsetfiles: + unnamed
messages: + msg9422
2015-01-18 16:08:03zyasoftsetmessages: + msg9421
2014-07-05 02:45:18zyasoftsetnosy: + zyasoft
2013-09-03 21:06:00santa4ntsetfiles: + issue2081.patch
keywords: + patch
messages: + msg8098
nosy: + santa4nt
2013-08-29 21:27:15dcolessetmessages: + msg8097
2013-08-29 21:17:59dcolescreate