diff options
Diffstat (limited to 'markdown/inlinepatterns.py')
-rw-r--r-- | markdown/inlinepatterns.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index f64aa58..e8ecaea 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals """ INLINE PATTERNS ============================================================================= @@ -41,17 +42,18 @@ So, we apply the expressions in the following order: * finally we apply strong and emphasis """ -import util -import odict +from __future__ import absolute_import +from . import util +from . import odict import re -from urlparse import urlparse, urlunparse -# If you see an ImportError for htmlentitydefs after using 2to3 to convert for -# use by Python3, then you are probably using the buggy version from Python 3.0. -# We recomend using the tool from Python 3.1 even if you will be running the -# code on Python 3.0. The following line should be converted by the tool to: -# `from html import entities` and later calls to `htmlentitydefs` should be -# changed to call `entities`. Python 3.1's tool does this but 3.0's does not. -import htmlentitydefs +try: + from urllib.parse import urlparse, urlunparse +except ImportError: + from urlparse import urlparse, urlunparse +try: + from html import entities +except ImportError: + import htmlentitydefs as entities def build_inlinepatterns(md_instance, **kwargs): @@ -141,7 +143,7 @@ The pattern classes ----------------------------------------------------------------------------- """ -class Pattern: +class Pattern(object): """Base class that inline patterns subclass. """ def __init__(self, pattern, markdown_instance=None): @@ -191,7 +193,7 @@ class Pattern: def itertext(el): ' Reimplement Element.itertext for older python versions ' tag = el.tag - if not isinstance(tag, basestring) and tag is not None: + if not isinstance(tag, util.string_type) and tag is not None: return if el.text: yield el.text @@ -204,7 +206,7 @@ class Pattern: id = m.group(1) if id in stash: value = stash.get(id) - if isinstance(value, basestring): + if isinstance(value, util.string_type): return value else: # An etree Element - return text content only @@ -464,7 +466,7 @@ class AutomailPattern(Pattern): def codepoint2name(code): """Return entity definition by code, or the code if not defined.""" - entity = htmlentitydefs.codepoint2name.get(code) + entity = entities.codepoint2name.get(code) if entity: return "%s%s;" % (util.AMP_SUBSTITUTE, entity) else: |