Пример #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_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
Пример #3
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("&", "&amp;")
         text = text.replace("\"", "&quot;")
     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
Пример #5
0
def test_encode_entity():
    """TODO: do a more complete set of tests"""
    assert encode_entity("my text") == "my text"
    expected = "1 is &gt; 0 &amp;&amp; 2 &lt; 3"
    assert encode_entity("1 is > 0 && 2 < 3") == expected