Plex plugin to to play various online streams (mostly Latvian).

exceptions.py 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. from __future__ import absolute_import
  2. # Base Exceptions
  3. class HTTPError(Exception):
  4. "Base exception used by this module."
  5. pass
  6. class HTTPWarning(Warning):
  7. "Base warning used by this module."
  8. pass
  9. class PoolError(HTTPError):
  10. "Base exception for errors caused within a pool."
  11. def __init__(self, pool, message):
  12. self.pool = pool
  13. HTTPError.__init__(self, "%s: %s" % (pool, message))
  14. def __reduce__(self):
  15. # For pickling purposes.
  16. return self.__class__, (None, None)
  17. class RequestError(PoolError):
  18. "Base exception for PoolErrors that have associated URLs."
  19. def __init__(self, pool, url, message):
  20. self.url = url
  21. PoolError.__init__(self, pool, message)
  22. def __reduce__(self):
  23. # For pickling purposes.
  24. return self.__class__, (None, self.url, None)
  25. class SSLError(HTTPError):
  26. "Raised when SSL certificate fails in an HTTPS connection."
  27. pass
  28. class ProxyError(HTTPError):
  29. "Raised when the connection to a proxy fails."
  30. pass
  31. class DecodeError(HTTPError):
  32. "Raised when automatic decoding based on Content-Type fails."
  33. pass
  34. class ProtocolError(HTTPError):
  35. "Raised when something unexpected happens mid-request/response."
  36. pass
  37. #: Renamed to ProtocolError but aliased for backwards compatibility.
  38. ConnectionError = ProtocolError
  39. # Leaf Exceptions
  40. class MaxRetryError(RequestError):
  41. """Raised when the maximum number of retries is exceeded.
  42. :param pool: The connection pool
  43. :type pool: :class:`~urllib3.connectionpool.HTTPConnectionPool`
  44. :param string url: The requested Url
  45. :param exceptions.Exception reason: The underlying error
  46. """
  47. def __init__(self, pool, url, reason=None):
  48. self.reason = reason
  49. message = "Max retries exceeded with url: %s (Caused by %r)" % (
  50. url, reason)
  51. RequestError.__init__(self, pool, url, message)
  52. class HostChangedError(RequestError):
  53. "Raised when an existing pool gets a request for a foreign host."
  54. def __init__(self, pool, url, retries=3):
  55. message = "Tried to open a foreign host with url: %s" % url
  56. RequestError.__init__(self, pool, url, message)
  57. self.retries = retries
  58. class TimeoutStateError(HTTPError):
  59. """ Raised when passing an invalid state to a timeout """
  60. pass
  61. class TimeoutError(HTTPError):
  62. """ Raised when a socket timeout error occurs.
  63. Catching this error will catch both :exc:`ReadTimeoutErrors
  64. <ReadTimeoutError>` and :exc:`ConnectTimeoutErrors <ConnectTimeoutError>`.
  65. """
  66. pass
  67. class ReadTimeoutError(TimeoutError, RequestError):
  68. "Raised when a socket timeout occurs while receiving data from a server"
  69. pass
  70. # This timeout error does not have a URL attached and needs to inherit from the
  71. # base HTTPError
  72. class ConnectTimeoutError(TimeoutError):
  73. "Raised when a socket timeout occurs while connecting to a server"
  74. pass
  75. class NewConnectionError(ConnectTimeoutError, PoolError):
  76. "Raised when we fail to establish a new connection. Usually ECONNREFUSED."
  77. pass
  78. class EmptyPoolError(PoolError):
  79. "Raised when a pool runs out of connections and no more are allowed."
  80. pass
  81. class ClosedPoolError(PoolError):
  82. "Raised when a request enters a pool after the pool has been closed."
  83. pass
  84. class LocationValueError(ValueError, HTTPError):
  85. "Raised when there is something wrong with a given URL input."
  86. pass
  87. class LocationParseError(LocationValueError):
  88. "Raised when get_host or similar fails to parse the URL input."
  89. def __init__(self, location):
  90. message = "Failed to parse: %s" % location
  91. HTTPError.__init__(self, message)
  92. self.location = location
  93. class ResponseError(HTTPError):
  94. "Used as a container for an error reason supplied in a MaxRetryError."
  95. GENERIC_ERROR = 'too many error responses'
  96. SPECIFIC_ERROR = 'too many {status_code} error responses'
  97. class SecurityWarning(HTTPWarning):
  98. "Warned when perfoming security reducing actions"
  99. pass
  100. class SubjectAltNameWarning(SecurityWarning):
  101. "Warned when connecting to a host with a certificate missing a SAN."
  102. pass
  103. class InsecureRequestWarning(SecurityWarning):
  104. "Warned when making an unverified HTTPS request."
  105. pass
  106. class SystemTimeWarning(SecurityWarning):
  107. "Warned when system time is suspected to be wrong"
  108. pass
  109. class InsecurePlatformWarning(SecurityWarning):
  110. "Warned when certain SSL configuration is not available on a platform."
  111. pass
  112. class SNIMissingWarning(HTTPWarning):
  113. "Warned when making a HTTPS request without SNI available."
  114. pass
  115. class DependencyWarning(HTTPWarning):
  116. """
  117. Warned when an attempt is made to import a module with missing optional
  118. dependencies.
  119. """
  120. pass
  121. class ResponseNotChunked(ProtocolError, ValueError):
  122. "Response needs to be chunked in order to read it as chunks."
  123. pass
  124. class ProxySchemeUnknown(AssertionError, ValueError):
  125. "ProxyManager does not support the supplied scheme"
  126. # TODO(t-8ch): Stop inheriting from AssertionError in v2.0.
  127. def __init__(self, scheme):
  128. message = "Not supported proxy scheme %s" % scheme
  129. super(ProxySchemeUnknown, self).__init__(message)
  130. class HeaderParsingError(HTTPError):
  131. "Raised by assert_header_parsing, but we convert it to a log.warning statement."
  132. def __init__(self, defects, unparsed_data):
  133. message = '%s, unparsed data: %r' % (defects or 'Unknown', unparsed_data)
  134. super(HeaderParsingError, self).__init__(message)