Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def GET(self, user):
baseurl = user.strip('/').split('/')
if len(baseurl) > 0:
user = baseurl[-1]
if not user: raise steam.items.InventoryError("Need an ID")
try:
prof = database.user(user).load()
ctx = database.sim_context(prof).load()
return templates.sim_selector(prof, ctx)
except steam.items.InventoryError as E:
raise web.NotFound(error_page.generic("Failed to load backpack ({0})".format(E)))
except steam.user.ProfileError as E:
raise web.NotFound(error_page.generic("Failed to load profile ({0})".format(E)))
except steam.api.HTTPError as E:
raise web.NotFound(error_page.generic("Couldn't connect to Steam (HTTP {0})".format(E)))
except database.CacheEmptyError as E:
raise web.NotFound(error_page.generic(E))
def GET(self, user):
baseurl = user.strip('/').split('/')
if len(baseurl) > 0:
user = baseurl[-1]
if not user:
raise steam.items.InventoryError("Need an ID")
try:
prof = models.user(user).load()
ctx = models.sim_context(prof).load()
for ct in (ctx or []):
ct.setdefault("inventory_logo", '')
return template.sim_selector(prof, ctx)
except steam.items.InventoryError as E:
raise web.NotFound(template.errors.generic("Failed to load backpack ({0})".format(E)))
except steam.user.ProfileError as E:
raise web.NotFound(template.errors.generic("Failed to load profile ({0})".format(E)))
except steam.api.HTTPError as E:
raise web.NotFound(template.errors.generic("Couldn't connect to Steam (HTTP {0})".format(E)))
except models.CacheEmptyError as E:
raise web.NotFound(template.errors.generic(E))
def __init__(self, app, profile, schema=None, section=None, timeout=None, lang=None):
"""
app is context data as returned by 'inventory_context.get'
profile is a valid user object or ID64
"""
self._cache = {}
self._section = section
self._ctx = app
self._timeout = timeout or api.socket_timeout.get()
self._language = loc.language(lang).name.lower()
if not app:
raise items.InventoryError("No inventory available")
try:
sid = profile.id64
except AttributeError:
sid = profile
self._user = sid
def __init__(self, app, profile, schema = None, section = None, timeout = None):
"""
app is context data as returned by 'inventory_context.get'
profile is a valid user object or ID64
"""
self._cache = {}
self._section = section
self._ctx = app
self._timeout = timeout or api.socket_timeout.get()
if not app:
raise items.InventoryError("No inventory available")
try:
sid = profile.id64
except AttributeError:
sid = profile
self._user = sid
for sec in downloadlist:
page_url = url + sec
if self._language:
page_url += "?l=" + self._language
req = api.http_downloader(page_url, timeout=self._timeout)
inventorysection = json.loads(req.download().decode("utf-8"))
if not inventorysection:
raise items.InventoryError("Empty context data returned")
try:
itemdescs = inventorysection["rgDescriptions"]
except KeyError:
raise items.InventoryError("Steam returned inventory with missing context")
inv = inventorysection.get("rgInventory")
if not inv:
continue
for id, item in inv.items():
# Store the section ID for later use
item["sec"] = sec
item.update(itemdescs.get(item["classid"] + "_" + item["instanceid"], {}))
merged_items.append(item)
self._cache = {"cells": cellcount, "items": merged_items}
return self._cache
def ctx(self):
if self._cache:
return self._cache
try:
data = self._downloader.download()
contexts = re.search("var g_rgAppContextData = (.+);",
data.decode("utf-8"))
match = contexts.group(1)
self._cache = json.loads(match)
except:
raise items.InventoryError("No SIM inventory information available for this user")
return self._cache
if self._cache:
return self._cache
status = None
try:
status = self._api["result"]["status"]
items = self._api["result"]["items"]
except KeyError:
# Only try to check status code if items don't exist (why error out when items are there)
if status is not None:
if status == 8:
raise BadID64Error("Bad Steam ID64 given")
elif status == 15:
raise ProfilePrivateError("Profile is private")
raise InventoryError("Backpack data incomplete or corrupt")
self._cache = {
"items": items,
"cells": self._api["result"].get("num_backpack_slots", len(items))
}
return self._cache
pass
class AssetError(api.APIError):
pass
class InventoryError(api.APIError):
pass
class BadID64Error(InventoryError):
pass
class ProfilePrivateError(InventoryError):
pass
class schema(object):
""" Wrapper for item schema of certain games from Valve. Those are currently
available (along with their ids):
* ``260`` - Counter Strike: Source Beta
* ``440`` - Team Fortress 2
* ``520`` - Team Fortress 2 Public Beta
* ``570`` - Dota 2
* ``620`` - Portal 2
* ``710`` - Counter-Strike: Global Offensive Beta Dev
* ``816`` - Dota 2 internal test
* ``841`` - Portal 2 Beta
* ``205790`` - Dota 2 (beta) test
return self._cache
status = None
try:
status = self._api["result"]["status"]
items = self._api["result"]["items"]
except KeyError:
# Only try to check status code if items don't exist (why error out
# when items are there)
if status is not None:
if status == 8:
raise BadID64Error("Bad Steam ID64 given")
elif status == 15:
raise ProfilePrivateError("Profile is private")
raise InventoryError("Backpack data incomplete or corrupt")
self._cache = {
"items": items,
"cells": self._api["result"].get("num_backpack_slots", len(items))
}
return self._cache