Example #1
0
 def _escape_attrib(text, encoding=None, replace=etree.string.replace):
     # escape attribute value
     try:
         if encoding:
             try:
                 text = etree._encode(text, encoding)
             except UnicodeError:
                 return etree._encode_entity(text)
         text = replace(text, "&", "&")
         text = replace(text, "\"", """)
         text = replace(text, "<", "&lt;")
         text = replace(text, ">", "&gt;")
         return text
     except (TypeError, AttributeError):
         etree._raise_serialization_error(text)
Example #2
0
def _escape_attrib(text, encoding=None, replace=string.replace):
    # escape attribute value
    try:
        if encoding:
            try:
                text = ET._encode(text, encoding)
            except UnicodeError:
                return ET._encode_entity(text)
        text = replace(text, "&", "&amp;")
        text = replace(text, "'", "&apos;") 
        #text = replace(text, "\"", "&quot;")
        text = replace(text, "<", "&lt;")
        text = replace(text, ">", "&gt;")
        return text
    except (TypeError, AttributeError):
        ET._raise_serialization_error(text)