aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Kahle <thomas.kahle@jpberlin.de>2015-06-20 18:19:22 +0200
committerThomas Kahle <thomas.kahle@jpberlin.de>2015-06-20 18:19:22 +0200
commitc80648a4008e4bd779ef1c92027292021e5737e7 (patch)
treeeab12aae7bb4412c633436c592e97ac1b6282e38
parentChange file permissions descriptor octal->decimal (diff)
downloadtatt-c80648a4008e4bd779ef1c92027292021e5737e7.tar.gz
tatt-c80648a4008e4bd779ef1c92027292021e5737e7.tar.bz2
tatt-c80648a4008e4bd779ef1c92027292021e5737e7.zip
Make import of urllib python2/3 compatible
-rw-r--r--tatt/tinderbox.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/tatt/tinderbox.py b/tatt/tinderbox.py
index 3048aef..b78bde8 100644
--- a/tatt/tinderbox.py
+++ b/tatt/tinderbox.py
@@ -1,9 +1,12 @@
"""acessing the tinderbox at http://tinderbox.dev.gentoo.org/misc/dindex/ """
import socket # For setting a global timeout
-# This will not work with python-2.6
-# import urllib.request, urllib.error, urllib.parse
-import urllib2
+# Support python2 and python3 versions of urllib:
+try:
+ from urllib2 import urlopen, HTTPError
+except:
+ from urllib.request import urlopen
+ from urllib.error import HTTPError
import sys
from subprocess import *
import random
@@ -29,11 +32,8 @@ def stablerdeps (package, config):
socket.setdefaulttimeout(45)
try:
- download = urllib2.urlopen(tinderbox + atom).read()
- # This would be thy python-3 version:
- # download = urllib.request.urlopen(tinderbox + atom).read()
- # except urllib.error.HTTPError as e:
- except urllib2.HTTPError as e:
+ download = urlopen(tinderbox + atom).read()
+ except HTTPError as e:
# Cleanup the timeout:
socket.setdefaulttimeout(None)
if e.code == 404: