<commit_before>from functools import wraps
from flask import url_for as flask_url_for, redirect, render_template, request, g, abort
from flask_login import login_required
from piiipod import config, debug, domain
import flask_login


def current_user():
    """Returns currently-logged-in user"""
    return flask_login.current_user


def render(f, *args, **kwargs):
    """Render templates with defaults"""
    for k, v in config.items():
        kwargs.setdefault('cfg_%s' % k, v)
    return render_template(f, *args,
        domain=domain,
        request=request,
        g=g,
        logout=request.args.get('logout', False),
        the_url=url_for,
        current_url=current_url,
        **kwargs)


def anonymous_required(f):
    """Decorator for views that require anonymous users (e.g., sign in)"""
    @wraps(f)
    def decorator(*args, **kwargs):
        if flask_login.current_user.is_authenticated:
            return redirect(url_for('dashboard.home'))
        return f(*args, **kwargs)
    return decorator


def requires(*permissions):
    """Decorator for views, restricting access to the roles listed"""
    def wrap(f):
        @wraps(f)
        def decorator(*args, **kwargs):
            if not all(u.can(p) for p in permissions):
                return 'Permissions Error'
            return f(*args, **kwargs)
        return decorator
    return wrap


def strip_subdomain(string):
    """Strip subdomain prefix if applicable"""
    if '/subdomain/' not in request.path or not g.group:
        return string
    parts = string.replace('subdomain', '').split('/');
    if not parts:
        pass
    if parts[1] == g.group.url:
        parts = parts[2:]
    elif parts[2] == g.group.url:
        parts = parts[3:]
    url = '/' + '/'.join(parts)
    return url


def current_url():
    """Return current URL"""
    return strip_subdomain(request.path)


def url_for(*args, **kwargs):
    """Special url function for subdomain websites"""
    return strip_subdomain(flask_url_for(*args, **kwargs))<commit_msg>deafult if g has no group<commit_after>from functools import wraps
from flask import url_for as flask_url_for, redirect, render_template, request, g, abort
from flask_login import login_required
from piiipod import config, debug, domain
import flask_login


def current_user():
    """Returns currently-logged-in user"""
    return flask_login.current_user


def render(f, *args, **kwargs):
    """Render templates with defaults"""
    for k, v in config.items():
        kwargs.setdefault('cfg_%s' % k, v)
    return render_template(f, *args,
        domain=domain,
        request=request,
        g=g,
        logout=request.args.get('logout', False),
        the_url=url_for,
        current_url=current_url,
        **kwargs)


def anonymous_required(f):
    """Decorator for views that require anonymous users (e.g., sign in)"""
    @wraps(f)
    def decorator(*args, **kwargs):
        if flask_login.current_user.is_authenticated:
            return redirect(url_for('dashboard.home'))
        return f(*args, **kwargs)
    return decorator


def requires(*permissions):
    """Decorator for views, restricting access to the roles listed"""
    def wrap(f):
        @wraps(f)
        def decorator(*args, **kwargs):
            if not all(u.can(p) for p in permissions):
                return 'Permissions Error'
            return f(*args, **kwargs)
        return decorator
    return wrap


def strip_subdomain(string):
    """Strip subdomain prefix if applicable"""
    if '/subdomain/' not in request.path or not getattr(g, 'group', None):
        return string
    parts = string.replace('subdomain', '').split('/');
    if not parts:
        pass
    if parts[1] == g.group.url:
        parts = parts[2:]
    elif parts[2] == g.group.url:
        parts = parts[3:]
    url = '/' + '/'.join(parts)
    return url


def current_url():
    """Return current URL"""
    return strip_subdomain(request.path)


def url_for(*args, **kwargs):
    """Special url function for subdomain websites"""
    return strip_subdomain(flask_url_for(*args, **kwargs))
{'fraction_non_alphanumeric': 0.124267578125, 'fraction_numerical': 0.001953125, 'mean_word_length': 2.9815354713313895, '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': '7010434', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1217, 'n_words': 360}