How to encode html and xml tag datas with standard python modules ?
DurumDara
durumdara at gmail.com
Thu May 11 03:51:15 EDT 2006
Hi !
I probed this function, but that is not encode the hungarian specific
characters, like áéíóüóöőúüű: so the chars above chr(127).
Have the python a function that can encode these chars too, like in Zope ?
Thanx for help:
dd
Fredrik Lundh írta:
> DurumDara wrote:
>
>
>> Have the python standard mod. lib. a html/xml encoder functions/procedures ?
>>
>
> you can use
>
> cgi.escape(s) # escapes < > &
>
> for CDATA sections, and
>
> cgi.escape(s, True) # escapes < > & "
>
> for attributes.
>
> to output ASCII, use
>
> cgi.escape(s).encode("ascii", "xmlcharrefreplace")
> cgi.escape(s, True).encode("ascii", "xmlcharrefreplace")
>
>
>> if b<32 or b>127 or c in ['<','>','"',';','&','@','%','#']:
>> c="&#%03d;"%b
>>
>
> that's a rather odd set of reserved characters...
>
> </F>
>
>
>
>
More information about the Python-list
mailing list