<commit_before># -*- coding: utf-8 -*-
# ###
# Copyright (c) 2013-2015, Rice University
# This software is subject to the provisions of the GNU Affero General
# Public License version 3 (AGPLv3).
# See LICENCE.txt for details.
# ###
import uuid
import base64

HASH_CHAR = '@'
VERSION_CHAR = '.'


__all__ = (
    'IdentHashSyntaxError',
    'IdentHashShortId',
    'IdentHashMissingVersion',
    'join_ident_hash',
    'split_ident_hash',
    'split_legacy_hash',
    'CNXHash',
    )


class IdentHashSyntaxError(Exception):
    """Raised when the ident-hash syntax is incorrect."""


class IdentHashShortId(Exception):
    """Raised when the ident-hash id is not a uuid"""
    def __init__(self, id, version):
        self.id = id
        self.version = version


class IdentHashMissingVersion(Exception):
    """Raised when the ident-hash does not have a version"""
    def __init__(self, id):
        self.id = id


def split_legacy_hash(legacy_hash):
    split_value = legacy_hash.split('/')
    id = split_value[0]
    version = None
    if len(split_value) == 2:
        if split_value[1] != 'latest':
            version = split_value[1]
    return id, version


def split_ident_hash(ident_hash, split_version=False):
    """Returns a valid id and version from the <id>@<version> hash syntax."""
    if HASH_CHAR not in ident_hash:
        ident_hash = '{}@'.format(ident_hash)
    split_value = ident_hash.split(HASH_CHAR)
    if split_value[0] == '':
        raise ValueError("Missing values")
<commit_msg>Add IdentHashError base exception class for all ident hash exceptions<commit_after># -*- coding: utf-8 -*-
# ###
# Copyright (c) 2013-2015, Rice University
# This software is subject to the provisions of the GNU Affero General
# Public License version 3 (AGPLv3).
# See LICENCE.txt for details.
# ###
import uuid
import base64

HASH_CHAR = '@'
VERSION_CHAR = '.'


__all__ = (
    'IdentHashSyntaxError',
    'IdentHashShortId',
    'IdentHashMissingVersion',
    'join_ident_hash',
    'split_ident_hash',
    'split_legacy_hash',
    'CNXHash',
    )


class IdentHashError(Exception):
    """Base exception class for all ident hash exceptions."""


class IdentHashSyntaxError(IdentHashError):
    """Raised when the ident-hash syntax is incorrect."""


class IdentHashShortId(IdentHashError):
    """Raised when the ident-hash id is not a uuid"""
    def __init__(self, id, version):
        self.id = id
        self.version = version


class IdentHashMissingVersion(IdentHashError):
    """Raised when the ident-hash does not have a version"""
    def __init__(self, id):
        self.id = id


def split_legacy_hash(legacy_hash):
    split_value = legacy_hash.split('/')
    id = split_value[0]
    version = None
    if len(split_value) == 2:
        if split_value[1] != 'latest':
            version = split_value[1]
    return id, version


def split_ident_hash(ident_hash, split_version=False):
    """Returns a valid id and version from the <id>@<version> hash syntax."""
    if HASH_CHAR not in ident_hash:
        ident_hash = '{}@'.format(ident_hash)
    split_value = ident_hash.split(HASH_CHAR)
    if split_value[0] == '':
        raise ValueError("Missing values")

{'fraction_non_alphanumeric': 0.1175, 'fraction_numerical': 0.01125, 'mean_word_length': 3.439667128987517, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2337345', 'n_tokens_mistral': 1024, 'n_tokens_neox': 996, 'n_words': 287}