2016-05-16 11:58:36 +05:30
|
|
|
##########################################################################
|
|
|
|
|
#
|
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
|
#
|
2017-01-04 13:33:32 +00:00
|
|
|
# Copyright (C) 2013 - 2017, The pgAdmin Development Team
|
2016-05-16 11:58:36 +05:30
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
|
#
|
|
|
|
|
#########################################################################
|
|
|
|
|
|
|
|
|
|
"""Utilities for HTML"""
|
|
|
|
|
|
|
|
|
|
import cgi
|
2017-03-07 15:30:57 +05:30
|
|
|
from pgadmin.utils import IS_PY2
|
2016-05-16 11:58:36 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def safe_str(x):
|
2017-03-07 15:30:57 +05:30
|
|
|
try:
|
2017-05-15 13:01:12 +01:00
|
|
|
# For Python2, it can be int, long, float
|
|
|
|
|
if IS_PY2:
|
|
|
|
|
if isinstance(x, (int, long, float)):
|
|
|
|
|
x = str(x)
|
|
|
|
|
else:
|
|
|
|
|
# For Python3, it can be int, float
|
|
|
|
|
if isinstance(x, (int, float)):
|
|
|
|
|
x = str(x)
|
|
|
|
|
|
|
|
|
|
x = x.encode(
|
|
|
|
|
'ascii', 'xmlcharrefreplace'
|
|
|
|
|
) if hasattr(x, 'encode') else x
|
|
|
|
|
|
2017-03-07 15:30:57 +05:30
|
|
|
if not IS_PY2:
|
|
|
|
|
x = x.decode('utf-8')
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
return cgi.escape(x)
|