diff --git a/shotgun_api3/lib/mockgun/mockgun.py b/shotgun_api3/lib/mockgun/mockgun.py index 18e4a142..45d0b2aa 100644 --- a/shotgun_api3/lib/mockgun/mockgun.py +++ b/shotgun_api3/lib/mockgun/mockgun.py @@ -177,7 +177,6 @@ def __init__(self, api_key=None, convert_datetimes_to_utc=True, http_proxy=None, - ensure_ascii=True, connect=True, ca_certs=None, login=None, diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index 49c4d120..652bd234 100644 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -491,7 +491,6 @@ def __init__( api_key=None, convert_datetimes_to_utc=True, http_proxy=None, - ensure_ascii=True, connect=True, ca_certs=None, login=None, @@ -709,9 +708,6 @@ def __init__( {self.config.scheme: proxy_addr} ) - if ensure_ascii: - self._json_loads = self._json_loads_ascii - self.client_caps = ClientCapabilities() # this relies on self.client_caps being set first self.reset_user_agent() @@ -3982,35 +3978,6 @@ def _decode_response(self, headers, body): def _json_loads(self, body): return json.loads(body) - def _json_loads_ascii(self, body): - """ - See http://stackoverflow.com/questions/956867 - """ - - def _decode_list(lst): - newlist = [] - for i in lst: - if isinstance(i, str): - i = sgutils.ensure_str(i) - elif isinstance(i, list): - i = _decode_list(i) - newlist.append(i) - return newlist - - def _decode_dict(dct): - newdict = {} - for k, v in dct.items(): - if isinstance(k, str): - k = sgutils.ensure_str(k) - if isinstance(v, str): - v = sgutils.ensure_str(v) - elif isinstance(v, list): - v = _decode_list(v) - newdict[k] = v - return newdict - - return json.loads(body, object_hook=_decode_dict) - def _response_errors(self, sg_response): """ Raise any API errors specified in the response. diff --git a/tests/test_api.py b/tests/test_api.py index e7e046d2..0302dfe0 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -29,7 +29,6 @@ import uuid import warnings -from shotgun_api3.lib import six from shotgun_api3.lib.httplib2 import Http import shotgun_api3 @@ -828,28 +827,24 @@ def test_summary_values(self): sorted(result["groups"], key=lambda x: x["group_name"]), groups ) - def test_ensure_ascii(self): - """test_ensure_ascii tests ensure_unicode flag.""" - sg_ascii = shotgun_api3.Shotgun( - self.config.server_url, ensure_ascii=True, **self.auth_args - ) + def test_json_dumps_default_ensure_ascii_disabled(self): + """Make sure SG'payload is using ensure_ascii for json dumps""" + sg = shotgun_api3.Shotgun(self.config.server_url, **self.auth_args) - result = sg_ascii.find_one( - "Note", [["id", "is", self.note["id"]]], fields=["content"] - ) - if six.PY2: - # In Python3 there isn't a separate unicode type. - self.assertFalse(_has_unicode(result)) + # Mock the _http_request method + sg._orig_http_request = sg._http_request + sg._http_request = unittest.mock.Mock(wraps=sg._orig_http_request) - def test_ensure_unicode(self): - """test_ensure_unicode tests ensure_unicode flag.""" - sg_unicode = shotgun_api3.Shotgun( - self.config.server_url, ensure_ascii=False, **self.auth_args + sg.find_one( + "Note", + [["content", "is", "Noëlご"]], # Force a non-ascii character ) - result = sg_unicode.find_one( - "Note", [["id", "is", self.note["id"]]], fields=["content"] + + sg._http_request.assert_called_once() + self.assertIn( + b"No\xc3\xabl\xe3\x81\x94", # utf-8 encoded version of Noëlご + sg._http_request.call_args.args[2], # Get the body of the request ) - self.assertTrue(_has_unicode(result)) def test_work_schedule(self): """test_work_schedule tests WorkDayRules api""" @@ -3443,15 +3438,6 @@ def test_import_httplib(self): self.assertTrue(hasattr(socks, "HTTPError")) -def _has_unicode(data): - for k, v in data.items(): - if isinstance(k, str): - return True - if isinstance(v, str): - return True - return False - - def _get_path(url): """Returns path component of a url without the sheme, host, query, anchor, or any other additional elements. diff --git a/tests/test_client.py b/tests/test_client.py index d9c66ae1..249203db 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -656,7 +656,6 @@ def _assert_decode_resonse(self, ensure_ascii, data): self.config.script_name, self.config.api_key, http_proxy=self.config.http_proxy, - ensure_ascii=ensure_ascii, connect=False, )