<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

import json
import zlib

from django.core.serializers.json import DjangoJSONEncoder

from django.core.signing import (
    Signer,
    b64_encode,
    b64_decode,
)

from django.utils.encoding import force_bytes

from ..cursors import CursorParameter, BaseCursor


class CursorJSONEncoder(DjangoJSONEncoder):
    """
    JSON Encoder subclass that knows how to serialize cursor parameters
    """
    def __init__(self, *args, **kwargs):
        kwargs.update(dict(separators=(',', ':'), encoding='latin-1'))
        return super(CursorJSONEncoder, self).__init__(*args, **kwargs)

    def default(self, o):
        if isinstance(o, CursorParameter):
            return o.to_json()
        else:
            return super(CursorJSONEncoder, self).default(o)


def dumps(obj, key=None, salt='django.core.signing',
          serializer=CursorJSONEncoder, compress=False):
    """
    Returns URL-safe, sha1 signed base64 compressed JSON string. If key is
    None, settings.SECRET_KEY is used instead.

    If compress is True (not the default) checks if compressing using zlib can
    save some space. Prepends a '.' to signify compression. This is included
    in the signature, to protect against zip bombs.

    Salt can be used to namespace the hash, so that a signed string is
    only valid for a given namespace. Leaving this at the default
    value or re-using a salt value across different parts of your
    application without good cause is a security risk.

    The serializer is expected to return a bytestring.
    """
    data = json.dumps(obj, cls=CursorJSONEncoder)<commit_msg>Updated JSON encoding to be python3 complaint.<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

import json
import zlib

from django.core.serializers.json import DjangoJSONEncoder

from django.core.signing import (
    Signer,
    b64_encode,
    b64_decode,
)

from django.utils.encoding import force_bytes

from ..cursors import CursorParameter, BaseCursor


class CursorJSONEncoder(DjangoJSONEncoder):
    """
    JSON Encoder subclass that knows how to serialize cursor parameters
    """
    def __init__(self, *args, **kwargs):
        kwargs.update(dict(separators=(',', ':')))
        return super(CursorJSONEncoder, self).__init__(*args, **kwargs)

    def default(self, o):
        if isinstance(o, CursorParameter):
            return o.to_json()
        else:
            return super(CursorJSONEncoder, self).default(o)


def dumps(obj, key=None, salt='django.core.signing',
          serializer=CursorJSONEncoder, compress=False):
    """
    Returns URL-safe, sha1 signed base64 compressed JSON string. If key is
    None, settings.SECRET_KEY is used instead.

    If compress is True (not the default) checks if compressing using zlib can
    save some space. Prepends a '.' to signify compression. This is included
    in the signature, to protect against zip bombs.

    Salt can be used to namespace the hash, so that a signed string is
    only valid for a given namespace. Leaving this at the default
    value or re-using a salt value across different parts of your
    application without good cause is a security risk.

    The serializer is expected to return a bytestring.
    """
    data = json.dumps(obj, cls=CursorJSONEncoder).encode('latin-1')
{'fraction_non_alphanumeric': 0.08108890819577179, 'fraction_numerical': 0.005502461627570229, 'mean_word_length': 3.4510309278350517, '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': '4105133', 'n_tokens_mistral': 968, 'n_tokens_neox': 937, 'n_words': 358}