diff --git a/filters/addsearch.genshi b/filters/addsearch.genshi
new file mode 100644
index 0000000..f6f36ce
--- /dev/null
+++ b/filters/addsearch.genshi
@@ -0,0 +1,30 @@
+
+
+
+
+ ${select('*')}
+
Search
+
+
+
+
+
+
+
+ ${select('*')}
+
+
+
+
+
+
+
+ ${input}
+
+
diff --git a/filters/addsearch.xslt b/filters/addsearch.xslt
new file mode 100644
index 0000000..0d77ca6
--- /dev/null
+++ b/filters/addsearch.xslt
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+ Search
+
+
+
+
+
+
+
+
+
+ /
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ opensearchdescription.xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/planet/shell/__init__.py b/planet/shell/__init__.py
index 7052454..8d28045 100644
--- a/planet/shell/__init__.py
+++ b/planet/shell/__init__.py
@@ -30,7 +30,7 @@ def run(template_file, doc, mode='template'):
if not mode in logged_modes:
log.info("%s search path:", mode)
for template_dir in dirs:
- log.error(" %s", os.path.realpath(template_dir))
+ log.info(" %s", os.path.realpath(template_dir))
logged_modes.append(mode)
return
template_resolved = os.path.realpath(template_resolved)
@@ -44,7 +44,10 @@ def run(template_file, doc, mode='template'):
base,ext = os.path.splitext(os.path.basename(template_resolved))
module_name = ext[1:]
try:
- module = __import__(module_name)
+ try:
+ module = __import__("_" + module_name)
+ except:
+ module = __import__(module_name)
except Exception, inst:
return log.error("Skipping %s '%s' after failing to load '%s': %s",
mode, template_resolved, module_name, inst)
diff --git a/planet/shell/_genshi.py b/planet/shell/_genshi.py
new file mode 100644
index 0000000..c08cd81
--- /dev/null
+++ b/planet/shell/_genshi.py
@@ -0,0 +1,23 @@
+from StringIO import StringIO
+
+from genshi.input import XMLParser
+from genshi.template import Context, MarkupTemplate
+
+def run(script, doc, output_file=None, options={}):
+ """ process an Genshi template """
+
+ context = Context(**options)
+
+ tmpl_fileobj = open(script)
+ tmpl = MarkupTemplate(tmpl_fileobj, script)
+ tmpl_fileobj.close()
+
+ context.push({'input':XMLParser(StringIO(doc))})
+ output=tmpl.generate(context).render('xml')
+
+ if output_file:
+ out_file = open(output_file,'w')
+ out_file.write(output)
+ out_file.close()
+ else:
+ return output
diff --git a/tests/data/filter/index.html b/tests/data/filter/index.html
new file mode 100644
index 0000000..4e621fc
--- /dev/null
+++ b/tests/data/filter/index.html
@@ -0,0 +1,18 @@
+
+
+
+
+Planet Intertwingly
+
+
+Planet Intertwingly
+
+
+
+
April 14, 2007
+
+Footnotes
+
+
+
+
diff --git a/tests/test_filter_genshi.py b/tests/test_filter_genshi.py
new file mode 100644
index 0000000..a2f7bb4
--- /dev/null
+++ b/tests/test_filter_genshi.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+import unittest, xml.dom.minidom
+from planet import shell, config, logger
+
+class GenshiFilterTests(unittest.TestCase):
+
+ def test_addsearch_filter(self):
+ testfile = 'tests/data/filter/index.html'
+ filter = 'addsearch.genshi'
+ output = shell.run(filter, open(testfile).read(), mode="filter")
+ self.assertTrue(output.find('Search
')>=0)
+ self.assertTrue(output.find('')>=0)
+ self.assertTrue(output.find(' href="http://planet.intertwingly.net/opensearchdescription.xml"')>=0)
+ self.assertTrue(output.find('')>=0)
+
+try:
+ import genshi
+except:
+ logger.warn("genshi is not available => can't test genshi filters")
+ for method in dir(GenshiFilterTests):
+ if method.startswith('test_'): delattr(GenshiFilterTests,method)
diff --git a/tests/test_filter_xslt.py b/tests/test_filter_xslt.py
index 061f805..05890c2 100644
--- a/tests/test_filter_xslt.py
+++ b/tests/test_filter_xslt.py
@@ -15,6 +15,15 @@ class XsltFilterTests(unittest.TestCase):
catterm = dom.getElementsByTagName('category')[0].getAttribute('term')
self.assertEqual('OnE', catterm)
+ def test_addsearch_filter(self):
+ testfile = 'tests/data/filter/index.html'
+ filter = 'addsearch.xslt'
+ output = shell.run(filter, open(testfile).read(), mode="filter")
+ self.assertTrue(output.find('Search
')>=0)
+ self.assertTrue(output.find('')>=0)
+ self.assertTrue(output.find(' href="http://planet.intertwingly.net/opensearchdescription.xml"')>=0)
+ self.assertTrue(output.find('')>=0)
+
try:
import libxslt
except:
@@ -26,3 +35,4 @@ except:
except:
logger.warn("libxslt is not available => can't test xslt filters")
del XsltFilterTests.test_xslt_filter
+ del XsltFilterTests.test_addsearch_filter