[GRASS-SVN] r73903 - in grass/trunk: gui/wxpython/core lib/python/ctypes lib/python/ctypes/ctypesgencore/printer lib/python/pygrass/gis lib/python/pygrass/modules/interface lib/python/pygrass/raster lib/python/pygrass/raster/testsuite lib/python/pygrass/vector lib/python/pygrass/vector/testsuite lib/python/temporal temporal/t.info temporal/t.merge temporal/t.rast.gapfill temporal/t.rast.series temporal/t.rast.to.rast3 temporal/t.rename temporal/t.unregister temporal/t.vect.observe.strds

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 2 11:34:42 PST 2019


Author: annakrat
Date: 2019-01-02 11:34:42 -0800 (Wed, 02 Jan 2019)
New Revision: 73903

Modified:
   grass/trunk/gui/wxpython/core/utils.py
   grass/trunk/lib/python/ctypes/ctypesgencore/printer/preamble.py
   grass/trunk/lib/python/ctypes/preamble.py
   grass/trunk/lib/python/pygrass/gis/__init__.py
   grass/trunk/lib/python/pygrass/modules/interface/module.py
   grass/trunk/lib/python/pygrass/raster/history.py
   grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_region.py
   grass/trunk/lib/python/pygrass/vector/__init__.py
   grass/trunk/lib/python/pygrass/vector/abstract.py
   grass/trunk/lib/python/pygrass/vector/geometry.py
   grass/trunk/lib/python/pygrass/vector/testsuite/test_geometry_attrs.py
   grass/trunk/lib/python/pygrass/vector/testsuite/test_table.py
   grass/trunk/lib/python/temporal/c_libraries_interface.py
   grass/trunk/lib/python/temporal/core.py
   grass/trunk/lib/python/temporal/open_stds.py
   grass/trunk/temporal/t.info/t.info.py
   grass/trunk/temporal/t.merge/t.merge.py
   grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py
   grass/trunk/temporal/t.rast.series/t.rast.series.py
   grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py
   grass/trunk/temporal/t.rename/t.rename.py
   grass/trunk/temporal/t.unregister/t.unregister.py
   grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py
Log:
python: various fixes for python 3 in pygrass and temporal

Modified: grass/trunk/gui/wxpython/core/utils.py
===================================================================
--- grass/trunk/gui/wxpython/core/utils.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/gui/wxpython/core/utils.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -260,7 +260,7 @@
     catstr = ''
 
     try:
-        cats = map(int, cats)
+        cats = list(map(int, cats))
     except:
         return catstr
 

Modified: grass/trunk/lib/python/ctypes/ctypesgencore/printer/preamble.py
===================================================================
--- grass/trunk/lib/python/ctypes/ctypesgencore/printer/preamble.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/ctypes/ctypesgencore/printer/preamble.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -1,13 +1,14 @@
+import ctypes
 import os
 import sys
-
-import ctypes
+import six
 from ctypes import *
+from grass.script.utils import encode
 
-if sys.version_info.major == 3:
+if sys.version_info.major >= 3:
     long = int
+    unicode = str
 
-
 _int_types = (c_int16, c_int32)
 if hasattr(ctypes, 'c_int64'):
     # Some builds of ctypes apparently do not have c_int64
@@ -45,7 +46,6 @@
 
 
 class UserString:
-
     def __init__(self, seq):
         if isinstance(seq, str):
             self.data = seq
@@ -292,8 +292,8 @@
                 ('data', c_char_p)]
 
     def __init__(self, obj=""):
-        if isinstance(obj, (str, UserString)):
-            self.data = str(obj)
+        if isinstance(obj, (str, unicode, bytes, UserString)):
+            self.data = encode(obj)
         else:
             self.raw = obj
 
@@ -310,9 +310,13 @@
             return obj
 
         # Convert from str
-        elif isinstance(obj, str):
+        elif isinstance(obj, bytes):
             return cls(obj)
 
+        # Convert from str/unicode
+        elif isinstance(obj, (str, unicode)):
+            return cls(obj)
+
         # Convert from c_char_p
         elif isinstance(obj, c_char_p):
             return obj
@@ -325,6 +329,10 @@
         elif isinstance(obj, int):
             return cls(cast(obj, POINTER(c_char)))
 
