安全地向html/xml标记添加不受信任的字符串。
MarkupSafe的Python项目详细描述
markupsafe实现了一个文本对象,它可以转义字符,因此 在HTML和XML中使用是安全的。有特殊含义的字符是 替换为显示为实际字符。这减轻了 注入攻击,意味着可以安全地显示不受信任的用户输入 在一页纸上。
示例
>>> frommarkupsafeimportMarkup,escape>>> # escape replaces special characters and wraps in Markup>>> escape('<script>alert(document.cookie);</script>')Markup(u'<script>alert(document.cookie);</script>') >>> # wrap in Markup to mark text "safe" and prevent escaping>>> Markup('<strong>Hello</strong>')Markup('<strong>hello</strong>') >>> escape(Markup('<strong>Hello</strong>'))Markup('<strong>hello</strong>') >>> # Markup is a text subclass (str on Python 3, unicode on Python 2)>>> # methods and operators escape their arguments>>> template=Markup("Hello <em>%s</em>")>>> template%'"World"'Markup('Hello <em>"World"</em>')
捐赠
托盘组织开发并支持MarkupSafe和其他 使用它的库。为了发展贡献者的社区 和用户,并允许维护人员将更多的时间用于 项目,please donate today。