ruff: Fix N813 camelcase imported as lowercase.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-11-15 21:28:44 -08:00 committed by Tim Abbott
parent 8f17093be2
commit 924d530292
6 changed files with 21 additions and 22 deletions

View File

@ -8,7 +8,7 @@ from django.conf import settings
from django.db.backends.utils import CursorWrapper from django.db.backends.utils import CursorWrapper
from django.template import loader from django.template import loader
from django.urls import reverse from django.urls import reverse
from markupsafe import Markup as mark_safe from markupsafe import Markup
from zerver.models import UserActivity from zerver.models import UserActivity
@ -58,36 +58,36 @@ def format_date_for_activity_reports(date: Optional[datetime]) -> str:
return "" return ""
def user_activity_link(email: str, user_profile_id: int) -> mark_safe: def user_activity_link(email: str, user_profile_id: int) -> Markup:
from analytics.views.user_activity import get_user_activity from analytics.views.user_activity import get_user_activity
url = reverse(get_user_activity, kwargs=dict(user_profile_id=user_profile_id)) url = reverse(get_user_activity, kwargs=dict(user_profile_id=user_profile_id))
email_link = f'<a href="{escape(url)}">{escape(email)}</a>' email_link = f'<a href="{escape(url)}">{escape(email)}</a>'
return mark_safe(email_link) return Markup(email_link)
def realm_activity_link(realm_str: str) -> mark_safe: def realm_activity_link(realm_str: str) -> Markup:
from analytics.views.realm_activity import get_realm_activity from analytics.views.realm_activity import get_realm_activity
url = reverse(get_realm_activity, kwargs=dict(realm_str=realm_str)) url = reverse(get_realm_activity, kwargs=dict(realm_str=realm_str))
realm_link = f'<a href="{escape(url)}">{escape(realm_str)}</a>' realm_link = f'<a href="{escape(url)}">{escape(realm_str)}</a>'
return mark_safe(realm_link) return Markup(realm_link)
def realm_stats_link(realm_str: str) -> mark_safe: def realm_stats_link(realm_str: str) -> Markup:
from analytics.views.stats import stats_for_realm from analytics.views.stats import stats_for_realm
url = reverse(stats_for_realm, kwargs=dict(realm_str=realm_str)) url = reverse(stats_for_realm, kwargs=dict(realm_str=realm_str))
stats_link = f'<a href="{escape(url)}"><i class="fa fa-pie-chart"></i>{escape(realm_str)}</a>' stats_link = f'<a href="{escape(url)}"><i class="fa fa-pie-chart"></i>{escape(realm_str)}</a>'
return mark_safe(stats_link) return Markup(stats_link)
def remote_installation_stats_link(server_id: int, hostname: str) -> mark_safe: def remote_installation_stats_link(server_id: int, hostname: str) -> Markup:
from analytics.views.stats import stats_for_remote_installation from analytics.views.stats import stats_for_remote_installation
url = reverse(stats_for_remote_installation, kwargs=dict(remote_server_id=server_id)) url = reverse(stats_for_remote_installation, kwargs=dict(remote_server_id=server_id))
stats_link = f'<a href="{escape(url)}"><i class="fa fa-pie-chart"></i>{escape(hostname)}</a>' stats_link = f'<a href="{escape(url)}"><i class="fa fa-pie-chart"></i>{escape(hostname)}</a>'
return mark_safe(stats_link) return Markup(stats_link)
def get_user_activity_summary(records: Collection[UserActivity]) -> Dict[str, Any]: def get_user_activity_summary(records: Collection[UserActivity]) -> Dict[str, Any]:

View File

@ -10,7 +10,7 @@ from django.http import HttpRequest, HttpResponse
from django.shortcuts import render from django.shortcuts import render
from django.template import loader from django.template import loader
from django.utils.timezone import now as timezone_now from django.utils.timezone import now as timezone_now
from markupsafe import Markup as mark_safe from markupsafe import Markup
from psycopg2.sql import SQL, Composable, Literal from psycopg2.sql import SQL, Composable, Literal
from analytics.lib.counts import COUNT_STATS from analytics.lib.counts import COUNT_STATS
@ -305,7 +305,7 @@ def realm_summary_table(realm_minutes: Dict[str, float]) -> str:
return content return content
def user_activity_intervals() -> Tuple[mark_safe, Dict[str, float]]: def user_activity_intervals() -> Tuple[Markup, Dict[str, float]]:
day_end = timestamp_to_datetime(time.time()) day_end = timestamp_to_datetime(time.time())
day_start = day_end - timedelta(hours=24) day_start = day_end - timedelta(hours=24)
@ -357,7 +357,7 @@ def user_activity_intervals() -> Tuple[mark_safe, Dict[str, float]]:
output += f"\nTotal duration: {total_duration}\n" output += f"\nTotal duration: {total_duration}\n"
output += f"\nTotal duration in minutes: {total_duration.total_seconds() / 60.}\n" output += f"\nTotal duration in minutes: {total_duration.total_seconds() / 60.}\n"
output += f"Total duration amortized to a month: {total_duration.total_seconds() * 30. / 60.}" output += f"Total duration amortized to a month: {total_duration.total_seconds() * 30. / 60.}"
content = mark_safe("<pre>" + output + "</pre>") content = Markup("<pre>" + output + "</pre>")
return content, realm_minutes return content, realm_minutes
@ -372,7 +372,7 @@ def ad_hoc_queries() -> List[Dict[str, str]]:
cursor.close() cursor.close()
def fix_rows( def fix_rows(
i: int, fixup_func: Union[Callable[[str], mark_safe], Callable[[datetime], str]] i: int, fixup_func: Union[Callable[[str], Markup], Callable[[datetime], str]]
) -> None: ) -> None:
for row in rows: for row in rows:
row[i] = fixup_func(row[i]) row[i] = fixup_func(row[i])

