From 358decd3b74591b2a2ccee55279f2b7c44312422 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Mon, 8 Dec 2008 20:05:39 -0500 Subject: A few more tweaks to extension loading. We don't test trying to load non-existant or broken extensions often enough. This should handle things better. --- markdown/__init__.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/markdown/__init__.py b/markdown/__init__.py index 8a473b1..44cb25e 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -283,15 +283,12 @@ class Markdown: for ext in extensions: if isinstance(ext, basestring): ext = load_extension(ext, configs.get(ext, [])) - elif hasattr(ext, 'extendMarkdown'): - # Looks like an Extension. - # Nothing to do here. - pass - else: + try: + ext.extendMarkdown(self, globals()) + except AttributeError: message(ERROR, "Incorrect type! Extension '%s' is " "neither a string or an Extension." %(repr(ext))) - continue - ext.extendMarkdown(self, globals()) + def registerExtension(self, extension): """ This gets called by the extension """ @@ -461,7 +458,7 @@ def load_extension(ext_name, configs = []): module_name_old_style = '_'.join(['mdx', ext_name]) # Try loading the extention first from one place, then another - try: # New style (markdown_extensons.) + try: # New style (markdown.extensons.) module = __import__(module_name_new_style, {}, {}, [ext_module]) except ImportError: try: # Old style (mdx.) @@ -474,7 +471,7 @@ def load_extension(ext_name, configs = []): # function called makeExtension() try: return module.makeExtension(configs.items()) - except: + except AttributeError: message(CRITICAL, "Failed to instantiate extension '%s'" % ext_name) -- cgit v1.2.3