# 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 ssl
import sys
    import urllib2 as request
from collections import namedtuple
from os import environ, path
from unittest import TestCase, skipIf
from .http import (
    BadProtocol, HTTPError, Options,
    binquote, http_req, opt_secure__unmodified as opt_secure)
    from urllib import request
        from multiprocessing import Process
        from socket import socket, SHUT_RDWR
        server = self.get_oneshot_server('GET', '502', 'eRrOr')
        try:
            http_req('GET', 'http://localhost:%d/path' % (server.port,))
        except HTTPError as e:
            self.assertTrue(isinstance(e, request.HTTPError))
            self.assertEqual(e.code, 502)
            self.assertDataEqual(e.response, 'eRrOr')
        else:
            self.assertFalse(True)
        server.join()

    def test_exception_str(self):
        server = self.get_oneshot_server('POST', '503', '{"errno":1}')
        url = 'http://localhost:%d/path' % (server.port,)
        try:
            http_req('POST', url, data='{"action":1}')
        except HTTPError as e:
            self.assertTrue(isinstance(e, request.HTTPError))
            error_str = str(e)
            self.assertIn('503', error_str)
            self.assertIn(url, error_str)
            self.assertIn('{"action":1}', error_str)
            self.assertIn('{"errno":1}', error_str)
        else:
            self.assertFalse(True)
        server.join()

    def test_https_only_through_options(self):
        self.assertRaises(
            BadProtocol, http_req,

# 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/http_test.py
import ssl
import sys
    import urllib2 as request
from collections import namedtuple
from os import environ, path
from unittest import TestCase, skipIf
from .http import (
    BadProtocol, HTTPError, Options,
    binquote, http_req, opt_secure__unmodified as opt_secure)
    from urllib import request
        from multiprocessing import Process
        from socket import socket, SHUT_RDWR

        server = self.get_oneshot_server('GET', '502', 'eRrOr')
        try:
            http_req('GET', 'http://localhost:%d/path' % (server.port,))
        except HTTPError as e:
            self.assertTrue(isinstance(e, request.HTTPError))
            self.assertEqual(e.code, 502)
            self.assertDataEqual(e.response, 'eRrOr')
        else:
            self.assertFalse(True)
        server.join()

    def test_exception_str(self):
        server = self.get_oneshot_server('POST', '503', '{"errno":1}')
        url = 'http://localhost:%d/path' % (server.port,)
        try:
            http_req('POST', url, data='{"action":1}')
        except HTTPError as e:
            self.assertTrue(isinstance(e, request.HTTPError))
            error_str = str(e)
            self.assertIn('503', error_str)
            self.assertIn(url, error_str)
            self.assertIn('{"action":1}', error_str)
            self.assertIn('{"errno":1}', error_str)
        else:
            self.assertFalse(True)
        server.join()

    def test_https_only_through_options(self):
        self.assertRaises(
            BadProtocol, http_req,

            'GET', 'http://localhost/path', opt=opt_secure)