<commit_before># -*- coding: utf-8 -*-

from openprocurement.api.models import Tender
from pyramid.security import (
    ALL_PERMISSIONS,
    Allow,
    Authenticated,
    Everyone,
)


class Root(object):
    __name__ = None
    __parent__ = None
    __acl__ = [
        (Allow, Everyone, ALL_PERMISSIONS),
        (Allow, Authenticated, 'view_tenders'),
        (Allow, Authenticated, 'create_tender'),
        (Allow, 'auction', 'auction'),
        (Allow, 'chronograph', 'edit_tender'),
        (Allow, 'chronograph', 'view_tender'),
        (Allow, 'g:admins', ALL_PERMISSIONS),
    ]

    def __init__(self, request):
        self.request = request
        self.db = request.registry.db


def get_item(parent, key, request, root):
    request.validated['{}_id'.format(key)] = request.matchdict['{}_id'.format(key)]
    items = [i for i in getattr(parent, '{}s'.format(key), []) if i.id == request.matchdict['{}_id'.format(key)]]
    if not items:
        request.errors.add('url', '{}_id'.format(key), 'Not Found')
        request.errors.status = 404
        return root
    else:
        request.validated['{}s'.format(key)] = items
        item = items[-1]
        request.validated[key] = item
        request.validated['id'] = request.matchdict['{}_id'.format(key)]
        item.__parent__ = parent
        return item


def factory(request):
    root = Root(request)
    if not request.matchdict.get('tender_id'):
        return root<commit_msg>Fixed traversal<commit_after># -*- coding: utf-8 -*-

from openprocurement.api.models import Tender
from pyramid.security import (
    ALL_PERMISSIONS,
    Allow,
    Authenticated,
    Everyone,
)


class Root(object):
    __name__ = None
    __parent__ = None
    __acl__ = [
        (Allow, Everyone, ALL_PERMISSIONS),
        (Allow, Authenticated, 'view_tenders'),
        (Allow, Authenticated, 'create_tender'),
        (Allow, 'auction', 'auction'),
        (Allow, 'chronograph', 'edit_tender'),
        (Allow, 'chronograph', 'view_tender'),
        (Allow, 'g:admins', ALL_PERMISSIONS),
    ]

    def __init__(self, request):
        self.request = request
        self.db = request.registry.db


def get_item(parent, key, request, root):
    request.validated['{}_id'.format(key)] = request.matchdict['{}_id'.format(key)]
    items = [i for i in getattr(parent, '{}s'.format(key), []) if i.id == request.matchdict['{}_id'.format(key)]]
    if not items:
        request.errors.add('url', '{}_id'.format(key), 'Not Found')
        request.errors.status = 404
        return root
    else:
        request.validated['{}s'.format(key)] = items
        item = items[-1]
        request.validated[key] = item
        request.validated['id'] = request.matchdict['{}_id'.format(key)]
        item.__parent__ = parent
        return item


def factory(request):
    root = Root(request)
    if not request.matchdict or not request.matchdict.get('tender_id'):
        return root
{'fraction_non_alphanumeric': 0.15073154134059205, 'fraction_numerical': 0.003402517863218782, 'mean_word_length': 2.888888888888889, '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': '5547177', 'n_tokens_mistral': 955, 'n_tokens_neox': 928, 'n_words': 201}