annotate libervia_server/html_tools.py @ 411:a0256b81d367

setup.py: update website (it's not http://www.salut-a-toi.org), and removed pyjamas framework which is not standard in pypi
author Goffi <goffi@goffi.org>
date Tue, 18 Mar 2014 19:18:16 +0100
parents ce5b33f499c5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
4 # Libervia: a Salut à Toi frontend
340
ce5b33f499c5 dates update
Goffi <goffi@goffi.org>
parents: 339
diff changeset
5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org>
8
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
7 # This program is free software: you can redistribute it and/or modify
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
10 # (at your option) any later version.
8
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
12 # This program is distributed in the hope that it will be useful,
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
15 # GNU Affero General Public License for more details.
8
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
19
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
20 def sanitizeHtml(text):
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
21 """Sanitize HTML by escaping everything"""
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
22 #this code comes from official python wiki: http://wiki.python.org/moin/EscapingHtml
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
23 html_escape_table = {
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
24 "&": "&amp;",
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
25 '"': "&quot;",
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
26 "'": "&apos;",
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
27 ">": "&gt;",
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
28 "<": "&lt;",
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
29 }
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
30
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
31 return "".join(html_escape_table.get(c,c) for c in text)
88ae360198ee html tools
Goffi <goffi@goffi.org>
parents:
diff changeset
32