diff options
author | Waylan Limberg <waylan.limberg@icloud.com> | 2018-07-27 10:55:41 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-27 10:55:41 -0400 |
commit | 25482261a494ad12c108435580ed13927bdc417c (patch) | |
tree | 5b108a5923322d5ceb3fa47d5f05d27a1039de7c /markdown/util.py | |
parent | 55d69f408cfabed6bd5953a4e7bfc926df2ac25b (diff) | |
download | markdown-25482261a494ad12c108435580ed13927bdc417c.tar.gz markdown-25482261a494ad12c108435580ed13927bdc417c.tar.bz2 markdown-25482261a494ad12c108435580ed13927bdc417c.zip |
All Markdown instances are now 'md'. (#691)
Previously, instances of the Markdown class were represented as any one
of 'md', 'md_instance', or 'markdown'. This inconsistency made it
difficult when developing extensions, or just maintaining the existing
code. Now, all instances are consistently represented as 'md'.
The old attributes on class instances still exist, but raise a
DeprecationWarning when accessed. Also on classes where the instance was
optional, the attribute always exists now and is simply None if no
instance was provided (previously the attribute wouldn't exist).
Diffstat (limited to 'markdown/util.py')
-rw-r--r-- | markdown/util.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/markdown/util.py b/markdown/util.py index d7701a2..1802bcc 100644 --- a/markdown/util.py +++ b/markdown/util.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import re import sys from collections import namedtuple +from functools import wraps import warnings @@ -118,6 +119,25 @@ def parseBoolValue(value, fail_on_errors=True, preserve_none=False): raise ValueError('Cannot parse bool value: %r' % value) +def deprecated(message): + """ + Raise a DeprecationWarning when wrapped function/method is called. + + Borrowed from https://stackoverflow.com/a/48632082/866026 + """ + def deprecated_decorator(func): + @wraps(func) + def deprecated_func(*args, **kwargs): + warnings.warn( + "'{}' is deprecated. {}".format(func.__name__, message), + category=DeprecationWarning, + stacklevel=2 + ) + return func(*args, **kwargs) + return deprecated_func + return deprecated_decorator + + """ MISC AUXILIARY CLASSES ============================================================================= @@ -130,9 +150,14 @@ class AtomicString(text_type): class Processor(object): - def __init__(self, markdown_instance=None): - if markdown_instance: - self.markdown = markdown_instance + def __init__(self, md=None): + self.md = md + + @property + @deprecated("Use 'md' instead.") + def markdown(self): + # TODO: remove this later + return self.md class HtmlStash(object): |