Browse Source

SteamID: updated steam2 format

* as_steam2 will now return the new format
* added as_steam2_zero format for goldsrc and orange box
* updated tests and docs
pull/18/merge
Rossen Georgiev 9 years ago
parent
commit
ddb2fa3261
  1. 27
      steam/steamid.py
  2. 12
      tests/test_steamid.py

27
steam/steamid.py

@ -102,14 +102,32 @@ class SteamID(int):
@property
def as_steam2(self):
"""
:return: steam2 format (e.g ``STEAM_0:0:1234``)
:return: steam2 format (e.g ``STEAM_1:0:1234``)
:rtype: str
.. note::
``STEAM_X:Y:Z``. The value of ``X`` should represent the universe, or ``1``
for ``Public``. However, there was a bug in GoldSrc and Orange Box games
and ``X`` was ``0``. If you need that format use :attr:`SteamID.as_steam2_zero`
"""
return "STEAM_0:%s:%s" % (
return "STEAM_1:%s:%s" % (
self.id % 2,
self.id >> 1,
)
@property
def as_steam2_zero(self):
"""
For GoldSrc and Orange Box games.
See :attr:`SteamID.as_steam2`
:return: steam2 format (e.g ``STEAM_0:0:1234``)
:rtype: str
"""
return self.as_steam2.replace("_1", "_0")
@property
def as_steam3(self):
"""
@ -242,10 +260,13 @@ def make_steam64(id=0, *args, **kwargs):
def steam2_to_tuple(value):
"""
:param value: steam2 (e.g. ``STEAM_0:0:1234``)
:param value: steam2 (e.g. ``STEAM_1:0:1234`)
:type value: str
:return: (accountid, type, universe, instance)
:rtype: ``tuple`` or ``None``
.. note::
The universe will be always set to ``1``. See :attr:`SteamID.as_steam2`
"""
match = re.match(r"^STEAM_(?P<universe>[01])"
r":(?P<reminder>[0-1])"

12
tests/test_steamid.py

@ -196,8 +196,16 @@ class SteamID_properties(unittest.TestCase):
self.assertEqual(str(SteamID(76580280500085312)), '76580280500085312')
def test_as_steam2(self):
self.assertEqual(SteamID('STEAM_0:1:4').as_steam2, 'STEAM_0:1:4')
self.assertEqual(SteamID('STEAM_1:1:4').as_steam2, 'STEAM_0:1:4')
self.assertEqual(SteamID('STEAM_0:1:4').as_steam2, 'STEAM_1:1:4')
self.assertEqual(SteamID('STEAM_1:1:4').as_steam2, 'STEAM_1:1:4')
self.assertEqual(SteamID('STEAM_0:0:4').as_steam2, 'STEAM_1:0:4')
self.assertEqual(SteamID('STEAM_1:0:4').as_steam2, 'STEAM_1:0:4')
def test_as_steam2_zero(self):
self.assertEqual(SteamID('STEAM_0:1:4').as_steam2_zero, 'STEAM_0:1:4')
self.assertEqual(SteamID('STEAM_1:1:4').as_steam2_zero, 'STEAM_0:1:4')
self.assertEqual(SteamID('STEAM_0:0:4').as_steam2_zero, 'STEAM_0:0:4')
self.assertEqual(SteamID('STEAM_1:0:4').as_steam2_zero, 'STEAM_0:0:4')
def test_as_steam3(self):
self.assertEqual(SteamID('[U:1:1234]').as_steam3, '[U:1:1234]')

Loading…
Cancel
Save