<commit_before>import yaml
import os.path

from django.http import Http404
from django.conf.urls import url
from django.conf import settings


def get_page(path):
    url = ('/%s/' % path) if path else '/'
    with (settings.PROJECT_DIR / 'prototype.yml').open() as f:
        data = yaml.load(f)
    try:
        page = data['urls'][url] or {
            'context': {},
        }
    except KeyError:
        raise Http404("Requested %s page not found." % url)

    if 'globals' in data and page.get('type', 'html') == 'html':
        page['context'] = dict(data['globals'], **page.get('context', {}))

    return page


def get_template(path):
    base = os.path.join('seimas', 'website')
    candidates = [
        os.path.join(path, 'index.html'),
        '%s.html' % path,
    ]
    for template in candidates:
        if os.path.exists(os.path.join(base, 'templates', template)):
            return template


def get_urls(view):
    with (settings.PROJECT_DIR / 'prototype.yml').open() as f:
        data = yaml.load(f)

    urls = []
    for path, page in data['urls'].items():
        if page and 'name' in page:
            pattern = r'^%s$' % path.lstrip('/')
            kwargs = {'path': path.strip('/')}
            urls.append(url(pattern, view, kwargs, name=page['name']))<commit_msg>Fix prototype template loading error<commit_after>import yaml
import os.path

from django.http import Http404
from django.conf.urls import url
from django.conf import settings


def get_page(path):
    url = ('/%s/' % path) if path else '/'
    with (settings.PROJECT_DIR / 'prototype.yml').open(encoding='utf-8') as f:
        data = yaml.load(f)
    try:
        page = data['urls'][url] or {
            'context': {},
        }
    except KeyError:
        raise Http404("Requested %s page not found." % url)

    if 'globals' in data and page.get('type', 'html') == 'html':
        page['context'] = dict(data['globals'], **page.get('context', {}))

    return page


def get_template(path):
    base = settings.PROJECT_DIR / 'seimas/website'
    candidates = [
        os.path.join(path, 'index.html'),
        '%s.html' % path,
    ]
    for template in candidates:
        if (base / 'templates' / template).exists():
            return template


def get_urls(view):
    with (settings.PROJECT_DIR / 'prototype.yml').open(encoding='utf-8') as f:
        data = yaml.load(f)

    urls = []
    for path, page in data['urls'].items():
        if page and 'name' in page:
            pattern = r'^%s$' % path.lstrip('/')
            kwargs = {'path': path.strip('/')}
            urls.append(url(pattern, view, kwargs, name=page['name']))
{'fraction_non_alphanumeric': 0.1630105900151286, 'fraction_numerical': 0.00529500756429652, 'mean_word_length': 2.5079575596816976, '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': '7029707', 'n_tokens_mistral': 858, 'n_tokens_neox': 837, 'n_words': 221}