# Path: exactonline/http.py
# FALLBACK_CACERT_FILE = '/etc/ssl/certs/ca-certificates.crt'
#     _PROPERTIES = ('protocols', 'verify_cert', 'cacert_file', 'headers')
# def binquote(value):
#     def __init__(self, url, code, msg, hdrs, response, reqmethod, reqdata):
#     def clean_and_trim(value):
#     def get_content_type(self):
#     def format_req(self):
#     def format_resp(self):
#     def __str__(self):
#     def __or__(self, other):
#     def __init__(self, method=None, *args, **kwargs):
#     def get_method(self):
#     def __init__(self, *args, **kwargs):
#     def connect(self):
#     def __init__(self, cacert_file):
#     def https_open(self, req):
# def http_req(method, url, data=None, opt=opt_default, limiter=None):
# def _marshalled(data):
# def _update_ratelimiter_with_exactonline_headers(limiter, headers):
# def _http_request(url, method=None, data=None, opt=None, limiter=None):
# class BadProtocol(ValueError):
# class HTTPError(request.HTTPError):
# class Options(object):
# class Request(request.Request):
# class ValidHTTPSConnection(HTTPConnection):
# class ValidHTTPSHandler(request.HTTPSHandler):
#             class CustomValidHTTPSConnection(ValidHTTPSConnection):


import json
import logging
import os
import sys
from time import sleep, time
from .http import HTTPError, Options, opt_secure, http_req, binquote, urljoin
        # Bring on the fresh stuff. This needs to be called 30 seconds before
        # token expiry. Or after a 401. See the Autorefresh mixin.

        # Build the URLs manually so we get consistent order.
        refresh_params = {
            'client_id': binquote(self.storage.get_client_id()),
            'client_secret': binquote(self.storage.get_client_secret()),
            'grant_type': 'refresh_token',
            'refresh_token': binquote(self.storage.get_refresh_token()),
        }
        refresh_data = ('client_id=%(client_id)s'
                        '&client_secret=%(client_secret)s'
                        '&grant_type=%(grant_type)s'
                        '&refresh_token=%(refresh_token)s' %
                        refresh_params)

        # Fire away!
        url = self.storage.get_refresh_url()
        response = _json_safe(http_req(
            'POST', url, refresh_data, opt=opt_secure, limiter=self.limiter))

        # Validate and store the values.
        self._set_tokens(response)

    def rest(self, request):
        # Don't pass "/api" in the resource, it's in the base URL already!
        # And don't start with a slash either, since we use urljoin on it.
        #
        # See this for a list of possible resources.
        # https://start.exactonline.co.uk/docs/HlpRestAPIResources.aspx

# Path: exactonline/http.py
# FALLBACK_CACERT_FILE = '/etc/ssl/certs/ca-certificates.crt'
#     _PROPERTIES = ('protocols', 'verify_cert', 'cacert_file', 'headers')
# def binquote(value):
#     def __init__(self, url, code, msg, hdrs, response, reqmethod, reqdata):
#     def clean_and_trim(value):
#     def get_content_type(self):
#     def format_req(self):
#     def format_resp(self):
#     def __str__(self):
#     def __or__(self, other):
#     def __init__(self, method=None, *args, **kwargs):
#     def get_method(self):
#     def __init__(self, *args, **kwargs):
#     def connect(self):
#     def __init__(self, cacert_file):
#     def https_open(self, req):
# def http_req(method, url, data=None, opt=opt_default, limiter=None):
# def _marshalled(data):
# def _update_ratelimiter_with_exactonline_headers(limiter, headers):
# def _http_request(url, method=None, data=None, opt=None, limiter=None):
# class BadProtocol(ValueError):
# class HTTPError(request.HTTPError):
# class Options(object):
# class Request(request.Request):
# class ValidHTTPSConnection(HTTPConnection):
# class ValidHTTPSHandler(request.HTTPSHandler):
#             class CustomValidHTTPSConnection(ValidHTTPSConnection):


# Path: exactonline/rawapi.py
import json
import logging
import os
import sys
from time import sleep, time
from .http import HTTPError, Options, opt_secure, http_req, binquote, urljoin

        # Bring on the fresh stuff. This needs to be called 30 seconds before
        # token expiry. Or after a 401. See the Autorefresh mixin.

        # Build the URLs manually so we get consistent order.
        refresh_params = {
            'client_id': binquote(self.storage.get_client_id()),
            'client_secret': binquote(self.storage.get_client_secret()),
            'grant_type': 'refresh_token',
            'refresh_token': binquote(self.storage.get_refresh_token()),
        }
        refresh_data = ('client_id=%(client_id)s'
                        '&client_secret=%(client_secret)s'
                        '&grant_type=%(grant_type)s'
                        '&refresh_token=%(refresh_token)s' %
                        refresh_params)

        # Fire away!
        url = self.storage.get_refresh_url()
        response = _json_safe(http_req(
            'POST', url, refresh_data, opt=opt_secure, limiter=self.limiter))

        # Validate and store the values.
        self._set_tokens(response)

    def rest(self, request):
        # Don't pass "/api" in the resource, it's in the base URL already!
        # And don't start with a slash either, since we use urljoin on it.
        #
        # See this for a list of possible resources.
        # https://start.exactonline.co.uk/docs/HlpRestAPIResources.aspx

        url = urljoin(