util¶
Utility package with various useful functions
-
steam.util.
ip_from_int
(ip)¶ Convert IP to
int
Parameters: ip (str) – IP in dot-decimal notation Return type: int
-
steam.util.
ip_to_int
(ip)¶ Convert
int
to IPParameters: ip (int) – int representing an IP Returns: IP in dot-decimal notation Return type: str
-
steam.util.
is_proto
(emsg)¶ Parameters: emsg (int) – emsg number Returns: True or False Return type: bool
-
steam.util.
set_proto_bit
(emsg)¶ Parameters: emsg (int) – emsg number Returns: emsg with proto bit set Return type: int
-
steam.util.
clear_proto_bit
(emsg)¶ Parameters: emsg (int) – emsg number Returns: emsg with proto bit removed Return type: int
-
steam.util.
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
-
steam.util.
proto_fill_from_dict
(message, data, clear=True)¶ Fills protobuf message parameters inplace from a
dict
Parameters: Returns: value of message paramater
Raises: incorrect types or values will raise
-
steam.util.
chunks
(arr, size)¶ Splits a list into chunks
Parameters: Returns: generator object
Return type: generator
-
class
steam.util.
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.
util.binary¶
-
class
steam.util.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
-
util.throttle¶
-
class
steam.util.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
-