[py3] use six for xrange / basestrign compat
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 03 Sep 2018 10:26:24 +0200
changeset 540 03c8777469f5
parent 539 7cd2b9a4d60c
child 541 78ef292acda7
[py3] use six for xrange / basestrign compat
nazca/rl/aligner.py
nazca/rl/blocking.py
nazca/utils/dataio.py
nazca/utils/distances.py
--- a/nazca/rl/aligner.py	Mon Sep 03 10:17:09 2018 +0200
+++ b/nazca/rl/aligner.py	Mon Sep 03 10:26:24 2018 +0200
@@ -19,6 +19,7 @@
 from collections import defaultdict
 
 from six import iteritems
+from six.moves import xrange
 
 from scipy import zeros
 from scipy.sparse import lil_matrix
--- a/nazca/rl/blocking.py	Mon Sep 03 10:17:09 2018 +0200
+++ b/nazca/rl/blocking.py	Mon Sep 03 10:26:24 2018 +0200
@@ -30,6 +30,7 @@
 from functools import partial
 
 from six import iteritems, itervalues
+from six.moves import xrange
 
 from scipy.spatial import KDTree
 
--- a/nazca/utils/dataio.py	Mon Sep 03 10:17:09 2018 +0200
+++ b/nazca/utils/dataio.py	Mon Sep 03 10:26:24 2018 +0200
@@ -17,12 +17,13 @@
 
 from os.path import exists as fileexists
 from os import path as osp
-
+import codecs
 import json
 import csv
 import urllib
 
-from six import iteritems
+from six import string_types, iteritems
+from six.moves import xrange
 
 from lxml import etree
 
@@ -225,7 +226,7 @@
         if field_size_limit:
             csv.field_size_limit(field_size_limit)
 
-        if isinstance(filename, basestring):
+        if isinstance(filename, string_types):
             csvfile = open(filename, 'r')
         else:
             csvfile = filename
@@ -278,9 +279,9 @@
                 alignid = alignset[aligned][0]
                 targetid = targetset[target][0]
                 fobj.write('%s;%s;%s\n' %
-                           (alignid.encode('utf-8') if isinstance(alignid, basestring)
+                           (alignid.encode('utf-8') if isinstance(alignid, string_types)
                             else alignid,
-                            targetid.encode('utf-8') if isinstance(targetid, basestring)
+                            targetid.encode('utf-8') if isinstance(targetid, string_types)
                             else targetid,
                             dist
                             ))
--- a/nazca/utils/distances.py	Mon Sep 03 10:17:09 2018 +0200
+++ b/nazca/utils/distances.py	Mon Sep 03 10:26:24 2018 +0200
@@ -18,6 +18,9 @@
 import difflib
 from functools import partial
 from math import cos, sqrt, pi  # Needed for geographical distance
+
+from six.moves import xrange
+
 try:
     from dateutil import parser as dateparser
     DATEUTIL_ENABLED = True