+        # Convert from c_char array
+        elif isinstance(obj, c_char * len(obj)):
+            return obj
+
         # Convert from object
         else:
             return String.from_param(obj._as_parameter_)
@@ -331,7 +339,7 @@
     from_param = classmethod(from_param)
 
 
-def ReturnString(obj):
+def ReturnString(obj, func=None, arguments=None):
     return String.from_param(obj)
 
 # As of ctypes 1.0, ctypes does not support custom error-checking
@@ -356,10 +364,12 @@
 
 class _variadic_function(object):
 
-    def __init__(self, func, restype, argtypes):
+    def __init__(self, func, restype, argtypes, errcheck):
         self.func = func
         self.func.restype = restype
         self.argtypes = argtypes
+        if errcheck:
+            self.func.errcheck = errcheck
 
     def _as_parameter_(self):
         # So we can pass this variadic function as a function pointer

Modified: grass/trunk/lib/python/ctypes/preamble.py
===================================================================
--- grass/trunk/lib/python/ctypes/preamble.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/ctypes/preamble.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -3,7 +3,7 @@
 import sys
 import six
 from ctypes import *
-from grass.script.utils import encode, decode
+from grass.script.utils import encode
 
 if sys.version_info.major >= 3:
     long = int
@@ -22,6 +22,13 @@
 del _int_types
 
 
+class c_void(Structure):
+    # c_void_p is a buggy return type, converting to int, so
+    # POINTER(None) == c_void_p is actually written as
+    # POINTER(c_void), so it can be treated as a real pointer.
+    _fields_ = [('dummy', c_int)]
+
+
 def POINTER(obj):
     p = ctypes.POINTER(obj)
 
@@ -40,7 +47,7 @@
 
 class UserString:
     def __init__(self, seq):
-        if isinstance(seq, basestring):
+        if isinstance(seq, str):
             self.data = seq
         elif isinstance(seq, UserString):
             self.data = seq.data[:]
@@ -47,26 +54,19 @@
         else:
             self.data = str(seq)
 
-    def __str__(self):
-        return str(self.data)
+    def __str__(self): return str(self.data)
 
-    def __repr__(self):
-        return repr(self.data)
+    def __repr__(self): return repr(self.data)
 
-    def __int__(self):
-        return int(self.data)
+    def __int__(self): return int(self.data)
 
-    def __long__(self):
-        return long(self.data)
+    def __long__(self): return long(self.data)
 
-    def __float__(self):
-        return float(self.data)
+    def __float__(self): return float(self.data)
 
-    def __complex__(self):
-        return complex(self.data)
+    def __complex__(self): return complex(self.data)
 
-    def __hash__(self):
-        return hash(self.data)
+    def __hash__(self): return hash(self.data)
 
     def __cmp__(self, string):
         if isinstance(string, UserString):
@@ -77,11 +77,9 @@
     def __contains__(self, char):
         return char in self.data
 
-    def __len__(self):
-        return len(self.data)
+    def __len__(self): return len(self.data)
 
-    def __getitem__(self, index):
-        return self.__class__(self.data[index])
+    def __getitem__(self, index): return self.__class__(self.data[index])
 
     def __getslice__(self, start, end):
         start = max(start, 0)
@@ -91,13 +89,13 @@
     def __add__(self, other):
         if isinstance(other, UserString):
             return self.__class__(self.data + other.data)
-        elif isinstance(other, basestring):
+        elif isinstance(other, str):
             return self.__class__(self.data + other)
         else:
             return self.__class__(self.data + str(other))
 
     def __radd__(self, other):
-        if isinstance(other, basestring):
+        if isinstance(other, str):
             return self.__class__(other + self.data)
         else:
             return self.__class__(str(other) + self.data)
@@ -110,8 +108,7 @@
         return self.__class__(self.data % args)
 
     # the following methods are defined in alphabetical order:
-    def capitalize(self):
-        return self.__class__(self.data.capitalize())
+    def capitalize(self): return self.__class__(self.data.capitalize())
 
     def center(self, width, *args):
         return self.__class__(self.data.center(width, *args))
@@ -149,44 +146,32 @@
     def index(self, sub, start=0, end=sys.maxsize):
         return self.data.index(sub, start, end)
 
-    def isalpha(self):
-        return self.data.isalpha()
+    def isalpha(self): return self.data.isalpha()
 
