summaryrefslogtreecommitdiffstats
path: root/module/network
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-05-12 21:57:53 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-05-12 21:57:53 +0200
commite269bec1053f059ba0fd701c1e7fa1ad424726bc (patch)
tree70e4ddb3578f7eef435ed563a9d6b7f9bbd9ddbb /module/network
parentfixed js (diff)
downloadpyload-e269bec1053f059ba0fd701c1e7fa1ad424726bc.tar.xz
some fixes, closed #306
Diffstat (limited to 'module/network')
-rw-r--r--module/network/Browser.py13
-rw-r--r--module/network/HTTPChunk.py2
-rw-r--r--module/network/HTTPDownload.py5
-rw-r--r--module/network/HTTPRequest.py11
-rw-r--r--module/network/RequestFactory.py15
5 files changed, 28 insertions, 18 deletions
diff --git a/module/network/Browser.py b/module/network/Browser.py
index 9020a6de1..2dc9c3d83 100644
--- a/module/network/Browser.py
+++ b/module/network/Browser.py
@@ -8,17 +8,16 @@ from HTTPDownload import HTTPDownload
class Browser(object):
- def __init__(self, interface=None, bucket=None, proxies={}):
+ def __init__(self, bucket=None, options={}):
self.log = getLogger("log")
- self.interface = interface
+ self.options = options #holds pycurl options
self.bucket = bucket
- self.proxies = proxies
self.cj = None # needs to be setted later
self._size = 0
- self.http = HTTPRequest(self.cj, interface, proxies)
+ self.http = HTTPRequest(self.cj, options)
self.dl = None
def setLastURL(self, val):
@@ -73,12 +72,12 @@ class Browser(object):
self._size = self.dl.size
self.dl.abort = True
- def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False, progressNotify=None, disposition=False):
+ def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False,
+ progressNotify=None, disposition=False):
""" this can also download ftp """
self._size = 0
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, progressNotify, disposition)
+ self.cj if cookies else None, self.bucket, self.options, progressNotify, disposition)
name = self.dl.download(chunks, resume)
self._size = self.dl.size
diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py
index a88d94afe..88e6e49c6 100644
--- a/module/network/HTTPChunk.py
+++ b/module/network/HTTPChunk.py
@@ -134,7 +134,7 @@ class HTTPChunk(HTTPRequest):
self.fp = None #file handle
self.initHandle()
- self.setInterface(self.p.interface, self.p.proxies)
+ self.setInterface(self.p.options["interface"], self.p.options["proxies"], self.p.options["ipv6"])
self.BOMChecked = False
# check and remove byte order mark
diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py
index 9d0395c6f..56f1cb1e4 100644
--- a/module/network/HTTPDownload.py
+++ b/module/network/HTTPDownload.py
@@ -33,7 +33,7 @@ from module.utils import save_join
class HTTPDownload():
""" loads a url http + ftp """
def __init__(self, url, filename, get={}, post={}, referer=None, cj=None, bucket=None,
- interface=None, proxies={}, progressNotify=None, disposition=False):
+ options={}, progressNotify=None, disposition=False):
self.url = url
self.filename = filename #complete file destination, not only name
self.get = get
@@ -41,8 +41,7 @@ class HTTPDownload():
self.referer = referer
self.cj = cj #cookiejar if cookies are needed
self.bucket = bucket
- self.interface = interface
- self.proxies = proxies
+ self.options = options
self.disposition = disposition
# all arguments
diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py
index f0a80fd93..598be78c7 100644
--- a/module/network/HTTPRequest.py
+++ b/module/network/HTTPRequest.py
@@ -34,7 +34,7 @@ class BadHeader(Exception):
class HTTPRequest():
- def __init__(self, cookies=None, interface=None, proxies=None):
+ def __init__(self, cookies=None, options=None):
self.c = pycurl.Curl()
self.rep = StringIO()
@@ -50,7 +50,7 @@ class HTTPRequest():
self.headers = [] #temporary request header
self.initHandle()
- self.setInterface(interface, proxies)
+ self.setInterface(options["interface"], options["proxies"], options["ipv6"])
self.c.setopt(pycurl.WRITEFUNCTION, self.write)
self.c.setopt(pycurl.HEADERFUNCTION, self.writeHeader)
@@ -80,7 +80,7 @@ class HTTPRequest():
"Connection: keep-alive",
"Keep-Alive: 300"])
- def setInterface(self, interface, proxy):
+ def setInterface(self, interface, proxy, ipv6=False):
if interface and interface.lower() != "none":
self.c.setopt(pycurl.INTERFACE, str(interface))
@@ -98,6 +98,11 @@ class HTTPRequest():
if proxy["username"]:
self.c.setopt(pycurl.PROXYUSERPWD, "%s:%s" % (proxy["username"], proxy["password"]))
+ if ipv6:
+ self.c.setopt(pycurl.IPRESOLVE, pycurl.IPRESOLVE_WHATEVER)
+ else:
+ self.c.setopt(pycurl.IPRESOLVE, pycurl.IPRESOLVE_V4)
+
def addCookies(self):
""" put cookies from curl handle to cj """
if self.cj:
diff --git a/module/network/RequestFactory.py b/module/network/RequestFactory.py
index 27854e95e..9b32ed570 100644
--- a/module/network/RequestFactory.py
+++ b/module/network/RequestFactory.py
@@ -43,7 +43,7 @@ class RequestFactory():
if type == "XDCC":
return XDCCRequest(proxies=self.getProxies())
- req = Browser(self.iface(), self.bucket, self.getProxies())
+ req = Browser(self.bucket, self.getOptions())
if account:
cj = self.getCookieJar(pluginName, account)
@@ -56,10 +56,10 @@ class RequestFactory():
def getHTTPRequest(self):
""" returns a http request, dont forget to close it ! """
- return HTTPRequest(CookieJar(None), self.iface(), self.getProxies())
+ return HTTPRequest(CookieJar(None), self.getOptions())
def getURL(self, url, get={}, post={}, multipart=False):
- h = HTTPRequest(None, self.iface(), self.getProxies())
+ h = HTTPRequest(None, self.getOptions())
rep = h.load(url, get, post, multipart=multipart)
h.close()
return rep
@@ -96,7 +96,13 @@ class RequestFactory():
"port": self.core.config["proxy"]["port"],
"username": username,
"password": pw,
- }
+ }
+
+ def getOptions(self):
+ """returns options needed for pycurl"""
+ return {"interface": self.iface(),
+ "proxies": self.getProxies(),
+ "ipv6": self.core.config["download"]["ipv6"]}
def updateBucket(self):
""" set values in the bucket according to settings"""
@@ -109,5 +115,6 @@ class RequestFactory():
def getURL(*args, **kwargs):
return pyreq.getURL(*args, **kwargs)
+
def getRequest(*args, **kwargs):
return pyreq.getHTTPRequest() \ No newline at end of file