utils¶
Utility package with various useful functions
-
steam.utils.
ip_from_int
(ip)¶ Convert IP to
int
Parameters: ip (str) – IP in dot-decimal notation Return type: int
-
steam.utils.
ip_to_int
(ip)¶ Convert
int
to IPParameters: ip (int) – int representing an IP Returns: IP in dot-decimal notation Return type: str
-
steam.utils.
chunks
(arr, size)¶ Splits a list into chunks
Parameters: Returns: generator object
Return type: generator
-
class
steam.utils.
WeakRefKeyDict
¶ Bases:
object
Pretends to be a dictionary. Use any object (even unhashable) as key and store a value. Once the object is garbage collected, the entry is destroyed automatically.
utils.appache¶
Appache file parsing examples:
>>> from steam.utils.appcache import parse_appinfo, parse_packageinfo
>>> header, apps = parse_appinfo(open('/d/Steam/appcache/appinfo.vdf', 'rb'))
>>> header
{'magic': b"'DV\x07", 'universe': 1}
>>> next(apps)
{'appid': 5,
'size': 79,
'info_state': 1,
'last_updated': 1484735377,
'access_token': 0,
'sha1': b'\x87\xfaCg\x85\x80\r\xb4\x90Im\xdc}\xb4\x81\xeeQ\x8b\x825',
'change_number': 4603827,
'data': {'appinfo': {'appid': 5, 'public_only': 1}}}
>>> header, pkgs = parse_packageinfo(open('/d/Steam/appcache/packageinfo.vdf', 'rb'))
>>> header
{'magic': b"'UV\x06", 'universe': 1}
>>> next(pkgs)
{'packageid': 7,
'sha1': b's\x8b\xf7n\t\xe5 k#\xb6-\x82\xd2 \x14k@\xfeDQ',
'change_number': 7469765,
'data': {'7': {'packageid': 7,
'billingtype': 1,
'licensetype': 1,
'status': 0,
'extended': {'requirespreapproval': 'WithRedFlag'},
'appids': {'0': 10, '1': 80, '2': 100, '3': 254430},
'depotids': {'0': 0, '1': 95, '2': 101, '3': 102, '4': 103, '5': 254431},
'appitems': {}}}}
utils.binary¶
-
class
steam.utils.binary.
StructReader
(data)¶ Bases:
object
Simplifies parsing of struct data from bytes
Parameters: data ( bytes
) – data bytes-
rlen
()¶ Number of remaining bytes that can be read
Returns: number of remaining bytes Return type: int
-
read
(n=1)¶ Return n bytes
Parameters: n ( int
) – number of bytes to returnReturns: bytes Return type: bytes
-
read_cstring
(terminator=b'\x00')¶ Reads a single null termianted string
Returns: string without bytes Return type: bytes
-
unpack
(format_text)¶ Unpack bytes using struct modules format
Parameters: format_text ( str
) – struct’s module formatReturn data: result from struct.unpack_from()
Return type: tuple
-
utils.proto¶
-
steam.utils.proto.
is_proto
(emsg)¶ Parameters: emsg (int) – emsg number Returns: True or False Return type: bool
-
steam.utils.proto.
set_proto_bit
(emsg)¶ Parameters: emsg (int) – emsg number Returns: emsg with proto bit set Return type: int
-
steam.utils.proto.
clear_proto_bit
(emsg)¶ Parameters: emsg (int) – emsg number Returns: emsg with proto bit removed Return type: int
-
steam.utils.proto.
proto_to_dict
(message)¶ Converts protobuf message instance to dict
Parameters: message – protobuf message instance Returns: parameters and their values Return type: dict Raises: TypeError
ifmessage
is not a proto message
utils.throttle¶
-
class
steam.utils.throttle.
ConstantRateLimit
(times, seconds, exit_wait=False, sleep_func=<built-in function sleep>)¶ Bases:
object
Context manager for enforcing constant rate on code inside the block .
rate = seconds / times
Parameters: Example:
with RateLimiter(1, 5) as r: # code taking 1s r.wait() # blocks for 4s # code taking 7s r.wait() # doesn't block # code taking 1s r.wait() # blocks for 4s
-
wait
()¶ Blocks until the rate is met
-
utils.web¶
-
steam.utils.web.
make_requests_session
()¶ Returns: requests session Return type: requests.Session