Handle the possibility of bytes in watchdog 5.0

This commit is contained in:
Masen Furer 2024-08-29 16:00:07 -07:00
parent 4fcfa1103b
commit 4969df2dc2
No known key found for this signature in database
GPG Key ID: B0008AD22B3B3A95

View File

@ -1,5 +1,7 @@
"""General utility functions."""
from __future__ import annotations
import contextlib
import os
import shutil
@ -81,7 +83,7 @@ class AssetFolderHandler(FileSystemEventHandler):
if os.path.exists(dest_path):
shutil.rmtree(dest_path)
def get_dest_path(self, src_path: str) -> str:
def get_dest_path(self, src_path: str | bytes) -> str:
"""Get public file path.
Args:
@ -90,6 +92,10 @@ class AssetFolderHandler(FileSystemEventHandler):
Returns:
The public file path.
"""
if isinstance(src_path, (bytes, bytearray)):
src_path = src_path.decode()
elif isinstance(src_path, memoryview):
src_path = src_path.tobytes().decode()
return src_path.replace(
str(self.root / Dirs.APP_ASSETS),
str(self.root / get_web_dir() / Dirs.PUBLIC),