Skip to content

Commit

Permalink
Format code with pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterPhoenix committed Sep 13, 2024
1 parent 6f97b3a commit 1ac892d
Show file tree
Hide file tree
Showing 105 changed files with 111 additions and 186 deletions.
13 changes: 6 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# steam documentation build configuration file, created by
# sphinx-quickstart on Sun Jan 17 23:28:57 2016.
Expand Down Expand Up @@ -51,8 +50,8 @@
# General information about the project.
from steam import __version__, __author__

project = u'steam'
copyright = u'2019, %s' % __author__
project = 'steam'
copyright = '2019, %s' % __author__
author = __author__

# The version info for the project you're documenting, acts as replacement for
Expand Down Expand Up @@ -229,8 +228,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'steam.tex', u'steam Documentation',
u'Rossen Georgiev', 'manual'),
(master_doc, 'steam.tex', 'steam Documentation',
'Rossen Georgiev', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -259,7 +258,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'steam', u'steam Documentation',
(master_doc, 'steam', 'steam Documentation',
[author], 1)
]

Expand All @@ -273,7 +272,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'steam', u'steam Documentation',
(master_doc, 'steam', 'steam Documentation',
author, 'steam', 'One line description of project.',
'Miscellaneous'),
]
Expand Down
8 changes: 4 additions & 4 deletions generate_enums_from_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@

for class_name, (attrs, attrs_starting_with_number) in sorted(classes.items(), key=lambda x: x[0].lower()):
if attrs_starting_with_number:
print("\n%s = SteamIntEnum(%r, {" % (class_name, class_name))
print("\n{} = SteamIntEnum({!r}, {{".format(class_name, class_name))
for ikey, ivalue in attrs.items():
print(" %r: %r," % (ikey, ivalue))
print(" {!r}: {!r},".format(ikey, ivalue))
print(" })")
else:
print("\nclass {class_name}(SteamIntEnum):".format(class_name=class_name))
print(f"\nclass {class_name}(SteamIntEnum):")
for ikey, ivalue in attrs.items():
print(" {} = {}".format(ikey, ivalue))
print(f" {ikey} = {ivalue}")

print("\n__all__ = [")

Expand Down
2 changes: 1 addition & 1 deletion recipes/2.SimpleWebAPI/steam_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
LOG = logging.getLogger("Steam Worker")


class SteamWorker(object):
class SteamWorker:
def __init__(self):
self.logged_on_once = False

Expand Down
3 changes: 1 addition & 2 deletions steam/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import json
from random import random
from time import time
from io import open
from getpass import getpass
import logging

Expand Down Expand Up @@ -57,7 +56,7 @@ def __init__(self):
BuiltinBase.__init__(self)

