Skip to content

Commit 158480f

Browse files
committed
trivia_quiz: Remove Python < 3.4 compatibility code.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 8b3c502 commit 158480f

File tree

2 files changed

+3
-28
lines changed

2 files changed

+3
-28
lines changed

zulip_bots/zulip_bots/bots/trivia_quiz/test_trivia_quiz.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import html
21
import json
32
from typing import Any, Dict, Optional, Tuple
43
from unittest.mock import patch
54

65
from typing_extensions import override
76

87
from zulip_bots.bots.trivia_quiz.trivia_quiz import (
9-
fix_quotes,
108
get_quiz_from_id,
119
get_quiz_from_payload,
1210
handle_answer,
@@ -57,17 +55,6 @@ def test_question_not_available(self) -> None:
5755
with mock_request_exception():
5856
self.verify_reply("new", "Uh-Oh! Trivia service is down.")
5957

60-
def test_fix_quotes(self) -> None:
61-
self.assertEqual(fix_quotes("test &amp; test"), html.unescape("test &amp; test"))
62-
print("f")
63-
with patch("html.unescape") as mock_html_unescape:
64-
mock_html_unescape.side_effect = Exception
65-
with self.assertRaises(Exception) as exception:
66-
fix_quotes("test")
67-
self.assertEqual(
68-
str(exception.exception), "Please use python3.4 or later for this bot."
69-
)
70-
7158
def test_invalid_answer(self) -> None:
7259
invalid_replies = ["answer A", "answer A Q10", "answer Q001 K", "answer 001 A"]
7360
for reply in invalid_replies:

zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
import random
44
import re
5-
from typing import Any, Dict, Optional, Tuple
5+
from typing import Any, Dict, Tuple
66

77
import requests
88

@@ -107,18 +107,6 @@ def get_trivia_payload() -> Dict[str, Any]:
107107
return payload
108108

109109

110-
def fix_quotes(s: str) -> Optional[str]:
111-
# opentdb is nice enough to escape HTML for us, but
112-
# we are sending this to code that does that already :)
113-
#
114-
# Meanwhile Python took until version 3.4 to have a
115-
# simple html.unescape function.
116-
try:
117-
return html.unescape(s)
118-
except Exception:
119-
raise Exception("Please use python3.4 or later for this bot.")
120-
121-
122110
def get_quiz_from_payload(payload: Dict[str, Any]) -> Dict[str, Any]:
123111
result = payload["results"][0]
124112
question = result["question"]
@@ -129,9 +117,9 @@ def get_quiz_from_payload(payload: Dict[str, Any]) -> Dict[str, Any]:
129117
answers[correct_letter] = result["correct_answer"]
130118
for i in range(3):
131119
answers[letters[i + 1]] = result["incorrect_answers"][i]
132-
answers = {letter: fix_quotes(answer) for letter, answer in answers.items()}
120+
answers = {letter: html.unescape(answer) for letter, answer in answers.items()}
133121
quiz: Dict[str, Any] = dict(
134-
question=fix_quotes(question),
122+
question=html.unescape(question),
135123
answers=answers,
136124
answered_options=[],
137125
pending=True,

0 commit comments

Comments
 (0)