-    def isalnum(self):
-        return self.data.isalnum()
+    def isalnum(self): return self.data.isalnum()
 
-    def isdecimal(self):
-        return self.data.isdecimal()
+    def isdecimal(self): return self.data.isdecimal()
 
-    def isdigit(self):
-        return self.data.isdigit()
+    def isdigit(self): return self.data.isdigit()
 
-    def islower(self):
-        return self.data.islower()
+    def islower(self): return self.data.islower()
 
-    def isnumeric(self):
-        return self.data.isnumeric()
+    def isnumeric(self): return self.data.isnumeric()
 
-    def isspace(self):
-        return self.data.isspace()
+    def isspace(self): return self.data.isspace()
 
-    def istitle(self):
-        return self.data.istitle()
+    def istitle(self): return self.data.istitle()
 
-    def isupper(self):
-        return self.data.isupper()
+    def isupper(self): return self.data.isupper()
 
-    def join(self, seq):
-        return self.data.join(seq)
+    def join(self, seq): return self.data.join(seq)
 
     def ljust(self, width, *args):
         return self.__class__(self.data.ljust(width, *args))
 
-    def lower(self):
-        return self.__class__(self.data.lower())
+    def lower(self): return self.__class__(self.data.lower())
 
-    def lstrip(self, chars=None):
-        return self.__class__(self.data.lstrip(chars))
+    def lstrip(self, chars=None): return self.__class__(self.data.lstrip(chars))
 
     def partition(self, sep):
         return self.data.partition(sep)
@@ -206,8 +191,7 @@
     def rpartition(self, sep):
         return self.data.rpartition(sep)
 
-    def rstrip(self, chars=None):
-        return self.__class__(self.data.rstrip(chars))
+    def rstrip(self, chars=None): return self.__class__(self.data.rstrip(chars))
 
     def split(self, sep=None, maxsplit=-1):
         return self.data.split(sep, maxsplit)
@@ -215,29 +199,23 @@
     def rsplit(self, sep=None, maxsplit=-1):
         return self.data.rsplit(sep, maxsplit)
 
-    def splitlines(self, keepends=0):
-        return self.data.splitlines(keepends)
+    def splitlines(self, keepends=0): return self.data.splitlines(keepends)
 
     def startswith(self, prefix, start=0, end=sys.maxsize):
         return self.data.startswith(prefix, start, end)
 
-    def strip(self, chars=None):
-        return self.__class__(self.data.strip(chars))
+    def strip(self, chars=None): return self.__class__(self.data.strip(chars))
 
-    def swapcase(self):
-        return self.__class__(self.data.swapcase())
+    def swapcase(self): return self.__class__(self.data.swapcase())
 
-    def title(self):
-        return self.__class__(self.data.title())
+    def title(self): return self.__class__(self.data.title())
 
     def translate(self, *args):
         return self.__class__(self.data.translate(*args))
 
-    def upper(self):
-        return self.__class__(self.data.upper())
+    def upper(self): return self.__class__(self.data.upper())
 
-    def zfill(self, width):
-        return self.__class__(self.data.zfill(width))
+    def zfill(self, width): return self.__class__(self.data.zfill(width))
 
 
 class MutableString(UserString):
@@ -281,7 +259,7 @@
         end = max(end, 0)
         if isinstance(sub, UserString):
             self.data = self.data[:start] + sub.data + self.data[end:]
-        elif isinstance(sub, basestring):
+        elif isinstance(sub, str):
             self.data = self.data[:start] + sub + self.data[end:]
         else:
             self.data = self.data[:start] + str(sub) + self.data[end:]
@@ -297,7 +275,7 @@
     def __iadd__(self, other):
         if isinstance(other, UserString):
             self.data += other.data
-        elif isinstance(other, basestring):
+        elif isinstance(other, str):
             self.data += other
         else:
             self.data += str(other)
@@ -314,8 +292,8 @@
                 ('data', c_char_p)]
 
     def __init__(self, obj=""):
-        if isinstance(obj, (str, unicode, UserString)):
-            self.data = encode(str(obj))
+        if isinstance(obj, (str, unicode, bytes, UserString)):
+            self.data = encode(obj)
         else:
             self.raw = obj
 

