<commit_before># -*- coding: utf-8  -*-
"""
Objects representing Mediawiki log entries
"""
#
# (C) Pywikipedia bot team, 2007-08
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id: $'

from api import APIError

class LogEntry(object):
    """Generic log entry"""
    def __init__(self, apidata):
        """Initialize object from a logevent dict returned by MW API"""
        raise NotImplementedError(self.__class__)

class BlockEntry(LogEntry):
    pass

class ProtectEntry(LogEntry):
    pass

class RightsEntry(LogEntry):
    pass

class DeleteEntry(LogEntry):
    pass

class UploadEntry(LogEntry):
    pass

class MoveEntry(LogEntry):
    pass

class ImportEntry(LogEntry):
    pass

class PatrolEntry(LogEntry):
    pass

class NewUsersEntry(LogEntry):
    pass

#TODO entries for merge,suppress,makebot,gblblock,renameuser,globalauth,gblrights ?


_logtypes = {
    'block':BlockEntry,
    'protect':ProtectEntry,
    'rights':RightsEntry,
    'delete':DeleteEntry,
    'upload':UploadEntry,
    'move':MoveEntry,
    'import':ImportEntry,
    'patrol':PatrolEntry,
    'newusers':NewUsersEntry
}

def _getEntryClass(logtype):
    """
    Returns the class corresponding to the @logtype string parameter.
    Returns LogEntry if logtype is unknown or not supported
    """
    try:
        return _logtypes[logtype]
    except KeyError:
        return LogEntry

class LogEntryFactory(object):
    """
    LogEntry Factory

    Only available method is create()
    """
    def __init__(self, logtype=None):
        """
        @param logtype: The log type of the log entries, if known in advance.
                        If None, the Factory will fetch the log entry from
                        the data to create each object.
        @type logtype: (letype) str : move/block/patrol/etc...
        """
        if logtype is None:
            self._creator = self._createFromData
        else:
            # Bind a Class object to self._creator:
            # When called, it will initialize a new object of that class
            self._creator = _getEntryClass(logtype)

    def create(self, logdata):
        """
        Instantiates the LogEntry object representing logdata
        @param logdata: <item> returned by the api
        @type logdata: dict

        @return LogEntry object representing logdata
        """
        return self._creator(logdata)

    def _createFromData(self, logdata):
        """
        Checks for logtype from data, and creates the correct LogEntry
        """
        try:
            logtype = logdata['type'] 
            return _getEntryClass(logtype)(logdata)
        except KeyError:
            raise APIError("Log entry has no 'type' key")<commit_msg>APIError is not appropriate here '-_-<commit_after># -*- coding: utf-8  -*-
"""
Objects representing Mediawiki log entries
"""
#
# (C) Pywikipedia bot team, 2007-08
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id: $'

from pywikibot.exceptions import *

class LogEntry(object):
    """Generic log entry"""
    def __init__(self, apidata):
        """Initialize object from a logevent dict returned by MW API"""
        raise NotImplementedError(self.__class__)

class BlockEntry(LogEntry):
    pass

class ProtectEntry(LogEntry):
    pass

class RightsEntry(LogEntry):
    pass

class DeleteEntry(LogEntry):
    pass

class UploadEntry(LogEntry):
    pass

class MoveEntry(LogEntry):
    pass

class ImportEntry(LogEntry):
    pass

class PatrolEntry(LogEntry):
    pass

class NewUsersEntry(LogEntry):
    pass

#TODO entries for merge,suppress,makebot,gblblock,renameuser,globalauth,gblrights ?


_logtypes = {
    'block':BlockEntry,
    'protect':ProtectEntry,
    'rights':RightsEntry,
    'delete':DeleteEntry,
    'upload':UploadEntry,
    'move':MoveEntry,
    'import':ImportEntry,
    'patrol':PatrolEntry,
    'newusers':NewUsersEntry
}

def _getEntryClass(logtype):
    """
    Returns the class corresponding to the @logtype string parameter.
    Returns LogEntry if logtype is unknown or not supported
    """
    try:
        return _logtypes[logtype]
    except KeyError:
        return LogEntry

class LogEntryFactory(object):
    """
    LogEntry Factory

    Only available method is create()
    """
    def __init__(self, logtype=None):
        """
        @param logtype: The log type of the log entries, if known in advance.
                        If None, the Factory will fetch the log entry from
                        the data to create each object.
        @type logtype: (letype) str : move/block/patrol/etc...
        """
        if logtype is None:
            self._creator = self._createFromData
        else:
            # Bind a Class object to self._creator:
            # When called, it will initialize a new object of that class
            self._creator = _getEntryClass(logtype)

    def create(self, logdata):
        """
        Instantiates the LogEntry object representing logdata
        @param logdata: <item> returned by the api
        @type logdata: dict

        @return LogEntry object representing logdata
        """
        return self._creator(logdata)

    def _createFromData(self, logdata):
        """
        Checks for logtype from data, and creates the correct LogEntry
        """
        try:
            logtype = logdata['type'] 
            return _getEntryClass(logtype)(logdata)
        except KeyError:
            raise Error("Log entry has no 'type' key")
{'fraction_non_alphanumeric': 0.09034495345866034, 'fraction_numerical': 0.0025552108048914036, 'mean_word_length': 2.6123928806855634, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4795989', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1533, 'n_words': 483}