From 337a79f8caeff25422b28771e851c140d5d744ac Mon Sep 17 00:00:00 2001 From: David Lord Date: Wed, 29 Jan 2020 20:13:47 -0800 Subject: apply pyupgrade --- src/markupsafe/__init__.py | 33 +++++++++++++++------------------ src/markupsafe/_constants.py | 1 - src/markupsafe/_native.py | 3 +-- 3 files changed, 16 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/markupsafe/__init__.py b/src/markupsafe/__init__.py index fac362a..71a881e 100644 --- a/src/markupsafe/__init__.py +++ b/src/markupsafe/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Implements an escape function and a Markup string to replace HTML special characters with safe representations. @@ -24,11 +23,11 @@ class Markup(str): it to mark it safe without escaping. To escape the text, use the :meth:`escape` class method instead. - >>> Markup('Hello, World!') + >>> Markup("Hello, World!") Markup('Hello, World!') >>> Markup(42) Markup('42') - >>> Markup.escape('Hello, World!') + >>> Markup.escape("Hello, World!") Markup('Hello <em>World</em>!') This implements the ``__html__()`` interface that some frameworks @@ -45,15 +44,15 @@ class Markup(str): This is a subclass of :class:`str`. It has the same methods, but escapes their arguments and returns a ``Markup`` instance. - >>> Markup('%s') % 'foo & bar' + >>> Markup("%s") % ("foo & bar",) Markup('foo & bar') - >>> Markup('Hello ') + '' + >>> Markup("Hello ") + "" Markup('Hello <foo>') """ __slots__ = () - def __new__(cls, base=u"", encoding=None, errors="strict"): + def __new__(cls, base="", encoding=None, errors="strict"): if hasattr(base, "__html__"): base = base.__html__() if encoding is None: @@ -88,7 +87,7 @@ class Markup(str): return self.__class__(super().__mod__(arg)) def __repr__(self): - return "%s(%s)" % (self.__class__.__name__, super().__repr__()) + return f"{self.__class__.__name__}({super().__repr__()})" def join(self, seq): return self.__class__(super().join(map(self.escape, seq))) @@ -114,7 +113,7 @@ class Markup(str): """Convert escaped markup back into a text string. This replaces HTML entities with the characters they represent. - >>> Markup('Main » About').unescape() + >>> Markup("Main » About").unescape() 'Main » About' """ from ._constants import HTML_ENTITIES @@ -139,10 +138,10 @@ class Markup(str): """:meth:`unescape` the markup, remove tags, and normalize whitespace to single spaces. - >>> Markup('Main »\tAbout').striptags() + >>> Markup("Main »\tAbout").striptags() 'Main » About' """ - stripped = u" ".join(_striptags_re.sub("", self).split()) + stripped = " ".join(_striptags_re.sub("", self).split()) return Markup(stripped).unescape() @classmethod @@ -247,10 +246,9 @@ class EscapeFormatter(string.Formatter): elif hasattr(value, "__html__"): if format_spec: raise ValueError( - "Format specifier {0} given, but {1} does not" - " define __html_format__. A class that defines" - " __html__ must define __html_format__ to work" - " with format specifiers.".format(format_spec, type(value)) + f"Format specifier {format_spec} given, but {type(value)} does not" + " define __html_format__. A class that defines __html__ must define" + " __html_format__ to work with format specifiers." ) rv = value.__html__() else: @@ -268,8 +266,8 @@ def _escape_argspec(obj, iterable, escape): return obj -class _MarkupEscapeHelper(object): - """Helper for Markup.__mod__""" +class _MarkupEscapeHelper: + """Helper for :meth:`Markup.__mod__`.""" def __init__(self, obj, escape): self.obj = obj @@ -291,8 +289,7 @@ class _MarkupEscapeHelper(object): return float(self.obj) -# we have to import it down here as the speedups and native -# modules imports the markup type which is define above. +# circular import try: from ._native import _make_soft_unicode from ._speedups import escape, escape_silent, soft_unicode as soft_str diff --git a/src/markupsafe/_constants.py b/src/markupsafe/_constants.py index a19d214..7638937 100644 --- a/src/markupsafe/_constants.py +++ b/src/markupsafe/_constants.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- HTML_ENTITIES = { "AElig": 198, "Aacute": 193, diff --git a/src/markupsafe/_native.py b/src/markupsafe/_native.py index f886a2c..75d9f65 100644 --- a/src/markupsafe/_native.py +++ b/src/markupsafe/_native.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Native Python implementation used when the C module is not compiled. """ @@ -49,7 +48,7 @@ def soft_str(s): string, so it will still be marked as safe and won't be escaped again. - >>> value = escape('') + >>> value = escape("") >>> value Markup('<User 1>') >>> escape(str(value)) -- cgit v1.2.1