Skip to content

Commit 592377c

Browse files
authored
SG-38306 Python2 Removal - Part 8 - Remove deprecated ensure_ascii parameter from SG object (#405)
1 parent 59b8f05 commit 592377c

File tree

4 files changed

+14
-63
lines changed

4 files changed

+14
-63
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
@@ -491,7 +491,6 @@ def __init__(
491491
api_key=None,
492492
convert_datetimes_to_utc=True,
493493
http_proxy=None,
494-
ensure_ascii=True,
495494
connect=True,
496495
ca_certs=None,
497496
login=None,
@@ -709,9 +708,6 @@ def __init__(
709708
{self.config.scheme: proxy_addr}
710709
)
711710

712-
if ensure_ascii:
713-
self._json_loads = self._json_loads_ascii
714-
715711
self.client_caps = ClientCapabilities()
716712
# this relies on self.client_caps being set first
717713
self.reset_user_agent()
@@ -3981,35 +3977,6 @@ def _decode_response(self, headers, body):
39813977
def _json_loads(self, body):
39823978
return json.loads(body)
39833979

3984-
def _json_loads_ascii(self, body):
3985-
"""
3986-
See http://stackoverflow.com/questions/956867
3987-
"""
3988-
3989-
def _decode_list(lst):
3990-
newlist = []
3991-
for i in lst:
3992-
if isinstance(i, str):
3993-
i = sgutils.ensure_str(i)
3994-
elif isinstance(i, list):
3995-
i = _decode_list(i)
3996-
newlist.append(i)
3997-
return newlist
3998-
3999-
def _decode_dict(dct):
4000-
newdict = {}
4001-
for k, v in dct.items():
4002-
if isinstance(k, str):
4003-
k = sgutils.ensure_str(k)
4004-
if isinstance(v, str):
4005-
v = sgutils.ensure_str(v)
4006-
elif isinstance(v, list):
4007-
v = _decode_list(v)
4008-
newdict[k] = v
4009-
return newdict
4010-
4011-
return json.loads(body, object_hook=_decode_dict)
4012-
40133980
def _response_errors(self, sg_response):
40143981
"""
40153982
Raise any API errors specified in the response.

tests/test_api.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import uuid
3030
import warnings
3131

32-
from shotgun_api3.lib import six
3332
from shotgun_api3.lib.httplib2 import Http
3433

3534
import shotgun_api3
@@ -828,28 +827,24 @@ def test_summary_values(self):
828827
sorted(result["groups"], key=lambda x: x["group_name"]), groups
829828
)
830829

831-
def test_ensure_ascii(self):
832-
"""test_ensure_ascii tests ensure_unicode flag."""
833-
sg_ascii = shotgun_api3.Shotgun(
834-
self.config.server_url, ensure_ascii=True, **self.auth_args
835-
)
830+
def test_json_dumps_default_ensure_ascii_disabled(self):
831+
"""Make sure SG'payload is using ensure_ascii for json dumps"""
832+
sg = shotgun_api3.Shotgun(self.config.server_url, **self.auth_args)
836833

837-
result = sg_ascii.find_one(
838-
"Note", [["id", "is", self.note["id"]]], fields=["content"]
839-
)
840-
if six.PY2:
841-
# In Python3 there isn't a separate unicode type.
842-
self.assertFalse(_has_unicode(result))
834+
# Mock the _http_request method
835+
sg._orig_http_request = sg._http_request
836+
sg._http_request = unittest.mock.Mock(wraps=sg._orig_http_request)
843837

844-
def test_ensure_unicode(self):
845-
"""test_ensure_unicode tests ensure_unicode flag."""
846-
sg_unicode = shotgun_api3.Shotgun(
847-
self.config.server_url, ensure_ascii=False, **self.auth_args
838+
sg.find_one(
839+
"Note",
840+
[["content", "is", "Noëlご"]], # Force a non-ascii character
848841
)
849-
result = sg_unicode.find_one(
850-
"Note", [["id", "is", self.note["id"]]], fields=["content"]
842+
843+
sg._http_request.assert_called_once()
844+
self.assertIn(
845+
b"No\xc3\xabl\xe3\x81\x94", # utf-8 encoded version of Noëlご
846+
sg._http_request.call_args.args[2], # Get the body of the request
851847
)
852-
self.assertTrue(_has_unicode(result))
853848

854849
def test_work_schedule(self):
855850
"""test_work_schedule tests WorkDayRules api"""
@@ -3409,15 +3404,6 @@ def test_import_httplib(self):
34093404
self.assertTrue(hasattr(socks, "HTTPError"))
34103405

34113406

3412-
def _has_unicode(data):
3413-
for k, v in data.items():
3414-
if isinstance(k, str):
3415-
return True
3416-
if isinstance(v, str):
3417-
return True
3418-
return False
3419-
3420-
34213407
def _get_path(url):
34223408
"""Returns path component of a url without the sheme, host, query, anchor, or any other
34233409
additional elements.

tests/test_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,6 @@ def _assert_decode_resonse(self, ensure_ascii, data):
647647
self.config.script_name,
648648
self.config.api_key,
649649
http_proxy=self.config.http_proxy,
650-
ensure_ascii=ensure_ascii,
651650
connect=False,
652651
)
653652

0 commit comments

Comments
 (0)