summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyload/network/HTTPRequest.py29
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 """