Skip to content

Commit

Permalink
Merge pull request #46 from OpenAstroTech/bugfix/js/45-unicode-decode…
Browse files Browse the repository at this point in the history
…-error

Fix text byte decoding to not use strict error handling
  • Loading branch information
julianneswinoga authored Mar 1, 2024
2 parents 409c688 + 729ca48 commit a92eb00
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions OATFWGUI/anon_usage_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from platform_check import get_platform, PlatformEnum
from gui_state import LogicState
from misc_utils import decode_bytes

log = logging.getLogger('')

Expand Down Expand Up @@ -163,7 +164,7 @@ def get_uuid_windows() -> str:
capture_output=True)
if sub_proc.returncode != 0:
return 'unknown-windows'
windows_uuid = sub_proc.stdout.decode('UTF-8')
windows_uuid = decode_bytes(sub_proc.stdout)
return windows_uuid


Expand All @@ -185,7 +186,7 @@ def to_nearest_half(num: float) -> float:
def get_approx_location() -> Tuple[float, float]:
geo_ip_url = 'https://ipinfo.io/loc'
response = requests.get(geo_ip_url, timeout=2.0)
resp_str = response.content.decode().strip()
resp_str = decode_bytes(response.content).strip()
lat_str, lon_str = resp_str.split(',')
lat_approx = to_nearest_half(float(lat_str))
lon_approx = to_nearest_half(float(lon_str))
Expand Down
6 changes: 4 additions & 2 deletions OATFWGUI/external_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from PySide6.QtCore import Slot, QProcess, QStandardPaths, QProcessEnvironment

from misc_utils import decode_bytes

log = logging.getLogger('')


Expand Down Expand Up @@ -62,14 +64,14 @@ def cleanup(self):
@Slot()
def handle_stderr(self):
data = self.qproc.readAllStandardError()
stderr = bytes(data).decode("utf8")
stderr = decode_bytes(bytes(data))
self.stderr_text += stderr
log.error(stderr)

@Slot()
def handle_stdout(self):
data = self.qproc.readAllStandardOutput()
stdout = bytes(data).decode("utf8")
stdout = decode_bytes(bytes(data))
self.stdout_text += stdout
log.info(stdout)

Expand Down
5 changes: 5 additions & 0 deletions OATFWGUI/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ def remove_readonly(func: Callable, path, excinfo):
func(path)

shutil.rmtree(dir_to_delete, onerror=remove_readonly)


def decode_bytes(byte_string: bytes) -> str:
# Just to consolidate all text decoding and make sure they're all the same
return byte_string.decode('utf-8', errors='backslashreplace')

0 comments on commit a92eb00

Please sign in to comment.