Markup and escape should be imported from markupsafe
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 39846a8 · Browse files · 8 files·+37 added−34 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+37 added−34 removed
- tests:+5 added−5 removed
- other:+32 added−29 removed
Provenance
- Commit
aafe94d- Tree
edc0f1c- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
39846a8
8 files changed+37 added−34 removed
modified:docs/api.rst-18 removed
607 unmodified lines608 .. autofunction:: jinja2.evalcontextfunction609 610 .. autofunction:: jinja2.environmentfunction611 612-.. function:: escape(s)613-614- Convert the characters ``&``, ``<``, ``>``, ``'``, and ``"`` in string `s`615- to HTML-safe sequences. Use this if you need to display text that might616- contain such characters in HTML. This function will not escaped objects617- that do have an HTML representation such as already escaped data.618-619- The return value is a :class:`Markup` string.620-612 .. autofunction:: jinja2.clear_caches613 614 .. autofunction:: jinja2.is_undefined615 625-.. autoclass:: jinja2.Markup([string])626- :members: escape, unescape, striptags616 628-.. admonition:: Note629-630- The Jinja :class:`Markup` class is compatible with at least Pylons and631- Genshi. It's expected that more template engines and framework will pick632- up the `__html__` concept soon.633-634-617 Exceptions618 ----------619 620 .. autoexception:: jinja2.TemplateError311 unmodified linesmodified:src/jinja2/__init__.py+2 added-3 removed
1 """Jinja is a template engine written in pure Python. It provides a2 non-XML syntax that supports inline expressions and an optional3 sandboxed environment.4 """5-from markupsafe import escape6-from markupsafe import Markup7-5 from .bccache import BytecodeCache6 from .bccache import FileSystemBytecodeCache7 from .bccache import MemcachedBytecodeCache8 from .environment import Environment23 unmodified lines32 from .runtime import Undefined33 from .utils import clear_caches34 from .utils import contextfunction35 from .utils import environmentfunction36+from .utils import escape37 from .utils import evalcontextfunction38 from .utils import is_undefined39+from .utils import Markup40 from .utils import pass_context41 from .utils import pass_environment42 from .utils import pass_eval_context43 from .utils import select_autoescape2 unmodified linesmodified:src/jinja2/utils.py+30 added-8 removed
10 unmodified lines11 from threading import Lock12 from types import CodeType13 from urllib.parse import quote_from_bytes14 15-from markupsafe import escape16-from markupsafe import Markup15+import markupsafe16 17 if t.TYPE_CHECKING:18 F = t.TypeVar("F", bound=t.Callable[..., t.Any])19 310 unmodified lines330 331 def trim_url(x):332 return x333 335- words = re.split(r"(\s+)", str(escape(text)))336- rel_attr = f' rel="{escape(rel)}"' if rel else ""337- target_attr = f' target="{escape(target)}"' if target else ""334+ words = re.split(r"(\s+)", str(markupsafe.escape(text)))335+ rel_attr = f' rel="{markupsafe.escape(rel)}"' if rel else ""336+ target_attr = f' target="{markupsafe.escape(target)}"' if target else ""337 338 for i, word in enumerate(words):339 head, middle, tail = "", word, ""340 match = re.match(r"^([(<]|<)+", middle)105 unmodified lines446 result.append(p)447 448 if not html:449 return "\n\n".join(result)451- return Markup("\n".join(f"<p>{escape(x)}</p>" for x in result))450+ return markupsafe.Markup(451+ "\n".join(f"<p>{markupsafe.escape(x)}</p>" for x in result)452+ )453 454 455 def url_quote(obj: t.Any, charset: str = "utf-8", for_qs: bool = False) -> str:456 """Quote a string for use in a URL using the given charset.244 unmodified lines701 702 703 def htmlsafe_json_dumps(704 obj: t.Any, dumps: t.Optional[t.Callable[..., str]] = None, **kwargs: t.Any704-) -> Markup:705+) -> markupsafe.Markup:706 """Serialize an object to a string of JSON with :func:`json.dumps`,707 then replace HTML-unsafe characters with Unicode escapes and mark708 the result safe with :class:`~markupsafe.Markup`.709 20 unmodified lines730 """731 if dumps is None:732 dumps = json.dumps733 733- return Markup(734+ return markupsafe.Markup(735 dumps(obj, **kwargs)736 .replace("<", "\\u003c")737 .replace(">", "\\u003e")738 .replace("&", "\\u0026")98 unmodified lines837 exec("async def _():\n async for _ in ():\n yield _")838 have_async_gen = True839 except SyntaxError:840 have_async_gen = False841+842+843+class Markup(markupsafe.Markup):844+ def __init__(self, *args, **kwargs):845+ warnings.warn(846+ "'jinja2.Markup' is deprecated and will be removed in Jinja"847+ " 3.1. Import 'markupsafe.Markup' instead.",848+ DeprecationWarning,849+ stacklevel=2,850+ )851+ super().__init__(*args, **kwargs)852+853+854+def escape(s):855+ warnings.warn(856+ "'jinja2.escape' is deprecated and will be removed in Jinja"857+ " 3.1. Import 'markupsafe.escape' instead.",858+ DeprecationWarning,859+ stacklevel=2,860+ )861+ return markupsafe.escape(s)modified:tests/test_asyncfilters.py+1 added-1 removed
1 from collections import namedtuple2 3 import pytest4+from markupsafe import Markup5 6 from jinja2 import Environment7 from jinja2.asyncsupport import auto_aiter7-from jinja2.utils import Markup8 9 10 async def make_aiter(iter):11 for item in iter:242 unmodified linesmodified:tests/test_filters.py+1 added-1 removed
1 import random2 from collections import namedtuple3 4 import pytest5+from markupsafe import Markup6 7 from jinja2 import Environment7-from jinja2 import Markup8 from jinja2 import StrictUndefined9 from jinja2 import TemplateRuntimeError10 from jinja2 import UndefinedError11 from jinja2.exceptions import TemplateAssertionError832 unmodified linesmodified:tests/test_regression.py+1 added-1 removed
611 unmodified lines612 )613 assert tmpl.render(values=[]) == "0"614 615 def test_markup_and_chainable_undefined(self):616- from jinja2 import Markup616+ from markupsafe import Markup617 from jinja2.runtime import ChainableUndefined618 619 assert str(Markup(ChainableUndefined())) == ""620 132 unmodified linesmodified:tests/test_security.py+1 added-1 removed
1 import pytest2+from markupsafe import escape3 4 from jinja2 import Environment4-from jinja2 import escape5 from jinja2.exceptions import SecurityError6 from jinja2.exceptions import TemplateRuntimeError7 from jinja2.exceptions import TemplateSyntaxError8 from jinja2.nodes import EvalContext165 unmodified linesmodified:tests/test_tests.py+1 added-1 removed
1 import pytest2+from markupsafe import Markup3 4 from jinja2 import Environment4-from jinja2 import Markup5 from jinja2 import TemplateAssertionError6 from jinja2 import TemplateRuntimeError7 8 225 unmodified lines