[PATCH 3 of 4 [leaflet]] python-modernize -w

adrien.dimascio at logilab.fr adrien.dimascio at logilab.fr
Sat Jun 9 18:09:33 CEST 2018


# HG changeset patch
# User Adrien Di Mascio <Adrien.DiMascio at logilab.fr>
# Date 1525278511 -7200
#      mer. mai 02 18:28:31 2018 +0200
# Node ID 958d5d617549772329132bdc4091e264f714a766
# Parent  8c5b7c30b4caa642f26b979ec19595867f5dd340
python-modernize -w

diff --git a/cubicweb_leaflet/setup.py b/cubicweb_leaflet/setup.py
--- a/cubicweb_leaflet/setup.py
+++ b/cubicweb_leaflet/setup.py
@@ -18,16 +18,22 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
 """Generic Setup script, takes package info from __pkginfo__.py file
 """
-__docformat__ = "restructuredtext en"
+from __future__ import absolute_import
 
 import os
 import sys
 import shutil
-from os.path import isdir, exists, join, walk
+from os.path import exists, join, walk
+
+import six
+
+from . import __pkginfo__
+
+__docformat__ = "restructuredtext en"
 
 try:
     if os.environ.get('NO_SETUPTOOLS'):
         raise ImportError() # do as there is no setuptools
     from setuptools import setup
@@ -38,26 +44,26 @@ except ImportError:
     from distutils.command import install_lib
     USE_SETUPTOOLS = False
 from distutils.command import install_data
 
 # import required features
-from __pkginfo__ import modname, version, license, description, web, \
+from .__pkginfo__ import modname, version, license, description, web, \
      author, author_email, classifiers
 
 if exists('README'):
-    long_description = file('README').read()
+    long_description = open('README').read()
 else:
     long_description = ''
 
 # import optional features
-import __pkginfo__
+
 if USE_SETUPTOOLS:
     requires = {}
     for entry in ("__depends__",): # "__recommends__"):
         requires.update(getattr(__pkginfo__, entry, {}))
     install_requires = [("%s %s" % (d, v and v or "")).strip()
-                       for d, v in requires.iteritems()]
+                       for d, v in six.iteritems(requires)]
 else:
     install_requires = []
 
 distname = getattr(__pkginfo__, 'distname', modname)
 scripts = getattr(__pkginfo__, 'scripts', ())
@@ -113,11 +119,11 @@ def export(from_dir, to_dir,
                 if exists(dest):
                     os.remove(dest)
                 shutil.copy2(src, dest)
     try:
         os.mkdir(to_dir)
-    except OSError, ex:
+    except OSError as ex:
         # file exists ?
         import errno
         if ex.errno != errno.EEXIST:
             raise
     walk(from_dir, make_mirror, None)
diff --git a/cubicweb_leaflet/views.py b/cubicweb_leaflet/views.py
--- a/cubicweb_leaflet/views.py
+++ b/cubicweb_leaflet/views.py
@@ -13,11 +13,14 @@
 # details.
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-leaflet views/forms/actions/components for web ui"""
-import json
+from __future__ import absolute_import
+
+import six
+from six.moves import range
 
 from logilab.mtconverter import xml_escape
 
 from cubicweb import _
 from cubicweb.utils import js_dumps, make_uid, JSString
@@ -83,11 +86,11 @@ class LeafletMap(object):
         }
     }
 
     def __init__(self, custom_settings=None):
         settings = self.get_settings(custom_settings)
-        if isinstance(settings['provider'], basestring):
+        if isinstance(settings['provider'], six.string_types):
             settings['provider'] = self.providers[settings['provider']]
         self.settings = settings
 
     def get_settings(self, custom_settings=None):
         settings = self.default_settings.copy()
@@ -195,11 +198,11 @@ class AbstractLeafletView(AnyRsetView):
         self.w(geomap.render(self._cw, datasource=markers, use_cdn=use_cdn))
 
     def _update_settings(self, custom_settings):
         """ Update the default settings with custom settings and form"""
         settings = custom_settings.copy() if custom_settings else {}
-        for attr, value in self._cw.form.iteritems():
+        for attr, value in six.iteritems(self._cw.form):
             if attr in settings:
                 settings[attr] = value
         if 'cluster' in self._cw.form:
             settings['cluster'] = True
         return settings
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -20,10 +20,11 @@
 # along with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
 """cubicweb_leaflet setup module using data from
 cubicweb_leaflet/__pkginfo__.py file
 """
 
+from __future__ import absolute_import
 from os.path import join, dirname
 
 from setuptools import find_packages, setup
 
 
diff --git a/test/test_leaflet.py b/test/test_leaflet.py
--- a/test/test_leaflet.py
+++ b/test/test_leaflet.py
@@ -35,10 +35,11 @@ uncomment code below if you want to acti
         def list_startup_views(self):
             '''only test startup views of the returned identifiers'''
             return ('some', 'startup', 'views')
 """
 
+from __future__ import absolute_import
 from cubicweb.devtools import testlib
 
 class DefaultTC(testlib.CubicWebTC):
     def test_something(self):
         self.skipTest('this cube has no test')


More information about the cubicweb-devel mailing list