View File

@ -18,7 +18,7 @@ from django.utils.http import urlsafe_base64_encode
from django.utils.translation import get_language from django.utils.translation import get_language
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy from django.utils.translation import gettext_lazy
from markupsafe import Markup as mark_safe from markupsafe import Markup
from two_factor.forms import AuthenticationTokenForm as TwoFactorAuthenticationTokenForm from two_factor.forms import AuthenticationTokenForm as TwoFactorAuthenticationTokenForm
from two_factor.utils import totp_digits from two_factor.utils import totp_digits
@ -75,9 +75,9 @@ def email_is_not_mit_mailing_list(email: str) -> None:
DNS.dnslookup(f"{address.username}.pobox.ns.athena.mit.edu", DNS.Type.TXT) DNS.dnslookup(f"{address.username}.pobox.ns.athena.mit.edu", DNS.Type.TXT)
except DNS.Base.ServerError as e: except DNS.Base.ServerError as e:
if e.rcode == DNS.Status.NXDOMAIN: if e.rcode == DNS.Status.NXDOMAIN:
# This error is mark_safe only because 1. it needs to render HTML # This error is Markup only because 1. it needs to render HTML
# 2. It's not formatted with any user input. # 2. It's not formatted with any user input.
raise ValidationError(mark_safe(MIT_VALIDATION_ERROR)) raise ValidationError(Markup(MIT_VALIDATION_ERROR))
else: else:
raise AssertionError("Unexpected DNS error") raise AssertionError("Unexpected DNS error")

View File

@ -26,7 +26,6 @@ from typing import (
Union, Union,
) )
from urllib.parse import urlencode, urljoin, urlsplit from urllib.parse import urlencode, urljoin, urlsplit
from xml.etree import ElementTree as etree
from xml.etree.ElementTree import Element, SubElement from xml.etree.ElementTree import Element, SubElement
import ahocorasick import ahocorasick
@ -1713,7 +1712,7 @@ class BlockQuoteProcessor(markdown.blockprocessors.BlockQuoteProcessor):
# a blank line intentionally. # a blank line intentionally.
# #
# This is a new blockquote. Create a new parent element. # This is a new blockquote. Create a new parent element.
quote = etree.SubElement(parent, "blockquote") quote = SubElement(parent, "blockquote")
# Recursively parse block with blockquote as parent. # Recursively parse block with blockquote as parent.
# change parser state so blockquotes embedded in lists use p tags # change parser state so blockquotes embedded in lists use p tags

View File

@ -23,7 +23,7 @@ from django.core.files.uploadedfile import UploadedFile
from django.core.signing import BadSignature, TimestampSigner from django.core.signing import BadSignature, TimestampSigner
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from markupsafe import Markup as mark_safe from markupsafe import Markup
from mypy_boto3_s3.client import S3Client from mypy_boto3_s3.client import S3Client
from mypy_boto3_s3.service_resource import Bucket, Object from mypy_boto3_s3.service_resource import Bucket, Object
from PIL import GifImagePlugin, Image, ImageOps, PngImagePlugin from PIL import GifImagePlugin, Image, ImageOps, PngImagePlugin
@ -112,7 +112,7 @@ def sanitize_name(value: str) -> str:
value = re.sub(r"[^\w\s.-]", "", value).strip() value = re.sub(r"[^\w\s.-]", "", value).strip()
value = re.sub(r"[-\s]+", "-", value) value = re.sub(r"[-\s]+", "-", value)
assert value not in {"", ".", ".."} assert value not in {"", ".", ".."}
return mark_safe(value) return Markup(value)
class BadImageError(JsonableError): class BadImageError(JsonableError):

View File

@ -25,7 +25,7 @@ from django.utils.http import url_has_allowed_host_and_scheme
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_safe from django.views.decorators.http import require_safe
from markupsafe import Markup as mark_safe from markupsafe import Markup
from social_django.utils import load_backend, load_strategy from social_django.utils import load_backend, load_strategy
from two_factor.forms import BackupTokenForm from two_factor.forms import BackupTokenForm
from two_factor.views import LoginView as BaseTwoFactorLoginView from two_factor.views import LoginView as BaseTwoFactorLoginView
@ -718,7 +718,7 @@ def update_login_page_context(request: HttpRequest, context: Dict[str, Any]) ->
return return
try: try:
validate_email(deactivated_email) validate_email(deactivated_email)
context["deactivated_account_error"] = mark_safe( context["deactivated_account_error"] = Markup(
DEACTIVATED_ACCOUNT_ERROR.format(username=escape(deactivated_email)) DEACTIVATED_ACCOUNT_ERROR.format(username=escape(deactivated_email))
) )
except ValidationError: except ValidationError: