<commit_before>import steam, urllib2
import cPickle as pickle
from optf2.backend import database
from optf2.backend import items as itemtools
from optf2.frontend.markup import generate_mode_url
import web
import time
import config
import template

templates = template.template

class loadout:
    """ User loadout lists """

    def GET(self, game, user):
        web.ctx.current_game = game
        web.ctx.current_user = user
        try:
            userp = database.load_profile_cached(user)
            items = itemtools.process_attributes(database.load_pack_cached(userp))
            equippeditems = {}
            schema = database.load_schema_cached(web.ctx.language)
            valid_classes = schema.get_classes().values()
            slotlist = ["Head", "Misc", "Primary", "Secondary", "Melee", "Pda", "Pda2", "Building", "Action"]

            normalitems = itemtools.process_attributes(itemtools.filter_by_quality(schema, "0"))
            for item in normalitems:
                classes = item.get_equipable_classes()
                for c in classes:
                    if c not in equippeditems:
                        equippeditems[c] = {}

                    slot = item.get_slot().title()
                    if slot not in slotlist: slotlist.append(slot)
                    if slot not in equippeditems[c]:
                        equippeditems[c][slot] = []

                    equippeditems[c][slot].append(item)

            for item in items:
                classes = item.get_equipped_classes()
                for c in classes:
                    if c not in equippeditems: equippeditems[c] = {}
                    # WORKAROUND: There is one unique shotgun for all classes, and it's in the primary slot. This
                    # has obvious problems
                    if item.get_schema_id() == 199 and c != "Engineer":
                        slot = "Secondary"
                    else:
                        slot = item.get_slot().title()
                    if slot not in slotlist: slotlist.append(slot)
                    if slot not in equippeditems[c] or equippeditems[c][slot][0].get_quality()["id"] == 0:
                        equippeditems[c][slot] = []
                    equippeditems[c][slot].append(item)

            return templates.loadout(userp, equippeditems, valid_classes, slotlist)
        except steam.items.Error as E:
            return templates.error("Backpack error: {0}".format(E))
        except steam.user.ProfileError as E:
            return templates.error("Profile error: {0}".format(E))
        except:
            return templates.error("Couldn't load loadout page")

class item:
    def GET(self, app, iid):
        web.ctx.current_game = app
        schema = database.load_schema_cached(web.ctx.language)
        user = None
        item_outdated = False
        try:
            theitem = schema[long(iid)]

            item = itemtools.process_attributes([theitem])[0]
            if web.input().get("contents"):
                itemcontents = item.optf2.get("contents")
                if itemcontents:
                    newitem = itemtools.process_attributes([itemcontents], gift = True)[0]
                    newitem.optf2 = dict(item.optf2, **newitem.optf2)
                    newitem.optf2["container_id"] = item.get_id()
                    item = newitem
        except urllib2.URLError:
            return templates.error("Couldn't connect to Steam")
        except:
            return templates.item_error_notfound(iid)
        return templates.item(user, item, item_outdated)

class live_item:
    """ More or less temporary until database stuff is sorted """
    def GET(self, app, user, iid):
        web.ctx.current_game = app
        web.ctx["current_user"] = user
        user = database.load_profile_cached(user)
        item_outdated = False
        try:
            items = database.load_pack_cached(user)
            theitem = None
            for item in items:
                if item.get_id() == long(iid):<commit_msg>Fix ID match errors showing up in log with traceback<commit_after>import steam, urllib2
import cPickle as pickle
from optf2.backend import database
from optf2.backend import items as itemtools
from optf2.frontend.markup import generate_mode_url
import web
import time
import config
import template

templates = template.template

class loadout:
    """ User loadout lists """

    def GET(self, game, user):
        web.ctx.current_game = game
        web.ctx.current_user = user
        try:
            userp = database.load_profile_cached(user)
            items = itemtools.process_attributes(database.load_pack_cached(userp))
            equippeditems = {}
            schema = database.load_schema_cached(web.ctx.language)
            valid_classes = schema.get_classes().values()
            slotlist = ["Head", "Misc", "Primary", "Secondary", "Melee", "Pda", "Pda2", "Building", "Action"]

            normalitems = itemtools.process_attributes(itemtools.filter_by_quality(schema, "0"))
            for item in normalitems:
                classes = item.get_equipable_classes()
                for c in classes:
                    if c not in equippeditems:
                        equippeditems[c] = {}

                    slot = item.get_slot().title()
                    if slot not in slotlist: slotlist.append(slot)
                    if slot not in equippeditems[c]:
                        equippeditems[c][slot] = []

                    equippeditems[c][slot].append(item)

            for item in items:
                classes = item.get_equipped_classes()
                for c in classes:
                    if c not in equippeditems: equippeditems[c] = {}
                    # WORKAROUND: There is one unique shotgun for all classes, and it's in the primary slot. This
                    # has obvious problems
                    if item.get_schema_id() == 199 and c != "Engineer":
                        slot = "Secondary"
                    else:
                        slot = item.get_slot().title()
                    if slot not in slotlist: slotlist.append(slot)
                    if slot not in equippeditems[c] or equippeditems[c][slot][0].get_quality()["id"] == 0:
                        equippeditems[c][slot] = []
                    equippeditems[c][slot].append(item)

            return templates.loadout(userp, equippeditems, valid_classes, slotlist)
        except steam.items.Error as E:
            return templates.error("Backpack error: {0}".format(E))
        except steam.user.ProfileError as E:
            return templates.error("Profile error: {0}".format(E))
        except:
            return templates.error("Couldn't load loadout page")

class item:
    def GET(self, app, iid):
        web.ctx.current_game = app
        schema = database.load_schema_cached(web.ctx.language)
        user = None
        item_outdated = False
        try:
            theitem = schema[long(iid)]

            item = itemtools.process_attributes([theitem])[0]
            if web.input().get("contents"):
                itemcontents = item.optf2.get("contents")
                if itemcontents:
                    newitem = itemtools.process_attributes([itemcontents], gift = True)[0]
                    newitem.optf2 = dict(item.optf2, **newitem.optf2)
                    newitem.optf2["container_id"] = item.get_id()
                    item = newitem
        except urllib2.URLError:
            return templates.error("Couldn't connect to Steam")
        except:
            return templates.item_error_notfound(iid)
        return templates.item(user, item, item_outdated)

class live_item:
    """ More or less temporary until database stuff is sorted """
    def GET(self, app, user, iid):
        web.ctx.current_game = app
        web.ctx["current_user"] = user
        item_outdated = False
        try:
            user = database.load_profile_cached(user)
            items = database.load_pack_cached(user)
            theitem = None
            for item in items:
                if item.get_id() == long(iid):
{'fraction_non_alphanumeric': 0.095425964739243, 'fraction_numerical': 0.005178153125385279, 'mean_word_length': 1.8847795163584637, 'pattern_counts': {'":': 2, '<': 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': '7209826', 'n_tokens_mistral': 2213, 'n_tokens_neox': 2122, 'n_words': 554}