From 509cb4f0d9493f8592b854240496d7a21f8a32ad Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Tue, 7 Jan 2020 21:29:07 +0000 Subject: [PATCH] Convert most of the format() string calls to f-strings using libcst. Exact commands run were: python3 -m libcst.tool codemod convert_format_to_fstring.ConvertFormatStringCommand . --no-format python3 setup.py build_ext --inplace --- TODO.md | 3 +- bemani/api/app.py | 2 +- bemani/backend/core/core.py | 14 +-- bemani/backend/ddr/base.py | 6 +- bemani/backend/ddr/common.py | 6 +- bemani/backend/ddr/ddr2013.py | 22 ++--- bemani/backend/ddr/ddr2014.py | 22 ++--- bemani/backend/ddr/ddrace.py | 4 +- bemani/backend/ddr/ddrx2.py | 18 ++-- bemani/backend/ddr/ddrx3.py | 22 ++--- bemani/backend/dispatch.py | 6 +- bemani/backend/iidx/base.py | 6 +- bemani/backend/iidx/copula.py | 2 +- bemani/backend/iidx/course.py | 4 +- bemani/backend/iidx/pendual.py | 2 +- bemani/backend/iidx/sinobuz.py | 2 +- bemani/backend/iidx/spada.py | 2 +- bemani/backend/iidx/tricoro.py | 2 +- bemani/backend/jubeat/base.py | 2 +- bemani/backend/jubeat/clan.py | 4 +- bemani/backend/jubeat/prop.py | 2 +- bemani/backend/museca/base.py | 4 +- bemani/backend/museca/museca1.py | 2 +- bemani/backend/museca/museca1plus.py | 2 +- bemani/backend/popn/base.py | 2 +- bemani/backend/popn/eclale.py | 4 +- bemani/backend/popn/fantasia.py | 2 +- bemani/backend/popn/lapistoria.py | 2 +- bemani/backend/popn/sunnypark.py | 2 +- bemani/backend/popn/usaneko.py | 6 +- bemani/backend/reflec/base.py | 4 +- bemani/backend/reflec/colette.py | 12 +-- bemani/backend/reflec/groovin.py | 10 +- bemani/backend/reflec/limelight.py | 8 +- bemani/backend/reflec/reflecbeat.py | 8 +- bemani/backend/reflec/volzza.py | 8 +- bemani/backend/reflec/volzza2.py | 8 +- bemani/backend/reflec/volzzabase.py | 2 +- bemani/backend/sdvx/base.py | 4 +- bemani/backend/sdvx/gravitywars.py | 2 +- bemani/backend/sdvx/gravitywars_s1.py | 2 +- bemani/backend/sdvx/gravitywars_s2.py | 4 +- bemani/backend/sdvx/infiniteinfection.py | 4 +- bemani/client/base.py | 31 +++--- bemani/client/bishi/bishi.py | 8 +- bemani/client/ddr/ddr2013.py | 26 ++---- bemani/client/ddr/ddr2014.py | 24 ++--- bemani/client/ddr/ddrace.py | 40 +++----- bemani/client/ddr/ddrx2.py | 46 +++------ bemani/client/ddr/ddrx3.py | 56 ++++------- bemani/client/iidx/copula.py | 44 ++++----- bemani/client/iidx/pendual.py | 44 ++++----- bemani/client/iidx/sinobuz.py | 44 ++++----- bemani/client/iidx/spada.py | 42 ++++----- bemani/client/iidx/tricoro.py | 42 ++++----- bemani/client/jubeat/clan.py | 24 ++--- bemani/client/jubeat/prop.py | 50 ++++------ bemani/client/jubeat/qubell.py | 24 ++--- bemani/client/jubeat/saucer.py | 22 ++--- bemani/client/jubeat/saucerfulfill.py | 34 +++---- bemani/client/museca/museca1.py | 28 +++--- bemani/client/museca/museca1plus.py | 28 +++--- bemani/client/popn/eclale.py | 38 ++++---- bemani/client/popn/fantasia.py | 36 ++++--- bemani/client/popn/lapistoria.py | 26 +++--- bemani/client/popn/sunnypark.py | 36 ++++--- bemani/client/popn/tunestreet.py | 24 ++--- bemani/client/popn/usaneko.py | 54 +++++------ bemani/client/protocol.py | 13 +-- bemani/client/reflec/colette.py | 36 +++---- bemani/client/reflec/groovin.py | 48 ++++------ bemani/client/reflec/limelight.py | 40 +++----- bemani/client/reflec/reflec.py | 34 +++---- bemani/client/reflec/volzza.py | 38 +++----- bemani/client/reflec/volzza2.py | 56 +++++------ bemani/client/sdvx/booth.py | 32 +++---- bemani/client/sdvx/gravitywars_s1.py | 32 +++---- bemani/client/sdvx/gravitywars_s2.py | 32 +++---- bemani/client/sdvx/heavenlyhaven.py | 32 +++---- bemani/client/sdvx/infiniteinfection.py | 36 +++---- bemani/common/aes.py | 2 +- bemani/common/card.py | 10 +- bemani/common/http.py | 8 +- bemani/common/id.py | 4 +- bemani/common/model.py | 6 +- bemani/data/api/client.py | 20 ++-- bemani/data/data.py | 11 +-- bemani/data/mysql/game.py | 5 +- bemani/data/mysql/music.py | 27 ++---- bemani/data/mysql/network.py | 2 +- bemani/data/types.py | 114 +++-------------------- bemani/format/ifs.py | 4 +- bemani/format/iidxmusicdb.py | 2 +- bemani/format/twodx.py | 2 +- bemani/frontend/admin/admin.py | 2 +- bemani/frontend/app.py | 2 +- bemani/frontend/arcade/arcade.py | 2 +- bemani/frontend/base.py | 6 +- bemani/frontend/bishi/endpoints.py | 2 +- bemani/frontend/ddr/ddr.py | 2 +- bemani/frontend/ddr/endpoints.py | 12 +-- bemani/frontend/iidx/endpoints.py | 12 +-- bemani/frontend/jubeat/endpoints.py | 8 +- bemani/frontend/museca/endpoints.py | 8 +- bemani/frontend/popn/endpoints.py | 8 +- bemani/frontend/reflec/endpoints.py | 8 +- bemani/frontend/sdvx/endpoints.py | 8 +- bemani/protocol/binary.py | 22 ++--- bemani/protocol/node.py | 58 ++++-------- bemani/protocol/protocol.py | 6 +- bemani/protocol/stream.py | 4 +- bemani/protocol/xml.py | 8 +- bemani/sniff/sniff.py | 8 +- bemani/tests/helpers.py | 2 +- bemani/tests/test_CardCipher.py | 8 +- bemani/tests/test_protocol.py | 8 +- bemani/utils/arcutils.py | 2 +- bemani/utils/bemanishark.py | 24 ++--- bemani/utils/dbutils.py | 8 +- bemani/utils/ifsutils.py | 2 +- bemani/utils/iidxutils.py | 2 +- bemani/utils/proxy.py | 37 +++----- bemani/utils/read.py | 81 +++++++--------- bemani/utils/replay.py | 23 +---- bemani/utils/responsegen.py | 40 +++----- bemani/utils/trafficgen.py | 8 +- bemani/utils/twodxutils.py | 2 +- 127 files changed, 862 insertions(+), 1343 deletions(-) diff --git a/TODO.md b/TODO.md index 60a273f..3547bcf 100644 --- a/TODO.md +++ b/TODO.md @@ -8,7 +8,8 @@ Things that I have not gotten around to doing. - Make the frontend work better on mobile. It works well enough, but it could be a much better experience. - Support for DanEvo. I meant to do this but my DanEvo ended up in storage before I could tackle it, so the only thing that exists at the moment is a rudimentary music DB parser. - Figure out phase/unlock/etc bits for some older IIDX and Pop'n Music versions and hook them up to the Arcade panel to allow switching events. + - Auto-prune events in the event log after some configured date. Currently it grows indefinitely which is fine for small hobby setups but could be a problem with lots of events. General maintenance that I have not yet performed. - - Upgrade legacy uses of .format() to use f-strings instead. + - Upgrade legacy uses of .format() to use f-strings instead (partially done). diff --git a/bemani/api/app.py b/bemani/api/app.py index 546319d..9027938 100644 --- a/bemani/api/app.py +++ b/bemani/api/app.py @@ -301,7 +301,7 @@ def lookup(protoversion: str, requestgame: str, requestversion: str) -> Dict[str inst = handler(g.data, game, version, omnimix) try: - fetchmethod = getattr(inst, 'fetch_{}'.format(protoversion)) + fetchmethod = getattr(inst, f'fetch_{protoversion}') except AttributeError: # Don't know how to handle this object for this version abort(501) diff --git a/bemani/backend/core/core.py b/bemani/backend/core/core.py index e46e97b..d447f94 100644 --- a/bemani/backend/core/core.py +++ b/bemani/backend/core/core.py @@ -22,11 +22,7 @@ class CoreHandler(Base): node.set_attribute('url', url) return node - url = '{}://{}:{}/'.format( - 'https' if self.config['server']['https'] else 'http', - self.config['server']['address'], - self.config['server']['port'], - ) + url = f'{"https" if self.config["server"]["https"] else "http"}://{self.config["server"]["address"]}:{self.config["server"]["port"]}/' root = Node.void('services') root.set_attribute('expire', '600') # This can be set to 'operation', 'debug', 'test', and 'factory'. @@ -58,13 +54,7 @@ class CoreHandler(Base): keepalive = socket.gethostbyname(keepalive) root.add_child(item( 'keepalive', - 'http://{}/core/keepalive?pa={}&ia={}&ga={}&ma={}&t1=2&t2=10'.format( - keepalive, - keepalive, - keepalive, - keepalive, - keepalive, - ), + f'http://{keepalive}/core/keepalive?pa={keepalive}&ia={keepalive}&ga={keepalive}&ma={keepalive}&t1=2&t2=10', )) return root diff --git a/bemani/backend/ddr/base.py b/bemani/backend/ddr/base.py index 70582eb..14ef17e 100644 --- a/bemani/backend/ddr/base.py +++ b/bemani/backend/ddr/base.py @@ -215,7 +215,7 @@ class DDRBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.CHART_DOUBLE_EXPERT, self.CHART_DOUBLE_CHALLENGE, ]: - raise Exception('Invalid chart {}'.format(chart)) + raise Exception(f'Invalid chart {chart}') if halo not in [ self.HALO_NONE, self.HALO_GOOD_FULL_COMBO, @@ -223,7 +223,7 @@ class DDRBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.HALO_PERFECT_FULL_COMBO, self.HALO_MARVELOUS_FULL_COMBO, ]: - raise Exception('Invalid halo {}'.format(halo)) + raise Exception(f'Invalid halo {halo}') if rank not in [ self.RANK_E, self.RANK_D, @@ -242,7 +242,7 @@ class DDRBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.RANK_AA_PLUS, self.RANK_AAA, ]: - raise Exception('Invalid rank {}'.format(rank)) + raise Exception(f'Invalid rank {rank}') if userid is not None: oldscore = self.data.local.music.get_score( diff --git a/bemani/backend/ddr/common.py b/bemani/backend/ddr/common.py index 8a361af..de54fa5 100644 --- a/bemani/backend/ddr/common.py +++ b/bemani/backend/ddr/common.py @@ -187,7 +187,7 @@ class DDRGameScoreHandler(DDRBase): # Return the most recent five scores game = Node.void('game') for i in range(len(recentscores)): - game.set_attribute('sc{}'.format(i + 1), str(recentscores[i])) + game.set_attribute(f'sc{i + 1}', str(recentscores[i])) return game @@ -396,14 +396,14 @@ class DDRGameFriendHandler(DDRBase): game.add_child(gr_s) index = 1 for entry in friend.get_int_array('gr_s', 5): - gr_s.set_attribute('gr{}'.format(index), str(entry)) + gr_s.set_attribute(f'gr{index}', str(entry)) index = index + 1 gr_d = Node.void('gr_d') game.add_child(gr_d) index = 1 for entry in friend.get_int_array('gr_d', 5): - gr_d.set_attribute('gr{}'.format(index), str(entry)) + gr_d.set_attribute(f'gr{index}', str(entry)) index = index + 1 return game diff --git a/bemani/backend/ddr/ddr2013.py b/bemani/backend/ddr/ddr2013.py index 937e021..d60ad2a 100644 --- a/bemani/backend/ddr/ddr2013.py +++ b/bemani/backend/ddr/ddr2013.py @@ -376,7 +376,7 @@ class DDR2013( root.add_child(result_star) result_stars = profile.get_int_array('result_stars', 9) for i in range(9): - result_star.set_attribute('slot{}'.format(i + 1), str(result_stars[i])) + result_star.set_attribute(f'slot{i + 1}', str(result_stars[i])) # Target stuff target = Node.void('target') @@ -389,14 +389,14 @@ class DDR2013( root.add_child(gr_s) index = 1 for entry in profile.get_int_array('gr_s', 5): - gr_s.set_attribute('gr{}'.format(index), str(entry)) + gr_s.set_attribute(f'gr{index}', str(entry)) index = index + 1 gr_d = Node.void('gr_d') root.add_child(gr_d) index = 1 for entry in profile.get_int_array('gr_d', 5): - gr_d.set_attribute('gr{}'.format(index), str(entry)) + gr_d.set_attribute(f'gr{index}', str(entry)) index = index + 1 # Options in menus @@ -458,14 +458,14 @@ class DDR2013( friendnode.add_child(gr_s) index = 1 for entry in friend.get_int_array('gr_s', 5): - gr_s.set_attribute('gr{}'.format(index), str(entry)) + gr_s.set_attribute(f'gr{index}', str(entry)) index = index + 1 gr_d = Node.void('gr_d') friendnode.add_child(gr_d) index = 1 for entry in friend.get_int_array('gr_d', 5): - gr_d.set_attribute('gr{}'.format(index), str(entry)) + gr_d.set_attribute(f'gr{index}', str(entry)) index = index + 1 # Play area @@ -473,7 +473,7 @@ class DDR2013( play_area = Node.void('play_area') root.add_child(play_area) for i in range(len(areas)): - play_area.set_attribute('play_cnt{}'.format(i), str(areas[i])) + play_area.set_attribute(f'play_cnt{i}', str(areas[i])) return root @@ -538,7 +538,7 @@ class DDR2013( if title_gr is not None: title_grdict.replace_int('s', title.value) newprofile.replace_dict('title_gr', title_grdict) - play_stats.increment_int('cnt_m{}'.format(mode)) + play_stats.increment_int(f'cnt_m{mode}') # Result stars result_star = request.child('result_star') @@ -695,7 +695,7 @@ class DDR2013( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', oldfriends[i], ) elif oldfriends[i] is None: @@ -704,7 +704,7 @@ class DDR2013( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', newfriends[i], {}, ) @@ -714,14 +714,14 @@ class DDR2013( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', oldfriends[i], ) self.data.local.user.put_link( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', newfriends[i], {}, ) diff --git a/bemani/backend/ddr/ddr2014.py b/bemani/backend/ddr/ddr2014.py index 368ba57..1aaae50 100644 --- a/bemani/backend/ddr/ddr2014.py +++ b/bemani/backend/ddr/ddr2014.py @@ -431,21 +431,21 @@ class DDR2014( root.add_child(result_star) result_stars = profile.get_int_array('result_stars', 9) for i in range(9): - result_star.set_attribute('slot{}'.format(i + 1), str(result_stars[i])) + result_star.set_attribute(f'slot{i + 1}', str(result_stars[i])) # Groove gauge level-ups gr_s = Node.void('gr_s') root.add_child(gr_s) index = 1 for entry in profile.get_int_array('gr_s', 5): - gr_s.set_attribute('gr{}'.format(index), str(entry)) + gr_s.set_attribute(f'gr{index}', str(entry)) index = index + 1 gr_d = Node.void('gr_d') root.add_child(gr_d) index = 1 for entry in profile.get_int_array('gr_d', 5): - gr_d.set_attribute('gr{}'.format(index), str(entry)) + gr_d.set_attribute(f'gr{index}', str(entry)) index = index + 1 # Options in menus @@ -513,14 +513,14 @@ class DDR2014( friendnode.add_child(gr_s) index = 1 for entry in friend.get_int_array('gr_s', 5): - gr_s.set_attribute('gr{}'.format(index), str(entry)) + gr_s.set_attribute(f'gr{index}', str(entry)) index = index + 1 gr_d = Node.void('gr_d') friendnode.add_child(gr_d) index = 1 for entry in friend.get_int_array('gr_d', 5): - gr_d.set_attribute('gr{}'.format(index), str(entry)) + gr_d.set_attribute(f'gr{index}', str(entry)) index = index + 1 # Target stuff @@ -534,7 +534,7 @@ class DDR2014( play_area = Node.void('play_area') root.add_child(play_area) for i in range(len(areas)): - play_area.set_attribute('play_cnt{}'.format(i), str(areas[i])) + play_area.set_attribute(f'play_cnt{i}', str(areas[i])) return root @@ -599,7 +599,7 @@ class DDR2014( if title_gr is not None: title_grdict.replace_int('s', title.value) newprofile.replace_dict('title_gr', title_grdict) - play_stats.increment_int('cnt_m{}'.format(mode)) + play_stats.increment_int(f'cnt_m{mode}') # Result stars result_star = request.child('result_star') @@ -756,7 +756,7 @@ class DDR2014( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', oldfriends[i], ) elif oldfriends[i] is None: @@ -765,7 +765,7 @@ class DDR2014( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', newfriends[i], {}, ) @@ -775,14 +775,14 @@ class DDR2014( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', oldfriends[i], ) self.data.local.user.put_link( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', newfriends[i], {}, ) diff --git a/bemani/backend/ddr/ddrace.py b/bemani/backend/ddr/ddrace.py index 194adc6..e3eb9f3 100644 --- a/bemani/backend/ddr/ddrace.py +++ b/bemani/backend/ddr/ddrace.py @@ -539,7 +539,7 @@ class DDRAce( for userid, score in scores: if profiles_by_userid.get(userid) is None: - raise Exception('Logic error, couldn\'t find any profile for {}'.format(userid)) + raise Exception(f'Logic error, couldn\'t find any profile for {userid}') profiledata = profiles_by_userid[userid] record = Node.void('record') @@ -756,7 +756,7 @@ class DDRAce( 3: self.GAME_RIVAL_SLOT_3_ACTIVE_OFFSET, }[rivalno] - whichfriend = lastdict.get_int('rival{}'.format(rivalno)) - 1 + whichfriend = lastdict.get_int(f'rival{rivalno}') - 1 if whichfriend < 0: # This rival isn't active rival[activeslot] = b'0' diff --git a/bemani/backend/ddr/ddrx2.py b/bemani/backend/ddr/ddrx2.py index 64cec6e..af2e4ca 100644 --- a/bemani/backend/ddr/ddrx2.py +++ b/bemani/backend/ddr/ddrx2.py @@ -435,14 +435,14 @@ class DDRX2( root.add_child(gr_s) index = 1 for entry in profile.get_int_array('gr_s', 5): - gr_s.set_attribute('gr{}'.format(index), str(entry)) + gr_s.set_attribute(f'gr{index}', str(entry)) index = index + 1 gr_d = Node.void('gr_d') root.add_child(gr_d) index = 1 for entry in profile.get_int_array('gr_d', 5): - gr_d.set_attribute('gr{}'.format(index), str(entry)) + gr_d.set_attribute(f'gr{index}', str(entry)) index = index + 1 # Options in menus @@ -504,14 +504,14 @@ class DDRX2( friendnode.add_child(gr_s) index = 1 for entry in friend.get_int_array('gr_s', 5): - gr_s.set_attribute('gr{}'.format(index), str(entry)) + gr_s.set_attribute(f'gr{index}', str(entry)) index = index + 1 gr_d = Node.void('gr_d') friendnode.add_child(gr_d) index = 1 for entry in friend.get_int_array('gr_d', 5): - gr_d.set_attribute('gr{}'.format(index), str(entry)) + gr_d.set_attribute(f'gr{index}', str(entry)) index = index + 1 return root @@ -577,7 +577,7 @@ class DDRX2( if title_gr is not None: title_grdict.replace_int('s', title.value) newprofile.replace_dict('title_gr', title_grdict) - play_stats.increment_int('cnt_m{}'.format(mode)) + play_stats.increment_int(f'cnt_m{mode}') # Update last attributes lastdict.replace_int('fri', intish(last.attribute('fri'))) @@ -744,7 +744,7 @@ class DDRX2( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', oldfriends[i], ) elif oldfriends[i] is None: @@ -753,7 +753,7 @@ class DDRX2( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', newfriends[i], {}, ) @@ -763,14 +763,14 @@ class DDRX2( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', oldfriends[i], ) self.data.local.user.put_link( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', newfriends[i], {}, ) diff --git a/bemani/backend/ddr/ddrx3.py b/bemani/backend/ddr/ddrx3.py index fd3bd05..fa8451b 100644 --- a/bemani/backend/ddr/ddrx3.py +++ b/bemani/backend/ddr/ddrx3.py @@ -451,7 +451,7 @@ class DDRX3( root.add_child(result_star) result_stars = profile.get_int_array('result_stars', 9) for i in range(9): - result_star.set_attribute('slot{}'.format(i + 1), str(result_stars[i])) + result_star.set_attribute(f'slot{i + 1}', str(result_stars[i])) # Target stuff target = Node.void('target') @@ -464,14 +464,14 @@ class DDRX3( root.add_child(gr_s) index = 1 for entry in profile.get_int_array('gr_s', 5): - gr_s.set_attribute('gr{}'.format(index), str(entry)) + gr_s.set_attribute(f'gr{index}', str(entry)) index = index + 1 gr_d = Node.void('gr_d') root.add_child(gr_d) index = 1 for entry in profile.get_int_array('gr_d', 5): - gr_d.set_attribute('gr{}'.format(index), str(entry)) + gr_d.set_attribute(f'gr{index}', str(entry)) index = index + 1 # Options in menus @@ -533,14 +533,14 @@ class DDRX3( friendnode.add_child(gr_s) index = 1 for entry in friend.get_int_array('gr_s', 5): - gr_s.set_attribute('gr{}'.format(index), str(entry)) + gr_s.set_attribute(f'gr{index}', str(entry)) index = index + 1 gr_d = Node.void('gr_d') friendnode.add_child(gr_d) index = 1 for entry in friend.get_int_array('gr_d', 5): - gr_d.set_attribute('gr{}'.format(index), str(entry)) + gr_d.set_attribute(f'gr{index}', str(entry)) index = index + 1 # Play area @@ -548,7 +548,7 @@ class DDRX3( play_area = Node.void('play_area') root.add_child(play_area) for i in range(len(areas)): - play_area.set_attribute('play_cnt{}'.format(i), str(areas[i])) + play_area.set_attribute(f'play_cnt{i}', str(areas[i])) return root @@ -613,7 +613,7 @@ class DDRX3( if title_gr is not None: title_grdict.replace_int('s', title.value) newprofile.replace_dict('title_gr', title_grdict) - play_stats.increment_int('cnt_m{}'.format(mode)) + play_stats.increment_int(f'cnt_m{mode}') # Result stars result_star = request.child('result_star') @@ -770,7 +770,7 @@ class DDRX3( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', oldfriends[i], ) elif oldfriends[i] is None: @@ -779,7 +779,7 @@ class DDRX3( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', newfriends[i], {}, ) @@ -789,14 +789,14 @@ class DDRX3( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', oldfriends[i], ) self.data.local.user.put_link( self.game, self.version, userid, - 'friend_{}'.format(i), + f'friend_{i}', newfriends[i], {}, ) diff --git a/bemani/backend/dispatch.py b/bemani/backend/dispatch.py index 41a3e8b..699e977 100644 --- a/bemani/backend/dispatch.py +++ b/bemani/backend/dispatch.py @@ -141,7 +141,7 @@ class Dispatch: # First, try to handle with specific service/method function try: - handler = getattr(game, 'handle_{}_{}_request'.format(request.name, method)) + handler = getattr(game, f'handle_{request.name}_{method}_request') except AttributeError: handler = None if handler is not None: @@ -150,7 +150,7 @@ class Dispatch: if response is None: # Now, try to pass it off to a generic service handler try: - handler = getattr(game, 'handle_{}_request'.format(request.name)) + handler = getattr(game, f'handle_{request.name}_request') except AttributeError: handler = None if handler is not None: @@ -158,7 +158,7 @@ class Dispatch: if response is None: # Unrecognized handler - self.log("Unrecognized service {} method {}".format(request.name, method)) + self.log(f"Unrecognized service {request.name} method {method}") return None # Make sure we have a status value if one wasn't provided diff --git a/bemani/backend/iidx/base.py b/bemani/backend/iidx/base.py index 380324a..05ef97a 100644 --- a/bemani/backend/iidx/base.py +++ b/bemani/backend/iidx/base.py @@ -314,7 +314,7 @@ class IIDXBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.CLEAR_STATUS_EX_HARD_CLEAR, self.CLEAR_STATUS_FULL_COMBO, ]: - raise Exception("Invalid clear status value {}".format(clear_status)) + raise Exception(f"Invalid clear status value {clear_status}") # Calculate ex score ex_score = (2 * pgreats) + greats @@ -419,7 +419,7 @@ class IIDXBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.DAN_RANKING_SINGLE, self.DAN_RANKING_DOUBLE, ]: - raise Exception("Invalid dan rank type value {}".format(dantype)) + raise Exception(f"Invalid dan rank type value {dantype}") # Range check rank if rank not in [ @@ -443,7 +443,7 @@ class IIDXBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.DAN_RANK_CHUDEN, self.DAN_RANK_KAIDEN, ]: - raise Exception("Invalid dan rank {}".format(rank)) + raise Exception(f"Invalid dan rank {rank}") if cleared: # Update profile if needed diff --git a/bemani/backend/iidx/copula.py b/bemani/backend/iidx/copula.py index 22181e2..a3fe306 100644 --- a/bemani/backend/iidx/copula.py +++ b/bemani/backend/iidx/copula.py @@ -522,7 +522,7 @@ class IIDXCopula(IIDXCourse, IIDXBase): if rivalid == -1: attr = 'iidxid' else: - attr = 'iidxid{}'.format(rivalid) + attr = f'iidxid{rivalid}' try: extid = int(request.attribute(attr)) diff --git a/bemani/backend/iidx/course.py b/bemani/backend/iidx/course.py index fadc0b7..39a6dee 100644 --- a/bemani/backend/iidx/course.py +++ b/bemani/backend/iidx/course.py @@ -31,7 +31,7 @@ class IIDXCourse(IIDXBase): self.COURSE_TYPE_INTERNET_RANKING, self.COURSE_TYPE_CLASSIC, ]: - raise Exception("Invalid course type value {}".format(coursetype)) + raise Exception(f"Invalid course type value {coursetype}") # Range check medals if clear_status not in [ @@ -44,7 +44,7 @@ class IIDXCourse(IIDXBase): self.CLEAR_STATUS_EX_HARD_CLEAR, self.CLEAR_STATUS_FULL_COMBO, ]: - raise Exception("Invalid clear status value {}".format(clear_status)) + raise Exception(f"Invalid clear status value {clear_status}") # Update achievement to track course statistics course_score = self.data.local.user.get_achievement( diff --git a/bemani/backend/iidx/pendual.py b/bemani/backend/iidx/pendual.py index 4f40ef2..e9a9b65 100644 --- a/bemani/backend/iidx/pendual.py +++ b/bemani/backend/iidx/pendual.py @@ -505,7 +505,7 @@ class IIDXPendual(IIDXCourse, IIDXBase): if rivalid == -1: attr = 'iidxid' else: - attr = 'iidxid{}'.format(rivalid) + attr = f'iidxid{rivalid}' try: extid = int(request.attribute(attr)) diff --git a/bemani/backend/iidx/sinobuz.py b/bemani/backend/iidx/sinobuz.py index 09cc77f..d9e86b2 100644 --- a/bemani/backend/iidx/sinobuz.py +++ b/bemani/backend/iidx/sinobuz.py @@ -551,7 +551,7 @@ class IIDXSinobuz(IIDXCourse, IIDXBase): if rivalid == -1: attr = 'iidxid' else: - attr = 'iidxid{}'.format(rivalid) + attr = f'iidxid{rivalid}' try: extid = int(request.attribute(attr)) diff --git a/bemani/backend/iidx/spada.py b/bemani/backend/iidx/spada.py index 03ad84c..47d816b 100644 --- a/bemani/backend/iidx/spada.py +++ b/bemani/backend/iidx/spada.py @@ -454,7 +454,7 @@ class IIDXSpada(IIDXBase): if rivalid == -1: attr = 'iidxid' else: - attr = 'iidxid{}'.format(rivalid) + attr = f'iidxid{rivalid}' try: extid = int(request.attribute(attr)) diff --git a/bemani/backend/iidx/tricoro.py b/bemani/backend/iidx/tricoro.py index 143c3fc..e014618 100644 --- a/bemani/backend/iidx/tricoro.py +++ b/bemani/backend/iidx/tricoro.py @@ -453,7 +453,7 @@ class IIDXTricoro(IIDXBase): if rivalid == -1: attr = 'iidxid' else: - attr = 'iidxid{}'.format(rivalid) + attr = f'iidxid{rivalid}' try: extid = int(request.attribute(attr)) diff --git a/bemani/backend/jubeat/base.py b/bemani/backend/jubeat/base.py index 64c782c..74d3eca 100644 --- a/bemani/backend/jubeat/base.py +++ b/bemani/backend/jubeat/base.py @@ -171,7 +171,7 @@ class JubeatBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.PLAY_MEDAL_NEARLY_EXCELLENT, self.PLAY_MEDAL_EXCELLENT, ]: - raise Exception("Invalid medal value {}".format(medal)) + raise Exception(f"Invalid medal value {medal}") oldscore = self.data.local.music.get_score( self.game, diff --git a/bemani/backend/jubeat/clan.py b/bemani/backend/jubeat/clan.py index 80426d9..b2fb2bc 100644 --- a/bemani/backend/jubeat/clan.py +++ b/bemani/backend/jubeat/clan.py @@ -1499,7 +1499,7 @@ class JubeatClan( item = Node.void('item') item_list.add_child(item) item.set_attribute('id', str(itemid)) - item.add_child(Node.s32('num', dropdata.get_int('item_{}'.format(itemid)))) + item.add_child(Node.s32('num', dropdata.get_int(f'item_{itemid}'))) # Fill in category fill_in_category = Node.void('fill_in_category') @@ -1663,7 +1663,7 @@ class JubeatClan( olddrop.replace_int('exp', exp) olddrop.replace_int('flag', flag) for itemid, num in items.items(): - olddrop.replace_int('item_{}'.format(itemid), num) + olddrop.replace_int(f'item_{itemid}', num) # Save it as an achievement self.data.local.user.put_achievement( diff --git a/bemani/backend/jubeat/prop.py b/bemani/backend/jubeat/prop.py index 91e5cac..4c8bbe0 100644 --- a/bemani/backend/jubeat/prop.py +++ b/bemani/backend/jubeat/prop.py @@ -294,7 +294,7 @@ class JubeatProp( elif direction == 'demote': new_class, new_subclass = cls.__decrement_class(cur_class, cur_subclass) else: - raise Exception('Logic error, unknown direction {}!'.format(direction)) + raise Exception(f'Logic error, unknown direction {direction}!') if new_class != cur_class or new_subclass != cur_subclass: # If they've checked last time, set up the new old class. diff --git a/bemani/backend/museca/base.py b/bemani/backend/museca/base.py index d4a6382..8bbc789 100644 --- a/bemani/backend/museca/base.py +++ b/bemani/backend/museca/base.py @@ -195,7 +195,7 @@ class MusecaBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.CLEAR_TYPE_CLEARED, self.CLEAR_TYPE_FULL_COMBO, ]: - raise Exception("Invalid clear type value {}".format(clear_type)) + raise Exception(f"Invalid clear type value {clear_type}") # Range check grade if grade not in [ @@ -209,7 +209,7 @@ class MusecaBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.GRADE_MASTERPIECE, self.GRADE_PERFECT, ]: - raise Exception("Invalid grade value {}".format(grade)) + raise Exception(f"Invalid grade value {grade}") if userid is not None: oldscore = self.data.local.music.get_score( diff --git a/bemani/backend/museca/museca1.py b/bemani/backend/museca/museca1.py index a077bf5..25b7431 100644 --- a/bemani/backend/museca/museca1.py +++ b/bemani/backend/museca/museca1.py @@ -340,7 +340,7 @@ class Museca1( self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', paramvals, ) diff --git a/bemani/backend/museca/museca1plus.py b/bemani/backend/museca/museca1plus.py index e998882..5771178 100644 --- a/bemani/backend/museca/museca1plus.py +++ b/bemani/backend/museca/museca1plus.py @@ -381,7 +381,7 @@ class Museca1Plus( self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', paramvals, ) diff --git a/bemani/backend/popn/base.py b/bemani/backend/popn/base.py index 37b5eb3..47939a8 100644 --- a/bemani/backend/popn/base.py +++ b/bemani/backend/popn/base.py @@ -191,7 +191,7 @@ class PopnMusicBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.PLAY_MEDAL_STAR_FULL_COMBO, self.PLAY_MEDAL_PERFECT, ]: - raise Exception("Invalid medal value {}".format(medal)) + raise Exception(f"Invalid medal value {medal}") oldscore = self.data.local.music.get_score( self.game, diff --git a/bemani/backend/popn/eclale.py b/bemani/backend/popn/eclale.py index 990bf75..9f2c53a 100644 --- a/bemani/backend/popn/eclale.py +++ b/bemani/backend/popn/eclale.py @@ -246,7 +246,7 @@ class PopnMusicEclale(PopnMusicBase): self.version, userid, itemid, - 'item_{}'.format(itemtype), + f'item_{itemtype}', { 'param': itemparam, 'is_new': True, @@ -688,7 +688,7 @@ class PopnMusicEclale(PopnMusicBase): self.version, userid, itemid, - 'item_{}'.format(itemtype), + f'item_{itemtype}', { 'param': param, 'is_new': is_new, diff --git a/bemani/backend/popn/fantasia.py b/bemani/backend/popn/fantasia.py index 3b4f273..e79cdc7 100644 --- a/bemani/backend/popn/fantasia.py +++ b/bemani/backend/popn/fantasia.py @@ -201,7 +201,7 @@ class PopnMusicFantasia(PopnMusicBase): netvs.add_child(Node.s8_array('jewelry', [0] * 15)) for dialog in [0, 1, 2, 3, 4, 5]: # TODO: Configure this, maybe? - netvs.add_child(Node.string('dialog', 'dialog#{}'.format(dialog))) + netvs.add_child(Node.string('dialog', f'dialog#{dialog}')) sp_data = Node.void('sp_data') root.add_child(sp_data) diff --git a/bemani/backend/popn/lapistoria.py b/bemani/backend/popn/lapistoria.py index afd84f2..6e15319 100644 --- a/bemani/backend/popn/lapistoria.py +++ b/bemani/backend/popn/lapistoria.py @@ -335,7 +335,7 @@ class PopnMusicLapistoria(PopnMusicBase): netvs.add_child(Node.u32('netvs_play_cnt', 0)) for dialog in [0, 1, 2, 3, 4, 5]: # TODO: Configure this, maybe? - netvs.add_child(Node.string('dialog', 'dialog#{}'.format(dialog))) + netvs.add_child(Node.string('dialog', f'dialog#{dialog}')) # Set up config config = Node.void('config') diff --git a/bemani/backend/popn/sunnypark.py b/bemani/backend/popn/sunnypark.py index f06f1ff..3a5ac8e 100644 --- a/bemani/backend/popn/sunnypark.py +++ b/bemani/backend/popn/sunnypark.py @@ -210,7 +210,7 @@ class PopnMusicSunnyPark(PopnMusicBase): netvs.add_child(Node.u8('netvs_play_cnt', 0)) for dialog in [0, 1, 2, 3, 4, 5]: # TODO: Configure this, maybe? - netvs.add_child(Node.string('dialog', 'dialog#{}'.format(dialog))) + netvs.add_child(Node.string('dialog', f'dialog#{dialog}')) sp_data = Node.void('sp_data') root.add_child(sp_data) diff --git a/bemani/backend/popn/usaneko.py b/bemani/backend/popn/usaneko.py index 21b563e..2f31feb 100644 --- a/bemani/backend/popn/usaneko.py +++ b/bemani/backend/popn/usaneko.py @@ -363,7 +363,7 @@ class PopnMusicUsaNeko(PopnMusicBase): achievements.append( Achievement( itemid, - 'item_{}'.format(itemtype), + f'item_{itemtype}', 0, { 'param': param, @@ -622,7 +622,7 @@ class PopnMusicUsaNeko(PopnMusicBase): self.version, userid, itemid, - 'item_{}'.format(itemtype), + f'item_{itemtype}', { 'param': itemparam, 'is_new': True, @@ -1124,7 +1124,7 @@ class PopnMusicUsaNeko(PopnMusicBase): self.version, userid, itemid, - 'item_{}'.format(itemtype), + f'item_{itemtype}', { 'param': param, 'is_new': is_new, diff --git a/bemani/backend/reflec/base.py b/bemani/backend/reflec/base.py index 8c012bd..f67e1fd 100644 --- a/bemani/backend/reflec/base.py +++ b/bemani/backend/reflec/base.py @@ -143,7 +143,7 @@ class ReflecBeatBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.CLEAR_TYPE_HARD_CLEARED, self.CLEAR_TYPE_S_HARD_CLEARED, ]: - raise Exception("Invalid clear_type value {}".format(clear_type)) + raise Exception(f"Invalid clear_type value {clear_type}") # Range check combo type if combo_type not in [ @@ -152,7 +152,7 @@ class ReflecBeatBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.COMBO_TYPE_FULL_COMBO, self.COMBO_TYPE_FULL_COMBO_ALL_JUST, ]: - raise Exception("Invalid combo_type value {}".format(combo_type)) + raise Exception(f"Invalid combo_type value {combo_type}") oldscore = self.data.local.music.get_score( self.game, diff --git a/bemani/backend/reflec/colette.py b/bemani/backend/reflec/colette.py index 95f1f22..00b49c0 100644 --- a/bemani/backend/reflec/colette.py +++ b/bemani/backend/reflec/colette.py @@ -60,8 +60,8 @@ class ReflecBeatColette(ReflecBeatBase): self.COMBO_TYPE_FULL_COMBO_ALL_JUST, ]: return self.GAME_CLEAR_TYPE_FULL_COMBO - raise Exception('Invalid db_combo_type {}'.format(db_combo_type)) - raise Exception('Invalid db_clear_type {}'.format(db_clear_type)) + raise Exception(f'Invalid db_combo_type {db_combo_type}') + raise Exception(f'Invalid db_clear_type {db_clear_type}') def __game_to_db_clear_type(self, game_clear_type: int) -> Tuple[int, int]: if game_clear_type == self.GAME_CLEAR_TYPE_NO_PLAY: @@ -75,7 +75,7 @@ class ReflecBeatColette(ReflecBeatBase): if game_clear_type == self.GAME_CLEAR_TYPE_FULL_COMBO: return (self.CLEAR_TYPE_CLEARED, self.COMBO_TYPE_FULL_COMBO) - raise Exception('Invalid game_clear_type {}'.format(game_clear_type)) + raise Exception(f'Invalid game_clear_type {game_clear_type}') def handle_pcb_error_request(self, request: Node) -> Node: return Node.void('pcb') @@ -1068,7 +1068,7 @@ class ReflecBeatColette(ReflecBeatBase): self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', { 'param': param, }, @@ -1170,7 +1170,7 @@ class ReflecBeatColette(ReflecBeatBase): self.version, userid, eqpexp_id, - 'eqpexp_{}'.format(eqpexp_stype), + f'eqpexp_{eqpexp_stype}', ) or ValidatedDict() self.data.local.user.put_achievement( @@ -1178,7 +1178,7 @@ class ReflecBeatColette(ReflecBeatBase): self.version, userid, eqpexp_id, - 'eqpexp_{}'.format(eqpexp_stype), + f'eqpexp_{eqpexp_stype}', { 'exp': data.get_int('exp') + eqpexp_exp, }, diff --git a/bemani/backend/reflec/groovin.py b/bemani/backend/reflec/groovin.py index 3af469a..ed1f309 100644 --- a/bemani/backend/reflec/groovin.py +++ b/bemani/backend/reflec/groovin.py @@ -90,7 +90,7 @@ class ReflecBeatGroovin(ReflecBeatBase): return self.COMBO_TYPE_FULL_COMBO if game_combo == self.GAME_COMBO_TYPE_FULL_COMBO_ALL_JUST: return self.COMBO_TYPE_FULL_COMBO_ALL_JUST - raise Exception('Invalid game_combo value {}'.format(game_combo)) + raise Exception(f'Invalid game_combo value {game_combo}') def handle_pcb_rb4error_request(self, request: Node) -> Node: return Node.void('pcb') @@ -1360,7 +1360,7 @@ class ReflecBeatGroovin(ReflecBeatBase): self.version, userid, bank, - 'player_param_{}'.format(item_type), + f'player_param_{item_type}', { 'data': paramdata, }, @@ -1376,7 +1376,7 @@ class ReflecBeatGroovin(ReflecBeatBase): # I assume this is copypasta, but I want to be sure extid = child.child_value('user_id') if extid != newprofile.get_int('extid'): - raise Exception('Unexpected user ID, got {} expecting {}'.format(extid, newprofile.get_int('extid'))) + raise Exception(f'Unexpected user ID, got {extid} expecting {newprofile.get_int("extid")}') episode_type = child.child_value('type') episode_value0 = child.child_value('value0') @@ -1416,7 +1416,7 @@ class ReflecBeatGroovin(ReflecBeatBase): self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', { 'param': param, }, @@ -1438,7 +1438,7 @@ class ReflecBeatGroovin(ReflecBeatBase): self.version, userid, announce_id, - 'announcement_{}'.format(announce_type), + f'announcement_{announce_type}', { 'param': param, 'need': need, diff --git a/bemani/backend/reflec/limelight.py b/bemani/backend/reflec/limelight.py index b9dea01..5460018 100644 --- a/bemani/backend/reflec/limelight.py +++ b/bemani/backend/reflec/limelight.py @@ -61,8 +61,8 @@ class ReflecBeatLimelight(ReflecBeatBase): ]: return self.GAME_CLEAR_TYPE_FULL_COMBO - raise Exception('Invalid db_combo_type {}'.format(db_combo_type)) - raise Exception('Invalid db_clear_type {}'.format(db_clear_type)) + raise Exception(f'Invalid db_combo_type {db_combo_type}') + raise Exception(f'Invalid db_clear_type {db_clear_type}') def __game_to_db_clear_type(self, game_clear_type: int) -> Tuple[int, int]: if game_clear_type == self.GAME_CLEAR_TYPE_NO_PLAY: @@ -74,7 +74,7 @@ class ReflecBeatLimelight(ReflecBeatBase): if game_clear_type == self.GAME_CLEAR_TYPE_FULL_COMBO: return (self.CLEAR_TYPE_CLEARED, self.COMBO_TYPE_FULL_COMBO) - raise Exception('Invalid game_clear_type {}'.format(game_clear_type)) + raise Exception(f'Invalid game_clear_type {game_clear_type}') def handle_log_exception_request(self, request: Node) -> Node: return Node.void('log') @@ -812,7 +812,7 @@ class ReflecBeatLimelight(ReflecBeatBase): self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', { 'param': param, }, diff --git a/bemani/backend/reflec/reflecbeat.py b/bemani/backend/reflec/reflecbeat.py index 23efaed..ecd40cc 100644 --- a/bemani/backend/reflec/reflecbeat.py +++ b/bemani/backend/reflec/reflecbeat.py @@ -56,8 +56,8 @@ class ReflecBeat(ReflecBeatBase): ]: return self.GAME_CLEAR_TYPE_FULL_COMBO - raise Exception('Invalid db_combo_type {}'.format(db_combo_type)) - raise Exception('Invalid db_clear_type {}'.format(db_clear_type)) + raise Exception(f'Invalid db_combo_type {db_combo_type}') + raise Exception(f'Invalid db_clear_type {db_clear_type}') def __game_to_db_clear_type(self, game_clear_type: int, game_achievement_rate: int) -> Tuple[int, int]: if game_clear_type == self.GAME_CLEAR_TYPE_NO_PLAY: @@ -70,7 +70,7 @@ class ReflecBeat(ReflecBeatBase): if game_clear_type == self.GAME_CLEAR_TYPE_FULL_COMBO: return (self.CLEAR_TYPE_CLEARED, self.COMBO_TYPE_FULL_COMBO) - raise Exception('Invalid game_clear_type {}'.format(game_clear_type)) + raise Exception(f'Invalid game_clear_type {game_clear_type}') def handle_log_pcb_status_request(self, request: Node) -> Node: return Node.void('log') @@ -450,7 +450,7 @@ class ReflecBeat(ReflecBeatBase): self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', {}, ) diff --git a/bemani/backend/reflec/volzza.py b/bemani/backend/reflec/volzza.py index 0d1afac..4ae8cc8 100644 --- a/bemani/backend/reflec/volzza.py +++ b/bemani/backend/reflec/volzza.py @@ -637,7 +637,7 @@ class ReflecBeatVolzza(ReflecBeatVolzzaBase): self.version, userid, bank, - 'player_param_{}'.format(item_type), + f'player_param_{item_type}', { 'data': data, }, @@ -653,7 +653,7 @@ class ReflecBeatVolzza(ReflecBeatVolzzaBase): # I assume this is copypasta, but I want to be sure extid = child.child_value('user_id') if extid != newprofile.get_int('extid'): - raise Exception('Unexpected user ID, got {} expecting {}'.format(extid, newprofile.get_int('extid'))) + raise Exception(f'Unexpected user ID, got {extid} expecting {newprofile.get_int("extid")}') episode_type = child.child_value('type') episode_value0 = child.child_value('value0') @@ -693,7 +693,7 @@ class ReflecBeatVolzza(ReflecBeatVolzzaBase): self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', { 'param': param, }, @@ -715,7 +715,7 @@ class ReflecBeatVolzza(ReflecBeatVolzzaBase): self.version, userid, announce_id, - 'announcement_{}'.format(announce_type), + f'announcement_{announce_type}', { 'param': param, 'need': need, diff --git a/bemani/backend/reflec/volzza2.py b/bemani/backend/reflec/volzza2.py index afeb7fc..e0992f9 100644 --- a/bemani/backend/reflec/volzza2.py +++ b/bemani/backend/reflec/volzza2.py @@ -753,7 +753,7 @@ class ReflecBeatVolzza2(ReflecBeatVolzzaBase): self.version, userid, bank, - 'player_param_{}'.format(item_type), + f'player_param_{item_type}', { 'data': data, }, @@ -769,7 +769,7 @@ class ReflecBeatVolzza2(ReflecBeatVolzzaBase): # I assume this is copypasta, but I want to be sure extid = child.child_value('user_id') if extid != newprofile.get_int('extid'): - raise Exception('Unexpected user ID, got {} expecting {}'.format(extid, newprofile.get_int('extid'))) + raise Exception(f'Unexpected user ID, got {extid} expecting {newprofile.get_int("extid")}') episode_type = child.child_value('type') episode_value0 = child.child_value('value0') @@ -810,7 +810,7 @@ class ReflecBeatVolzza2(ReflecBeatVolzzaBase): self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', { 'param': param, 'time': time, @@ -833,7 +833,7 @@ class ReflecBeatVolzza2(ReflecBeatVolzzaBase): self.version, userid, announce_id, - 'announcement_{}'.format(announce_type), + f'announcement_{announce_type}', { 'param': param, 'need': need, diff --git a/bemani/backend/reflec/volzzabase.py b/bemani/backend/reflec/volzzabase.py index c3630b7..74a0aac 100644 --- a/bemani/backend/reflec/volzzabase.py +++ b/bemani/backend/reflec/volzzabase.py @@ -65,7 +65,7 @@ class ReflecBeatVolzzaBase(ReflecBeatBase): return self.COMBO_TYPE_FULL_COMBO if game_combo == self.GAME_COMBO_TYPE_FULL_COMBO_ALL_JUST: return self.COMBO_TYPE_FULL_COMBO_ALL_JUST - raise Exception('Invalid game_combo value {}'.format(game_combo)) + raise Exception(f'Invalid game_combo value {game_combo}') def _add_event_info(self, root: Node) -> None: # Overridden in subclasses diff --git a/bemani/backend/sdvx/base.py b/bemani/backend/sdvx/base.py index c6c99e0..704e619 100644 --- a/bemani/backend/sdvx/base.py +++ b/bemani/backend/sdvx/base.py @@ -198,7 +198,7 @@ class SoundVoltexBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.CLEAR_TYPE_ULTIMATE_CHAIN, self.CLEAR_TYPE_PERFECT_ULTIMATE_CHAIN, ]: - raise Exception("Invalid clear type value {}".format(clear_type)) + raise Exception(f"Invalid clear type value {clear_type}") # Range check grade if grade not in [ @@ -214,7 +214,7 @@ class SoundVoltexBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): self.GRADE_AAA_PLUS, self.GRADE_S, ]: - raise Exception("Invalid clear type value {}".format(grade)) + raise Exception(f"Invalid clear type value {grade}") if userid is not None: oldscore = self.data.local.music.get_score( diff --git a/bemani/backend/sdvx/gravitywars.py b/bemani/backend/sdvx/gravitywars.py index a86248f..bf404fd 100644 --- a/bemani/backend/sdvx/gravitywars.py +++ b/bemani/backend/sdvx/gravitywars.py @@ -338,7 +338,7 @@ class SoundVoltexGravityWars( self.version, userid, item_id[i], - 'item_{}'.format(item_type[i]), + f'item_{item_type[i]}', { 'param': param[i], }, diff --git a/bemani/backend/sdvx/gravitywars_s1.py b/bemani/backend/sdvx/gravitywars_s1.py index 72a562d..7a8b40b 100644 --- a/bemani/backend/sdvx/gravitywars_s1.py +++ b/bemani/backend/sdvx/gravitywars_s1.py @@ -3318,7 +3318,7 @@ class SoundVoltexGravityWarsSeason1( self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', { 'param': param, }, diff --git a/bemani/backend/sdvx/gravitywars_s2.py b/bemani/backend/sdvx/gravitywars_s2.py index 4990265..d0a8ed8 100644 --- a/bemani/backend/sdvx/gravitywars_s2.py +++ b/bemani/backend/sdvx/gravitywars_s2.py @@ -4180,7 +4180,7 @@ class SoundVoltexGravityWarsSeason2( self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', { 'param': param, }, @@ -4225,7 +4225,7 @@ class SoundVoltexGravityWarsSeason2( self.version, userid, param_id, - 'param_{}'.format(param_type), + f'param_{param_type}', { 'param': param_param, }, diff --git a/bemani/backend/sdvx/infiniteinfection.py b/bemani/backend/sdvx/infiniteinfection.py index 19e5db1..9630216 100644 --- a/bemani/backend/sdvx/infiniteinfection.py +++ b/bemani/backend/sdvx/infiniteinfection.py @@ -2271,7 +2271,7 @@ class SoundVoltexInfiniteInfection( self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', { 'param': param, }, @@ -2476,7 +2476,7 @@ class SoundVoltexInfiniteInfection( self.version, userid, item_id, - 'item_{}'.format(item_type), + f'item_{item_type}', { 'param': param, }, diff --git a/bemani/client/base.py b/bemani/client/base.py index 0994fc6..219e064 100644 --- a/bemani/client/base.py +++ b/bemani/client/base.py @@ -41,12 +41,7 @@ class BaseClient: method = tree.children[0].attribute('method') return self.__proto.exchange( - '{}?model={}&module={}&method={}'.format( - path, - self.config['model'], - module, - method, - ), + f'{path}?model={self.config["model"]}&module={module}&method={method}', tree, ) @@ -92,7 +87,7 @@ class BaseClient: """ if not self.__assert_path(root, path): - raise Exception('Path \'{}\' not found in root node:\n{}'.format(path, root)) + raise Exception(f'Path \'{path}\' not found in root node:\n{root}') def verify_services_get(self, expected_services: List[str]=[]) -> None: call = self.call_node() @@ -126,7 +121,7 @@ class BaseClient: for service in expected_services: if service not in returned_services: - raise Exception('Service \'{}\' expected but not returned'.format(service)) + raise Exception(f'Service \'{service}\' expected but not returned') def verify_pcbtracker_alive(self, ecflag: int = 1) -> bool: call = self.call_node() @@ -262,7 +257,7 @@ class BaseClient: # Verify that we weren't found status = int(resp.child('cardmng').attribute('status')) if status != self.CARD_NEW: - raise Exception('Card \'{}\' returned invalid status \'{}\''.format(card_id, status)) + raise Exception(f'Card \'{card_id}\' returned invalid status \'{status}\'') # Nothing to return return None @@ -278,11 +273,11 @@ class BaseClient: ecflag = int(resp.child('cardmng').attribute('ecflag')) if binded != 0: - raise Exception('Card \'{}\' returned invalid binded value \'{}\''.format(card_id, binded)) + raise Exception(f'Card \'{card_id}\' returned invalid binded value \'{binded}\'') if newflag != 1: - raise Exception('Card \'{}\' returned invalid newflag value \'{}\''.format(card_id, newflag)) + raise Exception(f'Card \'{card_id}\' returned invalid newflag value \'{newflag}\'') if ecflag != (1 if paseli_enabled else 0): - raise Exception('Card \'{}\' returned invalid ecflag value \'{}\''.format(card_id, newflag)) + raise Exception(f'Card \'{card_id}\' returned invalid ecflag value \'{newflag}\'') # Return the refid return resp.child('cardmng').attribute('refid') @@ -298,16 +293,16 @@ class BaseClient: ecflag = int(resp.child('cardmng').attribute('ecflag')) if binded != 1: - raise Exception('Card \'{}\' returned invalid binded value \'{}\''.format(card_id, binded)) + raise Exception(f'Card \'{card_id}\' returned invalid binded value \'{binded}\'') if newflag != 1: - raise Exception('Card \'{}\' returned invalid newflag value \'{}\''.format(card_id, newflag)) + raise Exception(f'Card \'{card_id}\' returned invalid newflag value \'{newflag}\'') if ecflag != (1 if paseli_enabled else 0): - raise Exception('Card \'{}\' returned invalid ecflag value \'{}\''.format(card_id, newflag)) + raise Exception(f'Card \'{card_id}\' returned invalid ecflag value \'{newflag}\'') # Return the refid return resp.child('cardmng').attribute('refid') else: - raise Exception('Unrecognized message type \'{}\''.format(msg_type)) + raise Exception(f'Unrecognized message type \'{msg_type}\'') def verify_cardmng_getrefid(self, card_id: str) -> str: call = self.call_node() @@ -347,7 +342,7 @@ class BaseClient: status = int(resp.child('cardmng').attribute('status')) if status != (self.CARD_OK if correct else self.CARD_BAD_PIN): - raise Exception('Ref ID \'{}\' returned invalid status \'{}\''.format(ref_id, status)) + raise Exception(f'Ref ID \'{ref_id}\' returned invalid status \'{status}\'') def verify_eacoin_checkin(self, card_id: str) -> Tuple[str, int]: call = self.call_node() @@ -392,7 +387,7 @@ class BaseClient: newbalance = resp.child('eacoin').child_value('balance') if balance - amount != newbalance: - raise Exception("Expected to get back balance {} but got {}".format(balance - amount, newbalance)) + raise Exception(f"Expected to get back balance {balance - amount} but got {newbalance}") def verify_eacoin_checkout(self, session: str) -> None: call = self.call_node() diff --git a/bemani/client/bishi/bishi.py b/bemani/client/bishi/bishi.py index 27f96e4..1ac348a 100644 --- a/bemani/client/bishi/bishi.py +++ b/bemani/client/bishi/bishi.py @@ -187,15 +187,15 @@ class TheStarBishiBashiClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Bishi doesn't read a new profile, it just writes out CSV for a blank one self.verify_usergamedata_send(ref_id, msg_type='new') else: @@ -206,7 +206,7 @@ class TheStarBishiBashiClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify profile saving diff --git a/bemani/client/ddr/ddr2013.py b/bemani/client/ddr/ddr2013.py index a99adfc..f23d7d2 100644 --- a/bemani/client/ddr/ddr2013.py +++ b/bemani/client/ddr/ddr2013.py @@ -338,7 +338,7 @@ class DDR2013Client(BaseClient): self.assert_path(resp, "response/game/flag") self.assert_path(resp, "response/game/rank") for i in range(55): - self.assert_path(resp, "response/game/play_area/@play_cnt{}".format(i)) + self.assert_path(resp, f"response/game/play_area/@play_cnt{i}") gr_s = resp.child('game/gr_s') gr_d = resp.child('game/gr_d') @@ -537,15 +537,15 @@ class DDR2013Client(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Bishi doesn't read a new profile, it just writes out CSV for a blank one self.verify_game_load(ref_id, msg_type='new') self.verify_game_new(ref_id) @@ -557,7 +557,7 @@ class DDR2013Client(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify locking and unlocking profile ability self.verify_game_lock(ref_id, 1) @@ -698,7 +698,7 @@ class DDR2013Client(BaseClient): for score in dummyscores: data = scores.get(score['id'], {}).get(score['chart'], None) if data is None: - raise Exception('Expected to get score back for song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Expected to get score back for song {score["id"]} chart {score["chart"]}!') # Verify the attributes of the score expected_score = score.get('expected_score', score['score']) @@ -706,22 +706,16 @@ class DDR2013Client(BaseClient): expected_halo = score.get('expected_halo', score['halo']) if data['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["score"]}\'') if data['rank'] != expected_rank: - raise Exception('Expected a rank of \'{}\' for song \'{}\' chart \'{}\' but got rank \'{}\''.format( - expected_rank, score['id'], score['chart'], data['rank'], - )) + raise Exception(f'Expected a rank of \'{expected_rank}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got rank \'{data["rank"]}\'') if data['halo'] != expected_halo: - raise Exception('Expected a halo of \'{}\' for song \'{}\' chart \'{}\' but got halo \'{}\''.format( - expected_halo, score['id'], score['chart'], data['halo'], - )) + raise Exception(f'Expected a halo of \'{expected_halo}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got halo \'{data["halo"]}\'') # Verify that the last score is our score last_five = self.verify_game_score(ref_id, score['id'], score['chart']) if last_five[0] != score['score']: - raise Exception('Invalid score returned for last five scores on song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Invalid score returned for last five scores on song {score["id"]} chart {score["chart"]}!') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/ddr/ddr2014.py b/bemani/client/ddr/ddr2014.py index 772f65c..1979069 100644 --- a/bemani/client/ddr/ddr2014.py +++ b/bemani/client/ddr/ddr2014.py @@ -343,7 +343,7 @@ class DDR2014Client(BaseClient): self.assert_path(resp, "response/game/target/@flag") self.assert_path(resp, "response/game/target/@setnum") for i in range(55): - self.assert_path(resp, "response/game/play_area/@play_cnt{}".format(i)) + self.assert_path(resp, f"response/game/play_area/@play_cnt{i}") gr_s = resp.child('game/gr_s') gr_d = resp.child('game/gr_d') @@ -539,15 +539,15 @@ class DDR2014Client(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Bishi doesn't read a new profile, it just writes out CSV for a blank one self.verify_game_load(ref_id, msg_type='new') self.verify_game_new(ref_id) @@ -559,7 +559,7 @@ class DDR2014Client(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify locking and unlocking profile ability self.verify_game_lock(ref_id, 1) @@ -695,7 +695,7 @@ class DDR2014Client(BaseClient): for score in dummyscores: data = scores.get(score['id'], {}).get(score['chart'], None) if data is None: - raise Exception('Expected to get score back for song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Expected to get score back for song {score["id"]} chart {score["chart"]}!') # Verify the attributes of the score expected_score = score.get('expected_score', score['score']) @@ -703,17 +703,11 @@ class DDR2014Client(BaseClient): expected_halo = score.get('expected_halo', score['halo']) if data['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["score"]}\'') if data['rank'] != expected_rank: - raise Exception('Expected a rank of \'{}\' for song \'{}\' chart \'{}\' but got rank \'{}\''.format( - expected_rank, score['id'], score['chart'], data['rank'], - )) + raise Exception(f'Expected a rank of \'{expected_rank}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got rank \'{data["rank"]}\'') if data['halo'] != expected_halo: - raise Exception('Expected a halo of \'{}\' for song \'{}\' chart \'{}\' but got halo \'{}\''.format( - expected_halo, score['id'], score['chart'], data['halo'], - )) + raise Exception(f'Expected a halo of \'{expected_halo}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got halo \'{data["halo"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/ddr/ddrace.py b/bemani/client/ddr/ddrace.py index df00ad9..369ea50 100644 --- a/bemani/client/ddr/ddrace.py +++ b/bemani/client/ddr/ddrace.py @@ -595,7 +595,7 @@ class DDRAceClient(BaseClient): profiledata['COMMON'][25] = self.NAME.encode('shift-jis') else: - raise Exception('Unknown message type {}!'.format(msg_type)) + raise Exception(f'Unknown message type {msg_type}!') if send_only_common: profiledata = {'COMMON': profiledata['COMMON']} @@ -707,16 +707,16 @@ class DDRAceClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) self.verify_system_convcardnumber(card) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') extid = self.verify_playerdata_usergamedata_advanced_usernew(ref_id) self.verify_usergamedata_send(ref_id, extid, 'new') self.verify_playerdata_usergamedata_advanced_inheritance(ref_id, location) @@ -735,7 +735,7 @@ class DDRAceClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: is_new, music = self.verify_playerdata_usergamedata_advanced_userload(ref_id) @@ -836,7 +836,7 @@ class DDRAceClient(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -852,17 +852,11 @@ class DDRAceClient(BaseClient): expected_halo = expected['halo'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['rank'] != expected_rank: - raise Exception('Expected a rank of \'{}\' for song \'{}\' chart \'{}\' but got rank \'{}\''.format( - expected_rank, expected['id'], expected['chart'], actual['rank'], - )) + raise Exception(f'Expected a rank of \'{expected_rank}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got rank \'{actual["rank"]}\'') if actual['halo'] != expected_halo: - raise Exception('Expected a halo of \'{}\' for song \'{}\' chart \'{}\' but got halo \'{}\''.format( - expected_halo, expected['id'], expected['chart'], actual['halo'], - )) + raise Exception(f'Expected a halo of \'{expected_halo}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got halo \'{actual["halo"]}\'') # Now verify that the ghost for this score is what we saved ghost = self.verify_playerdata_usergamedata_advanced_ghostload(ref_id, received['ghostid']) @@ -872,21 +866,13 @@ class DDRAceClient(BaseClient): expected_ghost = expected['ghost'] if ghost['id'] != received['id']: - raise Exception('Wrong song ID \'{}\' returned for ghost, expected ID \'{}\''.format( - ghost['id'], received['id'], - )) + raise Exception(f'Wrong song ID \'{ghost["id"]}\' returned for ghost, expected ID \'{received["id"]}\'') if ghost['chart'] != received['chart']: - raise Exception('Wrong song chart \'{}\' returned for ghost, expected chart \'{}\''.format( - ghost['chart'], received['chart'], - )) + raise Exception(f'Wrong song chart \'{ghost["chart"]}\' returned for ghost, expected chart \'{received["chart"]}\'') if ghost['ghost'] != expected_ghost: - raise Exception('Wrong ghost data \'{}\' returned for ghost, expected \'{}\''.format( - ghost['ghost'], expected_ghost, - )) + raise Exception(f'Wrong ghost data \'{ghost["ghost"]}\' returned for ghost, expected \'{expected_ghost}\'') if ghost['extid'] != extid: - raise Exception('Wrong extid \'{}\' returned for ghost, expected \'{}\''.format( - ghost['extid'], extid, - )) + raise Exception(f'Wrong extid \'{ghost["extid"]}\' returned for ghost, expected \'{extid}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/ddr/ddrx2.py b/bemani/client/ddr/ddrx2.py index d4c388e..b9176cd 100644 --- a/bemani/client/ddr/ddrx2.py +++ b/bemani/client/ddr/ddrx2.py @@ -497,15 +497,15 @@ class DDRX2Client(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Bishi doesn't read a new profile, it just writes out CSV for a blank one self.verify_game_load(ref_id, msg_type='new') self.verify_game_new(ref_id) @@ -517,7 +517,7 @@ class DDRX2Client(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify locking and unlocking profile ability self.verify_game_lock(ref_id, 1) @@ -652,7 +652,7 @@ class DDRX2Client(BaseClient): for score in dummyscores: data = scores.get(score['id'], {}).get(score['chart'], None) if data is None: - raise Exception('Expected to get score back for song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Expected to get score back for song {score["id"]} chart {score["chart"]}!') # Verify the attributes of the score expected_score = score.get('expected_score', score['score']) @@ -660,22 +660,16 @@ class DDRX2Client(BaseClient): expected_halo = score.get('expected_halo', score['halo']) if data['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["score"]}\'') if data['rank'] != expected_rank: - raise Exception('Expected a rank of \'{}\' for song \'{}\' chart \'{}\' but got rank \'{}\''.format( - expected_rank, score['id'], score['chart'], data['rank'], - )) + raise Exception(f'Expected a rank of \'{expected_rank}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got rank \'{data["rank"]}\'') if data['halo'] != expected_halo: - raise Exception('Expected a halo of \'{}\' for song \'{}\' chart \'{}\' but got halo \'{}\''.format( - expected_halo, score['id'], score['chart'], data['halo'], - )) + raise Exception(f'Expected a halo of \'{expected_halo}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got halo \'{data["halo"]}\'') # Verify that the last score is our score last_five = self.verify_game_score(ref_id, score['id'], score['chart']) if last_five[0] != score['score']: - raise Exception('Invalid score returned for last five scores on song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Invalid score returned for last five scores on song {score["id"]} chart {score["chart"]}!') # Sleep so we don't end up putting in score history on the same second time.sleep(1) @@ -739,7 +733,7 @@ class DDRX2Client(BaseClient): for course in dummycourses: data = courses.get(course['id'], {}).get(course['chart'], None) if data is None: - raise Exception('Expected to get course back for course {} chart {}!'.format(course['id'], course['chart'])) + raise Exception(f'Expected to get course back for course {course["id"]} chart {course["chart"]}!') expected_score = course.get('expected_score', course['score']) expected_combo = course.get('expected_combo', course['combo']) @@ -748,25 +742,15 @@ class DDRX2Client(BaseClient): expected_combo_type = course.get('expected_combo_type', course['combo_type']) if data['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for course \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, course['id'], course['chart'], data['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for course \'{course["id"]}\' chart \'{course["chart"]}\' but got score \'{data["score"]}\'') if data['combo'] != expected_combo: - raise Exception('Expected a combo of \'{}\' for course \'{}\' chart \'{}\' but got combo \'{}\''.format( - expected_combo, course['id'], course['chart'], data['combo'], - )) + raise Exception(f'Expected a combo of \'{expected_combo}\' for course \'{course["id"]}\' chart \'{course["chart"]}\' but got combo \'{data["combo"]}\'') if data['rank'] != expected_rank: - raise Exception('Expected a rank of \'{}\' for course \'{}\' chart \'{}\' but got rank \'{}\''.format( - expected_rank, course['id'], course['chart'], data['rank'], - )) + raise Exception(f'Expected a rank of \'{expected_rank}\' for course \'{course["id"]}\' chart \'{course["chart"]}\' but got rank \'{data["rank"]}\'') if data['stage'] != expected_stage: - raise Exception('Expected a stage of \'{}\' for course \'{}\' chart \'{}\' but got stage \'{}\''.format( - expected_stage, course['id'], course['chart'], data['stage'], - )) + raise Exception(f'Expected a stage of \'{expected_stage}\' for course \'{course["id"]}\' chart \'{course["chart"]}\' but got stage \'{data["stage"]}\'') if data['combo_type'] != expected_combo_type: - raise Exception('Expected a combo_type of \'{}\' for course \'{}\' chart \'{}\' but got combo_type \'{}\''.format( - expected_combo_type, course['id'], course['chart'], data['combo_type'], - )) + raise Exception(f'Expected a combo_type of \'{expected_combo_type}\' for course \'{course["id"]}\' chart \'{course["chart"]}\' but got combo_type \'{data["combo_type"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/ddr/ddrx3.py b/bemani/client/ddr/ddrx3.py index d41b9d3..617ddab 100644 --- a/bemani/client/ddr/ddrx3.py +++ b/bemani/client/ddr/ddrx3.py @@ -312,7 +312,7 @@ class DDRX3Client(BaseClient): self.assert_path(resp, "response/game/flag") self.assert_path(resp, "response/game/rank") for i in range(55): - self.assert_path(resp, "response/game/play_area/@play_cnt{}".format(i)) + self.assert_path(resp, f"response/game/play_area/@play_cnt{i}") gr_s = resp.child('game/gr_s') gr_d = resp.child('game/gr_d') @@ -574,15 +574,15 @@ class DDRX3Client(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Bishi doesn't read a new profile, it just writes out CSV for a blank one self.verify_game_load(ref_id, msg_type='new') self.verify_game_new(ref_id) @@ -594,7 +594,7 @@ class DDRX3Client(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify locking and unlocking profile ability self.verify_game_lock(ref_id, 1) @@ -775,7 +775,7 @@ class DDRX3Client(BaseClient): for score in dummyscores: data = scores.get(score['id'], {}).get(score['chart'], None) if data is None: - raise Exception('Expected to get score back for song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Expected to get score back for song {score["id"]} chart {score["chart"]}!') # Verify the attributes of the score expected_score = score.get('expected_score', score['score']) @@ -786,31 +786,21 @@ class DDRX3Client(BaseClient): if score['score'] != 0: if data['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["score"]}\'') if data['rank'] != expected_rank: - raise Exception('Expected a rank of \'{}\' for song \'{}\' chart \'{}\' but got rank \'{}\''.format( - expected_rank, score['id'], score['chart'], data['rank'], - )) + raise Exception(f'Expected a rank of \'{expected_rank}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got rank \'{data["rank"]}\'') if data['halo'] != expected_halo: - raise Exception('Expected a halo of \'{}\' for song \'{}\' chart \'{}\' but got halo \'{}\''.format( - expected_halo, score['id'], score['chart'], data['halo'], - )) + raise Exception(f'Expected a halo of \'{expected_halo}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got halo \'{data["halo"]}\'') # Verify that the last score is our score last_five = self.verify_game_score(ref_id, score['id'], score['chart']) if last_five[0] != score['score']: - raise Exception('Invalid score returned for last five scores on song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Invalid score returned for last five scores on song {score["id"]} chart {score["chart"]}!') if score['score_2nd'] != 0: if data['score_2nd'] != expected_score_2nd: - raise Exception('Expected a score_2nd of \'{}\' for song \'{}\' chart \'{}\' but got score_2nd \'{}\''.format( - expected_score_2nd, score['id'], score['chart'], data['score_2nd'], - )) + raise Exception(f'Expected a score_2nd of \'{expected_score_2nd}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score_2nd \'{data["score_2nd"]}\'') if data['rank_2nd'] != expected_rank_2nd: - raise Exception('Expected a rank_2nd of \'{}\' for song \'{}\' chart \'{}\' but got rank_2nd \'{}\''.format( - expected_rank_2nd, score['id'], score['chart'], data['rank_2nd'], - )) + raise Exception(f'Expected a rank_2nd of \'{expected_rank_2nd}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got rank_2nd \'{data["rank_2nd"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) @@ -874,7 +864,7 @@ class DDRX3Client(BaseClient): for course in dummycourses: data = courses.get(course['id'], {}).get(course['chart'], None) if data is None: - raise Exception('Expected to get course back for course {} chart {}!'.format(course['id'], course['chart'])) + raise Exception(f'Expected to get course back for course {course["id"]} chart {course["chart"]}!') expected_score = course.get('expected_score', course['score']) expected_combo = course.get('expected_combo', course['combo']) @@ -883,25 +873,15 @@ class DDRX3Client(BaseClient): expected_combo_type = course.get('expected_combo_type', course['combo_type']) if data['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for course \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, course['id'], course['chart'], data['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for course \'{course["id"]}\' chart \'{course["chart"]}\' but got score \'{data["score"]}\'') if data['combo'] != expected_combo: - raise Exception('Expected a combo of \'{}\' for course \'{}\' chart \'{}\' but got combo \'{}\''.format( - expected_combo, course['id'], course['chart'], data['combo'], - )) + raise Exception(f'Expected a combo of \'{expected_combo}\' for course \'{course["id"]}\' chart \'{course["chart"]}\' but got combo \'{data["combo"]}\'') if data['rank'] != expected_rank: - raise Exception('Expected a rank of \'{}\' for course \'{}\' chart \'{}\' but got rank \'{}\''.format( - expected_rank, course['id'], course['chart'], data['rank'], - )) + raise Exception(f'Expected a rank of \'{expected_rank}\' for course \'{course["id"]}\' chart \'{course["chart"]}\' but got rank \'{data["rank"]}\'') if data['stage'] != expected_stage: - raise Exception('Expected a stage of \'{}\' for course \'{}\' chart \'{}\' but got stage \'{}\''.format( - expected_stage, course['id'], course['chart'], data['stage'], - )) + raise Exception(f'Expected a stage of \'{expected_stage}\' for course \'{course["id"]}\' chart \'{course["chart"]}\' but got stage \'{data["stage"]}\'') if data['combo_type'] != expected_combo_type: - raise Exception('Expected a combo_type of \'{}\' for course \'{}\' chart \'{}\' but got combo_type \'{}\''.format( - expected_combo_type, course['id'], course['chart'], data['combo_type'], - )) + raise Exception(f'Expected a combo_type of \'{expected_combo_type}\' for course \'{course["id"]}\' chart \'{course["chart"]}\' but got combo_type \'{data["combo_type"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/iidx/copula.py b/bemani/client/iidx/copula.py index 59019f0..13ec61d 100644 --- a/bemani/client/iidx/copula.py +++ b/bemani/client/iidx/copula.py @@ -85,12 +85,12 @@ class IIDXCopulaClient(BaseClient): self.assert_path(resp, "response/IIDX23music") for child in resp.child("IIDX23music").children: if child.name != 'c': - raise Exception('Invalid node {} in clear rate response!'.format(child)) + raise Exception(f'Invalid node {child} in clear rate response!') if len(child.value) != 12: - raise Exception('Invalid node data {} in clear rate response!'.format(child)) + raise Exception(f'Invalid node data {child} in clear rate response!') for v in child.value: if v < 0 or v > 101: - raise Exception('Invalid clear percent {} in clear rate response!'.format(child)) + raise Exception(f'Invalid clear percent {child} in clear rate response!') def verify_iidx23shop_getconvention(self, lid: str) -> None: call = self.call_node() @@ -209,7 +209,7 @@ class IIDXCopulaClient(BaseClient): name = resp.child('IIDX23pc/pcdata').attribute('name') if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') # Extract and return account data ir_data: Dict[int, Dict[int, Dict[str, int]]] = {} @@ -657,15 +657,15 @@ class IIDXCopulaClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_iidx23pc_reg(ref_id, card, lid) self.verify_iidx23pc_get(ref_id, card, lid) else: @@ -676,7 +676,7 @@ class IIDXCopulaClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -770,7 +770,7 @@ class IIDXCopulaClient(BaseClient): for score in dummyscores: data = scores.get(score['id'], {}).get(score['chart'], None) if data is None: - raise Exception('Expected to get score back for song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Expected to get score back for song {score["id"]} chart {score["chart"]}!') if 'expected_ex_score' in score: expected_score = score['expected_ex_score'] @@ -786,30 +786,22 @@ class IIDXCopulaClient(BaseClient): expected_miss_count = score['mnum'] if data['ex_score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['ex_score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["ex_score"]}\'') if data['clear_status'] != expected_clear_status: - raise Exception('Expected a clear status of \'{}\' for song \'{}\' chart \'{}\' but got clear status \'{}\''.format( - expected_clear_status, score['id'], score['chart'], data['clear_status'], - )) + raise Exception(f'Expected a clear status of \'{expected_clear_status}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got clear status \'{data["clear_status"]}\'') if data['miss_count'] != expected_miss_count: - raise Exception('Expected a miss count of \'{}\' for song \'{}\' chart \'{}\' but got miss count \'{}\''.format( - expected_miss_count, score['id'], score['chart'], data['miss_count'], - )) + raise Exception(f'Expected a miss count of \'{expected_miss_count}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got miss count \'{data["miss_count"]}\'') # Verify we can fetch our own ghost ex_score, ghost = self.verify_iidx23music_appoint(profile['extid'], score['id'], score['chart']) if ex_score != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['ex_score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["ex_score"]}\'') if len(ghost) != 64: - raise Exception('Wrong ghost length {} for ghost!'.format(len(ghost))) + raise Exception(f'Wrong ghost length {len(ghost)} for ghost!') for g in ghost: if g != 0x01: - raise Exception('Got back wrong ghost data for song \'{}\' chart \'{}\''.format(score['id'], score['chart'])) + raise Exception(f'Got back wrong ghost data for song \'{score["id"]}\' chart \'{score["chart"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) @@ -866,9 +858,9 @@ class IIDXCopulaClient(BaseClient): }) scores = self.verify_iidx23music_getrank(profile['extid']) if 1000 not in scores: - raise Exception('Didn\'t get expected scores back for song {} beginner chart!'.format(1000)) + raise Exception(f'Didn\'t get expected scores back for song {1000} beginner chart!') if 6 not in scores[1000]: - raise Exception('Didn\'t get beginner score back for song {}!'.format(1000)) + raise Exception(f'Didn\'t get beginner score back for song {1000}!') if scores[1000][6] != {'clear_status': 4, 'ex_score': -1, 'miss_count': -1}: raise Exception('Didn\'t get correct status back from beginner save!') @@ -887,7 +879,7 @@ class IIDXCopulaClient(BaseClient): profile = self.verify_iidx23pc_get(ref_id, card, lid) for ptype in ['ir_data', 'secret_course_data']: if profile[ptype] != {2: {1: {'clear_status': 4, 'pgnum': 1771, 'gnum': 967}}}: - raise Exception('Invalid data {} returned on profile load for {}!'.format(profile[ptype], ptype)) + raise Exception(f'Invalid data {profile[ptype]} returned on profile load for {ptype}!') else: print("Skipping score checks for existing card") diff --git a/bemani/client/iidx/pendual.py b/bemani/client/iidx/pendual.py index dd41379..80ed0e5 100644 --- a/bemani/client/iidx/pendual.py +++ b/bemani/client/iidx/pendual.py @@ -85,12 +85,12 @@ class IIDXPendualClient(BaseClient): self.assert_path(resp, "response/IIDX22music") for child in resp.child("IIDX22music").children: if child.name != 'c': - raise Exception('Invalid node {} in clear rate response!'.format(child)) + raise Exception(f'Invalid node {child} in clear rate response!') if len(child.value) != 12: - raise Exception('Invalid node data {} in clear rate response!'.format(child)) + raise Exception(f'Invalid node data {child} in clear rate response!') for v in child.value: if v < 0 or v > 101: - raise Exception('Invalid clear percent {} in clear rate response!'.format(child)) + raise Exception(f'Invalid clear percent {child} in clear rate response!') def verify_iidx22shop_getconvention(self, lid: str) -> None: call = self.call_node() @@ -210,7 +210,7 @@ class IIDXPendualClient(BaseClient): name = resp.child('IIDX22pc/pcdata').attribute('name') if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') # Extract and return account data ir_data: Dict[int, Dict[int, Dict[str, int]]] = {} @@ -658,15 +658,15 @@ class IIDXPendualClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_iidx22pc_reg(ref_id, card, lid) self.verify_iidx22pc_get(ref_id, card, lid) else: @@ -677,7 +677,7 @@ class IIDXPendualClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -771,7 +771,7 @@ class IIDXPendualClient(BaseClient): for score in dummyscores: data = scores.get(score['id'], {}).get(score['chart'], None) if data is None: - raise Exception('Expected to get score back for song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Expected to get score back for song {score["id"]} chart {score["chart"]}!') if 'expected_ex_score' in score: expected_score = score['expected_ex_score'] @@ -787,30 +787,22 @@ class IIDXPendualClient(BaseClient): expected_miss_count = score['mnum'] if data['ex_score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['ex_score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["ex_score"]}\'') if data['clear_status'] != expected_clear_status: - raise Exception('Expected a clear status of \'{}\' for song \'{}\' chart \'{}\' but got clear status \'{}\''.format( - expected_clear_status, score['id'], score['chart'], data['clear_status'], - )) + raise Exception(f'Expected a clear status of \'{expected_clear_status}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got clear status \'{data["clear_status"]}\'') if data['miss_count'] != expected_miss_count: - raise Exception('Expected a miss count of \'{}\' for song \'{}\' chart \'{}\' but got miss count \'{}\''.format( - expected_miss_count, score['id'], score['chart'], data['miss_count'], - )) + raise Exception(f'Expected a miss count of \'{expected_miss_count}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got miss count \'{data["miss_count"]}\'') # Verify we can fetch our own ghost ex_score, ghost = self.verify_iidx22music_appoint(profile['extid'], score['id'], score['chart']) if ex_score != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['ex_score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["ex_score"]}\'') if len(ghost) != 64: - raise Exception('Wrong ghost length {} for ghost!'.format(len(ghost))) + raise Exception(f'Wrong ghost length {len(ghost)} for ghost!') for g in ghost: if g != 0x01: - raise Exception('Got back wrong ghost data for song \'{}\' chart \'{}\''.format(score['id'], score['chart'])) + raise Exception(f'Got back wrong ghost data for song \'{score["id"]}\' chart \'{score["chart"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) @@ -867,9 +859,9 @@ class IIDXPendualClient(BaseClient): }) scores = self.verify_iidx22music_getrank(profile['extid']) if 1000 not in scores: - raise Exception('Didn\'t get expected scores back for song {} beginner chart!'.format(1000)) + raise Exception(f'Didn\'t get expected scores back for song {1000} beginner chart!') if 6 not in scores[1000]: - raise Exception('Didn\'t get beginner score back for song {}!'.format(1000)) + raise Exception(f'Didn\'t get beginner score back for song {1000}!') if scores[1000][6] != {'clear_status': 4, 'ex_score': -1, 'miss_count': -1}: raise Exception('Didn\'t get correct status back from beginner save!') @@ -888,7 +880,7 @@ class IIDXPendualClient(BaseClient): profile = self.verify_iidx22pc_get(ref_id, card, lid) for ptype in ['ir_data', 'secret_course_data']: if profile[ptype] != {2: {1: {'clear_status': 4, 'pgnum': 1771, 'gnum': 967}}}: - raise Exception('Invalid data {} returned on profile load for {}!'.format(profile[ptype], ptype)) + raise Exception(f'Invalid data {profile[ptype]} returned on profile load for {ptype}!') else: print("Skipping score checks for existing card") diff --git a/bemani/client/iidx/sinobuz.py b/bemani/client/iidx/sinobuz.py index 6899034..eae8705 100644 --- a/bemani/client/iidx/sinobuz.py +++ b/bemani/client/iidx/sinobuz.py @@ -87,12 +87,12 @@ class IIDXSinobuzClient(BaseClient): self.assert_path(resp, "response/IIDX24music") for child in resp.child("IIDX24music").children: if child.name != 'c': - raise Exception('Invalid node {} in clear rate response!'.format(child)) + raise Exception(f'Invalid node {child} in clear rate response!') if len(child.value) != 12: - raise Exception('Invalid node data {} in clear rate response!'.format(child)) + raise Exception(f'Invalid node data {child} in clear rate response!') for v in child.value: if v < 0 or v > 1001: - raise Exception('Invalid clear percent {} in clear rate response!'.format(child)) + raise Exception(f'Invalid clear percent {child} in clear rate response!') def verify_iidx24shop_getconvention(self, lid: str) -> None: call = self.call_node() @@ -220,7 +220,7 @@ class IIDXSinobuzClient(BaseClient): name = resp.child('IIDX24pc/pcdata').attribute('name') if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') # Extract and return account data ir_data: Dict[int, Dict[int, Dict[str, int]]] = {} @@ -705,15 +705,15 @@ class IIDXSinobuzClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_iidx24pc_reg(ref_id, card, lid) self.verify_iidx24pc_get(ref_id, card, lid) else: @@ -724,7 +724,7 @@ class IIDXSinobuzClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -818,7 +818,7 @@ class IIDXSinobuzClient(BaseClient): for score in dummyscores: data = scores.get(score['id'], {}).get(score['chart'], None) if data is None: - raise Exception('Expected to get score back for song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Expected to get score back for song {score["id"]} chart {score["chart"]}!') if 'expected_ex_score' in score: expected_score = score['expected_ex_score'] @@ -834,30 +834,22 @@ class IIDXSinobuzClient(BaseClient): expected_miss_count = score['mnum'] if data['ex_score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['ex_score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["ex_score"]}\'') if data['clear_status'] != expected_clear_status: - raise Exception('Expected a clear status of \'{}\' for song \'{}\' chart \'{}\' but got clear status \'{}\''.format( - expected_clear_status, score['id'], score['chart'], data['clear_status'], - )) + raise Exception(f'Expected a clear status of \'{expected_clear_status}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got clear status \'{data["clear_status"]}\'') if data['miss_count'] != expected_miss_count: - raise Exception('Expected a miss count of \'{}\' for song \'{}\' chart \'{}\' but got miss count \'{}\''.format( - expected_miss_count, score['id'], score['chart'], data['miss_count'], - )) + raise Exception(f'Expected a miss count of \'{expected_miss_count}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got miss count \'{data["miss_count"]}\'') # Verify we can fetch our own ghost ex_score, ghost = self.verify_iidx24music_appoint(profile['extid'], score['id'], score['chart']) if ex_score != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['ex_score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["ex_score"]}\'') if len(ghost) != 64: - raise Exception('Wrong ghost length {} for ghost!'.format(len(ghost))) + raise Exception(f'Wrong ghost length {len(ghost)} for ghost!') for g in ghost: if g != 0x01: - raise Exception('Got back wrong ghost data for song \'{}\' chart \'{}\''.format(score['id'], score['chart'])) + raise Exception(f'Got back wrong ghost data for song \'{score["id"]}\' chart \'{score["chart"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) @@ -914,9 +906,9 @@ class IIDXSinobuzClient(BaseClient): }) scores = self.verify_iidx24music_getrank(profile['extid']) if 1000 not in scores: - raise Exception('Didn\'t get expected scores back for song {} beginner chart!'.format(1000)) + raise Exception(f'Didn\'t get expected scores back for song {1000} beginner chart!') if 6 not in scores[1000]: - raise Exception('Didn\'t get beginner score back for song {}!'.format(1000)) + raise Exception(f'Didn\'t get beginner score back for song {1000}!') if scores[1000][6] != {'clear_status': 4, 'ex_score': -1, 'miss_count': -1}: raise Exception('Didn\'t get correct status back from beginner save!') @@ -936,7 +928,7 @@ class IIDXSinobuzClient(BaseClient): profile = self.verify_iidx24pc_get(ref_id, card, lid) for ptype in ['ir_data', 'secret_course_data', 'classic_course_data']: if profile[ptype] != {2: {1: {'clear_status': 4, 'pgnum': 1771, 'gnum': 967}}}: - raise Exception('Invalid data {} returned on profile load for {}!'.format(profile[ptype], ptype)) + raise Exception(f'Invalid data {profile[ptype]} returned on profile load for {ptype}!') else: print("Skipping score checks for existing card") diff --git a/bemani/client/iidx/spada.py b/bemani/client/iidx/spada.py index ea055c0..2a3c724 100644 --- a/bemani/client/iidx/spada.py +++ b/bemani/client/iidx/spada.py @@ -87,12 +87,12 @@ class IIDXSpadaClient(BaseClient): self.assert_path(resp, "response/IIDX21music") for child in resp.child("IIDX21music").children: if child.name != 'c': - raise Exception('Invalid node {} in clear rate response!'.format(child)) + raise Exception(f'Invalid node {child} in clear rate response!') if len(child.value) != 12: - raise Exception('Invalid node data {} in clear rate response!'.format(child)) + raise Exception(f'Invalid node data {child} in clear rate response!') for v in child.value: if v < 0 or v > 101: - raise Exception('Invalid clear percent {} in clear rate response!'.format(child)) + raise Exception(f'Invalid clear percent {child} in clear rate response!') def verify_iidx21shop_getconvention(self, lid: str) -> None: call = self.call_node() @@ -210,7 +210,7 @@ class IIDXSpadaClient(BaseClient): name = resp.child('IIDX21pc/pcdata').attribute('name') if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') return { 'extid': int(resp.child('IIDX21pc/pcdata').attribute('id')), @@ -575,15 +575,15 @@ class IIDXSpadaClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_iidx21pc_reg(ref_id, card, lid) self.verify_iidx21pc_get(ref_id, card, lid) else: @@ -594,7 +594,7 @@ class IIDXSpadaClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -682,7 +682,7 @@ class IIDXSpadaClient(BaseClient): for score in dummyscores: data = scores.get(score['id'], {}).get(score['chart'], None) if data is None: - raise Exception('Expected to get score back for song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Expected to get score back for song {score["id"]} chart {score["chart"]}!') if 'expected_ex_score' in score: expected_score = score['expected_ex_score'] @@ -698,30 +698,22 @@ class IIDXSpadaClient(BaseClient): expected_miss_count = score['mnum'] if data['ex_score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['ex_score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["ex_score"]}\'') if data['clear_status'] != expected_clear_status: - raise Exception('Expected a clear status of \'{}\' for song \'{}\' chart \'{}\' but got clear status \'{}\''.format( - expected_clear_status, score['id'], score['chart'], data['clear_status'], - )) + raise Exception(f'Expected a clear status of \'{expected_clear_status}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got clear status \'{data["clear_status"]}\'') if data['miss_count'] != expected_miss_count: - raise Exception('Expected a miss count of \'{}\' for song \'{}\' chart \'{}\' but got miss count \'{}\''.format( - expected_miss_count, score['id'], score['chart'], data['miss_count'], - )) + raise Exception(f'Expected a miss count of \'{expected_miss_count}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got miss count \'{data["miss_count"]}\'') # Verify we can fetch our own ghost ex_score, ghost = self.verify_iidx21music_appoint(profile['extid'], score['id'], score['chart']) if ex_score != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['ex_score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["ex_score"]}\'') if len(ghost) != 64: - raise Exception('Wrong ghost length {} for ghost!'.format(len(ghost))) + raise Exception(f'Wrong ghost length {len(ghost)} for ghost!') for g in ghost: if g != 0x01: - raise Exception('Got back wrong ghost data for song \'{}\' chart \'{}\''.format(score['id'], score['chart'])) + raise Exception(f'Got back wrong ghost data for song \'{score["id"]}\' chart \'{score["chart"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) @@ -756,9 +748,9 @@ class IIDXSpadaClient(BaseClient): }) scores = self.verify_iidx21music_getrank(profile['extid']) if 1000 not in scores: - raise Exception('Didn\'t get expected scores back for song {} beginner chart!'.format(1000)) + raise Exception(f'Didn\'t get expected scores back for song {1000} beginner chart!') if 6 not in scores[1000]: - raise Exception('Didn\'t get beginner score back for song {}!'.format(1000)) + raise Exception(f'Didn\'t get beginner score back for song {1000}!') if scores[1000][6] != {'clear_status': 4, 'ex_score': -1, 'miss_count': -1}: raise Exception('Didn\'t get correct status back from beginner save!') diff --git a/bemani/client/iidx/tricoro.py b/bemani/client/iidx/tricoro.py index 1ea4a00..e2ac191 100644 --- a/bemani/client/iidx/tricoro.py +++ b/bemani/client/iidx/tricoro.py @@ -84,12 +84,12 @@ class IIDXTricoroClient(BaseClient): self.assert_path(resp, "response/music") for child in resp.child("music").children: if child.name != 'c': - raise Exception('Invalid node {} in clear rate response!'.format(child)) + raise Exception(f'Invalid node {child} in clear rate response!') if len(child.value) != 12: - raise Exception('Invalid node data {} in clear rate response!'.format(child)) + raise Exception(f'Invalid node data {child} in clear rate response!') for v in child.value: if v < 0 or v > 101: - raise Exception('Invalid clear percent {} in clear rate response!'.format(child)) + raise Exception(f'Invalid clear percent {child} in clear rate response!') def verify_shop_getconvention(self, lid: str) -> None: call = self.call_node() @@ -205,7 +205,7 @@ class IIDXTricoroClient(BaseClient): name = resp.child('pc/pcdata').attribute('name') if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') return { 'extid': int(resp.child('pc/pcdata').attribute('id')), @@ -545,15 +545,15 @@ class IIDXTricoroClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_pc_reg(ref_id, card, lid) self.verify_pc_get(ref_id, card, lid) else: @@ -564,7 +564,7 @@ class IIDXTricoroClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -652,7 +652,7 @@ class IIDXTricoroClient(BaseClient): for score in dummyscores: data = scores.get(score['id'], {}).get(score['chart'], None) if data is None: - raise Exception('Expected to get score back for song {} chart {}!'.format(score['id'], score['chart'])) + raise Exception(f'Expected to get score back for song {score["id"]} chart {score["chart"]}!') if 'expected_ex_score' in score: expected_score = score['expected_ex_score'] @@ -668,30 +668,22 @@ class IIDXTricoroClient(BaseClient): expected_miss_count = score['mnum'] if data['ex_score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['ex_score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["ex_score"]}\'') if data['clear_status'] != expected_clear_status: - raise Exception('Expected a clear status of \'{}\' for song \'{}\' chart \'{}\' but got clear status \'{}\''.format( - expected_clear_status, score['id'], score['chart'], data['clear_status'], - )) + raise Exception(f'Expected a clear status of \'{expected_clear_status}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got clear status \'{data["clear_status"]}\'') if data['miss_count'] != expected_miss_count: - raise Exception('Expected a miss count of \'{}\' for song \'{}\' chart \'{}\' but got miss count \'{}\''.format( - expected_miss_count, score['id'], score['chart'], data['miss_count'], - )) + raise Exception(f'Expected a miss count of \'{expected_miss_count}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got miss count \'{data["miss_count"]}\'') # Verify we can fetch our own ghost ex_score, ghost = self.verify_music_appoint(profile['extid'], score['id'], score['chart']) if ex_score != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], data['ex_score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{data["ex_score"]}\'') if len(ghost) != 64: - raise Exception('Wrong ghost length {} for ghost!'.format(len(ghost))) + raise Exception(f'Wrong ghost length {len(ghost)} for ghost!') for g in ghost: if g != 0x01: - raise Exception('Got back wrong ghost data for song \'{}\' chart \'{}\''.format(score['id'], score['chart'])) + raise Exception(f'Got back wrong ghost data for song \'{score["id"]}\' chart \'{score["chart"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) @@ -726,9 +718,9 @@ class IIDXTricoroClient(BaseClient): }) scores = self.verify_music_getrank(profile['extid']) if 1000 not in scores: - raise Exception('Didn\'t get expected scores back for song {} beginner chart!'.format(1000)) + raise Exception(f'Didn\'t get expected scores back for song {1000} beginner chart!') if 6 not in scores[1000]: - raise Exception('Didn\'t get beginner score back for song {}!'.format(1000)) + raise Exception(f'Didn\'t get beginner score back for song {1000}!') if scores[1000][6] != {'clear_status': 4, 'ex_score': -1, 'miss_count': -1}: raise Exception('Didn\'t get correct status back from beginner save!') diff --git a/bemani/client/jubeat/clan.py b/bemani/client/jubeat/clan.py index 55be5be..80b84bc 100644 --- a/bemani/client/jubeat/clan.py +++ b/bemani/client/jubeat/clan.py @@ -154,7 +154,7 @@ class JubeatClanClient(BaseClient): 'mtg_hold_cnt', 'mtg_result', ]: - self.assert_path(resp, "response/gametop/data/player/info/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/info/{item}") for item in [ 'music_list', @@ -169,7 +169,7 @@ class JubeatClanClient(BaseClient): 'new/theme_list', 'new/marker_list', ]: - self.assert_path(resp, "response/gametop/data/player/item/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/item/{item}") for item in [ 'play_time', @@ -181,7 +181,7 @@ class JubeatClanClient(BaseClient): 'category', 'expert_option', ]: - self.assert_path(resp, "response/gametop/data/player/last/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/last/{item}") for item in [ 'marker', @@ -195,7 +195,7 @@ class JubeatClanClient(BaseClient): 'hard', 'hazard', ]: - self.assert_path(resp, "response/gametop/data/player/last/settings/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/last/settings/{item}") # Misc stuff self.assert_path(resp, "response/gametop/data/player/session_id") @@ -580,15 +580,15 @@ class JubeatClanClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_gametop_regist(card, ref_id) else: print("Skipping new card checks for existing card") @@ -598,7 +598,7 @@ class JubeatClanClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -708,14 +708,10 @@ class JubeatClanClient(BaseClient): expected_score = score['score'] if newscore['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], newscore['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{newscore["score"]}\'') if newscore['medal'] != score['expected_medal']: - raise Exception('Expected a medal of \'{}\' for song \'{}\' chart \'{}\' but got medal \'{}\''.format( - score['expected_medal'], score['id'], score['chart'], newscore['medal'], - )) + raise Exception(f'Expected a medal of \'{score["expected_medal"]}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got medal \'{newscore["medal"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/jubeat/prop.py b/bemani/client/jubeat/prop.py index 2ac8c41..2bb92b4 100644 --- a/bemani/client/jubeat/prop.py +++ b/bemani/client/jubeat/prop.py @@ -104,7 +104,7 @@ class JubeatPropClient(BaseClient): 'mtg_hold_cnt', 'mtg_result', ]: - self.assert_path(resp, "response/gametop/data/player/info/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/info/{item}") for item in [ 'music_list', @@ -118,7 +118,7 @@ class JubeatPropClient(BaseClient): 'new/theme_list', 'new/marker_list', ]: - self.assert_path(resp, "response/gametop/data/player/item/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/item/{item}") for item in [ 'play_time', @@ -130,7 +130,7 @@ class JubeatPropClient(BaseClient): 'music_id', 'seq_id', ]: - self.assert_path(resp, "response/gametop/data/player/last/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/last/{item}") for item in [ 'marker', @@ -144,7 +144,7 @@ class JubeatPropClient(BaseClient): 'hazard', 'hard', ]: - self.assert_path(resp, "response/gametop/data/player/last/settings/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/last/settings/{item}") # Misc stuff self.assert_path(resp, "response/gametop/data/player/session_id") @@ -411,7 +411,7 @@ class JubeatPropClient(BaseClient): break if playernode is None: - raise Exception("Didn't find any scores for ExtID {}".format(jid)) + raise Exception(f"Didn't find any scores for ExtID {jid}") ret = [] for result in playernode.child('result_list').children: @@ -458,7 +458,7 @@ class JubeatPropClient(BaseClient): break if playernode is None: - raise Exception("Didn't find any scores for ExtID {}".format(jid)) + raise Exception(f"Didn't find any scores for ExtID {jid}") result = playernode.child_value('result/score') if result is not None: @@ -539,15 +539,15 @@ class JubeatPropClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_gametop_regist(card, ref_id) else: print("Skipping new card checks for existing card") @@ -557,7 +557,7 @@ class JubeatPropClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -677,14 +677,10 @@ class JubeatPropClient(BaseClient): expected_score = score['score'] if newscore['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], newscore['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{newscore["score"]}\'') if newscore['medal'] != score['expected_medal']: - raise Exception('Expected a medal of \'{}\' for song \'{}\' chart \'{}\' but got medal \'{}\''.format( - score['expected_medal'], score['id'], score['chart'], newscore['medal'], - )) + raise Exception(f'Expected a medal of \'{score["expected_medal"]}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got medal \'{newscore["medal"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) @@ -730,7 +726,7 @@ class JubeatPropClient(BaseClient): foundcourses = [c for c in courses if c['course_id'] == course['course_id']] if len(foundcourses) == 0: - raise Exception("Didn't find course by ID {}".format(course['course_id'])) + raise Exception(f"Didn't find course by ID {course['course_id']}") foundcourse = foundcourses[0] if 'expected_rating' in course: @@ -747,15 +743,11 @@ class JubeatPropClient(BaseClient): raise Exception("Logic error!") if foundcourse['rating'] != expected_rating: - raise Exception('Expected a rating of \'{}\' for course \'{}\' but got rating \'{}\''.format( - expected_rating, course['course_id'], foundcourse['rating'], - )) + raise Exception(f'Expected a rating of \'{expected_rating}\' for course \'{course["course_id"]}\' but got rating \'{foundcourse["rating"]}\'') for i in range(len(expected_scores)): if foundcourse['scores'][i] != expected_scores[i]: - raise Exception('Expected a score of \'{}\' for course \'{}\' song number \'{}\' but got score \'{}\''.format( - expected_scores[i], course['course_id'], i, foundcourse['scores'][i], - )) + raise Exception(f'Expected a score of \'{expected_scores[i]}\' for course \'{course["course_id"]}\' song number \'{i}\' but got score \'{foundcourse["scores"][i]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) @@ -766,11 +758,7 @@ class JubeatPropClient(BaseClient): league = self.verify_gametop_get_league(jid) if league[1][0] != 123456 or league[1][1] != 234567 or league[1][2] != 345678: - raise Exception('League score didn\t save! Got wrong values {}, {}, {} back!'.format( - league[1][0], - league[1][1], - league[1][2], - )) + raise Exception(f'League score didn\t save! Got wrong values {league[1][0]}, {league[1][1]}, {league[1][2]} back!') # Play a league course, do worse, make sure it doesn't overwrite self.verify_gameend_regist(ref_id, jid, [], {}, (league[0], (12345, 23456, 34567))) @@ -778,11 +766,7 @@ class JubeatPropClient(BaseClient): league = self.verify_gametop_get_league(jid) if league[1][0] != 123456 or league[1][1] != 234567 or league[1][2] != 345678: - raise Exception('League score got overwritten! Got wrong values {}, {}, {} back!'.format( - league[1][0], - league[1][1], - league[1][2], - )) + raise Exception(f'League score got overwritten! Got wrong values {league[1][0]}, {league[1][1]}, {league[1][2]} back!') else: print("Skipping score checks for existing card") diff --git a/bemani/client/jubeat/qubell.py b/bemani/client/jubeat/qubell.py index 3b08d7b..7a0e27c 100644 --- a/bemani/client/jubeat/qubell.py +++ b/bemani/client/jubeat/qubell.py @@ -105,7 +105,7 @@ class JubeatQubellClient(BaseClient): 'mtg_hold_cnt', 'mtg_result', ]: - self.assert_path(resp, "response/gametop/data/player/info/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/info/{item}") for item in [ 'music_list', @@ -119,7 +119,7 @@ class JubeatQubellClient(BaseClient): 'new/theme_list', 'new/marker_list', ]: - self.assert_path(resp, "response/gametop/data/player/item/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/item/{item}") for item in [ 'play_time', @@ -131,7 +131,7 @@ class JubeatQubellClient(BaseClient): 'music_id', 'seq_id', ]: - self.assert_path(resp, "response/gametop/data/player/last/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/last/{item}") for item in [ 'marker', @@ -145,7 +145,7 @@ class JubeatQubellClient(BaseClient): 'hazard', 'hard', ]: - self.assert_path(resp, "response/gametop/data/player/last/settings/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/last/settings/{item}") # Misc stuff self.assert_path(resp, "response/gametop/data/player/session_id") @@ -440,15 +440,15 @@ class JubeatQubellClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_gametop_regist(card, ref_id) else: print("Skipping new card checks for existing card") @@ -458,7 +458,7 @@ class JubeatQubellClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -563,14 +563,10 @@ class JubeatQubellClient(BaseClient): expected_score = score['score'] if newscore['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], newscore['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{newscore["score"]}\'') if newscore['medal'] != score['expected_medal']: - raise Exception('Expected a medal of \'{}\' for song \'{}\' chart \'{}\' but got medal \'{}\''.format( - score['expected_medal'], score['id'], score['chart'], newscore['medal'], - )) + raise Exception(f'Expected a medal of \'{score["expected_medal"]}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got medal \'{newscore["medal"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/jubeat/saucer.py b/bemani/client/jubeat/saucer.py index 04cd005..028e10b 100644 --- a/bemani/client/jubeat/saucer.py +++ b/bemani/client/jubeat/saucer.py @@ -76,7 +76,7 @@ class JubeatSaucerClient(BaseClient): 'mtg_hold_cnt', 'mtg_result', ]: - self.assert_path(resp, "response/gametop/data/player/info/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/info/{item}") for item in [ 'secret_list', @@ -89,7 +89,7 @@ class JubeatSaucerClient(BaseClient): 'new/theme_list', 'new/marker_list', ]: - self.assert_path(resp, "response/gametop/data/player/item/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/item/{item}") for item in [ 'music_id', @@ -106,7 +106,7 @@ class JubeatSaucerClient(BaseClient): 'shopname', 'areaname', ]: - self.assert_path(resp, "response/gametop/data/player/last/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/last/{item}") # Misc stuff self.assert_path(resp, "response/gametop/data/player/session_id") @@ -339,15 +339,15 @@ class JubeatSaucerClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_gametop_regist(card, ref_id) else: print("Skipping new card checks for existing card") @@ -357,7 +357,7 @@ class JubeatSaucerClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -460,14 +460,10 @@ class JubeatSaucerClient(BaseClient): expected_score = score['score'] if newscore['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], newscore['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{newscore["score"]}\'') if newscore['medal'] != score['expected_medal']: - raise Exception('Expected a medal of \'{}\' for song \'{}\' chart \'{}\' but got medal \'{}\''.format( - score['expected_medal'], score['id'], score['chart'], newscore['medal'], - )) + raise Exception(f'Expected a medal of \'{score["expected_medal"]}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got medal \'{newscore["medal"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/jubeat/saucerfulfill.py b/bemani/client/jubeat/saucerfulfill.py index cb7aad0..f62a73f 100644 --- a/bemani/client/jubeat/saucerfulfill.py +++ b/bemani/client/jubeat/saucerfulfill.py @@ -81,7 +81,7 @@ class JubeatSaucerFulfillClient(BaseClient): 'mtg_hold_cnt', 'mtg_result', ]: - self.assert_path(resp, "response/gametop/data/player/info/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/info/{item}") for item in [ 'secret_list', @@ -94,7 +94,7 @@ class JubeatSaucerFulfillClient(BaseClient): 'new/theme_list', 'new/marker_list', ]: - self.assert_path(resp, "response/gametop/data/player/item/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/item/{item}") for item in [ 'music_id', @@ -115,7 +115,7 @@ class JubeatSaucerFulfillClient(BaseClient): 'shopname', 'areaname', ]: - self.assert_path(resp, "response/gametop/data/player/last/{}".format(item)) + self.assert_path(resp, f"response/gametop/data/player/last/{item}") # Misc stuff self.assert_path(resp, "response/gametop/data/player/session_id") @@ -342,7 +342,7 @@ class JubeatSaucerFulfillClient(BaseClient): break if playernode is None: - raise Exception("Didn't find any scores for ExtID {}".format(jid)) + raise Exception(f"Didn't find any scores for ExtID {jid}") ret = [] for result in playernode.child('result_list').children: @@ -413,15 +413,15 @@ class JubeatSaucerFulfillClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_gametop_regist(card, ref_id) else: print("Skipping new card checks for existing card") @@ -431,7 +431,7 @@ class JubeatSaucerFulfillClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -543,14 +543,10 @@ class JubeatSaucerFulfillClient(BaseClient): expected_score = score['score'] if newscore['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], newscore['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{newscore["score"]}\'') if newscore['medal'] != score['expected_medal']: - raise Exception('Expected a medal of \'{}\' for song \'{}\' chart \'{}\' but got medal \'{}\''.format( - score['expected_medal'], score['id'], score['chart'], newscore['medal'], - )) + raise Exception(f'Expected a medal of \'{score["expected_medal"]}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got medal \'{newscore["medal"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) @@ -596,7 +592,7 @@ class JubeatSaucerFulfillClient(BaseClient): foundcourses = [c for c in courses if c['course_id'] == course['course_id']] if len(foundcourses) == 0: - raise Exception("Didn't find course by ID {}".format(course['course_id'])) + raise Exception(f"Didn't find course by ID {course['course_id']}") foundcourse = foundcourses[0] if 'expected_rating' in course: @@ -613,15 +609,11 @@ class JubeatSaucerFulfillClient(BaseClient): raise Exception("Logic error!") if foundcourse['rating'] != expected_rating: - raise Exception('Expected a rating of \'{}\' for course \'{}\' but got rating \'{}\''.format( - expected_rating, course['course_id'], foundcourse['rating'], - )) + raise Exception(f'Expected a rating of \'{expected_rating}\' for course \'{course["course_id"]}\' but got rating \'{foundcourse["rating"]}\'') for i in range(len(expected_scores)): if foundcourse['scores'][i] != expected_scores[i]: - raise Exception('Expected a score of \'{}\' for course \'{}\' song number \'{}\' but got score \'{}\''.format( - expected_scores[i], course['course_id'], i, foundcourse['scores'][i], - )) + raise Exception(f'Expected a score of \'{expected_scores[i]}\' for course \'{course["course_id"]}\' song number \'{i}\' but got score \'{foundcourse["scores"][i]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/museca/museca1.py b/bemani/client/museca/museca1.py index 3fbbdb4..ed94d57 100644 --- a/bemani/client/museca/museca1.py +++ b/bemani/client/museca/museca1.py @@ -279,7 +279,7 @@ class Museca1Client(BaseClient): 'items': items, } else: - raise Exception("Invalid game load type {}".format(msg_type)) + raise Exception(f"Invalid game load type {msg_type}") def verify_game_play_e(self, location: str, refid: str) -> None: call = self.call_node() @@ -412,15 +412,15 @@ class Museca1Client(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Museca doesn't read the new profile, it asks for the profile itself after calling new self.verify_game_load(card, ref_id, msg_type='new') self.verify_game_new(location, ref_id) @@ -433,7 +433,7 @@ class Museca1Client(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify account freezing self.verify_game_frozen(ref_id, 900) @@ -444,7 +444,7 @@ class Museca1Client(BaseClient): # Verify profile loading and saving profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 0: raise Exception('Profile has nonzero blocks associated with it!') if profile['block'] != 0: @@ -455,7 +455,7 @@ class Museca1Client(BaseClient): self.verify_game_save(location, ref_id, packet=123, block=234, blaster_energy=42) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 123: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 234: @@ -539,7 +539,7 @@ class Museca1Client(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -555,17 +555,11 @@ class Museca1Client(BaseClient): expected_clear_type = expected['clear_type'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['grade'] != expected_grade: - raise Exception('Expected a grade of \'{}\' for song \'{}\' chart \'{}\' but got grade \'{}\''.format( - expected_grade, expected['id'], expected['chart'], actual['grade'], - )) + raise Exception(f'Expected a grade of \'{expected_grade}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got grade \'{actual["grade"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/museca/museca1plus.py b/bemani/client/museca/museca1plus.py index a7c979d..0a3ac54 100644 --- a/bemani/client/museca/museca1plus.py +++ b/bemani/client/museca/museca1plus.py @@ -280,7 +280,7 @@ class Museca1PlusClient(BaseClient): 'items': items, } else: - raise Exception("Invalid game load type {}".format(msg_type)) + raise Exception(f"Invalid game load type {msg_type}") def verify_game_play_e(self, location: str, refid: str) -> None: call = self.call_node() @@ -427,15 +427,15 @@ class Museca1PlusClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Museca doesn't read the new profile, it asks for the profile itself after calling new self.verify_game_load(card, ref_id, msg_type='new') self.verify_game_new(location, ref_id) @@ -448,7 +448,7 @@ class Museca1PlusClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify account freezing self.verify_game_frozen(ref_id, 900) @@ -462,7 +462,7 @@ class Museca1PlusClient(BaseClient): # Verify profile loading and saving profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 0: raise Exception('Profile has nonzero blocks associated with it!') if profile['block'] != 0: @@ -473,7 +473,7 @@ class Museca1PlusClient(BaseClient): self.verify_game_save(location, ref_id, packet=123, block=234, blaster_energy=42) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 123: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 234: @@ -557,7 +557,7 @@ class Museca1PlusClient(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -573,17 +573,11 @@ class Museca1PlusClient(BaseClient): expected_clear_type = expected['clear_type'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['grade'] != expected_grade: - raise Exception('Expected a grade of \'{}\' for song \'{}\' chart \'{}\' but got grade \'{}\''.format( - expected_grade, expected['id'], expected['chart'], actual['grade'], - )) + raise Exception(f'Expected a grade of \'{expected_grade}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got grade \'{actual["grade"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/popn/eclale.py b/bemani/client/popn/eclale.py index fe7b15d..6ea70e9 100644 --- a/bemani/client/popn/eclale.py +++ b/bemani/client/popn/eclale.py @@ -39,12 +39,12 @@ class PopnMusicEclaleClient(BaseClient): self.assert_path(resp, "response/pcb23/@status") def __verify_common(self, root: str, resp: Node) -> None: - self.assert_path(resp, "response/{}/phase/event_id".format(root)) - self.assert_path(resp, "response/{}/phase/phase".format(root)) - self.assert_path(resp, "response/{}/area/area_id".format(root)) - self.assert_path(resp, "response/{}/area/end_date".format(root)) - self.assert_path(resp, "response/{}/area/medal_id".format(root)) - self.assert_path(resp, "response/{}/area/is_limit".format(root)) + self.assert_path(resp, f"response/{root}/phase/event_id") + self.assert_path(resp, f"response/{root}/phase/phase") + self.assert_path(resp, f"response/{root}/area/area_id") + self.assert_path(resp, f"response/{root}/area/end_date") + self.assert_path(resp, f"response/{root}/area/medal_id") + self.assert_path(resp, f"response/{root}/area/is_limit") def verify_info23_common(self, loc: str) -> None: call = self.call_node() @@ -135,7 +135,7 @@ class PopnMusicEclaleClient(BaseClient): self.assert_path(resp, "response/player23/result") status = resp.child_value('player23/result') if status != 2: - raise Exception('Reference ID \'{}\' returned invalid status \'{}\''.format(ref_id, status)) + raise Exception(f'Reference ID \'{ref_id}\' returned invalid status \'{status}\'') return { 'medals': {}, @@ -150,10 +150,10 @@ class PopnMusicEclaleClient(BaseClient): self.assert_path(resp, "response/player23/result") status = resp.child_value('player23/result') if status != 0: - raise Exception('Reference ID \'{}\' returned invalid status \'{}\''.format(ref_id, status)) + raise Exception(f'Reference ID \'{ref_id}\' returned invalid status \'{status}\'') name = resp.child_value('player23/account/name') if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') # Medals and items items: Dict[int, Dict[str, int]] = {} @@ -182,7 +182,7 @@ class PopnMusicEclaleClient(BaseClient): 'lumina': {0: {'lumina': resp.child_value('player23/account/lumina')}}, } else: - raise Exception('Unrecognized message type \'{}\''.format(msg_type)) + raise Exception(f'Unrecognized message type \'{msg_type}\'') def verify_player23_read_score(self, ref_id: str) -> Dict[str, Dict[int, Dict[int, int]]]: call = self.call_node() @@ -405,15 +405,15 @@ class PopnMusicEclaleClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_player23_read(ref_id, msg_type='new') self.verify_player23_new(ref_id) else: @@ -424,7 +424,7 @@ class PopnMusicEclaleClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify proper handling of basic stuff self.verify_player23_read(ref_id, msg_type='query') @@ -478,7 +478,7 @@ class PopnMusicEclaleClient(BaseClient): if unlocks['items'][6]['param'] != 8: raise Exception('Expecting to see item ID 6 to have param 8 in items!') if unlocks['lumina'][0]['lumina'] != 150: - raise Exception('Got wrong value for lumina {} after purchase!'.format(unlocks['lumina'][0]['lumina'])) + raise Exception(f'Got wrong value for lumina {unlocks["lumina"][0]["lumina"]} after purchase!') if cardid is None: # Verify score handling @@ -568,13 +568,9 @@ class PopnMusicEclaleClient(BaseClient): expected_medal = expected['medal'] if newscore != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], newscore, - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{newscore}\'') if newmedal != expected_medal: - raise Exception('Expected a medal of \'{}\' for song \'{}\' chart \'{}\' but got medal \'{}\''.format( - expected_medal, expected['id'], expected['chart'], newmedal, - )) + raise Exception(f'Expected a medal of \'{expected_medal}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got medal \'{newmedal}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/popn/fantasia.py b/bemani/client/popn/fantasia.py index 7601276..acff3a2 100644 --- a/bemani/client/popn/fantasia.py +++ b/bemani/client/popn/fantasia.py @@ -93,9 +93,9 @@ class PopnMusicFantasiaClient(BaseClient): node = resp.child('game').child(name) if node is None: - raise Exception('Missing node \'{}\' in response!'.format(name)) + raise Exception(f'Missing node \'{name}\' in response!') if node.data_type != 's32': - raise Exception('Node \'{}\' has wrong data type!'.format(name)) + raise Exception(f'Node \'{name}\' has wrong data type!') sel_ranking = resp.child('game').child('sel_ranking') up_ranking = resp.child('game').child('up_ranking') @@ -111,13 +111,13 @@ class PopnMusicFantasiaClient(BaseClient): dtype = nodepair[2] if node is None: - raise Exception('Missing node \'{}\' in response!'.format(name)) + raise Exception(f'Missing node \'{name}\' in response!') if node.data_type != dtype: - raise Exception('Node \'{}\' has wrong data type!'.format(name)) + raise Exception(f'Node \'{name}\' has wrong data type!') if not node.is_array: - raise Exception('Node \'{}\' is not array!'.format(name)) + raise Exception(f'Node \'{name}\' is not array!') if len(node.value) != 10: - raise Exception('Node \'{}\' is wrong array length!'.format(name)) + raise Exception(f'Node \'{name}\' is wrong array length!') def verify_playerdata_get(self, ref_id: str, msg_type: str) -> Optional[Dict[str, Any]]: call = self.call_node() @@ -143,7 +143,7 @@ class PopnMusicFantasiaClient(BaseClient): status = int(resp.child('playerdata').attribute('status')) if status != 109: - raise Exception('Reference ID \'{}\' returned invalid status \'{}\''.format(ref_id, status)) + raise Exception(f'Reference ID \'{ref_id}\' returned invalid status \'{status}\'') # No score data return None @@ -165,7 +165,7 @@ class PopnMusicFantasiaClient(BaseClient): name = resp.child('playerdata').child('base').child('name').value if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') # Extract and return score data self.assert_path(resp, "response/playerdata/base/clear_medal") @@ -198,7 +198,7 @@ class PopnMusicFantasiaClient(BaseClient): return {'medals': medals, 'scores': scores} else: - raise Exception('Unrecognized message type \'{}\''.format(msg_type)) + raise Exception(f'Unrecognized message type \'{msg_type}\'') def verify_playerdata_set(self, ref_id: str, scores: List[Dict[str, Any]]) -> None: call = self.call_node() @@ -238,7 +238,7 @@ class PopnMusicFantasiaClient(BaseClient): name = resp.child('playerdata').child('name').value if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') def verify_playerdata_new(self, ref_id: str) -> None: call = self.call_node() @@ -304,15 +304,15 @@ class PopnMusicFantasiaClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_playerdata_get(ref_id, msg_type='new') self.verify_playerdata_new(ref_id) else: @@ -323,7 +323,7 @@ class PopnMusicFantasiaClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -418,13 +418,9 @@ class PopnMusicFantasiaClient(BaseClient): expected_medal = score['medal'] if newscore != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], newscore, - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{newscore}\'') if newmedal != expected_medal: - raise Exception('Expected a medal of \'{}\' for song \'{}\' chart \'{}\' but got medal \'{}\''.format( - expected_medal, score['id'], score['chart'], newmedal, - )) + raise Exception(f'Expected a medal of \'{expected_medal}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got medal \'{newmedal}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/popn/lapistoria.py b/bemani/client/popn/lapistoria.py index 0c9e1f8..ec4f0cc 100644 --- a/bemani/client/popn/lapistoria.py +++ b/bemani/client/popn/lapistoria.py @@ -45,9 +45,9 @@ class PopnMusicLapistoriaClient(BaseClient): node = resp.child('info22').child(name) if node is None: - raise Exception('Missing node \'{}\' in response!'.format(name)) + raise Exception(f'Missing node \'{name}\' in response!') if node.data_type != 'void': - raise Exception('Node \'{}\' has wrong data type!'.format(name)) + raise Exception(f'Node \'{name}\' has wrong data type!') def verify_player22_read(self, ref_id: str, msg_type: str) -> Optional[Dict[str, Any]]: call = self.call_node() @@ -70,7 +70,7 @@ class PopnMusicLapistoriaClient(BaseClient): status = int(resp.child('player22').attribute('status')) if status != 109: - raise Exception('Reference ID \'{}\' returned invalid status \'{}\''.format(ref_id, status)) + raise Exception(f'Reference ID \'{ref_id}\' returned invalid status \'{status}\'') # No score data return None @@ -89,7 +89,7 @@ class PopnMusicLapistoriaClient(BaseClient): name = resp.child('player22').child('account').child('name').value if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') # Extract and return score data medals: Dict[int, List[int]] = {} @@ -111,7 +111,7 @@ class PopnMusicLapistoriaClient(BaseClient): return {'medals': medals, 'scores': scores} else: - raise Exception('Unrecognized message type \'{}\''.format(msg_type)) + raise Exception(f'Unrecognized message type \'{msg_type}\'') def verify_player22_write(self, ref_id: str, scores: List[Dict[str, Any]]) -> None: call = self.call_node() @@ -216,15 +216,15 @@ class PopnMusicLapistoriaClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_player22_read(ref_id, msg_type='new') self.verify_player22_new(ref_id) else: @@ -235,7 +235,7 @@ class PopnMusicLapistoriaClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -332,13 +332,9 @@ class PopnMusicLapistoriaClient(BaseClient): expected_medal = score['medal'] if newscore != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], newscore, - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{newscore}\'') if newmedal != expected_medal: - raise Exception('Expected a medal of \'{}\' for song \'{}\' chart \'{}\' but got medal \'{}\''.format( - expected_medal, score['id'], score['chart'], newmedal, - )) + raise Exception(f'Expected a medal of \'{expected_medal}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got medal \'{newmedal}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/popn/sunnypark.py b/bemani/client/popn/sunnypark.py index 785115c..6702350 100644 --- a/bemani/client/popn/sunnypark.py +++ b/bemani/client/popn/sunnypark.py @@ -60,9 +60,9 @@ class PopnMusicSunnyParkClient(BaseClient): node = resp.child('game').child(name) if node is None: - raise Exception('Missing node \'{}\' in response!'.format(name)) + raise Exception(f'Missing node \'{name}\' in response!') if node.data_type != 's32': - raise Exception('Node \'{}\' has wrong data type!'.format(name)) + raise Exception(f'Node \'{name}\' has wrong data type!') sel_ranking = resp.child('game').child('sel_ranking') up_ranking = resp.child('game').child('up_ranking') @@ -72,13 +72,13 @@ class PopnMusicSunnyParkClient(BaseClient): node = nodepair[1] if node is None: - raise Exception('Missing node \'{}\' in response!'.format(name)) + raise Exception(f'Missing node \'{name}\' in response!') if node.data_type != 's16': - raise Exception('Node \'{}\' has wrong data type!'.format(name)) + raise Exception(f'Node \'{name}\' has wrong data type!') if not node.is_array: - raise Exception('Node \'{}\' is not array!'.format(name)) + raise Exception(f'Node \'{name}\' is not array!') if len(node.value) != 5: - raise Exception('Node \'{}\' is wrong array length!'.format(name)) + raise Exception(f'Node \'{name}\' is wrong array length!') def verify_playerdata_get(self, ref_id: str, msg_type: str) -> Optional[Dict[str, Any]]: call = self.call_node() @@ -111,7 +111,7 @@ class PopnMusicSunnyParkClient(BaseClient): status = int(resp.child('playerdata').attribute('status')) if status != 109: - raise Exception('Reference ID \'{}\' returned invalid status \'{}\''.format(ref_id, status)) + raise Exception(f'Reference ID \'{ref_id}\' returned invalid status \'{status}\'') # No score data return None @@ -129,7 +129,7 @@ class PopnMusicSunnyParkClient(BaseClient): name = resp.child('playerdata').child('base').child('name').value if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') # Extract and return score data self.assert_path(resp, "response/playerdata/base/clear_medal") @@ -162,7 +162,7 @@ class PopnMusicSunnyParkClient(BaseClient): return {'medals': medals, 'scores': scores} else: - raise Exception('Unrecognized message type \'{}\''.format(msg_type)) + raise Exception(f'Unrecognized message type \'{msg_type}\'') def verify_playerdata_set(self, ref_id: str, scores: List[Dict[str, Any]]) -> None: call = self.call_node() @@ -194,7 +194,7 @@ class PopnMusicSunnyParkClient(BaseClient): name = resp.child('playerdata').child('name').value if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') def verify_playerdata_new(self, ref_id: str) -> None: call = self.call_node() @@ -253,15 +253,15 @@ class PopnMusicSunnyParkClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_playerdata_get(ref_id, msg_type='new') self.verify_playerdata_new(ref_id) else: @@ -272,7 +272,7 @@ class PopnMusicSunnyParkClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -367,13 +367,9 @@ class PopnMusicSunnyParkClient(BaseClient): expected_medal = score['medal'] if newscore != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], newscore, - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{newscore}\'') if newmedal != expected_medal: - raise Exception('Expected a medal of \'{}\' for song \'{}\' chart \'{}\' but got medal \'{}\''.format( - expected_medal, score['id'], score['chart'], newmedal, - )) + raise Exception(f'Expected a medal of \'{expected_medal}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got medal \'{newmedal}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/popn/tunestreet.py b/bemani/client/popn/tunestreet.py index bb3b180..8b9a3c0 100644 --- a/bemani/client/popn/tunestreet.py +++ b/bemani/client/popn/tunestreet.py @@ -55,7 +55,7 @@ class PopnMusicTuneStreetClient(BaseClient): 'psp_phase', ]: if name not in resp.child('game').attributes: - raise Exception('Missing attribute \'{}\' in response!'.format(name)) + raise Exception(f'Missing attribute \'{name}\' in response!') def verify_playerdata_get(self, ref_id: str, msg_type: str) -> Optional[Dict[str, Any]]: call = self.call_node() @@ -80,7 +80,7 @@ class PopnMusicTuneStreetClient(BaseClient): status = int(resp.child('playerdata').attribute('status')) if status != 109: - raise Exception('Reference ID \'{}\' returned invalid status \'{}\''.format(ref_id, status)) + raise Exception(f'Reference ID \'{ref_id}\' returned invalid status \'{status}\'') # No score data return None @@ -92,7 +92,7 @@ class PopnMusicTuneStreetClient(BaseClient): name = resp.child('playerdata').child('b').value[0:12].decode('SHIFT_JIS').replace("\x00", "") if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') medals = resp.child('playerdata').child('b').value[108:] medals = [(medals[x] + (medals[x + 1] << 8)) for x in range(0, len(medals), 2)] @@ -137,7 +137,7 @@ class PopnMusicTuneStreetClient(BaseClient): return {'medals': medals, 'scores': scores} else: - raise Exception('Unrecognized message type \'{}\''.format(msg_type)) + raise Exception(f'Unrecognized message type \'{msg_type}\'') def verify_playerdata_set(self, ref_id: str, scores: List[Dict[str, Any]]) -> None: call = self.call_node() @@ -241,15 +241,15 @@ class PopnMusicTuneStreetClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_playerdata_get(ref_id, msg_type='new') self.verify_playerdata_new(card, ref_id) else: @@ -260,7 +260,7 @@ class PopnMusicTuneStreetClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') if cardid is None: # Verify score handling @@ -355,13 +355,9 @@ class PopnMusicTuneStreetClient(BaseClient): expected_medal = score['medal'] if newscore != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, score['id'], score['chart'], newscore, - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{newscore}\'') if newmedal != expected_medal: - raise Exception('Expected a medal of \'{}\' for song \'{}\' chart \'{}\' but got medal \'{}\''.format( - expected_medal, score['id'], score['chart'], newmedal, - )) + raise Exception(f'Expected a medal of \'{expected_medal}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got medal \'{newmedal}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/popn/usaneko.py b/bemani/client/popn/usaneko.py index 0734282..a774afa 100644 --- a/bemani/client/popn/usaneko.py +++ b/bemani/client/popn/usaneko.py @@ -39,18 +39,18 @@ class PopnMusicUsaNekoClient(BaseClient): self.assert_path(resp, "response/pcb24/@status") def __verify_common(self, root: str, resp: Node) -> None: - self.assert_path(resp, "response/{}/phase/event_id".format(root)) - self.assert_path(resp, "response/{}/phase/phase".format(root)) - self.assert_path(resp, "response/{}/area/area_id".format(root)) - self.assert_path(resp, "response/{}/area/end_date".format(root)) - self.assert_path(resp, "response/{}/area/medal_id".format(root)) - self.assert_path(resp, "response/{}/area/is_limit".format(root)) - self.assert_path(resp, "response/{}/choco/choco_id".format(root)) - self.assert_path(resp, "response/{}/choco/param".format(root)) - self.assert_path(resp, "response/{}/goods/item_id".format(root)) - self.assert_path(resp, "response/{}/goods/item_type".format(root)) - self.assert_path(resp, "response/{}/goods/price".format(root)) - self.assert_path(resp, "response/{}/goods/goods_type".format(root)) + self.assert_path(resp, f"response/{root}/phase/event_id") + self.assert_path(resp, f"response/{root}/phase/phase") + self.assert_path(resp, f"response/{root}/area/area_id") + self.assert_path(resp, f"response/{root}/area/end_date") + self.assert_path(resp, f"response/{root}/area/medal_id") + self.assert_path(resp, f"response/{root}/area/is_limit") + self.assert_path(resp, f"response/{root}/choco/choco_id") + self.assert_path(resp, f"response/{root}/choco/param") + self.assert_path(resp, f"response/{root}/goods/item_id") + self.assert_path(resp, f"response/{root}/goods/item_type") + self.assert_path(resp, f"response/{root}/goods/price") + self.assert_path(resp, f"response/{root}/goods/goods_type") def verify_info24_common(self, loc: str) -> None: call = self.call_node() @@ -152,7 +152,7 @@ class PopnMusicUsaNekoClient(BaseClient): self.assert_path(resp, "response/player24/result") status = resp.child_value('player24/result') if status != 2: - raise Exception('Reference ID \'{}\' returned invalid status \'{}\''.format(ref_id, status)) + raise Exception(f'Reference ID \'{ref_id}\' returned invalid status \'{status}\'') return { 'items': {}, @@ -166,10 +166,10 @@ class PopnMusicUsaNekoClient(BaseClient): self.assert_path(resp, "response/player24/result") status = resp.child_value('player24/result') if status != 0: - raise Exception('Reference ID \'{}\' returned invalid status \'{}\''.format(ref_id, status)) + raise Exception(f'Reference ID \'{ref_id}\' returned invalid status \'{status}\'') name = resp.child_value('player24/account/name') if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for Ref ID \'{}\''.format(name, ref_id)) + raise Exception(f'Invalid name \'{name}\' returned for Ref ID \'{ref_id}\'') # Medals and items items: Dict[int, Dict[str, int]] = {} @@ -201,7 +201,7 @@ class PopnMusicUsaNekoClient(BaseClient): 'points': {0: {'points': resp.child_value('player24/account/player_point')}}, } else: - raise Exception('Unrecognized message type \'{}\''.format(msg_type)) + raise Exception(f'Unrecognized message type \'{msg_type}\'') def verify_player24_read_score(self, ref_id: str) -> Dict[str, Dict[int, Dict[int, int]]]: call = self.call_node() @@ -452,15 +452,15 @@ class PopnMusicUsaNekoClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') self.verify_player24_read(ref_id, msg_type='new') self.verify_player24_new(ref_id) else: @@ -471,7 +471,7 @@ class PopnMusicUsaNekoClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify proper handling of basic stuff self.verify_player24_read(ref_id, msg_type='query') @@ -520,7 +520,7 @@ class PopnMusicUsaNekoClient(BaseClient): if unlocks['items'][6]['param'] != 8: raise Exception('Expecting to see item ID 6 to have param 8 in items!') if unlocks['points'][0]['points'] != 150: - raise Exception('Got wrong value for points {} after purchase!'.format(unlocks['points'][0]['points'])) + raise Exception(f'Got wrong value for points {unlocks["points"][0]["points"]} after purchase!') # Verify course handling self.verify_player24_update_ranking(ref_id, location) @@ -643,17 +643,11 @@ class PopnMusicUsaNekoClient(BaseClient): expected_rank = 8 if newscore != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], newscore, - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{newscore}\'') if newmedal != expected_medal: - raise Exception('Expected a medal of \'{}\' for song \'{}\' chart \'{}\' but got medal \'{}\''.format( - expected_medal, expected['id'], expected['chart'], newmedal, - )) + raise Exception(f'Expected a medal of \'{expected_medal}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got medal \'{newmedal}\'') if newrank != expected_rank: - raise Exception('Expected a rank of \'{}\' for song \'{}\' chart \'{}\' but got rank \'{}\''.format( - expected_rank, expected['id'], expected['chart'], newrank, - )) + raise Exception(f'Expected a rank of \'{expected_rank}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got rank \'{newrank}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/protocol.py b/bemani/client/protocol.py index 0424861..b498ca8 100644 --- a/bemani/client/protocol.py +++ b/bemani/client/protocol.py @@ -25,14 +25,11 @@ class ClientProtocol: elif packet_encoding == "binary": _packet_encoding = EAmuseProtocol.BINARY else: - raise Exception("Unknown packet encoding {}".format(packet_encoding)) + raise Exception(f"Unknown packet encoding {packet_encoding}") # Handle encryption if self.__encryption: - encryption = '1-{}-{}'.format( - random_hex_string(8), - random_hex_string(4), - ) + encryption = f'1-{random_hex_string(8)}-{random_hex_string(4)}' headers['X-Eamuse-Info'] = encryption else: encryption = None @@ -56,11 +53,7 @@ class ClientProtocol: # Send the request, get the response r = requests.post( - 'http://{}:{}/{}'.format( - self.__address, - self.__port, - uri, - ), + f'http://{self.__address}:{self.__port}/{uri}', headers=headers, data=req, ) diff --git a/bemani/client/reflec/colette.py b/bemani/client/reflec/colette.py index 75c90da..5b4c180 100644 --- a/bemani/client/reflec/colette.py +++ b/bemani/client/reflec/colette.py @@ -182,7 +182,7 @@ class ReflecBeatColette(BaseClient): self.assert_path(resp, "response/player/pdata/record") if resp.child_value('player/pdata/base/name') != self.NAME: - raise Exception('Invalid name {} returned on profile read!'.format(resp.child_value('player/pdata/base/name'))) + raise Exception(f'Invalid name {resp.child_value("player/pdata/base/name")} returned on profile read!') scores = [] for child in resp.child('player/pdata/record').children: @@ -409,9 +409,9 @@ class ReflecBeatColette(BaseClient): name = child.child_value('name') comment = child.child_value('comment') if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for comment!'.format(name)) + raise Exception(f'Invalid name \'{name}\' returned for comment!') if comment != 'アメ〜〜!': - raise Exception('Invalid comment \'{}\' returned for comment!'.format(comment)) + raise Exception(f'Invalid comment \'{comment}\' returned for comment!') found = True if not found: @@ -488,15 +488,15 @@ class ReflecBeatColette(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Always get a player start, regardless of new profile or not self.verify_player_start(ref_id) self.verify_player_delete(ref_id) @@ -522,7 +522,7 @@ class ReflecBeatColette(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify lobby functionality self.verify_lobby_read(location, extid) @@ -621,7 +621,7 @@ class ReflecBeatColette(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -645,25 +645,15 @@ class ReflecBeatColette(BaseClient): expected_miss_count = expected['miss_count'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['achievement_rate'] != expected_achievement_rate: - raise Exception('Expected an achievement rate of \'{}\' for song \'{}\' chart \'{}\' but got achievement rate \'{}\''.format( - expected_achievement_rate, expected['id'], expected['chart'], actual['achievement_rate'], - )) + raise Exception(f'Expected an achievement rate of \'{expected_achievement_rate}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got achievement rate \'{actual["achievement_rate"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') if actual['combo'] != expected_combo: - raise Exception('Expected a combo of \'{}\' for song \'{}\' chart \'{}\' but got combo \'{}\''.format( - expected_combo, expected['id'], expected['chart'], actual['combo'], - )) + raise Exception(f'Expected a combo of \'{expected_combo}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got combo \'{actual["combo"]}\'') if actual['miss_count'] != expected_miss_count: - raise Exception('Expected a miss count of \'{}\' for song \'{}\' chart \'{}\' but got miss count \'{}\''.format( - expected_miss_count, expected['id'], expected['chart'], actual['miss_count'], - )) + raise Exception(f'Expected a miss count of \'{expected_miss_count}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got miss count \'{actual["miss_count"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/reflec/groovin.py b/bemani/client/reflec/groovin.py index 05115d4..58d72e4 100644 --- a/bemani/client/reflec/groovin.py +++ b/bemani/client/reflec/groovin.py @@ -193,11 +193,11 @@ class ReflecBeatGroovinUpper(BaseClient): if resp.child_value('player/player_select_score/name') != self.NAME: raise Exception( - 'Invalid name {} returned on score read!'.format(resp.child_value('player/player_select_score/name')) + f'Invalid name {resp.child_value("player/player_select_score/name")} returned on score read!' ) if resp.child_value('player/player_select_score/user_id') != extid: raise Exception( - 'Invalid name {} returned on score read!'.format(resp.child_value('player/player_select_score/user_id')) + f'Invalid name {resp.child_value("player/player_select_score/user_id")} returned on score read!' ) def verify_player_rb4succeed(self, refid: str) -> None: @@ -289,7 +289,7 @@ class ReflecBeatGroovinUpper(BaseClient): self.assert_path(resp, "response/player/pdata/pue") if resp.child_value('player/pdata/base/name') != self.NAME: - raise Exception('Invalid name {} returned on profile read!'.format(resp.child_value('player/pdata/base/name'))) + raise Exception(f'Invalid name {resp.child_value("player/pdata/base/name")} returned on profile read!') def verify_player_rb4readscore(self, refid: str, location: str) -> List[Dict[str, int]]: call = self.call_node() @@ -339,7 +339,7 @@ class ReflecBeatGroovinUpper(BaseClient): continue if child.child_value('user_id') != extid: - raise Exception('Invalid user ID returned {}'.format(child.child_value('user_id'))) + raise Exception(f'Invalid user ID returned {child.child_value("user_id")}') episode = { 'id': child.child_value('type'), @@ -586,9 +586,9 @@ class ReflecBeatGroovinUpper(BaseClient): name = child.child_value('name') comment = child.child_value('comment') if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for comment!'.format(name)) + raise Exception(f'Invalid name \'{name}\' returned for comment!') if comment != 'アメ〜〜!': - raise Exception('Invalid comment \'{}\' returned for comment!'.format(comment)) + raise Exception(f'Invalid comment \'{comment}\' returned for comment!') found = True if not found: @@ -668,15 +668,15 @@ class ReflecBeatGroovinUpper(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Always get a player start, regardless of new profile or not self.verify_player_rb4start(ref_id) @@ -694,7 +694,7 @@ class ReflecBeatGroovinUpper(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify lobby functionality self.verify_lobby_rb4read(location, extid) @@ -741,11 +741,7 @@ class ReflecBeatGroovinUpper(BaseClient): for i in range(len(dummyepisodes)): for key in dummyepisodes[i]: if dummyepisodes[i][key] != episodes[i][key]: - raise Exception('Invalid value {} returned for episode {} key {}'.format( - episodes[i][key], - dummyepisodes[i]['id'], - key, - )) + raise Exception(f'Invalid value {episodes[i][key]} returned for episode {dummyepisodes[i]["id"]} key {key}') # Verify we start with empty scores scores = self.verify_player_rb4readscore(ref_id, location) @@ -838,7 +834,7 @@ class ReflecBeatGroovinUpper(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -862,25 +858,15 @@ class ReflecBeatGroovinUpper(BaseClient): expected_miss_count = expected['miss_count'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['achievement_rate'] != expected_achievement_rate: - raise Exception('Expected an achievement rate of \'{}\' for song \'{}\' chart \'{}\' but got achievement rate \'{}\''.format( - expected_achievement_rate, expected['id'], expected['chart'], actual['achievement_rate'], - )) + raise Exception(f'Expected an achievement rate of \'{expected_achievement_rate}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got achievement rate \'{actual["achievement_rate"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') if actual['combo_type'] != expected_combo_type: - raise Exception('Expected a combo_type of \'{}\' for song \'{}\' chart \'{}\' but got combo_type \'{}\''.format( - expected_combo_type, expected['id'], expected['chart'], actual['combo_type'], - )) + raise Exception(f'Expected a combo_type of \'{expected_combo_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got combo_type \'{actual["combo_type"]}\'') if actual['miss_count'] != expected_miss_count: - raise Exception('Expected a miss count of \'{}\' for song \'{}\' chart \'{}\' but got miss count \'{}\''.format( - expected_miss_count, expected['id'], expected['chart'], actual['miss_count'], - )) + raise Exception(f'Expected a miss count of \'{expected_miss_count}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got miss count \'{actual["miss_count"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/reflec/limelight.py b/bemani/client/reflec/limelight.py index b3de48e..7104e62 100644 --- a/bemani/client/reflec/limelight.py +++ b/bemani/client/reflec/limelight.py @@ -213,7 +213,7 @@ class ReflecBeatLimelight(BaseClient): self.assert_path(resp, "response/player/pdata/narrow_down/adv_param") if resp.child_value('player/pdata/base/name') != self.NAME: - raise Exception('Invalid name {} returned on profile read!'.format(resp.child_value('player/pdata/base/name'))) + raise Exception(f'Invalid name {resp.child_value("player/pdata/base/name")} returned on profile read!') scores = [] for child in resp.child('player/pdata/record').children: @@ -326,7 +326,7 @@ class ReflecBeatLimelight(BaseClient): # First, filter down to only records that are also in the battle log def key(thing: Dict[str, int]) -> str: - return '{}-{}'.format(thing['id'], thing['chart']) + return f'{thing["id"]}-{thing["chart"]}' updates = [key(score) for score in scores] sortedrecords = {key(record): record for record in records if key(record) in updates} @@ -661,9 +661,9 @@ class ReflecBeatLimelight(BaseClient): name = child.child_value('p_name') comment = child.child_value('comment') if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for comment!'.format(name)) + raise Exception(f'Invalid name \'{name}\' returned for comment!') if comment != 'アメ〜〜!': - raise Exception('Invalid comment \'{}\' returned for comment!'.format(comment)) + raise Exception(f'Invalid comment \'{comment}\' returned for comment!') found = True if not found: @@ -677,7 +677,7 @@ class ReflecBeatLimelight(BaseClient): if child.child_value('uid') == extid: name = child.child_value('p_name') if name != self.NAME: - raise Exception('Invalid name \'{}\' returned for status!'.format(name)) + raise Exception(f'Invalid name \'{name}\' returned for status!') found = True if not found: @@ -720,15 +720,15 @@ class ReflecBeatLimelight(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Always get a player start, regardless of new profile or not self.verify_player_start(ref_id) self.verify_player_delete(ref_id) @@ -747,7 +747,7 @@ class ReflecBeatLimelight(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify lobby functionality self.verify_lobby_read(location, extid) @@ -848,7 +848,7 @@ class ReflecBeatLimelight(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -872,25 +872,15 @@ class ReflecBeatLimelight(BaseClient): expected_miss_count = expected['miss_count'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['achievement_rate'] != expected_achievement_rate: - raise Exception('Expected an achievement rate of \'{}\' for song \'{}\' chart \'{}\' but got achievement rate \'{}\''.format( - expected_achievement_rate, expected['id'], expected['chart'], actual['achievement_rate'], - )) + raise Exception(f'Expected an achievement rate of \'{expected_achievement_rate}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got achievement rate \'{actual["achievement_rate"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') if actual['combo'] != expected_combo: - raise Exception('Expected a combo of \'{}\' for song \'{}\' chart \'{}\' but got combo \'{}\''.format( - expected_combo, expected['id'], expected['chart'], actual['combo'], - )) + raise Exception(f'Expected a combo of \'{expected_combo}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got combo \'{actual["combo"]}\'') if actual['miss_count'] != expected_miss_count: - raise Exception('Expected a miss count of \'{}\' for song \'{}\' chart \'{}\' but got miss count \'{}\''.format( - expected_miss_count, expected['id'], expected['chart'], actual['miss_count'], - )) + raise Exception(f'Expected a miss count of \'{expected_miss_count}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got miss count \'{actual["miss_count"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/reflec/reflec.py b/bemani/client/reflec/reflec.py index ce78e38..896576e 100644 --- a/bemani/client/reflec/reflec.py +++ b/bemani/client/reflec/reflec.py @@ -155,7 +155,7 @@ class ReflecBeat(BaseClient): self.assert_path(resp, "response/player/pdata/cmnt") if resp.child_value('player/pdata/base/name') != self.NAME: - raise Exception('Invalid name {} returned on profile read!'.format(resp.child_value('player/pdata/base/name'))) + raise Exception(f'Invalid name {resp.child_value("player/pdata/base/name")} returned on profile read!') scores = [] for child in resp.child('player/pdata/record').children: @@ -212,7 +212,7 @@ class ReflecBeat(BaseClient): # First, filter down to only records that are also in the battle log def key(thing: Dict[str, int]) -> str: - return '{}-{}'.format(thing['id'], thing['chart']) + return f'{thing["id"]}-{thing["chart"]}' updates = [key(score) for score in scores] sortedrecords = {key(record): record for record in records if key(record) in updates} @@ -450,15 +450,15 @@ class ReflecBeat(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Always get a player start, regardless of new profile or not self.verify_player_start(ref_id) self.verify_player_delete(ref_id) @@ -477,7 +477,7 @@ class ReflecBeat(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify lobby functionality self.verify_lobby_read(location, extid) @@ -573,7 +573,7 @@ class ReflecBeat(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -597,25 +597,15 @@ class ReflecBeat(BaseClient): expected_miss_count = expected['miss_count'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['achievement_rate'] != expected_achievement_rate: - raise Exception('Expected an achievement rate of \'{}\' for song \'{}\' chart \'{}\' but got achievement rate \'{}\''.format( - expected_achievement_rate, expected['id'], expected['chart'], actual['achievement_rate'], - )) + raise Exception(f'Expected an achievement rate of \'{expected_achievement_rate}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got achievement rate \'{actual["achievement_rate"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') if actual['combo'] != expected_combo: - raise Exception('Expected a combo of \'{}\' for song \'{}\' chart \'{}\' but got combo \'{}\''.format( - expected_combo, expected['id'], expected['chart'], actual['combo'], - )) + raise Exception(f'Expected a combo of \'{expected_combo}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got combo \'{actual["combo"]}\'') if actual['miss_count'] != expected_miss_count: - raise Exception('Expected a miss count of \'{}\' for song \'{}\' chart \'{}\' but got miss count \'{}\''.format( - expected_miss_count, expected['id'], expected['chart'], actual['miss_count'], - )) + raise Exception(f'Expected a miss count of \'{expected_miss_count}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got miss count \'{actual["miss_count"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/reflec/volzza.py b/bemani/client/reflec/volzza.py index 2ff299c..5749924 100644 --- a/bemani/client/reflec/volzza.py +++ b/bemani/client/reflec/volzza.py @@ -194,11 +194,11 @@ class ReflecBeatVolzza(BaseClient): if resp.child_value('player/player_select_score/name') != self.NAME: raise Exception( - 'Invalid name {} returned on score read!'.format(resp.child_value('player/player_select_score/name')) + f'Invalid name {resp.child_value("player/player_select_score/name")} returned on score read!' ) if resp.child_value('player/player_select_score/user_id') != extid: raise Exception( - 'Invalid name {} returned on score read!'.format(resp.child_value('player/player_select_score/user_id')) + f'Invalid name {resp.child_value("player/player_select_score/user_id")} returned on score read!' ) def verify_player_rb5_player_read_rival_ranking_data(self, extid: int) -> None: @@ -222,7 +222,7 @@ class ReflecBeatVolzza(BaseClient): self.assert_path(resp, "response/player/rival_data/rl/sl/t") if resp.child_value('player/rival_data/rl/nm') != self.NAME: raise Exception( - 'Invalid name {} returned on rival ranking read!'.format(resp.child_value('player/rival_data/rl/nm')) + f'Invalid name {resp.child_value("player/rival_data/rl/nm")} returned on rival ranking read!' ) def verify_player_rb5_player_succeed(self, refid: str) -> None: @@ -297,7 +297,7 @@ class ReflecBeatVolzza(BaseClient): self.assert_path(resp, "response/player/pdata/mylist/list/mlst") if resp.child_value('player/pdata/base/name') != self.NAME: - raise Exception('Invalid name {} returned on profile read!'.format(resp.child_value('player/pdata/base/name'))) + raise Exception(f'Invalid name {resp.child_value("player/pdata/base/name")} returned on profile read!') def verify_player_rb5_player_read_score(self, refid: str, location: str) -> List[Dict[str, int]]: call = self.call_node() @@ -568,15 +568,15 @@ class ReflecBeatVolzza(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Always get a player start, regardless of new profile or not self.verify_player_rb5_player_start(ref_id) @@ -593,7 +593,7 @@ class ReflecBeatVolzza(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify lobby functionality self.verify_lobby_rb5_lobby_read(location, extid) @@ -691,7 +691,7 @@ class ReflecBeatVolzza(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -715,25 +715,15 @@ class ReflecBeatVolzza(BaseClient): expected_miss_count = expected['miss_count'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['achievement_rate'] != expected_achievement_rate: - raise Exception('Expected an achievement rate of \'{}\' for song \'{}\' chart \'{}\' but got achievement rate \'{}\''.format( - expected_achievement_rate, expected['id'], expected['chart'], actual['achievement_rate'], - )) + raise Exception(f'Expected an achievement rate of \'{expected_achievement_rate}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got achievement rate \'{actual["achievement_rate"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') if actual['combo_type'] != expected_combo_type: - raise Exception('Expected a combo_type of \'{}\' for song \'{}\' chart \'{}\' but got combo_type \'{}\''.format( - expected_combo_type, expected['id'], expected['chart'], actual['combo_type'], - )) + raise Exception(f'Expected a combo_type of \'{expected_combo_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got combo_type \'{actual["combo_type"]}\'') if actual['miss_count'] != expected_miss_count: - raise Exception('Expected a miss count of \'{}\' for song \'{}\' chart \'{}\' but got miss count \'{}\''.format( - expected_miss_count, expected['id'], expected['chart'], actual['miss_count'], - )) + raise Exception(f'Expected a miss count of \'{expected_miss_count}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got miss count \'{actual["miss_count"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/reflec/volzza2.py b/bemani/client/reflec/volzza2.py index 788c69b..b3c0579 100644 --- a/bemani/client/reflec/volzza2.py +++ b/bemani/client/reflec/volzza2.py @@ -196,11 +196,11 @@ class ReflecBeatVolzza2(BaseClient): if resp.child_value('player/player_select_score/name') != self.NAME: raise Exception( - 'Invalid name {} returned on score read!'.format(resp.child_value('player/player_select_score/name')) + f'Invalid name {resp.child_value("player/player_select_score/name")} returned on score read!' ) if resp.child_value('player/player_select_score/user_id') != extid: raise Exception( - 'Invalid name {} returned on score read!'.format(resp.child_value('player/player_select_score/user_id')) + f'Invalid name {resp.child_value("player/player_select_score/user_id")} returned on score read!' ) def verify_player_rb5_player_read_rival_ranking_data_5(self, extid: int) -> None: @@ -224,7 +224,7 @@ class ReflecBeatVolzza2(BaseClient): self.assert_path(resp, "response/player/rival_data/rl/sl/t") if resp.child_value('player/rival_data/rl/nm') != self.NAME: raise Exception( - 'Invalid name {} returned on rival ranking read!'.format(resp.child_value('player/rival_data/rl/nm')) + f'Invalid name {resp.child_value("player/rival_data/rl/nm")} returned on rival ranking read!' ) def verify_player_rb5_player_succeed(self, refid: str) -> None: @@ -304,7 +304,7 @@ class ReflecBeatVolzza2(BaseClient): self.assert_path(resp, "response/player/pdata/mycourse_f") if resp.child_value('player/pdata/base/name') != self.NAME: - raise Exception('Invalid name {} returned on profile read!'.format(resp.child_value('player/pdata/base/name'))) + raise Exception(f'Invalid name {resp.child_value("player/pdata/base/name")} returned on profile read!') mycourse = [ { @@ -673,15 +673,15 @@ class ReflecBeatVolzza2(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Always get a player start, regardless of new profile or not self.verify_player_rb5_player_start(ref_id) @@ -698,7 +698,7 @@ class ReflecBeatVolzza2(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify lobby functionality self.verify_lobby_rb5_lobby_read(location, extid) @@ -805,7 +805,7 @@ class ReflecBeatVolzza2(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -829,25 +829,15 @@ class ReflecBeatVolzza2(BaseClient): expected_miss_count = expected['miss_count'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['achievement_rate'] != expected_achievement_rate: - raise Exception('Expected an achievement rate of \'{}\' for song \'{}\' chart \'{}\' but got achievement rate \'{}\''.format( - expected_achievement_rate, expected['id'], expected['chart'], actual['achievement_rate'], - )) + raise Exception(f'Expected an achievement rate of \'{expected_achievement_rate}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got achievement rate \'{actual["achievement_rate"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') if actual['combo_type'] != expected_combo_type: - raise Exception('Expected a combo_type of \'{}\' for song \'{}\' chart \'{}\' but got combo_type \'{}\''.format( - expected_combo_type, expected['id'], expected['chart'], actual['combo_type'], - )) + raise Exception(f'Expected a combo_type of \'{expected_combo_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got combo_type \'{actual["combo_type"]}\'') if actual['miss_count'] != expected_miss_count: - raise Exception('Expected a miss count of \'{}\' for song \'{}\' chart \'{}\' but got miss count \'{}\''.format( - expected_miss_count, expected['id'], expected['chart'], actual['miss_count'], - )) + raise Exception(f'Expected a miss count of \'{expected_miss_count}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got miss count \'{actual["miss_count"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) @@ -882,11 +872,11 @@ class ReflecBeatVolzza2(BaseClient): profile = self.verify_player_rb5_player_read(ref_id, card, location) for i in range(len(profile['mycourse'])): if profile['mycourse'][i]['music_id'] != firstcourse[i]['music_id']: - raise Exception('invalid music ID for mycourse entry {}!'.format(i)) + raise Exception(f'invalid music ID for mycourse entry {i}!') if profile['mycourse'][i]['note_grade'] != firstcourse[i]['note_grade']: - raise Exception('invalid chart for mycourse entry {}!'.format(i)) + raise Exception(f'invalid chart for mycourse entry {i}!') if profile['mycourse'][i]['score'] != firstcourse[i]['score']: - raise Exception('invalid score for mycourse entry {}!'.format(i)) + raise Exception(f'invalid score for mycourse entry {i}!') # Do a worse job on a different course secondcourse = [ @@ -915,11 +905,11 @@ class ReflecBeatVolzza2(BaseClient): profile = self.verify_player_rb5_player_read(ref_id, card, location) for i in range(len(profile['mycourse'])): if profile['mycourse'][i]['music_id'] != firstcourse[i]['music_id']: - raise Exception('invalid music ID for mycourse entry {}!'.format(i)) + raise Exception(f'invalid music ID for mycourse entry {i}!') if profile['mycourse'][i]['note_grade'] != firstcourse[i]['note_grade']: - raise Exception('invalid chart for mycourse entry {}!'.format(i)) + raise Exception(f'invalid chart for mycourse entry {i}!') if profile['mycourse'][i]['score'] != firstcourse[i]['score']: - raise Exception('invalid score for mycourse entry {}!'.format(i)) + raise Exception(f'invalid score for mycourse entry {i}!') # Now, do better on our course, and verify it updates thirdcourse = [ @@ -948,11 +938,11 @@ class ReflecBeatVolzza2(BaseClient): profile = self.verify_player_rb5_player_read(ref_id, card, location) for i in range(len(profile['mycourse'])): if profile['mycourse'][i]['music_id'] != thirdcourse[i]['music_id']: - raise Exception('invalid music ID for mycourse entry {}!'.format(i)) + raise Exception(f'invalid music ID for mycourse entry {i}!') if profile['mycourse'][i]['note_grade'] != thirdcourse[i]['note_grade']: - raise Exception('invalid chart for mycourse entry {}!'.format(i)) + raise Exception(f'invalid chart for mycourse entry {i}!') if profile['mycourse'][i]['score'] != thirdcourse[i]['score']: - raise Exception('invalid score for mycourse entry {}!'.format(i)) + raise Exception(f'invalid score for mycourse entry {i}!') # Verify ending game self.verify_player_rb5_player_end(ref_id) diff --git a/bemani/client/sdvx/booth.py b/bemani/client/sdvx/booth.py index d79dc6a..497c939 100644 --- a/bemani/client/sdvx/booth.py +++ b/bemani/client/sdvx/booth.py @@ -283,7 +283,7 @@ class SoundVoltexBoothClient(BaseClient): 'exp': resp.child_value('game/exp_point'), } else: - raise Exception("Invalid game load type {}".format(msg_type)) + raise Exception(f"Invalid game load type {msg_type}") def verify_game_lounge(self) -> None: call = self.call_node() @@ -436,15 +436,15 @@ class SoundVoltexBoothClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # SDVX doesn't read the new profile, it asks for the profile itself after calling new self.verify_game_load(card, ref_id, msg_type='new') self.verify_game_new(location, ref_id) @@ -457,7 +457,7 @@ class SoundVoltexBoothClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify account freezing self.verify_game_frozen(ref_id, 900) @@ -472,7 +472,7 @@ class SoundVoltexBoothClient(BaseClient): # Verify profile loading and saving profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 0: raise Exception('Profile has nonzero blocks associated with it!') if profile['block'] != 0: @@ -486,7 +486,7 @@ class SoundVoltexBoothClient(BaseClient): self.verify_game_save(location, ref_id, packet=123, block=234, exp=42) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 123: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 234: @@ -497,7 +497,7 @@ class SoundVoltexBoothClient(BaseClient): self.verify_game_save(location, ref_id, packet=1, block=2, exp=3) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 124: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 236: @@ -509,7 +509,7 @@ class SoundVoltexBoothClient(BaseClient): self.verify_game_buy(ref_id, 1004, True) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 124: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 226: @@ -593,7 +593,7 @@ class SoundVoltexBoothClient(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -609,17 +609,11 @@ class SoundVoltexBoothClient(BaseClient): expected_clear_type = expected['clear_type'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['grade'] != expected_grade: - raise Exception('Expected a grade of \'{}\' for song \'{}\' chart \'{}\' but got grade \'{}\''.format( - expected_grade, expected['id'], expected['chart'], actual['grade'], - )) + raise Exception(f'Expected a grade of \'{expected_grade}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got grade \'{actual["grade"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/sdvx/gravitywars_s1.py b/bemani/client/sdvx/gravitywars_s1.py index ea8e8a5..14b471d 100644 --- a/bemani/client/sdvx/gravitywars_s1.py +++ b/bemani/client/sdvx/gravitywars_s1.py @@ -346,7 +346,7 @@ class SoundVoltexGravityWarsS1Client(BaseClient): 'courses': courses, } else: - raise Exception("Invalid game load type {}".format(msg_type)) + raise Exception(f"Invalid game load type {msg_type}") def verify_game_lounge(self) -> None: call = self.call_node() @@ -567,15 +567,15 @@ class SoundVoltexGravityWarsS1Client(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # SDVX doesn't read the new profile, it asks for the profile itself after calling new self.verify_game_load(card, ref_id, msg_type='new') self.verify_game_new(location, ref_id) @@ -588,7 +588,7 @@ class SoundVoltexGravityWarsS1Client(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify account freezing self.verify_game_frozen(ref_id, 900) @@ -605,7 +605,7 @@ class SoundVoltexGravityWarsS1Client(BaseClient): # Verify profile loading and saving profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 0: raise Exception('Profile has nonzero blocks associated with it!') if profile['block'] != 0: @@ -623,7 +623,7 @@ class SoundVoltexGravityWarsS1Client(BaseClient): self.verify_game_save(location, ref_id, packet=123, block=234, blaster_energy=42) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 123: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 234: @@ -638,7 +638,7 @@ class SoundVoltexGravityWarsS1Client(BaseClient): self.verify_game_save(location, ref_id, packet=1, block=2, blaster_energy=3) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 124: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 236: @@ -654,7 +654,7 @@ class SoundVoltexGravityWarsS1Client(BaseClient): self.verify_game_buy(ref_id, 0, 29, 1, 10, 0, 29, 3, True) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 124: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 226: @@ -754,7 +754,7 @@ class SoundVoltexGravityWarsS1Client(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -770,17 +770,11 @@ class SoundVoltexGravityWarsS1Client(BaseClient): expected_clear_type = expected['clear_type'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['grade'] != expected_grade: - raise Exception('Expected a grade of \'{}\' for song \'{}\' chart \'{}\' but got grade \'{}\''.format( - expected_grade, expected['id'], expected['chart'], actual['grade'], - )) + raise Exception(f'Expected a grade of \'{expected_grade}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got grade \'{actual["grade"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/sdvx/gravitywars_s2.py b/bemani/client/sdvx/gravitywars_s2.py index 724f999..7927d25 100644 --- a/bemani/client/sdvx/gravitywars_s2.py +++ b/bemani/client/sdvx/gravitywars_s2.py @@ -234,7 +234,7 @@ class SoundVoltexGravityWarsS2Client(BaseClient): 'courses': courses, } else: - raise Exception("Invalid game load type {}".format(msg_type)) + raise Exception(f"Invalid game load type {msg_type}") def verify_game_save(self, location: str, refid: str, packet: int, block: int, blaster_energy: int) -> None: call = self.call_node() @@ -590,15 +590,15 @@ class SoundVoltexGravityWarsS2Client(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # SDVX doesn't read the new profile, it asks for the profile itself after calling new self.verify_game_load(card, ref_id, msg_type='new') self.verify_game_new(location, ref_id) @@ -611,7 +611,7 @@ class SoundVoltexGravityWarsS2Client(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify rivals node (necessary to return but can hold nothing) self.verify_game_load_r(ref_id) @@ -631,7 +631,7 @@ class SoundVoltexGravityWarsS2Client(BaseClient): # Verify profile loading and saving profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 0: raise Exception('Profile has nonzero blocks associated with it!') if profile['block'] != 0: @@ -649,7 +649,7 @@ class SoundVoltexGravityWarsS2Client(BaseClient): self.verify_game_save(location, ref_id, packet=123, block=234, blaster_energy=42) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 123: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 234: @@ -664,7 +664,7 @@ class SoundVoltexGravityWarsS2Client(BaseClient): self.verify_game_save(location, ref_id, packet=1, block=2, blaster_energy=3) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 124: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 236: @@ -680,7 +680,7 @@ class SoundVoltexGravityWarsS2Client(BaseClient): self.verify_game_buy(ref_id, 0, 29, 1, 10, 0, 29, 3, True) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 124: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 226: @@ -780,7 +780,7 @@ class SoundVoltexGravityWarsS2Client(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -796,17 +796,11 @@ class SoundVoltexGravityWarsS2Client(BaseClient): expected_clear_type = expected['clear_type'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['grade'] != expected_grade: - raise Exception('Expected a grade of \'{}\' for song \'{}\' chart \'{}\' but got grade \'{}\''.format( - expected_grade, expected['id'], expected['chart'], actual['grade'], - )) + raise Exception(f'Expected a grade of \'{expected_grade}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got grade \'{actual["grade"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/sdvx/heavenlyhaven.py b/bemani/client/sdvx/heavenlyhaven.py index a0e7de6..9418b2a 100644 --- a/bemani/client/sdvx/heavenlyhaven.py +++ b/bemani/client/sdvx/heavenlyhaven.py @@ -262,7 +262,7 @@ class SoundVoltexHeavenlyHavenClient(BaseClient): 'courses': courses, } else: - raise Exception("Invalid game load type {}".format(msg_type)) + raise Exception(f"Invalid game load type {msg_type}") def verify_game_save(self, location: str, refid: str, packet: int, block: int, blaster_energy: int) -> None: call = self.call_node() @@ -669,15 +669,15 @@ class SoundVoltexHeavenlyHavenClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # SDVX doesn't read the new profile, it asks for the profile itself after calling new self.verify_game_load(card, ref_id, msg_type='new') self.verify_game_new(location, ref_id) @@ -690,7 +690,7 @@ class SoundVoltexHeavenlyHavenClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify rivals node (necessary to return but can hold nothing) self.verify_game_load_r(ref_id) @@ -709,7 +709,7 @@ class SoundVoltexHeavenlyHavenClient(BaseClient): # Verify profile loading and saving profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 0: raise Exception('Profile has nonzero blocks associated with it!') if profile['block'] != 0: @@ -727,7 +727,7 @@ class SoundVoltexHeavenlyHavenClient(BaseClient): self.verify_game_save(location, ref_id, packet=123, block=234, blaster_energy=42) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 123: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 234: @@ -740,7 +740,7 @@ class SoundVoltexHeavenlyHavenClient(BaseClient): self.verify_game_save(location, ref_id, packet=1, block=2, blaster_energy=3) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 124: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 236: @@ -754,7 +754,7 @@ class SoundVoltexHeavenlyHavenClient(BaseClient): self.verify_game_buy(ref_id, 0, 29, 1, 10, 0, 29, 3, True) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 124: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 226: @@ -858,7 +858,7 @@ class SoundVoltexHeavenlyHavenClient(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -874,17 +874,11 @@ class SoundVoltexHeavenlyHavenClient(BaseClient): expected_clear_type = expected['clear_type'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['grade'] != expected_grade: - raise Exception('Expected a grade of \'{}\' for song \'{}\' chart \'{}\' but got grade \'{}\''.format( - expected_grade, expected['id'], expected['chart'], actual['grade'], - )) + raise Exception(f'Expected a grade of \'{expected_grade}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got grade \'{actual["grade"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/client/sdvx/infiniteinfection.py b/bemani/client/sdvx/infiniteinfection.py index f922dd1..a7a9954 100644 --- a/bemani/client/sdvx/infiniteinfection.py +++ b/bemani/client/sdvx/infiniteinfection.py @@ -339,7 +339,7 @@ class SoundVoltexInfiniteInfectionClient(BaseClient): 'courses': courses, } else: - raise Exception("Invalid game load type {}".format(msg_type)) + raise Exception(f"Invalid game load type {msg_type}") def verify_game_lounge(self) -> None: call = self.call_node() @@ -519,15 +519,15 @@ class SoundVoltexInfiniteInfectionClient(BaseClient): card = cardid else: card = self.random_card() - print("Generated random card ID {} for use.".format(card)) + print(f"Generated random card ID {card} for use.") if cardid is None: self.verify_cardmng_inquire(card, msg_type='unregistered', paseli_enabled=paseli_enabled) ref_id = self.verify_cardmng_getrefid(card) if len(ref_id) != 16: - raise Exception('Invalid refid \'{}\' returned when registering card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when registering card') if ref_id != self.verify_cardmng_inquire(card, msg_type='new', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # SDVX doesn't read the new profile, it asks for the profile itself after calling new self.verify_game_load(card, ref_id, msg_type='new') self.verify_game_new(location, ref_id) @@ -540,7 +540,7 @@ class SoundVoltexInfiniteInfectionClient(BaseClient): self.verify_cardmng_authpass(ref_id, correct=True) self.verify_cardmng_authpass(ref_id, correct=False) if ref_id != self.verify_cardmng_inquire(card, msg_type='query', paseli_enabled=paseli_enabled): - raise Exception('Invalid refid \'{}\' returned when querying card'.format(ref_id)) + raise Exception(f'Invalid refid \'{ref_id}\' returned when querying card') # Verify account freezing self.verify_game_frozen(ref_id, 900) @@ -555,7 +555,7 @@ class SoundVoltexInfiniteInfectionClient(BaseClient): # Verify profile loading and saving profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 0: raise Exception('Profile has nonzero blocks associated with it!') if profile['block'] != 0: @@ -575,7 +575,7 @@ class SoundVoltexInfiniteInfectionClient(BaseClient): self.verify_game_save(location, ref_id, packet=123, block=234, blaster_energy=42, appealcards=[]) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 123: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 234: @@ -592,7 +592,7 @@ class SoundVoltexInfiniteInfectionClient(BaseClient): self.verify_game_save(location, ref_id, packet=1, block=2, blaster_energy=3, appealcards=[]) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 124: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 236: @@ -610,7 +610,7 @@ class SoundVoltexInfiniteInfectionClient(BaseClient): self.verify_game_buy(ref_id, 0, 29, 1, 10, 0, 29, 3, True) profile = self.verify_game_load(card, ref_id, msg_type='existing') if profile['name'] != self.NAME: - raise Exception('Profile has incorrect name {} associated with it!'.format(profile['name'])) + raise Exception(f'Profile has incorrect name {profile["name"]} associated with it!') if profile['packet'] != 124: raise Exception('Profile has invalid blocks associated with it!') if profile['block'] != 226: @@ -631,9 +631,9 @@ class SoundVoltexInfiniteInfectionClient(BaseClient): profile = self.verify_game_load(card, ref_id, msg_type='existing') for i in [1001, 1002, 1003, 1004, 1005]: if i not in profile['appealcards']: - raise Exception('Profile missing appeal card {}'.format(i)) + raise Exception(f'Profile missing appeal card {i}') if profile['appealcards'][i] != 0: - raise Exception('Profile has bad count for appeal card {}'.format(i)) + raise Exception(f'Profile has bad count for appeal card {i}') # Verify that we can finish skill analyzer courses self.verify_game_save_c(location, ref_id, 14, 3) @@ -721,7 +721,7 @@ class SoundVoltexInfiniteInfectionClient(BaseClient): break if actual is None: - raise Exception("Didn't find song {} chart {} in response!".format(expected['id'], expected['chart'])) + raise Exception(f"Didn't find song {expected['id']} chart {expected['chart']} in response!") if 'expected_score' in expected: expected_score = expected['expected_score'] @@ -737,17 +737,11 @@ class SoundVoltexInfiniteInfectionClient(BaseClient): expected_clear_type = expected['clear_type'] if actual['score'] != expected_score: - raise Exception('Expected a score of \'{}\' for song \'{}\' chart \'{}\' but got score \'{}\''.format( - expected_score, expected['id'], expected['chart'], actual['score'], - )) + raise Exception(f'Expected a score of \'{expected_score}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got score \'{actual["score"]}\'') if actual['grade'] != expected_grade: - raise Exception('Expected a grade of \'{}\' for song \'{}\' chart \'{}\' but got grade \'{}\''.format( - expected_grade, expected['id'], expected['chart'], actual['grade'], - )) + raise Exception(f'Expected a grade of \'{expected_grade}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got grade \'{actual["grade"]}\'') if actual['clear_type'] != expected_clear_type: - raise Exception('Expected a clear_type of \'{}\' for song \'{}\' chart \'{}\' but got clear_type \'{}\''.format( - expected_clear_type, expected['id'], expected['chart'], actual['clear_type'], - )) + raise Exception(f'Expected a clear_type of \'{expected_clear_type}\' for song \'{expected["id"]}\' chart \'{expected["chart"]}\' but got clear_type \'{actual["clear_type"]}\'') # Sleep so we don't end up putting in score history on the same second time.sleep(1) diff --git a/bemani/common/aes.py b/bemani/common/aes.py index 731305c..a504106 100644 --- a/bemani/common/aes.py +++ b/bemani/common/aes.py @@ -14,7 +14,7 @@ class AESCipher: self.__key = hashlib.sha256(key.encode('utf-8')).digest() def __pad(self, s: str) -> str: - intermediate = "{}.{}".format(len(s), s) + intermediate = f"{len(s)}.{s}" while len(intermediate) % self.__padamt != 0: intermediate = intermediate + '-' return intermediate diff --git a/bemani/common/card.py b/bemani/common/card.py index 73795c3..8bd0e44 100644 --- a/bemani/common/card.py +++ b/bemani/common/card.py @@ -220,7 +220,7 @@ class CardCipher: """ if len(cardid) != 16: raise CardCipherException( - 'Expected 16-character card ID, got {}'.format(len(cardid)), + f'Expected 16-character card ID, got {len(cardid)}', ) cardint = [int(cardid[i:(i + 2)], 16) for i in range(0, len(cardid), 2)] @@ -284,13 +284,13 @@ class CardCipher: if len(cardid) != 16: raise CardCipherException( - 'Expected 16-character card ID, got {}'.format(len(cardid)), + f'Expected 16-character card ID, got {len(cardid)}', ) for c in cardid: if c not in CardCipher.VALID_CHARS: raise CardCipherException( - 'Got unexpected character {} in card ID'.format(c), + f'Got unexpected character {c} in card ID', ) # Convert chars to groups @@ -365,7 +365,7 @@ class CardCipher: def __encode(inbytes: bytes) -> bytes: if len(inbytes) != 8: raise CardCipherException( - 'Expected 8-byte input, got {}'.format(len(inbytes)), + f'Expected 8-byte input, got {len(inbytes)}', ) inp = [b for b in inbytes] @@ -381,7 +381,7 @@ class CardCipher: def __decode(inbytes: bytes) -> bytes: if len(inbytes) != 8: raise CardCipherException( - 'Expected 8-byte input, got {}'.format(len(inbytes)), + f'Expected 8-byte input, got {len(inbytes)}', ) inp = [b for b in inbytes] diff --git a/bemani/common/http.py b/bemani/common/http.py index fe8e75d..1e46d01 100644 --- a/bemani/common/http.py +++ b/bemani/common/http.py @@ -130,9 +130,9 @@ class HTTP: # Add first part of header if request: - out.append('{} {} {}'.format(parsed_headers['method'], parsed_headers['uri'], parsed_headers['version'])) + out.append(f'{parsed_headers["method"]} {parsed_headers["uri"]} {parsed_headers["version"]}') elif response: - out.append('{} {} {}'.format(parsed_headers['version'], parsed_headers['code'], parsed_headers['error'])) + out.append(f'{parsed_headers["version"]} {parsed_headers["code"]} {parsed_headers["error"]}') else: raise Exception("Logic error!") @@ -149,9 +149,9 @@ class HTTP: continue else: # Woah, can't figure this out! - raise Exception("Unknown transfer-encodign {}".format(value)) + raise Exception(f"Unknown transfer-encodign {value}") - out.append("{}: {}".format(name, value)) + out.append(f"{name}: {value}") # Concatenate it with the binary data return "\r\n".join(out).encode('ascii') + b'\r\n\r\n' + data diff --git a/bemani/common/id.py b/bemani/common/id.py index 3b10571..67070c1 100644 --- a/bemani/common/id.py +++ b/bemani/common/id.py @@ -19,7 +19,7 @@ class ID: extid_str = str(extid) while len(extid_str) < 8: extid_str = '0' + extid_str - return '{}-{}'.format(extid_str[0:4], extid_str[4:8]) + return f'{extid_str[0:4]}-{extid_str[4:8]}' @staticmethod def parse_extid(extid: str) -> Optional[int]: @@ -46,7 +46,7 @@ class ID: """ Take a machine ID as an integer, format it as a string. """ - return 'US-{}'.format(machine_id) + return f'US-{machine_id}' @staticmethod def parse_machine_id(machine_id: str) -> Optional[int]: diff --git a/bemani/common/model.py b/bemani/common/model.py index afd042c..e011ae3 100644 --- a/bemani/common/model.py +++ b/bemani/common/model.py @@ -43,10 +43,10 @@ class Model: elif len(parts) == 4: game, dest, spec, rev = parts return Model(game, dest, spec, rev, None) - raise Exception('Couldn\'t parse model {}'.format(model)) + raise Exception(f'Couldn\'t parse model {model}') def __str__(self) -> str: if self.version is None: - return '{}:{}:{}:{}'.format(self.game, self.dest, self.spec, self.rev) + return f'{self.game}:{self.dest}:{self.spec}:{self.rev}' else: - return '{}:{}:{}:{}:{}'.format(self.game, self.dest, self.spec, self.rev, self.version) + return f'{self.game}:{self.dest}:{self.spec}:{self.rev}:{self.version}' diff --git a/bemani/data/api/client.py b/bemani/data/api/client.py index c7545ba..22687e5 100644 --- a/bemani/data/api/client.py +++ b/bemani/data/api/client.py @@ -44,12 +44,12 @@ class APIClient: def __exchange_data(self, request_uri: str, request_args: Dict[str, Any]) -> Dict[str, Any]: if self.base_uri[-1:] != '/': - uri = '{}/{}'.format(self.base_uri, request_uri) + uri = f'{self.base_uri}/{request_uri}' else: - uri = '{}{}'.format(self.base_uri, request_uri) + uri = f'{self.base_uri}{request_uri}' headers = { - 'Authorization': 'Token {}'.format(self.token), + 'Authorization': f'Token {self.token}', 'Content-Type': 'application/json; charset=utf-8', } data = json.dumps(request_args).encode('utf8') @@ -67,7 +67,7 @@ class APIClient: raise APIException('Failed to query remote server!') if r.headers['content-type'] != 'application/json; charset=utf-8': - raise APIException('API returned invalid content type \'{}\'!'.format(r.headers['content-type'])) + raise APIException(f'API returned invalid content type \'{r.headers["content-type"]}\'!') jsondata = r.json() @@ -75,7 +75,7 @@ class APIClient: return jsondata if 'error' not in jsondata: - raise APIException('API returned error code {} but did not include \'error\' attribute in response JSON!'.format(r.status_code)) + raise APIException(f'API returned error code {r.status_code} but did not include \'error\' attribute in response JSON!') error = jsondata['error'] if r.status_code == 401: @@ -85,7 +85,7 @@ class APIClient: if r.status_code == 405: raise UnrecognizedRequestAPIException('The server did not recognize the request!') if r.status_code == 500: - raise RemoteServerErrorAPIException('The server had an error processing the request and returned \'{}\''.format(error)) + raise RemoteServerErrorAPIException(f'The server had an error processing the request and returned \'{error}\'') if r.status_code == 501: raise UnsupportedVersionAPIException('The server does not support this version of the API!') raise APIException('The server returned an invalid status code {}!', format(r.status_code)) @@ -184,7 +184,7 @@ class APIClient: try: servergame, serverversion = self.__translate(game, version) resp = self.__exchange_data( - '{}/{}/{}'.format(self.API_VERSION, servergame, serverversion), + f'{self.API_VERSION}/{servergame}/{serverversion}', { 'ids': ids, 'type': idtype, @@ -221,7 +221,7 @@ class APIClient: if until is not None: data['until'] = until resp = self.__exchange_data( - '{}/{}/{}'.format(self.API_VERSION, servergame, serverversion), + f'{self.API_VERSION}/{servergame}/{serverversion}', data, ) return resp['records'] @@ -237,7 +237,7 @@ class APIClient: try: servergame, serverversion = self.__translate(game, version) resp = self.__exchange_data( - '{}/{}/{}'.format(self.API_VERSION, servergame, serverversion), + f'{self.API_VERSION}/{servergame}/{serverversion}', { 'ids': ids, 'type': idtype, @@ -255,7 +255,7 @@ class APIClient: try: servergame, serverversion = self.__translate(game, version) resp = self.__exchange_data( - '{}/{}/{}'.format(self.API_VERSION, servergame, serverversion), + f'{self.API_VERSION}/{servergame}/{serverversion}', { 'ids': [], 'type': 'server', diff --git a/bemani/data/data.py b/bemani/data/data.py index 8b35607..918f459 100644 --- a/bemani/data/data.py +++ b/bemani/data/data.py @@ -121,12 +121,7 @@ class Data: @classmethod def sqlalchemy_url(cls, config: Dict[str, Any]) -> str: - return "mysql://{}:{}@{}/{}?charset=utf8mb4".format( - config['database']['user'], - config['database']['password'], - config['database']['address'], - config['database']['database'], - ) + return f"mysql://{config['database']['user']}:{config['database']['password']}@{config['database']['address']}/{config['database']['database']}?charset=utf8mb4" @classmethod def create_engine(cls, config: Dict[str, Any]) -> Engine: @@ -149,9 +144,9 @@ class Data: '-c', os.path.join(base_dir, 'alembic.ini'), '-x', - 'script_location={}'.format(base_dir), + f'script_location={base_dir}', '-x', - 'sqlalchemy.url={}'.format(self.__url), + f'sqlalchemy.url={self.__url}', command, ] alembicArgs.extend(args) diff --git a/bemani/data/mysql/game.py b/bemani/data/mysql/game.py index 1b0b1a4..e5d029c 100644 --- a/bemani/data/mysql/game.py +++ b/bemani/data/mysql/game.py @@ -298,10 +298,7 @@ class GameData(BaseData): if result['start_time'] == start_time and result['end_time'] == end_time: # This is just this event being updated, that's fine. continue - raise Exception('This event overlaps an existing one with start time {} and end time {}'.format( - result['start_time'], - result['end_time'], - )) + raise Exception(f'This event overlaps an existing one with start time {result["start_time"]} and end time {result["end_time"]}') # Insert or update this setting sql = ( diff --git a/bemani/data/mysql/music.py b/bemani/data/mysql/music.py index 5c906ca..5431a6a 100644 --- a/bemani/data/mysql/music.py +++ b/bemani/data/mysql/music.py @@ -101,12 +101,7 @@ class MusicData(BaseData): cursor = self.execute(sql, {'songid': songid, 'chart': songchart, 'game': game, 'version': version}) if cursor.rowcount != 1: # music doesn't exist - raise Exception('Song {} chart {} doesn\'t exist for game {} version {}'.format( - songid, - songchart, - game, - version, - )) + raise Exception(f'Song {songid} chart {songchart} doesn\'t exist for game {game} version {version}') result = cursor.fetchone() return result['id'] @@ -226,11 +221,7 @@ class MusicData(BaseData): ) except IntegrityError: raise ScoreSaveException( - 'There is already an attempt by {} for music id {} at {}'.format( - userid if userid is not None else 0, - musicid, - ts, - ) + f'There is already an attempt by {userid if userid is not None else 0} for music id {musicid} at {ts}' ) def get_score(self, game: str, version: int, userid: UserID, songid: int, songchart: int) -> Optional[Score]: @@ -584,7 +575,7 @@ class MusicData(BaseData): "WHERE music.id = :musicid" ) if interested_versions is not None: - sql += " AND music.version in ({})".format(",".join(str(int(v)) for v in interested_versions)) + sql += f" AND music.version in ({','.join(str(int(v)) for v in interested_versions)})" cursor = self.execute(sql, {'musicid': musicid}) all_songs = [] for result in cursor.fetchall(): @@ -764,17 +755,11 @@ class MusicData(BaseData): if len(userlist) == 0: # We don't have any users, but SQL will shit the bed, so lets add a fake one. userlist.append(UserID(-1)) - user_sql = ( - "SELECT userid FROM score WHERE score.musicid = played.musicid AND score.userid IN :userlist {} ORDER BY points DESC, timestamp DESC LIMIT 1" - ).format(location_sql) + user_sql = f"SELECT userid FROM score WHERE score.musicid = played.musicid AND score.userid IN :userlist {location_sql} ORDER BY points DESC, timestamp DESC LIMIT 1" params['userlist'] = tuple(userlist) else: - user_sql = ( - "SELECT userid FROM score WHERE score.musicid = played.musicid {} ORDER BY points DESC, timestamp DESC LIMIT 1" - ).format(location_sql) - records_sql = ( - "SELECT ({}) AS userid, musicid FROM ({}) played" - ).format(user_sql, musicid_sql) + user_sql = f"SELECT userid FROM score WHERE score.musicid = played.musicid {location_sql} ORDER BY points DESC, timestamp DESC LIMIT 1" + records_sql = f"SELECT ({user_sql}) AS userid, musicid FROM ({musicid_sql}) played" # Now, join it up against the score and music table to grab the info we need sql = ( diff --git a/bemani/data/mysql/network.py b/bemani/data/mysql/network.py index 3bccaca..ad3c4a0 100644 --- a/bemani/data/mysql/network.py +++ b/bemani/data/mysql/network.py @@ -270,7 +270,7 @@ class NetworkData(BaseData): if until_id is not None: wheres.append("id < :until_id") if len(wheres) > 0: - sql = sql + "WHERE {} ".format(' AND '.join(wheres)) + sql = sql + f"WHERE {' AND '.join(wheres)} " # Order it newest to oldest sql = sql + "ORDER BY id DESC" diff --git a/bemani/data/types.py b/bemani/data/types.py index dae92ff..8c7b521 100644 --- a/bemani/data/types.py +++ b/bemani/data/types.py @@ -32,12 +32,7 @@ class User: self.admin = admin def __repr__(self) -> str: - return "User(userid={}, username={}, email={}, admin={})".format( - self.id, - self.username, - self.email, - self.admin, - ) + return f"User(userid={self.id}, username={self.username}, email={self.email}, admin={self.admin})" class Achievement: @@ -64,12 +59,7 @@ class Achievement: self.data = ValidatedDict(data) def __repr__(self) -> str: - return "Achievement(achievementid={}, achievementtype={}, timestamp={}, data={})".format( - self.id, - self.type, - self.timestamp, - self.data, - ) + return f"Achievement(achievementid={self.id}, achievementtype={self.type}, timestamp={self.timestamp}, data={self.data})" class Link: @@ -94,12 +84,7 @@ class Link: self.data = ValidatedDict(data) def __repr__(self) -> str: - return "Link(userid={}, linktype={}, other_userid={}, data={})".format( - self.userid, - self.type, - self.other_userid, - self.data, - ) + return f"Link(userid={self.userid}, linktype={self.type}, other_userid={self.other_userid}, data={self.data})" class Machine: @@ -147,17 +132,7 @@ class Machine: self.data = ValidatedDict(data) def __repr__(self) -> str: - return "Machine(machineid={}, pcbid={}, name={}, description={}, arcade={}, port={}, game={}, version={}, data={})".format( - self.id, - self.pcbid, - self.name, - self.description, - self.arcade, - self.port, - self.game, - self.version, - self.data, - ) + return f"Machine(machineid={self.id}, pcbid={self.pcbid}, name={self.name}, description={self.description}, arcade={self.arcade}, port={self.port}, game={self.game}, version={self.version}, data={self.data})" class Arcade: @@ -189,14 +164,7 @@ class Arcade: self.owners = owners def __repr__(self) -> str: - return "Arcade(arcadeid={}, name={}, description={}, pin={}, data={}, owners={})".format( - self.id, - self.name, - self.description, - self.pin, - self.data, - self.owners, - ) + return f"Arcade(arcadeid={self.id}, name={self.name}, description={self.description}, pin={self.pin}, data={self.data}, owners={self.owners})" class Song: @@ -238,16 +206,7 @@ class Song: self.data = ValidatedDict(data) def __repr__(self) -> str: - return "Song(game={}, version={}, songid={}, songchart={}, name={}, artist={}, genre={}, data={})".format( - self.game, - self.version, - self.id, - self.chart, - self.name, - self.artist, - self.genre, - self.data, - ) + return f"Song(game={self.game}, version={self.version}, songid={self.id}, songchart={self.chart}, name={self.name}, artist={self.artist}, genre={self.genre}, data={self.data})" class Score: @@ -292,17 +251,7 @@ class Score: self.data = ValidatedDict(data) def __repr__(self) -> str: - return "Score(key={}, songid={}, songchart={}, points={}, timestamp={}, update={}, location={}, plays={}, data={})".format( - self.key, - self.id, - self.chart, - self.points, - self.timestamp, - self.update, - self.location, - self.plays, - self.data, - ) + return f"Score(key={self.key}, songid={self.id}, songchart={self.chart}, points={self.points}, timestamp={self.timestamp}, update={self.update}, location={self.location}, plays={self.plays}, data={self.data})" class Attempt: @@ -344,16 +293,7 @@ class Attempt: self.data = ValidatedDict(data) def __repr__(self) -> str: - return "Attempt(key={}, songid={}, songchart={}, points={}, timestamp={}, location={}, new_record={}, data={})".format( - self.key, - self.id, - self.chart, - self.points, - self.timestamp, - self.location, - self.new_record, - self.data, - ) + return f"Attempt(key={self.key}, songid={self.id}, songchart={self.chart}, points={self.points}, timestamp={self.timestamp}, location={self.location}, new_record={self.new_record}, data={self.data})" class News: @@ -378,12 +318,7 @@ class News: self.body = body def __repr__(self) -> str: - return "News(newsid={}, timestamp={}, title={}, body={})".format( - self.id, - self.timestamp, - self.title, - self.body, - ) + return f"News(newsid={self.id}, timestamp={self.timestamp}, title={self.title}, body={self.body})" class Event: @@ -412,14 +347,7 @@ class Event: self.data = ValidatedDict(data) def __repr__(self) -> str: - return "Event(auditid={}, timestamp={}, userid={}, arcadeid={}, event={}, data={})".format( - self.id, - self.timestamp, - self.userid, - self.arcadeid, - self.type, - self.data, - ) + return f"Event(auditid={self.id}, timestamp={self.timestamp}, userid={self.userid}, arcadeid={self.arcadeid}, event={self.type}, data={self.data})" class Item: @@ -441,11 +369,7 @@ class Item: self.data = ValidatedDict(data) def __repr__(self) -> str: - return "Item(cattype={}, catid={}, data={})".format( - self.type, - self.id, - self.data, - ) + return f"Item(cattype={self.type}, catid={self.id}, data={self.data})" class Client: @@ -470,12 +394,7 @@ class Client: self.token = token def __repr__(self) -> str: - return "Client(clientid={}, timestamp={}, name={}, token={})".format( - self.id, - self.timestamp, - self.name, - self.token, - ) + return f"Client(clientid={self.id}, timestamp={self.timestamp}, name={self.name}, token={self.token})" class Server: @@ -504,11 +423,4 @@ class Server: self.allow_scores = allow_scores def __repr__(self) -> str: - return "Server(serverid={}, timestamp={}, uri={}, token={}, allow_stats={}, allow_scores={})".format( - self.id, - self.timestamp, - self.uri, - self.token, - self.allow_stats, - self.allow_scores, - ) + return f"Server(serverid={self.id}, timestamp={self.timestamp}, uri={self.uri}, token={self.token}, allow_stats={self.allow_stats}, allow_scores={self.allow_scores})" diff --git a/bemani/format/ifs.py b/bemani/format/ifs.py index fe48405..3d24a42 100644 --- a/bemani/format/ifs.py +++ b/bemani/format/ifs.py @@ -79,7 +79,7 @@ class IFS: files[node_name] = (node.value[0] + data_index, node.value[1], node.value[2]) else: for subchild in node.children: - get_children(os.path.join(parent, "{}/".format(real_name)), subchild) + get_children(os.path.join(parent, f"{real_name}/"), subchild) get_children("/", header) @@ -110,7 +110,7 @@ class IFS: if md5sum == filename: if textfmt == "argb8888rev": - name = '{}.png'.format(subchild.attribute('name')) + name = f'{subchild.attribute("name")}.png' else: name = subchild.attribute('name') newpath = os.path.join(path, name) diff --git a/bemani/format/iidxmusicdb.py b/bemani/format/iidxmusicdb.py index 380d693..0d16ba6 100644 --- a/bemani/format/iidxmusicdb.py +++ b/bemani/format/iidxmusicdb.py @@ -82,7 +82,7 @@ class IIDXMusicDB: leap = 0x340 if sig[0] != b'IIDX': - raise Exception('Invalid signature \'{}\' found!'.format(sig[0])) + raise Exception(f'Invalid signature \'{sig[0]}\' found!') def parse_string(string: bytes) -> str: for i in range(len(string)): diff --git a/bemani/format/twodx.py b/bemani/format/twodx.py index 2acfc99..8c20542 100644 --- a/bemani/format/twodx.py +++ b/bemani/format/twodx.py @@ -38,7 +38,7 @@ class TwoDX: wavOffset = offset + headerSize wavData = data[wavOffset:(wavOffset + wavSize)] - self.__files['{}_{}.wav'.format(self.__name, fileno)] = wavData + self.__files[f'{self.__name}_{fileno}.wav'] = wavData fileno = fileno + 1 @property diff --git a/bemani/frontend/admin/admin.py b/bemani/frontend/admin/admin.py index c8972a5..c4af266 100644 --- a/bemani/frontend/admin/admin.py +++ b/bemani/frontend/admin/admin.py @@ -687,7 +687,7 @@ def updatepcbid() -> Dict[str, Any]: # Make sure we don't duplicate port assignments other_pcbid = g.data.local.machine.from_port(machine['port']) if other_pcbid is not None and other_pcbid != machine['pcbid']: - raise Exception('This port is already in use by \'{}\'!'.format(other_pcbid)) + raise Exception(f'This port is already in use by \'{other_pcbid}\'!') if machine['port'] < 1 or machine['port'] > 65535: raise Exception('The specified port is out of range!') diff --git a/bemani/frontend/app.py b/bemani/frontend/app.py index 4c1b386..8d3d7c7 100644 --- a/bemani/frontend/app.py +++ b/bemani/frontend/app.py @@ -119,7 +119,7 @@ def jsx(filename: str) -> Response: # Figure out what our update time is to namespace on jsxfile = os.path.join(static_location, filename) mtime = os.path.getmtime(jsxfile) - namespace = '{}.{}'.format(mtime, jsxfile) + namespace = f'{mtime}.{jsxfile}' jsx = g.cache.get(namespace) if jsx is None: transformer = JSXTransformer() diff --git a/bemani/frontend/arcade/arcade.py b/bemani/frontend/arcade/arcade.py index cb7cfb8..3aeb811 100644 --- a/bemani/frontend/arcade/arcade.py +++ b/bemani/frontend/arcade/arcade.py @@ -309,7 +309,7 @@ def updatearcade(arcadeid: int, attribute: str) -> Dict[str, Any]: elif attribute == 'mask_services_url': arcade.data.replace_bool('mask_services_url', new_value) else: - raise Exception('Unknown attribute {} to update!'.format(attribute)) + raise Exception(f'Unknown attribute {attribute} to update!') g.data.local.machine.put_arcade(arcade) diff --git a/bemani/frontend/base.py b/bemani/frontend/base.py index 7e78c5a..fb204c2 100644 --- a/bemani/frontend/base.py +++ b/bemani/frontend/base.py @@ -39,7 +39,7 @@ class FrontendBase: self.cache = cache def make_index(self, songid: int, chart: int) -> str: - return '{}-{}'.format(songid, chart) + return f'{songid}-{chart}' def get_duplicate_id(self, musicid: int, chart: int) -> Optional[Tuple[int, int]]: return None @@ -105,7 +105,7 @@ class FrontendBase: def get_all_songs(self, force_db_load: bool=False) -> Dict[int, Dict[str, Any]]: if not force_db_load: - cached_songs = self.cache.get('{}.sorted_songs'.format(self.game)) + cached_songs = self.cache.get(f'{self.game}.sorted_songs') if cached_songs is not None: return cached_songs @@ -120,7 +120,7 @@ class FrontendBase: else: songs[song.id] = self.merge_song(songs[song.id], song) - self.cache.set('{}.sorted_songs'.format(self.game), songs, timeout=600) + self.cache.set(f'{self.game}.sorted_songs', songs, timeout=600) return songs def get_all_player_info(self, userids: List[UserID], limit: Optional[int]=None, allow_remote: bool=False) -> Dict[UserID, Dict[int, Dict[str, Any]]]: diff --git a/bemani/frontend/bishi/endpoints.py b/bemani/frontend/bishi/endpoints.py index a9d3952..afaaaf1 100644 --- a/bemani/frontend/bishi/endpoints.py +++ b/bemani/frontend/bishi/endpoints.py @@ -57,7 +57,7 @@ def viewplayer(userid: UserID) -> Response: latest_version = sorted(djinfo.keys(), reverse=True)[0] return render_react( - '{}\'s BishiBashi Profile'.format(djinfo[latest_version]['name']), + f'{djinfo[latest_version]["name"]}\'s BishiBashi Profile', 'bishi/player.react.js', { 'playerid': userid, diff --git a/bemani/frontend/ddr/ddr.py b/bemani/frontend/ddr/ddr.py index 6a48eca..c5615ad 100644 --- a/bemani/frontend/ddr/ddr.py +++ b/bemani/frontend/ddr/ddr.py @@ -26,7 +26,7 @@ class DDRFrontend(FrontendBase): DDRBase.CHART_DOUBLE_CHALLENGE, ] - valid_rival_types = ['friend_{}'.format(i) for i in range(10)] + valid_rival_types = [f'friend_{i}' for i in range(10)] max_active_rivals = { VersionConstants.DDR_X2: 1, diff --git a/bemani/frontend/ddr/endpoints.py b/bemani/frontend/ddr/endpoints.py index 187a528..3c1675e 100644 --- a/bemani/frontend/ddr/endpoints.py +++ b/bemani/frontend/ddr/endpoints.py @@ -68,7 +68,7 @@ def viewscores(userid: UserID) -> Response: scores = frontend.round_to_ten(scores) return render_react( - '{}\'s DDR Scores'.format(info['name']), + f'{info["name"]}\'s DDR Scores', 'ddr/scores.react.js', { 'attempts': scores, @@ -140,7 +140,7 @@ def viewrecords(userid: UserID) -> Response: abort(404) return render_react( - '{}\'s DDR Records'.format(info['name']), + f'{info["name"]}\'s DDR Records', 'ddr/records.react.js', { 'records': frontend.get_records(userid), @@ -197,7 +197,7 @@ def viewtopscores(musicid: int) -> Response: top_scores = frontend.get_top_scores(musicid) return render_react( - 'Top DDR Scores for {} - {}'.format(artist, name), + f'Top DDR Scores for {artist} - {name}', 'ddr/topscores.react.js', { 'name': name, @@ -260,7 +260,7 @@ def viewplayer(userid: UserID) -> Response: latest_version = sorted(info.keys(), reverse=True)[0] return render_react( - '{}\'s DDR Profile'.format(info[latest_version]['name']), + f'{info[latest_version]["name"]}\'s DDR Profile', 'ddr/player.react.js', { 'playerid': userid, @@ -551,7 +551,7 @@ def addrival() -> Dict[str, Any]: GameConstants.DDR, version, userid, - 'friend_{}'.format(newrivalpos), + f'friend_{newrivalpos}', other_userid, {}, ) @@ -580,7 +580,7 @@ def removerival() -> Dict[str, Any]: GameConstants.DDR, version, userid, - 'friend_{}'.format(position), + f'friend_{position}', other_userid, ) diff --git a/bemani/frontend/iidx/endpoints.py b/bemani/frontend/iidx/endpoints.py index d9e2bf5..223cddf 100644 --- a/bemani/frontend/iidx/endpoints.py +++ b/bemani/frontend/iidx/endpoints.py @@ -68,7 +68,7 @@ def viewscores(userid: UserID) -> Response: scores = frontend.round_to_ten(scores) return render_react( - 'dj {}\'s IIDX Scores'.format(djinfo['name']), + f'dj {djinfo["name"]}\'s IIDX Scores', 'iidx/scores.react.js', { 'attempts': scores, @@ -140,7 +140,7 @@ def viewrecords(userid: UserID) -> Response: abort(404) return render_react( - 'dj {}\'s IIDX Records'.format(djinfo['name']), + f'dj {djinfo["name"]}\'s IIDX Records', 'iidx/records.react.js', { 'records': frontend.get_records(userid), @@ -203,7 +203,7 @@ def viewtopscores(musicid: int) -> Response: top_scores = frontend.get_top_scores(musicid) return render_react( - 'Top IIDX Scores for {} - {}'.format(artist, name), + f'Top IIDX Scores for {artist} - {name}', 'iidx/topscores.react.js', { 'name': name, @@ -272,7 +272,7 @@ def viewplayer(userid: UserID) -> Response: djinfo[version]['dp_rival'] = dp_rival is not None return render_react( - 'dj {}\'s IIDX Profile'.format(djinfo[latest_version]['name']), + f'dj {djinfo[latest_version]["name"]}\'s IIDX Profile', 'iidx/player.react.js', { 'playerid': userid, @@ -557,7 +557,7 @@ def addrival() -> Dict[str, Any]: # Add this rival link if rivaltype != 'sp_rival' and rivaltype != 'dp_rival': - raise Exception('Invalid rival type {}!'.format(rivaltype)) + raise Exception(f'Invalid rival type {rivaltype}!') profile = g.data.remote.user.get_profile(GameConstants.IIDX, version, other_userid) if profile is None: raise Exception('Unable to find profile for rival!') @@ -592,7 +592,7 @@ def removerival() -> Dict[str, Any]: # Remove this rival link if rivaltype != 'sp_rival' and rivaltype != 'dp_rival': - raise Exception('Invalid rival type {}!'.format(rivaltype)) + raise Exception(f'Invalid rival type {rivaltype}!') g.data.local.user.destroy_link( GameConstants.IIDX, diff --git a/bemani/frontend/jubeat/endpoints.py b/bemani/frontend/jubeat/endpoints.py index 4152e19..b0b689c 100644 --- a/bemani/frontend/jubeat/endpoints.py +++ b/bemani/frontend/jubeat/endpoints.py @@ -68,7 +68,7 @@ def viewscores(userid: UserID) -> Response: scores = frontend.round_to_ten(scores) return render_react( - '{}\'s Jubeat Scores'.format(info['name']), + f'{info["name"]}\'s Jubeat Scores', 'jubeat/scores.react.js', { 'attempts': scores, @@ -140,7 +140,7 @@ def viewrecords(userid: UserID) -> Response: abort(404) return render_react( - '{}\'s Jubeat Records'.format(info['name']), + f'{info["name"]}\'s Jubeat Records', 'jubeat/records.react.js', { 'records': frontend.get_records(userid), @@ -200,7 +200,7 @@ def viewtopscores(musicid: int) -> Response: top_scores = frontend.get_top_scores(musicid) return render_react( - 'Top Jubeat Scores for {} - {}'.format(artist, name), + f'Top Jubeat Scores for {artist} - {name}', 'jubeat/topscores.react.js', { 'name': name, @@ -262,7 +262,7 @@ def viewplayer(userid: UserID) -> Response: latest_version = sorted(info.keys(), reverse=True)[0] return render_react( - '{}\'s Jubeat Profile'.format(info[latest_version]['name']), + f'{info[latest_version]["name"]}\'s Jubeat Profile', 'jubeat/player.react.js', { 'playerid': userid, diff --git a/bemani/frontend/museca/endpoints.py b/bemani/frontend/museca/endpoints.py index 0102efa..b6af1ed 100644 --- a/bemani/frontend/museca/endpoints.py +++ b/bemani/frontend/museca/endpoints.py @@ -67,7 +67,7 @@ def viewscores(userid: UserID) -> Response: scores = frontend.round_to_ten(scores) return render_react( - '{}\'s MÚSECA Scores'.format(info['name']), + f'{info["name"]}\'s MÚSECA Scores', 'museca/scores.react.js', { 'attempts': scores, @@ -141,7 +141,7 @@ def viewrecords(userid: UserID) -> Response: versions = {version: name for (game, version, name) in frontend.all_games()} return render_react( - '{}\'s MÚSECA Records'.format(info['name']), + f'{info["name"]}\'s MÚSECA Records', 'museca/records.react.js', { 'records': frontend.get_records(userid), @@ -202,7 +202,7 @@ def viewtopscores(musicid: int) -> Response: top_scores = frontend.get_top_scores(musicid) return render_react( - 'Top MÚSECA Scores for {} - {}'.format(artist, name), + f'Top MÚSECA Scores for {artist} - {name}', 'museca/topscores.react.js', { 'name': name, @@ -263,7 +263,7 @@ def viewplayer(userid: UserID) -> Response: latest_version = sorted(info.keys(), reverse=True)[0] return render_react( - '{}\'s MÚSECA Profile'.format(info[latest_version]['name']), + f'{info[latest_version]["name"]}\'s MÚSECA Profile', 'museca/player.react.js', { 'playerid': userid, diff --git a/bemani/frontend/popn/endpoints.py b/bemani/frontend/popn/endpoints.py index 5026776..6874b0d 100644 --- a/bemani/frontend/popn/endpoints.py +++ b/bemani/frontend/popn/endpoints.py @@ -67,7 +67,7 @@ def viewscores(userid: UserID) -> Response: scores = frontend.round_to_ten(scores) return render_react( - '{}\'s Pop\'n Music Scores'.format(info['name']), + f'{info["name"]}\'s Pop\'n Music Scores', 'popn/scores.react.js', { 'attempts': scores, @@ -142,7 +142,7 @@ def viewrecords(userid: UserID) -> Response: versions[0] = 'CS and Licenses' return render_react( - '{}\'s Pop\'n Music Records'.format(info['name']), + f'{info["name"]}\'s Pop\'n Music Records', 'popn/records.react.js', { 'records': frontend.get_records(userid), @@ -206,7 +206,7 @@ def viewtopscores(musicid: int) -> Response: top_scores = frontend.get_top_scores(musicid) return render_react( - 'Top Pop\'n Music Scores for {} - {}'.format(artist, name), + f'Top Pop\'n Music Scores for {artist} - {name}', 'popn/topscores.react.js', { 'name': name, @@ -268,7 +268,7 @@ def viewplayer(userid: UserID) -> Response: latest_version = sorted(info.keys(), reverse=True)[0] return render_react( - '{}\'s Pop\'n Music Profile'.format(info[latest_version]['name']), + f'{info[latest_version]["name"]}\'s Pop\'n Music Profile', 'popn/player.react.js', { 'playerid': userid, diff --git a/bemani/frontend/reflec/endpoints.py b/bemani/frontend/reflec/endpoints.py index b000dd8..32d72d4 100644 --- a/bemani/frontend/reflec/endpoints.py +++ b/bemani/frontend/reflec/endpoints.py @@ -69,7 +69,7 @@ def viewscores(userid: UserID) -> Response: scores = frontend.round_to_ten(scores) return render_react( - '{}\'s Reflec Beat Scores'.format(info['name']), + f'{info["name"]}\'s Reflec Beat Scores', 'reflec/scores.react.js', { 'attempts': scores, @@ -143,7 +143,7 @@ def viewrecords(userid: UserID) -> Response: versions = {version: name for (game, version, name) in frontend.all_games()} return render_react( - '{}\'s Reflec Beat Records'.format(info['name']), + f'{info["name"]}\'s Reflec Beat Records', 'reflec/records.react.js', { 'records': frontend.get_records(userid), @@ -199,7 +199,7 @@ def viewtopscores(musicid: int) -> Response: top_scores = frontend.get_top_scores(musicid) return render_react( - 'Top Reflec Beat Scores for {} - {}'.format(artist, name), + f'Top Reflec Beat Scores for {artist} - {name}', 'reflec/topscores.react.js', { 'name': name, @@ -260,7 +260,7 @@ def viewplayer(userid: UserID) -> Response: latest_version = sorted(info.keys(), reverse=True)[0] return render_react( - '{}\'s Reflec Beat Profile'.format(info[latest_version]['name']), + f'{info[latest_version]["name"]}\'s Reflec Beat Profile', 'reflec/player.react.js', { 'playerid': userid, diff --git a/bemani/frontend/sdvx/endpoints.py b/bemani/frontend/sdvx/endpoints.py index 5cf9720..c3629d3 100644 --- a/bemani/frontend/sdvx/endpoints.py +++ b/bemani/frontend/sdvx/endpoints.py @@ -67,7 +67,7 @@ def viewscores(userid: UserID) -> Response: scores = frontend.round_to_ten(scores) return render_react( - '{}\'s SDVX Scores'.format(info['name']), + f'{info["name"]}\'s SDVX Scores', 'sdvx/scores.react.js', { 'attempts': scores, @@ -141,7 +141,7 @@ def viewrecords(userid: UserID) -> Response: versions = {version: name for (game, version, name) in frontend.all_games()} return render_react( - '{}\'s SDVX Records'.format(info['name']), + f'{info["name"]}\'s SDVX Records', 'sdvx/records.react.js', { 'records': frontend.get_records(userid), @@ -202,7 +202,7 @@ def viewtopscores(musicid: int) -> Response: top_scores = frontend.get_top_scores(musicid) return render_react( - 'Top SDVX Scores for {} - {}'.format(artist, name), + f'Top SDVX Scores for {artist} - {name}', 'sdvx/topscores.react.js', { 'name': name, @@ -263,7 +263,7 @@ def viewplayer(userid: UserID) -> Response: latest_version = sorted(info.keys(), reverse=True)[0] return render_react( - '{}\'s SDVX Profile'.format(info[latest_version]['name']), + f'{info[latest_version]["name"]}\'s SDVX Profile', 'sdvx/player.react.js', { 'playerid': userid, diff --git a/bemani/protocol/binary.py b/bemani/protocol/binary.py index f879fea..b431fcc 100644 --- a/bemani/protocol/binary.py +++ b/bemani/protocol/binary.py @@ -330,7 +330,7 @@ class BinaryDecoder: eod = self.stream.read_int() if eod != Node.END_OF_DOCUMENT: - raise BinaryEncodingException('Unknown node type {} at end of document'.format(eod)) + raise BinaryEncodingException(f'Unknown node type {eod} at end of document') # Skip by any padding while self.stream.pos < header_length + 4: @@ -386,13 +386,13 @@ class BinaryDecoder: loc = loc + 4 decode_data = body[loc:(loc + size)] - decode_value = '>{}{}'.format(size, enc) + decode_value = f'>{size}{enc}' else: # The size is built-in ordering.mark_used(size, loc) decode_data = body[loc:(loc + size)] - decode_value = '>{}'.format(enc) + decode_value = f'>{enc}' if composite: val_list = list(struct.unpack(decode_value, decode_data)) @@ -427,7 +427,7 @@ class BinaryDecoder: ordering.mark_used(length + 4, loc, round_to=4) loc = loc + 4 decode_data = body[loc:(loc + length)] - decode_value = '>{}'.format(enc * elems) + decode_value = f'>{enc * elems}' val = struct.unpack(decode_value, decode_data) node.set_value([v for v in val]) @@ -589,7 +589,7 @@ class BinaryEncoder: if val is None: raise BinaryEncodingException( - 'Node \'{}\' has invalid value None'.format(value['name']), + f'Node \'{value["name"]}\' has invalid value None', ) if not array: @@ -608,14 +608,14 @@ class BinaryEncoder: # Also, need to lob off the trailing null. if not isinstance(val, str): raise BinaryEncodingException( - 'Node \'{}\' has non-string value!'.format(value['name']), + f'Node \'{value["name"]}\' has non-string value!', ) try: valbytes = val.encode(self.encoding) + b'\0' except UnicodeEncodeError: raise BinaryEncodingException( - 'Node \'{}\' has un-encodable string value \'{}\''.format(value['name'], val) + f'Node \'{value["name"]}\' has un-encodable string value \'{val}\'' ) size = len(valbytes) self.__add_data(struct.pack('>I', size) + valbytes, size + 4, loc) @@ -633,7 +633,7 @@ class BinaryEncoder: continue elif composite: # Array, but not, somewhat silly - encode_value = '>{}'.format(enc) + encode_value = f'>{enc}' self.__add_data(struct.pack(encode_value, *val), size, loc) ordering.mark_used(size, loc) @@ -643,7 +643,7 @@ class BinaryEncoder: val = 1 if val else 0 # The size is built-in, emit it - encode_value = '>{}'.format(enc) + encode_value = f'>{enc}' self.__add_data(struct.pack(encode_value, val), size, loc) ordering.mark_used(size, loc) else: @@ -656,7 +656,7 @@ class BinaryEncoder: # Write out the header (number of bytes taken up) data = struct.pack('>I', length) - encode_value = '>{}'.format(enc) + encode_value = f'>{enc}' # Write out data one element at a time for v in val: @@ -768,7 +768,7 @@ class BinaryEncoding: break if encoding_magic is None: - raise BinaryEncodingException("Invalid text encoding {}".format(encoding)) + raise BinaryEncodingException(f"Invalid text encoding {encoding}") encoder = BinaryEncoder(tree, self.__sanitize_encoding(encoding)) data = encoder.get_data() diff --git a/bemani/protocol/node.py b/bemani/protocol/node.py index 50a8024..b0e30d8 100644 --- a/bemani/protocol/node.py +++ b/bemani/protocol/node.py @@ -235,28 +235,28 @@ class Node: def __validate(nodetype: int, name: str, value: int) -> None: if nodetype == Node.NODE_TYPE_U8: if value < 0 or value > 255: - raise NodeException('Invalid value {} for u8 {}'.format(value, name)) + raise NodeException(f'Invalid value {value} for u8 {name}') elif nodetype == Node.NODE_TYPE_S8: if value < -128 or value > 127: - raise NodeException('Invalid value {} for s8 {}'.format(value, name)) + raise NodeException(f'Invalid value {value} for s8 {name}') elif nodetype == Node.NODE_TYPE_U16: if value < 0 or value > 65535: - raise NodeException('Invalid value {} for u16 {}'.format(value, name)) + raise NodeException(f'Invalid value {value} for u16 {name}') elif nodetype == Node.NODE_TYPE_S16: if value < -32768 or value > 32767: - raise NodeException('Invalid value {} for s16 {}'.format(value, name)) + raise NodeException(f'Invalid value {value} for s16 {name}') elif nodetype == Node.NODE_TYPE_U32: if value < 0 or value > 4294967295: - raise NodeException('Invalid value {} for u32 {}'.format(value, name)) + raise NodeException(f'Invalid value {value} for u32 {name}') elif nodetype == Node.NODE_TYPE_S32: if value < -2147483648 or value > 2147483647: - raise NodeException('Invalid value {} for s32 {}'.format(value, name)) + raise NodeException(f'Invalid value {value} for s32 {name}') elif nodetype == Node.NODE_TYPE_U64: if value < 0 or value > 18446744073709551615: - raise NodeException('Invalid value {} for u64 {}'.format(value, name)) + raise NodeException(f'Invalid value {value} for u64 {name}') elif nodetype == Node.NODE_TYPE_S64: if value < -9223372036854775808 or value > 9223372036854775807: - raise NodeException('Invalid value {} for s32 {}'.format(value, name)) + raise NodeException(f'Invalid value {value} for s32 {name}') @staticmethod def u8(name: str, value: int) -> 'Node': @@ -399,7 +399,7 @@ class Node: # Ensure it isn't a violation for char in name: if char not in Node.NODE_NAME_CHARS: - raise NodeException('Invalid node name {}'.format(name)) + raise NodeException(f'Invalid node name {name}') self.__name = name @@ -437,7 +437,7 @@ class Node: self.__translated_type = Node.NODE_TYPES[type & (~Node.ARRAY_BIT)] self.__type = type except KeyError: - raise NodeException('Unknown node type {}'.format(type)) + raise NodeException(f'Unknown node type {type}') @property def type(self) -> int: @@ -629,13 +629,10 @@ class Node: if not is_array: raise NodeException('Input is not array, expected array') if len(val) != len(self.__translated_type['enc']): - raise NodeException('Input array for {} expected to be {} elements!'.format( - self.__translated_type['name'], - len(self.__translated_type['enc']), - )) + raise NodeException(f'Input array for {self.__translated_type["name"]} expected to be {len(self.__translated_type["enc"])} elements!') is_array = False if is_array != self.__array: - raise NodeException('Input {} array, expected {}'.format('is' if is_array else 'is not', 'array' if self.__array else 'scalar')) + raise NodeException(f'Input {"is" if is_array else "is not"} array, expected {"array" if self.__array else "scalar"}') def val_to_str(val: Any) -> str: if self.__translated_type['name'] == 'bool': @@ -653,14 +650,14 @@ class Node: try: # Support construction from binary ip = struct.unpack('BBBB', val) - return '{}.{}.{}.{}'.format(ip[0], ip[1], ip[2], ip[3]) + return f'{ip[0]}.{ip[1]}.{ip[2]}.{ip[3]}' except (struct.error, TypeError): # Assume that its user-built string? if isinstance(val, str): if len(val.split('.')) == 4: return val - raise NodeException('Invalid value {} for IP4 type'.format(val)) + raise NodeException(f'Invalid value {val} for IP4 type') elif self.__translated_type['int']: return str(val) else: @@ -737,7 +734,7 @@ class Node: return str(val) if attrs_dict: - attrs = ' ' + ' '.join(['{name}="{val}"'.format(name=attr, val=escape(attrs_dict[attr], attr=True)) for attr in order]) + attrs = ' ' + ' '.join([f'{attr}="{escape(attrs_dict[attr], attr=True)}"' for attr in order]) else: attrs = '' @@ -769,35 +766,18 @@ class Node: if self.__translated_type['len'] != 0: # Has children and a value children = [ - '{depth}{vals}\n'.format( - depth=' ' * ((depth + 1) * 4), - vals=get_val(), - ), + f'{" " * ((depth + 1) * 4)}{get_val()}\n', ] + children - string = '{depth}<{name}{attrs}>\n{children}{depth}\n'.format( - depth=' ' * (depth * 4), - name=self.__name, - attrs=attrs, - children=''.join(children), - ) + string = f'{" " * (depth * 4)}<{self.__name}{attrs}>\n{"".join(children)}{" " * (depth * 4)}\n' else: # Doesn't have children nodes if self.__translated_type['len'] == 0: # Void node - string = '{depth}<{name}{attrs} />\n'.format( - depth=' ' * (depth * 4), - name=self.__name, - attrs=attrs, - ) + string = f'{" " * (depth * 4)}<{self.__name}{attrs} />\n' else: # Node with values - string = '{depth}<{name}{attrs}>{vals}\n'.format( - depth=' ' * (depth * 4), - name=self.__name, - attrs=attrs, - vals=get_val(), - ) + string = f'{" " * (depth * 4)}<{self.__name}{attrs}>{get_val()}\n' return string diff --git a/bemani/protocol/protocol.py b/bemani/protocol/protocol.py index 8789a75..635cb65 100644 --- a/bemani/protocol/protocol.py +++ b/bemani/protocol/protocol.py @@ -141,7 +141,7 @@ class EAmuseProtocol: lz = Lz77() return lz.decompress(data) else: - raise EAmuseException('Unknown compression {}'.format(compression)) + raise EAmuseException(f'Unknown compression {compression}') # No compression return data @@ -171,7 +171,7 @@ class EAmuseProtocol: lz = Lz77() return lz.compress(data) else: - raise EAmuseException('Unknown compression {}'.format(compression)) + raise EAmuseException(f'Unknown compression {compression}') # No compression return data @@ -235,7 +235,7 @@ class EAmuseProtocol: xml = XmlEncoding() return xml.encode(tree, encoding=text_encoding) else: - raise EAmuseException("Invalid packet encoding {}".format(packet_encoding)) + raise EAmuseException(f"Invalid packet encoding {packet_encoding}") def decode(self, compression: Optional[str], encryption: Optional[str], data: bytes) -> Node: """ diff --git a/bemani/protocol/stream.py b/bemani/protocol/stream.py index 83c8a4a..46c9394 100644 --- a/bemani/protocol/stream.py +++ b/bemani/protocol/stream.py @@ -102,7 +102,7 @@ class InputStream: else: return struct.unpack('>i', data)[0] else: - raise StreamError('Unsupported size {}'.format(size)) + raise StreamError(f'Unsupported size {size}') class OutputStream: @@ -169,7 +169,7 @@ class OutputStream: self.__data.append(struct.pack('>i', integer)) self.__data_len = self.__data_len + 4 else: - raise StreamError('Unsupported size {}'.format(size)) + raise StreamError(f'Unsupported size {size}') self.__formatted_data = None def write_pad(self, pad_to: int) -> None: diff --git a/bemani/protocol/xml.py b/bemani/protocol/xml.py index bd29821..7edba71 100644 --- a/bemani/protocol/xml.py +++ b/bemani/protocol/xml.py @@ -59,7 +59,7 @@ class XmlDecoder: # Get the data value type_int = Node.typename_to_type(data_type) if type_int is None: - raise XmlEncodingException('Invalid node type {} for node {}'.format(data_type, tag.decode('ascii'))) + raise XmlEncodingException(f'Invalid node type {data_type} for node {tag.decode("ascii")}') node = Node(name=tag.decode('ascii'), type=type_int, array=array) @@ -84,7 +84,7 @@ class XmlDecoder: node = self.current.pop() if node.name != tag.decode('ascii'): - raise Exception('Logic error, expected {} but got {}'.format(tag.decode('ascii'), node.name)) + raise Exception(f'Logic error, expected {tag.decode("ascii")} but got {node.name}') if len(self.current) == 0: self.root = node @@ -344,7 +344,7 @@ class XmlEncoder: self.encoding = encoding def get_data(self) -> bytes: - magic = ''.format(self.encoding).encode('ascii') + magic = f''.encode('ascii') payload = self.to_xml(self.tree) return magic + payload @@ -540,7 +540,7 @@ class XmlEncoding: encoding = self.__fix_encoding(encoding) if encoding not in XmlEncoding.ACCEPTED_ENCODINGS: # XML pages only support shift-jis - raise XmlEncodingException("Invalid text encoding {}".format(encoding)) + raise XmlEncodingException(f"Invalid text encoding {encoding}") xml = XmlEncoder(tree, encoding) return xml.get_data() diff --git a/bemani/sniff/sniff.py b/bemani/sniff/sniff.py index f2081b6..3057bb7 100644 --- a/bemani/sniff/sniff.py +++ b/bemani/sniff/sniff.py @@ -267,12 +267,12 @@ class Sniffer: if ihl < Sniffer.IP_HEADER_LENGTH: raise InvalidPacketException( - 'Invalid IP length {}'.format(ihl), + f'Invalid IP length {ihl}', ) if version != 4: raise UnknownPacketException( - 'Unknown IP version {}'.format(version), + f'Unknown IP version {version}', ) s_addr = socket.inet_ntoa(iph[8]) @@ -391,7 +391,7 @@ class Sniffer: if eth_header['protocol'] != 8: # Not IP raise UnknownPacketException( - 'Unknown frame {}'.format(eth_header['protocol']) + f'Unknown frame {eth_header["protocol"]}' ) # Get the IP header @@ -401,7 +401,7 @@ class Sniffer: if ip_header['protocol'] != 6: # Not TCP raise UnknownPacketException( - 'Unknown protocol {}'.format(ip_header['protocol']), + f'Unknown protocol {ip_header["protocol"]}', ) # Get TCP header diff --git a/bemani/tests/helpers.py b/bemani/tests/helpers.py index 3a5bb8f..bf418e7 100644 --- a/bemani/tests/helpers.py +++ b/bemani/tests/helpers.py @@ -10,7 +10,7 @@ class FakeCursor(): def fetchone(self) -> Dict[str, Any]: if len(self.__rows) != 1: - raise Exception('Tried to fetch one row and there are {} rows!'.format(len(self.__rows))) + raise Exception(f'Tried to fetch one row and there are {len(self.__rows)} rows!') return self.__rows[0] def fetchall(self) -> List[Dict[str, Any]]: diff --git a/bemani/tests/test_CardCipher.py b/bemani/tests/test_CardCipher.py index bc50087..d743353 100644 --- a/bemani/tests/test_CardCipher.py +++ b/bemani/tests/test_CardCipher.py @@ -16,9 +16,9 @@ class TestCardCipher(unittest.TestCase): inp = bytes(pair[0]) out = bytes(pair[1]) encoded = CardCipher._CardCipher__encode(inp) # type: ignore - self.assertEqual(encoded, out, "Card encode {} doesn't match expected {}".format(encoded, out)) + self.assertEqual(encoded, out, f"Card encode {encoded} doesn't match expected {out}") decoded = CardCipher._CardCipher__decode(out) # type: ignore - self.assertEqual(decoded, inp, "Card decode {} doesn't match expected {}".format(decoded, inp)) + self.assertEqual(decoded, inp, f"Card decode {decoded} doesn't match expected {inp}") def test_external_cipher(self) -> None: test_cards = [ @@ -30,6 +30,6 @@ class TestCardCipher(unittest.TestCase): back = card[0] db = card[1] decoded = CardCipher.decode(back) - self.assertEqual(decoded, db, "Card DB {} doesn't match expected {}".format(decoded, db)) + self.assertEqual(decoded, db, f"Card DB {decoded} doesn't match expected {db}") encoded = CardCipher.encode(db) - self.assertEqual(encoded, back, "Card back {} doesn't match expected {}".format(encoded, back)) + self.assertEqual(encoded, back, f"Card back {encoded} doesn't match expected {back}") diff --git a/bemani/tests/test_protocol.py b/bemani/tests/test_protocol.py index 69cc022..bbece76 100644 --- a/bemani/tests/test_protocol.py +++ b/bemani/tests/test_protocol.py @@ -22,19 +22,19 @@ class TestProtocol(unittest.TestCase): binary = proto.encode(None, None, root, text_encoding=EAmuseProtocol.SHIFT_JIS, packet_encoding=encoding) newroot = proto.decode(None, None, binary) - self.assertEqual(newroot, root, "Round trip with {} and no encryption/compression doesn't match!".format(loop_name)) + self.assertEqual(newroot, root, f"Round trip with {loop_name} and no encryption/compression doesn't match!") binary = proto.encode(None, '1-abcdef-0123', root, text_encoding=EAmuseProtocol.SHIFT_JIS, packet_encoding=encoding) newroot = proto.decode(None, '1-abcdef-0123', binary) - self.assertEqual(newroot, root, "Round trip with {}, encryption and no compression doesn't match!".format(loop_name)) + self.assertEqual(newroot, root, f"Round trip with {loop_name}, encryption and no compression doesn't match!") binary = proto.encode('none', None, root, text_encoding=EAmuseProtocol.SHIFT_JIS, packet_encoding=encoding) newroot = proto.decode('none', None, binary) - self.assertEqual(newroot, root, "Round trip with {}, encryption and no compression doesn't match!".format(loop_name)) + self.assertEqual(newroot, root, f"Round trip with {loop_name}, encryption and no compression doesn't match!") binary = proto.encode('lz77', None, root, text_encoding=EAmuseProtocol.SHIFT_JIS, packet_encoding=encoding) newroot = proto.decode('lz77', None, binary) - self.assertEqual(newroot, root, "Round trip with {}, no encryption and lz77 compression doesn't match!".format(loop_name)) + self.assertEqual(newroot, root, f"Round trip with {loop_name}, no encryption and lz77 compression doesn't match!") def test_game_packet1(self) -> Node: root = Node.void('call') diff --git a/bemani/utils/arcutils.py b/bemani/utils/arcutils.py index a3ab0e8..d670c24 100644 --- a/bemani/utils/arcutils.py +++ b/bemani/utils/arcutils.py @@ -39,7 +39,7 @@ def main() -> None: if args.list_only: print(fn) else: - print('Extracting {} to disk...'.format(fn)) + print(f'Extracting {fn} to disk...') realfn = os.path.join(root, fn) dirof = os.path.dirname(realfn) os.makedirs(dirof, exist_ok=True) diff --git a/bemani/utils/bemanishark.py b/bemani/utils/bemanishark.py index da78f4f..35bcb87 100644 --- a/bemani/utils/bemanishark.py +++ b/bemani/utils/bemanishark.py @@ -38,16 +38,11 @@ def mainloop(address: Optional[str]=None, port: int=80, verbose: bool=False) -> except EAmuseException: in_req = None - print("Inbound request (from {}:{} to {}:{}):".format( - packets['source_address'], - packets['source_port'], - packets['destination_address'], - packets['destination_port'], - )) + print(f"Inbound request (from {packets['source_address']}:{packets['source_port']} to {packets['destination_address']}:{packets['destination_port']}):") if verbose: - print("HTTP {} request for URI {}".format(inbound['method'], inbound['uri'])) - print("Compression is {}".format(inbound['headers'].get('x-compress', 'none'))) - print("Encryption key is {}".format(inbound['headers'].get('x-eamuse-info', 'none'))) + print(f"HTTP {inbound['method']} request for URI {inbound['uri']}") + print(f"Compression is {inbound['headers'].get('x-compress', 'none')}") + print(f"Encryption key is {inbound['headers'].get('x-eamuse-info', 'none')}") if in_req is None: print("Inbound request was not parseable") else: @@ -66,15 +61,10 @@ def mainloop(address: Optional[str]=None, port: int=80, verbose: bool=False) -> except EAmuseException: out_req = None - print("Outbound response (from {}:{} to {}:{}):".format( - packets['destination_address'], - packets['destination_port'], - packets['source_address'], - packets['source_port'], - )) + print(f"Outbound response (from {packets['destination_address']}:{packets['destination_port']} to {packets['source_address']}:{packets['source_port']}):") if verbose: - print("Compression is {}".format(outbound['headers'].get('x-compress', 'none'))) - print("Encryption key is {}".format(outbound['headers'].get('x-eamuse-info', 'none'))) + print(f"Compression is {outbound['headers'].get('x-compress', 'none')}") + print(f"Encryption key is {outbound['headers'].get('x-eamuse-info', 'none')}") if out_req is None: print("Outbound response was not parseable") else: diff --git a/bemani/utils/dbutils.py b/bemani/utils/dbutils.py index fc70928..3d5e392 100644 --- a/bemani/utils/dbutils.py +++ b/bemani/utils/dbutils.py @@ -39,7 +39,7 @@ def change_password(config: Dict[str, Any], username: Optional[str]) -> None: if userid is None: raise Exception('User not found!') data.local.user.update_password(userid, password1) - print('User {} changed password.'.format(username)) + print(f'User {username} changed password.') def add_admin(config: Dict[str, Any], username: Optional[str]) -> None: @@ -52,7 +52,7 @@ def add_admin(config: Dict[str, Any], username: Optional[str]) -> None: user = data.local.user.get_user(userid) user.admin = True data.local.user.put_user(user) - print('User {} gained admin rights.'.format(username)) + print(f'User {username} gained admin rights.') def remove_admin(config: Dict[str, Any], username: Optional[str]) -> None: @@ -65,7 +65,7 @@ def remove_admin(config: Dict[str, Any], username: Optional[str]) -> None: user = data.local.user.get_user(userid) user.admin = False data.local.user.put_user(user) - print('User {} lost admin rights.'.format(username)) + print(f'User {username} lost admin rights.') def main() -> None: @@ -112,7 +112,7 @@ def main() -> None: elif args.operation == 'change-password': change_password(config, args.username) else: - raise Exception("Unknown operation '{}'".format(args.operation)) + raise Exception(f"Unknown operation '{args.operation}'") except DBCreateException as e: print(str(e)) sys.exit(1) diff --git a/bemani/utils/ifsutils.py b/bemani/utils/ifsutils.py index b466997..95e1366 100644 --- a/bemani/utils/ifsutils.py +++ b/bemani/utils/ifsutils.py @@ -40,7 +40,7 @@ def main() -> None: ifs = IFS(data, args.convert_xml_files, args.convert_texture_files) for fn in ifs.filenames: - print('Extracting {} to disk...'.format(fn)) + print(f'Extracting {fn} to disk...') realfn = os.path.join(root, fn) dirof = os.path.dirname(realfn) os.makedirs(dirof, exist_ok=True) diff --git a/bemani/utils/iidxutils.py b/bemani/utils/iidxutils.py index e2e2c46..746be1a 100644 --- a/bemani/utils/iidxutils.py +++ b/bemani/utils/iidxutils.py @@ -34,7 +34,7 @@ def main() -> None: song.difficulties[1] == 0 and song.difficulties[2] == 12 ): - print('Patching \'{}\' to only appear in leggendaria folder!'.format(song.title)) + print(f'Patching \'{song.title}\' to only appear in leggendaria folder!') song.folder = 0x5C print('Generating new database file...') diff --git a/bemani/utils/proxy.py b/bemani/utils/proxy.py index 437a48a..7883014 100644 --- a/bemani/utils/proxy.py +++ b/bemani/utils/proxy.py @@ -42,13 +42,7 @@ def modify_response(config: Dict[str, Any], resp_body: Node) -> Optional[Node]: address = socket.gethostbyname(config['keepalive']) child.set_attribute( 'url', - 'http://{}/core/keepalive?pa={}&ia={}&ga={}&ma={}&t1=2&t2=10'.format( - address, - address, - address, - address, - address, - ), + f'http://{address}/core/keepalive?pa={address}&ia={address}&ga={address}&ma={address}&t1=2&t2=10', ) else: # Get netloc to replace @@ -58,14 +52,9 @@ def modify_response(config: Dict[str, Any], resp_body: Node) -> Optional[Node]: 'https': 443, }.get(url.scheme, 0) if config['local_port'] != defaultport: - new_url = child.attribute('url').replace(url.netloc, '{}:{}'.format( - config['local_host'], - config['local_port'], - )) + new_url = child.attribute('url').replace(url.netloc, f'{config["local_host"]}:{config["local_port"]}') else: - new_url = child.attribute('url').replace(url.netloc, '{}'.format( - config['local_host'], - )) + new_url = child.attribute('url').replace(url.netloc, f'{config["local_host"]}') child.set_attribute('url', new_url) return resp_body @@ -82,13 +71,13 @@ def receive_healthcheck(path: str) -> Response: else: return Response("No route for default PCBID", 500) - actual_path = '/{}'.format(path) + actual_path = f'/{path}' if request.query_string is not None and len(request.query_string) > 0: - actual_path = actual_path + '?{}'.format(request.query_string.decode('ascii')) + actual_path = actual_path + f'?{request.query_string.decode("ascii")}' # Make request to foreign service, using the same parameters r = requests.get( - 'http://{}:{}{}'.format(remote_host, remote_port, actual_path), + f'http://{remote_host}:{remote_port}{actual_path}', timeout=config['timeout'], allow_redirects=False, ) @@ -111,14 +100,14 @@ def receive_request(path: str) -> Response: request_compression = request.headers.get('X-Compress', None) request_encryption = request.headers.get('X-Eamuse-Info', None) - actual_path = '/{}'.format(path) + actual_path = f'/{path}' if request.query_string is not None and len(request.query_string) > 0: - actual_path = actual_path + '?{}'.format(request.query_string.decode('ascii')) + actual_path = actual_path + f'?{request.query_string.decode("ascii")}' if config['verbose']: - print("HTTP request for URI {}".format(actual_path)) - print("Compression is {}".format(request_compression)) - print("Encryption key is {}".format(request_encryption)) + print(f"HTTP request for URI {actual_path}") + print(f"Compression is {request_compression}") + print(f"Encryption key is {request_encryption}") req = client_proto.decode( request_compression, @@ -143,7 +132,7 @@ def receive_request(path: str) -> Response: remote_host = config['remote']['*']['host'] remote_port = config['remote']['*']['port'] else: - return Response("No route for PCBID {}".format(pcbid), 500) + return Response(f"No route for PCBID {pcbid}", 500) modified_request = modify_request(config, req) if modified_request is None: @@ -177,7 +166,7 @@ def receive_request(path: str) -> Response: # Make request to foreign service, using the same parameters r = requests.post( - 'http://{}:{}{}'.format(remote_host, remote_port, actual_path), + f'http://{remote_host}:{remote_port}{actual_path}', headers=headers, data=req_binary, timeout=config['timeout'], diff --git a/bemani/utils/read.py b/bemani/utils/read.py index 90f3b8c..0d014a6 100644 --- a/bemani/utils/read.py +++ b/bemani/utils/read.py @@ -62,12 +62,7 @@ class ImportBase: self.update = update self.no_combine = no_combine self.__config = config - self.__url = "mysql://{}:{}@{}/{}?charset=utf8mb4".format( - config['database']['user'], - config['database']['password'], - config['database']['address'], - config['database']['database'], - ) + self.__url = f"mysql://{config['database']['user']}:{config['database']['password']}@{config['database']['address']}/{config['database']['database']}?charset=utf8mb4" self.__engine = create_engine(self.__url) # type: ignore self.__sessionmanager = sessionmaker(self.__engine) self.__conn = self.__engine.connect() @@ -243,9 +238,7 @@ class ImportBase: updates.append("genre = :genre") if len(updates) == 0: return - sql = "UPDATE `music` SET {} WHERE songid = :songid AND chart = :chart AND game = :game".format( - ", ".join(updates), - ) + sql = f"UPDATE `music` SET {', '.join(updates)} WHERE songid = :songid AND chart = :chart AND game = :game" if version is not None: sql = sql + " AND version = :version" self.execute( @@ -288,9 +281,7 @@ class ImportBase: updates.append("genre = :genre") if len(updates) == 0: return - sql = "UPDATE `music` SET {} WHERE id = :musicid AND game = :game".format( - ", ".join(updates), - ) + sql = f"UPDATE `music` SET {', '.join(updates)} WHERE id = :musicid AND game = :game" if version is not None: sql = sql + " AND version = :version" self.execute( @@ -990,7 +981,7 @@ class ImportPopn(ImportBase): mask & 0x4000000 > 0, # Battle hyper chart bit ) else: - raise Exception('Unsupported version {}'.format(self.version)) + raise Exception(f'Unsupported version {self.version}') def read_string(offset: int) -> str: # First, translate load offset in memory to disk offset @@ -1196,10 +1187,10 @@ class ImportPopn(ImportBase): if self.no_combine or old_id is None: # Insert original - print("New entry for {} {} ({} chart {})".format(artist, title, song['id'], chart)) + print(f"New entry for {artist} {title} ({song['id']} chart {chart})") next_id = self.get_next_music_id() else: - print("Reused entry for {} {} ({} chart {})".format(artist, title, song['id'], chart)) + print(f"Reused entry for {artist} {title} ({song['id']} chart {chart})") next_id = old_id self.insert_music_id_for_song( next_id, @@ -1351,11 +1342,11 @@ class ImportJubeat(ImportBase): old_id = self.get_music_id_for_song(songid, chart) if self.no_combine or old_id is None: # Insert original - print("New entry for {} chart {}".format(songid, chart)) + print(f"New entry for {songid} chart {chart}") next_id = self.get_next_music_id() else: # Insert pointing at same ID so scores transfer - print("Reused entry for {} chart {}".format(songid, chart)) + print(f"Reused entry for {songid} chart {chart}") next_id = old_id data = { 'difficulty': song['difficulty'][chart_map[chart]], @@ -1376,7 +1367,7 @@ class ImportJubeat(ImportBase): name = row[1] artist = row[2] - print("Setting name/artist for {} all charts".format(songid)) + print(f"Setting name/artist for {songid} all charts") self.start_batch() for chart in self.charts: self.update_metadata_for_song(songid, chart, name, artist) @@ -1588,9 +1579,9 @@ class ImportIIDX(ImportBase): bpm = (bpm_min, bpm_max) notecounts = iidxchart.notecounts else: - print("Could not find chart information for song {}!".format(song.id)) + print(f"Could not find chart information for song {song.id}!") else: - print("No chart information because chart for song {} is missing!".format(song.id)) + print(f"No chart information because chart for song {song.id} is missing!") songs.append({ 'id': song.id, @@ -1705,11 +1696,11 @@ class ImportIIDX(ImportBase): old_id = self.__revivals(song['id'], self.__charts(song['id'], chart)) if self.no_combine or old_id is None: # Insert original - print("New entry for {} chart {}".format(song['id'], chart)) + print(f"New entry for {song['id']} chart {chart}") next_id = self.get_next_music_id() else: # Insert pointing at same ID so scores transfer - print("Reused entry for {} chart {}".format(song['id'], chart)) + print(f"Reused entry for {song['id']} chart {chart}") next_id = old_id self.insert_music_id_for_song(next_id, song['id'], chart, song['title'], song['artist'], song['genre'], songdata) self.finish_batch() @@ -1733,7 +1724,7 @@ class ImportIIDX(ImportBase): if len(genre) == 0: genre = None - print("Setting name/artist/genre for {} all charts".format(songid)) + print(f"Setting name/artist/genre for {songid} all charts") self.start_batch() for chart in self.charts: self.update_metadata_for_song(songid, chart, name, artist, genre) @@ -2371,10 +2362,10 @@ class ImportDDR(ImportBase): old_id = self.get_music_id_for_song(song['edit_id'], chart, version=0) if self.no_combine or old_id is None: # Insert original - print("New entry for {} {} ({} chart {})".format(song['title'], song['artist'], song['id'], chart)) + print(f"New entry for {song['title']} {song['artist']} ({song['id']} chart {chart})") next_id = self.get_next_music_id() else: - print("Reused entry for {} {} ({} chart {})".format(song['title'], song['artist'], song['id'], chart)) + print(f"Reused entry for {song['title']} {song['artist']} ({song['id']} chart {chart})") next_id = old_id # Add the virtual entry we talked about above, so we can link this song in the future. self.insert_music_id_for_song( @@ -2501,7 +2492,7 @@ class ImportSDVX(ImportBase): for entry in entries: self.start_batch() - print("New catalog entry for {} chart {}".format(entry['musicid'], entry['chart'])) + print(f"New catalog entry for {entry['musicid']} chart {entry['chart']}") self.insert_catalog_entry( 'song_unlock', entry['catalogid'], @@ -2532,11 +2523,11 @@ class ImportSDVX(ImportBase): except (TypeError, ValueError): pass else: - raise Exception('Cannot import appeal cards for SDVX version {}'.format(self.version)) + raise Exception(f'Cannot import appeal cards for SDVX version {self.version}') self.start_batch() for appealid in appealids: - print("New catalog entry for appeal card {}".format(appealid)) + print(f"New catalog entry for appeal card {appealid}") self.insert_catalog_entry( 'appealcard', appealid, @@ -2576,7 +2567,7 @@ class ImportSDVX(ImportBase): limited = [int(info.text), int(info.text), int(info.text), int(info.text)] # Make sure we got everything if title is None or artist is None or bpm_min is None or bpm_max is None: - raise Exception('Couldn\'t parse info for song {}'.format(songid)) + raise Exception(f'Couldn\'t parse info for song {songid}') # Grab valid difficulties for difficulty in music_entry.findall('difficulty'): @@ -2662,11 +2653,11 @@ class ImportSDVX(ImportBase): old_id = self.get_music_id_for_song(songid, chart) if self.no_combine or old_id is None: # Insert original - print("New entry for {} chart {}".format(songid, chart)) + print(f"New entry for {songid} chart {chart}") next_id = self.get_next_music_id() else: # Insert pointing at same ID so scores transfer - print("Reused entry for {} chart {}".format(songid, chart)) + print(f"Reused entry for {songid} chart {chart}") next_id = old_id data = { 'limited': limited[chart], @@ -2685,7 +2676,7 @@ class ImportSDVX(ImportBase): if appealids: self.start_batch() for appealid in appealids: - print("New catalog entry for appeal card {}".format(appealid)) + print(f"New catalog entry for appeal card {appealid}") self.insert_catalog_entry( 'appealcard', appealid, @@ -2722,11 +2713,11 @@ class ImportSDVX(ImportBase): old_id = self.get_music_id_for_song(song.id, song.chart) if self.no_combine or old_id is None: # Insert original - print("New entry for {} chart {}".format(song.id, song.chart)) + print(f"New entry for {song.id} chart {song.chart}") next_id = self.get_next_music_id() else: # Insert pointing at same ID so scores transfer - print("Reused entry for {} chart {}".format(song.id, song.chart)) + print(f"Reused entry for {song.id} chart {song.chart}") next_id = old_id data = { 'limited': song.data.get_int('limited'), @@ -2742,14 +2733,14 @@ class ImportSDVX(ImportBase): self.start_batch() for item in game.get_items(self.game, self.version): if item.type == "appealcard": - print("New catalog entry for appeal card {}".format(item.id)) + print(f"New catalog entry for appeal card {item.id}") self.insert_catalog_entry( 'appealcard', item.id, {}, ) elif item.type == "song_unlock": - print("New catalog entry for {} chart {}".format(item.data.get_int('musicid'), item.data.get_int('chart'))) + print(f"New catalog entry for {item.data.get_int('musicid')} chart {item.data.get_int('chart')}") self.insert_catalog_entry( 'song_unlock', item.id, @@ -2829,11 +2820,11 @@ class ImportMuseca(ImportBase): old_id = self.get_music_id_for_song(songid, chart) if self.no_combine or old_id is None: # Insert original - print("New entry for {} chart {}".format(songid, chart)) + print(f"New entry for {songid} chart {chart}") next_id = self.get_next_music_id() else: # Insert pointing at same ID so scores transfer - print("Reused entry for {} chart {}".format(songid, chart)) + print(f"Reused entry for {songid} chart {chart}") next_id = old_id data = { 'limited': limited[chart], @@ -2874,11 +2865,11 @@ class ImportMuseca(ImportBase): old_id = self.get_music_id_for_song(song.id, song.chart) if self.no_combine or old_id is None: # Insert original - print("New entry for {} chart {}".format(song.id, song.chart)) + print(f"New entry for {song.id} chart {song.chart}") next_id = self.get_next_music_id() else: # Insert pointing at same ID so scores transfer - print("Reused entry for {} chart {}".format(song.id, song.chart)) + print(f"Reused entry for {song.id} chart {song.chart}") next_id = old_id data = { 'limited': song.data.get_int('limited'), @@ -3009,7 +3000,7 @@ class ImportReflecBeat(ImportBase): chart_length = 0x20 difficulties_offset = 0x1CC else: - raise Exception('Unsupported ReflecBeat version {}'.format(self.version)) + raise Exception(f'Unsupported ReflecBeat version {self.version}') def convert_string(inb: bytes) -> str: end = None @@ -3103,11 +3094,11 @@ class ImportReflecBeat(ImportBase): old_id = self.get_music_id_for_song_data(None, None, chartid, chart, version=0) if self.no_combine or old_id is None: # Insert original - print("New entry for {} chart {}".format(songid, chart)) + print(f"New entry for {songid} chart {chart}") next_id = self.get_next_music_id() else: # Insert pointing at same ID so scores transfer - print("Reused entry for {} chart {}".format(songid, chart)) + print(f"Reused entry for {songid} chart {chart}") next_id = old_id if old_id is None: # Add the virtual music entry we talked about above. Use the song ID when we discover @@ -3261,11 +3252,11 @@ class ImportDanceEvolution(ImportBase): old_id = self.get_music_id_for_song(song['id'], 0) if self.no_combine or old_id is None: # Insert original - print("New entry for {} chart {}".format(song['id'], 0)) + print(f"New entry for {song['id']} chart {0}") next_id = self.get_next_music_id() else: # Insert pointing at same ID so scores transfer - print("Reused entry for {} chart {}".format(song['id'], 0)) + print(f"Reused entry for {song['id']} chart {0}") next_id = old_id data = { 'level': song['level'], diff --git a/bemani/utils/replay.py b/bemani/utils/replay.py index 3cabc5b..8f2781b 100644 --- a/bemani/utils/replay.py +++ b/bemani/utils/replay.py @@ -35,14 +35,11 @@ class Protocol: elif packet_encoding == "binary": _packet_encoding = EAmuseProtocol.BINARY else: - raise Exception("Unknown packet encoding {}".format(packet_encoding)) + raise Exception(f"Unknown packet encoding {packet_encoding}") # Handle encryption if self.__encryption: - encryption = '1-{}-{}'.format( - hex_string(8), - hex_string(4), - ) + encryption = f'1-{hex_string(8)}-{hex_string(4)}' headers['X-Eamuse-Info'] = encryption else: encryption = None @@ -66,12 +63,7 @@ class Protocol: # Send the request, get the response r = requests.post( - 'http://{}:{}{}{}'.format( - self.__address, - self.__port, - '/' if uri[0] != '/' else '', - uri, - ), + f'http://{self.__address}:{self.__port}{"/" if uri[0] != "/" else ""}{uri}', headers=headers, data=req, ) @@ -112,7 +104,7 @@ def main() -> None: # Add an XML special node to force encoding (will be overwritten if there # is one in the packet). packet = b''.join([ - ''.format(args.encoding).encode(args.encoding), + f''.encode(args.encoding), packet, ]) @@ -134,12 +126,7 @@ def main() -> None: server = Protocol(args.address, args.port, False, False, False) server.exchange( - '{}?model={}&module={}&method={}'.format( - args.path, - model, - module, - method, - ), + f'{args.path}?model={model}&module={module}&method={method}', tree, ) diff --git a/bemani/utils/responsegen.py b/bemani/utils/responsegen.py index 9a6a75e..b713a06 100644 --- a/bemani/utils/responsegen.py +++ b/bemani/utils/responsegen.py @@ -12,10 +12,10 @@ def generate_node_name(node: Node, used_names: Dict[str, Node]) -> str: return potential_name loop = 1 - while '{}_{}'.format(potential_name, loop) in used_names: + while f'{potential_name}_{loop}' in used_names: loop = loop + 1 - potential_name = '{}_{}'.format(potential_name, loop) + potential_name = f'{potential_name}_{loop}' used_names[potential_name] = node return potential_name @@ -33,29 +33,20 @@ def generate_node_create(node: Node) -> str: else: method = dtype if node.is_array: - method = '{}_array'.format(method) + method = f'{method}_array' if dtype != 'void': # Format the type for display if dtype == 'str': - value = ', \'{}\''.format(node.value) + value = f', \'{node.value}\'' elif dtype == 'ip4': - value = ', \'{}.{}.{}.{}\''.format( - node.value[0], - node.value[1], - node.value[2], - node.value[3], - ) + value = f', \'{node.value[0]}.{node.value[1]}.{node.value[2]}.{node.value[3]}\'' else: - value = ', {}'.format(node.value) + value = f', {node.value}' else: value = '' - return 'Node.{}(\'{}\'{})'.format( - method, - node.name, - value - ) + return f'Node.{method}(\'{node.name}\'{value})' def generate_node_link(node_name: str, used_names: Dict[str, Node], parent: Node) -> str: @@ -67,12 +58,9 @@ def generate_node_link(node_name: str, used_names: Dict[str, Node], parent: Node break if found_parent is None: - raise Exception('Failed to find parent name for {}'.format(parent)) + raise Exception(f'Failed to find parent name for {parent}') - return '{}.add_child({})'.format( - found_parent, - node_name, - ) + return f'{found_parent}.add_child({node_name})' def generate_lines(node: Node, used_names: Dict[str, Node], parent: Optional[Node]=None) -> List[str]: @@ -85,7 +73,7 @@ def generate_lines(node: Node, used_names: Dict[str, Node], parent: Optional[Nod # Print the node generate itself out = [] node_name = generate_node_name(node, used_names) - out.append('{} = {}'.format(node_name, create)) + out.append(f'{node_name} = {create}') # Now, generate add to parent if exists if parent is not None: @@ -93,11 +81,7 @@ def generate_lines(node: Node, used_names: Dict[str, Node], parent: Optional[Nod # Now generate node attributes for attr in node.attributes: - out.append('{}.set_attribute(\'{}\', \'{}\')'.format( - node_name, - attr, - node.attributes[attr], - )) + out.append(f'{node_name}.set_attribute(\'{attr}\', \'{node.attributes[attr]}\')') # Now, do the same for all children for child in node.children: @@ -118,7 +102,7 @@ def generate_code(infile: str, outfile: str, encoding: str) -> None: # Add an XML special node to force encoding (will be overwritten if there # is one in the packet). packet = b''.join([ - ''.format(encoding).encode(encoding), + f''.encode(encoding), packet, ]) diff --git a/bemani/utils/trafficgen.py b/bemani/utils/trafficgen.py index 5e86ac6..ce97fb9 100644 --- a/bemani/utils/trafficgen.py +++ b/bemani/utils/trafficgen.py @@ -267,7 +267,7 @@ def get_client(proto: ClientProtocol, pcbid: str, game: str, config: Dict[str, A config, ) - raise Exception('Unknown game {}'.format(game)) + raise Exception(f'Unknown game {game}') def mainloop(address: str, port: int, configfile: str, action: str, game: str, cardid: Optional[str], verbose: bool) -> None: @@ -456,16 +456,16 @@ def mainloop(address: str, port: int, configfile: str, action: str, game: str, c } if action == 'list': for game in sorted([game for game in games]): - print('{} - {}'.format(game, games[game]['name'])) + print(f'{game} - {games[game]["name"]}') sys.exit(0) if action == 'game': if game not in games: - print('Unknown game {}'.format(game)) + print(f'Unknown game {game}') sys.exit(2) config = yaml.safe_load(open(configfile)) # type: ignore - print('Emulating {}'.format(games[game]['name'])) + print(f'Emulating {games[game]["name"]}') emu = get_client( ClientProtocol( address, diff --git a/bemani/utils/twodxutils.py b/bemani/utils/twodxutils.py index 84e9f63..7aaef42 100644 --- a/bemani/utils/twodxutils.py +++ b/bemani/utils/twodxutils.py @@ -45,7 +45,7 @@ def main() -> None: twodx = TwoDX(data) for fn in twodx.filenames: - print('Extracting {} to disk...'.format(fn)) + print(f'Extracting {fn} to disk...') realfn = os.path.join(root, fn) dirof = os.path.dirname(realfn) os.makedirs(dirof, exist_ok=True)