1 | #!/usr/bin/env python2
|
2 | from __future__ import print_function
|
3 |
|
4 | import cgi
|
5 | import unittest
|
6 |
|
7 |
|
8 | class FuncsTest(unittest.TestCase):
|
9 |
|
10 | def testHtmlEscape(self):
|
11 | s = '<script>"This" isn\'t right</script>'
|
12 | print(cgi.escape(s))
|
13 |
|
14 | # Hm I think you're supposed to escape ' too
|
15 | print(cgi.escape(s, quote=True))
|
16 |
|
17 | # Python 3 enhanced this to take a dict
|
18 | # https://docs.python.org/3.3/library/stdtypes.html?highlight=maketrans#str.maketrans
|
19 | # We should write our own
|
20 |
|
21 | d = {'<': '<'}
|
22 | #t = string.maketrans(['a', 'b'], ['aa', 'bb'])
|
23 | #print(t)
|
24 |
|
25 |
|
26 | if __name__ == '__main__':
|
27 | unittest.main()
|