mirror of
https://github.com/a2-4am/wozardry.git
synced 2024-12-12 17:29:14 +00:00
support setting creator (regression) and refactor creator validation
This commit is contained in:
parent
4145d18e5b
commit
17b850c54c
12
wozardry.py
12
wozardry.py
@ -12,7 +12,7 @@ import itertools
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
__version__ = "2.0-alpha" # https://semver.org
|
__version__ = "2.0-alpha" # https://semver.org
|
||||||
__date__ = "2019-02-15"
|
__date__ = "2019-02-17"
|
||||||
__progname__ = "wozardry"
|
__progname__ = "wozardry"
|
||||||
__displayname__ = __progname__ + " " + __version__ + " by 4am (" + __date__ + ")"
|
__displayname__ = __progname__ + " " + __version__ + " by 4am (" + __date__ + ")"
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ class WozValidator:
|
|||||||
def validate_info_creator(self, creator_as_bytes):
|
def validate_info_creator(self, creator_as_bytes):
|
||||||
raise_if(len(creator_as_bytes) > 32, WozINFOFormatError_BadCreator, "Creator is longer than 32 bytes")
|
raise_if(len(creator_as_bytes) > 32, WozINFOFormatError_BadCreator, "Creator is longer than 32 bytes")
|
||||||
try:
|
try:
|
||||||
creator_as_bytes.decode("UTF-8")
|
return creator_as_bytes.decode("UTF-8").strip()
|
||||||
except:
|
except:
|
||||||
raise_if(True, WozINFOFormatError_BadCreator, "Creator is not valid UTF-8")
|
raise_if(True, WozINFOFormatError_BadCreator, "Creator is not valid UTF-8")
|
||||||
|
|
||||||
@ -287,10 +287,6 @@ class WozValidator:
|
|||||||
self.validate_info_creator(creator_as_bytes)
|
self.validate_info_creator(creator_as_bytes)
|
||||||
return creator_as_bytes
|
return creator_as_bytes
|
||||||
|
|
||||||
def decode_info_creator(self, creator_as_bytes):
|
|
||||||
self.validate_info_creator(creator_as_bytes)
|
|
||||||
return creator_as_bytes.decode("UTF-8").strip()
|
|
||||||
|
|
||||||
def validate_info_disk_sides(self, disk_sides):
|
def validate_info_disk_sides(self, disk_sides):
|
||||||
"""|disk_sides| can be str, bytes, or int. returns same value as int"""
|
"""|disk_sides| can be str, bytes, or int. returns same value as int"""
|
||||||
# assumes WOZ version 2 or later
|
# assumes WOZ version 2 or later
|
||||||
@ -402,7 +398,7 @@ class WozReader(WozDiskImage, WozValidator):
|
|||||||
self.info["write_protected"] = self.validate_info_write_protected(data[2]) # boolean
|
self.info["write_protected"] = self.validate_info_write_protected(data[2]) # boolean
|
||||||
self.info["synchronized"] = self.validate_info_synchronized(data[3]) # boolean
|
self.info["synchronized"] = self.validate_info_synchronized(data[3]) # boolean
|
||||||
self.info["cleaned"] = self.validate_info_cleaned(data[4]) # boolean
|
self.info["cleaned"] = self.validate_info_cleaned(data[4]) # boolean
|
||||||
self.info["creator"] = self.decode_info_creator(data[5:37]) # string
|
self.info["creator"] = self.validate_info_creator(data[5:37]) # string
|
||||||
if self.info["version"] >= 2:
|
if self.info["version"] >= 2:
|
||||||
self.info["disk_sides"] = self.validate_info_disk_sides(data[37]) # int
|
self.info["disk_sides"] = self.validate_info_disk_sides(data[37]) # int
|
||||||
self.info["boot_sector_format"] = self.validate_info_boot_sector_format(data[38]) # int
|
self.info["boot_sector_format"] = self.validate_info_boot_sector_format(data[38]) # int
|
||||||
@ -875,6 +871,8 @@ requires_machine, notes, side, side_name, contributor, image_date. Other keys ar
|
|||||||
self.output.info[k] = self.output.validate_info_synchronized(v)
|
self.output.info[k] = self.output.validate_info_synchronized(v)
|
||||||
elif k == "cleaned":
|
elif k == "cleaned":
|
||||||
self.output.info[k] = self.output.validate_info_cleaned(v)
|
self.output.info[k] = self.output.validate_info_cleaned(v)
|
||||||
|
elif k == "creator":
|
||||||
|
self.output.info[k] = self.output.validate_info_creator(self.output.encode_info_creator(v))
|
||||||
if self.output.info["version"] == 1: continue
|
if self.output.info["version"] == 1: continue
|
||||||
|
|
||||||
# remaining fields are only recognized in WOZ2 files (v2+ INFO chunk)
|
# remaining fields are only recognized in WOZ2 files (v2+ INFO chunk)
|
||||||
|
Loading…
Reference in New Issue
Block a user