implement dict.get()

This commit is contained in:
Hay1tsme 2023-03-09 12:17:10 -05:00
parent dafc030050
commit e9ffd95435
3 changed files with 34 additions and 45 deletions

View File

@ -346,20 +346,16 @@ class AllnetPowerOnRequest:
def __init__(self, req: Dict) -> None: def __init__(self, req: Dict) -> None:
if req is None: if req is None:
raise AllnetRequestException("Request processing failed") raise AllnetRequestException("Request processing failed")
self.game_id: str = req["game_id"] if "game_id" in req else "" self.game_id: str = req.get("game_id", "")
self.ver: str = req["ver"] if "ver" in req else "" self.ver: str = req.get("ver", "")
self.serial: str = req["serial"] if "serial" in req else "" self.serial: str = req.get("serial", "")
self.ip: str = req["ip"] if "ip" in req else "" self.ip: str = req.get("ip", "")
self.firm_ver: str = req["firm_ver"] if "firm_ver" in req else "" self.firm_ver: str = req.get("firm_ver", "")
self.boot_ver: str = req["boot_ver"] if "boot_ver" in req else "" self.boot_ver: str = req.get("boot_ver", "")
self.encode: str = req["encode"] if "encode" in req else "" self.encode: str = req.get("encode", "")
self.hops = int(req.get("hops", "0"))
try: self.format_ver = int(req.get("hops", "2"))
self.hops = int(req["hops"]) if "hops" in req else 0 self.token = int(req.get("hops", "0"))
self.format_ver = int(req["format_ver"]) if "format_ver" in req else 2
self.token = int(req["token"]) if "token" in req else 0
except ValueError as e:
raise AllnetRequestException(f"Failed to parse int: {e}")
class AllnetPowerOnResponse3: class AllnetPowerOnResponse3:
@ -413,10 +409,10 @@ class AllnetPowerOnResponse2:
class AllnetDownloadOrderRequest: class AllnetDownloadOrderRequest:
def __init__(self, req: Dict) -> None: def __init__(self, req: Dict) -> None:
self.game_id = req["game_id"] if "game_id" in req else "" self.game_id = req.get("game_id", "")
self.ver = req["ver"] if "ver" in req else "" self.ver = req.get("ver", "")
self.serial = req["serial"] if "serial" in req else "" self.serial = req.get("serial", "")
self.encode = req["encode"] if "encode" in req else "" self.encode = req.get("encode", "")
class AllnetDownloadOrderResponse: class AllnetDownloadOrderResponse:

View File

@ -132,24 +132,19 @@ class MuchaServlet:
class MuchaAuthRequest: class MuchaAuthRequest:
def __init__(self, request: Dict) -> None: def __init__(self, request: Dict) -> None:
self.gameVer = ( # gameCd + boardType + countryCd + version
"" if "gameVer" not in request else request["gameVer"] self.gameVer = request.get("gameVer", "")
) # gameCd + boardType + countryCd + version self.sendDate = request.get("sendDate", "") # %Y%m%d
self.sendDate = ( self.serialNum = request.get("serialNum", "")
"" if "sendDate" not in request else request["sendDate"] self.gameCd = request.get("gameCd", "")
) # %Y%m%d self.boardType = request.get("boardType", "")
self.serialNum = "" if "serialNum" not in request else request["serialNum"] self.boardId = request.get("boardId", "")
self.gameCd = "" if "gameCd" not in request else request["gameCd"] self.mac = request.get("mac", "")
self.boardType = "" if "boardType" not in request else request["boardType"] self.placeId = request.get("placeId", "")
self.boardId = "" if "boardId" not in request else request["boardId"] self.storeRouterIp = request.get("storeRouterIp", "")
self.mac = "" if "mac" not in request else request["mac"] self.countryCd = request.get("countryCd", "")
self.placeId = "" if "placeId" not in request else request["placeId"] self.useToken = request.get("useToken", "")
self.storeRouterIp = ( self.allToken = request.get("allToken", "")
"" if "storeRouterIp" not in request else request["storeRouterIp"]
)
self.countryCd = "" if "countryCd" not in request else request["countryCd"]
self.useToken = "" if "useToken" not in request else request["useToken"]
self.allToken = "" if "allToken" not in request else request["allToken"]
class MuchaAuthResponse: class MuchaAuthResponse:
@ -199,14 +194,12 @@ class MuchaAuthResponse:
class MuchaUpdateRequest: class MuchaUpdateRequest:
def __init__(self, request: Dict) -> None: def __init__(self, request: Dict) -> None:
self.gameVer = "" if "gameVer" not in request else request["gameVer"] self.gameVer = request.get("gameVer", "")
self.gameCd = "" if "gameCd" not in request else request["gameCd"] self.gameCd = request.get("gameCd", "")
self.serialNum = "" if "serialNum" not in request else request["serialNum"] self.serialNum = request.get("serialNum", "")
self.countryCd = "" if "countryCd" not in request else request["countryCd"] self.countryCd = request.get("countryCd", "")
self.placeId = "" if "placeId" not in request else request["placeId"] self.placeId = request.get("placeId", "")
self.storeRouterIp = ( self.storeRouterIp = request.get("storeRouterIp", "")
"" if "storeRouterIp" not in request else request["storeRouterIp"]
)
class MuchaUpdateResponse: class MuchaUpdateResponse:

View File

@ -298,6 +298,6 @@ class DivaReader(BaseReader):
tree[key] = ( tree[key] = (
value value
if len(vector) == 1 if len(vector) == 1
else self.add_branch(tree[key] if key in tree else {}, vector[1:], value) else self.add_branch(tree.get(key, {}), vector[1:], value)
) )
return tree return tree