summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-12-22 14:25:56 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-12-22 14:25:56 +0100
commit052d09687627999b91b45a8c0224aa9de4769924 (patch)
tree0ed3dd7cc49cd43fd2ce4c1b1573a13265daefb6 /module
parentrefactoring part 1: deprecation warnings, reduced debug, cookie compatibility (diff)
downloadpyload-052d09687627999b91b45a8c0224aa9de4769924.tar.xz
cleaned request factory
Diffstat (limited to 'module')
-rw-r--r--module/RequestFactory.py94
-rw-r--r--module/network/Browser.py6
-rw-r--r--module/network/CookieJar.py41
-rw-r--r--module/network/RequestFactory.py68
-rw-r--r--module/plugins/AccountManager.py (renamed from module/AccountManager.py)0
-rw-r--r--module/plugins/PluginManager.py (renamed from module/PluginManager.py)0
6 files changed, 112 insertions, 97 deletions
diff --git a/module/RequestFactory.py b/module/RequestFactory.py
deleted file mode 100644
index 5eaa32ed9..000000000
--- a/module/RequestFactory.py
+++ /dev/null
@@ -1,94 +0,0 @@
-# -*- 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
-"""
-
-from threading import Lock
-from module.network.Request import Request
-from module.network.Browser import Browser
-from module.network.XdccRequest import XdccRequest
-from module.network.FtpRequest import FtpRequest
-from time import time
-from cookielib import CookieJar
-from cookielib import Cookie
-
-class RequestFactory():
- def __init__(self, core):
- self.lock = Lock()
- self.core = core
- self.requests = [] #seems useless
- self.cookiejars = []
- self.iface = self.core.config["general"]["download_interface"]
-
- def getRequest(self, pluginName, account=None, type="HTTP"):
- self.lock.acquire()
- if type == "HTTP":
- req = Browser()
- if account:
- cj = self.getCookieJar(pluginName, account)
- req.setCookieJar(cj)
- else:
- req.setCookieJar(PyLoadCookieJar(pluginName))
-
- elif type == "XDCC":
- req = XdccRequest()
-
- elif type == "FTP":
- req = FtpRequest()
-
- #self.requests.append((pluginName, account, req))
- self.lock.release()
- return req
-
- def clean(self):
- self.lock.acquire()
- for req in self.requests:
- req[2].clean()
- self.lock.release()
-
- def getCookieJar(self, plugin, account=None):
- for cj in self.cookiejars:
- if (cj.plugin, cj.account) == (plugin, account):
- return cj
- cj = PyLoadCookieJar(plugin, account)
- self.cookiejars.append(cj)
- return cj
-
-class PyLoadCookieJar(CookieJar):
- def __init__(self, plugin, account=None):
- CookieJar.__init__(self)
- self.cookies = {}
- self.plugin = plugin
- self.account = account
-
- def __del__(self):
- if hasattr(self, "cookies"):
- del self.cookies
- if hasattr(self, "plugin"):
- del self.plugin
-
- def getCookie(self, name):
- print "getCookie not implemented!"
- return None
-
- def setCookie(self, domain, name, value, path="/"):
- c = Cookie(version=0, name=name, value=value, port=None, port_specified=False,
- domain=domain, domain_specified=False,
- domain_initial_dot=(domain.startswith(".")), path=path, path_specified=True,
- secure=False, expires=None, discard=True, comment=None,
- comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
- self.set_cookie(c)
diff --git a/module/network/Browser.py b/module/network/Browser.py
index df0f24b4d..3d2d5a73f 100644
--- a/module/network/Browser.py
+++ b/module/network/Browser.py
@@ -2,9 +2,9 @@ from random import randint
from helper import *
from os.path import join
from logging import getLogger
-from cookielib import CookieJar
import zlib
+from CookieJar import CookieJar
from HTTPBase import HTTPBase
from HTTPDownload import HTTPDownload
from FTPBase import FTPDownload
@@ -13,7 +13,7 @@ from XDCCBase import XDCCDownload
from traceback import print_stack
class Browser(object):
- def __init__(self, interface=None, cookieJar=CookieJar(), bucket=None, proxies={}):
+ def __init__(self, interface=None, cookieJar=None, bucket=None, proxies={}):
self.log = getLogger("log")
self.lastURL = None
@@ -21,7 +21,7 @@ class Browser(object):
self.bucket = bucket
self.http = HTTPBase(interface=interface, proxies=proxies)
- self.setCookieJar(cookieJar)
+ self.setCookieJar(cookieJar if cookieJar else CookieJar())
self.proxies = proxies
def setCookieJar(self, cookieJar):
diff --git a/module/network/CookieJar.py b/module/network/CookieJar.py
new file mode 100644
index 000000000..fc6b5e076
--- /dev/null
+++ b/module/network/CookieJar.py
@@ -0,0 +1,41 @@
+# -*- 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 cookielib import CookieJar as PyCookieJar
+from cookielib import Cookie
+
+
+class CookieJar(PyCookieJar):
+ def __init__(self, pluginName=None, account=None):
+ PyCookieJar.__init__(self)
+ self.plugin = pluginName
+ self.account = account
+
+
+ def getCookie(self, name):
+ print "getCookie not implemented!"
+ return None
+
+ def setCookie(self, domain, name, value, path="/"):
+ c = Cookie(version=0, name=name, value=value, port=None, port_specified=False,
+ domain=domain, domain_specified=False,
+ domain_initial_dot=(domain.startswith(".")), path=path, path_specified=True,
+ secure=False, expires=None, discard=True, comment=None,
+ comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
+ self.set_cookie(c) \ No newline at end of file
diff --git a/module/network/RequestFactory.py b/module/network/RequestFactory.py
new file mode 100644
index 000000000..d73ab5e20
--- /dev/null
+++ b/module/network/RequestFactory.py
@@ -0,0 +1,68 @@
+# -*- 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 threading import Lock
+
+from Browser import Browser
+from HTTPBase import HTTPBase
+from CookieJar import CookieJar
+
+class RequestFactory():
+ def __init__(self, core):
+ self.lock = Lock()
+ self.core = core
+ self.cookiejars = {}
+
+ iface = property(lambda self: self.core.config["general"]["download_interface"])
+
+ def getRequest(self, pluginName, account=None):
+ self.lock.acquire()
+
+ req = Browser()
+ #@TODO proxy stuff, bucket
+
+ if account:
+ cj = self.getCookieJar(pluginName, account)
+ req.setCookieJar(cj)
+ else:
+ req.setCookieJar(CookieJar(pluginName))
+
+ self.lock.release()
+ return req
+
+ def getURL(self, url):
+ base = HTTPBase()
+ #@TODO proxies
+ #@TODO post,get...
+
+ resp = base.getResponse(url)
+ resp = resp.read()
+ return resp
+
+ def getCookieJar(self, pluginName, account=None):
+ if self.cookiejars.has_key((pluginName, account)):
+ return self.cookiejars[(pluginName, account)]
+
+ cj = CookieJar(pluginName, account)
+ self.cookiejars[(pluginName, account)] = cj
+ return cj
+
+# needs pyreq in global namespace
+def getURL(url):
+ pyreq.getURL(url) \ No newline at end of file
diff --git a/module/AccountManager.py b/module/plugins/AccountManager.py
index ab35334fc..ab35334fc 100644
--- a/module/AccountManager.py
+++ b/module/plugins/AccountManager.py
diff --git a/module/PluginManager.py b/module/plugins/PluginManager.py
index 3f11c067b..3f11c067b 100644
--- a/module/PluginManager.py
+++ b/module/plugins/PluginManager.py