[GRASS-SVN] r55229 - grass/trunk/lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Feb 26 02:50:53 PST 2013


Author: glynn
Date: 2013-02-26 02:50:53 -0800 (Tue, 26 Feb 2013)
New Revision: 55229

Modified:
   grass/trunk/lib/python/script/core.py
Log:
Added legal_name() function


Modified: grass/trunk/lib/python/script/core.py
===================================================================
--- grass/trunk/lib/python/script/core.py	2013-02-26 09:01:03 UTC (rev 55228)
+++ grass/trunk/lib/python/script/core.py	2013-02-26 10:50:53 UTC (rev 55229)
@@ -1398,3 +1398,18 @@
     _debug_level = 0
     if find_program('g.gisenv', ['--help']):
         _debug_level = int(gisenv().get('DEBUG', 0))
+
+def legal_name(s):
+    if not s or s[0] == '.':
+	warning(_("Illegal filename <%s>. Cannot be 'NULL' or start with '.'.") % s)
+	return False
+
+    illegal = [c
+               for c in s
+               if c in '/"\'@,=*~' or c <= ' ' or c >= '\177']
+    if illegal:
+        illegal = ''.join(sorted(set(illegal)))
+        warning(_("Illegal filename <%s>. <%s> not allowed.\n") % (s, repr(illegal)[1:-1]))
+        return False
+
+    return True



More information about the grass-commit mailing list