Skip to content

Commit 7354518

Browse files
committed
Encode paths with os.fsencode()
This way, we can pass Path objects or arbitrary bytes. It also handles invalid UTF-8 paths.
1 parent 25dd2b7 commit 7354518

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pylink/jlink.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import logging
3030
import math
3131
import operator
32+
import os
3233
import sys
3334
import time
3435
import six
@@ -827,7 +828,7 @@ def set_log_file(self, file_path):
827828
Raises:
828829
JLinkException: if the path specified is invalid.
829830
"""
830-
res = self._dll.JLINKARM_SetLogFile(file_path.encode())
831+
res = self._dll.JLINKARM_SetLogFile(os.fsencode(file_path))
831832
if res:
832833
raise errors.JLinkException(res)
833834

@@ -2271,7 +2272,7 @@ def flash_file(self, path, addr, on_progress=None, power_on=False):
22712272
pass
22722273

22732274
# Program the target.
2274-
bytes_flashed = self._dll.JLINK_DownloadFile(path.encode(), addr)
2275+
bytes_flashed = self._dll.JLINK_DownloadFile(os.fsencode(path), addr)
22752276
if bytes_flashed < 0:
22762277
raise errors.JLinkFlashException(bytes_flashed)
22772278

0 commit comments

Comments
 (0)