Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to add conditional fix for those on Windows running python ~3.x.x #196

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions pyflp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ def parse(file: pathlib.Path | str) -> Project:
stream.seek(22) # Back to start of events
while stream.tell() < file_size:
event_type: type[AnyEvent] | None = None
id = EventEnum(int.from_bytes(stream.read(1), "little"))

# Conditional fix for Windows with Python 3.13+
if platform.system() == "Windows" and sys.version_info >= (3, 13):
id = int.from_bytes(stream.read(1)) # Workaround for affected environments
else:
id = EventEnum(int.from_bytes(stream.read(1), "little")) # Default behavior
if id < WORD:
value = stream.read(1)
elif id < DWORD:
Expand Down Expand Up @@ -151,9 +154,16 @@ def parse(file: pathlib.Path | str) -> Project:
event_type = U16Event
elif id < TEXT:
event_type = U32Event
elif id < DATA or id.value in NEW_TEXT_IDS:
if str_type is None: # pragma: no cover
raise VersionNotDetected # ! This should never happen
# Conditional fix for Windows with Python 3.13+
elif platform.system() == "Windows" and sys.version_info >= (3, 13):
if id < DATA or id in NEW_TEXT_IDS: # Workaround for affected environments
if str_type is None: # pragma: no cover
raise VersionNotDetected # ! This should never happen
event_type = str_type
# Default behavior for unaffected users
elif id < DATA or id.value in NEW_TEXT_IDS: # Original logic retained
if str_type is None: # pragma: no cover
raise VersionNotDetected # ! This should never happen
event_type = str_type

if id == PluginID.InternalName:
Expand Down
6 changes: 5 additions & 1 deletion pyflp/_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ def __init__(self, id: EventEnum, data: bytes, **kwds: Any) -> None:
if len(data) != expected_size:
raise InvalidEventChunkSize(expected_size, len(data))

self.id = EventEnum(id)
# Conditional fix for Windows with Python 3.13+
if platform.system() == "Windows" and sys.version_info >= (3, 13):
self.id = id # Apply workaround for affected environments
else:
self.id = EventEnum(id) # Default behavior for unaffected environments
self._kwds = kwds
self.value = self.STRUCT.parse(data, **self._kwds)

Expand Down