# Path: oioswift/common/middleware/regexcontainer.py
# class RegexContainerMiddleware(AutoContainerBase):
#     BYPASS_QS = "bypass-autocontainer"
#     BYPASS_HEADER = "X-bypass-autocontainer"
#     def __init__(self, app, acct, patterns, failsafe=False,
#                  **kwargs):
#     def _call(self, env, start_response):
# def filter_factory(global_conf, **local_config):
#     def factory(app):


import os.path
import sys
import unittest
from swift.common import swob, utils
from swift.common.swob import Request
from oioswift.common.middleware import regexcontainer
from oio.common.autocontainer import ContainerBuilder
from test.unit.common.middleware.helpers import FakeSwift  # noqa: E402

# Hack PYTHONPATH so "test" is swift's test directory
sys.path.insert(1, os.path.abspath(os.path.join(__file__, '../../../../..')))  # noqa


class OioRegexContainer(unittest.TestCase):
    def setUp(self):
        conf = {'sds_default_account': 'OPENIO'}
        self.filter_conf = {
            'strip_v1': 'true',
            'swift3_compat': 'true',
            'account_first': 'true',
            'stop_at_first_match': 'true',
            'pattern1': r'(\d{3})/(\d{3})/(\d)\d\d/\d\d(\d)/',
            'pattern2': r'(\d{3})/(\d)\d\d/\d\d(\d)/',
            'pattern3': r'^(cloud)/([0-9a-f][0-9a-f])',
            'pattern4': r'^(cloud)/([0-9a-f])',
            'pattern9': r'^/?([^/]+)',
        }

        if hasattr(ContainerBuilder, 'alternatives'):
            self.filter_conf['stop_at_first_match'] = 'false'

        self.app = FakeSwift()

# Path: oioswift/common/middleware/regexcontainer.py
# class RegexContainerMiddleware(AutoContainerBase):
#     BYPASS_QS = "bypass-autocontainer"
#     BYPASS_HEADER = "X-bypass-autocontainer"
#     def __init__(self, app, acct, patterns, failsafe=False,
#                  **kwargs):
#     def _call(self, env, start_response):
# def filter_factory(global_conf, **local_config):
#     def factory(app):


# Path: tests/unit/common/middleware/test_regexcontainer.py
import os.path
import sys
import unittest
from swift.common import swob, utils
from swift.common.swob import Request
from oioswift.common.middleware import regexcontainer
from oio.common.autocontainer import ContainerBuilder
from test.unit.common.middleware.helpers import FakeSwift  # noqa: E402


# Hack PYTHONPATH so "test" is swift's test directory
sys.path.insert(1, os.path.abspath(os.path.join(__file__, '../../../../..')))  # noqa


class OioRegexContainer(unittest.TestCase):
    def setUp(self):
        conf = {'sds_default_account': 'OPENIO'}
        self.filter_conf = {
            'strip_v1': 'true',
            'swift3_compat': 'true',
            'account_first': 'true',
            'stop_at_first_match': 'true',
            'pattern1': r'(\d{3})/(\d{3})/(\d)\d\d/\d\d(\d)/',
            'pattern2': r'(\d{3})/(\d)\d\d/\d\d(\d)/',
            'pattern3': r'^(cloud)/([0-9a-f][0-9a-f])',
            'pattern4': r'^(cloud)/([0-9a-f])',
            'pattern9': r'^/?([^/]+)',
        }

        if hasattr(ContainerBuilder, 'alternatives'):
            self.filter_conf['stop_at_first_match'] = 'false'

        self.app = FakeSwift()

        self.ch = regexcontainer.filter_factory(