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
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("<", "<") except (TypeError, AttributeError): raise_serialization_error(text) return text