summaryrefslogtreecommitdiffstats
path: root/pyload/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/plugins')
-rw-r--r--pyload/plugins/Request.py11
-rw-r--r--pyload/plugins/network/CurlRequest.py5
2 files changed, 14 insertions, 2 deletions
diff --git a/pyload/plugins/Request.py b/pyload/plugins/Request.py
index 8e8e0cc6b..9f6fe8c2b 100644
--- a/pyload/plugins/Request.py
+++ b/pyload/plugins/Request.py
@@ -59,7 +59,16 @@ class Request(object):
if name == "":
self.options.clear()
else:
- del self.options[name]
+ if name in self.options:
+ del self.options[name]
+
+ def addAuth(self, user, pwd):
+ """ Adds authentication information to the request """
+ self.options["auth"] = user + ":" + pwd
+
+ def removeAuth(self):
+ """ Removes authentication from the request """
+ self.unsetOption("auth")
def load(self, uri, *args, **kwargs):
""" Loads given resource from given uri. Args and kwargs depends on implementation"""
diff --git a/pyload/plugins/network/CurlRequest.py b/pyload/plugins/network/CurlRequest.py
index 717590ac5..03c049cf5 100644
--- a/pyload/plugins/network/CurlRequest.py
+++ b/pyload/plugins/network/CurlRequest.py
@@ -63,7 +63,7 @@ class CurlRequest(Request):
self.c.setopt(pycurl.WRITEFUNCTION, self.write)
self.c.setopt(pycurl.HEADERFUNCTION, self.writeHeader)
- # TODO: addAuth, addHeader
+ # TODO: addHeader
@property
def http(self):
@@ -138,6 +138,9 @@ class CurlRequest(Request):
if "timeout" in options:
self.c.setopt(pycurl.LOW_SPEED_TIME, options["timeout"])
+ if "auth" in options:
+ self.c.setopt(pycurl.USERPWD, str(options["auth"]))
+
def initOptions(self, options):
""" Sets same options as available in pycurl """
for k, v in options.iteritems():