From 511797f9435f69bbedac18a97c666289d1d35a89 Mon Sep 17 00:00:00 2001 From: anthony sottile Date: Thu, 16 May 2024 16:54:11 -0400 Subject: [PATCH] ref: kill unused to_unicode and pprint template filter leftovers from python 2 --- src/sentry/interfaces/http.py | 6 ------ src/sentry/templatetags/sentry_helpers.py | 19 +------------------ src/sentry/utils/strings.py | 17 ++--------------- 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/src/sentry/interfaces/http.py b/src/sentry/interfaces/http.py index 981b4a20fd41da..cbbc73fb2d14c6 100644 --- a/src/sentry/interfaces/http.py +++ b/src/sentry/interfaces/http.py @@ -5,10 +5,8 @@ from django.utils.translation import gettext as _ from sentry.interfaces.base import Interface -from sentry.utils import json from sentry.utils.json import prune_empty_keys from sentry.utils.safe import get_path, safe_urlencode -from sentry.utils.strings import to_unicode from sentry.web.helpers import render_to_string @@ -63,10 +61,6 @@ def fix_broken_encoding(value): return value -def jsonify(value): - return to_unicode(value) if isinstance(value, str) else json.dumps(value) - - class Http(Interface): """ The Request information is stored in the Http interface. Two arguments diff --git a/src/sentry/templatetags/sentry_helpers.py b/src/sentry/templatetags/sentry_helpers.py index d52e9ee4faf75f..4115246663bd96 100644 --- a/src/sentry/templatetags/sentry_helpers.py +++ b/src/sentry/templatetags/sentry_helpers.py @@ -9,8 +9,6 @@ from django import template from django.template.defaultfilters import stringfilter from django.utils import timezone as django_timezone -from django.utils.html import escape -from django.utils.safestring import mark_safe from django.utils.translation import gettext as _ from packaging.version import parse as parse_version @@ -18,7 +16,7 @@ from sentry.api.serializers import serialize as serialize_func from sentry.utils import json from sentry.utils.strings import soft_break as _soft_break -from sentry.utils.strings import soft_hyphenate, to_unicode, truncatechars +from sentry.utils.strings import soft_hyphenate, truncatechars SentryVersion = namedtuple("SentryVersion", ["current", "latest", "update_available", "build"]) @@ -139,21 +137,6 @@ def security_contact(): return options.get("system.security-email") or options.get("system.admin-email") -@register.filter -def pprint(value, break_after=10): - """ - break_after is used to define how often a is - inserted (for soft wrapping). - """ - - value = to_unicode(value) - return mark_safe( - "".join( - escape(value[i : (i + break_after)]) for i in range(0, len(value), break_after) - ) - ) - - @register.filter def is_url(value): if not isinstance(value, str): diff --git a/src/sentry/utils/strings.py b/src/sentry/utils/strings.py index 43a7b491a1e207..e7fd2e97c4205b 100644 --- a/src/sentry/utils/strings.py +++ b/src/sentry/utils/strings.py @@ -7,9 +7,9 @@ import string import zlib from collections.abc import Callable -from typing import Any, overload +from typing import overload -from django.utils.encoding import force_str, smart_str +from django.utils.encoding import smart_str _sprintf_placeholder_re = re.compile( r"%(?:\d+\$)?[+-]?(?:[ 0]|\'.{1})?-?\d*(?:\.\d+)?[bcdeEufFgGosxX]" @@ -116,19 +116,6 @@ def soft_break_delimiter(match: re.Match[str]) -> str: return re.sub(rf"\S{{{length},}}", soft_break_delimiter, value) -def to_unicode(value: Any) -> str: - try: - value = str(force_str(value)) - except (UnicodeEncodeError, UnicodeDecodeError): - value = "(Error decoding value)" - except Exception: # in some cases we get a different exception - try: - value = str(repr(type(value))) - except Exception: - value = "(Error decoding value)" - return value - - valid_dot_atom_characters = frozenset(string.ascii_letters + string.digits + ".!#$%&'*+-/=?^_`{|}~")