aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Christopher Rosell <chrippa@tanuki.se>2012-09-08 00:13:07 +0200
committerGravatar Christopher Rosell <chrippa@tanuki.se>2012-09-08 14:32:41 +0200
commit7ce4938cff4b4f352cc2cade258391be2771fede (patch)
treeb9627e73dafe203c061cdbdc1e656e525a0edac1
parentd5942525de7b54f7559402d52e89ec08fd987152 (diff)
Add a exception argument to urlopen.
-rw-r--r--src/livestreamer/stream.py9
-rw-r--r--src/livestreamer/utils.py4
2 files changed, 6 insertions, 7 deletions
diff --git a/src/livestreamer/stream.py b/src/livestreamer/stream.py
index f72217b..82d9a9a 100644
--- a/src/livestreamer/stream.py
+++ b/src/livestreamer/stream.py
@@ -1,5 +1,5 @@
from .compat import str, is_win32
-from .utils import urlopen
+from .utils import urlget
import os
import pbs
@@ -96,10 +96,9 @@ class HTTPStream(Stream):
self.args = args
def open(self):
- try:
- res = urlopen(self.url, prefetch=False, **self.args)
- except Exception as err:
- raise StreamError(str(err))
+ res = urlget(self.url, prefetch=False,
+ exception=StreamError,
+ **self.args)
return res.raw
diff --git a/src/livestreamer/utils.py b/src/livestreamer/utils.py
index 90b9379..dfee53f 100644
--- a/src/livestreamer/utils.py
+++ b/src/livestreamer/utils.py
@@ -22,14 +22,14 @@ class ArgumentParser(argparse.ArgumentParser):
else:
yield "--%s" % line
-def urlopen(url, method="get", **args):
+def urlopen(url, method="get", exception=PluginError, **args):
if "data" in args and args["data"] is not None:
method = "post"
try:
res = requests.request(method, url, config=RequestsConfig, timeout=15, **args)
except requests.exceptions.RequestException as err:
- raise PluginError(("Unable to open URL: {url} ({err})").format(url=url, err=str(err)))
+ raise exception(("Unable to open URL: {url} ({err})").format(url=url, err=str(err)))
return res