Skip to content

Commit 4dcc57e

Browse files
committed
Fix problem with cgi.escape being depricated a different way. This way
uses anypy and is cleaner. Also fixes incorrect/incomplete change that resulted in escaped in TAL generated by TALInterpreter.py. The escaped quotes break javascript etc. defined using tal string: values. TODO: add test cases for TAL. This wouldn't have snuck through for a month if we had good coverage of that library.
1 parent 834e04d commit 4dcc57e

File tree

13 files changed

+21
-46
lines changed

13 files changed

+21
-46
lines changed

roundup/anypy/html.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
try:
2+
from html import escape as html_escape_ # python 3
3+
def html_escape(str, quote=False):
4+
# html_escape under python 3 sets quote to true by default
5+
# make it python 2 compatible
6+
return html_escape_(str, quote=quote)
7+
except ImportError:
8+
from cgi import escape as html_escape # python 2 fallback

roundup/backends/sessions_dbm.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
import os, marshal, time
1010

11-
try:
12-
from html import escape
13-
except ImportError:
14-
from cgi import escape
11+
from roundup.anypy.html import html_escape as escape
1512

1613
from roundup import hyperdb
1714
from roundup.i18n import _

roundup/backends/sessions_rdbms.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
__docformat__ = 'restructuredtext'
88
import os, time, logging
99

10-
try:
11-
from html import escape
12-
except ImportError:
13-
from cgi import escape
10+
from roundup.anypy.html import html_escape as escape
1411

1512
class BasicDatabase:
1613
''' Provide a nice encapsulation of an RDBMS table.

roundup/cgi/PageTemplates/TALES.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ def getInfo(self, as_html=0):
283283
if not as_html:
284284
return ' - Names:\n %s' % s.replace('\n', '\n ')
285285
else:
286-
from cgi import escape
287-
return '<b>Names:</b><pre>%s</pre>' % (escape(s))
286+
from roundup.anypy.html import html_escape
287+
return '<b>Names:</b><pre>%s</pre>' % (html_escape(s))
288288

289289

290290
class SimpleExpr:

roundup/cgi/TAL/TALGenerator.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
from .TALDefs import parseSubstitution
2626
from .TranslationContext import TranslationContext, DEFAULT_DOMAIN
2727

28-
try:
29-
from html import escape as html_escape # python 3
30-
except ImportError:
31-
from cgi import escape as html_escape # python 2 fallback
28+
from roundup.anypy.html import html_escape
3229

3330
I18N_REPLACE = 1
3431
I18N_CONTENT = 2

roundup/cgi/TAL/TALInterpreter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121
import getopt
2222
import re
2323

24-
try:
25-
from html import escape
26-
except ImportError:
27-
from cgi import escape
2824

25+
from roundup.anypy.html import html_escape as escape
2926
from roundup.anypy.strings import StringIO
3027
#from DocumentTemplate.DT_Util import ustr
3128
ustr = str

roundup/cgi/actions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
from roundup.anypy.strings import StringIO
1212
import roundup.anypy.random_ as random_
1313

14-
try:
15-
from html import escape as html_escape # python 3
16-
except ImportError:
17-
from cgi import escape as html_escape # python 2 fallback
14+
from roundup.anypy.html import html_escape
1815

1916
import time
2017
from datetime import timedelta

roundup/cgi/cgitb.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
import sys, os, keyword, linecache, tokenize, inspect, cgi
1111
import pydoc, traceback
1212

13-
try:
14-
from html import escape as html_escape # python 3
15-
except ImportError:
16-
from cgi import escape as html_escape # python 2 fallback
13+
from roundup.anypy.html import html_escape
1714

1815
from roundup.cgi import templating, TranslationService
1916
from roundup.anypy.strings import s2b

roundup/cgi/client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
class SysCallError(Exception):
2424
pass
2525

26-
try:
27-
from html import escape as html_escape # python 3
28-
except ImportError:
29-
from cgi import escape as html_escape # python 2 fallback
26+
from roundup.anypy.html import html_escape
3027

3128
from roundup import roundupdb, date, hyperdb, password
3229
from roundup.cgi import templating, cgitb, TranslationService

roundup/cgi/exceptions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66
from roundup.exceptions import LoginError, Unauthorised
77

8-
try:
9-
from html import escape as html_escape # python 3
10-
except ImportError:
11-
from cgi import escape as html_escape # python 2 fallback
8+
from roundup.anypy.html import html_escape
129

1310
class HTTPException(BaseException):
1411
pass

0 commit comments

Comments
 (0)