Merge pull request #867 from The-Compiler/collections
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Import abstract base classes from collections.abc
authored by David Lord · committed by GitHub · parents 0ece610, 31bf9b7 · Browse files · 6 files·+19 added−26 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+19 added−26 removed
- other:+19 added−26 removed
Provenance
- Commit
a7ba0b6- Tree
ea29e97- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
0ece610- Parent 2
31bf9b7
6 files changed+19 added−26 removed
modified:docs/jinjaext.py+2 added-2 removed
6 unmodified lines7 8 :copyright: Copyright 2008 by Armin Ronacher.9 :license: BSD.10 """11-import collections11 import os12 import re13 import inspect14 9 unmodified lines24 from pygments.style import Style25 from pygments.token import Keyword, Name, Comment, String, Error, \26 Number, Operator, Generic27 from jinja2 import Environment, FileSystemLoader28+from jinja2._compat import abc29 30 31 def parse_rst(state, content_offset, doc):32 node = nodes.section()126 unmodified lines159 if node.abstract:160 members = []161 for key, name in node.__dict__.items():162 if not key.startswith('_') and \163- not hasattr(node.__base__, key) and isinstance(name, collections.Callable):163+ not hasattr(node.__base__, key) and isinstance(name, abc.Callable):164 members.append(key)165 if members:166 members.sort()167 doc.append('%s :members: %s' % (p, ', '.join(members)), '')39 unmodified linesmodified:jinja2/_compat.py+6 added
95 unmodified lines96 try:97 from urllib.parse import quote_from_bytes as url_quote98 except ImportError:99 from urllib import quote as url_quote100+101+102+try:103+ from collections import abc104+except ImportError:105+ import collections as abcmodified:jinja2/runtime.py+2 added-7 removed
18 unmodified lines19 from jinja2.exceptions import UndefinedError, TemplateRuntimeError, \20 TemplateNotFound21 from jinja2._compat import imap, text_type, iteritems, \22 implements_iterator, implements_to_string, string_types, PY2, \23- with_metaclass23+ with_metaclass, abc24 25 26 # these variables are exported to the template runtime27 __all__ = ['LoopContext', 'TemplateReference', 'Macro', 'Markup',284 unmodified lines312 self.name313 )314 315 316-# register the context as mapping if possible317-try:318- from collections import Mapping319- Mapping.register(Context)316+abc.Mapping.register(Context)320-except ImportError:321- pass317 318 319 class BlockReference(object):320 """One block on a template reference."""488 unmodified linesmodified:jinja2/sandbox.py+5 added-7 removed
12 unmodified lines13 :license: BSD.14 """15 import types16 import operator17-from collections import Mapping17 from jinja2.environment import Environment18 from jinja2.exceptions import SecurityError20-from jinja2._compat import string_types, PY219+from jinja2._compat import string_types, PY2, abc20 from jinja2.utils import Markup21 22 from markupsafe import EscapeFormatter23 from string import Formatter53 unmodified lines77 except ImportError:78 pass79 80 #: register Python 2.6 abstract base classes82-from collections import MutableSet, MutableMapping, MutableSequence83-_mutable_set_types += (MutableSet,)84-_mutable_mapping_types += (MutableMapping,)85-_mutable_sequence_types += (MutableSequence,)81+_mutable_set_types += (abc.MutableSet,)82+_mutable_mapping_types += (abc.MutableMapping,)83+_mutable_sequence_types += (abc.MutableSequence,)84 85 86 _mutable_spec = (87 (_mutable_set_types, frozenset([12 unmodified lines100 ]))101 )102 103 106-class _MagicFormatMapping(Mapping):104+class _MagicFormatMapping(abc.Mapping):105 """This class implements a dummy wrapper to fix a bug in the Python106 standard library for string formatting.107 108 See https://bugs.python.org/issue13598 for information about why365 unmodified linesmodified:jinja2/tests.py+2 added-3 removed
8 unmodified lines9 :license: BSD, see LICENSE for more details.10 """11 import operator12 import re13-from collections import Mapping13 from jinja2.runtime import Undefined15-from jinja2._compat import text_type, string_types, integer_types14+from jinja2._compat import text_type, string_types, integer_types, abc15 import decimal16 17 number_re = re.compile(r'^-?\d+(\.\d+)?$')18 regex_type = type(number_re)63 unmodified lines82 """Return true if the object is a mapping (dict etc.).83 84 .. versionadded:: 2.685 """87- return isinstance(value, Mapping)86+ return isinstance(value, abc.Mapping)87 88 89 def test_number(value):90 """Return true if the variable is a number."""84 unmodified linesmodified:jinja2/utils.py+2 added-7 removed
12 unmodified lines13 import errno14 from collections import deque15 from threading import Lock16 from jinja2._compat import text_type, string_types, implements_iterator, \17- url_quote17+ url_quote, abc18 19 20 _word_split_re = re.compile(r'(\s+)')21 _punctuation_re = re.compile(457 unmodified lines479 480 __copy__ = copy481 482 483-# register the LRU cache as mutable mapping if possible484-try:485- from collections import MutableMapping486- MutableMapping.register(LRUCache)483+abc.MutableMapping.register(LRUCache)487-except ImportError:488- pass484 485 486 def select_autoescape(enabled_extensions=('html', 'htm', 'xml'),487 disabled_extensions=(),155 unmodified lines