You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.8 KiB

4 years ago
  1. # defusedxml
  2. #
  3. # Copyright (c) 2013 by Christian Heimes <christian@python.org>
  4. # Licensed to PSF under a Contributor Agreement.
  5. # See http://www.python.org/psf/license for licensing details.
  6. """Defused xml.dom.minidom
  7. """
  8. from __future__ import print_function, absolute_import
  9. from xml.dom.minidom import _do_pulldom_parse
  10. from . import expatbuilder as _expatbuilder
  11. from . import pulldom as _pulldom
  12. __origin__ = "xml.dom.minidom"
  13. def parse(file, parser=None, bufsize=None, forbid_dtd=False,
  14. forbid_entities=True, forbid_external=True):
  15. """Parse a file into a DOM by filename or file object."""
  16. if parser is None and not bufsize:
  17. return _expatbuilder.parse(file, forbid_dtd=forbid_dtd,
  18. forbid_entities=forbid_entities,
  19. forbid_external=forbid_external)
  20. else:
  21. return _do_pulldom_parse(_pulldom.parse, (file,),
  22. {'parser': parser, 'bufsize': bufsize,
  23. 'forbid_dtd': forbid_dtd, 'forbid_entities': forbid_entities,
  24. 'forbid_external': forbid_external})
  25. def parseString(string, parser=None, forbid_dtd=False,
  26. forbid_entities=True, forbid_external=True):
  27. """Parse a file into a DOM from a string."""
  28. if parser is None:
  29. return _expatbuilder.parseString(string, forbid_dtd=forbid_dtd,
  30. forbid_entities=forbid_entities,
  31. forbid_external=forbid_external)
  32. else:
  33. return _do_pulldom_parse(_pulldom.parseString, (string,),
  34. {'parser': parser, 'forbid_dtd': forbid_dtd,
  35. 'forbid_entities': forbid_entities,
  36. 'forbid_external': forbid_external})