2016-05-16 11:58:36 +05:30
|
|
|
##########################################################################
|
|
|
|
|
#
|
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
|
#
|
2022-01-04 13:54:25 +05:30
|
|
|
# Copyright (C) 2013 - 2022, The pgAdmin Development Team
|
2016-05-16 11:58:36 +05:30
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
|
#
|
|
|
|
|
#########################################################################
|
|
|
|
|
|
|
|
|
|
"""Utilities for HTML"""
|
|
|
|
|
|
2020-04-30 17:22:48 +05:30
|
|
|
from html import escape as html_escape
|
2020-02-18 12:10:38 +05:30
|
|
|
|
2016-05-16 11:58:36 +05:30
|
|
|
|
|
|
|
|
def safe_str(x):
|
2017-03-07 15:30:57 +05:30
|
|
|
try:
|
2020-04-30 17:22:48 +05:30
|
|
|
# For Python3, it can be int, float
|
|
|
|
|
if isinstance(x, (int, float)):
|
|
|
|
|
x = str(x)
|
2017-05-15 13:01:12 +01:00
|
|
|
|
|
|
|
|
x = x.encode(
|
|
|
|
|
'ascii', 'xmlcharrefreplace'
|
|
|
|
|
) if hasattr(x, 'encode') else x
|
|
|
|
|
|
2020-04-30 17:22:48 +05:30
|
|
|
x = x.decode('utf-8')
|
2018-01-31 13:58:55 +00:00
|
|
|
except Exception:
|
2017-03-07 15:30:57 +05:30
|
|
|
pass
|
2020-02-18 12:10:38 +05:30
|
|
|
return html_escape(x, False)
|