From 735451856bb0e338ffd53f73ad4b51f54e40189a Mon Sep 17 00:00:00 2001 From: "Issam E. Maghni" Date: Sun, 23 Mar 2025 01:22:20 -0400 Subject: [PATCH] Encode paths with os.fsencode() This way, we can pass Path objects or arbitrary bytes. It also handles invalid UTF-8 paths. --- pylink/jlink.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pylink/jlink.py b/pylink/jlink.py index 70f22ad..e4e465a 100644 --- a/pylink/jlink.py +++ b/pylink/jlink.py @@ -29,6 +29,7 @@ import logging import math import operator +import os import sys import time import six @@ -827,7 +828,7 @@ def set_log_file(self, file_path): Raises: JLinkException: if the path specified is invalid. """ - res = self._dll.JLINKARM_SetLogFile(file_path.encode()) + res = self._dll.JLINKARM_SetLogFile(os.fsencode(file_path)) if res: raise errors.JLinkException(res) @@ -2271,7 +2272,7 @@ def flash_file(self, path, addr, on_progress=None, power_on=False): pass # Program the target. - bytes_flashed = self._dll.JLINK_DownloadFile(path.encode(), addr) + bytes_flashed = self._dll.JLINK_DownloadFile(os.fsencode(path), addr) if bytes_flashed < 0: raise errors.JLinkFlashException(bytes_flashed)