From bc65baeff7cdbaa730d4dff17a388e0bdb6263e1 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 11 Dec 2017 16:20:00 +1000 Subject: [PATCH] cgi.escape is deprecated --- anki/importing/noteimp.py | 4 ++-- anki/importing/pauker.py | 4 ++-- anki/latex.py | 4 ++-- aqt/browser.py | 4 ++-- aqt/errors.py | 4 ++-- aqt/reviewer.py | 8 ++++---- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/anki/importing/noteimp.py b/anki/importing/noteimp.py index ffbf63de4..bbdc61acd 100644 --- a/anki/importing/noteimp.py +++ b/anki/importing/noteimp.py @@ -2,7 +2,7 @@ # Copyright: Damien Elmes # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import cgi +import html import unicodedata @@ -125,7 +125,7 @@ class NoteImporter(Importer): for n in notes: for c in range(len(n.fields)): if not self.allowHTML: - n.fields[c] = cgi.escape(n.fields[c]) + n.fields[c] = html.escape(n.fields[c]) n.fields[c] = n.fields[c].strip() if not self.allowHTML: n.fields[c] = n.fields[c].replace("\n", "
") diff --git a/anki/importing/pauker.py b/anki/importing/pauker.py index c5f7d45f8..95a1d12d5 100644 --- a/anki/importing/pauker.py +++ b/anki/importing/pauker.py @@ -2,7 +2,7 @@ # Copyright: Andreas Klauer # License: BSD-3 -import gzip, math, random, time, cgi +import gzip, math, random, time, html import xml.etree.ElementTree as ET from anki.importing.noteimp import NoteImporter, ForeignNote, ForeignCard from anki.stdmodels import addForwardReverse @@ -50,7 +50,7 @@ class PaukerImporter(NoteImporter): front = card.findtext('./FrontSide/Text') back = card.findtext('./ReverseSide/Text') note = ForeignNote() - note.fields = [cgi.escape(x.strip()).replace('\n','
').replace(' ','  ') for x in [front,back]] + note.fields = [html.escape(x.strip()).replace('\n','
').replace(' ','  ') for x in [front,back]] notes.append(note) # Determine due date for cards. diff --git a/anki/latex.py b/anki/latex.py index 016a0a2c2..75b9046b6 100644 --- a/anki/latex.py +++ b/anki/latex.py @@ -2,7 +2,7 @@ # Copyright: Damien Elmes # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import re, os, shutil, cgi +import re, os, shutil, html from anki.utils import checksum, call, namedtmp, tmpdir, isMac, stripHTML from anki.hooks import addHook from anki.lang import _ @@ -135,7 +135,7 @@ def _errMsg(type, texpath): log = open(namedtmp("latex_log.txt", rm=False)).read() if not log: raise Exception() - msg += "
" + cgi.escape(log) + "
" + msg += "
" + html.escape(log) + "
" except: msg += _("Have you installed latex and dvipng/dvisvgm?") pass diff --git a/aqt/browser.py b/aqt/browser.py index ddcbc7a4b..1258bdb62 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -3,7 +3,7 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import sre_constants -import cgi +import html import time import re from operator import itemgetter @@ -1740,7 +1740,7 @@ update cards set usn=?, mod=?, did=? where id in """ + scids, t += '''
  • %s: %s''' % ( "nid:" + ",".join(str(id) for id in nids), ngettext("%d note", "%d notes", len(nids)) % len(nids), - cgi.escape(val)) + html.escape(val)) t += "" t += "" web.setHtml(t) diff --git a/aqt/errors.py b/aqt/errors.py index 4f325d8b6..182084a24 100644 --- a/aqt/errors.py +++ b/aqt/errors.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import sys, traceback -import cgi +import html from anki.lang import _ from aqt.qt import * @@ -62,7 +62,7 @@ not able to correct them automatically. Please search for 'temp folder' in the \ Anki manual for more information.""") def onTimeout(self): - error = cgi.escape(self.pool) + error = html.escape(self.pool) self.pool = "" self.mw.progress.clear() if "abortSchemaMod" in error: diff --git a/aqt/reviewer.py b/aqt/reviewer.py index 300300f42..ba1f4def3 100644 --- a/aqt/reviewer.py +++ b/aqt/reviewer.py @@ -4,7 +4,7 @@ import difflib import re -import cgi +import html import unicodedata as ucd import html.parser @@ -416,11 +416,11 @@ Please run Tools>Empty Cards""") "Diff-corrects the typed-in answer." givenElems, correctElems = self.tokenizeComparison(given, correct) def good(s): - return ""+cgi.escape(s)+"" + return ""+html.escape(s)+"" def bad(s): - return ""+cgi.escape(s)+"" + return ""+html.escape(s)+"" def missed(s): - return ""+cgi.escape(s)+"" + return ""+html.escape(s)+"" if given == correct: res = good(given) else: