[Merge] lp:~jameinel/bzr/2.1.0b4-win32-fancy-rename-exception into lp:bzr

John Arbash Meinel john at arbash-meinel.com
Fri Nov 20 15:19:43 GMT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent Ladeuil wrote:
>>>>>> "jam" == John Arbash Meinel <john at arbash-meinel.com> writes:
> 
> <snip/>
> 
>     >> def create_file(self, content, file_name=None,
>     >> prefix='mytest', suffix='.tmp',
>     >> cleanup=True):
>     >> if file_name is None:
>     >> fileno, file_name = tempfile.mkstemp(suffix=suffix,
>     >> prefix=prefix)
>     >> f = os.fdopen(fileno, 'w+')
> 
>     jam> ^- This is generally much clearer as:
> 
>     jam> f = tempfile.TemporaryFile(suffix=suffix, prefix=prefix)
> 
>     jam> At least, IMO.
> 
> Sure. But where did you get the file_name then ?
> 
>       Vincent
> 

Well, f.name works. If you want to be more cautious you can use
NamedTemporaryFile.

However, neither of them actually lets you "open(fname)" on Windows.
(The permissions end up set so that the file cannot be re-opened again,
which seems pretty stupid for something called NamedTemporaryFile.)

Anyway, there are a lot of possible permutations for this sort of thing,
and it would depend on what tests actually need.

build_tree_contents()

Usually works just fine for whenever I've actually needed this sort of
thing.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksGs48ACgkQJdeBCYSNAAPO3wCgrHgyJ+cTrUFuGB2MNKArxICv
8P4AoK/wv328V51eJeso4hxjse7uHFoA
=Ht/W
-----END PGP SIGNATURE-----



More information about the bazaar mailing list