New submission from Bohuslav "Slavek" Kabrda:

This bug is very similar to #18879, the only difference is that 
_TemporaryFileWrapper.__iter__ is the problem (in #18879, __getattr__ was 
fixed, but __iter__ was not). The real world use case that helped me find this 
bug is at the bottom of this report, this is a simple reproducer:


>>> import tempfile
>>> for l in tempfile.NamedTemporaryFile(mode='a+b'):
...     print(l)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: readline of closed file


I'm attaching a patch that fixes this (+ testcase).

Note: I actually discovered this while using


>>> from urllib.request import urlopen
>>> for l in urlopen('ftp://<some_ftp>'):
...     print(l)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: readline of closed file


Opening FTP uses urllib.response, which in turn uses 
tempfile._TemporaryFileWrapper, which makes this example fail.

----------
components: Library (Lib)
files: python-3.4-tempfile-iter.patch
keywords: patch
messages: 238451
nosy: bkabrda
priority: normal
severity: normal
status: open
title: tempfile.NamedTemporaryFile can close too early if used as iterator
type: behavior
versions: Python 3.4, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file38543/python-3.4-tempfile-iter.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23700>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to