[Zope3-dev] Re: [Zope3-checkins] CVS: Zope3/lib/python/Zope/Configuration/tests - testXML.py:1.6

R. David Murray bitz@bitdance.com
Wed, 20 Nov 2002 14:24:27 -0500 (EST)


On Wed, 13 Nov 2002, Tim Peters wrote:
> Update of /cvs-repository/Zope3/lib/python/Zope/Configuration/tests
> In directory cvs.zope.org:/tmp/cvs-serv1238/lib/python/Zope/Configuration/tests
>
> Modified Files:
> 	testXML.py
> Log Message:
> The use of NamedTemporaryFile here doesn't work on Windows flavors at or
> after Win2K, and that's not shallow (temp files are faked on Windows
> via the Win O_TEMPORARY flag, and that has more than one effect on
> file semantics).  So used a different gimmick that should work everywhere.
[...]
> +# Caution:  tempfile.NamedTemporaryFile cannot be used on Windows, because
> +# the tests here want to open the file more than once.  You can't do that
> +# with an O_TEMPORARY file on Win2K (or higher).
> +import tempfile
> +
> +class TempFile:
[...]
> +    def __init__(self):
> +        self.file = open(tempfile.mktemp(), 'w')
> +        self.closed = 0
[...]
>      def testInclude(self):
> -        file = NamedTemporaryFile()
> +        file = TempFile()

My point in writing it the way I did originally, using NamedTemporaryFile
if it existed (2.3) and a dummy class if it didn't (2.2) was to
avoid the security warning running under 2.3.  Since mktemp is the
thing that generates the security warning, this change means the
security warning comes back.  (Not that you can tell; there are
a bunch of tests that currently generate this warning running
under 2.3).

So, what is the *correct* (secure) way to do temporary files
cross-platform when you need to be able to open the file again by
name after creating it?  (And yes, Tim, I realize that according
to your previous email about cross platform issues the answer is
"no" <grin>).

Oh, yeah, and there aren't any notes in the docs of NamedTemporaryFile
that say you *can't* open it twice on Windows.  And come to think
of it, given the description of how it works under Unix (removing
the directory entry as soon as it is created), how is it that my
original code even worked on Unix?

more-confused-now-than-when-I-started'ly yours,
                                 RDM