Permalink
Browse files

Correct failure to import Cheetah.Filters on Python 2.4.xx and 2.3.xx…

… due to the markdown module requiring ElementTree

For the tests, the Markdown test will not fail, but print an informative message. Use of the Cheetah.Filter.Markdown class
in "real life" however will raise a big ugly exception and print out a download link for 2.4 and 2.3 users

ElementTree was included in the base installation as of 2.5

Signed-off-by: R. Tyler Ballance <tyler@slide.com>
  • Loading branch information...
1 parent 9e1dedc commit b20949d36ee6c469f39bedb0d59b8238890f50f6 R. Tyler Ballance committed Apr 13, 2009
Showing with 24 additions and 10 deletions.
  1. +12 −7 src/Filters.py
  2. +12 −3 src/Tests/Filters.py
View
19 src/Filters.py
@@ -9,13 +9,6 @@
import Cheetah.contrib
import Cheetah.Template
-# This is a bit of a hack to allow outright embedding of the markdown module
-markdown_path = '/'.join(Cheetah.contrib.__file__.split('/')[:-1])
-sys.path.append(markdown_path)
-from Cheetah.contrib import markdown
-sys.path.pop()
-
-
# Additional entities WebSafe knows how to transform. No need to include
# '<', '>' or '&' since those will have been done already.
webSafeEntities = {' ': '&nbsp;', '"': '&quot;'}
@@ -96,6 +89,18 @@ class Markdown(EncodeUnicode):
best
'''
def filter(self, value, **kwargs):
+ # This is a bit of a hack to allow outright embedding of the markdown module
+ try:
+ markdown_path = '/'.join(Cheetah.contrib.__file__.split('/')[:-1])
+ sys.path.append(markdown_path)
+ from Cheetah.contrib import markdown
+ sys.path.pop()
+ except:
+ print '>>> Exception raised importing the "markdown" module'
+ print '>>> Are you sure you have the ElementTree module installed?'
+ print ' http://effbot.org/downloads/#elementtree'
+ raise
+
encoded = super(Markdown, self).filter(value, **kwargs)
return markdown.markdown(encoded)
View
15 src/Tests/Filters.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python
+import sys
+
import Cheetah.Template
import Cheetah.Filters
@@ -20,9 +22,16 @@ def test_BasicHeader(self):
'''
expected = '''<p>bar</p>
<h1>Header</h1>'''
- template = Cheetah.Template.Template(template, searchList=[{'foo' : 'bar'}])
- template = str(template)
- assert template == expected
+ try:
+ template = Cheetah.Template.Template(template, searchList=[{'foo' : 'bar'}])
+ template = str(template)
+ assert template == expected
+ except Exception, ex:
+ if ex.__class__.__name__ == 'MarkdownException' and sys.version_info[0] == 2 and sys.version_info[1] < 5:
+ print '>>> NOTE: Support for the Markdown filter will be broken for you. Markdown says: %s' % ex
+ return
+ raise
+
class BasicCodeHighlighterFilterTest(unittest.TestCase):
'''

0 comments on commit b20949d

Please sign in to comment.