[CMF-checkins] CVS: CMF - utils.py:1.12
Jeffrey Shell
jeffrey@digicool.com
Thu, 31 May 2001 20:20:24 -0400 (EDT)
Update of /cvs-repository/CMF/CMFCore
In directory korak.digicool.com:/home/jeffrey/InstanceHomes/cmf-dev/CMF/CMFCore
Modified Files:
utils.py
Log Message:
Added keyword splitter utility for parsing headers (subject AND
keywords as meta tags)
--- Updated File utils.py in package CMF --
--- utils.py 2001/05/31 17:58:00 1.11
+++ utils.py 2001/06/01 00:20:24 1.12
@@ -540,6 +540,21 @@
html = CMFHtmlWithImages( doc, level )
return html
+### Metadata Keyword splitter utilities
+import re, string, operator
+KEYSPLITRE = re.compile(r'[,;]')
+def keywordsplitter(headers,
+ names=('Subject', 'Keywords',),
+ splitter=KEYSPLITRE.split):
+ """ Splits keywords out of headers, keyed on names. Returns list. """
+ out = []
+ for head in names:
+ keylist = splitter(headers.get(head, ''))
+ keylist = map(string.strip, keylist)
+ out.extend(filter(operator.truth, keylist))
+ return out
+
+
if 0:
# Hopefully we can use this.