home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Bureautique
/
LibreOffice
/
LibreOffice_4.3.5_Win_x86.msi
/
__init__10.py
< prev
next >
Wrap
Text File
|
2014-12-12
|
704b
|
22 lines
"""
General functions for HTML manipulation.
"""
_escape_map = {ord('&'): '&', ord('<'): '<', ord('>'): '>'}
_escape_map_full = {ord('&'): '&', ord('<'): '<', ord('>'): '>',
ord('"'): '"', ord('\''): '''}
# NB: this is a candidate for a bytes/string polymorphic interface
def escape(s, quote=True):
"""
Replace special characters "&", "<" and ">" to HTML-safe sequences.
If the optional flag quote is true (the default), the quotation mark
characters, both double quote (") and single quote (') characters are also
translated.
"""
if quote:
return s.translate(_escape_map_full)
return s.translate(_escape_map)