Skip to content

Commit

Permalink
Merge dfc0374 into 40467ee
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonCoderAS committed Dec 25, 2019
2 parents 40467ee + dfc0374 commit c33a7da
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Unreleased
* The file for ModActions (praw/models/modaction.py) has been moved to
praw/models/mod_action.py and the previous has been Deprecated.

**Removed**

* Converting :class:`.APIException` to string will no longer escape unicode
characters.

6.4.0 (2019/09/21)
------------------

Expand Down
12 changes: 2 additions & 10 deletions praw/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = u"{}: '{}'".format(error_type, message)
error_str = "{}: '{}'".format(error_type, message)
if field:
error_str += u" on field '{}'".format(field)
error_str = error_str.encode("unicode_escape").decode("ascii")
error_str += " on field '{}'".format(field)

super().__init__(error_str)
self.error_type = error_type
Expand Down
1 change: 0 additions & 1 deletion tests/integration/models/reddit/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 u"\xf0\x9f\x98\x80" != widgets.sidebar[0] # for python 2
8 changes: 0 additions & 8 deletions tests/unit/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", u"実行回数が多すぎます", u"フィールド")
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):
Expand Down

0 comments on commit c33a7da

Please sign in to comment.