Modified: grass/trunk/lib/python/pygrass/gis/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/gis/__init__.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/pygrass/gis/__init__.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -50,7 +50,7 @@
     :return: True if valid else False
     :rtype: str
     """
-    return bool(CHECK_IS[type](encode(join(path, value))))
+    return bool(CHECK_IS[type](join(path, value)))
 
 
 def _check_raise(value, path, type):

Modified: grass/trunk/lib/python/pygrass/modules/interface/module.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/interface/module.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/pygrass/modules/interface/module.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -8,7 +8,8 @@
 
 from grass.exceptions import CalledModuleError, GrassError, ParameterError
 from grass.script.core import Popen, PIPE, use_temp_region, del_temp_region
-from grass.script.utils import encode, decode
+from grass.script.utils import encode
+from grass.pygrass.utils import decode
 from .docstring import docstring_property
 from .parameter import Parameter
 from .flag import Flag

Modified: grass/trunk/lib/python/pygrass/raster/history.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/history.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/pygrass/raster/history.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -8,6 +8,7 @@
 import grass.lib.raster as libraster
 import datetime
 from grass.script.utils import encode
+from grass.pygrass.utils import decode
 
 
 class History(object):
@@ -54,8 +55,8 @@
     # ----------------------------------------------------------------------
     # libraster.HIST_CREATOR
     def _get_creator(self):
-        return libraster.Rast_get_history(self.c_hist,
-                                          libraster.HIST_CREATOR)
+        return decode(libraster.Rast_get_history(self.c_hist,
+                                                 libraster.HIST_CREATOR))
 
     def _set_creator(self, creator):
         creator = encode(creator)
@@ -69,8 +70,8 @@
     # ----------------------------------------------------------------------
     # libraster.HIST_DATSRC_1
     def _get_src1(self):
-        return libraster.Rast_get_history(self.c_hist,
-                                          libraster.HIST_DATSRC_1)
+        return decode(libraster.Rast_get_history(self.c_hist,
+                                                 libraster.HIST_DATSRC_1))
 
     def _set_src1(self, src1):
         src1 = encode(src1)
@@ -84,8 +85,8 @@
     # ----------------------------------------------------------------------
     # libraster.HIST_DATSRC_2
     def _get_src2(self):
-        return libraster.Rast_get_history(self.c_hist,
-                                          libraster.HIST_DATSRC_2)
+        return decode(libraster.Rast_get_history(self.c_hist,
+                                                 libraster.HIST_DATSRC_2))
 
     def _set_src2(self, src2):
         src2 = encode(src2)
@@ -99,8 +100,8 @@
     # ----------------------------------------------------------------------
     # libraster.HIST_KEYWORD
     def _get_keyword(self):
-        return libraster.Rast_get_history(self.c_hist,
-                                          libraster.HIST_KEYWRD)
+        return decode(libraster.Rast_get_history(self.c_hist,
+                                                 libraster.HIST_KEYWRD))
 
     def _set_keyword(self, keyword):
         keyword = encode(keyword)
@@ -114,8 +115,8 @@
     # ----------------------------------------------------------------------
     # libraster.HIST_MAPID
     def _get_date(self):
-        date_str = libraster.Rast_get_history(self.c_hist,
-                                              libraster.HIST_MAPID)
+        date_str = decode(libraster.Rast_get_history(self.c_hist,
+                                                     libraster.HIST_MAPID))
         if date_str:
             try:
                 return datetime.datetime.strptime(date_str, self.date_fmt)
@@ -136,8 +137,8 @@
     # ----------------------------------------------------------------------
     # libraster.HIST_MAPSET
     def _get_mapset(self):
-        return libraster.Rast_get_history(self.c_hist,
-                                          libraster.HIST_MAPSET)
+        return decode(libraster.Rast_get_history(self.c_hist,
+                                                 libraster.HIST_MAPSET))
 
     def _set_mapset(self, mapset):
         mapset = encode(mapset)
@@ -151,8 +152,8 @@
     # ----------------------------------------------------------------------
     # libraster.HIST_MAPTYPE
     def _get_maptype(self):
-        return libraster.Rast_get_history(self.c_hist,
-                                          libraster.HIST_MAPTYPE)
+        return decode(libraster.Rast_get_history(self.c_hist,
+                                                 libraster.HIST_MAPTYPE))
 
     def _set_maptype(self, maptype):
         maptype = encode(maptype)
@@ -181,8 +182,8 @@
     # ----------------------------------------------------------------------
     # libraster.HIST_TITLE
     def _get_title(self):
-        return libraster.Rast_get_history(self.c_hist,
-                                          libraster.HIST_TITLE)
+        return decode(libraster.Rast_get_history(self.c_hist,
+                                                 libraster.HIST_TITLE))
 
     def _set_title(self, title):
         title = encode(title)

Modified: grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_region.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_region.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_region.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -1,4 +1,5 @@
 # -*- coding: utf-8
+import six
 from grass.gunittest.case import TestCase
 from grass.gunittest.main import test
 
@@ -42,8 +43,8 @@
         rast.set_region(region)
         rast.open(mode='r')
         
-        self.assertItemsEqual(rast[0].tolist(), [22, 22, 22, 22, 22, 32, 32, 32, 32, 32])
-        self.assertItemsEqual(rast[5].tolist(), [23, 23, 23, 23, 23, 33, 33, 33, 33, 33])
+        six.assertCountEqual(self, rast[0].tolist(), [22, 22, 22, 22, 22, 32, 32, 32, 32, 32])
+        six.assertCountEqual(self, rast[5].tolist(), [23, 23, 23, 23, 23, 33, 33, 33, 33, 33])
         
         rast.close()
 
@@ -74,8 +75,8 @@
         [nan, nan, nan, nan, nan, nan, nan, nan]
         """
 
