Skip to content

Commit f6275cd

Browse files
committed
Remove deprecated ensure_ascii parameter from SG object
1 parent b90a64b commit f6275cd

File tree

4 files changed

+13
-63
lines changed

4 files changed

+13
-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()
@@ -3982,35 +3978,6 @@ def _decode_response(self, headers, body):
39823978
def _json_loads(self, body):
39833979
return json.loads(body)
39843980

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

tests/test_api.py

Lines changed: 13 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,23 @@ 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
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(
833+
self.config.server_url, connect=False, **self.auth_args
835834
)
836835

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))
836+
# Mock the _http_request method so we can assert_called_with
837+
sg._http_request(return_value=(200, {}, ""))
843838

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
848-
)
849-
result = sg_unicode.find_one(
850-
"Note", [["id", "is", self.note["id"]]], fields=["content"]
839+
sg.find_one("Note", [["id", "is", "Noëlご"]]) # Force a non-ascii character
840+
841+
sg._http_request.assert_called_once_with(
842+
"POST", # verb
843+
"api3/json", # path
844+
"", # body
845+
{}, # headers
851846
)
852-
self.assertTrue(_has_unicode(result))
853847

854848
def test_work_schedule(self):
855849
"""test_work_schedule tests WorkDayRules api"""
@@ -3443,15 +3437,6 @@ def test_import_httplib(self):
34433437
self.assertTrue(hasattr(socks, "HTTPError"))
34443438

34453439

3446-
def _has_unicode(data):
3447-
for k, v in data.items():
3448-
if isinstance(k, str):
3449-
return True
3450-
if isinstance(v, str):
3451-
return True
3452-
return False
3453-
3454-
34553440
def _get_path(url):
34563441
"""Returns path component of a url without the sheme, host, query, anchor, or any other
34573442
additional elements.

tests/test_client.py

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

0 commit comments

Comments
 (0)