# Path: mastermind/driver.py
# class Driver:
#     def storage(self, storage_path):
#     def root(self, base_path):
#     def start(self, name):
#     def stop(self):
#     def state(self):
# def register(context):
# def index(path):
# def pid_number():
# def state():
# def stop_driver():
# def start_driver(ruleset):
# def exceptions(ruleset):
# 
# Path: mastermind/say.py
# def level(x):


import time
import yaml
from mitmproxy.models import decoded, Headers
from . import (http, rules, validator)
from .driver import driver
from .say import logger
            rules.process_headers('request',
                                  rule,
                                  flow.request.headers)


def response(context, flow):
    if driver.name:
        rule = flow.mastermind['rule']
        if rule:
            delay = rules.delay(rule)
            if delay:
                time.sleep(delay)

            with decoded(flow.response):
                status_code = rules.status_code(rule)
                body_filename = rules.body_filename(rule)
                schema = rules.schema(rule,
                                      context.source_dir)

                if status_code:
                    status_message = http.status_message(status_code)

                    flow.response.status_code = status_code
                    flow.response.msg = status_message

                if schema:
                    table = driver.db.table(flow.request.url)
                    res = yaml.safe_load(flow.response.content)
                    schema_result = validator.check(res, schema)
                    table.insert_multiple(schema_result)

# Path: mastermind/driver.py
# class Driver:
#     def storage(self, storage_path):
#     def root(self, base_path):
#     def start(self, name):
#     def stop(self):
#     def state(self):
# def register(context):
# def index(path):
# def pid_number():
# def state():
# def stop_driver():
# def start_driver(ruleset):
# def exceptions(ruleset):
# 
# Path: mastermind/say.py
# def level(x):


# Path: mastermind/handlers.py
import time
import yaml
from mitmproxy.models import decoded, Headers
from . import (http, rules, validator)
from .driver import driver
from .say import logger

            rules.process_headers('request',
                                  rule,
                                  flow.request.headers)


def response(context, flow):
    if driver.name:
        rule = flow.mastermind['rule']
        if rule:
            delay = rules.delay(rule)
            if delay:
                time.sleep(delay)

            with decoded(flow.response):
                status_code = rules.status_code(rule)
                body_filename = rules.body_filename(rule)
                schema = rules.schema(rule,
                                      context.source_dir)

                if status_code:
                    status_message = http.status_message(status_code)

                    flow.response.status_code = status_code
                    flow.response.msg = status_message

                if schema:
                    table = driver.db.table(flow.request.url)
                    res = yaml.safe_load(flow.response.content)
                    schema_result = validator.check(res, schema)
                    table.insert_multiple(schema_result)

                    logger.info(schema_result)