Skip to content

Commit d40ac85

Browse files
authored
[PULL-228] Encode paths with os.fsencode()
This way, we can pass Path objects or arbitrary bytes. It also handles invalid UTF-8 paths.
1 parent 5761591 commit d40ac85

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

@@ -2268,7 +2269,7 @@ def flash_file(self, path, addr, on_progress=None, power_on=False):
22682269
pass
22692270

22702271
# Program the target.
2271-
bytes_flashed = self._dll.JLINK_DownloadFile(path.encode(), addr)
2272+
bytes_flashed = self._dll.JLINK_DownloadFile(os.fsencode(path), addr)
22722273
if bytes_flashed < 0:
22732274
raise errors.JLinkFlashException(bytes_flashed)
22742275

0 commit comments

Comments
 (0)