summaryrefslogtreecommitdiffstats
path: root/module/network
diff options
context:
space:
mode:
Diffstat (limited to 'module/network')
-rw-r--r--module/network/Browser.py9
-rw-r--r--module/network/HTTPDownload.py2
-rw-r--r--module/network/HTTPRequest.py14
3 files changed, 19 insertions, 6 deletions
diff --git a/module/network/Browser.py b/module/network/Browser.py
index 19b6aca66..3a8cd94a0 100644
--- a/module/network/Browser.py
+++ b/module/network/Browser.py
@@ -22,7 +22,10 @@ class Browser(object):
self.http = HTTPRequest(self.cj, interface, proxies)
self.dl = None
+ # tunnel some attributes from HTTP Request to Browser
lastEffectiveURL = property(lambda self: self.http.lastEffectiveURL)
+ lastURL = property(lambda self: self.http.lastURL)
+ code = property(lambda self: self.http.code)
def setCookieJar(self, cj):
self.cj = cj
@@ -56,9 +59,10 @@ class Browser(object):
def clearCookies(self):
if self.cj:
self.cj.clear()
+ self.http.clearCookies()
def clearReferer(self):
- self.lastURL = None
+ self.http.lastURL = None
def abortDownloads(self):
self.http.abort = True
@@ -66,6 +70,7 @@ class Browser(object):
self.dl.abort = True
def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False):
+ """ this can also download ftp """
self.dl = HTTPDownload(url, filename, get, post, self.lastEffectiveURL if ref else None,
self.cj if cookies else None, self.bucket, self.interface,
self.proxies)
@@ -85,7 +90,7 @@ class Browser(object):
""" retrieves page """
return self.http.load(url, get, post, ref, cookies, just_header)
- def clean(self):
+ def close(self):
""" cleanup """
if hasattr(self, "http"):
self.http.close()
diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py
index 5ee33608b..c1ca77e2c 100644
--- a/module/network/HTTPDownload.py
+++ b/module/network/HTTPDownload.py
@@ -98,7 +98,7 @@ class HTTPDownload():
break
fo.write(data)
fi.close()
- if fo.tell() < self.info.getChunkName(i)[2]:
+ if fo.tell() < self.info.getChunkRange(i)[1]:
raise Exception("Downloaded content was smaller than expected")
remove(fname) #remove chunk
fo.close()
diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py
index b4bb0857a..e107831cd 100644
--- a/module/network/HTTPRequest.py
+++ b/module/network/HTTPRequest.py
@@ -50,6 +50,9 @@ class HTTPRequest():
self.initHandle()
self.setInterface(interface, proxies)
+ self.c.setopt(pycurl.WRITEFUNCTION, self.write)
+ self.c.setopt(pycurl.HEADERFUNCTION, self.writeHeader)
+
def initHandle(self):
""" sets common options to curl handle """
@@ -93,15 +96,20 @@ class HTTPRequest():
self.c.setopt(pycurl.PROXYUSERPWD, "%s:%s" % (proxy["username"], proxy["password"]))
def addCookies(self):
+ """ put cookies from curl handle to cj """
if self.cj:
self.cj.addCookies(self.c.getinfo(pycurl.INFO_COOKIELIST))
def getCookies(self):
+ """ add cookies from cj to curl handle """
if self.cj:
for c in self.cj.getCookies():
self.c.setopt(pycurl.COOKIELIST, c)
return
+ def clearCookies(self):
+ self.c.setopt(pycurl.COOKIELIST, "")
+
def setRequestContext(self, url, get, post, referer, cookies):
""" sets everything needed for the request """
@@ -133,8 +141,7 @@ class HTTPRequest():
self.setRequestContext(url, get, post, referer, cookies)
self.header = ""
- self.c.setopt(pycurl.WRITEFUNCTION, self.write)
- self.c.setopt(pycurl.HEADERFUNCTION, self.writeHeader)
+
#@TODO raw_cookies and some things in old backend, which are apperently not needed
if just_header:
@@ -184,10 +191,11 @@ class HTTPRequest():
def close(self):
""" cleanup, unusable after this """
- self.c.close()
self.rep.close()
if hasattr(self, "cj"):
del self.cj
+ if hasattr(self, "c"):
+ del self.c
if __name__ == "__main__":