From c4e84130ca5b320e050c019ecd0c60ddce4833dc Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Sat, 15 Jan 2022 21:16:12 -0500 Subject: [PATCH 01/12] Update .gitignore with %1 folder --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 283d4a09f..0aaeb9a64 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ htmlcov build dist shotgun_api3.egg-info +/%1 + From 6914d245b551f5fab4eb61aedf73ca8f8d6e978b Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Sat, 15 Jan 2022 21:27:07 -0500 Subject: [PATCH 02/12] Add ariel folder --- ariel/read_config.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 ariel/read_config.py diff --git a/ariel/read_config.py b/ariel/read_config.py new file mode 100644 index 000000000..71a88a095 --- /dev/null +++ b/ariel/read_config.py @@ -0,0 +1,6 @@ +def main(): + print("Hello script") + + +if __name__ == "__main__": + main() From 615501ab691a551531a2afb2a2aa19b949d32e42 Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Sat, 15 Jan 2022 21:44:52 -0500 Subject: [PATCH 03/12] Add docs info --- ariel/read_config.py | 17 ++++++++++++++++- tests/base.py | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ariel/read_config.py b/ariel/read_config.py index 71a88a095..7245d644a 100644 --- a/ariel/read_config.py +++ b/ariel/read_config.py @@ -1,5 +1,20 @@ +import sys + +sys.path.insert(0, "/Users/ariel.calzada/instances/github.com/000paradox000/shotgunsoftware/python-api") + +from shotgun_api3.lib.six.moves.configparser import SafeConfigParser as ConfigParser + + def main(): - print("Hello script") + config_path = "/Users/ariel.calzada/instances/github.com/000paradox000/shotgunsoftware/python-api/tests/config" + config_parser = ConfigParser() + config_parser.read(config_path) + for section in config_parser.sections(): + for option in config_parser.options(section): + value = config_parser.get(section, option) + print("Section: {}, Option: {}, Value: {}".format( + section, option, value + )) if __name__ == "__main__": diff --git a/tests/base.py b/tests/base.py index f1179c06c..81ce2f658 100644 --- a/tests/base.py +++ b/tests/base.py @@ -2,7 +2,7 @@ import os import re import unittest -from shotgun_api3.lib.six.moves.configparser import ConfigParser +from shotgun_api3.lib.six.moves.configparser import SafeConfigParser as ConfigParser from . import mock From f6957d263112e560844bc158d97d256ce98d79c7 Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Sat, 15 Jan 2022 23:15:51 -0500 Subject: [PATCH 04/12] Map base 64 encode method --- shotgun_api3/shotgun.py | 8 +++++++- tests/test_client.py | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index acaeb06fe..975c85cf0 100644 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -57,6 +57,12 @@ # to be exposed as part of the API. from .lib.six.moves.xmlrpc_client import Error, ProtocolError, ResponseError # noqa +if six.PY3: + from base64 import encodebytes as base64encode +else: + from base64 import encodestring as base64encode + + LOG = logging.getLogger("shotgun_api3") """ Logging instance for shotgun_api3 @@ -656,7 +662,7 @@ def __init__(self, # version of the credentials. auth, self.config.server = urllib.parse.splituser(urllib.parse.urlsplit(base_url).netloc) if auth: - auth = base64.encodestring(six.ensure_binary(urllib.parse.unquote(auth))).decode("utf-8") + auth = base64encode(six.ensure_binary(urllib.parse.unquote(auth))).decode("utf-8") self.config.authorization = "Basic " + auth.strip() # foo:bar@123.456.789.012:3456 diff --git a/tests/test_client.py b/tests/test_client.py index 00130c5d9..5043f6efd 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -37,9 +37,14 @@ from shotgun_api3.shotgun import ServerCapabilities, SG_TIMEZONE from . import base +if six.PY3: + from base64 import encodebytes as base64encode +else: + from base64 import encodestring as base64encode + def b64encode(val): - return base64.encodestring(six.ensure_binary(val)).decode("utf-8") + return base64encode(six.ensure_binary(val)).decode("utf-8") class TestShotgunClient(base.MockTestBase): From ea300c71d20a70f9f27e0af47841fbfd27aca38e Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Sat, 15 Jan 2022 23:33:56 -0500 Subject: [PATCH 05/12] Fix configparser compatibility --- azure-pipelines-templates/run-tests.yml | 2 ++ tests/base.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/azure-pipelines-templates/run-tests.yml b/azure-pipelines-templates/run-tests.yml index 4da866081..dcf8926b2 100644 --- a/azure-pipelines-templates/run-tests.yml +++ b/azure-pipelines-templates/run-tests.yml @@ -48,6 +48,8 @@ jobs: python.version: '2.7' Python37: python.version: '3.7' + Python39: + python.version: '3.9' # These are the steps that will be executed inside each job. steps: diff --git a/tests/base.py b/tests/base.py index 81ce2f658..8d0e3a5bb 100644 --- a/tests/base.py +++ b/tests/base.py @@ -2,8 +2,6 @@ import os import re import unittest -from shotgun_api3.lib.six.moves.configparser import SafeConfigParser as ConfigParser - from . import mock @@ -12,6 +10,12 @@ from shotgun_api3.shotgun import ServerCapabilities from shotgun_api3.lib import six +if six.PY2: + from shotgun_api3.lib.six.moves.configparser import SafeConfigParser as ConfigParser +else: + from shotgun_api3.lib.six.moves.configparser import ConfigParser + + try: # Attempt to import skip from unittest. Since this was added in Python 2.7 # in the case that we're running on Python 2.6 we'll need a decorator to From 98a553ab5fd9d382e05ca0f770cd4c13f2082524 Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Sat, 15 Jan 2022 23:54:14 -0500 Subject: [PATCH 06/12] Remove ariel test folder --- ariel/read_config.py | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 ariel/read_config.py diff --git a/ariel/read_config.py b/ariel/read_config.py deleted file mode 100644 index 7245d644a..000000000 --- a/ariel/read_config.py +++ /dev/null @@ -1,21 +0,0 @@ -import sys - -sys.path.insert(0, "/Users/ariel.calzada/instances/github.com/000paradox000/shotgunsoftware/python-api") - -from shotgun_api3.lib.six.moves.configparser import SafeConfigParser as ConfigParser - - -def main(): - config_path = "/Users/ariel.calzada/instances/github.com/000paradox000/shotgunsoftware/python-api/tests/config" - config_parser = ConfigParser() - config_parser.read(config_path) - for section in config_parser.sections(): - for option in config_parser.options(section): - value = config_parser.get(section, option) - print("Section: {}, Option: {}, Value: {}".format( - section, option, value - )) - - -if __name__ == "__main__": - main() From f030d7f43ac2dd196ed20ffe518a5031a52f4bec Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Sun, 16 Jan 2022 04:15:42 -0500 Subject: [PATCH 07/12] Add tests and fix assertEquals invocation --- tests/test_api.py | 10 +++---- tests/test_client.py | 25 ++++++++++++++-- tests/test_config_file | 7 +++++ tests/test_unit.py | 66 +++++++++++++++++++++--------------------- 4 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 tests/test_config_file diff --git a/tests/test_api.py b/tests/test_api.py index 506322164..0e341838a 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1661,7 +1661,7 @@ def test_zero_is_not_none(self): # Should be filtered out result = self.sg.find('Asset', [['id', 'is', self.asset['id']], [num_field, 'is_not', None]], [num_field]) - self.assertEquals([], result) + self.assertEqual([], result) # Set it to zero self.sg.update('Asset', self.asset['id'], {num_field: 0}) @@ -1681,17 +1681,17 @@ def test_include_archived_projects(self): if self.sg.server_caps.version > (5, 3, 13): # Ticket #25082 result = self.sg.find_one('Shot', [['id', 'is', self.shot['id']]]) - self.assertEquals(self.shot['id'], result['id']) + self.assertEqual(self.shot['id'], result['id']) # archive project self.sg.update('Project', self.project['id'], {'archived': True}) # setting defaults to True, so we should get result result = self.sg.find_one('Shot', [['id', 'is', self.shot['id']]]) - self.assertEquals(self.shot['id'], result['id']) + self.assertEqual(self.shot['id'], result['id']) result = self.sg.find_one('Shot', [['id', 'is', self.shot['id']]], include_archived_projects=False) - self.assertEquals(None, result) + self.assertEqual(None, result) # unarchive project self.sg.update('Project', self.project['id'], {'archived': False}) @@ -2810,7 +2810,7 @@ def test_import_httplib(self): # right one.) httplib2_compat_version = httplib2.Http.__module__.split(".")[-1] if six.PY2: - self.assertEquals(httplib2_compat_version, "python2") + self.assertEqual(httplib2_compat_version, "python2") elif six.PY3: self.assertTrue(httplib2_compat_version, "python3") diff --git a/tests/test_client.py b/tests/test_client.py index 5043f6efd..cf611a881 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -12,11 +12,11 @@ CRUD functions. These tests always use a mock http connection so not not need a live server to run against.""" -import base64 import datetime -from shotgun_api3.lib.six.moves import urllib import os import re + +from shotgun_api3.lib.six.moves import urllib from shotgun_api3.lib import six try: import simplejson as json @@ -37,6 +37,7 @@ from shotgun_api3.shotgun import ServerCapabilities, SG_TIMEZONE from . import base + if six.PY3: from base64 import encodebytes as base64encode else: @@ -169,6 +170,26 @@ def test_url(self): expected = "Basic " + b64encode(urllib.parse.unquote(login_password)).strip() self.assertEqual(expected, sg.config.authorization) + def test_b64encode(self): + """Parse value using the proper encoder.""" + login = "thelogin" + password = "%thepassw0r#$" + login_password = "%s:%s" % (login, password) + expected = 'dGhlbG9naW46JXRoZXBhc3N3MHIjJA==' + result = b64encode(urllib.parse.unquote(login_password)).strip() + self.assertEqual(expected, result) + + def test_read_config(self): + """Validate that config values are properly coerced.""" + this_dir = os.path.dirname(os.path.realpath(__file__)) + config_path = os.path.join(this_dir, "test_config_file") + config = base.ConfigParser() + config.read(config_path) + result = config.get("SERVER_INFO", "api_key") + expected = "%abce" + + self.assertEqual(expected, result) + def test_authorization(self): """Authorization passed to server""" login = self.human_user['login'] diff --git a/tests/test_config_file b/tests/test_config_file new file mode 100644 index 000000000..8215eecde --- /dev/null +++ b/tests/test_config_file @@ -0,0 +1,7 @@ +[SERVER_INFO] +server_url : https://url +script_name : xyz +api_key : %%abce + +[TEST_DATA] +project_name : hjkl \ No newline at end of file diff --git a/tests/test_unit.py b/tests/test_unit.py index 23ff67e06..1755b51cb 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -35,8 +35,8 @@ def test_http_proxy_server(self): self.api_key, http_proxy=http_proxy, connect=False) - self.assertEquals(sg.config.proxy_server, proxy_server) - self.assertEquals(sg.config.proxy_port, 8080) + self.assertEqual(sg.config.proxy_server, proxy_server) + self.assertEqual(sg.config.proxy_port, 8080) proxy_server = "123.456.789.012" http_proxy = proxy_server sg = api.Shotgun(self.server_path, @@ -44,8 +44,8 @@ def test_http_proxy_server(self): self.api_key, http_proxy=http_proxy, connect=False) - self.assertEquals(sg.config.proxy_server, proxy_server) - self.assertEquals(sg.config.proxy_port, 8080) + self.assertEqual(sg.config.proxy_server, proxy_server) + self.assertEqual(sg.config.proxy_port, 8080) def test_http_proxy_server_and_port(self): proxy_server = "someserver.com" @@ -56,8 +56,8 @@ def test_http_proxy_server_and_port(self): self.api_key, http_proxy=http_proxy, connect=False) - self.assertEquals(sg.config.proxy_server, proxy_server) - self.assertEquals(sg.config.proxy_port, proxy_port) + self.assertEqual(sg.config.proxy_server, proxy_server) + self.assertEqual(sg.config.proxy_port, proxy_port) proxy_server = "123.456.789.012" proxy_port = 1234 http_proxy = "%s:%d" % (proxy_server, proxy_port) @@ -66,8 +66,8 @@ def test_http_proxy_server_and_port(self): self.api_key, http_proxy=http_proxy, connect=False) - self.assertEquals(sg.config.proxy_server, proxy_server) - self.assertEquals(sg.config.proxy_port, proxy_port) + self.assertEqual(sg.config.proxy_server, proxy_server) + self.assertEqual(sg.config.proxy_port, proxy_port) def test_http_proxy_server_and_port_with_authentication(self): proxy_server = "someserver.com" @@ -81,10 +81,10 @@ def test_http_proxy_server_and_port_with_authentication(self): self.api_key, http_proxy=http_proxy, connect=False) - self.assertEquals(sg.config.proxy_server, proxy_server) - self.assertEquals(sg.config.proxy_port, proxy_port) - self.assertEquals(sg.config.proxy_user, proxy_user) - self.assertEquals(sg.config.proxy_pass, proxy_pass) + self.assertEqual(sg.config.proxy_server, proxy_server) + self.assertEqual(sg.config.proxy_port, proxy_port) + self.assertEqual(sg.config.proxy_user, proxy_user) + self.assertEqual(sg.config.proxy_pass, proxy_pass) proxy_server = "123.456.789.012" proxy_port = 1234 proxy_user = "user" @@ -96,10 +96,10 @@ def test_http_proxy_server_and_port_with_authentication(self): self.api_key, http_proxy=http_proxy, connect=False) - self.assertEquals(sg.config.proxy_server, proxy_server) - self.assertEquals(sg.config.proxy_port, proxy_port) - self.assertEquals(sg.config.proxy_user, proxy_user) - self.assertEquals(sg.config.proxy_pass, proxy_pass) + self.assertEqual(sg.config.proxy_server, proxy_server) + self.assertEqual(sg.config.proxy_port, proxy_port) + self.assertEqual(sg.config.proxy_user, proxy_user) + self.assertEqual(sg.config.proxy_pass, proxy_pass) def test_http_proxy_with_at_in_password(self): proxy_server = "someserver.com" @@ -113,10 +113,10 @@ def test_http_proxy_with_at_in_password(self): self.api_key, http_proxy=http_proxy, connect=False) - self.assertEquals(sg.config.proxy_server, proxy_server) - self.assertEquals(sg.config.proxy_port, proxy_port) - self.assertEquals(sg.config.proxy_user, proxy_user) - self.assertEquals(sg.config.proxy_pass, proxy_pass) + self.assertEqual(sg.config.proxy_server, proxy_server) + self.assertEqual(sg.config.proxy_port, proxy_port) + self.assertEqual(sg.config.proxy_user, proxy_user) + self.assertEqual(sg.config.proxy_pass, proxy_pass) def test_malformatted_proxy_info(self): conn_info = { @@ -172,7 +172,7 @@ def test_filters(self): args = ['', [[path, relation, value]], None] result = self.get_call_rpc_params(args, {}) actual_condition = result['filters']['conditions'][0] - self.assertEquals(expected_condition, actual_condition) + self.assertEqual(expected_condition, actual_condition) @patch('shotgun_api3.Shotgun._call_rpc') def get_call_rpc_params(self, args, kws, call_rpc): @@ -262,8 +262,8 @@ def assert_platform(self, sys_ret_val, expected): expected_local_path_field = "local_path_%s" % expected client_caps = api.shotgun.ClientCapabilities() - self.assertEquals(client_caps.platform, expected) - self.assertEquals(client_caps.local_path_field, expected_local_path_field) + self.assertEqual(client_caps.platform, expected) + self.assertEqual(client_caps.local_path_field, expected_local_path_field) finally: api.shotgun.sys.platform = platform @@ -272,8 +272,8 @@ def test_no_platform(self): try: api.shotgun.sys.platform = "unsupported" client_caps = api.shotgun.ClientCapabilities() - self.assertEquals(client_caps.platform, None) - self.assertEquals(client_caps.local_path_field, None) + self.assertEqual(client_caps.platform, None) + self.assertEqual(client_caps.local_path_field, None) finally: api.shotgun.sys.platform = platform @@ -285,7 +285,7 @@ def test_py_version(self, mock_sys): mock_sys.version_info = (major, minor, micro, 'final', 0) expected_py_version = "%s.%s" % (major, minor) client_caps = api.shotgun.ClientCapabilities() - self.assertEquals(client_caps.py_version, expected_py_version) + self.assertEqual(client_caps.py_version, expected_py_version) class TestFilters(unittest.TestCase): @@ -296,7 +296,7 @@ def test_empty(self): } result = api.shotgun._translate_filters([], None) - self.assertEquals(result, expected) + self.assertEqual(result, expected) def test_simple(self): filters = [ @@ -313,7 +313,7 @@ def test_simple(self): } result = api.shotgun._translate_filters(filters, "any") - self.assertEquals(result, expected) + self.assertEqual(result, expected) # Test both styles of passing arrays def test_arrays(self): @@ -329,14 +329,14 @@ def test_arrays(self): ] result = api.shotgun._translate_filters(filters, "all") - self.assertEquals(result, expected) + self.assertEqual(result, expected) filters = [ ["code", "in", ["test1", "test2", "test3"]] ] result = api.shotgun._translate_filters(filters, "all") - self.assertEquals(result, expected) + self.assertEqual(result, expected) def test_nested(self): filters = [ @@ -379,7 +379,7 @@ def test_nested(self): } result = api.shotgun._translate_filters(filters, "all") - self.assertEquals(result, expected) + self.assertEqual(result, expected) def test_invalid(self): self.assertRaises(api.ShotgunError, api.shotgun._translate_filters, [], "bogus") @@ -461,7 +461,7 @@ def test_found_correct_cert(self): os.path.join(os.path.dirname(api.__file__), "lib", "certifi", "cacert.pem") ) # Now ensure that the path the SG API has found is correct. - self.assertEquals(cert_path, self.certs) + self.assertEqual(cert_path, self.certs) self.assertTrue(os.path.isfile(self.certs)) def test_httplib(self): @@ -475,7 +475,7 @@ def test_httplib(self): # Now check that the good urls connect properly using the certs for url in self.test_urls: response, message = self._check_url_with_sg_api_httplib2(url, self.certs) - self.assertEquals(response["status"], "200") + self.assertEqual(response["status"], "200") def test_urlib(self): """ From d19d8bfe1c027a869ab6936682b67a970230f46c Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Sun, 16 Jan 2022 09:06:31 -0500 Subject: [PATCH 08/12] Remove unused import --- shotgun_api3/shotgun.py | 1 - 1 file changed, 1 deletion(-) diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index 975c85cf0..280ddf7e4 100644 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -35,7 +35,6 @@ from .lib.six import BytesIO # used for attachment upload from .lib.six.moves import map -import base64 from .lib.six.moves import http_cookiejar # used for attachment upload import datetime import logging From 17123b024ee297370c1e1e38a54a095b4bcc454a Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Sun, 16 Jan 2022 13:03:53 -0500 Subject: [PATCH 09/12] Patch split url functionality --- shotgun_api3/lib/six.py | 1 + shotgun_api3/shotgun.py | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/shotgun_api3/lib/six.py b/shotgun_api3/lib/six.py index 357e624ab..b22d2e57d 100644 --- a/shotgun_api3/lib/six.py +++ b/shotgun_api3/lib/six.py @@ -36,6 +36,7 @@ PY2 = sys.version_info[0] == 2 PY3 = sys.version_info[0] == 3 PY34 = sys.version_info[0:2] >= (3, 4) +PY38 = sys.version_info[0:2] >= (3, 8) if PY3: string_types = str, diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index 280ddf7e4..04fb81375 100644 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -659,7 +659,7 @@ def __init__(self, # Do NOT urlsplit(self.base_url) here, as it contains the lower case version # of the base_url argument. Doing so would base64-encode the lowercase # version of the credentials. - auth, self.config.server = urllib.parse.splituser(urllib.parse.urlsplit(base_url).netloc) + auth, self.config.server = self._split_url(base_url) if auth: auth = base64encode(six.ensure_binary(urllib.parse.unquote(auth))).decode("utf-8") self.config.authorization = "Basic " + auth.strip() @@ -715,6 +715,26 @@ def __init__(self, self.config.user_password = None self.config.auth_token = None + def _split_url(self, base_url): + if six.PY38: + auth = None + results = urllib.parse.urlparse(base_url) + server = results.hostname + if results.port: + server = "{}:{}".format(server, results.port) + + if results.username: + auth = results.username + + if results.password: + auth = "{}:{}".format(auth, results.password) + + else: + auth, server = urllib.parse.splituser( + urllib.parse.urlsplit(base_url).netloc) + + return auth, server + # ======================================================================== # API Functions From b9a2a48e506674063da083e5c20f71ba9ce28787 Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Sun, 16 Jan 2022 13:27:13 -0500 Subject: [PATCH 10/12] Remove splituser warning for python >= 3.8 --- tests/test_client.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_client.py b/tests/test_client.py index cf611a881..db4b93bdc 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -190,6 +190,41 @@ def test_read_config(self): self.assertEqual(expected, result) + def test_split_url(self): + """Validate that url parts are properly extracted.""" + + sg = api.Shotgun("https://ci.shotgunstudio.com", + "foo", "bar", connect=False) + + + base_url = "https://ci.shotgunstudio.com" + expected_server = "ci.shotgunstudio.com" + expected_auth = None + auth, server = sg._split_url(base_url) + self.assertEqual(auth, expected_auth) + self.assertEqual(server, expected_server) + + base_url = "https://ci.shotgunstudio.com:9500" + expected_server = "ci.shotgunstudio.com:9500" + expected_auth = None + auth, server = sg._split_url(base_url) + self.assertEqual(auth, expected_auth) + self.assertEqual(server, expected_server) + + base_url = "https://x:y@ci.shotgunstudio.com:9500" + expected_server = "ci.shotgunstudio.com:9500" + expected_auth = "x:y" + auth, server = sg._split_url(base_url) + self.assertEqual(auth, expected_auth) + self.assertEqual(server, expected_server) + + base_url = "https://12345XYZ@ci.shotgunstudio.com:9500" + expected_server = "ci.shotgunstudio.com:9500" + expected_auth = "12345XYZ" + auth, server = sg._split_url(base_url) + self.assertEqual(auth, expected_auth) + self.assertEqual(server, expected_server) + def test_authorization(self): """Authorization passed to server""" login = self.human_user['login'] From 5c3a36056c7978fc15d6c7babeea14d0d17f1d9e Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Mon, 17 Jan 2022 10:55:49 -0500 Subject: [PATCH 11/12] Add a comment to split_url explaining the different implementation with python version >= 3.8 --- shotgun_api3/shotgun.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index 04fb81375..adece54f5 100644 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -656,9 +656,6 @@ def __init__(self, # if the service contains user information strip it out # copied from the xmlrpclib which turned the user:password into # and auth header - # Do NOT urlsplit(self.base_url) here, as it contains the lower case version - # of the base_url argument. Doing so would base64-encode the lowercase - # version of the credentials. auth, self.config.server = self._split_url(base_url) if auth: auth = base64encode(six.ensure_binary(urllib.parse.unquote(auth))).decode("utf-8") @@ -716,6 +713,13 @@ def __init__(self, self.config.auth_token = None def _split_url(self, base_url): + """ + Extract the hostname:port and username/password/token from base_url + sent when connect to the API. + + In python 3.8 `urllib.parse.splituser` was deprecated warning devs to + use `urllib.parse.urlparse`. + """ if six.PY38: auth = None results = urllib.parse.urlparse(base_url) From d50cbaae7eb156844a60c2eac5a9459cb81fdefd Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Mon, 17 Jan 2022 11:02:53 -0500 Subject: [PATCH 12/12] Change the comment of not using self.base_url when splitting the url --- shotgun_api3/shotgun.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index adece54f5..7e48573d2 100644 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -656,15 +656,20 @@ def __init__(self, # if the service contains user information strip it out # copied from the xmlrpclib which turned the user:password into # and auth header + + # Do NOT self._split_url(self.base_url) here, as it contains the lower + # case version of the base_url argument. Doing so would base64encode + # the lowercase version of the credentials. auth, self.config.server = self._split_url(base_url) if auth: - auth = base64encode(six.ensure_binary(urllib.parse.unquote(auth))).decode("utf-8") + auth = base64encode(six.ensure_binary( + urllib.parse.unquote(auth))).decode("utf-8") self.config.authorization = "Basic " + auth.strip() # foo:bar@123.456.789.012:3456 if http_proxy: - # check if we're using authentication. Start from the end since there might be - # @ in the user's password. + # check if we're using authentication. Start from the end since + # there might be @ in the user's password. p = http_proxy.rsplit("@", 1) if len(p) > 1: self.config.proxy_user, self.config.proxy_pass = \