<commit_before>from io import BytesIO
from kqml import KQMLObject
from . import kqml_reader
from . import kqml_list
from .kqml_token import KQMLToken
from .kqml_exceptions import KQMLBadPerformativeException
from .util import safe_decode, safe_encode


class KQMLPerformative(KQMLObject):
    def __init__(self, objects):
        if not objects:
            raise KQMLBadPerformativeException('no elements for initialization')
        # If we get a string then we start a list with the string as the head
        if isinstance(objects, str):
            self.data = kqml_list.KQMLList(objects)
        elif isinstance(objects, kqml_list.KQMLList):
            self._validate(objects)
            self.data = objects

    @staticmethod
    def _validate(objects):
        if not isinstance(objects[0], KQMLToken):
            raise KQMLBadPerformativeException('list doesn\'t start ' +
                'with KQMLToken: ' + str(objects[0]))
        i = 1
        while i < len(objects):
            if not isinstance(objects[i], KQMLToken) or objects[i][0] != ':':
                raise KQMLBadPerformativeException('performative ' +
                    'element not a keyword: ' + objects[i])
            # Increment counter after keyword
            i += 1
            if i == len(objects):
                raise KQMLBadPerformativeException('missing value ' +
                    'for keyword: ' + objects[i-1])
            i += 1

    def __len__(self):
        return len(self.data)
<commit_msg>Fix silent error when objects[i] is not a string<commit_after>from io import BytesIO
from kqml import KQMLObject
from . import kqml_reader
from . import kqml_list
from .kqml_token import KQMLToken
from .kqml_exceptions import KQMLBadPerformativeException
from .util import safe_decode, safe_encode


class KQMLPerformative(KQMLObject):
    def __init__(self, objects):
        if not objects:
            raise KQMLBadPerformativeException('no elements for initialization')
        # If we get a string then we start a list with the string as the head
        if isinstance(objects, str):
            self.data = kqml_list.KQMLList(objects)
        elif isinstance(objects, kqml_list.KQMLList):
            self._validate(objects)
            self.data = objects

    @staticmethod
    def _validate(objects):
        if not isinstance(objects[0], KQMLToken):
            raise KQMLBadPerformativeException('list doesn\'t start ' +
                'with KQMLToken: ' + str(objects[0]))
        i = 1
        while i < len(objects):
            if not isinstance(objects[i], KQMLToken) or objects[i][0] != ':':
                raise KQMLBadPerformativeException('performative ' +
                    'element not a keyword: ' + str(objects[i]))
            # Increment counter after keyword
            i += 1
            if i == len(objects):
                raise KQMLBadPerformativeException('missing value ' +
                    'for keyword: ' + str(objects[i-1]))
            i += 1

    def __len__(self):
        return len(self.data)

{'fraction_non_alphanumeric': 0.0841828345938836, 'fraction_numerical': 0.0046037487668530086, 'mean_word_length': 2.3465346534653464, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7627124', 'n_tokens_mistral': 882, 'n_tokens_neox': 861, 'n_words': 248}