-        self.assertItemsEqual(rast[2].tolist()[2:6], [11., 21., 31., 41.])
-        self.assertItemsEqual(rast[5].tolist()[2:6], [14., 24., 34., 44.])
+        six.assertCountEqual(self, rast[2].tolist()[2:6], [11., 21., 31., 41.])
+        six.assertCountEqual(self, rast[5].tolist()[2:6], [14., 24., 34., 44.])
         
         rast.close()
 

Modified: grass/trunk/lib/python/pygrass/vector/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/__init__.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/pygrass/vector/__init__.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -88,7 +88,7 @@
         return self
 
     @must_be_open
-    def next(self):
+    def __next__(self):
         """::
 
             >>> test_vect = Vector(test_vector_name)
@@ -105,6 +105,10 @@
                               is2D=not self.is_3D())
 
     @must_be_open
+    def next(self):
+        return self.__next__()
+
+    @must_be_open
     def rewind(self):
         """Rewind vector map to cause reads to start at beginning."""
         if libvect.Vect_rewind(self.c_mapinfo) == -1:

Modified: grass/trunk/lib/python/pygrass/vector/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/abstract.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/pygrass/vector/abstract.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -119,7 +119,7 @@
 
     def _set_organization(self, org):
         """Private method to change the Vector organization"""
-        libvect.Vect_set_organization(self.c_mapinfo, ctypes.c_char_p(org))
+        libvect.Vect_set_organization(self.c_mapinfo, org)
 
     organization = property(fget=_get_organization, fset=_set_organization,
                             doc="Set or obtain the Vector organization")
@@ -130,7 +130,7 @@
 
     def _set_date(self, date):
         """Private method to change the Vector date"""
-        return libvect.Vect_set_date(self.c_mapinfo, ctypes.c_char_p(date))
+        return libvect.Vect_set_date(self.c_mapinfo, date)
 
     date = property(fget=_get_date, fset=_set_date,
                     doc="Set or obtain the Vector date")
@@ -141,7 +141,7 @@
 
     def _set_person(self, person):
         """Private method to change the Vector person"""
-        libvect.Vect_set_person(self.c_mapinfo, ctypes.c_char_p(person))
+        libvect.Vect_set_person(self.c_mapinfo, person)
 
     person = property(fget=_get_person, fset=_set_person,
                       doc="Set or obtain the Vector author")
@@ -152,7 +152,7 @@
 
     def _set_title(self, title):
         """Private method to change the Vector title"""
-        libvect.Vect_set_map_name(self.c_mapinfo, ctypes.c_char_p(title))
+        libvect.Vect_set_map_name(self.c_mapinfo, title)
 
     title = property(fget=_get_title, fset=_set_title,
                      doc="Set or obtain the Vector title")
@@ -168,7 +168,7 @@
     def _set_map_date(self, datetimeobj):
         """Private method to change the Vector map date"""
         date_str = datetimeobj.strftime(self.date_fmt)
-        libvect.Vect_set_map_date(self.c_mapinfo, ctypes.c_char_p(date_str))
+        libvect.Vect_set_map_date(self.c_mapinfo, date_str)
 
     map_date = property(fget=_get_map_date, fset=_set_map_date,
                         doc="Set or obtain the Vector map date")
@@ -190,7 +190,7 @@
 
     def _set_comment(self, comm):
         """Private method to set the Vector comment"""
-        return libvect.Vect_set_comment(self.c_mapinfo, ctypes.c_char_p(comm))
+        return libvect.Vect_set_comment(self.c_mapinfo, comm)
 
     comment = property(fget=_get_comment, fset=_set_comment,
                        doc="Set or obtain the Vector comment")

Modified: grass/trunk/lib/python/pygrass/vector/geometry.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/geometry.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/pygrass/vector/geometry.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -14,6 +14,7 @@
 import grass.lib.gis as libgis
 import grass.lib.vector as libvect
 
+from grass.pygrass.utils import decode
 from grass.pygrass.errors import GrassError, mapinfo_must_be_set
 
 from grass.pygrass.vector.basic import Ilist, Bbox, Cats
@@ -375,7 +376,7 @@
             >>> pnt.to_wkt()
             'POINT (10.0000000000000000 100.0000000000000000)'
         """
