# Path: apiritif/ssl_adapter.py
# class SSLAdapter(HTTPAdapter):
#     def __init__(self, *args, **kwargs):
#         certificate_file_path = kwargs.pop('certificate_file_path', None)
#         passphrase = kwargs.pop('passphrase', None)
# 
#         pkcs12_obj = CertificateReader.create_pkcs12_obj(certificate_file_path, passphrase)
#         self.ssl_context = CertificateReader.create_ssl_context(pkcs12_obj)
# 
#         super(SSLAdapter, self).__init__(*args, **kwargs)
# 
#     def init_poolmanager(self, *args, **kwargs):
#         if self.ssl_context:
#             kwargs['ssl_context'] = self.ssl_context
#         return super(SSLAdapter, self).init_poolmanager(*args, **kwargs)
# 
#     def proxy_manager_for(self, *args, **kwargs):
#         if self.ssl_context:
#             kwargs['ssl_context'] = self.ssl_context
#         return super(SSLAdapter, self).proxy_manager_for(*args, **kwargs)
# 
# Path: apiritif/thread.py
# def get_from_thread_store(names=None):
#     if names and hasattr(_thread_local, "kwargs"):
#         only_one = False
#         if isinstance(names, str):
#             names = [names]
#             only_one = True
#         kwargs = [_thread_local.kwargs.get(key) for key in names]
#         if only_one:
#             return kwargs[0]
#         else:
#             return kwargs
# 
#     elif hasattr(_thread_local, "args"):
#         return _thread_local.args
# 
# def put_into_thread_store(*args, **kwargs):
#     if args:
#         _thread_local.args = args
#     if kwargs:
#         current_kwargs = getattr(_thread_local, "kwargs", {})
#         current_kwargs.update(kwargs)
#         _thread_local.kwargs = current_kwargs
# 
# Path: apiritif/utils.py
# VERSION = "1.1.3"
# def get_trace(error):
# def graceful():
# def headers_as_text(headers_dict):
# def shorten(string, upto, end_with="..."):
# def assert_regexp(regex, text, match=False, msg=None):
# def assert_not_regexp(regex, text, match=False, msg=None):
# class NormalShutdown(BaseException):


import copy
import os
import threading
import time
import requests
import apiritif
from functools import wraps
from io import BytesIO
from jsonpath_ng.ext import parse as jsonpath_parse
from lxml import etree, html
from requests.structures import CaseInsensitiveDict
from apiritif.ssl_adapter import SSLAdapter
from apiritif.thread import get_from_thread_store, put_into_thread_store
from apiritif.utilities import *
from apiritif.utils import headers_as_text, assert_regexp, assert_not_regexp, log, get_trace, NormalShutdown, graceful

    @staticmethod
    def target(*args, **kwargs):
        return HTTPTarget(*args, **kwargs)

    @staticmethod
    def request(method, address, session=None,
                params=None, headers=None, cookies=None, data=None, json=None, files=None,
                encrypted_cert=None, allow_redirects=True, timeout=30):
        """

        :param method: str
        :param address: str
        :return: response
        :rtype: HTTPResponse
        """
        http.log.info("Request: %s %s", method, address)
        msg = "Request: params=%r, headers=%r, cookies=%r, data=%r, json=%r, files=%r, allow_redirects=%r, timeout=%r"
        http.log.debug(msg, params, headers, cookies, data, json, files, allow_redirects, timeout)

        if headers is None:
            headers = {}
        if "User-Agent" not in headers:
            headers["User-Agent"] = "Apiritif"

        if session is None:
            session = requests.Session()

        if encrypted_cert is not None:
            certificate_file_path, passphrase = encrypted_cert

# Path: apiritif/ssl_adapter.py
# class SSLAdapter(HTTPAdapter):
#     def __init__(self, *args, **kwargs):
#         certificate_file_path = kwargs.pop('certificate_file_path', None)
#         passphrase = kwargs.pop('passphrase', None)
# 
#         pkcs12_obj = CertificateReader.create_pkcs12_obj(certificate_file_path, passphrase)
#         self.ssl_context = CertificateReader.create_ssl_context(pkcs12_obj)
# 
#         super(SSLAdapter, self).__init__(*args, **kwargs)
# 
#     def init_poolmanager(self, *args, **kwargs):
#         if self.ssl_context:
#             kwargs['ssl_context'] = self.ssl_context
#         return super(SSLAdapter, self).init_poolmanager(*args, **kwargs)
# 
#     def proxy_manager_for(self, *args, **kwargs):
#         if self.ssl_context:
#             kwargs['ssl_context'] = self.ssl_context
#         return super(SSLAdapter, self).proxy_manager_for(*args, **kwargs)
# 
# Path: apiritif/thread.py
# def get_from_thread_store(names=None):
#     if names and hasattr(_thread_local, "kwargs"):
#         only_one = False
#         if isinstance(names, str):
#             names = [names]
#             only_one = True
#         kwargs = [_thread_local.kwargs.get(key) for key in names]
#         if only_one:
#             return kwargs[0]
#         else:
#             return kwargs
# 
#     elif hasattr(_thread_local, "args"):
#         return _thread_local.args
# 
# def put_into_thread_store(*args, **kwargs):
#     if args:
#         _thread_local.args = args
#     if kwargs:
#         current_kwargs = getattr(_thread_local, "kwargs", {})
#         current_kwargs.update(kwargs)
#         _thread_local.kwargs = current_kwargs
# 
# Path: apiritif/utils.py
# VERSION = "1.1.3"
# def get_trace(error):
# def graceful():
# def headers_as_text(headers_dict):
# def shorten(string, upto, end_with="..."):
# def assert_regexp(regex, text, match=False, msg=None):
# def assert_not_regexp(regex, text, match=False, msg=None):
# class NormalShutdown(BaseException):


# Path: apiritif/http.py
import copy
import os
import threading
import time
import requests
import apiritif
from functools import wraps
from io import BytesIO
from jsonpath_ng.ext import parse as jsonpath_parse
from lxml import etree, html
from requests.structures import CaseInsensitiveDict
from apiritif.ssl_adapter import SSLAdapter
from apiritif.thread import get_from_thread_store, put_into_thread_store
from apiritif.utilities import *
from apiritif.utils import headers_as_text, assert_regexp, assert_not_regexp, log, get_trace, NormalShutdown, graceful


    @staticmethod
    def target(*args, **kwargs):
        return HTTPTarget(*args, **kwargs)

    @staticmethod
    def request(method, address, session=None,
                params=None, headers=None, cookies=None, data=None, json=None, files=None,
                encrypted_cert=None, allow_redirects=True, timeout=30):
        """

        :param method: str
        :param address: str
        :return: response
        :rtype: HTTPResponse
        """
        http.log.info("Request: %s %s", method, address)
        msg = "Request: params=%r, headers=%r, cookies=%r, data=%r, json=%r, files=%r, allow_redirects=%r, timeout=%r"
        http.log.debug(msg, params, headers, cookies, data, json, files, allow_redirects, timeout)

        if headers is None:
            headers = {}
        if "User-Agent" not in headers:
            headers["User-Agent"] = "Apiritif"

        if session is None:
            session = requests.Session()

        if encrypted_cert is not None:
            certificate_file_path, passphrase = encrypted_cert

            adapter = SSLAdapter(certificate_file_path=certificate_file_path, passphrase=passphrase)