exceptions.py 951 B

12345678910111213141516171819202122232425262728
  1. """Exceptions defined by Beautiful Soup itself."""
  2. from typing import Union
  3. class StopParsing(Exception):
  4. """Exception raised by a TreeBuilder if it's unable to continue parsing."""
  5. class FeatureNotFound(ValueError):
  6. """Exception raised by the BeautifulSoup constructor if no parser with the
  7. requested features is found.
  8. """
  9. class ParserRejectedMarkup(Exception):
  10. """An Exception to be raised when the underlying parser simply
  11. refuses to parse the given markup.
  12. """
  13. def __init__(self, message_or_exception: Union[str, Exception]):
  14. """Explain why the parser rejected the given markup, either
  15. with a textual explanation or another exception.
  16. """
  17. if isinstance(message_or_exception, Exception):
  18. e = message_or_exception
  19. message_or_exception = "%s: %s" % (e.__class__.__name__, str(e))
  20. super(ParserRejectedMarkup, self).__init__(message_or_exception)