From ad5f0c05b5d865fb6d3acfc333fa1d0625e91752 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 2 Aug 2021 14:20:39 -0700 Subject: [PATCH] python: Remove default "utf8" argument for encode(), decode(). Partially generated by pyupgrade. Signed-off-by: Anders Kaseorg --- corporate/tests/test_stripe.py | 6 ++---- scripts/lib/email-mirror-postfix | 2 +- scripts/lib/hash_reqs.py | 2 +- scripts/lib/node_cache.py | 2 +- scripts/lib/puppet_cache.py | 2 +- scripts/lib/zulip_tools.py | 2 +- scripts/setup/compare-settings-to-template | 2 +- tools/generate-integration-docs-screenshot | 2 +- tools/lib/provision.py | 2 +- zerver/data_import/mattermost.py | 2 +- zerver/decorator.py | 2 +- zerver/lib/actions.py | 2 +- zerver/lib/cache.py | 2 +- zerver/lib/camo.py | 4 ++-- zerver/lib/ccache.py | 2 +- zerver/lib/initial_password.py | 4 ++-- zerver/lib/send_email.py | 2 +- zerver/lib/test_classes.py | 8 ++++---- zerver/lib/test_helpers.py | 2 +- zerver/lib/upload.py | 4 ++-- zerver/lib/utils.py | 2 +- zerver/middleware.py | 4 ++-- ...60_missed_message_addresses_from_redis_to_db.py | 2 +- zerver/tests/test_auth_backends.py | 2 +- zerver/tests/test_decorators.py | 4 ++-- zerver/tests/test_docs.py | 6 +++--- zerver/tests/test_home.py | 14 +++++++------- zerver/tests/test_push_notifications.py | 2 +- zerver/tests/test_signup.py | 10 +++++----- zerver/tests/test_subs.py | 2 +- zerver/views/zephyr.py | 2 +- zerver/webhooks/beanstalk/view.py | 4 ++-- 32 files changed, 54 insertions(+), 56 deletions(-) diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 153819d566..9318ef441f 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -411,13 +411,11 @@ class StripeTestCase(ZulipTestCase): self.next_year = datetime(2013, 1, 2, 3, 4, 5, tzinfo=timezone.utc) def get_signed_seat_count_from_response(self, response: HttpResponse) -> Optional[str]: - match = re.search( - r"name=\"signed_seat_count\" value=\"(.+)\"", response.content.decode("utf-8") - ) + match = re.search(r"name=\"signed_seat_count\" value=\"(.+)\"", response.content.decode()) return match.group(1) if match else None def get_salt_from_response(self, response: HttpResponse) -> Optional[str]: - match = re.search(r"name=\"salt\" value=\"(\w+)\"", response.content.decode("utf-8")) + match = re.search(r"name=\"salt\" value=\"(\w+)\"", response.content.decode()) return match.group(1) if match else None def upgrade( diff --git a/scripts/lib/email-mirror-postfix b/scripts/lib/email-mirror-postfix index 737f2a9b18..cc31ef8210 100755 --- a/scripts/lib/email-mirror-postfix +++ b/scripts/lib/email-mirror-postfix @@ -156,7 +156,7 @@ def send_email_mirror( "msg_base64": base64.b64encode(msg_bytes).decode(), "secret": shared_secret, } - req = Request(url=urljoin(host, url), data=urlencode(data).encode("utf8")) + req = Request(url=urljoin(host, url), data=urlencode(data).encode()) try: urlopen(req, context=context) except HTTPError as err: diff --git a/scripts/lib/hash_reqs.py b/scripts/lib/hash_reqs.py index 6b8ea21053..4d7c4b2641 100755 --- a/scripts/lib/hash_reqs.py +++ b/scripts/lib/hash_reqs.py @@ -40,7 +40,7 @@ def python_version() -> str: def hash_deps(deps: Iterable[str]) -> str: deps_str = "\n".join(deps) + "\n" + python_version() - return hashlib.sha1(deps_str.encode("utf-8")).hexdigest() + return hashlib.sha1(deps_str.encode()).hexdigest() def main() -> int: diff --git a/scripts/lib/node_cache.py b/scripts/lib/node_cache.py index 19a709668f..cce970121f 100644 --- a/scripts/lib/node_cache.py +++ b/scripts/lib/node_cache.py @@ -48,7 +48,7 @@ def generate_sha1sum_node_modules( data["yarn-args"] = get_yarn_args(production=production) sha1sum = hashlib.sha1() - sha1sum.update(json.dumps(data, sort_keys=True).encode("utf-8")) + sha1sum.update(json.dumps(data, sort_keys=True).encode()) return sha1sum.hexdigest() diff --git a/scripts/lib/puppet_cache.py b/scripts/lib/puppet_cache.py index dc1cd50907..5abe00bef0 100644 --- a/scripts/lib/puppet_cache.py +++ b/scripts/lib/puppet_cache.py @@ -27,7 +27,7 @@ def generate_sha1sum_puppet_modules() -> str: ).strip() sha1sum = hashlib.sha1() - sha1sum.update(json.dumps(data, sort_keys=True).encode("utf-8")) + sha1sum.update(json.dumps(data, sort_keys=True).encode()) return sha1sum.hexdigest() diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index a7cb16f3a6..aba9edfb96 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -451,7 +451,7 @@ def files_and_string_digest(filenames: Sequence[str], extra_strings: Sequence[st sha1sum.update(file_to_hash.read()) for extra_string in extra_strings: - sha1sum.update(extra_string.encode("utf-8")) + sha1sum.update(extra_string.encode()) return sha1sum.hexdigest() diff --git a/scripts/setup/compare-settings-to-template b/scripts/setup/compare-settings-to-template index ced009cc23..805e8d7cca 100755 --- a/scripts/setup/compare-settings-to-template +++ b/scripts/setup/compare-settings-to-template @@ -36,7 +36,7 @@ for tag in [t["name"] for t in resp.json()]: f"https://raw.githubusercontent.com/zulip/zulip/{tag}/zproject/prod_settings_template.py", ) if resp.status_code == 200: - templ[tag] = resp.content.decode("utf-8") + templ[tag] = resp.content.decode() else: print("Failure: ") print(resp) diff --git a/tools/generate-integration-docs-screenshot b/tools/generate-integration-docs-screenshot index b116c8697a..58cfc18d06 100755 --- a/tools/generate-integration-docs-screenshot +++ b/tools/generate-integration-docs-screenshot @@ -177,7 +177,7 @@ def send_bot_payload_message( headers = get_requests_headers(integration.name, fixture_name) headers.update(config.custom_headers) if config.use_basic_auth: - credentials = base64.b64encode(f"{bot.email}:{bot.api_key}".encode("utf8")).decode("utf8") + credentials = base64.b64encode(f"{bot.email}:{bot.api_key}".encode()).decode() auth = f"basic {credentials}" headers.update(dict(Authorization=auth)) diff --git a/tools/lib/provision.py b/tools/lib/provision.py index 3a753791e9..ba18517868 100755 --- a/tools/lib/provision.py +++ b/tools/lib/provision.py @@ -376,7 +376,7 @@ def main(options: argparse.Namespace) -> "NoReturn": sha_sum = hashlib.sha1() for apt_depedency in SYSTEM_DEPENDENCIES: - sha_sum.update(apt_depedency.encode("utf8")) + sha_sum.update(apt_depedency.encode()) if "debian" in os_families(): with open("scripts/lib/setup-apt-repo", "rb") as fb: sha_sum.update(fb.read()) diff --git a/zerver/data_import/mattermost.py b/zerver/data_import/mattermost.py index e34ad3a657..f2b8cda37a 100644 --- a/zerver/data_import/mattermost.py +++ b/zerver/data_import/mattermost.py @@ -227,7 +227,7 @@ def generate_huddle_name(huddle_members: List[str]) -> str: # lifetime of export tool run, as it doesn't appear in the output. import hashlib - return hashlib.md5("".join(sorted(huddle_members)).encode("utf-8")).hexdigest() + return hashlib.md5("".join(sorted(huddle_members)).encode()).hexdigest() def convert_huddle_data( diff --git a/zerver/decorator.py b/zerver/decorator.py index 31d21c38c6..a04abbd66c 100644 --- a/zerver/decorator.py +++ b/zerver/decorator.py @@ -655,7 +655,7 @@ def authenticated_rest_api_view( # case insensitive per RFC 1945 if auth_type.lower() != "basic": raise JsonableError(_("This endpoint requires HTTP basic authentication.")) - role, api_key = base64.b64decode(credentials).decode("utf-8").split(":") + role, api_key = base64.b64decode(credentials).decode().split(":") except ValueError: return json_unauthorized(_("Invalid authorization header for basic auth")) except KeyError: diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 6910907cf7..006be8f400 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -1286,7 +1286,7 @@ def do_deactivate_stream( # Prepend a substring of the hashed stream ID to the new stream name streamID = str(stream.id) - stream_id_hash_object = hashlib.sha512(streamID.encode("utf-8")) + stream_id_hash_object = hashlib.sha512(streamID.encode()) hashed_stream_id = stream_id_hash_object.hexdigest()[0:7] new_name = (hashed_stream_id + "!DEACTIVATED:" + old_name)[: Stream.MAX_NAME_LENGTH] diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py index 6d9f14ef9c..640acf2654 100644 --- a/zerver/lib/cache.py +++ b/zerver/lib/cache.py @@ -120,7 +120,7 @@ def bounce_key_prefix_for_testing(test_name: str) -> None: KEY_PREFIX = test_name + ":" + str(os.getpid()) + ":" # We are taking the hash of the KEY_PREFIX to decrease the size of the key. # Memcached keys should have a length of less than 250. - KEY_PREFIX = hashlib.sha1(KEY_PREFIX.encode("utf-8")).hexdigest() + ":" + KEY_PREFIX = hashlib.sha1(KEY_PREFIX.encode()).hexdigest() + ":" def get_cache_backend(cache_name: Optional[str]) -> BaseCache: diff --git a/zerver/lib/camo.py b/zerver/lib/camo.py index 37d60d2eb6..9bd54b3920 100644 --- a/zerver/lib/camo.py +++ b/zerver/lib/camo.py @@ -5,8 +5,8 @@ from django.conf import settings def generate_camo_url(url: str) -> str: - encoded_url = url.encode("utf-8") - encoded_camo_key = settings.CAMO_KEY.encode("utf-8") + encoded_url = url.encode() + encoded_camo_key = settings.CAMO_KEY.encode() digest = hmac.new(encoded_camo_key, encoded_url, hashlib.sha1).hexdigest() return "{}/{}".format(digest, encoded_url.hex()) diff --git a/zerver/lib/ccache.py b/zerver/lib/ccache.py index 9e226db846..bc8cd6e060 100644 --- a/zerver/lib/ccache.py +++ b/zerver/lib/ccache.py @@ -91,7 +91,7 @@ def der_encode_uint32(val: int) -> bytes: def der_encode_string(val: str) -> bytes: if not isinstance(val, str): raise TypeError("unicode") - return der_encode_tlv(0x1B, val.encode("utf-8")) + return der_encode_tlv(0x1B, val.encode()) def der_encode_octet_string(val: bytes) -> bytes: diff --git a/zerver/lib/initial_password.py b/zerver/lib/initial_password.py index 9c79e6238d..8ccbbc4336 100644 --- a/zerver/lib/initial_password.py +++ b/zerver/lib/initial_password.py @@ -10,9 +10,9 @@ def initial_password(email: str) -> Optional[str]: created by populate_db.""" if settings.INITIAL_PASSWORD_SALT is not None: - encoded_key = (settings.INITIAL_PASSWORD_SALT + email).encode("utf-8") + encoded_key = (settings.INITIAL_PASSWORD_SALT + email).encode() digest = hashlib.sha256(encoded_key).digest() - return base64.b64encode(digest)[:16].decode("utf-8") + return base64.b64encode(digest)[:16].decode() else: # None as a password for a user tells Django to set an unusable password return None diff --git a/zerver/lib/send_email.py b/zerver/lib/send_email.py index 1032696137..d04320f4a1 100644 --- a/zerver/lib/send_email.py +++ b/zerver/lib/send_email.py @@ -487,7 +487,7 @@ def send_custom_email(users: List[UserProfile], options: Dict[str, Any]) -> None with open(options["markdown_template_path"]) as f: text = f.read() parsed_email_template = Parser(policy=default).parsestr(text) - email_template_hash = hashlib.sha256(text.encode("utf-8")).hexdigest()[0:32] + email_template_hash = hashlib.sha256(text.encode()).hexdigest()[0:32] email_filename = f"custom/custom_email_{email_template_hash}.source.html" email_id = f"zerver/emails/custom/custom_email_{email_template_hash}" diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py index c7857245cc..79a65b4479 100644 --- a/zerver/lib/test_classes.py +++ b/zerver/lib/test_classes.py @@ -718,7 +718,7 @@ Output: identifier: Can be an email or a remote server uuid. """ credentials = f"{identifier}:{api_key}" - return "Basic " + base64.b64encode(credentials.encode("utf-8")).decode("utf-8") + return "Basic " + base64.b64encode(credentials.encode()).decode() def uuid_get(self, identifier: str, *args: Any, **kwargs: Any) -> HttpResponse: kwargs["HTTP_AUTHORIZATION"] = self.encode_uuid(identifier) @@ -904,17 +904,17 @@ Output: self.assertIn(msg_substring, self.get_json_error(result, status_code=status_code)) def assert_in_response(self, substring: str, response: HttpResponse) -> None: - self.assertIn(substring, response.content.decode("utf-8")) + self.assertIn(substring, response.content.decode()) def assert_in_success_response(self, substrings: List[str], response: HttpResponse) -> None: self.assertEqual(response.status_code, 200) - decoded = response.content.decode("utf-8") + decoded = response.content.decode() for substring in substrings: self.assertIn(substring, decoded) def assert_not_in_success_response(self, substrings: List[str], response: HttpResponse) -> None: self.assertEqual(response.status_code, 200) - decoded = response.content.decode("utf-8") + decoded = response.content.decode() for substring in substrings: self.assertNotIn(substring, decoded) diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py index 499262cebc..87c6773c3f 100644 --- a/zerver/lib/test_helpers.py +++ b/zerver/lib/test_helpers.py @@ -162,7 +162,7 @@ def queries_captured( if include_savepoints or not isinstance(sql, str) or "SAVEPOINT" not in sql: queries.append( { - "sql": self.mogrify(sql, params).decode("utf-8"), + "sql": self.mogrify(sql, params).decode(), "time": f"{duration:.3f}", } ) diff --git a/zerver/lib/upload.py b/zerver/lib/upload.py index 88122486c9..f4904f0145 100644 --- a/zerver/lib/upload.py +++ b/zerver/lib/upload.py @@ -767,7 +767,7 @@ LOCAL_FILE_ACCESS_TOKEN_SALT = "local_file_" def generate_unauthed_file_access_url(path_id: str) -> str: signed_data = TimestampSigner(salt=LOCAL_FILE_ACCESS_TOKEN_SALT).sign(path_id) - token = base64.b16encode(signed_data.encode("utf-8")).decode("utf-8") + token = base64.b16encode(signed_data.encode()).decode() filename = path_id.split("/")[-1] return reverse("local_file_unauthed", args=[token, filename]) @@ -776,7 +776,7 @@ def generate_unauthed_file_access_url(path_id: str) -> str: def get_local_file_path_id_from_token(token: str) -> Optional[str]: signer = TimestampSigner(salt=LOCAL_FILE_ACCESS_TOKEN_SALT) try: - signed_data = base64.b16decode(token).decode("utf-8") + signed_data = base64.b16decode(token).decode() path_id = signer.unsign(signed_data, max_age=timedelta(seconds=60)) except (BadSignature, binascii.Error): return None diff --git a/zerver/lib/utils.py b/zerver/lib/utils.py index 2dda3e1564..228ae9a025 100644 --- a/zerver/lib/utils.py +++ b/zerver/lib/utils.py @@ -92,7 +92,7 @@ def make_safe_digest(string: str, hash_func: Callable[[bytes], Any] = hashlib.sh """ # hashlib.sha1, md5, etc. expect bytes, so non-ASCII strings must # be encoded. - return hash_func(string.encode("utf-8")).hexdigest() + return hash_func(string.encode()).hexdigest() def log_statsd_event(name: str) -> None: diff --git a/zerver/middleware.py b/zerver/middleware.py index aa83a6a5dc..1bebdc6406 100644 --- a/zerver/middleware.py +++ b/zerver/middleware.py @@ -606,8 +606,8 @@ def alter_content(request: HttpRequest, content: bytes) -> bytes: ).placeholder_open_graph_description assert placeholder_open_graph_description is not None return content.replace( - placeholder_open_graph_description.encode("utf-8"), - first_paragraph_text.encode("utf-8"), + placeholder_open_graph_description.encode(), + first_paragraph_text.encode(), ) diff --git a/zerver/migrations/0260_missed_message_addresses_from_redis_to_db.py b/zerver/migrations/0260_missed_message_addresses_from_redis_to_db.py index 92dcbb2cdc..635331c434 100644 --- a/zerver/migrations/0260_missed_message_addresses_from_redis_to_db.py +++ b/zerver/migrations/0260_missed_message_addresses_from_redis_to_db.py @@ -39,7 +39,7 @@ def move_missed_message_addresses_to_database( redis_client.delete(key) continue - topic_name = subject_b.decode("utf-8") + topic_name = subject_b.decode() # The data model for missed-message emails has changed in two # key ways: We're moving it from Redis to the database for diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index 38301fdbb9..8508d73503 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -3995,7 +3995,7 @@ class GoogleAuthBackendTest(SocialAuthBase): url = re.findall( 'action="(http://zulip.testserver/accounts/do_confirm[^"]*)"', - result.content.decode("utf-8"), + result.content.decode(), )[0] confirmation = Confirmation.objects.all().first() assert confirmation is not None diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py index f9e707d760..ad31f5c174 100644 --- a/zerver/tests/test_decorators.py +++ b/zerver/tests/test_decorators.py @@ -538,11 +538,11 @@ class DecoratorLoggingTestCase(ZulipTestCase): user_profile = self.example_user("hamlet") api_key = get_api_key(user_profile) credentials = f"{user_profile.email}:{api_key}" - api_auth = "Digest " + base64.b64encode(credentials.encode("utf-8")).decode("utf-8") + api_auth = "Digest " + base64.b64encode(credentials.encode()).decode() result = self.client_post("/api/v1/external/zendesk", {}, HTTP_AUTHORIZATION=api_auth) self.assert_json_error(result, "This endpoint requires HTTP basic authentication.") - api_auth = "Basic " + base64.b64encode(b"foo").decode("utf-8") + api_auth = "Basic " + base64.b64encode(b"foo").decode() result = self.client_post("/api/v1/external/zendesk", {}, HTTP_AUTHORIZATION=api_auth) self.assert_json_error( result, "Invalid authorization header for basic auth", status_code=401 diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index d21b82a7c9..140fd5dcf8 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -256,10 +256,10 @@ class DocPageTest(ZulipTestCase): def test_electron_detection(self) -> None: result = self.client_get("/accounts/password/reset/") # TODO: Ideally, this Mozilla would be the specific browser. - self.assertTrue('data-platform="Mozilla"' in result.content.decode("utf-8")) + self.assertTrue('data-platform="Mozilla"' in result.content.decode()) result = self.client_get("/accounts/password/reset/", HTTP_USER_AGENT="ZulipElectron/1.0.0") - self.assertTrue('data-platform="ZulipElectron"' in result.content.decode("utf-8")) + self.assertTrue('data-platform="ZulipElectron"' in result.content.decode()) class HelpTest(ZulipTestCase): @@ -539,7 +539,7 @@ class AppsPageTest(ZulipTestCase): with self.settings(ZILENCER_ENABLED=True): result = self.client_get("/apps/") self.assertEqual(result.status_code, 200) - html = result.content.decode("utf-8") + html = result.content.decode() self.assertIn("Apps for every platform.", html) def test_app_download_link_view(self) -> None: diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 1eb00c4a1e..28a0af34ac 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -240,7 +240,7 @@ class HomeTest(ZulipTestCase): self.assert_length(queries, 43) self.assert_length(cache_mock.call_args_list, 5) - html = result.content.decode("utf-8") + html = result.content.decode() for html_bit in html_bits: if html_bit not in html: @@ -351,7 +351,7 @@ class HomeTest(ZulipTestCase): self.assert_length(queries2, 38) # Do a sanity check that our new streams were in the payload. - html = result.content.decode("utf-8") + html = result.content.decode() self.assertIn("test_stream_7", html) def _get_home_page(self, **kwargs: Any) -> HttpResponse: @@ -366,7 +366,7 @@ class HomeTest(ZulipTestCase): Use this for tests that are geared toward specific edge cases, but which still want the home page to load properly. """ - html = result.content.decode("utf-8") + html = result.content.decode() if "start a conversation" not in html: raise AssertionError("Home page probably did not load.") @@ -382,7 +382,7 @@ class HomeTest(ZulipTestCase): result = self.client_get("/", dict(stream="Denmark")) - html = result.content.decode("utf-8") + html = result.content.decode() self.assertIn("Accept the new Terms of Service", html) def test_banned_desktop_app_versions(self) -> None: @@ -390,7 +390,7 @@ class HomeTest(ZulipTestCase): self.login_user(user) result = self.client_get("/", HTTP_USER_AGENT="ZulipElectron/2.3.82") - html = result.content.decode("utf-8") + html = result.content.decode() self.assertIn("You are using old version of the Zulip desktop", html) def test_unsupported_browser(self) -> None: @@ -405,7 +405,7 @@ class HomeTest(ZulipTestCase): ] for user_agent in unsupported_user_agents: result = self.client_get("/", HTTP_USER_AGENT=user_agent) - html = result.content.decode("utf-8") + html = result.content.decode() self.assertIn("Internet Explorer is not supported by Zulip.", html) def test_terms_of_service_first_time_template(self) -> None: @@ -445,7 +445,7 @@ class HomeTest(ZulipTestCase): self.login("hamlet") result = self._get_home_page(stream="Denmark", topic="lunch") self._sanity_check(result) - html = result.content.decode("utf-8") + html = result.content.decode() self.assertIn("lunch", html) self.assertEqual( set(result["Cache-Control"].split(", ")), {"must-revalidate", "no-store", "no-cache"} diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 08c24fbe0f..7432bb81bc 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -241,7 +241,7 @@ class PushBouncerNotificationTest(BouncerTestCase): del self.API_KEYS[self.server_uuid] credentials = "{}:{}".format("5678-efgh", "invalid") - api_auth = "Basic " + base64.b64encode(credentials.encode("utf-8")).decode("utf-8") + api_auth = "Basic " + base64.b64encode(credentials.encode()).decode() result = self.client_post( endpoint, {"user_id": user_id, "token_kind": token_kind, "token": token}, diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 6d08caa153..a6a55afa19 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -5114,7 +5114,7 @@ class TestLoginPage(ZulipTestCase): class TestFindMyTeam(ZulipTestCase): def test_template(self) -> None: result = self.client_get("/accounts/find/") - self.assertIn("Find your Zulip accounts", result.content.decode("utf8")) + self.assertIn("Find your Zulip accounts", result.content.decode()) def test_result(self) -> None: # We capitalize a letter in cordelia's email to test that the search is case-insensitive. @@ -5126,7 +5126,7 @@ class TestFindMyTeam(ZulipTestCase): result.url, "/accounts/find/?emails=iago%40zulip.com%2CcordeliA%40zulip.com" ) result = self.client_get(result.url) - content = result.content.decode("utf8") + content = result.content.decode() self.assertIn("Emails sent! You will only receive emails", content) self.assertIn("iago@zulip.com", content) self.assertIn("cordeliA@zulip.com", content) @@ -5144,7 +5144,7 @@ class TestFindMyTeam(ZulipTestCase): result.url, "/accounts/find/?emails=iago%40zulip.com%2Cinvalid_email%40zulip.com" ) result = self.client_get(result.url) - content = result.content.decode("utf8") + content = result.content.decode() self.assertIn("Emails sent! You will only receive emails", content) self.assertIn(self.example_email("iago"), content) self.assertIn("invalid_email@", content) @@ -5167,7 +5167,7 @@ class TestFindMyTeam(ZulipTestCase): def test_find_team_zero_emails(self) -> None: data = {"emails": ""} result = self.client_post("/accounts/find/", data) - self.assertIn("This field is required", result.content.decode("utf8")) + self.assertIn("This field is required", result.content.decode()) self.assertEqual(result.status_code, 200) from django.core.mail import outbox @@ -5215,7 +5215,7 @@ class TestFindMyTeam(ZulipTestCase): data = {"emails": ",".join(f"hamlet-{i}@zulip.com" for i in range(11))} result = self.client_post("/accounts/find/", data) self.assertEqual(result.status_code, 200) - self.assertIn("Please enter at most 10", result.content.decode("utf8")) + self.assertIn("Please enter at most 10", result.content.decode()) from django.core.mail import outbox self.assert_length(outbox, 0) diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py index 03c7595924..4ad25297b6 100644 --- a/zerver/tests/test_subs.py +++ b/zerver/tests/test_subs.py @@ -1395,7 +1395,7 @@ class StreamAdminTest(ZulipTestCase): # A deleted stream's name is changed, is deactivated, is invite-only, # and has no subscribers. - hashed_stream_id = hashlib.sha512(str(stream_id).encode("utf-8")).hexdigest()[0:7] + hashed_stream_id = hashlib.sha512(str(stream_id).encode()).hexdigest()[0:7] deactivated_stream_name = hashed_stream_id + "!DEACTIVATED:" + active_name deactivated_stream = get_stream(deactivated_stream_name, realm) self.assertTrue(deactivated_stream.deactivated) diff --git a/zerver/views/zephyr.py b/zerver/views/zephyr.py index 939d1dd319..e41d7ff10e 100644 --- a/zerver/views/zephyr.py +++ b/zerver/views/zephyr.py @@ -65,7 +65,7 @@ def webathena_kerberos_login( "/home/zulip/python-zulip-api/zulip/integrations/zephyr/process_ccache", user, api_key, - base64.b64encode(ccache).decode("utf-8"), + base64.b64encode(ccache).decode(), ] subprocess.check_call( ["ssh", settings.PERSONAL_ZMIRROR_SERVER, "--", " ".join(map(shlex.quote, command))] diff --git a/zerver/webhooks/beanstalk/view.py b/zerver/webhooks/beanstalk/view.py index 802f5adbdf..d36668cb3d 100644 --- a/zerver/webhooks/beanstalk/view.py +++ b/zerver/webhooks/beanstalk/view.py @@ -62,10 +62,10 @@ def beanstalk_decoder(view_func: ViewFuncT) -> ViewFuncT: encoded_value: str auth_type, encoded_value = request.META["HTTP_AUTHORIZATION"].split() if auth_type.lower() == "basic": - email, api_key = base64.b64decode(encoded_value).decode("utf-8").split(":") + email, api_key = base64.b64decode(encoded_value).decode().split(":") email = email.replace("%40", "@") credentials = f"{email}:{api_key}" - encoded_credentials: str = base64.b64encode(credentials.encode("utf-8")).decode("utf8") + encoded_credentials: str = base64.b64encode(credentials.encode()).decode() request.META["HTTP_AUTHORIZATION"] = "Basic " + encoded_credentials return view_func(request, *args, **kwargs)