def __repr__(self):
return "<%s(%s) %s>" % (self.__class__.__name__,
return "<{}({}) {}>".format(self.__class__.__name__,
repr(self.current_server_addr),
'online' if self.connected else 'offline',
)
Expand Down
4 changes: 2 additions & 2 deletions steam/client/builtins/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from steam.utils.proto import proto_fill_from_dict


class Apps(object):
class Apps:
licenses = None #: :class:`dict` Accounts' package licenses

def __init__(self, *args, **kwargs):
super(Apps, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.licenses = {}
self.on(self.EVENT_DISCONNECTED, self.__handle_disconnect)
self.on(EMsg.ClientLicenseList, self._handle_licenses)
Expand Down
4 changes: 2 additions & 2 deletions steam/client/builtins/friends.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from steam.client.user import SteamUser


class Friends(object):
class Friends:
def __init__(self, *args, **kwargs):
super(Friends, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

#: :class:`.SteamFriendlist` instance
self.friends = SteamFriendlist(self, logger_name="%s.friends" % self.__class__.__name__)
Expand Down
6 changes: 3 additions & 3 deletions steam/client/builtins/gameservers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
from steam.exceptions import SteamError


class GameServers(object):
class GameServers:
def __init__(self, *args, **kwargs):
super(GameServers, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

self.gameservers = SteamGameServers(self) #: instance of :class:`SteamGameServers`


class SteamGameServers(object):
class SteamGameServers:
def __init__(self, steam):
self._s = steam

Expand Down
9 changes: 4 additions & 5 deletions steam/client/builtins/leaderboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from steam.utils.throttle import ConstantRateLimit


class Leaderboards(object):
class Leaderboards:
def __init__(self, *args, **kwargs):
super(Leaderboards, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def get_leaderboard(self, app_id, name):
""".. versionadded:: 0.8.2
Expand Down Expand Up @@ -42,7 +42,7 @@ def get_leaderboard(self, app_id, name):
return SteamLeaderboard(self, app_id, name, resp)


class SteamLeaderboard(object):
class SteamLeaderboard:
""".. versionadded:: 0.8.2
Steam leaderboard object.
Expand Down Expand Up @@ -181,8 +181,7 @@ def entry_generator():
for entries in chunks(self, chunk_size):
if not entries:
return
for entry in entries:
yield entry
yield from entries
r.wait()
return entry_generator()

Expand Down
4 changes: 2 additions & 2 deletions steam/client/builtins/unified_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
from steam.utils.proto import proto_fill_from_dict


class UnifiedMessages(object):
class UnifiedMessages:
def __init__(self, *args, **kwargs):
super(UnifiedMessages, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def send_um(self, method_name, params=None):
"""Send service method request
Expand Down
4 changes: 2 additions & 2 deletions steam/client/builtins/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from steam.core.msg import MsgProto
from steam.utils.proto import proto_fill_from_dict

class User(object):
class User:
EVENT_CHAT_MESSAGE = 'chat_message'
"""On new private chat message
Expand All @@ -20,7 +20,7 @@ class User(object):
current_games_played = [] #: :class:`list` of app ids currently being played

def __init__(self, *args, **kwargs):
super(User, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

self._user_cache = WeakValueDictionary()

Expand Down
4 changes: 2 additions & 2 deletions steam/client/builtins/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from steam.utils.web import make_requests_session, generate_session_id


class Web(object):
class Web:
_web_session = None

def __init__(self, *args, **kwargs):
super(Web, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

self.on(self.EVENT_DISCONNECTED, self.__handle_disconnect)

Expand Down
29 changes: 14 additions & 15 deletions steam/client/cdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_content_servers_from_cs(cell_id, host='cs.steamcontent.com', port=80, nu
"""
proto = 'https' if port == 443 else 'http'

url = '%s://%s:%s/serverlist/%s/%s/' % (proto, host, port, cell_id, num_servers)
url = '{}://{}:{}/serverlist/{}/{}/'.format(proto, host, port, cell_id, num_servers)
session = make_requests_session() if session is None else session
resp = session.get(url)

Expand Down Expand Up @@ -205,7 +205,7 @@ def get_content_servers_from_webapi(cell_id, num_servers=20):
return servers


class ContentServer(object):
class ContentServer:
https = False
host = None
vhost = None
Expand All @@ -216,7 +216,7 @@ class ContentServer(object):
weighted_load = None

def __repr__(self):
return "<%s('%s://%s:%s', type=%s, cell_id=%s)>" % (
return "<{}('{}://{}:{}', type={}, cell_id={})>".format(
self.__class__.__name__,
'https' if self.https else 'http',
self.host,
Expand Down Expand Up @@ -247,7 +247,7 @@ def __init__(self, manifest, file_mapping):
self._lcbuff = b''

def __repr__(self):
return "<%s(%s, %s, %s, %s, %s)>" % (
return "<{}({}, {}, {}, {}, {})>".format(
self.__class__.__name__,
self.manifest.app_id,
self.manifest.depot_id,
Expand Down Expand Up @@ -280,7 +280,7 @@ def seek(self, offset, whence=0):

if whence == 0:
if offset < 0:
raise IOError("Invalid argument")
raise OSError("Invalid argument")
elif whence == 1:
offset = self.offset + offset
elif whence == 2:
Expand Down Expand Up @@ -428,7 +428,7 @@ def __repr__(self):
if self.filenames_encrypted:
params += ', filenames_encrypted=True'

return "<%s(%s)>" % (
return "<{}({})>".format(
self.__class__.__name__,
params,
)
Expand All @@ -442,7 +442,7 @@ def deserialize(self, data):
mapping.chunks.sort(key=lambda x: x.offset, reverse=False)


class CDNClient(object):
class CDNClient:
DepotManifestClass = CDNDepotManifest
_LOG = logging.getLogger("CDNClient")
servers = deque() #: CS Server list
Expand Down Expand Up @@ -562,7 +562,7 @@ def cdn_cmd(self, command, args):
server = self.get_content_server()

while True:
url = "%s://%s:%s/%s/%s" % (
url = "{}://{}:{}/{}/{}".format(
'https' if server.https else 'http',
server.host,
server.port,
Expand Down Expand Up @@ -598,7 +598,7 @@ def get_chunk(self, app_id, depot_id, chunk_id):
:raises SteamError: error message
"""
if (depot_id, chunk_id) not in self._chunk_cache:
resp = self.cdn_cmd('depot', '%s/chunk/%s' % (depot_id, chunk_id))
resp = self.cdn_cmd('depot', '{}/chunk/{}'.format(depot_id, chunk_id))

data = symmetric_decrypt(resp.content, self.get_depot_key(app_id, depot_id))

Expand Down Expand Up @@ -661,7 +661,7 @@ def get_manifest_request_code(self, app_id, depot_id, manifest_gid, branch='publ
)

if resp is None or resp.header.eresult != EResult.OK:
raise SteamError("Failed to get manifest code for %s, %s, %s" % (app_id, depot_id, manifest_gid),
raise SteamError("Failed to get manifest code for {}, {}, {}".format(app_id, depot_id, manifest_gid),
EResult.Timeout if resp is None else EResult(resp.header.eresult))

return resp.body.manifest_request_code
Expand All @@ -684,9 +684,9 @@ def get_manifest(self, app_id, depot_id, manifest_gid, decrypt=True, manifest_re
"""
if (app_id, depot_id, manifest_gid) not in self.manifests:
if manifest_request_code:
resp = self.cdn_cmd('depot', '%s/manifest/%s/5/%s' % (depot_id, manifest_gid, manifest_request_code))
resp = self.cdn_cmd('depot', '{}/manifest/{}/5/{}'.format(depot_id, manifest_gid, manifest_request_code))
else:
resp = self.cdn_cmd('depot', '%s/manifest/%s/5' % (depot_id, manifest_gid))
resp = self.cdn_cmd('depot', '{}/manifest/{}/5'.format(depot_id, manifest_gid))

if resp.ok:
manifest = self.DepotManifestClass(self, app_id, resp.content)
Expand Down Expand Up @@ -757,7 +757,7 @@ def get_manifests(self, app_id, branch='public', password=None, filter_func=None
is_enc_branch = False

if branch not in depots.get('branches', {}):
raise SteamError("No branch named %s for app_id %s" % (repr(branch), app_id))
raise SteamError("No branch named {} for app_id {}".format(repr(branch), app_id))
elif int(depots['branches'][branch].get('pwdrequired', 0)) > 0:
is_enc_branch = True

Expand Down Expand Up @@ -889,8 +889,7 @@ def iter_files(self, app_id, filename_filter=None, branch='public', password=Non
:rtype: [:class:`.CDNDepotFile`]
"""
for manifest in self.get_manifests(app_id, branch, password, filter_func):
for fp in manifest.iter_files(filename_filter):
yield fp
yield from manifest.iter_files(filename_filter)

def get_manifest_for_workshop_item(self, item_id):
"""Get the manifest file for a worshop item that is hosted on SteamPipe
Expand Down
4 changes: 2 additions & 2 deletions steam/client/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from steam.enums.emsg import EMsg
from steam.core.msg import MsgProto

class SteamUser(object):
class SteamUser:
"""
A data model for a Steam user. Holds user persona state, and related actions
Expand All @@ -24,7 +24,7 @@ def __init__(self, steam_id, steam):
self.steam_id = SteamID(steam_id)

def __repr__(self):
return "<%s(%s, %s, %s)>" % (
return "<{}({}, {}, {})>".format(
self.__class__.__name__,
str(self.steam_id),
self.relationship,
Expand Down
8 changes: 4 additions & 4 deletions steam/core/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, protocol=PROTOCOL_TCP):
def emit(self, event, *args):
if event is not None:
self._LOG.debug("Emit event: %s" % repr(event))
super(CMClient, self).emit(event, *args)
super().emit(event, *args)

def connect(self, retry=0, delay=0):
"""Initiate connection to CM. Blocks until connected unless ``retry`` is specified.
Expand Down Expand Up @@ -204,7 +204,7 @@ def send(self, message):
message.sessionID = self.session_id

if self.verbose_debug:
self._LOG.debug("Outgoing: %s\n%s" % (repr(message), str(message)))
self._LOG.debug("Outgoing: {}\n{}".format(repr(message), str(message)))
else:
self._LOG.debug("Outgoing: %s", repr(message))

Expand Down Expand Up @@ -277,7 +277,7 @@ def _parse_message(self, message):
msg.parse()

if self.verbose_debug:
self._LOG.debug("Incoming: %s\n%s" % (repr(msg), str(msg)))
self._LOG.debug("Incoming: {}\n{}".format(repr(msg), str(msg)))
else:
self._LOG.debug("Incoming: %s", repr(msg))

Expand Down Expand Up @@ -406,7 +406,7 @@ def idle(self):
gevent.idle()


class CMServerList(object):
class CMServerList:
"""
Managing object for CM servers
Expand Down
Loading

0 comments on commit 1ac892d

Please sign in to comment.