Skip to content

Commit

Permalink
Merge pull request #359 from friedererdmann/master
Browse files Browse the repository at this point in the history
Actual fix for #346 - unroll of #357
  • Loading branch information
mottosso authored Jul 16, 2021
2 parents 60fc345 + 4ab3b79 commit 50aebfc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
15 changes: 6 additions & 9 deletions Qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,14 +1260,6 @@ def _setup(module, extras):
Qt.__binding__ = module.__name__

def _warn_import_error(exc, module):
if sys.version_info > (3, 0):
unicode = str
else:
try:
if isinstance(exc, unicode):
exc = exc.encode('ascii', 'replace')
except (UnboundLocalError, NameError):
pass
msg = str(exc)
if "No module named" in msg:
return
Expand Down Expand Up @@ -1690,7 +1682,12 @@ def _log(text):


def _warn(text):
sys.stderr.write("Qt.py [warning]: %s\n" % text)
try:
sys.stderr.write("Qt.py [warning]: %s\n" % text)
except UnicodeDecodeError:
import locale
encoding = locale.getpreferredencoding()
sys.stderr.write("Qt.py [warning]: %s\n" % text.decode(encoding))


def _convert(lines):
Expand Down
14 changes: 14 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding=utf-8
"""Tests that run once"""
import io
import os
Expand Down Expand Up @@ -891,6 +892,19 @@ def test_missing():
)


def test_unicode_error_messages():
"""Test if unicode error messages with non-ascii characters
throw the error reporter off"""
import Qt
unicode_message = u"DLL load failed : le module spécifié est introuvable."
str_message = "DLL load failed : le module"

with captured_output() as out:
stdout, stderr = out
Qt._warn(text=unicode_message)
assert str_message in stderr.getvalue()


if sys.version_info < (3, 5):
# PySide is not available for Python > 3.4
# Shiboken(1) doesn't support Python 3.5
Expand Down

0 comments on commit 50aebfc

Please sign in to comment.