<commit_before>from __future__ import with_statement

import os
import subprocess
import time

from flask import url_for
from jinja2 import Markup

class Funnel(object):

    def __init__(self, app=None):
        if app is not None:
            self.init_app(app)
        else:
            self.app = None

    def init_app(self, app):
        self.app = app

        app.config.setdefault('CSS_MEDIA_DEFAULT', 'screen,projection,tv')
        app.config.setdefault('LESS_PREPROCESS', False)
        app.config.setdefault('BUNDLES_DIR', 'bundles')

        app.config.setdefault('CSS_BUNDLES', {})
        app.config.setdefault('JS_BUNDLES', {})

        @app.context_processor
        def context_processor():
            def get_path(item):
                return os.path.join(app.static_folder, item)

            def get_url(item):
                if item.startswith(('//', 'http://', 'https://')):
                    return item
                item = item.split('?', 1)
                url = url_for('static', filename=item[0])
                if item[1]:
                    url += '?' + item[1]
                return url

            def get_mtime(item):
                if item.startswith(('//', 'http://', 'https://')):
                    return int(time.time())

                try:
                    return int(os.path.getmtime(get_path(item)))
                except OSError:
                    return int(time.time())

            def build_html(items, wrapper):
                return Markup('\n'.join((wrapper % (get_url(item))
                    for item in items)))

            def ensure_path_exists(path):
                try:
                    os.makedirs(path)
                except OSError:
                    if OSError.errno != OSError.errno.EEXIST:
                        raise

            def compile_less(item):
                path_css = get_path('%s.css' % item)
                path_less = get_path(item)

                updated_less = os.path.getmtime(get_path(item))
                updated_css = 0
                if os.path.exists(path_css):
                    updated_css = os.path.getmtime(path_css)

                if updated_less > updated_css:
                    ensure_path_exists(os.path.dirname(path_css))
                    with open(path_css, 'w') as output:
                        subprocess.Popen([app.config.get('LESS_BIN', 'lessc'),
                                          path_less], stdout=output)

                return path_css

            def js(bundle, defer=False, async=False, debug=app.debug):
                if debug:<commit_msg>Small fix<commit_after>from __future__ import with_statement

import os
import subprocess
import time

from flask import url_for
from jinja2 import Markup

class Funnel(object):

    def __init__(self, app=None):
        if app is not None:
            self.init_app(app)
        else:
            self.app = None

    def init_app(self, app):
        self.app = app

        app.config.setdefault('CSS_MEDIA_DEFAULT', 'screen,projection,tv')
        app.config.setdefault('LESS_PREPROCESS', False)
        app.config.setdefault('BUNDLES_DIR', 'bundles')

        app.config.setdefault('CSS_BUNDLES', {})
        app.config.setdefault('JS_BUNDLES', {})

        @app.context_processor
        def context_processor():
            def get_path(item):
                return os.path.join(app.static_folder, item)

            def get_url(item):
                if item.startswith(('//', 'http://', 'https://')):
                    return item
                item = item.split('?', 1)
                url = url_for('static', filename=item[0])
                if item[1]:
                    url += '?' + item[1]
                return url

            def get_mtime(item):
                if item.startswith(('//', 'http://', 'https://')):
                    return int(time.time())

                try:
                    return int(os.path.getmtime(get_path(item)))
                except OSError:
                    return int(time.time())

            def build_html(items, wrapper):
                return Markup('\n'.join((wrapper % (get_url(item))
                    for item in items)))

            def ensure_path_exists(path):
                try:
                    os.makedirs(path)
                except OSError, e:
                    if e.errno != e.errno.EEXIST:
                        raise

            def compile_less(item):
                path_css = get_path('%s.css' % item)
                path_less = get_path(item)

                updated_less = os.path.getmtime(get_path(item))
                updated_css = 0
                if os.path.exists(path_css):
                    updated_css = os.path.getmtime(path_css)

                if updated_less > updated_css:
                    ensure_path_exists(os.path.dirname(path_css))
                    with open(path_css, 'w') as output:
                        subprocess.Popen([app.config.get('LESS_BIN', 'lessc'),
                                          path_less], stdout=output)

                return path_css

            def js(bundle, defer=False, async=False, debug=app.debug):
                if debug:
{'fraction_non_alphanumeric': 0.1106848263955496, 'fraction_numerical': 0.002301937464032227, 'mean_word_length': 1.4536470588235295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1834882', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1419, 'n_words': 291}