Drop support for simplejson
[htsworkflow.git] / htsworkflow / pipelines / retrieve_config.py
index a00bbd017185ac8692361d11403bde3c2824cd4e..a2153d055230d9b35e94cf8f39e9aecc3b73a339 100644 (file)
@@ -1,19 +1,16 @@
 #!/usr/bin/env python
 
 import csv
-from ConfigParser import RawConfigParser
+from six.moves.configparser import RawConfigParser
 import logging
 from optparse import OptionParser, IndentedHelpFormatter
 import os
 import sys
 import types
-import urllib
-import urllib2
+import six
+from six.moves import urllib
 
-try:
-    import json
-except ImportError as e:
-    import simplejson as json
+import json
 
 from htsworkflow.auth import apidata
 from htsworkflow.util import api
@@ -47,9 +44,9 @@ def retrieve_flowcell_info(base_host_url, flowcell):
     url = api.flowcell_url(base_host_url, flowcell)
 
     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.HTTPError as e:
         errmsg = 'URLError: %d %s' % (e.code, e.msg)
         LOGGER.error(errmsg)
         LOGGER.error('opened %s' % (url,))
@@ -403,15 +400,13 @@ def format_pooled_libraries(shared, library):
     sequences = library.get('index_sequence', None)
     if sequences is None:
         return []
-    elif (type(sequences) in types.StringTypes and
-          sequences.lower().startswith('err')):
+    elif isinstance(sequences, six.string_types):
         shared['Index'] = ''
         shared['SampleProject'] = library['library_id']
         return [shared]
-    elif (type(sequences) == types.DictType):
+    elif isinstance(sequences, dict):
         pooled = []
-        multiplex_ids = sequences.keys()
-        multiplex_ids.sort(key=natural_sort_key)
+        multiplex_ids = sorted(sequences.keys(), key=natural_sort_key)
         for multiplex_id in multiplex_ids:
             sample = {}
             sample.update(shared)