<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from aybu.website.models.language import Language
from aybu.website.models.node import NodeInfo
import logging


__all__ = []

log = logging.getLogger(__name__)


def get_root_resource(request):

    log.debug('get_root_resource: %s', request.path_info)

    url_parts = [(url_part, Resource())
                 for url_part in request.path_info.strip('/').split('/') 
                 if url_part]

    log.debug('url_parts: %s', url_parts)

    if not url_parts:
        # URL is '/'.
        log.debug('Return NoLanguage context.')
        return NoLanguage()

    request.language = Language.get_by_lang(request.db_session, url_parts[0][0])

    if len(url_parts) == 1:
        # URL is like '/{lang}'.
        log.debug('Get Context by Language %s.', url_parts[0][0])
        url_parts[0] = (url_parts[0][0], request.language)

    else:
        # URL is like '/{lang}/{node}/[...]/{page}[.ext]<commit_msg>Added comment<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from aybu.website.models.language import Language
from aybu.website.models.node import NodeInfo
import logging


__all__ = []

log = logging.getLogger(__name__)


def get_root_resource(request):

    log.debug('get_root_resource: %s', request.path_info)

    # Getting url_parts and for each part associating a Resource
    # On request.path_info applying strip('/') remvoe the initial / so
    # with the following split('/') we obtain a list just with parts
    url_parts = [(url_part, Resource())
                 for url_part in request.path_info.strip('/').split('/')
                 if url_part]

    log.debug('url_parts: %s', url_parts)

    if not url_parts:
        # URL is '/'.
        log.debug('Return NoLanguage context.')
        return NoLanguage()

    request.language = Language.get_by_lang(request.db_session, url_parts[0][0])

    if len(url_parts) == 1:
        # URL is like '/{lang}'.
        log.debug('Get Context by Language %s.', url_parts[0][0])
        url_parts[0] = (url_parts[0][0], request.language)

    else:
        # URL is like '/{lang}/{node}/[...]/{page}[.ext]
{'fraction_non_alphanumeric': 0.14837209302325582, 'fraction_numerical': 0.008372093023255815, 'mean_word_length': 2.834224598930481, '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': '740126', 'n_tokens_mistral': 707, 'n_tokens_neox': 675, 'n_words': 164}