# Path: py3status/exceptions.py
# class RequestTimeout(RequestException):
#     """
#     A timeout has occurred during a request made via Py3.request().
#     """
# 
# class RequestURLError(RequestException):
#     """
#     A URL related error has occurred during a request made via Py3.request().
#     """
# 
# class RequestInvalidJSON(RequestException):
#     """
#     The request has not returned valid JSON
#     """


import base64
import json
import socket
from urllib.error import URLError, HTTPError
from urllib.parse import urlsplit, urlunsplit, parse_qsl, urlencode
from urllib.request import (
    urlopen,
    Request,
    build_opener,
    install_opener,
    HTTPCookieProcessor,
)
from py3status.exceptions import RequestTimeout, RequestURLError, RequestInvalidJSON
            auth_str = base64.b64encode(("%s:%s" % auth).encode("utf-8"))
            headers["Authorization"] = "Basic %s" % auth_str.decode("utf-8")
        if data:
            data = urlencode(data).encode()
        if cookiejar is not None:
            self._cookiejar = cookiejar
            opener = build_opener(HTTPCookieProcessor(cookiejar))
            install_opener(opener)

        request = Request(url, headers=headers)

        try:
            self._response = urlopen(request, data=data, timeout=timeout)
            self._error_message = None
        except URLError as e:
            reason = e.reason
            if isinstance(reason, socket.timeout):
                raise RequestTimeout("request timed out")
            elif isinstance(e, HTTPError):
                self._status_code = e.code
                self._error_message = reason
                # we return an HttpResponse but have no response
                # so create some 'fake' response data.
                self._text = ""
                self._json = {}
                self._headers = []
            else:
                # unknown exception, so just raise it
                raise RequestURLError(reason)
        except socket.timeout:

# Path: py3status/exceptions.py
# class RequestTimeout(RequestException):
#     """
#     A timeout has occurred during a request made via Py3.request().
#     """
# 
# class RequestURLError(RequestException):
#     """
#     A URL related error has occurred during a request made via Py3.request().
#     """
# 
# class RequestInvalidJSON(RequestException):
#     """
#     The request has not returned valid JSON
#     """


# Path: py3status/request.py
import base64
import json
import socket
from urllib.error import URLError, HTTPError
from urllib.parse import urlsplit, urlunsplit, parse_qsl, urlencode
from urllib.request import (
    urlopen,
    Request,
    build_opener,
    install_opener,
    HTTPCookieProcessor,
)
from py3status.exceptions import RequestTimeout, RequestURLError, RequestInvalidJSON

            auth_str = base64.b64encode(("%s:%s" % auth).encode("utf-8"))
            headers["Authorization"] = "Basic %s" % auth_str.decode("utf-8")
        if data:
            data = urlencode(data).encode()
        if cookiejar is not None:
            self._cookiejar = cookiejar
            opener = build_opener(HTTPCookieProcessor(cookiejar))
            install_opener(opener)

        request = Request(url, headers=headers)

        try:
            self._response = urlopen(request, data=data, timeout=timeout)
            self._error_message = None
        except URLError as e:
            reason = e.reason
            if isinstance(reason, socket.timeout):
                raise RequestTimeout("request timed out")
            elif isinstance(e, HTTPError):
                self._status_code = e.code
                self._error_message = reason
                # we return an HttpResponse but have no response
                # so create some 'fake' response data.
                self._text = ""
                self._json = {}
                self._headers = []
            else:
                # unknown exception, so just raise it
                raise RequestURLError(reason)
        except socket.timeout:

            raise RequestTimeout("request timed out")