WebHost: fix is_zipfile check for flask FileStorage objects

- and assorted cleanup
This commit is contained in:
Fabian Dill 2022-01-06 06:09:15 +01:00
parent a6a9989fcf
commit 80b3a5b1d4
7 changed files with 15 additions and 17 deletions

View File

@ -782,10 +782,9 @@ class RegionType(int, Enum):
class Region(object): class Region(object):
def __init__(self, name: str, type_: RegionType, hint, player: int, world: Optional[MultiWorld] = None):
def __init__(self, name: str, type: str, hint, player: int, world: Optional[MultiWorld] = None):
self.name = name self.name = name
self.type = type self.type = type_
self.entrances = [] self.entrances = []
self.exits = [] self.exits = []
self.locations = [] self.locations = []

View File

@ -100,7 +100,7 @@ def uploads():
if file.filename == '': if file.filename == '':
flash('No selected file') flash('No selected file')
elif file and allowed_file(file.filename): elif file and allowed_file(file.filename):
if zipfile.is_zipfile(file.filename): if zipfile.is_zipfile(file):
with zipfile.ZipFile(file, 'r') as zfile: with zipfile.ZipFile(file, 'r') as zfile:
res = upload_zip_to_db(zfile) res = upload_zip_to_db(zfile)
if type(res) == str: if type(res) == str:

View File

@ -9,6 +9,7 @@ Utils.local_path.cached_path = file_path
from BaseClasses import MultiWorld, CollectionState from BaseClasses import MultiWorld, CollectionState
from worlds.alttp.Items import ItemFactory from worlds.alttp.Items import ItemFactory
class TestBase(unittest.TestCase): class TestBase(unittest.TestCase):
world: MultiWorld world: MultiWorld
_state_cache = {} _state_cache = {}

View File

View File

@ -1,4 +1,4 @@
from typing import NamedTuple from typing import NamedTuple, List
import unittest import unittest
from worlds.AutoWorld import World from worlds.AutoWorld import World
from Fill import FillError, fill_restrictive from Fill import FillError, fill_restrictive
@ -28,8 +28,8 @@ def generate_multi_world(players: int = 1) -> MultiWorld:
class PlayerDefinition(NamedTuple): class PlayerDefinition(NamedTuple):
id: int id: int
menu: Region menu: Region
locations: list[Location] locations: List[Location]
prog_items: list[Item] prog_items: List[Item]
def generate_player_data(multi_world: MultiWorld, player_id: int, location_count: int, prog_item_count: int) -> PlayerDefinition: def generate_player_data(multi_world: MultiWorld, player_id: int, location_count: int, prog_item_count: int) -> PlayerDefinition:
@ -40,7 +40,7 @@ def generate_player_data(multi_world: MultiWorld, player_id: int, location_count
return PlayerDefinition(player_id, menu, locations, prog_items) return PlayerDefinition(player_id, menu, locations, prog_items)
def generate_locations(count: int, player_id: int, address: int = None, region: Region = None) -> list[Location]: def generate_locations(count: int, player_id: int, address: int = None, region: Region = None) -> List[Location]:
locations = [] locations = []
for i in range(count): for i in range(count):
name = "player" + str(player_id) + "_location" + str(i) name = "player" + str(player_id) + "_location" + str(i)
@ -50,7 +50,7 @@ def generate_locations(count: int, player_id: int, address: int = None, region:
return locations return locations
def generate_items(count: int, player_id: int, advancement: bool = False, code: int = None) -> list[Location]: def generate_items(count: int, player_id: int, advancement: bool = False, code: int = None) -> List[Item]:
items = [] items = []
for i in range(count): for i in range(count):
name = "player" + str(player_id) + "_item" + str(i) name = "player" + str(player_id) + "_item" + str(i)

View File

@ -4,15 +4,15 @@ from BaseClasses import MultiWorld
from worlds.alttp.Dungeons import create_dungeons, get_dungeon_item_pool from worlds.alttp.Dungeons import create_dungeons, get_dungeon_item_pool
from worlds.alttp.EntranceShuffle import link_entrances from worlds.alttp.EntranceShuffle import link_entrances
from worlds.alttp.InvertedRegions import mark_dark_world_regions from worlds.alttp.InvertedRegions import mark_dark_world_regions
from worlds.alttp.ItemPool import difficulties, generate_itempool from worlds.alttp.ItemPool import difficulties
from worlds.alttp.Items import ItemFactory from worlds.alttp.Items import ItemFactory
from worlds.alttp.Regions import create_regions from worlds.alttp.Regions import create_regions
from worlds.alttp.Shops import create_shops from worlds.alttp.Shops import create_shops
from worlds.alttp.Rules import set_rules
from test.TestBase import TestBase from test.TestBase import TestBase
from worlds import AutoWorld from worlds import AutoWorld
class TestMinor(TestBase): class TestMinor(TestBase):
def setUp(self): def setUp(self):
self.world = MultiWorld(1) self.world = MultiWorld(1)
@ -30,7 +30,9 @@ class TestMinor(TestBase):
self.world.worlds[1].create_items() self.world.worlds[1].create_items()
self.world.required_medallions[1] = ['Ether', 'Quake'] self.world.required_medallions[1] = ['Ether', 'Quake']
self.world.itempool.extend(get_dungeon_item_pool(self.world)) self.world.itempool.extend(get_dungeon_item_pool(self.world))
self.world.itempool.extend(ItemFactory(['Green Pendant', 'Red Pendant', 'Blue Pendant', 'Beat Agahnim 1', 'Beat Agahnim 2', 'Crystal 1', 'Crystal 2', 'Crystal 3', 'Crystal 4', 'Crystal 5', 'Crystal 6', 'Crystal 7'], 1)) self.world.itempool.extend(ItemFactory(
['Green Pendant', 'Red Pendant', 'Blue Pendant', 'Beat Agahnim 1', 'Beat Agahnim 2', 'Crystal 1',
'Crystal 2', 'Crystal 3', 'Crystal 4', 'Crystal 5', 'Crystal 6', 'Crystal 7'], 1))
self.world.get_location('Agahnim 1', 1).item = None self.world.get_location('Agahnim 1', 1).item = None
self.world.get_location('Agahnim 2', 1).item = None self.world.get_location('Agahnim 2', 1).item = None
mark_dark_world_regions(self.world, 1) mark_dark_world_regions(self.world, 1)

View File

@ -68,16 +68,12 @@ class HKWorld(World):
self.world.itempool += pool self.world.itempool += pool
def set_rules(self): def set_rules(self):
set_rules(self.world, self.player) set_rules(self.world, self.player)
def create_regions(self): def create_regions(self):
create_regions(self.world, self.player) create_regions(self.world, self.player)
def generate_output(self):
pass # Hollow Knight needs no output files
def fill_slot_data(self): def fill_slot_data(self):
slot_data = {} slot_data = {}
for option_name in self.options: for option_name in self.options: