Skip to content

Commit 2f109c4

Browse files
committed
Remove deprecated ensure_ascii parameter from SG object
1 parent 8ac9c8d commit 2f109c4

File tree

4 files changed

+13
-62
lines changed

4 files changed

+13
-62
lines changed

shotgun_api3/lib/mockgun/mockgun.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ def __init__(self,
177177
api_key=None,
178178
convert_datetimes_to_utc=True,
179179
http_proxy=None,
180-
ensure_ascii=True,
181180
connect=True,
182181
ca_certs=None,
183182
login=None,

shotgun_api3/shotgun.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ def __init__(
490490
api_key=None,
491491
convert_datetimes_to_utc=True,
492492
http_proxy=None,
493-
ensure_ascii=True,
494493
connect=True,
495494
ca_certs=None,
496495
login=None,
@@ -726,9 +725,6 @@ def __init__(
726725
{self.config.scheme: proxy_addr}
727726
)
728727

729-
if ensure_ascii:
730-
self._json_loads = self._json_loads_ascii
731-
732728
self.client_caps = ClientCapabilities()
733729
# this relies on self.client_caps being set first
734730
self.reset_user_agent()
@@ -3999,35 +3995,6 @@ def _decode_response(self, headers, body):
39993995
def _json_loads(self, body):
40003996
return json.loads(body)
40013997

4002-
def _json_loads_ascii(self, body):
4003-
"""
4004-
See http://stackoverflow.com/questions/956867
4005-
"""
4006-
4007-
def _decode_list(lst):
4008-
newlist = []
4009-
for i in lst:
4010-
if isinstance(i, str):
4011-
i = sgutils.ensure_str(i)
4012-
elif isinstance(i, list):
4013-
i = _decode_list(i)
4014-
newlist.append(i)
4015-
return newlist
4016-
4017-
def _decode_dict(dct):
4018-
newdict = {}
4019-
for k, v in dct.items():
4020-
if isinstance(k, str):
4021-
k = sgutils.ensure_str(k)
4022-
if isinstance(v, str):
4023-
v = sgutils.ensure_str(v)
4024-
elif isinstance(v, list):
4025-
v = _decode_list(v)
4026-
newdict[k] = v
4027-
return newdict
4028-
4029-
return json.loads(body, object_hook=_decode_dict)
4030-
40313998
def _response_errors(self, sg_response):
40323999
"""
40334000
Raise any API errors specified in the response.

tests/test_api.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -825,28 +825,23 @@ def test_summary_values(self):
825825
sorted(result["groups"], key=lambda x: x["group_name"]), groups
826826
)
827827

828-
def test_ensure_ascii(self):
829-
"""test_ensure_ascii tests ensure_unicode flag."""
830-
sg_ascii = shotgun_api3.Shotgun(
831-
self.config.server_url, ensure_ascii=True, **self.auth_args
828+
def test_json_dumps_default_ensure_ascii_disabled(self):
829+
"""Make sure SG'payload is using ensure_ascii for json dumps"""
830+
sg = shotgun_api3.Shotgun(
831+
self.config.server_url, connect=False, **self.auth_args
832832
)
833833

834-
result = sg_ascii.find_one(
835-
"Note", [["id", "is", self.note["id"]]], fields=["content"]
836-
)
837-
if six.PY2:
838-
# In Python3 there isn't a separate unicode type.
839-
self.assertFalse(_has_unicode(result))
834+
# Mock the _http_request method so we can assert_called_with
835+
sg._http_request(return_value=(200, {}, ""))
840836

841-
def test_ensure_unicode(self):
842-
"""test_ensure_unicode tests ensure_unicode flag."""
843-
sg_unicode = shotgun_api3.Shotgun(
844-
self.config.server_url, ensure_ascii=False, **self.auth_args
845-
)
846-
result = sg_unicode.find_one(
847-
"Note", [["id", "is", self.note["id"]]], fields=["content"]
837+
sg.find_one("Note", [["id", "is", "Noëlご"]]) # Force a non-ascii character
838+
839+
sg._http_request.assert_called_once_with(
840+
"POST", # verb
841+
"api3/json", # path
842+
"", # body
843+
{}, # headers
848844
)
849-
self.assertTrue(_has_unicode(result))
850845

851846
def test_work_schedule(self):
852847
"""test_work_schedule tests WorkDayRules api"""
@@ -3440,15 +3435,6 @@ def test_import_httplib(self):
34403435
self.assertTrue(hasattr(socks, "HTTPError"))
34413436

34423437

3443-
def _has_unicode(data):
3444-
for k, v in data.items():
3445-
if isinstance(k, str):
3446-
return True
3447-
if isinstance(v, str):
3448-
return True
3449-
return False
3450-
3451-
34523438
def _get_path(url):
34533439
"""Returns path component of a url without the sheme, host, query, anchor, or any other
34543440
additional elements.

tests/test_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,6 @@ def _assert_decode_resonse(self, ensure_ascii, data):
655655
self.config.script_name,
656656
self.config.api_key,
657657
http_proxy=self.config.http_proxy,
658-
ensure_ascii=ensure_ascii,
659658
connect=False,
660659
)
661660

0 commit comments

Comments
 (0)