<commit_before>import sys, site, os
from os.path import join

PROJECT_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', '..')
DEFAULT_LANGUAGE = 'en'

def rel(*x):
    return os.path.join(PROJECT_ROOT, *x)

prev_sys_path = list(sys.path)

site.addsitedir(rel('env/lib/python2.6/site-packages'))

sys.path.append(PROJECT_ROOT)
sys.path.append(rel('unisubs'))
sys.path.append(rel('unisubs', 'libs'))
sys.path.append(rel('unisubs', 'apps'))

sys.stdout = sys.stderr

new_sys_path = [p for p in sys.path if p not in prev_sys_path]
for item in new_sys_path:
    sys.path.remove(item)
sys.path[:0] = new_sys_path

import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'unisubs.unisubs_settings'
os.environ["CELERY_LOADER"] = "django"
application = django.core.handlers.wsgi.WSGIHandler()

handler = django.core.handlers.wsgi.WSGIHandler()
disabled_file_path = rel('unisubs', 'disabled')

# instrumenting for tracelytics
try:
    import oboeware.djangoware
    from oboeware import OboeMiddleware
    handler = OboeMiddleware(application, {'oboe.tracing_mode': 'always'}, layer="wsgi")
except ImportError:
    # production, dev and local installs shouldn have that
    pass
    
def application(environ, start_response):
    if os.path.exists(disabled_file_path):
        start_response('200 OK', [('Content-type', 'text/html; charset=utf-8')])
        
        langs = environ.get('HTTP_ACCEPT_LANGUAGE', 'en').split(',')
        langs.append(DEFAULT_LANGUAGE)

        for lang in langs:
            lang = lang.split(';')[0].split('-')[0].lower()
            off_tpl_path = rel('unisubs', 'templates', 'off_template', '%s.html' % lang)
            if os.path.exists(off_tpl_path):
                break

        return open(off_tpl_path).read()        
    else:    
        return handler(environ, start_response)<commit_msg>updated disabled site to return 503 ; sifter #701<commit_after>import sys, site, os
from os.path import join

PROJECT_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', '..')
DEFAULT_LANGUAGE = 'en'

def rel(*x):
    return os.path.join(PROJECT_ROOT, *x)

prev_sys_path = list(sys.path)

site.addsitedir(rel('env/lib/python2.6/site-packages'))

sys.path.append(PROJECT_ROOT)
sys.path.append(rel('unisubs'))
sys.path.append(rel('unisubs', 'libs'))
sys.path.append(rel('unisubs', 'apps'))

sys.stdout = sys.stderr

new_sys_path = [p for p in sys.path if p not in prev_sys_path]
for item in new_sys_path:
    sys.path.remove(item)
sys.path[:0] = new_sys_path

import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'unisubs.unisubs_settings'
os.environ["CELERY_LOADER"] = "django"
application = django.core.handlers.wsgi.WSGIHandler()

handler = django.core.handlers.wsgi.WSGIHandler()
disabled_file_path = rel('unisubs', 'disabled')

# instrumenting for tracelytics
try:
    import oboeware.djangoware
    from oboeware import OboeMiddleware
    handler = OboeMiddleware(application, {'oboe.tracing_mode': 'always'}, layer="wsgi")
except ImportError:
    # production, dev and local installs shouldn have that
    pass
    
def application(environ, start_response):
    if os.path.exists(disabled_file_path):
        start_response('503 Service Unavailable', [('Content-type', 'text/html; charset=utf-8')])
        
        langs = environ.get('HTTP_ACCEPT_LANGUAGE', 'en').split(',')
        langs.append(DEFAULT_LANGUAGE)

        for lang in langs:
            lang = lang.split(';')[0].split('-')[0].lower()
            off_tpl_path = rel('unisubs', 'templates', 'off_template', '%s.html' % lang)
            if os.path.exists(off_tpl_path):
                break

        return open(off_tpl_path).read()        
    else:    
        return handler(environ, start_response)
{'fraction_non_alphanumeric': 0.1441823482639809, 'fraction_numerical': 0.0063609859528226875, 'mean_word_length': 3.9140625, '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': '2598105', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1327, 'n_words': 247}