<commit_before>import inspect
from lampost.editor.scripts import validate_scripts

from lampost.server.handlers import MethodHandler, SessionHandler
from lampost.context.resource import m_requires
from lampost.datastore.classes import get_dbo_class
from lampost.datastore.exceptions import DataError


m_requires(__name__, 'log', 'datastore', 'dispatcher', 'perm', 'edit_notify_service')

obj_defaults = {}


class Editor(MethodHandler):
    parent_type = None
    children_types = None

    def prepare(self):
        super().prepare()
        check_perm(self.player, self)

    def initialize(self, obj_class, imm_level='builder'):
        self.obj_class = obj_class
        self.imm_level = imm_level
        self.dbo_key_type = obj_class.dbo_key_type
        if hasattr(obj_class, 'dbo_children_types'):
            self.children_types = obj_class.dbo_children_types

    def list(self):
        return [self._edit_dto(obj) for obj in load_object_set(self.obj_class) if obj.can_read(self.player)]

    def create(self):
        self.raw['owner_id'] = self.session.player.dbo_id
        self._pre_create()
        if has_perm(self.play, 'admin'):
            validate_scripts(self.raw)
        new_obj = create_object(self.obj_class, self.raw)
        self._post_create(new_obj)
        return publish_edit('create', new_obj, self.session)

    def delete_obj(self):
        del_obj = load_object(self.raw['dbo_id'], self.obj_class)
        if not del_obj:
            raise DataError('Gone: Object with key {} does not exist'.format(self.raw['dbo_id']))
        check_perm(self.player, del_obj)
        self._pre_delete(del_obj)
        holder_keys = fetch_set_keys('{}:holders'.format(del_obj.dbo_key))
        for dbo_key in holder_keys:
            cached_holder = load_cached(dbo_key)
            if cached_holder:
                save_object(cached_holder)
        delete_object(del_obj)
        for dbo_key in holder_keys:
            reloaded = reload_object(dbo_key)
            if reloaded:
                publish_edit('update', reloaded, self.session, True)
        self._post_delete(del_obj)
        publish_edit('delete', del_obj, self.session)

    def update(self):
        existing_obj = load_object(self.raw['dbo_id'], self.obj_class)
        if not existing_obj:
            raise DataError("GONE:  Object with key {} no longer exists.".format(self.raw['dbo.id']))
        check_perm(self.player, existing_obj)
        self._pre_update(existing_obj)<commit_msg>Fixed a blocking typo in method Editor.create()<commit_after>import inspect
from lampost.editor.scripts import validate_scripts

from lampost.server.handlers import MethodHandler, SessionHandler
from lampost.context.resource import m_requires
from lampost.datastore.classes import get_dbo_class
from lampost.datastore.exceptions import DataError


m_requires(__name__, 'log', 'datastore', 'dispatcher', 'perm', 'edit_notify_service')

obj_defaults = {}


class Editor(MethodHandler):
    parent_type = None
    children_types = None

    def prepare(self):
        super().prepare()
        check_perm(self.player, self)

    def initialize(self, obj_class, imm_level='builder'):
        self.obj_class = obj_class
        self.imm_level = imm_level
        self.dbo_key_type = obj_class.dbo_key_type
        if hasattr(obj_class, 'dbo_children_types'):
            self.children_types = obj_class.dbo_children_types

    def list(self):
        return [self._edit_dto(obj) for obj in load_object_set(self.obj_class) if obj.can_read(self.player)]

    def create(self):
        self.raw['owner_id'] = self.session.player.dbo_id
        self._pre_create()
        if has_perm(self.player, 'admin'):
            validate_scripts(self.raw)
        new_obj = create_object(self.obj_class, self.raw)
        self._post_create(new_obj)
        return publish_edit('create', new_obj, self.session)

    def delete_obj(self):
        del_obj = load_object(self.raw['dbo_id'], self.obj_class)
        if not del_obj:
            raise DataError('Gone: Object with key {} does not exist'.format(self.raw['dbo_id']))
        check_perm(self.player, del_obj)
        self._pre_delete(del_obj)
        holder_keys = fetch_set_keys('{}:holders'.format(del_obj.dbo_key))
        for dbo_key in holder_keys:
            cached_holder = load_cached(dbo_key)
            if cached_holder:
                save_object(cached_holder)
        delete_object(del_obj)
        for dbo_key in holder_keys:
            reloaded = reload_object(dbo_key)
            if reloaded:
                publish_edit('update', reloaded, self.session, True)
        self._post_delete(del_obj)
        publish_edit('delete', del_obj, self.session)

    def update(self):
        existing_obj = load_object(self.raw['dbo_id'], self.obj_class)
        if not existing_obj:
            raise DataError("GONE:  Object with key {} no longer exists.".format(self.raw['dbo.id']))
        check_perm(self.player, existing_obj)
        self._pre_update(existing_obj)
{'fraction_non_alphanumeric': 0.10015993602558976, 'fraction_numerical': 0.0, 'mean_word_length': 3.1008196721311476, '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': '4116912', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1541, 'n_words': 303}