Message335672
| Author |
martin.panter |
| Recipients |
Anthony.Kong, LorenzMende, ajaksu2, dheiberg, ggenellina, jjlee, kc, martin.panter, matejcik, orsenthil |
| Date |
2019年02月16日.07:13:23 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1550301204.07.0.981227468533.issue5038@roundup.psfhosted.org> |
| In-reply-to |
| Content |
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 |
|