# 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
        self.test_suite = self.controller.current_sample.test_suite

    def __enter__(self):
        self.controller.set_start_time()

        super(smart_transaction, self).__enter__()
        put_into_thread_store(test_case=self.name, test_suite=self.test_suite)
        for func in apiritif.get_transaction_handlers()["enter"]:
            func()

    def __exit__(self, exc_type, exc_val, exc_tb):
        super(smart_transaction, self).__exit__(exc_type, exc_val, exc_tb)

        message = ''

        if exc_type:
            message = str(exc_val)
            exc = exc_type, exc_val, exc_tb
            if isinstance(exc_val, AssertionError):
                status = 'failed'
                self.controller.addFailure(exc, is_transaction=True)
            else:
                status = 'broken'
                tb = get_trace(exc)
                self.controller.addError(exc_type.__name__, message, tb, is_transaction=True)

        else:
            status = 'success'
            self.controller.addSuccess(is_transaction=True)


# 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

        self.test_suite = self.controller.current_sample.test_suite

    def __enter__(self):
        self.controller.set_start_time()

        super(smart_transaction, self).__enter__()
        put_into_thread_store(test_case=self.name, test_suite=self.test_suite)
        for func in apiritif.get_transaction_handlers()["enter"]:
            func()

    def __exit__(self, exc_type, exc_val, exc_tb):
        super(smart_transaction, self).__exit__(exc_type, exc_val, exc_tb)

        message = ''

        if exc_type:
            message = str(exc_val)
            exc = exc_type, exc_val, exc_tb
            if isinstance(exc_val, AssertionError):
                status = 'failed'
                self.controller.addFailure(exc, is_transaction=True)
            else:
                status = 'broken'
                tb = get_trace(exc)
                self.controller.addError(exc_type.__name__, message, tb, is_transaction=True)

        else:
            status = 'success'
            self.controller.addSuccess(is_transaction=True)


        put_into_thread_store(status=status, message=message)