示例#1
0
 def escape_attrib(text, encoding=None, entity_map=None):
     """Escape attribute value."""
     try:
         if encoding:
             try:
                 text = text.encode(encoding)
             except UnicodeError:
                 return encode_entity(text, entities=entity_map)
         text = text.replace("&", "&")
         text = text.replace("\"", """)
     except (TypeError, AttributeError):
         raise_serialization_error(text)
     return text
示例#2
0
 def escape_attrib(text, encoding=None, entity_map=None):
     """Escape attribute value."""
     try:
         if encoding:
             try:
                 text = text.encode(encoding)
             except UnicodeError:
                 return encode_entity(text, entities=entity_map)
         text = text.replace("&", "&")
         text = text.replace("\"", """)
     except (TypeError, AttributeError):
         raise_serialization_error(text)
     return text
示例#3
0
 def escape_cdata(text, encoding=None, entity_map=None):
     """Escape character data."""
     try:
         if encoding:
             try:
                 text = text.encode(encoding)
             except UnicodeError:
                 return encode_entity(text, entities=entity_map)
         text = text.replace("&", "&")
         text = text.replace("<", "&lt;")
     except (TypeError, AttributeError):
         raise_serialization_error(text)
     return text
示例#4
0
 def escape_cdata(text, encoding=None, entity_map=None):
     """Escape character data."""
     try:
         if encoding:
             try:
                 text = text.encode(encoding)
             except UnicodeError:
                 return encode_entity(text, entities=entity_map)
         text = text.replace("&", "&amp;")
         text = text.replace("<", "&lt;")
     except (TypeError, AttributeError):
         raise_serialization_error(text)
     return text