This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: XML.sax.saxutils.escape -- always escapes <, >, &,
Type: Stage:
Components: Documentation, XML Versions: Python 2.4, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, loewis, msandler, ryan.freckleton
Priority: normal Keywords: easy, patch

Created on 2006-01-21 20:17 by msandler, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
diff msandler, 2006-01-22 15:57 suggested change in _documentation_ to reflect _real_ behavior of the function
sax_utils_rst.patch ryan.freckleton, 2008-01-19 18:53 Patch adding explicit explanation to xml.sax.utils escape and unescape.
Messages (4)
msg49377 - (view) Author: Mark Sandler (msandler) Date: 2006-01-21 20:17
sax.saxutils.escape -- always escapes <, >, &, even
if entities are provided.  

E.g. 
escape("<abcd>", {'a':'\a'}) would produce

"<\abcd%rt;" instead of "<\abcd>"

While it might be expected behaviour, the documentation
states 

"You can escape other strings of data by passing a
dictionary as the optional entities parameter. The keys
and values must all be strings; each key will be
replaced with its corresponding value. "

and it is not at all obvious that entities specify
_additional_ (to <, >, &) escape strings.

It is also impossible to do custom escapes of <,>,&
using saxutils.escape. 
(while custom escapes of < and > might be never
necessary for XML,  the escape function is general
enough to be of interest in other circumstances).





msg49378 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-01-28 12:32
Logged In: YES 
user_id=21627

The behaviour is indeed intentional; reclassifying this as a
patch.
msg60212 - (view) Author: Ryan Freckleton (ryan.freckleton) Date: 2008-01-19 18:53
I've included a unified diff that explicitly states the behavior of &,
<, and > for escape/unescape in the documentation. It's based on
msandler's patch.
msg60228 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-01-19 20:41
Fixed in r60099.
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 42818
2008-01-19 20:41:15georg.brandlsetstatus: open -> closed
nosy: + georg.brandl
resolution: fixed
messages: + msg60228
2008-01-19 18:54:12ryan.freckletonsetcomponents: + Documentation
versions: + Python 2.6
2008-01-19 18:53:26ryan.freckletonsetfiles: + sax_utils_rst.patch
nosy: + ryan.freckleton
messages: + msg60212
2008-01-12 00:53:02akuchlingsetkeywords: + easy
2006-01-21 20:17:14msandlercreate