<commit_before>import logging

from adhocracy import model
from paste.deploy.converters import asbool

log = logging.getLogger(__name__)


class InstanceDiscriminatorMiddleware(object):

    def __init__(self, app, domain, config):
        self.app = app
        self.domain = domain
        self.config = config
        log.debug("Host name: %s." % domain)

    def __call__(self, environ, start_response):
        environ['adhocracy.domain'] = self.domain
        instance_key = self.config.get('adhocracy.instance')
        if instance_key is None:
            if asbool(self.config.get('adhocracy.relative_urls', 'false')):
                path = environ.get('PATH_INFO', '')
                if path.startswith('/i/'):
                    instance_key = path.split('/')[2]
                    if instance_key == '':
                        instance_key = path.split('/')[1]
                    environ['PATH_INFO'] = path[len('/i/' + instance_key):]
		    if environ['PATH_INFO'] == '':
		        environ['PATH_INFO'] += '/'
            else:
                host = environ.get('HTTP_HOST', "")
                host = host.replace(self.domain, "")
                host = host.replace('localhost', "")
                host = host.split(':', 1)[0]
                host = host.strip('.').strip()
                instance_key = host

        if instance_key: # instance key is set (neither None nor "")
            instance = model.Instance.find(instance_key)
            if instance is None:
                log.debug("No such instance: %s, defaulting!" % instance_key)
            else:
                model.instance_filter.setup_thread(instance)
        try:
            return self.app(environ, start_response)
        finally:
            model.instance_filter.setup_thread(None)

<commit_msg>Removed unnecessary line<commit_after>import logging

from adhocracy import model
from paste.deploy.converters import asbool

log = logging.getLogger(__name__)


class InstanceDiscriminatorMiddleware(object):

    def __init__(self, app, domain, config):
        self.app = app
        self.domain = domain
        self.config = config
        log.debug("Host name: %s." % domain)

    def __call__(self, environ, start_response):
        environ['adhocracy.domain'] = self.domain
        instance_key = self.config.get('adhocracy.instance')
        if instance_key is None:
            if asbool(self.config.get('adhocracy.relative_urls', 'false')):
                path = environ.get('PATH_INFO', '')
                if path.startswith('/i/'):
                    instance_key = path.split('/')[2]
                    environ['PATH_INFO'] = path[len('/i/' + instance_key):]
		    if environ['PATH_INFO'] == '':
		        environ['PATH_INFO'] += '/'
            else:
                host = environ.get('HTTP_HOST', "")
                host = host.replace(self.domain, "")
                host = host.replace('localhost', "")
                host = host.split(':', 1)[0]
                host = host.strip('.').strip()
                instance_key = host

        if instance_key: # instance key is set (neither None nor "")
            instance = model.Instance.find(instance_key)
            if instance is None:
                log.debug("No such instance: %s, defaulting!" % instance_key)
            else:
                model.instance_filter.setup_thread(instance)
        try:
            return self.app(environ, start_response)
        finally:
            model.instance_filter.setup_thread(None)


{'fraction_non_alphanumeric': 0.12428734321550741, 'fraction_numerical': 0.0019954389965792475, 'mean_word_length': 1.9586846543001686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5756655', 'n_tokens_mistral': 987, 'n_tokens_neox': 949, 'n_words': 204}