[issue17673] add `copy_from` argument to temporaryfile

2013-04-29 Thread Kyle Roberts
Kyle Roberts added the comment: Thanks for the comments Antoine. I didn't have a good reason for using the file name at the time, although even when using the file name I should have used the file variable that was already created. I tried using the file descriptor, but I encountered a [Errno

[issue17673] add `copy_from` argument to temporaryfile

2013-04-17 Thread R. David Murray
R. David Murray added the comment: Personally I prefer having the test create the needed test file, rather than adding a new file to the repository, for small files. That's just my opinion, though; as you found what you did is common practice currently. Your patch doesn't include the file,

[issue17673] add `copy_from` argument to temporaryfile

2013-04-17 Thread Kyle Roberts
Kyle Roberts added the comment: Thanks for the quick response. The test file is sandwiched in between the two patch files, so it's easy to miss. You made a great point about not cluttering up the repo with any unnecessary files. I'll change the test methods to create a new copy_from file

[issue17673] add `copy_from` argument to temporaryfile

2013-04-17 Thread R. David Murray
R. David Murray added the comment: I did miss it. Not that it matters if you are going to rewrite the test, but FYI you can include new files in a patch by adding them ('hg add') before doing the 'hg diff' to generate the patch. -- ___ Python

[issue17673] add `copy_from` argument to temporaryfile

2013-04-17 Thread Kyle Roberts
Kyle Roberts added the comment: Very cool, I didn't think it'd be included in the patch for some reason. Thanks! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17673 ___

[issue17673] add `copy_from` argument to temporaryfile

2013-04-17 Thread Antoine Pitrou
Antoine Pitrou added the comment: Some comments about the patch: - unless I'm missing something, I think you should re-use the fd instead of reopening the file by name - it would be nice if copy_from accepted an open file-like object, e.g. a BytesIO instance - I don't think you need a specific

[issue17673] add `copy_from` argument to temporaryfile

2013-04-16 Thread Kyle Roberts
Kyle Roberts added the comment: Attached is a patch to include the copy_from argument in mkstemp, TemporaryFile, and NamedTemporaryFile. Also attached is a text file for testing the copy operation. Some notes: I intended to use shutil's copyfile(src, dst) method to copy the copy_from file

[issue17673] add `copy_from` argument to temporaryfile

2013-04-16 Thread Kyle Roberts
Changes by Kyle Roberts roberts...@gmail.com: Added file: http://bugs.python.org/file29896/copy_from_test.txt ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17673 ___

[issue17673] add `copy_from` argument to temporaryfile

2013-04-16 Thread Kyle Roberts
Kyle Roberts added the comment: Sorry, disregard my second question about finding a test file. I found an example in test_mailcap.py. I've uploaded a new patch with the cleaner test functions. -- Added file: http://bugs.python.org/file29897/copy_from_v2.patch

[issue17673] add `copy_from` argument to temporaryfile

2013-04-15 Thread Kyle Roberts
Kyle Roberts added the comment: I think `copy_from` should be included for mkstemp as well. It provides similar functionality to TemporaryFile and NamedTemporaryFile, but it doesn't delete the temp file on close as the other two do by default. Thoughts? --

[issue17673] add `copy_from` argument to temporaryfile

2013-04-12 Thread Kyle Roberts
Kyle Roberts added the comment: I'm working on a patch for this. -- nosy: +kyle.roberts ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17673 ___

[issue17673] add `copy_from` argument to temporaryfile

2013-04-09 Thread Antoine Pitrou
New submission from Antoine Pitrou: It is sometimes useful to create a temporary file as a copy of an existing file (especially e.g. in tests, when you want to mutate the temp file but not the original). I would suggest adding a `copy_from` argument to TemporaryFile and NamedTemporaryFile,