-        return libvect.Vect_line_to_wkt(self.c_points, self.gtype, not self.is2D)
+        return decode(libvect.Vect_line_to_wkt(self.c_points, self.gtype, not self.is2D))
 
     def to_wkb(self):
         """Return a "well know binary" (WKB) geometry byte array, this method uses
@@ -721,8 +722,8 @@
                                           pnt.c_points.contents.x,
                                           pnt.c_points.contents.y,
                                           pnt.c_points.contents.z,
-                                          ctypes.c_double(angle),
-                                          ctypes.c_double(slope)):
+                                          ctypes.pointer(ctypes.c_double(angle)),
+                                          ctypes.pointer(ctypes.c_double(slope))):
             raise ValueError("Vect_point_on_line give an error.")
         pnt.is2D = self.is2D
         return pnt
@@ -1710,7 +1711,7 @@
         """Return a "well know text" (WKT) area string, this method uses
            the GEOS implementation in the vector library. ::
         """
-        return libvect.Vect_read_area_to_wkt(self.c_mapinfo, self.id)
+        return decode(libvect.Vect_read_area_to_wkt(self.c_mapinfo, self.id))
 
     def to_wkb(self):
         """Return a "well know binary" (WKB) area byte array, this method uses

Modified: grass/trunk/lib/python/pygrass/vector/testsuite/test_geometry_attrs.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/testsuite/test_geometry_attrs.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/pygrass/vector/testsuite/test_geometry_attrs.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -54,7 +54,7 @@
         with self.assertRaises(ValueError) as cm:
             self.attrs['not_existing_column_name']
 
-        self.assertTrue(u"not_existing_column_name" in cm.exception.message)
+        self.assertTrue(u"not_existing_column_name" in str(cm.exception))
 
 
     def test_setitem(self):

Modified: grass/trunk/lib/python/pygrass/vector/testsuite/test_table.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/testsuite/test_table.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/pygrass/vector/testsuite/test_table.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -73,6 +73,9 @@
     """Define a class to share common methods between TestCase."""
     path = os.path.join(tmp.gettempdir(), randstr(prefix='temp', suffix='.db'))
     connection = sqlite3.connect(get_path(path))
