|
23 | 23 | class SysCallError(Exception): |
24 | 24 | pass |
25 | 25 |
|
| 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 |
| 30 | + |
26 | 31 | from roundup import roundupdb, date, hyperdb, password |
27 | 32 | from roundup.cgi import templating, cgitb, TranslationService |
28 | 33 | from roundup.cgi import actions |
@@ -68,7 +73,7 @@ def initialiseSecurity(security): |
68 | 73 |
|
69 | 74 | def add_message(msg_list, msg, escape=True): |
70 | 75 | if escape: |
71 | | - msg = cgi.escape(msg).replace('\n', '<br />\n') |
| 76 | + msg = html_escape(msg).replace('\n', '<br />\n') |
72 | 77 | else: |
73 | 78 | msg = msg.replace('\n', '<br />\n') |
74 | 79 | msg_list.append (msg) |
@@ -1767,9 +1772,9 @@ def renderContext(self): |
1767 | 1772 | result = result.replace('</body>', s) |
1768 | 1773 | return result |
1769 | 1774 | except templating.NoTemplate as message: |
1770 | | - return '<strong>%s</strong>'%cgi.escape(str(message)) |
| 1775 | + return '<strong>%s</strong>'%html_escape(str(message)) |
1771 | 1776 | except templating.Unauthorised as message: |
1772 | | - raise Unauthorised(cgi.escape(str(message))) |
| 1777 | + raise Unauthorised(html_escape(str(message))) |
1773 | 1778 | except: |
1774 | 1779 | # everything else |
1775 | 1780 | if self.instance.config.WEB_DEBUG: |
@@ -1862,7 +1867,7 @@ def get_action_class(self, action_name): |
1862 | 1867 | if name == action_name: |
1863 | 1868 | break |
1864 | 1869 | else: |
1865 | | - raise ValueError('No such action "%s"'%cgi.escape(action_name)) |
| 1870 | + raise ValueError('No such action "%s"'%html_escape(action_name)) |
1866 | 1871 | return action_klass |
1867 | 1872 |
|
1868 | 1873 | def _socket_op(self, call, *args, **kwargs): |
|
0 commit comments