diff options
author | R. Tyler Ballance <tyler@slide.com> | 2009-04-13 07:40:01 -0400 |
---|---|---|
committer | R. Tyler Ballance <tyler@slide.com> | 2009-04-13 07:40:01 -0400 |
commit | b20949d36ee6c469f39bedb0d59b8238890f50f6 (patch) | |
tree | a39a26fc0451541620035f5329ca792030783c3a | |
parent | 9e1dedca81904adfc0e65140617479160cb3047d (diff) | |
download | python-cheetah-b20949d36ee6c469f39bedb0d59b8238890f50f6.tar.gz |
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>
-rw-r--r-- | src/Filters.py | 19 | ||||
-rw-r--r-- | src/Tests/Filters.py | 15 |
2 files changed, 24 insertions, 10 deletions
diff --git a/src/Filters.py b/src/Filters.py index 1303c6d..5664b6f 100644 --- a/src/Filters.py +++ b/src/Filters.py @@ -9,13 +9,6 @@ import sys 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 = {' ': ' ', '"': '"'} @@ -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) diff --git a/src/Tests/Filters.py b/src/Tests/Filters.py index ab065b2..04afdd5 100644 --- a/src/Tests/Filters.py +++ b/src/Tests/Filters.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +import sys + import Cheetah.Template import Cheetah.Filters @@ -20,9 +22,16 @@ Header ''' 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): ''' |