11cb0ef41Sopenharmony_ci# -*- coding: utf-8 -*- 21cb0ef41Sopenharmony_ci""" 31cb0ef41Sopenharmony_ci markupsafe._native 41cb0ef41Sopenharmony_ci ~~~~~~~~~~~~~~~~~~ 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci Native Python implementation the C module is not compiled. 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci :copyright: (c) 2010 by Armin Ronacher. 91cb0ef41Sopenharmony_ci :license: BSD, see LICENSE for more details. 101cb0ef41Sopenharmony_ci""" 111cb0ef41Sopenharmony_cifrom markupsafe import Markup 121cb0ef41Sopenharmony_cifrom markupsafe._compat import text_type 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cidef escape(s): 161cb0ef41Sopenharmony_ci """Convert the characters &, <, >, ' and " in string s to HTML-safe 171cb0ef41Sopenharmony_ci sequences. Use this if you need to display text that might contain 181cb0ef41Sopenharmony_ci such characters in HTML. Marks return value as markup string. 191cb0ef41Sopenharmony_ci """ 201cb0ef41Sopenharmony_ci if hasattr(s, '__html__'): 211cb0ef41Sopenharmony_ci return s.__html__() 221cb0ef41Sopenharmony_ci return Markup(text_type(s) 231cb0ef41Sopenharmony_ci .replace('&', '&') 241cb0ef41Sopenharmony_ci .replace('>', '>') 251cb0ef41Sopenharmony_ci .replace('<', '<') 261cb0ef41Sopenharmony_ci .replace("'", ''') 271cb0ef41Sopenharmony_ci .replace('"', '"') 281cb0ef41Sopenharmony_ci ) 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_cidef escape_silent(s): 321cb0ef41Sopenharmony_ci """Like :func:`escape` but converts `None` into an empty 331cb0ef41Sopenharmony_ci markup string. 341cb0ef41Sopenharmony_ci """ 351cb0ef41Sopenharmony_ci if s is None: 361cb0ef41Sopenharmony_ci return Markup() 371cb0ef41Sopenharmony_ci return escape(s) 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_cidef soft_unicode(s): 411cb0ef41Sopenharmony_ci """Make a string unicode if it isn't already. That way a markup 421cb0ef41Sopenharmony_ci string is not converted back to unicode. 431cb0ef41Sopenharmony_ci """ 441cb0ef41Sopenharmony_ci if not isinstance(s, text_type): 451cb0ef41Sopenharmony_ci s = text_type(s) 461cb0ef41Sopenharmony_ci return s 47