+    for t in (np.int8, np.int16, np.int32, np.int64, np.uint8,
+              np.uint16, np.uint32, np.uint64):
+        sqlite3.register_adapter(t, int)
     columns = [('cat', 'INTEGER PRIMARY KEY'),
                ('cint', 'INT'),
                ('creal', 'REAL'),

Modified: grass/trunk/lib/python/temporal/c_libraries_interface.py
===================================================================
--- grass/trunk/lib/python/temporal/c_libraries_interface.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/temporal/c_libraries_interface.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -27,7 +27,8 @@
 from grass.pygrass.rpc.base import RPCServerBase
 from grass.pygrass.raster import RasterRow
 from grass.pygrass.vector import VectorTopo
-from grass.script.utils import encode, decode
+from grass.script.utils import encode
+from grass.pygrass.utils import decode
 
 ###############################################################################
 
@@ -190,7 +191,7 @@
        :returns: Name of the current mapset
     """
     mapset = libgis.G_mapset()
-    conn.send(mapset)
+    conn.send(decode(mapset))
 
 ###############################################################################
 
@@ -205,7 +206,7 @@
        :returns: Name of the location
     """
     location = libgis.G_location()
-    conn.send(location)
+    conn.send(decode(location))
 
 ###############################################################################
 
@@ -220,7 +221,7 @@
        :returns: Name of the gisdatabase
     """
     gisdbase = libgis.G_gisdbase()
-    conn.send(gisdbase)
+    conn.send(decode(gisdbase))
 
 ###############################################################################
 
@@ -237,9 +238,11 @@
     mapset = data[1]
     if not mapset:
         mapset = libgis.G_mapset()
+    else:
+        mapset = encode(mapset)
 
     drstring = libtgis.tgis_get_mapset_driver_name(mapset)
-    conn.send(drstring.data)
+    conn.send(decode(drstring.data))
 
 ###############################################################################
 
@@ -258,6 +261,8 @@
         mapset = data[1]
         if not mapset:
             mapset = libgis.G_mapset()
+        else:
+            mapset = encode(mapset)
         dbstring = libtgis.tgis_get_mapset_database_name(mapset)
         dbstring = dbstring.data
 
@@ -266,11 +271,11 @@
             # This behavior is in conjunction with db.connect
             dbstring = dbstring.replace(encode("$GISDBASE"), libgis.G_gisdbase())
             dbstring = dbstring.replace(encode("$LOCATION_NAME"), libgis.G_location())
-            dbstring = dbstring.replace(encode("$MAPSET"), encode(mapset))
+            dbstring = dbstring.replace(encode("$MAPSET"), mapset)
     except:
         raise
     finally:
-        conn.send(dbstring)
+        conn.send(decode(dbstring))
 
 ###############################################################################
 

Modified: grass/trunk/lib/python/temporal/core.py
===================================================================
--- grass/trunk/lib/python/temporal/core.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/temporal/core.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -450,11 +450,11 @@
     global message_interface
 
     mapsets = c_library_interface.available_mapsets()
-
+    
     tgis_mapsets = {}
 
     for mapset in mapsets:
-        mapset = decode(mapset)
+        mapset = mapset
         driver = c_library_interface.get_driver_name(mapset)
         database = c_library_interface.get_database_name(mapset)
 
@@ -461,20 +461,18 @@
         message_interface.debug(1, "get_available_temporal_mapsets: "\
                                    "\n  mapset %s\n  driver %s\n  database %s"%(mapset,
                                    driver, database))
-
         if driver and database:
             # Check if the temporal sqlite database exists
             # We need to set non-existing databases in case the mapset is the current mapset
             # to create it
-            if (encode(driver) == "sqlite" and os.path.exists(database)) or encode(mapset) == get_current_mapset() :
+            if (driver == "sqlite" and os.path.exists(database)) or mapset == get_current_mapset() :
                 tgis_mapsets[mapset] = (driver,  database)
 
             # We need to warn if the connection is defined but the database does not
             # exists
-            if encode(driver) == "sqlite" and not os.path.exists(database):
+            if driver == "sqlite" and not os.path.exists(database):
                 message_interface.warning("Temporal database connection defined as:\n" + \
                                           database + "\nBut database file does not exist.")
-
     return tgis_mapsets
 
 ###############################################################################
@@ -543,9 +541,9 @@
     grassenv = gscript.gisenv()
 
     # Set the global variable for faster access
-    current_mapset = gscript.encode(grassenv["MAPSET"])
-    current_location = gscript.encode(grassenv["LOCATION_NAME"])
-    current_gisdbase = gscript.encode(grassenv["GISDBASE"])
+    current_mapset = grassenv["MAPSET"]
+    current_location = grassenv["LOCATION_NAME"]
+    current_gisdbase = grassenv["GISDBASE"]
 
     # Check environment variable GRASS_TGIS_RAISE_ON_ERROR
     if os.getenv("GRASS_TGIS_RAISE_ON_ERROR") == "True" or \

Modified: grass/trunk/lib/python/temporal/open_stds.py
===================================================================
--- grass/trunk/lib/python/temporal/open_stds.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/lib/python/temporal/open_stds.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -49,7 +49,7 @@
 
     # Check if the dataset name contains the mapset as well
     if name.find("@") < 0:
-        id = name.decode("utf-8") + "@" + mapset.decode("utf-8")
+        id = name + "@" + mapset
     else:
         id = name
 

Modified: grass/trunk/temporal/t.info/t.info.py
===================================================================
--- grass/trunk/temporal/t.info/t.info.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/temporal/t.info/t.info.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -105,7 +105,7 @@
     if name.find("@") >= 0:
         id_ = name
     else:
-        id_ = name + "@" + grass.encode(grass.gisenv()["MAPSET"])
+        id_ = name + "@" + grass.gisenv()["MAPSET"])
 
     dataset = tgis.dataset_factory(type_, id_)
 

Modified: grass/trunk/temporal/t.merge/t.merge.py
===================================================================
--- grass/trunk/temporal/t.merge/t.merge.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/temporal/t.merge/t.merge.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -58,7 +58,7 @@
     tgis.init()
 
     #Get the current mapset to create the id of the space time dataset
-    mapset = grass.encode(grass.gisenv()["MAPSET"])
+    mapset = grass.gisenv()["MAPSET"]
 
     inputs_split = inputs.split(",")
     input_ids = []

Modified: grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py
===================================================================
--- grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/temporal/t.rast.gapfill/t.rast.gapfill.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -89,7 +89,7 @@
     nprocs = options["nprocs"]
     tsuffix = options["suffix"]
 
-    mapset = grass.encode(grass.gisenv()["MAPSET"])
+    mapset = grass.gisenv()["MAPSET"]
 
     # Make sure the temporal database exists
     tgis.init()

Modified: grass/trunk/temporal/t.rast.series/t.rast.series.py
===================================================================
--- grass/trunk/temporal/t.rast.series/t.rast.series.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/temporal/t.rast.series/t.rast.series.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -137,7 +137,7 @@
             if output.find("@") >= 0:
                 id = output
             else:
-                mapset = grass.encode(grass.gisenv()["MAPSET"])
+                mapset = grass.gisenv()["MAPSET"]
                 id = output + "@" + mapset
 
             map = sp.get_new_map_instance(id)

Modified: grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py
===================================================================
--- grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -56,7 +56,7 @@
     # Make sure the temporal database exists
     tgis.init()
 
-    mapset = grass.encode(grass.gisenv()["MAPSET"])
+    mapset = grass.gisenv()["MAPSET"]
 
     sp = tgis.open_old_stds(input, "strds")
 

Modified: grass/trunk/temporal/t.rename/t.rename.py
===================================================================
--- grass/trunk/temporal/t.rename/t.rename.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/temporal/t.rename/t.rename.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -57,7 +57,7 @@
     tgis.init()
 
     #Get the current mapset to create the id of the space time dataset
-    mapset = grass.encode(grass.gisenv()["MAPSET"])
+    mapset = grass.gisenv()["MAPSET"]
 
     if input.find("@") >= 0:
         old_id = input

Modified: grass/trunk/temporal/t.unregister/t.unregister.py
===================================================================
--- grass/trunk/temporal/t.unregister/t.unregister.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/temporal/t.unregister/t.unregister.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -73,7 +73,7 @@
     if not maps and not file:
         grass.fatal(_("%s= or %s= must be specified") % ("input", "file"))
 
-    mapset = grass.encode(grass.gisenv()["MAPSET"])
+    mapset = grass.gisenv()["MAPSET"]
 
     dbif = tgis.SQLDatabaseInterfaceConnection()
     dbif.connect()

Modified: grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py
===================================================================
--- grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py	2019-01-02 18:30:28 UTC (rev 73902)
+++ grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py	2019-01-02 19:34:42 UTC (rev 73903)
@@ -104,7 +104,7 @@
     dbif = tgis.SQLDatabaseInterfaceConnection()
     dbif.connect()
 
-    mapset = grass.encode(grass.gisenv()["MAPSET"])
+    mapset = grass.gisenv()["MAPSET"]
 
     out_sp = tgis.check_new_stds(output, "stvds", dbif, overwrite)
 



More information about the grass-commit mailing list