7 changed files with 217 additions and 64 deletions
@ -1 +1,23 @@ |
|||||
|
"""This module contains various value enumerations. |
||||
|
|
||||
|
They are all based on :py:class:`IntEnum`, which gives them :py:class:`int` properties. |
||||
|
They can be compared to :py:class:`int` and used in places there :py:class:`int` is required. |
||||
|
Like for example, protobuf message. |
||||
|
They also provide a easy way to resolve a name or value for a specific enum. |
||||
|
|
||||
|
.. code:: python |
||||
|
|
||||
|
>>> EResult.OK |
||||
|
<EResult.OK: 1> |
||||
|
>>> EResult(1) |
||||
|
<EResult.OK: 1> |
||||
|
>>> EResult['OK'] |
||||
|
<EResult.OK: 1> |
||||
|
>>> EResult.OK == 1 |
||||
|
True |
||||
|
|
||||
|
.. note:: |
||||
|
all enums from :py:mod:`steam.enum.common` can be imported directly from :py:mod:`steam.enum` |
||||
|
""" |
||||
|
|
||||
from steam.enums.common import EResult, EType, EUniverse, EServerType |
from steam.enums.common import EResult, EType, EUniverse, EServerType |
||||
|
@ -1,23 +1,56 @@ |
|||||
|
"""Utility package with various useful functions |
||||
|
""" |
||||
|
|
||||
import struct |
import struct |
||||
import socket |
import socket |
||||
|
|
||||
|
|
||||
def ip_from_int(ip): |
def ip_from_int(ip): |
||||
|
"""Convert IP to :py:class:`int` |
||||
|
|
||||
|
:param ip: IP in dot-decimal notation |
||||
|
:type ip: str |
||||
|
:rtype: int |
||||
|
""" |
||||
return socket.inet_ntoa(struct.pack(">L", ip)) |
return socket.inet_ntoa(struct.pack(">L", ip)) |
||||
|
|
||||
def ip_to_int(ip): |
def ip_to_int(ip): |
||||
|
"""Convert :py:class:`int` to IP |
||||
|
|
||||
|
:param ip: int representing an IP |
||||
|
:type ip: int |
||||
|
:return: IP in dot-decimal notation |
||||
|
:rtype: str |
||||
|
""" |
||||
return struct.unpack(">L", socket.inet_aton(ip))[0] |
return struct.unpack(">L", socket.inet_aton(ip))[0] |
||||
|
|
||||
|
|
||||
protobuf_mask = 0x80000000 |
protobuf_mask = 0x80000000 |
||||
|
|
||||
def is_proto(emsg): |
def is_proto(emsg): |
||||
|
""" |
||||
|
:param emsg: emsg number |
||||
|
:type emsg: int |
||||
|
:return: True or False |
||||
|
:rtype: bool |
||||
|
""" |
||||
return (int(emsg) & protobuf_mask) > 0 |
return (int(emsg) & protobuf_mask) > 0 |
||||
|
|
||||
def set_proto_bit(emsg): |
def set_proto_bit(emsg): |
||||
|
""" |
||||
|
:param emsg: emsg number |
||||
|
:type emsg: int |
||||
|
:return: emsg with proto bit set |
||||
|
:rtype: int |
||||
|
""" |
||||
return int(emsg) | protobuf_mask |
return int(emsg) | protobuf_mask |
||||
|
|
||||
def clear_proto_bit(emsg): |
def clear_proto_bit(emsg): |
||||
|
""" |
||||
|
:param emsg: emsg number |
||||
|
:type emsg: int |
||||
|
:return: emsg with proto bit removed |
||||
|
:rtype: int |
||||
|
""" |
||||
return int(emsg) & ~protobuf_mask |
return int(emsg) & ~protobuf_mask |
||||
|
|
||||
|
|
||||
|
Loading…
Reference in new issue