diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-11-15 06:23:06 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-11-15 06:25:38 +0100 |
commit | a6f09e309346a22875495d679dbaef13a0ed9e69 (patch) | |
tree | 52107ae3c1d0386fb9b14367b4f0d3da9c79f7d7 /pyload/network | |
parent | [LinkCryptWs] Fix typo (diff) | |
download | pyload-a6f09e309346a22875495d679dbaef13a0ed9e69.tar.xz |
[HTTPRequest] Raise Fail if write response fails
Conflicts:
pyload/network/HTTPRequest.py
Diffstat (limited to 'pyload/network')
-rw-r--r-- | pyload/network/HTTPRequest.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/pyload/network/HTTPRequest.py b/pyload/network/HTTPRequest.py index 8b1f92a63..0384da5ff 100644 --- a/pyload/network/HTTPRequest.py +++ b/pyload/network/HTTPRequest.py @@ -24,7 +24,7 @@ from httplib import responses from logging import getLogger from cStringIO import StringIO -from pyload.plugins.Plugin import Abort +from pyload.plugins.Plugin import Abort, Fail def myquote(url): return quote(url.encode('utf_8') if isinstance(url, unicode) else url, safe="%/:=&?~#+!$,;'@()*[]") @@ -236,11 +236,13 @@ class HTTPRequest: def getResponse(self): """ retrieve response from string io """ - if self.rep is None: return "" - value = self.rep.getvalue() - self.rep.close() - self.rep = StringIO() - return value + if self.rep is None: + return "" + else: + value = self.rep.getvalue() + self.rep.close() + self.rep = StringIO() + return value def decodeResponse(self, rep): """ decode with correct encoding, relies on header """ @@ -271,6 +273,7 @@ class HTTPRequest: except LookupError: self.log.debug("No Decoder foung for %s" % encoding) + except Exception: self.log.debug("Error when decoding string from %s." % encoding) @@ -280,13 +283,15 @@ class HTTPRequest: """ writes response """ if self.rep.tell() > 1000000 or self.abort: rep = self.getResponse() - if self.abort: raise Abort() - f = open("response.dump", "wb") - f.write(rep) - f.close() - raise Exception("Loaded Url exceeded limit") - self.rep.write(buf) + if self.abort: + raise Abort() + + with open("response.dump", "wb") as f: + f.write(rep) + raise Fail("Loaded url exceeded size limit") + else: + self.rep.write(buf) def writeHeader(self, buf): """ writes header """ |