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, "<", "<") text = replace(text, ">", ">") return text except (TypeError, AttributeError): etree._raise_serialization_error(text)
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, "&", "&") text = replace(text, "'", "'") #text = replace(text, "\"", """) text = replace(text, "<", "<") text = replace(text, ">", ">") return text except (TypeError, AttributeError): ET._raise_serialization_error(text)