MCPcopy Create free account
hub / github.com/webpy/webpy / websafe

Function websafe

web/net.py:249–268  ·  view source on GitHub ↗

r""" Converts `val` so that it is safe for use in Unicode HTML. >>> websafe("<'&\">") u'&lt;&#39;&amp;&quot;&gt;' >>> websafe(None) u'' >>> websafe(u'\u203d') == u'\u203d' True

(val)

Source from the content-addressed store, hash-verified

247
248
249def websafe(val):
250 r"""
251 Converts `val` so that it is safe for use in Unicode HTML.
252
253 >>> websafe("<'&\">")
254 u'&lt;&#39;&amp;&quot;&gt;'
255 >>> websafe(None)
256 u''
257 >>> websafe(u'\u203d') == u'\u203d'
258 True
259 """
260 if val is None:
261 return ""
262
263 if isinstance(val, bytes):
264 val = val.decode("utf-8")
265 elif not isinstance(val, str):
266 val = str(val)
267
268 return htmlquote(val)
269
270
271if __name__ == "__main__":

Callers 1

recurse_overFunction · 0.90

Calls 2

htmlquoteFunction · 0.85
decodeMethod · 0.80

Tested by

no test coverage detected