# 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
        return "Assertion(name=%r, failure_message=%r)" % (self.name, self.failure_message)


class _EventRecorder(object):
    local = threading.local()

    def __init__(self):
        self.log = log.getChild('recorder')
        self.log.debug("Creating recorder")

    def get_recording(self):
        rec = getattr(self.local, 'recording', None)
        if rec is None:
            self.local.recording = []
        return self.local.recording

    def pop_events(self, from_ts, to_ts):
        recording = self.get_recording()
        collected = []
        new_recording = []
        for event in recording:
            if from_ts <= event.timestamp <= to_ts:
                collected.append(event)
            else:
                new_recording.append(event)
        del recording[:]
        recording.extend(new_recording)
        return collected

    def record_event(self, event):

# 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

        return "Assertion(name=%r, failure_message=%r)" % (self.name, self.failure_message)


class _EventRecorder(object):
    local = threading.local()

    def __init__(self):
        self.log = log.getChild('recorder')
        self.log.debug("Creating recorder")

    def get_recording(self):
        rec = getattr(self.local, 'recording', None)
        if rec is None:
            self.local.recording = []
        return self.local.recording

    def pop_events(self, from_ts, to_ts):
        recording = self.get_recording()
        collected = []
        new_recording = []
        for event in recording:
            if from_ts <= event.timestamp <= to_ts:
                collected.append(event)
            else:
                new_recording.append(event)
        del recording[:]
        recording.extend(new_recording)
        return collected

    def record_event(self, event):

        self.log.debug("Recording event %r", event)