Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
python: Skip unnecessary decode before JSON parsing.
Anders Kaseorg86e8d81c7f31
diff --git a/scripts/lib/email-mirror-postfix b/scripts/lib/email-mirror-postfixindex ebf49f19e82..458e2faa119 100755--- a/scripts/lib/email-mirror-postfix+++ b/scripts/lib/email-mirror-postfix@@ -81,7 +81,7 @@ MAX_ALLOWED_PAYLOAD = 25 * 1024 * 1024def process_response_error(e: HTTPError) -> None:if e.code == 400:response_content = e.read()- response_data = json.loads(response_content.decode('utf8'))+ response_data = json.loads(response_content)print(response_data['msg'])exit(posix.EX_NOUSER)else:diff --git a/zerver/tests/test_bots.py b/zerver/tests/test_bots.pyindex 2aab06ee800..413c7f27831 100644--- a/zerver/tests/test_bots.py+++ b/zerver/tests/test_bots.py@@ -1574,7 +1574,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):response = self.client_post("/json/bots", bot_metadata)self.assertEqual(response.status_code, 400)expected_error_message = 'Invalid stripe_api_key value _invalid_key (stripe_api_key starts with a "_" and is hence invalid.)'- self.assertEqual(orjson.loads(response.content.decode('utf-8'))["msg"], expected_error_message)+ self.assertEqual(orjson.loads(response.content)["msg"], expected_error_message)with self.assertRaises(UserProfile.DoesNotExist):UserProfile.objects.get(full_name="My Stripe Bot")@@ -1590,7 +1590,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):response = self.client_post("/json/bots", bot_metadata)self.assertEqual(response.status_code, 400)expected_error_message = "Missing configuration parameters: {'stripe_api_key'}"- self.assertEqual(orjson.loads(response.content.decode('utf-8'))["msg"], expected_error_message)+ self.assertEqual(orjson.loads(response.content)["msg"], expected_error_message)with self.assertRaises(UserProfile.DoesNotExist):UserProfile.objects.get(full_name="My Stripe Bot")@@ -1619,6 +1619,6 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):response = self.client_post("/json/bots", bot_metadata)self.assertEqual(response.status_code, 400)expected_error_message = "Invalid integration 'stripes'."- self.assertEqual(orjson.loads(response.content.decode('utf-8'))["msg"], expected_error_message)+ self.assertEqual(orjson.loads(response.content)["msg"], expected_error_message)with self.assertRaises(UserProfile.DoesNotExist):UserProfile.objects.get(full_name="My Stripe Bot")diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.pyindex 2259065cc1c..d793d773943 100644--- a/zerver/tests/test_message_edit.py+++ b/zerver/tests/test_message_edit.py@@ -249,8 +249,7 @@ class EditMessageTest(ZulipTestCase):messages_result = self.client_get("/json/messages",{"anchor": msg_id_1, "num_before": 0, "num_after": 10})self.assert_json_success(messages_result)- json_messages = orjson.loads(- messages_result.content.decode('utf-8'))+ json_messages = orjson.loads(messages_result.content)for msg in json_messages['messages']:self.assertNotIn("edit_history", msg)@@ -271,8 +270,7 @@ class EditMessageTest(ZulipTestCase):message_edit_history_1 = self.client_get("/json/messages/" + str(msg_id_1) + "/history")- json_response_1 = orjson.loads(- message_edit_history_1.content.decode('utf-8'))+ json_response_1 = orjson.loads(message_edit_history_1.content)message_history_1 = json_response_1['message_history']# Check content of message after edit.@@ -307,8 +305,7 @@ class EditMessageTest(ZulipTestCase):message_edit_history_2 = self.client_get("/json/messages/" + str(msg_id_2) + "/history")- json_response_2 = orjson.loads(- message_edit_history_2.content.decode('utf-8'))+ json_response_2 = orjson.loads(message_edit_history_2.content)message_history_2 = json_response_2['message_history']self.assertEqual(message_history_2[0]['rendered_content'],@@ -342,8 +339,7 @@ class EditMessageTest(ZulipTestCase):message_edit_history_1 = self.client_get("/json/messages/" + str(msg_id_1) + "/history")- json_response_1 = orjson.loads(- message_edit_history_1.content.decode('utf-8'))+ json_response_1 = orjson.loads(message_edit_history_1.content)message_history_1 = json_response_1['message_history']# Check content of message after edit.@@ -469,7 +465,7 @@ class EditMessageTest(ZulipTestCase):# correct filled-out fieldsmessage_edit_history = self.client_get("/json/messages/" + str(msg_id) + "/history")- json_response = orjson.loads(message_edit_history.content.decode('utf-8'))+ json_response = orjson.loads(message_edit_history.content)# We reverse the message history view output so that the IDs line up with the above.message_history = list(reversed(json_response['message_history']))diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.pyindex 512c22299b9..742faace020 100644--- a/zerver/tests/test_message_send.py+++ b/zerver/tests/test_message_send.py@@ -323,7 +323,7 @@ class MessagePOSTTest(ZulipTestCase):"client": "test suite","to": othello.email})self.assert_json_success(result)- message_id = orjson.loads(result.content.decode())['id']+ message_id = orjson.loads(result.content)['id']recent_conversations = get_recent_private_conversations(user_profile)self.assertEqual(len(recent_conversations), 1)@@ -338,7 +338,7 @@ class MessagePOSTTest(ZulipTestCase):"client": "test suite","to": user_profile.email})self.assert_json_success(result)- self_message_id = orjson.loads(result.content.decode())['id']+ self_message_id = orjson.loads(result.content)['id']recent_conversations = get_recent_private_conversations(user_profile)self.assertEqual(len(recent_conversations), 2)diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex 4fd405075f2..dae28be64ea 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -306,7 +306,7 @@ class TestCreateStreams(ZulipTestCase):"already_subscribed": {},}self.assertEqual(response.status_code, 200)- self.assertEqual(orjson.loads(response.content.decode()), expected_response)+ self.assertEqual(orjson.loads(response.content), expected_response)# 2 messages should be created, one in announce and one in the new stream itself.self.assertEqual(final_message_count - initial_message_count, 2)diff --git a/zerver/views/video_calls.py b/zerver/views/video_calls.pyindex 78b8ad1218c..9d3d3e52d58 100644--- a/zerver/views/video_calls.py+++ b/zerver/views/video_calls.py@@ -144,7 +144,7 @@ def make_zoom_video_call(request: HttpRequest, user: UserProfile) -> HttpRespons@require_POST@has_request_variablesdef deauthorize_zoom_user(request: HttpRequest) -> HttpResponse:- data = json.loads(request.body.decode("utf-8"))+ data = json.loads(request.body)payload = data["payload"]if payload["user_data_retention"] == "false":requests.post(