def _attempt_zip(s: str): unzip = all(char not in s for char in "|;,.") # O(4n) try: if unzip: return Coder.unzip(s) return Coder.zip(s) except Exception: return s
def _attempt_zip(string: str) -> str: unzip = all(char not in string for char in "|;,.") # O(m*n) try: if unzip: return Coder.unzip(string) return Coder.zip(string) except Exception: return string
async def upload_level( self, data: str, name: str, level_id: int, version: int, length: LevelLength, audio_track: int, desc: str, song_id: int, is_auto: bool, original: int, two_player: bool, objects: int, coins: int, stars: int, unlisted: bool, ldm: bool, password: Optional[Union[int, str]], copyable: bool, *, client: Client, ) -> int: data = Coder.zip(data) extra_string = "_".join(map(str, (0 for _ in range(55)))) desc = Coder.do_base64(desc) upload_seed = Coder.gen_level_upload_seed(data) seed2 = Coder.gen_chk(type="level", values=[upload_seed]) seed = Coder.gen_rs() pwd = 0 if copyable and password is None: pwd = 1 check, add = str(password), 1000000 if check.isdigit() and int(check) < add: pwd = add + int(password) payload = ( Params() .create_new() .put_definer("accountid", client.account_id) .put_definer("levelid", level_id) .put_definer("song", song_id) .put_seed(seed) .put_seed(seed2, suffix=2) .put_seed(0, prefix="wt") .put_seed(0, prefix="wt", suffix=2) .put_password(client.encodedpass) .put_username(client.name) .finish() ) options = { "level_name": name, "level_desc": desc, "level_version": version, "level_length": length.value, "audio_track": audio_track, "auto": int(is_auto), "original": int(original), "two_player": int(two_player), "objects": objects, "coins": coins, "requested_stars": stars, "unlisted": int(unlisted), "ldm": int(ldm), "password": pwd, "level_string": data, "extra_string": extra_string, "level_info": "H4sIAAAAAAAAC_NIrVQoyUgtStVRCMpPSi0qUbDStwYAsgpl1RUAAAA=", } payload_cased = { Converter.snake_to_camel(key): str(value) for key, value in options.items() } payload.update(payload_cased) level_id = await self.http.request(Route.UPLOAD_LEVEL, payload) if level_id == -1: raise MissingAccess("Failed to upload a level.") return level_id