summaryrefslogtreecommitdiffstats
path: root/pyload/network
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/network')
-rw-r--r--pyload/network/Browser.py2
-rw-r--r--pyload/network/CookieJar.py54
-rw-r--r--pyload/network/RequestFactory.py66
3 files changed, 41 insertions, 81 deletions
diff --git a/pyload/network/Browser.py b/pyload/network/Browser.py
index 25cbf669b..262adaebd 100644
--- a/pyload/network/Browser.py
+++ b/pyload/network/Browser.py
@@ -6,7 +6,7 @@ from logging import getLogger
from HTTPRequest import HTTPRequest
from HTTPDownload import HTTPDownload
-
+# @ Deprecated
class Browser(object):
__slots__ = ("log", "options", "bucket", "cj", "_size", "http", "dl")
diff --git a/pyload/network/CookieJar.py b/pyload/network/CookieJar.py
index ea2c43a9e..3d39c66b9 100644
--- a/pyload/network/CookieJar.py
+++ b/pyload/network/CookieJar.py
@@ -1,53 +1,19 @@
# -*- coding: utf-8 -*-
-"""
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- @author: mkaay, RaNaN
-"""
-
from time import time
+from Cookie import SimpleCookie
-# TODO: replace with simplecookie?
-class CookieJar():
- def __init__(self, pluginname):
- self.cookies = {}
- self.pluginname = pluginname
-
- def __repr__(self):
- return ("<CookieJar plugin=%s>\n\t" % self.pluginname) + "\n\t".join(self.cookies.values())
-
- def addCookies(self, clist):
- for c in clist:
- name = c.split("\t")[5]
- self.cookies[name] = c
-
- def getCookies(self):
- return self.cookies.values()
+class CookieJar(SimpleCookie):
def getCookie(self, name):
- if name in self.cookies:
- return self.cookies[name].split("\t")[6]
- else:
- return None
+ return self[name].value
- def setCookie(self, domain, name, value, path="/", exp=None):
+ def setCookie(self, domain, name, value, path="/", exp=None, secure="FALSE"):
if not exp: exp = time() + 3600 * 24 * 180
- # dot makes it valid on all subdomains
- s = ".%s TRUE %s FALSE %s %s %s" % (domain.strip("."), path, exp, name, value)
- self.cookies[name] = s
-
- def clear(self):
- self.cookies = {} \ No newline at end of file
+ self[name] = value
+ self[name]["domain"] = domain
+ self[name]["path"] = path
+ self[name]["expires"] = exp
+ if secure == "TRUE":
+ self[name]["secure"] = secure
diff --git a/pyload/network/RequestFactory.py b/pyload/network/RequestFactory.py
index 1581be9fc..e6015219f 100644
--- a/pyload/network/RequestFactory.py
+++ b/pyload/network/RequestFactory.py
@@ -17,44 +17,20 @@
@author: mkaay, RaNaN
"""
-from threading import Lock
-
-from Browser import Browser
from Bucket import Bucket
-from HTTPRequest import HTTPRequest
from CookieJar import CookieJar
+from pyload.plugins.network.DefaultRequest import DefaultRequest, DefaultDownload
+
class RequestFactory():
def __init__(self, core):
- self.lock = Lock()
self.core = core
self.bucket = Bucket()
self.updateBucket()
- @property
- def iface(self):
- return self.core.config["download"]["interface"]
-
- def getRequest(self, pluginName, cj=None):
- # TODO: mostly obsolete, browser could be removed completely
- req = Browser(self.bucket, self.getOptions())
-
- if cj:
- req.setCookieJar(cj)
- else:
- req.setCookieJar(CookieJar(pluginName))
-
- return req
-
- def getHTTPRequest(self, **kwargs):
- """ returns a http request, don't forget to close it ! """
- options = self.getOptions()
- options.update(kwargs) # submit kwargs as additional options
- return HTTPRequest(CookieJar(None), options)
-
def getURL(self, *args, **kwargs):
""" see HTTPRequest for argument list """
- h = HTTPRequest(None, self.getOptions())
+ h = DefaultRequest(self.getConfig())
try:
rep = h.load(*args, **kwargs)
finally:
@@ -62,9 +38,25 @@ class RequestFactory():
return rep
- def openCookieJar(self, pluginname):
- """Create new CookieJar"""
- return CookieJar(pluginname)
+ ########## old api methods above
+
+ def getRequest(self, context=None, klass=DefaultRequest):
+ """ Creates a request with new or given context """
+ # also accepts cookiejars, not so nice, since it depends on implementation
+ if isinstance(context, CookieJar):
+ return klass(self.getConfig(), context)
+ elif context:
+ return klass(*context)
+ else:
+ return klass(self.getConfig())
+
+ def getDownloadRequest(self, request=None, klass=DefaultDownload):
+ """ Instantiates a instance for downloading """
+ # TODO: load with plugin manager
+ return klass(self.bucket, request)
+
+ def getInterface(self):
+ return self.core.config["download"]["interface"]
def getProxies(self):
""" returns a proxy list for the request classes """
@@ -73,8 +65,10 @@ class RequestFactory():
else:
type = "http"
setting = self.core.config["proxy"]["type"].lower()
- if setting == "socks4": type = "socks4"
- elif setting == "socks5": type = "socks5"
+ if setting == "socks4":
+ type = "socks4"
+ elif setting == "socks5":
+ type = "socks5"
username = None
if self.core.config["proxy"]["username"] and self.core.config["proxy"]["username"].lower() != "none":
@@ -90,11 +84,11 @@ class RequestFactory():
"port": self.core.config["proxy"]["port"],
"username": username,
"password": pw,
- }
+ }
- def getOptions(self):
+ def getConfig(self):
"""returns options needed for pycurl"""
- return {"interface": self.iface,
+ return {"interface": self.getInterface(),
"proxies": self.getProxies(),
"ipv6": self.core.config["download"]["ipv6"]}
@@ -111,4 +105,4 @@ def getURL(*args, **kwargs):
def getRequest(*args, **kwargs):
- return pyreq.getHTTPRequest()
+ return pyreq.getRequest(*args, **kwargs)