1# -*- coding: utf-8 -*-
2
3"""
4requests.exceptions
5~~~~~~~~~~~~~~~~~~~
6
7This module contains the set of Requests' exceptions.
8
9"""
10from .packages.urllib3.exceptions import HTTPError as BaseHTTPError
11
12
13class RequestException(IOError):
14    """There was an ambiguous exception that occurred while handling your
15    request."""
16
17    def __init__(self, *args, **kwargs):
18        """
19        Initialize RequestException with `request` and `response` objects.
20        """
21        response = kwargs.pop('response', None)
22        self.response = response
23        self.request = kwargs.pop('request', None)
24        if (response is not None and not self.request and
25                hasattr(response, 'request')):
26            self.request = self.response.request
27        super(RequestException, self).__init__(*args, **kwargs)
28
29
30class HTTPError(RequestException):
31    """An HTTP error occurred."""
32
33
34class ConnectionError(RequestException):
35    """A Connection error occurred."""
36
37
38class ProxyError(ConnectionError):
39    """A proxy error occurred."""
40
41
42class SSLError(ConnectionError):
43    """An SSL error occurred."""
44
45
46class Timeout(RequestException):
47    """The request timed out.
48
49    Catching this error will catch both
50    :exc:`~requests.exceptions.ConnectTimeout` and
51    :exc:`~requests.exceptions.ReadTimeout` errors.
52    """
53
54
55class ConnectTimeout(ConnectionError, Timeout):
56    """The request timed out while trying to connect to the remote server.
57
58    Requests that produced this error are safe to retry.
59    """
60
61
62class ReadTimeout(Timeout):
63    """The server did not send any data in the allotted amount of time."""
64
65
66class URLRequired(RequestException):
67    """A valid URL is required to make a request."""
68
69
70class TooManyRedirects(RequestException):
71    """Too many redirects."""
72
73
74class MissingSchema(RequestException, ValueError):
75    """The URL schema (e.g. http or https) is missing."""
76
77
78class InvalidSchema(RequestException, ValueError):
79    """See defaults.py for valid schemas."""
80
81
82class InvalidURL(RequestException, ValueError):
83    """ The URL provided was somehow invalid. """
84
85
86class ChunkedEncodingError(RequestException):
87    """The server declared chunked encoding but sent an invalid chunk."""
88
89
90class ContentDecodingError(RequestException, BaseHTTPError):
91    """Failed to decode response content"""
92
93
94class StreamConsumedError(RequestException, TypeError):
95    """The content for this response was already consumed"""
96
97
98class RetryError(RequestException):
99    """Custom retries logic failed"""
100
101
102# Warnings
103
104
105class RequestsWarning(Warning):
106    """Base warning for Requests."""
107    pass
108
109
110class FileModeWarning(RequestsWarning, DeprecationWarning):
111    """
112    A file was opened in text mode, but Requests determined its binary length.
113    """
114    pass
115