summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyload/plugins/Hoster.py2
-rw-r--r--pyload/plugins/network/CurlChunk.py2
-rw-r--r--pyload/plugins/network/CurlDownload.py8
-rw-r--r--pyload/plugins/network/CurlRequest.py3
-rw-r--r--tests/other/test_curlDownload.py29
-rw-r--r--tests/other/test_curlRequest.py11
6 files changed, 43 insertions, 12 deletions
diff --git a/pyload/plugins/Hoster.py b/pyload/plugins/Hoster.py
index a37102aff..44b10899d 100644
--- a/pyload/plugins/Hoster.py
+++ b/pyload/plugins/Hoster.py
@@ -294,7 +294,7 @@ class Hoster(Base):
try:
# TODO: hardcoded arguments
newname = self.dl.download(url, filename, get=get, post=post, referer=ref, chunks=self.getChunkCount(),
- resume=self.resumeDownload, disposition=disposition)
+ resume=self.resumeDownload, cookies=cookies, disposition=disposition)
finally:
self.dl.close()
self.pyfile.size = self.dl.size
diff --git a/pyload/plugins/network/CurlChunk.py b/pyload/plugins/network/CurlChunk.py
index 4250db2ce..f5a19eb0d 100644
--- a/pyload/plugins/network/CurlChunk.py
+++ b/pyload/plugins/network/CurlChunk.py
@@ -164,7 +164,7 @@ class CurlChunk(CurlRequest):
def getHandle(self):
""" returns a Curl handle ready to use for perform/multiperform """
- self.setRequestContext(self.p.url, self.p.get, self.p.post, self.p.referer, self.cj)
+ self.setRequestContext(self.p.url, self.p.get, self.p.post, self.p.referer, self.p.cookies)
self.c.setopt(pycurl.WRITEFUNCTION, self.writeBody)
self.c.setopt(pycurl.HEADERFUNCTION, self.writeHeader)
diff --git a/pyload/plugins/network/CurlDownload.py b/pyload/plugins/network/CurlDownload.py
index 5de83ec7b..985513691 100644
--- a/pyload/plugins/network/CurlDownload.py
+++ b/pyload/plugins/network/CurlDownload.py
@@ -24,6 +24,7 @@ from shutil import move
import pycurl
from pyload.plugins.Base import Abort
+from pyload.network.CookieJar import CookieJar
from pyload.utils.fs import save_join, fs_encode
from ..Download import Download
@@ -38,6 +39,8 @@ class CurlDownload(Download):
# def __init__(self, url, filename, get={}, post={}, referer=None, cj=None, bucket=None,
# options={}, disposition=False):
+ CONTEXT_CLASS = CookieJar
+
def __init__(self, *args, **kwargs):
Download.__init__(self, *args, **kwargs)
@@ -108,7 +111,7 @@ class CurlDownload(Download):
except IOError:
self.info = ChunkInfo(self.path)
- def download(self, uri, path, get={}, post={}, referer=True, disposition=False, chunks=1, resume=False):
+ def download(self, uri, path, get={}, post={}, referer=True, disposition=False, chunks=1, resume=False, cookies=True):
""" returns new filename or None """
self.url = uri
self.path = path
@@ -116,6 +119,7 @@ class CurlDownload(Download):
self.get = get
self.post = post
self.referer = referer
+ self.cookies = cookies
self.checkResume()
chunks = max(1, chunks)
@@ -317,7 +321,5 @@ class CurlDownload(Download):
if hasattr(self, "m"):
self.m.close()
del self.m
- if hasattr(self, "cj"):
- del self.cj
if hasattr(self, "info"):
del self.info \ No newline at end of file
diff --git a/pyload/plugins/network/CurlRequest.py b/pyload/plugins/network/CurlRequest.py
index e5adc8be1..775c98522 100644
--- a/pyload/plugins/network/CurlRequest.py
+++ b/pyload/plugins/network/CurlRequest.py
@@ -177,7 +177,8 @@ class CurlRequest(Request):
self.c.setopt(pycurl.REFERER, "")
if cookies:
- self.c.setopt(pycurl.COOKIELIST, self.cj.output())
+ for c in self.cj.output().splitlines():
+ self.c.setopt(pycurl.COOKIELIST, c)
else:
# Magic string that erases all cookies
self.c.setopt(pycurl.COOKIELIST, "ALL")
diff --git a/tests/other/test_curlDownload.py b/tests/other/test_curlDownload.py
index d3f8f6754..17af1cdd4 100644
--- a/tests/other/test_curlDownload.py
+++ b/tests/other/test_curlDownload.py
@@ -1,13 +1,17 @@
# -*- coding: utf-8 -*-
from os import stat
-from os.path import exists
+
+from unittest import TestCase
from tests.helper.Stubs import Core
from pyload.network.Bucket import Bucket
+from pyload.plugins.network.CurlRequest import CurlRequest
from pyload.plugins.network.CurlDownload import CurlDownload
-class TestCurlRequest:
+class TestCurlRequest(TestCase):
+
+ cookieURL = "http://forum.pyload.org"
def setUp(self):
self.dl = CurlDownload(Bucket())
@@ -17,12 +21,33 @@ class TestCurlRequest:
def test_download(self):
+ assert self.dl.context is not None
+
self.dl.download("http://pyload.org/lib/tpl/pyload/images/pyload-logo-edited3.5-new-font-small.png", "/tmp/random.bin")
print self.dl.size, self.dl.arrived
assert self.dl.size == self.dl.arrived > 0
assert stat("/tmp/random.bin").st_size == self.dl.size
+ def test_cookies(self):
+
+ req = CurlRequest({})
+ req.load(self.cookieURL)
+
+ assert len(req.cj) > 0
+
+ dl = CurlDownload(Bucket(), req)
+
+ assert req.context is dl.context is not None
+
+ dl.download(self.cookieURL + "/cookies.php", "cookies.txt")
+ cookies = open("cookies.txt", "rb").read().splitlines()
+
+ self.assertEqual(len(cookies), len(dl.context))
+ for c in cookies:
+ k, v = c.strip().split(":")
+ self.assertIn(k, req.cj)
+
def test_attributes(self):
assert self.dl.size == 0
diff --git a/tests/other/test_curlRequest.py b/tests/other/test_curlRequest.py
index 09d65b385..6bd4a2772 100644
--- a/tests/other/test_curlRequest.py
+++ b/tests/other/test_curlRequest.py
@@ -21,16 +21,19 @@ class TestCurlRequest(TestCase):
def test_cookies(self):
self.req.load(self.cookieURL, cookies=False)
- assert len(self.req.cj.values()) == 0
+ assert len(self.req.cj) == 0
self.req.load(self.cookieURL)
- assert len(self.req.cj.values()) > 0
+ assert len(self.req.cj) > 1
- for c in self.req.load(self.cookieURL + "/cookies.php").splitlines():
- k, v = c.strip().split(":")
+ cookies = dict([c.strip().split(":") for c in self.req.load(self.cookieURL + "/cookies.php").splitlines()])
+ for k, v in cookies.iteritems():
self.assertIn(k, self.req.cj)
self.assertEqual(v, self.req.cj[k].value)
+ for c in self.req.cj:
+ self.assertIn(c, cookies)
+
cookies = self.req.load(self.cookieURL + "/cookies.php", cookies=False)
self.assertEqual(cookies, "")