Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

29 linhas
930 B

  1. """
  2. Utilities for XML generation/parsing.
  3. """
  4. import re
  5. from xml.sax.saxutils import XMLGenerator
  6. class UnserializableContentError(ValueError):
  7. pass
  8. class SimplerXMLGenerator(XMLGenerator):
  9. def addQuickElement(self, name, contents=None, attrs=None):
  10. "Convenience method for adding an element with no children"
  11. if attrs is None:
  12. attrs = {}
  13. self.startElement(name, attrs)
  14. if contents is not None:
  15. self.characters(contents)
  16. self.endElement(name)
  17. def characters(self, content):
  18. if content and re.search(r'[\x00-\x08\x0B-\x0C\x0E-\x1F]', content):
  19. # Fail loudly when content has control chars (unsupported in XML 1.0)
  20. # See http://www.w3.org/International/questions/qa-controls
  21. raise UnserializableContentError("Control characters are not supported in XML 1.0")
  22. XMLGenerator.characters(self, content)