summaryrefslogtreecommitdiffstats
path: root/module/RequestFactory.py
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 /module/RequestFactory.py
parentdlc update (diff)
downloadpyload-70815efe19e50718bc149ed77466a35833f8dbd1.tar.xz
new request factory
Diffstat (limited to 'module/RequestFactory.py')
-rw-r--r--module/RequestFactory.py53
1 files changed, 53 insertions, 0 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()