[issue12760] Add create mode to open()

2012-05-20 Thread Roundup Robot

Roundup Robot  added the comment:

New changeset ef406c4c6463 by Charles-François Natali in branch 'default':
Issue #12760: Add some mising documentation about the new `x` exclusive
http://hg.python.org/cpython/rev/ef406c4c6463

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-05-19 Thread Petri Lehtinen

Petri Lehtinen  added the comment:

Shouldn't the documentation of builtin open() (in Doc/library/functions.rst) be 
updated too?

--
nosy: +petri.lehtinen

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-14 Thread Charles-François Natali

Charles-François Natali  added the comment:

Thanks, I've committed your version.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-14 Thread Roundup Robot

Roundup Robot  added the comment:

New changeset 8bcbe2dc3835 by Charles-François Natali in branch 'default':
Issue #12760: Refer to the new 'x' open mode as "exclusive creation" mode.
http://hg.python.org/cpython/rev/8bcbe2dc3835

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-11 Thread David Townshend

David Townshend  added the comment:

I've done a bit or rewording in the io docs, but I honestly don't know if this 
is any better that what you already had!

--
Added file: http://bugs.python.org/file24210/x_diff2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-10 Thread Charles-François Natali

Charles-François Natali  added the comment:

Nick suggested to call the new flag "exclusive create" in the doc (and explain 
in whatsnew that it's based C11 new 'x' flag).
Could someone please check the attached patch?
My wording sounds really clumsy, so I'd prefer if a native speaker could review 
it.

--
nosy: +ncoghlan
Added file: http://bugs.python.org/file24195/x_flag.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-09 Thread Charles-François Natali

Charles-François Natali  added the comment:

Committed.
David, thanks for the patch!

--
resolution:  -> fixed
stage: commit review -> committed/rejected
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-09 Thread Roundup Robot

Roundup Robot  added the comment:

New changeset bf609baff4d3 by Charles-François Natali in branch 'default':
Issue #12760: Add a create mode to open(). Patch by David Townshend.
http://hg.python.org/cpython/rev/bf609baff4d3

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-08 Thread Charles-François Natali

Charles-François Natali  added the comment:

> Just a small note: FileExistsError is raised, not exactly OSError,
> when the file exists.

I've updated the doc accordingly.

--
stage: patch review -> commit review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-08 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

> Here's a new version of the patch that should address all the comments.

Just a small note: FileExistsError is raised, not exactly OSError, when
the file exists.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-08 Thread Charles-François Natali

Charles-François Natali  added the comment:

Here's a new version of the patch that should address all the comments.

--
Added file: http://bugs.python.org/file24179/open_create_x-3.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-08 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

I don't think the "created()" method has to be exposed. People can inspect the 
"mode" attribute if they want to have that information.
(besides, the semantics are misleading since a new file opened with "w" has 
also be created, but created() would return False)

There's some bogus indentation in the patch (it uses tab characters in some 
places).

Also:

+if not (creating + reading or writing or appending):

Not sure why the "+". Shouldn't it be "or" instead?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-08 Thread Charles-François Natali

Charles-François Natali  added the comment:

I intend to commit this patch within a couple days (unless anyone objects of 
course).

--
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2012-01-05 Thread Charles-François Natali

Charles-François Natali  added the comment:

I've done a small review.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-12-30 Thread Éric Araujo

Éric Araujo  added the comment:

> [...] There is slightly more versatility with the opener method, but no more 
> obviousness
> and no less typing.

I agree with your opinion.  I re-read this report:
- Antoine thinks this fills an important use case, namely avoiding race 
conditions
- Amaury then suggested the opener argument idea, which was implemented in the 
openat bug
- Antoine judged it would be better than what we had before

I don’t have a strong opinion on “opener is generic and good enough” vs. “not 
as ice as it could be”.  Antoine seems to agree with you, so your patch will 
get reviewed and eventually accepted.  Cheers

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-12-30 Thread Devin Jeanpierre

Devin Jeanpierre  added the comment:

> Amaury did not suggest to use openat, but the new opener argument to open, 
> which was especially added for use cases such as the one discussed here:

Sorry, yes. Wrong words, same thought. We can implement this using opener, but 
we could implement this with os.open before. What's changed, except that 
there's more ways to do it? (There is slightly more versatility with the opener 
method, but no more obviousness and no less typing).

