summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-05-06 17:46:57 +0200
committerGravatar mkaay <mkaay@mkaay.de> 2010-05-06 17:46:57 +0200
commit70815efe19e50718bc149ed77466a35833f8dbd1 (patch)
tree8ae616d088456a35ec981bfcd8e69703d61793f5
parentdlc update (diff)
downloadpyload-70815efe19e50718bc149ed77466a35833f8dbd1.tar.xz
new request factory
-rw-r--r--module/RequestFactory.py53
-rwxr-xr-xmodule/network/Request.py25
-rw-r--r--module/plugins/Plugin.py3
-rwxr-xr-xpyLoadCore.py3
4 files changed, 78 insertions, 6 deletions
diff --git a/module/RequestFactory.py b/module/RequestFactory.py
new file mode 100644
index 000000000..a2a3ad902
--- /dev/null
+++ b/module/RequestFactory.py
@@ -0,0 +1,53 @@
+# -*- 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 tempfile import NamedTemporaryFile
+
+class RequestFactory():
+ def __init__(self, core):
+ self.lock = Lock()
+ self.core = core
+ self.requests = []
+
+ def getRequest(self, pluginName, account=None):
+ self.lock.acquire()
+ for req in self.requests:
+ if req[0:2] == (pluginName, account):
+ self.lock.release()
+ return req[2]
+ name = pluginName
+ if account:
+ name += "_"
+ name += account
+ th = NamedTemporaryFile(mode="w", prefix="pyload_cookies_%s" % name, delete=False)
+ cookieFile = th.name
+ th.close()
+
+ req = Request(cookieFile)
+ 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()
diff --git a/module/network/Request.py b/module/network/Request.py
index ef2e7d1a4..73ba06e2f 100755
--- a/module/network/Request.py
+++ b/module/network/Request.py
@@ -27,12 +27,14 @@ from os.path import exists
import urllib
from cStringIO import StringIO
import pycurl
+from tempfile import NamedTemporaryFile
+from os import remove
class AbortDownload(Exception):
pass
class Request:
- def __init__(self):
+ def __init__(self, cookieFile=None):
self.dl_time = 0
self.dl_finished = 0
@@ -63,6 +65,12 @@ class Request:
self.speedLimitActive = False
self.maxSpeed = 0
self.isSlow = False
+
+ if not cookieFile:
+ th = NamedTemporaryFile(mode="w", prefix="pyload_cookies", delete=False)
+ cookieFile = th.name
+ th.close()
+ self.cookieFile = cookieFile
self.init_curl()
@@ -138,9 +146,8 @@ class Request:
return self.get_rep()
def curl_enable_cookies(self):
- cookie_file = "module" + sep + "cookies.txt"
- self.pycurl.setopt(pycurl.COOKIEFILE, cookie_file)
- self.pycurl.setopt(pycurl.COOKIEJAR, cookie_file)
+ self.pycurl.setopt(pycurl.COOKIEFILE, self.cookieFile)
+ self.pycurl.setopt(pycurl.COOKIEJAR, self.cookieFile)
def add_auth(self, user, pw):
@@ -334,6 +341,16 @@ class Request:
if not exists(temp_name):
file_name = temp_name
return file_name
+
+ def __del__(self):
+ self.clean()
+
+ def clean(self):
+ try:
+ remove(self.cookieFile)
+ self.pycurl.close()
+ except:
+ print "cant clean"
def getURL(url):
"""
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index 107c4f0ca..50923498f 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -26,7 +26,6 @@ from time import sleep
import sys
from os.path import exists
-from module.network.Request import Request
from os import makedirs
from module.DownloadThread import CaptchaError
@@ -44,7 +43,7 @@ class Plugin():
self.configparser = parent.core.parser_plugins
self.config = {}
self.parent = parent
- self.req = Request()
+ self.req = parent.core.requestFactory.getRequest(self.__name__)
self.html = 0
self.time_plus_wait = 0 #time() + wait in seconds
self.want_reconnect = False
diff --git a/pyLoadCore.py b/pyLoadCore.py
index a777d4a50..e5695ca1e 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -72,6 +72,7 @@ from module.HookManager import HookManager
from module.PullEvents import PullManager
from module.PluginManager import PluginManager
from module.FileList import FileList
+from module.RequestFactory import RequestFactory
class Core(object):
""" pyLoad Core """
@@ -252,6 +253,7 @@ class Core(object):
self.lastGuiConnected = 0
self.server_methods = ServerMethods(self)
+ self.requestFactory = RequestFactory(self)
self.file_list = FileList(self)
self.pullManager = PullManager(self)
self.thread_list = ThreadManager(self)
@@ -439,6 +441,7 @@ class Core(object):
for thread in self.thread_list.threads:
thread.join(10)
self.file_list.save()
+ self.requestFactory.clean()
except:
self.logger.info(_("error while shutting down"))