Author sbt
Recipients brian.curtin, dabrahams, davide.rizzo, dlenski, eric.araujo, eric.smith, jaraco, ncoghlan, pitrou, r.david.murray, sbt, tim.golden
Date 2012-07-01.23:45:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1341186348.92.0.717832797592.issue14243@psf.upfronthosting.co.za>
In-reply-to
Content
I checked the source in

   c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/crt/src/open.c

and it seems that on Windows open() is more or less implemented as a wrapper of sopen(..., ..., SH_DENYNO, ...).

So the only reason that trying to reopen a NamedTemporaryFile fails on Windows is because when we reopen we need to use O_TEMPORARY.

The following works for unmodified python:

  import os, tempfile

  DATA = b"hello bob"

  def temp_opener(name, flag, mode=0o777):
      return os.open(name, flag | os.O_TEMPORARY, mode)

  with tempfile.NamedTemporaryFile() as f:
      f.write(DATA)
      f.flush()
      with open(f.name, "rb", opener=temp_opener) as f:
          assert f.read() == DATA

  assert not os.path.exists(f.name)

So maybe we should just define tempfile.opener().
History
Date User Action Args
2012-07-01 23:45:49sbtsetrecipients: + sbt, jaraco, ncoghlan, pitrou, eric.smith, tim.golden, eric.araujo, r.david.murray, brian.curtin, dabrahams, davide.rizzo, dlenski
2012-07-01 23:45:48sbtsetmessageid: <1341186348.92.0.717832797592.issue14243@psf.upfronthosting.co.za>
2012-07-01 23:45:48sbtlinkissue14243 messages
2012-07-01 23:45:48sbtcreate