aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/__init__.py20
-rw-r--r--markdown/blockprocessors.py3
-rw-r--r--markdown/etree_loader.py4
-rw-r--r--markdown/exceptions36
-rw-r--r--markdown/extensions/headerid.py3
-rw-r--r--markdown/md_logging.py36
-rw-r--r--markdown/util.py2
7 files changed, 90 insertions, 14 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py
index d7ec4f2..8658e60 100644
--- a/markdown/__init__.py
+++ b/markdown/__init__.py
@@ -64,8 +64,11 @@ Markdown processing takes place in four steps:
Those steps are put together by the Markdown() class.
"""
+
+
+from logging import DEBUG, INFO, WARN, ERROR, CRITICAL
+from md_logging import message
import util
-import misc_logging
import preprocessors
import blockprocessors
import treeprocessors
@@ -78,7 +81,6 @@ import odict
# The things defined in these modules started off in __init__.py so third
# party code might need to access them here.
from util import *
-from misc_logging import *
# Adds the ability to output html4
import html4
@@ -239,9 +241,9 @@ class Markdown:
try:
ext.extendMarkdown(self, globals())
except NotImplementedError, e:
- misc_logging.message(misc_logging.ERROR, e)
+ message(ERROR, e)
else:
- misc_logging.message(misc_logging.ERROR,
+ message(ERROR,
'Extension "%s.%s" must be of type: "markdown.Extension".' \
% (ext.__class__.__module__, ext.__class__.__name__))
@@ -265,7 +267,7 @@ class Markdown:
try:
self.serializer = self.output_formats[format.lower()]
except KeyError:
- misc_logging.message(misc_logging.CRITICAL,
+ message(CRITICAL,
'Invalid Output Format: "%s". Use one of %s.' \
% (format, self.output_formats.keys()))
@@ -285,7 +287,7 @@ class Markdown:
try:
source = unicode(source)
except UnicodeDecodeError:
- misc_logging.message(misc_logging.CRITICAL,
+ message(CRITICAL,
'UnicodeDecodeError: Markdown only accepts unicode or ascii input.')
return u""
@@ -321,7 +323,7 @@ class Markdown:
output = ''
else:
# We have a serious problem
- misc_logging.message(misc_logging.CRITICAL, 'Failed to strip top level tags.')
+ message(CRITICAL, 'Failed to strip top level tags.')
# Run the text post-processors
for pp in self.postprocessors.values():
@@ -449,7 +451,7 @@ def load_extension(ext_name, configs = []):
try: # Old style (mdx.<extension>)
module = __import__(module_name_old_style)
except ImportError:
- misc_logging.message(misc_logging.WARN, "Failed loading extension '%s' from '%s' or '%s'"
+ message(WARN, "Failed loading extension '%s' from '%s' or '%s'"
% (ext_name, module_name_new_style, module_name_old_style))
# Return None so we don't try to initiate none-existant extension
return None
@@ -459,7 +461,7 @@ def load_extension(ext_name, configs = []):
try:
return module.makeExtension(configs.items())
except AttributeError, e:
- misc_logging.message(misc_logging.CRITICAL, "Failed to initiate extension '%s': %s" % (ext_name, e))
+ message(CRITICAL, "Failed to initiate extension '%s': %s" % (ext_name, e))
def load_extensions(ext_names):
diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py
index 6e1f146..a64be2a 100644
--- a/markdown/blockprocessors.py
+++ b/markdown/blockprocessors.py
@@ -14,7 +14,8 @@ as they need to alter how markdown blocks are parsed.
import re
import util
-from misc_logging import CRITICAL, message
+from logging import CRITICAL
+from md_logging import message
class BlockProcessor:
""" Base class for block processors.
diff --git a/markdown/etree_loader.py b/markdown/etree_loader.py
index 8abb1aa..0ea38f6 100644
--- a/markdown/etree_loader.py
+++ b/markdown/etree_loader.py
@@ -1,5 +1,5 @@
-
-from misc_logging import message, CRITICAL
+from logging import CRITICAL
+from md_logging import message
import sys
## Import
diff --git a/markdown/exceptions b/markdown/exceptions
new file mode 100644
index 0000000..463be15
--- /dev/null
+++ b/markdown/exceptions
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+import logging
+from logging import DEBUG, INFO, WARN, ERROR, CRITICAL
+import sys
+import warnings
+
+#
+# Exceptions
+#
+
+class MarkdownException(Exception):
+ """ A Markdown Exception. """
+ pass
+
+
+class MarkdownWarning(Warning):
+ """ A Markdown Warning. """
+ pass
+
+
+#
+# Global functions
+#
+
+def message(level, text):
+ """ A wrapper method for logging debug messages. """
+ logger = logging.getLogger('MARKDOWN')
+ if logger.handlers:
+ # The logger is configured
+ logger.log(level, text)
+ if level > WARN:
+ sys.exit(0)
+ elif level > WARN:
+ raise MarkdownException, text
+ else:
+ warnings.warn(text, MarkdownWarning) \ No newline at end of file
diff --git a/markdown/extensions/headerid.py b/markdown/extensions/headerid.py
index 762301c..4f43aa5 100644
--- a/markdown/extensions/headerid.py
+++ b/markdown/extensions/headerid.py
@@ -67,7 +67,8 @@ Dependencies:
import markdown
from markdown.util import etree
-from markdown.misc_logging import CRITICAL, message
+from logging import CRITICAL
+from markdown.md_logging import message
import re
from string import ascii_lowercase, digits, punctuation
diff --git a/markdown/md_logging.py b/markdown/md_logging.py
new file mode 100644
index 0000000..463be15
--- /dev/null
+++ b/markdown/md_logging.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+import logging
+from logging import DEBUG, INFO, WARN, ERROR, CRITICAL
+import sys
+import warnings
+
+#
+# Exceptions
+#
+
+class MarkdownException(Exception):
+ """ A Markdown Exception. """
+ pass
+
+
+class MarkdownWarning(Warning):
+ """ A Markdown Warning. """
+ pass
+
+
+#
+# Global functions
+#
+
+def message(level, text):
+ """ A wrapper method for logging debug messages. """
+ logger = logging.getLogger('MARKDOWN')
+ if logger.handlers:
+ # The logger is configured
+ logger.log(level, text)
+ if level > WARN:
+ sys.exit(0)
+ elif level > WARN:
+ raise MarkdownException, text
+ else:
+ warnings.warn(text, MarkdownWarning) \ No newline at end of file
diff --git a/markdown/util.py b/markdown/util.py
index 9cdd234..4890b89 100644
--- a/markdown/util.py
+++ b/markdown/util.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import re
-from misc_logging import CRITICAL
+from logging import CRITICAL
import etree_loader