Browse Source

pygrass: fix python2 and python3 syntax

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@68353 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 9 years ago
parent
commit
241ebc25e8

+ 1 - 1
lib/python/pygrass/rpc/__init__.py

@@ -21,7 +21,7 @@ from grass.exceptions import FatalError
 from grass.pygrass.vector import *
 from grass.pygrass.raster import *
 import grass.lib.gis as libgis
-from base import RPCServerBase
+from .base import RPCServerBase
 from grass.pygrass.gis.region import Region
 import grass.pygrass.utils as utils
 import logging

+ 7 - 5
lib/python/pygrass/vector/__init__.py

@@ -1,4 +1,6 @@
 # -*- coding: utf-8 -*-
+from __future__ import print_function
+
 from os.path import join, exists
 import grass.lib.gis as libgis
 libgis.G_gisinit('')
@@ -188,7 +190,7 @@ class Vector(Info):
                 cur = self.table.conn.cursor()
                 cur.execute(self.table.columns.insert_str, attr)
                 cur.close()
-        
+
         if cat is not None:
             cats = Cats(geo_obj.c_cats)
             cats.reset()
@@ -246,7 +248,7 @@ class VectorTopo(Vector):
 
         >>> with VectorTopo(test_vector_name, mode='r') as test_vect:
         ...     for feature in test_vect[:7]:
-        ...         print feature.attrs['name']
+        ...         print(feature.attrs['name'])
         ...
         point
         point
@@ -396,7 +398,7 @@ class VectorTopo(Vector):
             >>> from operator import methodcaller as method
             >>> areas.sort(key=method('area'), reverse=True)  # sort the list
             >>> for area in areas[:3]:
-            ...     print area, area.area()
+            ...     print(area, area.area())
             Area(1) 12.0
             Area(2) 8.0
             Area(4) 8.0
@@ -533,8 +535,8 @@ class VectorTopo(Vector):
             attr.extend(attrs)
             self.table.update(key=line, values=attr)
         elif self.table is None and attrs:
-            print "Table for vector {name} does not exist, attributes not" \
-                  " loaded".format(name=self.name)
+            print("Table for vector {name} does not exist, attributes not"
+                  " loaded".format(name=self.name))
         libvect.Vect_cat_set(geo_obj.c_cats, self.layer, line)
         result = libvect.Vect_rewrite_line(self.c_mapinfo,
                                            line, geo_obj.gtype,

+ 1 - 1
lib/python/pygrass/vector/table.py

@@ -194,7 +194,7 @@ class Columns(object):
         return item in self.names()
 
     def __repr__(self):
-        return "Columns(%r)" % self.items()
+        return "Columns(%r)" % list(self.items())
 
     def __getitem__(self, key):
         return self.odict[key]

+ 6 - 0
lib/python/pygrass/vector/testsuite/test_table.py

@@ -4,6 +4,12 @@ Created on Wed Jun 25 11:08:22 2014
 
 @author: pietro
 """
+try:
+    from builtins import long
+except ImportError:
+    # python3
+    long = int
+
 import os
 import sqlite3
 import tempfile as tmp