فهرست منبع

pythonlib: define 'delimiter' for parse_command()
don't use has_key()


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@46915 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 14 سال پیش
والد
کامیت
57754c3020
3فایلهای تغییر یافته به همراه21 افزوده شده و 11 حذف شده
  1. 16 6
      lib/python/core.py
  2. 1 1
      lib/python/setup.py.sed
  3. 4 4
      lib/python/vector.py

+ 16 - 6
lib/python/core.py

@@ -236,31 +236,41 @@ def read_command(*args, **kwargs):
     return ps.communicate()[0]
 
 def parse_command(*args, **kwargs):
-    """!Passes all arguments to read_command, then parses the output by
-    parse_key_val().
+    """!Passes all arguments to read_command, then parses the output
+    by parse_key_val().
 
-    Parsing function can be optionally given by <b>parse</b> parameter
+    Parsing function can be optionally given by <em>parse</em> parameter
     including its arguments, e.g.
 
     @code
     parse_command(..., parse = (grass.parse_key_val, { 'sep' : ':' }))
     @endcode
 
+    or you can simply define <em>delimiter</em>
+
+    @code
+    parse_command(..., delimiter = ':')
+    @endcode
+
     @param args list of unnamed arguments (see start_command() for details)
     @param kwargs list of named arguments (see start_command() for details)
     
     @return parsed module output
     """
     parse = None
-    if kwargs.has_key('parse'):
+    parse_args = {}
+    if 'parse' in kwargs:
         if type(kwargs['parse']) is types.TupleType:
             parse = kwargs['parse'][0]
             parse_args = kwargs['parse'][1]
         del kwargs['parse']
     
+    if 'delimiter' in kwargs:
+        parse_args = { 'sep' : kwargs['delimiter'] }
+        del kwargs['delimiter']
+    
     if not parse:
         parse = parse_key_val # use default fn
-        parse_args = {}
         
     res = read_command(*args, **kwargs)
 
@@ -712,7 +722,7 @@ def mlist_grouped(type, pattern = None):
             warning(_("Invalid element '%s'") % line)
             continue
         
-        if result.has_key(mapset_element):
+        if mapset_element in result:
             result[mapset_element].append(map)
         else:
 	    result[mapset_element] = [map, ]

+ 1 - 1
lib/python/setup.py.sed

@@ -38,7 +38,7 @@ def init(gisbase, dbase = '', location = 'demolocation', mapset = 'PERMANENT'):
     """
     os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'bin') + \
         os.pathsep + os.path.join(gisbase, 'scripts')
-    if not os.environ.has_key('@LD_LIBRARY_PATH_VAR@'):
+    if '@LD_LIBRARY_PATH_VAR@' not in os.environ:
         os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
     os.environ['@LD_LIBRARY_PATH_VAR@'] += os.path.join(gisbase, 'lib')
     

+ 4 - 4
lib/python/vector.py

@@ -162,7 +162,7 @@ def vector_info_topo(map):
     """
     s = read_command('v.info', flags = 't', map = map)
     ret = parse_key_val(s, val_type = int)
-    if ret.has_key('map3d'):
+    if 'map3d' in ret:
         ret['map3d'] = bool(ret['map3d'])
     
     return ret
@@ -193,7 +193,7 @@ def vector_db_select(map, layer = 1, **kwargs):
                   { 'layer' : layer, 'map' : map })
         return { 'columns' : [], 'values' : {} }
         
-    if kwargs.has_key('columns'):
+    if 'columns' in kwargs:
         if key not in kwargs['columns'].split(','):
             # add key column if missing
             debug("Adding key column to the output")
@@ -264,7 +264,7 @@ def vector_what(map, coord, distance = 0.0):
 
     @return parsed list
     """
-    if os.environ.has_key("LC_ALL"):
+    if "LC_ALL" in os.environ:
         locale = os.environ["LC_ALL"]
         os.environ["LC_ALL"] = "C"
 
@@ -290,7 +290,7 @@ def vector_what(map, coord, distance = 0.0):
                        east_north = ','.join(coord_list),
                        distance   = float(distance))
     
-    if os.environ.has_key("LC_ALL"):
+    if "LC_ALL" in os.environ:
         os.environ["LC_ALL"] = locale
         
     data = list()