use six.moves to get to python3-style urllib
authorDiane Trout <diane@ghic.org>
Thu, 29 Jan 2015 18:44:00 +0000 (10:44 -0800)
committerDiane Trout <diane@ghic.org>
Thu, 29 Jan 2015 18:46:51 +0000 (10:46 -0800)
htsworkflow/util/api.py
htsworkflow/util/opener.py
samples/models.py

index ce97e18d84cf6bfddc91f0f12660f5dfd9dbdaaf..f7272bce4dfe9b8b7297d0ce9faa883aac501bf4 100644 (file)
@@ -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
index 035bb24dabc9cc43d2f9ae10a3fe8562243230fd..6d5e2c00246e2a7d2d53d131890d39e18d497d51 100644 (file)
@@ -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':
index 21b6f40f25d71495433bf6c3a3eeeae5f4fa51c0..5cf2e9097ee1693ddcb15b0306b0ed33ed654bb8 100644 (file)
@@ -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