Martin Panter <[email protected]> added the comment:
For 3.7+ (where iterable objects are supported), I suggest:
1. Document the problem as a limitation of handlers like
AbstractBasicAuthHandler, and consider raising an exception instead of trying
to upload a file or iterable a second time.
2. Clarify the behaviour for different types of the “urllib.request” data
parameter. I understand “file-like objects” means objects with a “read”
attribute, and the “read” method is called in preference to iteration or
treating the parameter as a “bytes” object.
Despite the bug title, I don’t think the library should mess with the file
position. Certainly not when making a single request. But it should already be
possible for the caller to supply a custom iterable object that resets the file
position:
class FileReiterator:
def __iter__(self):
self.file.seek(0)
while True:
chunk = self.file.read(self.chunksize)
yield chunk
if len(chunk) < self.chunksize:
break
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue5038>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com