-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Open
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
Proposed Feature: Add escape_attr function to xml.sax.saxutils
Problem
Currently, developers need to choose between:
escape()- doesn't handle quotes (for text content)quoteattr()- adds quoting and escaping (for attributes)
Sometimes we need just escaping for attributes without the automatic quoting.
Solution
Add escape_attr() function that escapes all XML special characters including quotes, but doesn't add the outer quotes.
Benefits
- Cleaner API for attribute value escaping
- Maintains backward compatibility
- Consistent with existing saxutils design
def escape_attr(data):
"""Escape string for use in XML attributes, including quotes.
This is a convenience function that escapes all special characters
required for XML attributes, including both single and double quotes.
"""
return escape(data, entities={'"': """, "'": "'"})Note in escape function:
"""
Note: This function is intended for escaping text content, not attributes.
For attributes, use quoteattr() or escape_attr().
"""Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Metadata
Metadata
Assignees
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-featureA feature request or enhancementA feature request or enhancement