<commit_before>"""
    inventory
"""
from __future__ import absolute_import, division, print_function
import contextlib
import logging
from mcedit2.command import SimpleRevisionCommand
from mceditlib import nbt

from PySide import QtGui, QtCore
from PySide.QtCore import Qt
import itertools

from mcedit2.widgets.itemtype_list import ItemTypeListModel, ItemTypeIcon, ICON_SIZE
from mcedit2.widgets.layout import Row, Column
from mcedit2.widgets.nbttree.nbteditor import NBTEditorWidget
from mceditlib.blocktypes import VERSION_1_7, VERSION_1_8


log = logging.getLogger(__name__)


class InventoryItemModel(QtCore.QAbstractItemModel):
    ItemIDRole = Qt.UserRole
    ItemRawIDRole = ItemIDRole + 1
    ItemIconRole = ItemRawIDRole + 1
    ItemDamageRole = ItemIconRole + 1
    ItemCountRole = ItemDamageRole + 1

    def __init__(self, itemListRef, editorSession):
        super(InventoryItemModel, self).__init__()
        assert editorSession is not None
        self.editorSession = editorSession
        self.itemListRef = itemListRef
        self.textureCache = {}

    def index(self, slot, parentIndex=QtCore.QModelIndex()):
        if parentIndex.isValid():
            return QtCore.QModelIndex()
        return self.createIndex(slot, 0)

    def rowCount(self, parent):
        # slot numbers are defined by the view's slotLayout
        # maybe that should be the model's slotLayout instead
        return 0

    def data(self, index, role):
        if not index.isValid():
            return 0

        slot = index.row()
        itemStack = self.itemListRef.getItemInSlot(slot)
        if itemStack is None:
            return None
        try:
            itemType = itemStack.itemType
        except ValueError as e:  # itemType not mapped
            return None
        except KeyError as e:  # missing NBT tag?
            log.exception("Error while reading item data: %r", e)
            return None

        if role == self.ItemIconRole:
            return ItemTypeIcon(itemType, self.editorSession, itemStack)

        if role == self.ItemIDRole:
            return itemStack.id
        if role == self.ItemRawIDRole:
            return itemStack.raw_id
        if role == self.ItemCountRole:
            return itemStack.Count
        if role == self.ItemDamageRole:
            return itemStack.Damage

        return None

    def setData(self, index, value, role):<commit_msg>Don't return None for all data roles when the itemType can't be found - it's only needed for the icon<commit_after>"""
    inventory
"""
from __future__ import absolute_import, division, print_function
import contextlib
import logging
from mcedit2.command import SimpleRevisionCommand
from mceditlib import nbt

from PySide import QtGui, QtCore
from PySide.QtCore import Qt
import itertools

from mcedit2.widgets.itemtype_list import ItemTypeListModel, ItemTypeIcon, ICON_SIZE
from mcedit2.widgets.layout import Row, Column
from mcedit2.widgets.nbttree.nbteditor import NBTEditorWidget
from mceditlib.blocktypes import VERSION_1_7, VERSION_1_8


log = logging.getLogger(__name__)


class InventoryItemModel(QtCore.QAbstractItemModel):
    ItemIDRole = Qt.UserRole
    ItemRawIDRole = ItemIDRole + 1
    ItemIconRole = ItemRawIDRole + 1
    ItemDamageRole = ItemIconRole + 1
    ItemCountRole = ItemDamageRole + 1

    def __init__(self, itemListRef, editorSession):
        super(InventoryItemModel, self).__init__()
        assert editorSession is not None
        self.editorSession = editorSession
        self.itemListRef = itemListRef
        self.textureCache = {}

    def index(self, slot, parentIndex=QtCore.QModelIndex()):
        if parentIndex.isValid():
            return QtCore.QModelIndex()
        return self.createIndex(slot, 0)

    def rowCount(self, parent):
        # slot numbers are defined by the view's slotLayout
        # maybe that should be the model's slotLayout instead
        return 0

    def data(self, index, role):
        if not index.isValid():
            return 0

        slot = index.row()
        itemStack = self.itemListRef.getItemInSlot(slot)
        if itemStack is None:
            return None

        if role == self.ItemIconRole:
            try:
                itemType = itemStack.itemType
            except ValueError as e:  # itemType not mapped
                return None
            except KeyError as e:  # missing NBT tag?
                log.exception("Error while reading item data: %r", e)
                return None
            return ItemTypeIcon(itemType, self.editorSession, itemStack)

        if role == self.ItemIDRole:
            return itemStack.id
        if role == self.ItemRawIDRole:
            return itemStack.raw_id
        if role == self.ItemCountRole:
            return itemStack.Count
        if role == self.ItemDamageRole:
            return itemStack.Damage

        return None

    def setData(self, index, value, role):
{'fraction_non_alphanumeric': 0.06626016260162601, 'fraction_numerical': 0.006097560975609756, 'mean_word_length': 2.647887323943662, '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': '105097', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1355, 'n_words': 413}