From 624f018999b8df123ce8284272a6f4429017f0c6 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Thu, 29 Jan 2015 10:44:00 -0800 Subject: [PATCH] use six.moves to get to python3-style urllib --- htsworkflow/util/api.py | 10 ++++------ htsworkflow/util/opener.py | 6 +++--- samples/models.py | 1 - 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/htsworkflow/util/api.py b/htsworkflow/util/api.py index ce97e18..f7272bc 100644 --- a/htsworkflow/util/api.py +++ b/htsworkflow/util/api.py @@ -13,9 +13,7 @@ except ImportError: import os from optparse import OptionGroup -import urllib -import urllib2 -import urlparse +from six.moves import urllib LOGGER = logging.getLogger(__name__) @@ -129,9 +127,9 @@ def retrieve_info(url, apidata): Return a dictionary from the HTSworkflow API """ try: - apipayload = urllib.urlencode(apidata) - web = urllib2.urlopen(url, apipayload) - except urllib2.URLError as e: + apipayload = urllib.parse.urlencode(apidata) + web = urllib.request.urlopen(url, apipayload) + except urllib.request.URLError as e: if hasattr(e, 'code') and e.code == 404: LOGGER.info("%s was not found" % (url,)) return None diff --git a/htsworkflow/util/opener.py b/htsworkflow/util/opener.py index 035bb24..6d5e2c0 100644 --- a/htsworkflow/util/opener.py +++ b/htsworkflow/util/opener.py @@ -5,7 +5,7 @@ import os import gzip import bz2 import types -import urllib2 +from six.moves import urllib def isfilelike(file_ref, mode): """Does file_ref have the core file operations? @@ -31,7 +31,7 @@ def isurllike(file_ref, mode): (AKA does it start with protocol:// ?) """ #what if mode is 'w'? - parsed = urllib2.urlparse.urlparse(file_ref) + parsed = urllib.parse.urlparse(file_ref) schema, netloc, path, params, query, fragment = parsed return len(schema) > 0 @@ -47,7 +47,7 @@ def autoopen(file_ref, mode='r'): elif isfilelike(file_ref, mode): return file_ref elif isurllike(file_ref, mode): - return urllib2.urlopen(file_ref) + return urllib.request.urlopen(file_ref) elif os.path.splitext(file_ref)[1] == ".gz": return gzip.open(file_ref, mode) elif os.path.splitext(file_ref)[1] == '.bz2': diff --git a/samples/models.py b/samples/models.py index 21b6f40..5cf2e90 100644 --- a/samples/models.py +++ b/samples/models.py @@ -1,6 +1,5 @@ import types import logging -import urlparse from django.db import models from django.contrib.auth.models import User, UserManager from django.core import urlresolvers -- 2.30.2