<commit_before><commit_msg>Added some helpers that's been useful in in-house projects<commit_after># -*- coding: utf-8 -*-

from BeautifulSoup import BeautifulSoup

from django.template import loader, Context, Template

run_template = lambda t, **kw: Template(t).render(Context(kw))
soup_template = lambda t, **kw: BeautifulSoup(run_template(t, **kw))

def render_raw(name, **ctx):
    return loader.render_to_string(name, SekizaiContext(ctx))

def render_to_soup(name, **ctx):
    return BeautifulSoup(render_raw(name, **ctx))

def fake_get(path='/', user=None):
    from django.test.client import RequestFactory
    from django.contrib.auth.models import AnonymousUser

    req = RequestFactory().get(path)
    req.user = AnonymousUser() if user is None else user
    req.current_page = 'dummy'

    return req
{'fraction_non_alphanumeric': 0.11945812807881774, 'fraction_numerical': 0.0012315270935960591, 'mean_word_length': 5.067164179104478, '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': '6402844', 'n_tokens_mistral': 254, 'n_tokens_neox': 248, 'n_words': 69}