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

"""
httpbin.filters
~~~~~~~~~~~~~~~

This module provides response filter decorators.
"""

import gzip as gzip2

from cStringIO import StringIO
from decimal import Decimal
from time import time as now

import omnijson
from decorator import decorator
from flask import Flask, Response


app = Flask(__name__)


@decorator
def x_runtime(f, *args, **kwargs):
    """X-Runtime Flask Response Decorator."""

    _t0 = now()
    r = f(*args, **kwargs)
    _t1 = now()
    r.headers['X-Runtime'] = '{0}s'.format(Decimal(str(_t1-_t0)))

    return r


@decorator
def json(f, *args, **kwargs):
    """JSON Flask Response Decorator."""

    data = f(*args, **kwargs)

    # we already have a formatted response, move along
    if isinstance(data, Response):
        return data

    dump = omnijson.dumps(data, sort_keys=True, indent=3)

    r = app.make_response(dump)
    r.headers['Content-Type'] = 'application/json'


    return r


@decorator
def gzip(f, *args, **kwargs):
    """GZip Flask Response Decorator."""


    data = f(*args, **kwargs)

    if isinstance(data, Response):
        content = data.data
    else:
        content = data

    gzip_buffer = StringIO()
    gzip_file = gzip2.GzipFile(
        mode='wb',<commit_msg>fix omnijson usage<commit_after># -*- coding: utf-8 -*-

"""
httpbin.filters
~~~~~~~~~~~~~~~

This module provides response filter decorators.
"""

import gzip as gzip2

from cStringIO import StringIO
from decimal import Decimal
from time import time as now

import omnijson
from decorator import decorator
from flask import Flask, Response


app = Flask(__name__)


@decorator
def x_runtime(f, *args, **kwargs):
    """X-Runtime Flask Response Decorator."""

    _t0 = now()
    r = f(*args, **kwargs)
    _t1 = now()
    r.headers['X-Runtime'] = '{0}s'.format(Decimal(str(_t1-_t0)))

    return r


@decorator
def json(f, *args, **kwargs):
    """JSON Flask Response Decorator."""

    data = f(*args, **kwargs)

    # we already have a formatted response, move along
    if isinstance(data, Response):
        return data

    dump = omnijson.dumps(data)

    r = app.make_response(dump)
    r.headers['Content-Type'] = 'application/json'


    return r


@decorator
def gzip(f, *args, **kwargs):
    """GZip Flask Response Decorator."""


    data = f(*args, **kwargs)

    if isinstance(data, Response):
        content = data.data
    else:
        content = data

    gzip_buffer = StringIO()
    gzip_file = gzip2.GzipFile(
        mode='wb',
{'fraction_non_alphanumeric': 0.1412138040460135, 'fraction_numerical': 0.006743355811186037, 'mean_word_length': 3.2103505843071787, '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': '7416912', 'n_tokens_mistral': 858, 'n_tokens_neox': 812, 'n_words': 241}