From 6e0c33a7a11602505034a8471204da7dc38e4232 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Sun, 22 Dec 2019 17:06:00 -0500 Subject: [PATCH 1/4] Remove useless unicode prefixes --- praw/exceptions.py | 4 ++-- tests/integration/models/reddit/test_widgets.py | 2 +- tests/unit/test_exceptions.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/praw/exceptions.py b/praw/exceptions.py index 505fdba4fd..2ab28781da 100644 --- a/praw/exceptions.py +++ b/praw/exceptions.py @@ -28,9 +28,9 @@ def __init__(self, error_type, message, field): the instance. """ - error_str = u"{}: '{}'".format(error_type, message) + error_str = "{}: '{}'".format(error_type, message) if field: - error_str += u" on field '{}'".format(field) + error_str += " on field '{}'".format(field) error_str = error_str.encode("unicode_escape").decode("ascii") super(APIException, self).__init__(error_str) diff --git a/tests/integration/models/reddit/test_widgets.py b/tests/integration/models/reddit/test_widgets.py index ab95e5f0a2..2a68d399b6 100644 --- a/tests/integration/models/reddit/test_widgets.py +++ b/tests/integration/models/reddit/test_widgets.py @@ -975,4 +975,4 @@ def test_inequality(self): assert len(widgets.sidebar) >= 2 assert widgets.sidebar[0] != widgets.sidebar[1] assert widgets.sidebar[0] != widgets.sidebar[1].id - assert u"\xf0\x9f\x98\x80" != widgets.sidebar[0] # for python 2 + assert "\xf0\x9f\x98\x80" != widgets.sidebar[0] # for python 2 diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py index 2ed8af7e66..d0e6c22407 100644 --- a/tests/unit/test_exceptions.py +++ b/tests/unit/test_exceptions.py @@ -24,7 +24,7 @@ def test_str(self): ) def test_str_for_localized_error_string(self): - exception = APIException("RATELIMIT", u"実行回数が多すぎます", u"フィールド") + exception = APIException("RATELIMIT", "実行回数が多すぎます", "フィールド") assert str(exception) == ( "RATELIMIT: '\\u5b9f\\u884c\\u56de\\u6570\\u304c\\u591a" "\\u3059\\u304e\\u307e\\u3059' on field " From a07288f0bc8d23a7e2083346f73636f81793f556 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Sun, 22 Dec 2019 17:24:46 -0500 Subject: [PATCH 2/4] remove unicode escape --- praw/exceptions.py | 8 -------- tests/unit/test_exceptions.py | 8 -------- 2 files changed, 16 deletions(-) diff --git a/praw/exceptions.py b/praw/exceptions.py index 2ab28781da..d29eece485 100644 --- a/praw/exceptions.py +++ b/praw/exceptions.py @@ -20,18 +20,10 @@ def __init__(self, error_type, message, field): :param error_type: The error type set on Reddit's end. :param message: The associated message for the error. :param field: The input field associated with the error if available. - - .. note:: Calling ``str()`` on the instance returns - ``unicode_escape``-d ASCII string because the message may be - localized and may contain UNICODE characters. If you want a - non-escaped message, access the ``message`` attribute on - the instance. - """ error_str = "{}: '{}'".format(error_type, message) if field: error_str += " on field '{}'".format(field) - error_str = error_str.encode("unicode_escape").decode("ascii") super(APIException, self).__init__(error_str) self.error_type = error_type diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py index d0e6c22407..eceffde0b5 100644 --- a/tests/unit/test_exceptions.py +++ b/tests/unit/test_exceptions.py @@ -23,14 +23,6 @@ def test_str(self): "BAD_SOMETHING: 'invalid something' on field 'some_field'" ) - def test_str_for_localized_error_string(self): - exception = APIException("RATELIMIT", "実行回数が多すぎます", "フィールド") - assert str(exception) == ( - "RATELIMIT: '\\u5b9f\\u884c\\u56de\\u6570\\u304c\\u591a" - "\\u3059\\u304e\\u307e\\u3059' on field " - "'\\u30d5\\u30a3\\u30fc\\u30eb\\u30c9'" - ) - class TestClientException: def test_inheritance(self): From 03a388cf6841f21cab0b2773e807574a38a21523 Mon Sep 17 00:00:00 2001 From: PokestarFan Date: Sun, 22 Dec 2019 17:37:35 -0500 Subject: [PATCH 3/4] Add changelog entry --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index e8af02de89..63dbbcf4f5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -34,6 +34,11 @@ Unreleased * :meth:`.moderator_subreddits` as :meth:`.Redditor.moderated` provides more functionality. +**Removed** + +* Converting :class:`.APIException` to string will no longer escape unicode + characters. + 6.4.0 (2019/09/21) ------------------ From 497a8edaec4bb1757b20ab6db144636100ae279f Mon Sep 17 00:00:00 2001 From: PokestarFan <13932583+PokestarFan@users.noreply.github.com> Date: Wed, 25 Dec 2019 16:04:45 -0500 Subject: [PATCH 4/4] Update test_widgets.py --- tests/integration/models/reddit/test_widgets.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/models/reddit/test_widgets.py b/tests/integration/models/reddit/test_widgets.py index 2a68d399b6..4835b5d7c6 100644 --- a/tests/integration/models/reddit/test_widgets.py +++ b/tests/integration/models/reddit/test_widgets.py @@ -975,4 +975,3 @@ def test_inequality(self): assert len(widgets.sidebar) >= 2 assert widgets.sidebar[0] != widgets.sidebar[1] assert widgets.sidebar[0] != widgets.sidebar[1].id - assert "\xf0\x9f\x98\x80" != widgets.sidebar[0] # for python 2