mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Add optional 'quote' flag argument to escape(); if true, translate '"'
to '"'.
This commit is contained in:
parent
1e8c8a20f2
commit
64c6620934
1 changed files with 3 additions and 1 deletions
|
@ -1316,12 +1316,14 @@ environment as well. Here are some common variable names:
|
||||||
# Utilities
|
# Utilities
|
||||||
# =========
|
# =========
|
||||||
|
|
||||||
def escape(s):
|
def escape(s, quote=None):
|
||||||
"""Replace special characters '&', '<' and '>' by SGML entities."""
|
"""Replace special characters '&', '<' and '>' by SGML entities."""
|
||||||
import regsub
|
import regsub
|
||||||
s = regsub.gsub("&", "&", s) # Must be done first!
|
s = regsub.gsub("&", "&", s) # Must be done first!
|
||||||
s = regsub.gsub("<", "<", s)
|
s = regsub.gsub("<", "<", s)
|
||||||
s = regsub.gsub(">", ">", s)
|
s = regsub.gsub(">", ">", s)
|
||||||
|
if quote:
|
||||||
|
s = regsub.gsub('"', """, s)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue