Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
xml escapedness
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Robin Becker, post: 3452861"] A colleague has decided to keep his django database string values (which are xml fragments) in an xml escaped form to avoid having the problem of escaping them when they are used in templates etc etc. Unfortunately he found that the normal admin doesn't escape on the way through so thought of adding a standard mechanism to the save methods. However, this brings in the possibility of escaping twice ie once in his original capture code and then in the django save methods. I suggested he could use a subclass of str to represent escaped strings and an escape function which leaves the subclass instances alone so class xmlstr(str): pass from xml.sax.saxutils import escape def xmlEscape(s): if isinstance(s,xmlstr): return s return xmlstr(escape(s)) this works up to a point, but anything which modifies the string reverts to the base class (as it probably should). type(xmlstr('<') + '') is type(str) clearly there are a large number of operations which should be overridden or just hidden to prevent the wrong outcome; has anyone else thought about this in any detail? [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
xml escapedness
Top