Ver código fonte

pythonlib: fix for comment:4:ticket:2431 - object_pairs_hook not implemented in python 2.6, it's needed for using OrderedDict instead of normal dict, but vector_what will still work, only the order in which the results are presented is not defined

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@62645 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 10 anos atrás
pai
commit
2ec8ab64fb
1 arquivos alterados com 7 adições e 3 exclusões
  1. 7 3
      lib/python/script/vector.py

+ 7 - 3
lib/python/script/vector.py

@@ -370,10 +370,14 @@ def vector_what(map, coord, distance=0.0, ttype=None, encoding=None):
         except ImportError:
             orderedDict = dict
 
+    kwargs = {}
     if encoding:
-        result = json.loads(ret, object_pairs_hook=orderedDict, encoding=encoding)
-    else:
-        result = json.loads(ret, object_pairs_hook=orderedDict)
+        kwargs['encoding'] = encoding
+
+    if sys.version_info[0:2] > (2, 6):
+        kwargs['object_pairs_hook'] = orderedDict
+
+    result = json.loads(ret, **kwargs)
 
     for vmap in result['Maps']:
         cats = vmap.pop('Categories', None)