<commit_before># -*- coding: utf8 -*-
"""View module for Flask-Z3950."""

import json
from flask import Flask, request, abort, Response, render_template
from flask import current_app
from flask.ext.z3950 import ZoomError


def error_status(e):
    """Return the HTTP status code associated with an exception"""
    codes = {"QuerySyntaxError": 400,
             "ValueError": 400,
             "RuntimeError": 500}

    name = e.__class__.__name__
    if name not in codes.keys():
        return 500

    return codes[name]


def search_marcxml(db):
    """Return the results of a Z39.50 database search as MARCXML.

    :param db: The identifier of the database to be searched.
    """
    try:
        (msg, dataset, kwargs) = _handle_search_request(db, request.args)
    except (ZoomError, ValueError, RuntimeError) as e:
        return render_template('error.xml', msg=str(e)), error_status(e)

    resp = dataset.to_marcxml()
    return Response(resp, 200, mimetype="application/xml")


def search_raw(db):
    """Return the results of a Z39.50 database search as raw data.

    :param db: The identifier of the database to be searched.
    """
    try:
        (msg, dataset, kwargs) = _handle_search_request(db, request.args)
    except (ZoomError, ValueError, RuntimeError) as e:
        abort(error_status(e))<commit_msg>Fix mime type for xml error<commit_after># -*- coding: utf8 -*-
"""View module for Flask-Z3950."""

import json
from flask import Flask, request, abort, Response, render_template
from flask import current_app
from flask.ext.z3950 import ZoomError


def error_status(e):
    """Return the HTTP status code associated with an exception"""
    codes = {"QuerySyntaxError": 400,
             "ValueError": 400,
             "RuntimeError": 500}

    name = e.__class__.__name__
    if name not in codes.keys():
        return 500

    return codes[name]


def search_marcxml(db):
    """Return the results of a Z39.50 database search as MARCXML.

    :param db: The identifier of the database to be searched.
    """
    try:
        (msg, dataset, kwargs) = _handle_search_request(db, request.args)
    except (ZoomError, ValueError, RuntimeError) as e:
        resp = render_template('error.xml', msg=str(e))
        return Response(resp, error_status(e), mimetype="application/xml")

    resp = dataset.to_marcxml()
    return Response(resp, 200, mimetype="application/xml")


def search_raw(db):
    """Return the results of a Z39.50 database search as raw data.

    :param db: The identifier of the database to be searched.
    """
    try:
        (msg, dataset, kwargs) = _handle_search_request(db, request.args)
    except (ZoomError, ValueError, RuntimeError) as e:
        abort(error_status(e))
{'fraction_non_alphanumeric': 0.10761346998535871, 'fraction_numerical': 0.02342606149341142, 'mean_word_length': 3.276995305164319, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '724384', 'n_tokens_mistral': 867, 'n_tokens_neox': 803, 'n_words': 275}