<commit_before># -*- coding: utf-8 -*-
"""
    flaskext.versioned
    ~~~~~~~~~~~~~~~~~~

    Rewrite file paths to add version info.

    :copyright: (c) 2010 by <NAME>.
    :license: BSD, see LICENSE for more details
"""
import os
import time


__all__ = ['Driver', 'FileChangedDriver', 'Versioned']


class VersionedError(Exception):
    """Base error class."""
    pass


class Driver(object):
    def __init__(self, format='/version-%(version)s/%(path)s'):
        self.format = format

    def version(self, stream):
        raise NotImplementedError()


class FileChangedDriver(Driver):

    def version(self, stream):
        if not os.path.isfile(stream):
            raise VersionedError("no such file: %s" % stream)

        modt = time.localtime(os.path.getmtime(stream))
        mods = time.strftime('%Y%m%dT%H%M%S', modt)
        return self.format % {
            'version': mods,
            'path': stream,
        }


class Versioned(object):

    def __init__(self, app, driver_cls=FileChangedDriver, **driver_options):
        self._driver = driver_cls(**driver_options)
        app.jinja_env.filters.setdefault('versioned', self)

    def __call__(self, stream):
        return self._driver.version(stream)<commit_msg>add app shortcut to drivers; do os.path.join(app.root_path, path) for relative paths<commit_after># -*- coding: utf-8 -*-
"""
    flaskext.versioned
    ~~~~~~~~~~~~~~~~~~

    Rewrite file paths to add version info.

    :copyright: (c) 2010 by <NAME>.
    :license: BSD, see LICENSE for more details
"""
import os
import time


__all__ = ['Driver', 'FileChangedDriver', 'Versioned']


class VersionedError(Exception):
    """Base error class."""
    pass


class Driver(object):
    def __init__(self, app, format='/version-%(version)s/%(path)s'):
        self.app = app
        self.format = format

    def version(self, stream):
        raise NotImplementedError()


class FileChangedDriver(Driver):

    def version(self, stream):
        path = stream
        if os.path.isabs(path):
            pass
        else:
            path = os.path.join(self.app.root_path, path)

        if not os.path.isfile(path):
            raise VersionedError("no such file: %s" % path)

        modt = time.localtime(os.path.getmtime(path))
        mods = time.strftime('%Y%m%dT%H%M%S', modt)
        return self.format % {
            'version': mods,
            'path': path,
        }


class Versioned(object):

    def __init__(self, app, driver_cls=FileChangedDriver, **driver_options):
        self._driver = driver_cls(app, **driver_options)
        app.jinja_env.filters.setdefault('versioned', self)

    def __call__(self, stream):
        return self._driver.version(stream)
{'fraction_non_alphanumeric': 0.1434878587196468, 'fraction_numerical': 0.003679175864606328, 'mean_word_length': 2.8081232492997197, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3926443', 'n_tokens_mistral': 867, 'n_tokens_neox': 822, 'n_words': 202}