<commit_before>from flask import Flask, render_template, request, g, Response, redirect
from flaskext.bcrypt import Bcrypt
from flaskext.markdown import Markdown

from jinja2 import FileSystemLoader, ChoiceLoader
from shutil import copyfile, rmtree
import scss
import os
import traceback
import subprocess

from .views import HookView, APIView, MediaView, DocsView
from .config import _cfg, _cfgi
from .files import extension, get_mimetype
from .views.media import render_media, type_files
from .share import share

app = Flask(__name__)
app.jinja_env.cache = None
bcrypt = Bcrypt(app)
Markdown(app)
scss.config.LOAD_PATHS = [
    './styles/'
];

notice_enabled = False
notice_text = "Processing time is higher than usual due to heavy load."

def prepare():
    if os.path.exists(app.static_folder):
        rmtree(app.static_folder)
    os.makedirs(app.static_folder)
    compiler = scss.Scss(scss_opts = {
        'style': 'compressed'
    })

    # Compile styles (scss)
    d = os.walk('styles')
    for f in list(d)[0][2]:
        if extension(f) == "scss":
            with open(os.path.join('styles', f)) as r:
                output = compiler.compile(r.read())

            parts = f.rsplit('.')
            css = '.'.join(parts[:-1]) + ".css"

            with open(os.path.join(app.static_folder, css), "w") as w:
                w.write(output)
                w.flush()

    copy = ['images', 'scripts']
    # Simple copy for the rest of the files
    for folder in copy:
        for f in list(os.walk(folder))[0][2]:
            copyfile(os.path.join(folder, f), os.path.join(app.static_folder, os.path.basename(f)))

@app.before_first_request
def compile_first():
    prepare()

@app.before_request
def compile_if_debug():
    if app.debug:
        prepare()

@app.before_request
def find_dnt():
    field = "Dnt"
    do_not_track = False
    if field in request.headers:
        do_not_track = True if request.headers[field] == "1" else False

    g.do_not_track = do_not_track

@app.before_request
def jinja_template_loader():
    mobile = request.user_agent.platform in ['android', 'iphone', 'ipad']
    g.mobile = mobile
    if mobile:
        app.jinja_loader = ChoiceLoader([
            FileSystemLoader(os.path.join("templates", "mobile")),
            FileSystemLoader("templates"),
        ])
    else:
        app.jinja_loader = FileSystemLoader("templates")

@app.errorhandler(404)
def not_found(e):
    return render_template("error.html", error="File not found."), 404

@app.errorhandler(Exception)<commit_msg>Show mobile website to Windows Phone<commit_after>from flask import Flask, render_template, request, g, Response, redirect
from flaskext.bcrypt import Bcrypt
from flaskext.markdown import Markdown

from jinja2 import FileSystemLoader, ChoiceLoader
from shutil import copyfile, rmtree
import scss
import os
import traceback
import subprocess

from .views import HookView, APIView, MediaView, DocsView
from .config import _cfg, _cfgi
from .files import extension, get_mimetype
from .views.media import render_media, type_files
from .share import share

app = Flask(__name__)
app.jinja_env.cache = None
bcrypt = Bcrypt(app)
Markdown(app)
scss.config.LOAD_PATHS = [
    './styles/'
];

notice_enabled = False
notice_text = "Processing time is higher than usual due to heavy load."

def prepare():
    if os.path.exists(app.static_folder):
        rmtree(app.static_folder)
    os.makedirs(app.static_folder)
    compiler = scss.Scss(scss_opts = {
        'style': 'compressed'
    })

    # Compile styles (scss)
    d = os.walk('styles')
    for f in list(d)[0][2]:
        if extension(f) == "scss":
            with open(os.path.join('styles', f)) as r:
                output = compiler.compile(r.read())

            parts = f.rsplit('.')
            css = '.'.join(parts[:-1]) + ".css"

            with open(os.path.join(app.static_folder, css), "w") as w:
                w.write(output)
                w.flush()

    copy = ['images', 'scripts']
    # Simple copy for the rest of the files
    for folder in copy:
        for f in list(os.walk(folder))[0][2]:
            copyfile(os.path.join(folder, f), os.path.join(app.static_folder, os.path.basename(f)))

@app.before_first_request
def compile_first():
    prepare()

@app.before_request
def compile_if_debug():
    if app.debug:
        prepare()

@app.before_request
def find_dnt():
    field = "Dnt"
    do_not_track = False
    if field in request.headers:
        do_not_track = True if request.headers[field] == "1" else False

    g.do_not_track = do_not_track

@app.before_request
def jinja_template_loader():
    mobile = request.user_agent.platform in ['android', 'iphone', 'ipad'] or 'windows phone' in request.user_agent.string.lower()
    g.mobile = mobile
    if mobile:
        app.jinja_loader = ChoiceLoader([
            FileSystemLoader(os.path.join("templates", "mobile")),
            FileSystemLoader("templates"),
        ])
    else:
        app.jinja_loader = FileSystemLoader("templates")

@app.errorhandler(404)
def not_found(e):
    return render_template("error.html", error="File not found."), 404

@app.errorhandler(Exception)
{'fraction_non_alphanumeric': 0.12041884816753927, 'fraction_numerical': 0.005041690905565251, 'mean_word_length': 3.1596774193548387, 'pattern_counts': {'":': 2, '<': 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': '1409647', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1638, 'n_words': 427}