summaryrefslogtreecommitdiffstats
path: root/module/network
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/network
parentdlc update (diff)
downloadpyload-70815efe19e50718bc149ed77466a35833f8dbd1.tar.xz
new request factory
Diffstat (limited to 'module/network')
-rwxr-xr-xmodule/network/Request.py25
1 files changed, 21 insertions, 4 deletions
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):
"""