<commit_before># -*- coding: utf-8 -*-
import httplib as http
import logging

from flask import request

from framework.exceptions import HTTPError
from framework.auth.decorators import collect_auth
from framework.transactions.handlers import no_auto_transaction


from website.views import serialize_log, paginate
from website.project.model import NodeLog
from website.project.model import has_anonymous_link
from website.project.decorators import must_be_valid_project

logger = logging.getLogger(__name__)


@collect_auth
@no_auto_transaction
def get_log(auth, log_id):

    log = NodeLog.load(log_id)
    node_to_use = log.node

    if not node_to_use.can_view(auth):
        raise HTTPError(http.FORBIDDEN)

    return {'log': serialize_log(log)}


def _get_logs(node, count, auth, link=None, page=0):
    """

    :param Node node:
    :param int count:
    :param auth:
    :return list: List of serialized logs,
            boolean: if there are more logs

    """
    logs = []
    total = 0
    for log in reversed(node.logs):
        # A number of errors due to database inconsistency can arise here. The
        # log can be None; its `node__logged` back-ref can be empty, and the
        # 0th logged node can be None. Catch and log these errors and ignore
        # the offending logs.
        log_node = log.resolve_node(node)
        if log.can_view(node, auth):
            total += 1
            anonymous = has_anonymous_link(log_node, auth)
            logs.append(serialize_log(log, anonymous))

    paginated_logs, pages = paginate(logs, total, page, count)

    return list(paginated_logs), total, pages


@no_auto_transaction
@collect_auth
@must_be_valid_project
def get_logs(auth, **kwargs):
    """

    """
    node = kwargs['node'] or kwargs['project']
    try:
        page = int(request.args.get('page', 0))
    except ValueError:<commit_msg>Prevent 500 when loading logs for projects with logs that are None<commit_after># -*- coding: utf-8 -*-
import httplib as http
import logging

from flask import request

from framework.exceptions import HTTPError
from framework.auth.decorators import collect_auth
from framework.transactions.handlers import no_auto_transaction


from website.views import serialize_log, paginate
from website.project.model import NodeLog
from website.project.model import has_anonymous_link
from website.project.decorators import must_be_valid_project

logger = logging.getLogger(__name__)


@collect_auth
@no_auto_transaction
def get_log(auth, log_id):

    log = NodeLog.load(log_id)
    node_to_use = log.node

    if not node_to_use.can_view(auth):
        raise HTTPError(http.FORBIDDEN)

    return {'log': serialize_log(log)}


def _get_logs(node, count, auth, link=None, page=0):
    """

    :param Node node:
    :param int count:
    :param auth:
    :return list: List of serialized logs,
            boolean: if there are more logs

    """
    logs = []
    total = 0
    for log in reversed(node.logs):
        # A number of errors due to database inconsistency can arise here. The
        # log can be None; its `node__logged` back-ref can be empty, and the
        # 0th logged node can be None. Need to make sure that log is not None
        if log:
            log_node = log.resolve_node(node)
            if log.can_view(node, auth):
                total += 1
                anonymous = has_anonymous_link(log_node, auth)
                logs.append(serialize_log(log, anonymous))
        else:
            logger.warn('Log on node {} is None'.format(node._id))

    paginated_logs, pages = paginate(logs, total, page, count)

    return list(paginated_logs), total, pages


@no_auto_transaction
@collect_auth
@must_be_valid_project
def get_logs(auth, **kwargs):
    """

    """
    node = kwargs['node'] or kwargs['project']
    try:
        page = int(request.args.get('page', 0))
    except ValueError:
{'fraction_non_alphanumeric': 0.08931788931788932, 'fraction_numerical': 0.003861003861003861, 'mean_word_length': 3.165058949624866, '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': '4200833', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1156, 'n_words': 361}