My understanding from reading the other thread is that this is not the primary 
use-case of the new parameter for open(). In fact, this ticket was not really 
mentioned at all there.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-12-30 Thread Éric Araujo

Éric Araujo  added the comment:

> This is not a "duplicate issue". The openat solution is no easier than the 
> os.open
> solution.

Amaury did not suggest to use openat, but the new opener argument to open, 
which was especially added for use cases such as the one discussed here:

...
open_exclusive = lambda path, mode: os.open(path, 
mode|os.O_CREAT|os.O_EXCL))
...
fp = open(filename, 'w', opener=open_exclusive)
...

That’s why this bug was initially closed as duplicate.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-12-27 Thread Chris Rebert

Changes by Chris Rebert :


--
nosy: +cvrebert

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-12-27 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

> C11 uses 'x' for this, for what it's worth.
> 
> This is not a "duplicate issue". The openat solution is no easier than 
> the os.open solution.

Ok, let's re-open then. I'm not sold on the feature, but the fact C11 adds a 
dedicated letter mode for it could be a good excuse for us to mimick it :)

--
resolution: duplicate -> 
status: closed -> open
superseder: io.FileIO and io.open should support openat -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-12-26 Thread Devin Jeanpierre

Devin Jeanpierre  added the comment:

C11 uses 'x' for this, for what it's worth.

This is not a "duplicate issue". The openat solution is no easier than the 
os.open solution.

--
nosy: +Devin Jeanpierre

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-11-18 Thread Éric Araujo

Éric Araujo  added the comment:

See #13424 for a doc request about this.

--
nosy: +eric.araujo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-11-06 Thread David Townshend

David Townshend  added the comment:

It is already possible to write a wrapper function that does it:

def create(file):
fd = os.open(file, os.O_EXCL | os.O_CREAT | os.O_WRONLY)
return os.fdopen(fd)

The point it not that it can't be done, but that it is not straight forward.  
The docs say this about os.open(): "This function is intended for low-level 
I/O. For normal usage, use the built-in function open()" 

I wouldn't call creating a new file low-level I/O, but it is normal usage.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-10-31 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc  added the comment:

issue12797 would allow things like:

def create_exclusive_file(filename):
  return open(filename, "w",
  opener=lambda path, mode: os.open(path, 
mode|os.O_CREAT|os.O_EXCL))

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-10-31 Thread David Townshend

David Townshend  added the comment:

I see this has been marked as a duplicate of http://bugs.python.org/issue12797. 
 Please explain how this is, since that proposal does not appear to provide the 
functionality discussed here.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-10-29 Thread Charles-François Natali

Changes by Charles-François Natali :


--
resolution:  -> duplicate
status: open -> closed
superseder:  -> io.FileIO and io.open should support openat

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-09-08 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis :


--
nosy: +Arfrever

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-24 Thread STINNER Victor

STINNER Victor  added the comment:

