<commit_before>from functools import partial


def update_schema_if_mandatory(response, config, patch_collection):
    if 'details' in response:
        collection_schema = {
            'schema': response['details']['existing'].get('schema'),
            'uiSchema': response['details']['existing'].get('uiSchema'),
            'displayFields': response['details']['existing'].get(
                'displayFields'),
        }
    else:
        collection_schema = {
            'schema': response['data'].get('schema'),
            'uiSchema': response['data'].get('uiSchema'),
            'displayFields': response['data'].get('displayFields'),
        }

    if config and collection_schema != config:
        patch_collection(data=config)


def get_kinto_records(kinto_client, bucket, collection, permissions,
                      config=None):
    """Return all the kinto records for this bucket/collection."""
    # Create bucket if needed
    kinto_client.create_bucket(bucket, if_not_exists=True)
    response = kinto_client.create_collection(
        collection, bucket, permissions=permissions, if_not_exists=True)<commit_msg>Allow json2kinto to work even without the bucket_creation permission.<commit_after>from functools import partial
from kinto_http.exceptions import KintoException


def update_schema_if_mandatory(response, config, patch_collection):
    if 'details' in response:
        collection_schema = {
            'schema': response['details']['existing'].get('schema'),
            'uiSchema': response['details']['existing'].get('uiSchema'),
            'displayFields': response['details']['existing'].get(
                'displayFields'),
        }
    else:
        collection_schema = {
            'schema': response['data'].get('schema'),
            'uiSchema': response['data'].get('uiSchema'),
            'displayFields': response['data'].get('displayFields'),
        }

    if config and collection_schema != config:
        patch_collection(data=config)


def get_kinto_records(kinto_client, bucket, collection, permissions,
                      config=None):
    """Return all the kinto records for this bucket/collection."""
    # Create bucket if needed
    try:
        kinto_client.create_bucket(bucket, if_not_exists=True)
    except KintoException as e:
        if hasattr(e, 'response') and e.response.status_code == 403:
            # The user cannot create buckets on this server, ignore the creation.
            pass

    response = kinto_client.create_collection(
        collection, bucket, permissions=permissions, if_not_exists=True)
{'fraction_non_alphanumeric': 0.11839568067875048, 'fraction_numerical': 0.0015426147319706903, 'mean_word_length': 3.143769968051118, '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': '7085230', 'n_tokens_mistral': 667, 'n_tokens_neox': 659, 'n_words': 155}