import os
import random
+import re
import types
from xml.sax import saxutils
self.cookbook = cookbook
self.cookbook.make_index()
self.env = Environment(loader=FileSystemLoader(template_root))
+ self.tag_regexp = re.compile('[a-zA-Z./ ].*') # allowed characters
def cleanup(self):
#self.cookbook.save('new-recipe')
recipe = self.cookbook.index[name]
if recipe.tags == None:
recipe.tags = []
+ tag = self._clean_tag(tag)
+ if tag == None:
+ return
if tag not in recipe.tags:
recipe.tags.append(tag)
with open(recipe.path, 'w') as f:
recipe = self.cookbook.index[name]
if recipe.tags == None:
return
+ tag = self._clean_tag(tag)
+ if tag == None:
+ return
if tag in recipe.tags:
recipe.tags.remove(tag)
with open(recipe.path, 'w') as f:
raise cherrypy.HTTPRedirect(
'recipe?name=%s' % recipe.clean_name(), status=302)
+ def _clean_tag(self, tag):
+ """Sanitize tag."""
+ tags = []
+ m = self.tag_regexp.match(t)
+ if m != None:
+ return m.group()
+ return None
+
def test():
import doctest