From 6f97b3a9767f00c94ddcc7e84c2e5510b4bde222 Mon Sep 17 00:00:00 2001 From: WinterPhoenix Date: Fri, 13 Sep 2024 00:20:13 -0400 Subject: [PATCH] - Drop Python 2 support and only support 3.6+ - Update contact info --- recipes/3.WalletBalance/wallet_webauth.py | 12 ++++-------- setup.py | 16 ++++++---------- steam/client/__init__.py | 8 -------- steam/client/builtins/friends.py | 3 +-- steam/client/cdn.py | 18 ++++++------------ steam/core/crypto.py | 6 +----- steam/core/msg/structs.py | 7 +------ steam/globalid.py | 8 +------- steam/steamid.py | 7 +------ steam/utils/__init__.py | 8 +------- steam/utils/proto.py | 9 +-------- steam/utils/throttle.py | 11 ++--------- steam/webauth.py | 15 ++------------- tests/generete_webauth_vcr.py | 6 +----- 14 files changed, 28 insertions(+), 106 deletions(-) diff --git a/recipes/3.WalletBalance/wallet_webauth.py b/recipes/3.WalletBalance/wallet_webauth.py index b1a2f895..44b1a6f1 100755 --- a/recipes/3.WalletBalance/wallet_webauth.py +++ b/recipes/3.WalletBalance/wallet_webauth.py @@ -2,12 +2,8 @@ from getpass import getpass import steam.webauth as wa -try: - user_input = raw_input -except NameError: - user_input = input -username = user_input("Username: ") +username = input("Username: ") password = getpass("Password: ") webclient = wa.WebAuth(username, password) @@ -16,11 +12,11 @@ webclient.login() except wa.CaptchaRequired: print("Captcha:" + webclient.captcha_url) - webclient.login(captcha=user_input("Captcha code: ")) + webclient.login(captcha=input("Captcha code: ")) except wa.EmailCodeRequired: - webclient.login(email_code=user_input("Email code: ")) + webclient.login(email_code=input("Email code: ")) except wa.TwoFactorCodeRequired: - webclient.login(twofactor_code=user_input("2FA code: ")) + webclient.login(twofactor_code=input("2FA code: ")) if webclient.complete: resp = webclient.session.get('https://store.steampowered.com/account/store_transactions/') diff --git a/setup.py b/setup.py index 1a3d8cc7..766100cc 100644 --- a/setup.py +++ b/setup.py @@ -14,21 +14,17 @@ __version__ = f.readline().split('"')[1] install_requires = [ - 'six>=1.10', 'pycryptodomex>=3.7.0', 'requests>=2.9.1', 'urllib3<2', 'vdf>=3.3', 'cachetools>=3.0.0', - "win-inet-pton; python_version == '2.7' and sys_platform == 'win32'", - "enum34==1.1.2; python_version < '3.4'", ] install_extras = { 'client': [ 'gevent>=1.3.0', - 'protobuf~=3.0; python_version >= "3"', - 'protobuf<3.18.0; python_version < "3"', + 'protobuf~=3.0', 'gevent-eventemitter~=2.1', ], } @@ -38,24 +34,24 @@ version=__version__, description='Module for interacting with various Steam features', long_description=long_description, - url='https://github.com/ValvePython/steam', - author="Rossen Georgiev", - author_email='rossen@rgp.io', + url='https://github.com/solsticegamestudios/steam', + author="Rossen Georgiev / Solstice Game Studios", + author_email='py-steam@solsticegamestudios.com', license='MIT', + python_requires=">=3.6", classifiers=[ 'Development Status :: 5 - Production/Stable', 'Natural Language :: English', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Programming Language :: Python :: Implementation :: PyPy', ], keywords='valve steam steamid api webapi steamcommunity', diff --git a/steam/client/__init__.py b/steam/client/__init__.py index 664dd4cc..e91a9380 100644 --- a/steam/client/__init__.py +++ b/steam/client/__init__.py @@ -20,7 +20,6 @@ from io import open from getpass import getpass import logging -import six from eventemitter import EventEmitter from steam.enums import EResult, EOSType, EPersonaState @@ -35,13 +34,6 @@ from steam.utils.proto import proto_fill_from_dict -# TODO: remove py2 support. -if six.PY2: - _cli_input = raw_input -else: - _cli_input = input - - class SteamClient(CMClient, BuiltinBase): EVENT_LOGGED_ON = 'logged_on' """After successful login""" diff --git a/steam/client/builtins/friends.py b/steam/client/builtins/friends.py index 6282bf67..7d3e4795 100644 --- a/steam/client/builtins/friends.py +++ b/steam/client/builtins/friends.py @@ -1,5 +1,4 @@ import logging -from six import itervalues from eventemitter import EventEmitter from steam.steamid import SteamID, intBase from steam.enums import EResult, EFriendRelationship @@ -129,7 +128,7 @@ def __len__(self): return len(self._fr) def __iter__(self): - return itervalues(self._fr) + return self._fr.values() def __list__(self): return list(iter(self)) diff --git a/steam/client/cdn.py b/steam/client/cdn.py index d8419c62..3dd6b683 100644 --- a/steam/client/cdn.py +++ b/steam/client/cdn.py @@ -96,7 +96,6 @@ from zipfile import ZipFile from io import BytesIO from collections import OrderedDict, deque -from six import itervalues, iteritems from binascii import crc32, unhexlify from datetime import datetime import logging @@ -114,11 +113,8 @@ from steam.core.crypto import symmetric_decrypt, symmetric_decrypt_ecb from steam.core.manifest import DepotManifest, DepotFile from steam.protobufs.content_manifest_pb2 import ContentManifestPayload +import lzma -try: - import lzma -except ImportError: - from backports import lzma def decrypt_manifest_gid_2(encrypted_gid, password): """Decrypt manifest gid v2 bytes @@ -164,7 +160,7 @@ def get_content_servers_from_cs(cell_id, host='cs.steamcontent.com', port=80, nu servers = [] - for entry in itervalues(kv['serverlist']): + for entry in kv['serverlist'].values(): server = ContentServer() server.type = entry['type'] server.https = True if entry['https_support'] == 'mandatory' else False @@ -497,9 +493,9 @@ def load_licenses(self): return packages = list(map(lambda l: {'packageid': l.package_id, 'access_token': l.access_token}, - itervalues(self.steam.licenses))) + self.steam.licenses.values())) - for package_id, info in iteritems(self.steam.get_product_info(packages=packages)['packages']): + for package_id, info in self.steam.get_product_info(packages=packages)['packages'].items(): self.licensed_app_ids.update(info['appids'].values()) self.licensed_depot_ids.update(info['depotids'].values()) @@ -800,7 +796,7 @@ def async_fetch_manifest( tasks = [] shared_depots = {} - for depot_id, depot_info in iteritems(depots): + for depot_id, depot_info in depots.items(): if not depot_id.isdigit(): continue @@ -866,7 +862,7 @@ def async_fetch_manifest( manifests.append(result) # load shared depot manifests - for app_id, depot_ids in iteritems(shared_depots): + for app_id, depot_ids in shared_depots.items(): def nested_ffunc(depot_id, depot_info, depot_ids=depot_ids, ffunc=filter_func): return (int(depot_id) in depot_ids and (ffunc is None or ffunc(depot_id, depot_info))) @@ -939,5 +935,3 @@ def get_manifest_for_workshop_item(self, item_id): manifest.name = wf.title return manifest - - diff --git a/steam/core/crypto.py b/steam/core/crypto.py index 583bbde6..3d6954c0 100644 --- a/steam/core/crypto.py +++ b/steam/core/crypto.py @@ -24,11 +24,7 @@ class UniverseKey(object): BS = 16 pad = lambda s: s + (BS - len(s) % BS) * pack('B', BS - len(s) % BS) - -if sys.version_info < (3,): - unpad = lambda s: s[0:-ord(s[-1])] -else: - unpad = lambda s: s[0:-s[-1]] +unpad = lambda s: s[0:-s[-1]] def generate_session_key(hmac_secret=b''): diff --git a/steam/core/msg/structs.py b/steam/core/msg/structs.py index 901b9340..9dd032ca 100644 --- a/steam/core/msg/structs.py +++ b/steam/core/msg/structs.py @@ -1,8 +1,6 @@ """Classes to (de)serialize various struct messages""" import struct -import six import vdf -from six.moves import range from steam.enums import EResult, EUniverse from steam.enums.emsg import EMsg from steam.utils.binary import StructReader @@ -26,8 +24,7 @@ def __new__(metacls, name, bases, classdict): return cls -@six.add_metaclass(StructMessageMeta) -class StructMessage: +class StructMessage(object, metaclass=StructMessageMeta): def __init__(self, data=None): if data: self.load(data) @@ -37,7 +34,6 @@ def serialize(self): def load(self, data): raise NotImplementedError - class ChannelEncryptRequest(StructMessage): protocolVersion = 1 universe = EUniverse.Invalid @@ -426,4 +422,3 @@ def __str__(self): class ClientPasswordChangeResponse(_ResultStruct): pass - diff --git a/steam/globalid.py b/steam/globalid.py index 9d997606..659cfcce 100644 --- a/steam/globalid.py +++ b/steam/globalid.py @@ -1,13 +1,7 @@ import sys from datetime import datetime, timedelta -if sys.version_info < (3,): - intBase = long -else: - intBase = int - - -class GlobalID(intBase): +class GlobalID(int): """ Represents a globally unique identifier within the Steam network. Guaranteed to be unique across all racks and servers for a given Steam universe. diff --git a/steam/steamid.py b/steam/steamid.py index 34cb1446..9c2d4b62 100644 --- a/steam/steamid.py +++ b/steam/steamid.py @@ -8,11 +8,6 @@ from steam.core.crypto import md5_hash from steam.utils.web import make_requests_session -if sys.version_info < (3,): - intBase = long -else: - intBase = int - class ETypeChar(SteamIntEnum): I = EType.Invalid U = EType.Individual @@ -40,7 +35,7 @@ def __str__(self): _csgofrcode_chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789' -class SteamID(intBase): +class SteamID(int): """ Object for converting steamID to its' various representations diff --git a/steam/utils/__init__.py b/steam/utils/__init__.py index e97bdac4..120662c2 100644 --- a/steam/utils/__init__.py +++ b/steam/utils/__init__.py @@ -1,12 +1,6 @@ """Utility package with various useful functions """ -import six -from six.moves import xrange as _range import sys - -if six.PY2 and sys.platform == 'win32': - import win_inet_pton - import weakref import struct import socket @@ -63,7 +57,7 @@ def chunks(arr, size): :return: generator object :rtype: :class:`generator` """ - for i in _range(0, len(arr), size): + for i in range(0, len(arr), size): yield arr[i:i+size] diff --git a/steam/utils/proto.py b/steam/utils/proto.py index 41387030..321bcb1d 100644 --- a/steam/utils/proto.py +++ b/steam/utils/proto.py @@ -1,14 +1,7 @@ - -import six from types import GeneratorType as _GeneratorType from google.protobuf.message import Message as _ProtoMessageType - -if six.PY2: - _list_types = list, xrange, _GeneratorType -else: - _list_types = list, range, _GeneratorType, map, filter - +_list_types = list, range, _GeneratorType, map, filter protobuf_mask = 0x80000000 diff --git a/steam/utils/throttle.py b/steam/utils/throttle.py index 6d9e45c4..3552b1ec 100644 --- a/steam/utils/throttle.py +++ b/steam/utils/throttle.py @@ -1,11 +1,6 @@ import sys import time -if sys.version_info >= (3,3): - _monotonic = time.monotonic -else: - _monotonic = time.time # not really monotonic vOv - class ConstantRateLimit(object): def __init__(self, times, seconds, exit_wait=False, sleep_func=time.sleep): @@ -47,14 +42,12 @@ def __exit__(self, etype, evalue, traceback): self.wait() def _update_ref(self): - self._ref = _monotonic() + self.rate + self._ref = time.monotonic() + self.rate def wait(self): """Blocks until the rate is met""" - now = _monotonic() + now = time.monotonic() if now < self._ref: delay = max(0, self._ref - now) self.sleep_func(delay) self._update_ref() - - diff --git a/steam/webauth.py b/steam/webauth.py index f3b393c4..deb373c7 100644 --- a/steam/webauth.py +++ b/steam/webauth.py @@ -58,7 +58,6 @@ from time import time, sleep from base64 import b64encode from getpass import getpass -import six import requests from steam.enums.proto import EAuthSessionGuardType, EAuthTokenPlatformType, ESessionPersistence @@ -67,16 +66,6 @@ from steam.core.crypto import rsa_publickey, pkcs1v15_encrypt -# TODO: Remove python2 support. -# TODO: Encrease min python version to 3.5 - -if six.PY2: - intBase = long - _cli_input = raw_input -else: - intBase = int - _cli_input = input - API_HEADERS = { 'origin': 'https://steamcommunity.com', 'referer': 'https://steamcommunity.com/', @@ -189,8 +178,8 @@ def _encrypt_password(self): """ r = self._get_rsa_key() - mod = intBase(r['response']['publickey_mod'], 16) - exp = intBase(r['response']['publickey_exp'], 16) + mod = int(r['response']['publickey_mod'], 16) + exp = int(r['response']['publickey_exp'], 16) pub_key = rsa_publickey(mod, exp) encrypted = pkcs1v15_encrypt(pub_key, self.password.encode('ascii')) diff --git a/tests/generete_webauth_vcr.py b/tests/generete_webauth_vcr.py index e952e820..a88cebff 100644 --- a/tests/generete_webauth_vcr.py +++ b/tests/generete_webauth_vcr.py @@ -16,10 +16,6 @@ from steam import webauth as wa -try: - _input = raw_input -except: - _input = input # personal info scrubbers # ----------------------- @@ -80,7 +76,7 @@ def response_scrubber(r): def user_pass_only(): print("Please enter a user that can login with just password.") - u = _input("Username: ") + u = input("Username: ") p = getpass("Password (no echo): ") user_pass_only_success(u, p)