>open(filename, 'w',
> fd_opener=lambda path, mode: os.open(path, mode|os.O_CREAT)

I prefer open(name, "c").

> it doesn't fill a use case: actually, avoiding race conditions
> is an important use case, ...

It may help the issue #8604 (and maybe #8828).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-24 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

> What if we can override the inner call to os.open()?
> For example, io.open() could grow an additional argument "fd_opener"
> which defaults to the equivalent of os.open.

I agree it would be a much better situation than what we have now.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-24 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc  added the comment:

> - os.open followed by os.fdopen is easy: it isn't that easy to get
> the incantation right (the pure Python open() in _pyio is 70 lines
> of code), especially if you want the file object to have the right
> "name" attribute

What if we can override the inner call to os.open()?
For example, io.open() could grow an additional argument "fd_opener" which 
defaults to the equivalent of os.open.

Then creation mode can be expressed like this:
open(filename, 'w',
 fd_opener=lambda path, mode: os.open(path, mode|os.O_CREAT)
Another use case with openat (see #12797):
open(filename,
 fd_opener=lambda path, mode: os.openat(fd, path, mode)

--
nosy: +amaury.forgeotdarc

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-24 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

Ah, right. Well I think all arguments against it were quite weak (or even 
wrong). Let's see:

- it's not cross-platform: actually it is (OS_EXCL has been POSIX since at 
least 1997 (*), and Windows also has it)

- os.open followed by os.fdopen is easy: it isn't that easy to get the 
incantation right (the pure Python open() in _pyio is 70 lines of code), 
especially if you want the file object to have the right "name" attribute

- it doesn't fill a use case: actually, avoiding race conditions is an 
important use case, even though many people may never encounter it (I must 
admit I myself never really cared about this)

So this looks like a reasonable feature request IMHO.

(*) http://pubs.opengroup.org/onlinepubs/007908799/xsh/open.html

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-24 Thread Charles-François Natali

Charles-François Natali  added the comment:

> I haven't seen any discussion on python-dev. Have I missed something?

It was on Python-ideas actually:
http://mail.python.org/pipermail/python-ideas/2011-August/011183.html

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-24 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

I haven't seen any discussion on python-dev. Have I missed something?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-24 Thread Charles-François Natali

Charles-François Natali  added the comment:

So, what was the conclusion of the discussion brought up on python-dev?
I had a feeling some core devs were opposed to this (I'm personally -0).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-18 Thread David Townshend

David Townshend  added the comment:

I hope this patch suits you better :-)

I've updated the documentation typo (thanks for pointing that out). I've also 
changed 'c' to 'x', since I think that if there is a convention we should stick 
to it.  I don't think that it matters if the glibc docs say 'exclusive', as 
long it its clear in the python docs what it does, which I think it is. Having 
said that, I don't really have a strong opinion either way, so I'll happily 
change it back to 'c' if its preferred.

--
Added file: http://bugs.python.org/file22935/open_create_x-2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-18 Thread STINNER Victor

STINNER Victor  added the comment:

> I don't know if it's documented behavior

See #12103: it is not documented.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-18 Thread Charles-François Natali

Charles-François Natali  added the comment:

> Yeah, but I think "exclusively" is quite misleading since it does not
> perform any locking of any kind.

It might be misleading, but I find it clear enough, and this name has been 
endorsed by POSIX.

Furthermore, there's an added bonus: actually, with the old I/O layer, one can 
already pass an 'x' flag to open, since it just calls fopen:
"""
cf@neobox:~$ strace -e open python -c "open('/tmp/foo', 'wx')"
[...]
open("/tmp/foo", O_WRONLY|O_CREAT|O_EXCL|O_TRUNC|O_LARGEFILE, 0666) = 3
cf@neobox:~$ strace -e open python -c "open('/tmp/foo', 'wx')"
[...]
open("/usr/lib/pymodules/python2.6/", O_RDONLY|O_LARGEFILE) = -1 ENOENT 
(No such file or directory)
IOError: [Errno 17] File exists: '/tmp/foo'
"""

I don't know if it's documented behavior, but the OP in issue 12105 was using 
it with python 2.
Changing it to 'x' would make such code backward-compatible.

Finally, when I read open('/tmp/foo', 'wx'), it's immediately clear to me 
what's going on, while I'd have to look at open()'s documentation to find out 
what the 'c' flag does.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-18 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

> Well, I'd rather have this flag called 'x', to be consistent with
> glibc's fopen():
> 
> """
>c (since glibc 2.3.3)
>   Do not make the open operation, or subsequent read and write
>   operations, thread cancellation points.
> 
>x  Open the file exclusively (like the O_EXCL flag of
> open(2)).  If the
>   file already exists, fopen() fails, and sets errno to
> EEXIST.  This
>   flag is ignored for fdopen().

Yeah, but I think "exclusively" is quite misleading since it does not
perform any locking of any kind. Also, I don't think we'll ever
integrate the glibc's "c" option in io.open().

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-18 Thread Julian Berman

Julian Berman  added the comment:

A minor documentation error in io.rst line 475 which was changed to:

+   The *mode* can be ``'c'``, ``'r'``, ``'w'`` or ``'a'`` for reading
+   (default), writing, or appending.

and should have "creating" at the front I assume, like you have it later.

--
nosy: +Julian

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-18 Thread David Townshend

David Townshend  added the comment:

Changing form 'c' to 'x' is easy enough, and if there is already a convention 
it makes sense to stick to it.

I thought I had done a mercurial diff! I'll try again and resubmit.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-18 Thread Charles-François Natali

Charles-François Natali  added the comment:

> The "#ifdef O_EXCL" in the source code is probably very old. Copying a 
> message I posted on python-ideas:
>
> O_EXCL is a POSIX standard. It is also supported
> under Windows by the _open/_wopen compatibility functions (which we use
> for file I/O).
>

If it's supported by Windows then I'm OK (not that I personaly care
about Windows :-).

> and is not as easy to read as "open(file, 'c')"

Well, I'd rather have this flag called 'x', to be consistent with
glibc's fopen():

"""
   c (since glibc 2.3.3)
  Do not make the open operation, or subsequent read and write
  operations, thread cancellation points.

   x  Open the file exclusively (like the O_EXCL flag of
open(2)).  If the
  file already exists, fopen() fails, and sets errno to
EEXIST.  This
  flag is ignored for fdopen().
"""

By the way, could you submit your patch as a mercurial diff ("hg diff")?
It makes it easier to review under Rietveld.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-18 Thread David Townshend

David Townshend  added the comment:

My aim isn't to add all the commonly used flags, that would be pointless since 
its already possible using os.open.  The aim is to add a missing feature to the 
builtin open(), i.e. file creation.  At the moment open() implements read, 
write, and append, and creation is only implied by write. But in many cases, an 
explicit creation is desired (i.e, specifically create a new file, with an 
exception on failure).  It is true that this is possible with os.open, but it 
is somewhat obscure, especially for beginners, and is not as easy to read as 
"open(file, 'c')"

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-18 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

The "#ifdef O_EXCL" in the source code is probably very old. Copying a message 
I posted on python-ideas:

O_EXCL is a POSIX standard. It is also supported
under Windows by the _open/_wopen compatibility functions (which we use
for file I/O).

Probably there are very old systems which don't support it, and perhaps
new systems that don't implement it *correctly* (meaning not
atomically); for the former I'd say we just don't care (who's gonna run
Python 3 on a 1995 system?) and for the latter, well, if the OS
designers think it's fine, let's just expose it as it is.

As for NFS, there's an interesting comment from 2007 here:
http://lwn.net/Articles/251971/

“My NFS tester shows that it at least appears to work with Linux,
Solaris and FreeBSD:
http://www.dovecot.org/list/dovecot/2007-July/024102.html. Looking at
Linux 2.6 sources it doesn't look like it tries to implement a racy
O_EXCL check in client side (fs/nfs/nfs3proc.c nfs3_proc_create()), so
the test's results should be correct. I don't know if other OSes do
that. I guess it would be nice to have a better O_EXCL tester which
tries to catch race conditions.”

--
assignee: docs@python -> 
components:  -Documentation, Tests
nosy: +pitrou

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-16 Thread David Townshend

David Townshend  added the comment:

It was discussed on python-ideas, but the subject of the thread was actually on 
shutils.move so it was not really discussed much. I will repost this idea 
separately.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-16 Thread Charles-François Natali

Charles-François Natali  added the comment:

See also issue 12105.
A couple downsides:
- O_EXCL is not necessarily portable (doesn't work well with NFS, maybe not on 
Windows?)
- O_EXCL is useful, as is O_CLOEXEC: to be consistent, we should also end up 
adding all other commonly-used flags, which are really OS-specific

Furthermore, you can achieve the same thing with:
os.fdopen(os.open('/etc/fstab', os.O_WRONLY|os.O_CLOEXEC|os.O_CREAT))
it's more verbose, though.

--
nosy: +neologix

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-16 Thread Benjamin Peterson

Benjamin Peterson  added the comment:

I think this should be brought up on python-ideas or python-dev.

--
nosy: +benjamin.peterson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-16 Thread STINNER Victor

STINNER Victor  added the comment:

I'm not sure that O_EXCL is portable (exist on all platforms) because Python 
source code uses "#ifdef O_EXCL".

--
nosy: +haypo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12760] Add create mode to open()

2011-08-16 Thread David Townshend

New submission from David Townshend :

Currently, opening a file with open(file, 'w') overwrites existing files.  It 
would be useful for open() to raise an error when the file exists.  This 
proposal is to add a 'c' mode to open, which has the effect to creating a file 
and opening it for writing, but raising an IOError if it already exists (i.e. 
the same as os.open(file, os.O_EXCL|os.O_CREAT).

The attached patch implements this, including tests and documentation.

--
assignee: docs@python
components: Documentation, IO, Library (Lib), Tests
files: open_create.patch
keywords: patch
messages: 142193
nosy: David.Townshend, docs@python
priority: normal
severity: normal
status: open
title: Add create mode to open()
type: feature request
versions: Python 3.3
Added file: http://bugs.python.org/file22910/open_create.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com