exceptions.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """
  2. Scrapy core exceptions
  3. These exceptions are documented in docs/topics/exceptions.rst. Please don't add
  4. new exceptions here without documenting them there.
  5. """
  6. # Internal
  7. class NotConfigured(Exception):
  8. """Indicates a missing configuration situation"""
  9. pass
  10. class _InvalidOutput(TypeError):
  11. """
  12. Indicates an invalid value has been returned by a middleware's processing method.
  13. Internal and undocumented, it should not be raised or caught by user code.
  14. """
  15. pass
  16. # HTTP and crawling
  17. class IgnoreRequest(Exception):
  18. """Indicates a decision was made not to process a request"""
  19. class DontCloseSpider(Exception):
  20. """Request the spider not to be closed yet"""
  21. pass
  22. class CloseSpider(Exception):
  23. """Raise this from callbacks to request the spider to be closed"""
  24. def __init__(self, reason='cancelled'):
  25. super(CloseSpider, self).__init__()
  26. self.reason = reason
  27. # Items
  28. class DropItem(Exception):
  29. """Drop item from the item pipeline"""
  30. pass
  31. class NotSupported(Exception):
  32. """Indicates a feature or method is not supported"""
  33. pass
  34. # Commands
  35. class UsageError(Exception):
  36. """To indicate a command-line usage error"""
  37. def __init__(self, *a, **kw):
  38. self.print_help = kw.pop('print_help', True)
  39. super(UsageError, self).__init__(*a, **kw)
  40. class ScrapyDeprecationWarning(Warning):
  41. """Warning category for deprecated features, since the default
  42. DeprecationWarning is silenced on Python 2.7+
  43. """
  44. pass
  45. class ContractFail(AssertionError):
  46. """Error raised in case of a failing contract"""
  47. pass