[CMF-checkins] CVS: CMF - utils.py:1.6
Jeffrey Shell
jeffrey@digicool.com
Tue, 5 Jun 2001 19:01:12 -0400 (EDT)
Update of /cvs-repository/CMF/CMFDefault
In directory korak.digicool.com:/home/jeffrey/InstanceHomes/about-stuff/CMF/CMFDefault
Modified Files:
utils.py
Log Message:
Modified tuplize() function to include the ability to pass in a
splitter function for string values, defaulting to 'string.split'.
Added two additional helpful functions, 'semi_split' and 'comma_split'
to use with it.
This allows extra funky but sometimes needed uses, like passing in a
regex splitter, (ie 're.compile(r"[.;:]\s").split').
--- Updated File utils.py in package CMF --
--- utils.py 2001/05/29 14:47:50 1.5
+++ utils.py 2001/06/05 23:01:12 1.6
@@ -76,11 +76,16 @@
return headers, join( lines[ i+1: ], '\n' )
-
-def tuplize( valueName, value ):
+def semi_split(s):
+ return map(strip, split(s, ';'))
+
+def comma_split(s):
+ return map(strip, split(s, ','))
+
+def tuplize( valueName, value, splitter=split ):
if type(value) == type(()): return value
if type(value) == type([]): return tuple( value )
- if type(value) == type(''): return tuple( split( value ) )
+ if type(value) == type(''): return tuple( splitter( value ) )
raise ValueError, "%s of unsupported type" % valueName