diff --git a/bemani/backend/jubeat/prop.py b/bemani/backend/jubeat/prop.py index 63a783f..42483ca 100644 --- a/bemani/backend/jubeat/prop.py +++ b/bemani/backend/jubeat/prop.py @@ -168,7 +168,7 @@ class JubeatProp( return lut[rank] @classmethod - def __increment_class(cls, cur_class: int, cur_subclass: int) -> Tuple[int, int]: + def _increment_class(cls, cur_class: int, cur_subclass: int) -> Tuple[int, int]: """ Given a class and subclass, return a tuple representing the next class/subclass if we were to be promoted. @@ -176,7 +176,7 @@ class JubeatProp( return cls.__rank_to_class(cls.__class_to_rank(cur_class, cur_subclass) + 1) @classmethod - def __decrement_class(cls, cur_class: int, cur_subclass: int) -> Tuple[int, int]: + def _decrement_class(cls, cur_class: int, cur_subclass: int) -> Tuple[int, int]: """ Given a class and subclass, return a tuple representing the previous class/subclass if we were to be demoted. @@ -184,7 +184,7 @@ class JubeatProp( return cls.__rank_to_class(cls.__class_to_rank(cur_class, cur_subclass) - 1) @classmethod - def __get_league_buckets(cls, scores: List[Tuple[UserID, int]]) -> Tuple[List[UserID], List[UserID], List[UserID]]: + def _get_league_buckets(cls, scores: List[Tuple[UserID, int]]) -> Tuple[List[UserID], List[UserID], List[UserID]]: """ Given a list of userid, score tuples, return a tuple containing three lists. The first list is the top 30% scorer IDs, the next list is the middle 40% @@ -205,7 +205,7 @@ class JubeatProp( return (promotions, neutrals, demotions) @classmethod - def __get_league_scores(cls, data: Data, current_id: int, profiles: List[Tuple[UserID, ValidatedDict]]) -> Tuple[List[Tuple[UserID, int]], List[UserID]]: + def _get_league_scores(cls, data: Data, current_id: int, profiles: List[Tuple[UserID, ValidatedDict]]) -> Tuple[List[Tuple[UserID, int]], List[UserID]]: """ Given the current League ID (calculated based on the date range) and a list of all user profiles for this game/version, return a uple containing two lists. @@ -243,7 +243,7 @@ class JubeatProp( return scores, absentees @classmethod - def __get_league_absentees(cls, data: Data, current_id: int, absentees: List[UserID]) -> List[UserID]: + def _get_league_absentees(cls, data: Data, current_id: int, absentees: List[UserID]) -> List[UserID]: """ Given a list of user IDs that didn't play for some number of weeks, return a subset of those IDs that have been absent enough weeks to get a demotion. @@ -277,7 +277,7 @@ class JubeatProp( return delinquents @classmethod - def __modify_profile(cls, data: Data, userid: UserID, direction: str) -> None: + def _modify_profile(cls, data: Data, userid: UserID, direction: str) -> None: """ Given a user ID and a direction (promote or demote), load the user's profile, make the necessary promotion/demotion, and set the profile to notify the user @@ -290,9 +290,9 @@ class JubeatProp( cur_subclass = profile.get_int('league_subclass', 5) if direction == 'promote': - new_class, new_subclass = cls.__increment_class(cur_class, cur_subclass) + new_class, new_subclass = cls._increment_class(cur_class, cur_subclass) elif direction == 'demote': - new_class, new_subclass = cls.__decrement_class(cur_class, cur_subclass) + new_class, new_subclass = cls._decrement_class(cur_class, cur_subclass) else: raise Exception(f'Logic error, unknown direction {direction}!') @@ -344,17 +344,17 @@ class JubeatProp( # Evaluate player scores on previous courses and find players # that didn't play last week. all_profiles = data.local.user.get_all_profiles(cls.game, cls.version) - scores, absentees = cls.__get_league_scores(data, leagueid, all_profiles) + scores, absentees = cls._get_league_scores(data, leagueid, all_profiles) # Get user IDs to promote, demote and ignore based on scores. - promote, ignore, demote = cls.__get_league_buckets(scores) - demote.extend(cls.__get_league_absentees(data, leagueid, absentees)) + promote, ignore, demote = cls._get_league_buckets(scores) + demote.extend(cls._get_league_absentees(data, leagueid, absentees)) # Actually modify the profiles so the game knows to tell the user. for userid in promote: - cls.__modify_profile(data, userid, 'promote') + cls._modify_profile(data, userid, 'promote') for userid in demote: - cls.__modify_profile(data, userid, 'demote') + cls._modify_profile(data, userid, 'demote') # Mark that we did some actual work here. data.local.network.mark_scheduled(cls.game, cls.version, 'league_course', 'weekly') diff --git a/bemani/data/api/client.py b/bemani/data/api/client.py index 2fe4286..5a9f6ea 100644 --- a/bemani/data/api/client.py +++ b/bemani/data/api/client.py @@ -42,7 +42,7 @@ class APIClient: self.allow_stats = allow_stats self.allow_scores = allow_scores - def __content_type_valid(self, content_type: str) -> bool: + def _content_type_valid(self, content_type: str) -> bool: if ';' in content_type: left, right = content_type.split(';', 1) left = left.strip().lower() @@ -83,7 +83,7 @@ class APIClient: raise APIException('Failed to query remote server!') # Verify that content type is in the form of "application/json; charset=utf-8". - if not self.__content_type_valid(r.headers['content-type']): + if not self._content_type_valid(r.headers['content-type']): raise APIException(f'API returned invalid content type \'{r.headers["content-type"]}\'!') jsondata = r.json() diff --git a/bemani/format/afp/decompile.py b/bemani/format/afp/decompile.py index e7d78b3..759be17 100644 --- a/bemani/format/afp/decompile.py +++ b/bemani/format/afp/decompile.py @@ -434,7 +434,7 @@ class ByteCodeDecompiler(VerboseOutput): raise Exception("Call decompile() first before retrieving statements!") return self.__statements - def __graph_control_flow(self, bytecode: ByteCode) -> Tuple[List[ByteCodeChunk], Dict[int, int]]: + def _graph_control_flow(self, bytecode: ByteCode) -> Tuple[List[ByteCodeChunk], Dict[int, int]]: # Start by assuming that the whole bytecode never directs flow. This is, confusingly, # indexed by AP2Action offset, not by actual bytecode offset, so we can avoid the # prickly problem of opcodes that take more than one byte in the data. @@ -3239,7 +3239,7 @@ class ByteCodeDecompiler(VerboseOutput): def __decompile(self) -> None: # First, we need to construct a control flow graph. self.vprint("Generating control flow graph...") - chunks, offset_map = self.__graph_control_flow(self.bytecode) + chunks, offset_map = self._graph_control_flow(self.bytecode) if self.bytecode.start_offset is None: raise Exception("Logic error, we should not be decompiling empty bytecode!") start_id = offset_map[self.bytecode.start_offset] diff --git a/bemani/tests/test_APIClient.py b/bemani/tests/test_APIClient.py index ab88293..bb1ec08 100644 --- a/bemani/tests/test_APIClient.py +++ b/bemani/tests/test_APIClient.py @@ -8,14 +8,14 @@ class TestAPIClient(unittest.TestCase): def test_content_type(self) -> None: client = APIClient('https://127.0.0.1', 'token', False, False) - self.assertFalse(client._APIClient__content_type_valid('application/text')) - self.assertFalse(client._APIClient__content_type_valid('application/json')) - self.assertFalse(client._APIClient__content_type_valid('application/json; charset=shift-jis')) - self.assertTrue(client._APIClient__content_type_valid('application/json; charset=utf-8')) - self.assertTrue(client._APIClient__content_type_valid('application/json;charset=utf-8')) - self.assertTrue(client._APIClient__content_type_valid('application/json;charset = utf-8')) - self.assertTrue(client._APIClient__content_type_valid('application/json; charset = utf-8')) - self.assertTrue(client._APIClient__content_type_valid('application/json; charset=UTF-8')) - self.assertTrue(client._APIClient__content_type_valid('application/json;charset=UTF-8')) - self.assertTrue(client._APIClient__content_type_valid('application/json;charset = UTF-8')) - self.assertTrue(client._APIClient__content_type_valid('application/json; charset = UTF-8')) + self.assertFalse(client._content_type_valid('application/text')) + self.assertFalse(client._content_type_valid('application/json')) + self.assertFalse(client._content_type_valid('application/json; charset=shift-jis')) + self.assertTrue(client._content_type_valid('application/json; charset=utf-8')) + self.assertTrue(client._content_type_valid('application/json;charset=utf-8')) + self.assertTrue(client._content_type_valid('application/json;charset = utf-8')) + self.assertTrue(client._content_type_valid('application/json; charset = utf-8')) + self.assertTrue(client._content_type_valid('application/json; charset=UTF-8')) + self.assertTrue(client._content_type_valid('application/json;charset=UTF-8')) + self.assertTrue(client._content_type_valid('application/json;charset = UTF-8')) + self.assertTrue(client._content_type_valid('application/json; charset = UTF-8')) diff --git a/bemani/tests/test_JubeatProp.py b/bemani/tests/test_JubeatProp.py index 3a56eb0..5b97497 100644 --- a/bemani/tests/test_JubeatProp.py +++ b/bemani/tests/test_JubeatProp.py @@ -11,40 +11,40 @@ class TestJubeatProp(unittest.TestCase): def test_increment_class(self) -> None: # Verify normal increase - self.assertEqual(JubeatProp._JubeatProp__increment_class(1, 5), (1, 4)) - self.assertEqual(JubeatProp._JubeatProp__increment_class(1, 4), (1, 3)) - self.assertEqual(JubeatProp._JubeatProp__increment_class(3, 3), (3, 2)) + self.assertEqual(JubeatProp._increment_class(1, 5), (1, 4)) + self.assertEqual(JubeatProp._increment_class(1, 4), (1, 3)) + self.assertEqual(JubeatProp._increment_class(3, 3), (3, 2)) # Verify bumping class when minor class is at max - self.assertEqual(JubeatProp._JubeatProp__increment_class(1, 1), (2, 5)) - self.assertEqual(JubeatProp._JubeatProp__increment_class(2, 1), (3, 5)) + self.assertEqual(JubeatProp._increment_class(1, 1), (2, 5)) + self.assertEqual(JubeatProp._increment_class(2, 1), (3, 5)) # Verify bumping class to legend which only has one subclass - self.assertEqual(JubeatProp._JubeatProp__increment_class(3, 1), (4, 1)) + self.assertEqual(JubeatProp._increment_class(3, 1), (4, 1)) # Verify bumping when already at max - self.assertEqual(JubeatProp._JubeatProp__increment_class(4, 1), (4, 1)) + self.assertEqual(JubeatProp._increment_class(4, 1), (4, 1)) def test_decrement_class(self) -> None: # Verify normal decrease - self.assertEqual(JubeatProp._JubeatProp__decrement_class(1, 3), (1, 4)) - self.assertEqual(JubeatProp._JubeatProp__decrement_class(1, 4), (1, 5)) - self.assertEqual(JubeatProp._JubeatProp__decrement_class(3, 2), (3, 3)) + self.assertEqual(JubeatProp._decrement_class(1, 3), (1, 4)) + self.assertEqual(JubeatProp._decrement_class(1, 4), (1, 5)) + self.assertEqual(JubeatProp._decrement_class(3, 2), (3, 3)) # Verify demoting class when minor class is at min - self.assertEqual(JubeatProp._JubeatProp__decrement_class(2, 5), (1, 1)) - self.assertEqual(JubeatProp._JubeatProp__decrement_class(3, 5), (2, 1)) + self.assertEqual(JubeatProp._decrement_class(2, 5), (1, 1)) + self.assertEqual(JubeatProp._decrement_class(3, 5), (2, 1)) # Verify demoting class when starting at legend - self.assertEqual(JubeatProp._JubeatProp__decrement_class(4, 1), (3, 1)) + self.assertEqual(JubeatProp._decrement_class(4, 1), (3, 1)) # Verify decrease when already at min - self.assertEqual(JubeatProp._JubeatProp__decrement_class(1, 5), (1, 5)) + self.assertEqual(JubeatProp._decrement_class(1, 5), (1, 5)) def test_get_league_buckets(self) -> None: # Verify correct behavior with empty input self.assertEqual( - JubeatProp._JubeatProp__get_league_buckets( + JubeatProp._get_league_buckets( [], ), ( @@ -56,7 +56,7 @@ class TestJubeatProp(unittest.TestCase): # Verify correct behavior with only one entrant (should be promoted) self.assertEqual( - JubeatProp._JubeatProp__get_league_buckets( + JubeatProp._get_league_buckets( [ (5, 12345), ], @@ -72,7 +72,7 @@ class TestJubeatProp(unittest.TestCase): # Verify correct behavior with two entrants (should be one promotion, one demotion) self.assertEqual( - JubeatProp._JubeatProp__get_league_buckets( + JubeatProp._get_league_buckets( [ (5, 12345), (7, 54321), @@ -91,7 +91,7 @@ class TestJubeatProp(unittest.TestCase): # Verify correct behavior with three entrants (should be one promotion, one demotion, one same) self.assertEqual( - JubeatProp._JubeatProp__get_league_buckets( + JubeatProp._get_league_buckets( [ (5, 12345), (7, 54321), @@ -113,7 +113,7 @@ class TestJubeatProp(unittest.TestCase): # Verify correct behavior with ten entrants (should be 3 promotions, 3 demotions, 4 same) self.assertEqual( - JubeatProp._JubeatProp__get_league_buckets( + JubeatProp._get_league_buckets( [ (5, 55555), (7, 77777), @@ -154,7 +154,7 @@ class TestJubeatProp(unittest.TestCase): # Test correct behavior on empty input self.assertEqual( - JubeatProp._JubeatProp__get_league_scores( + JubeatProp._get_league_scores( None, 999, [] @@ -168,7 +168,7 @@ class TestJubeatProp(unittest.TestCase): # Test that we can load last week's score if it exists for a user data.local.user.get_achievement = Mock(return_value={'score': [123, 456, 789]}) self.assertEqual( - JubeatProp._JubeatProp__get_league_scores( + JubeatProp._get_league_scores( data, 999, [(UserID(1337), {})], @@ -190,7 +190,7 @@ class TestJubeatProp(unittest.TestCase): # Test that if it doesn't exist last week they get marked as absent data.local.user.get_achievement = Mock(return_value=None) self.assertEqual( - JubeatProp._JubeatProp__get_league_scores( + JubeatProp._get_league_scores( data, 999, [(UserID(1337), {})], @@ -216,7 +216,7 @@ class TestJubeatProp(unittest.TestCase): # Test that we do the right thing with empty input self.assertEqual( - JubeatProp._JubeatProp__get_league_absentees( + JubeatProp._get_league_absentees( None, 999, [], @@ -227,7 +227,7 @@ class TestJubeatProp(unittest.TestCase): # Test that a user who never played doesn't get flagged absentee data.local.user.get_achievements = Mock(return_value=[]) self.assertEqual( - JubeatProp._JubeatProp__get_league_absentees( + JubeatProp._get_league_absentees( data, 999, [1337], @@ -246,7 +246,7 @@ class TestJubeatProp(unittest.TestCase): Achievement(997, 'league', None, {}), ]) self.assertEqual( - JubeatProp._JubeatProp__get_league_absentees( + JubeatProp._get_league_absentees( data, 999, [1337], @@ -265,7 +265,7 @@ class TestJubeatProp(unittest.TestCase): Achievement(996, 'league', None, {}), ]) self.assertEqual( - JubeatProp._JubeatProp__get_league_absentees( + JubeatProp._get_league_absentees( data, 999, [1337], @@ -285,7 +285,7 @@ class TestJubeatProp(unittest.TestCase): Achievement(995, 'league', None, {}), ]) self.assertEqual( - JubeatProp._JubeatProp__get_league_absentees( + JubeatProp._get_league_absentees( data, 999, [1337], @@ -304,7 +304,7 @@ class TestJubeatProp(unittest.TestCase): Achievement(994, 'league', None, {}), ]) self.assertEqual( - JubeatProp._JubeatProp__get_league_absentees( + JubeatProp._get_league_absentees( data, 999, [1337], @@ -328,7 +328,7 @@ class TestJubeatProp(unittest.TestCase): 'league_class': 1, 'league_subclass': 5, })) - JubeatProp._JubeatProp__modify_profile( + JubeatProp._modify_profile( data, 1337, 'demote', @@ -340,7 +340,7 @@ class TestJubeatProp(unittest.TestCase): 'league_class': 4, 'league_subclass': 1, })) - JubeatProp._JubeatProp__modify_profile( + JubeatProp._modify_profile( data, 1337, 'promote', @@ -353,7 +353,7 @@ class TestJubeatProp(unittest.TestCase): 'league_subclass': 5, 'league_is_checked': True, })) - JubeatProp._JubeatProp__modify_profile( + JubeatProp._modify_profile( data, 1337, 'promote', @@ -380,7 +380,7 @@ class TestJubeatProp(unittest.TestCase): 'league_subclass': 3, 'league_is_checked': True, })) - JubeatProp._JubeatProp__modify_profile( + JubeatProp._modify_profile( data, 1337, 'demote', @@ -411,7 +411,7 @@ class TestJubeatProp(unittest.TestCase): 'league_subclass': 3, }, })) - JubeatProp._JubeatProp__modify_profile( + JubeatProp._modify_profile( data, 1337, 'demote', diff --git a/bemani/tests/test_afp_decompile.py b/bemani/tests/test_afp_decompile.py index 44793ee..33b5aff 100644 --- a/bemani/tests/test_afp_decompile.py +++ b/bemani/tests/test_afp_decompile.py @@ -130,7 +130,7 @@ class TestAFPControlGraph(ExtendedTestCase): bcd = ByteCodeDecompiler(bytecode, optimize=True) # Call it, return the data in an easier to test fashion. - chunks, offset_map = bcd._ByteCodeDecompiler__graph_control_flow(bytecode) + chunks, offset_map = bcd._graph_control_flow(bytecode) return {chunk.id: chunk for chunk in chunks}, offset_map def __equiv(self, bytecode: Union[ByteCode, ByteCodeChunk, List[AP2Action]]) -> List[str]: