[GRASS-SVN] r73358 - in grass/trunk/lib/python/pygrass: . raster
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Sep 16 21:04:08 PDT 2018
Author: annakrat
Date: 2018-09-16 21:04:08 -0700 (Sun, 16 Sep 2018)
New Revision: 73358
Modified:
grass/trunk/lib/python/pygrass/raster/category.py
grass/trunk/lib/python/pygrass/utils.py
Log:
pygrass: work on Python 3 support - fixes to get raster tests working
Modified: grass/trunk/lib/python/pygrass/raster/category.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/category.py 2018-09-17 02:30:53 UTC (rev 73357)
+++ grass/trunk/lib/python/pygrass/raster/category.py 2018-09-17 04:04:08 UTC (rev 73358)
@@ -11,7 +11,7 @@
from grass.exceptions import ImplementationError
from grass.pygrass.errors import GrassError
-
+from grass.pygrass.utils import decode
from grass.pygrass.raster.raster_type import TYPE as RTYPE
@@ -146,11 +146,11 @@
"""
min_cat = ctypes.pointer(RTYPE[self.mtype]['grass def']())
max_cat = ctypes.pointer(RTYPE[self.mtype]['grass def']())
- lab = libraster.Rast_get_ith_cat(ctypes.byref(self.c_cats),
- index,
- ctypes.cast(min_cat, ctypes.c_void_p),
- ctypes.cast(max_cat, ctypes.c_void_p),
- self._gtype)
+ lab = decode(libraster.Rast_get_ith_cat(ctypes.byref(self.c_cats),
+ index,
+ ctypes.cast(min_cat, ctypes.c_void_p),
+ ctypes.cast(max_cat, ctypes.c_void_p),
+ self._gtype))
# Manage C function Errors
if lab == '':
raise GrassError(_("Error executing: Rast_get_ith_cat"))
Modified: grass/trunk/lib/python/pygrass/utils.py
===================================================================
--- grass/trunk/lib/python/pygrass/utils.py 2018-09-17 02:30:53 UTC (rev 73357)
+++ grass/trunk/lib/python/pygrass/utils.py 2018-09-17 04:04:08 UTC (rev 73358)
@@ -7,6 +7,7 @@
import grass.lib.gis as libgis
libgis.G_gisinit('')
import grass.lib.raster as libraster
+from grass.lib.ctypes_preamble import String
from grass.script import core as grasscore
from grass.script import utils as grassutils
@@ -117,6 +118,19 @@
grasscore.run_command('g.copy', quiet=True, **kwargs)
+def decode(obj, encoding=None):
+ """Decode string coming from c functions,
+ can be ctypes class String, bytes, or None
+ """
+ if isinstance(obj, String):
+ return grassutils.decode(obj.data, encoding=encoding)
+ elif isinstance(obj, bytes):
+ return grassutils.decode(obj)
+ else:
+ # eg None
+ return obj
+
+
def getenv(env):
"""Return the current grass environment variables
@@ -125,7 +139,7 @@
True
"""
- return grassutils.decode(libgis.G_getenv_nofatal(env))
+ return decode(libgis.G_getenv_nofatal(env))
def get_mapset_raster(mapname, mapset=''):
@@ -135,7 +149,7 @@
True
"""
- return grassutils.decode(libgis.G_find_raster2(mapname, mapset))
+ return decode(libgis.G_find_raster2(mapname, mapset))
def get_mapset_vector(mapname, mapset=''):
@@ -145,7 +159,7 @@
True
"""
- return grassutils.decode(libgis.G_find_vector2(mapname, mapset))
+ return decode(libgis.G_find_vector2(mapname, mapset))
def is_clean_name(name):
More information about the grass-commit
mailing list