112112from collections import defaultdict
113113
114114from lib .errors import MarkdownError
115- from lib .utils import slugify , calculate_toc_html , curry , regex_from_encoded_pattern , dedentlines , dedent
115+ from lib .utils import (
116+ slugify ,
117+ calculate_toc_html ,
118+ curry ,
119+ regex_from_encoded_pattern ,
120+ dedentlines ,
121+ dedent ,
122+ memoized ,
123+ )
116124
117125# ---- globals
118126
@@ -2471,33 +2479,6 @@ class UnicodeWithAttrs(str):
24712479 toc_html = None
24722480
24732481
2474- class _memoized (object ):
2475- """Decorator that caches a function's return value each time it is called.
2476- If called later with the same arguments, the cached value is returned, and
2477- not re-evaluated.
2478-
2479- http://wiki.python.org/moin/PythonDecoratorLibrary
2480- """
2481- def __init__ (self , func ):
2482- self .func = func
2483- self .cache = {}
2484-
2485- def __call__ (self , * args ):
2486- try :
2487- return self .cache [args ]
2488- except KeyError :
2489- self .cache [args ] = value = self .func (* args )
2490- return value
2491- except TypeError :
2492- # uncachable -- for instance, passing a list as an argument.
2493- # Better to not cache than to blow up entirely.
2494- return self .func (* args )
2495-
2496- def __repr__ (self ):
2497- """Return the function's docstring."""
2498- return self .func .__doc__
2499-
2500-
25012482def _xml_oneliner_re_from_tab_width (tab_width ):
25022483 """Standalone XML processing instruction regex."""
25032484 return re .compile (r"""
@@ -2517,7 +2498,7 @@ def _xml_oneliner_re_from_tab_width(tab_width):
25172498 (?=\n{2,}|\Z) # followed by a blank line or end of document
25182499 )
25192500 """ % (tab_width - 1 ), re .X )
2520- _xml_oneliner_re_from_tab_width = _memoized (_xml_oneliner_re_from_tab_width )
2501+ _xml_oneliner_re_from_tab_width = memoized (_xml_oneliner_re_from_tab_width )
25212502
25222503
25232504def _hr_tag_re_from_tab_width (tab_width ):
@@ -2537,7 +2518,7 @@ def _hr_tag_re_from_tab_width(tab_width):
25372518 (?=\n{2,}|\Z) # followed by a blank line or end of document
25382519 )
25392520 """ % (tab_width - 1 ), re .X )
2540- _hr_tag_re_from_tab_width = _memoized (_hr_tag_re_from_tab_width )
2521+ _hr_tag_re_from_tab_width = memoized (_hr_tag_re_from_tab_width )
25412522
25422523
25432524def _xml_escape_attr (attr , skip_single_quote = True ):
0 commit comments