aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil <neil@dip.sun.ac.za>2016-03-08 16:52:48 +0200
committerNeil <neil@dip.sun.ac.za>2016-03-08 16:52:48 +0200
commit5ddac4729d938c30d85256ef18f69f1d97e9ca3e (patch)
tree6c947db2815523edf735cf7793e068ed25531ef7
parentVersion bump for release 2.16. (diff)
downloadirker-5ddac4729d938c30d85256ef18f69f1d97e9ca3e.tar.xz
Don't hang when confronted with urls which require authentication
-rwxr-xr-xirkerhook.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/irkerhook.py b/irkerhook.py
index 0a62a54..33a4c52 100755
--- a/irkerhook.py
+++ b/irkerhook.py
@@ -41,7 +41,7 @@ default_channels = "irc://chat.freenode.net/#commits"
version = "2.16"
-import os, sys, socket, urllib, subprocess, locale, datetime, re
+import os, sys, socket, urllib2, subprocess, locale, datetime, re
from pipes import quote as shellquote
try:
@@ -80,13 +80,13 @@ class Commit:
urlprefix = urlprefixmap.get(self.urlprefix, self.urlprefix)
webview = (urlprefix % self.__dict__) + self.commit
try:
- if urllib.urlopen(webview).getcode() == 404:
- raise IOError
+ # See it the url is accessible
+ res = urllib2.urlopen(webview)
if self.tinyifier and self.tinyifier.lower() != "none":
try:
- # Didn't get a retrieval error or 404 on the web
+ # Didn't get a retrieval error on the web
# view, so try to tinyify a reference to it.
- self.url = open(urllib.urlretrieve(self.tinyifier + webview)[0]).read()
+ self.url = urllib2.urlopen(self.tinyifier + webview).read()
try:
self.url = self.url.decode('UTF-8')
except UnicodeError:
@@ -95,8 +95,12 @@ class Commit:
self.url = webview
else:
self.url = webview
- except IOError:
- self.url = ""
+ except IOError as e:
+ if e.code == 401:
+ # Authentication error, so we assume the view is valid
+ self.url = webview
+ else:
+ self.url = ""
res = self.template % self.__dict__
return unicode(res, 'UTF-8') if not isinstance(res, unicode) else res