From 027256dbb764f8d7a269a2ae57a39294e13c89ad Mon Sep 17 00:00:00 2001 From: manmorjim Date: Tue, 11 Feb 2020 18:51:24 +0100 Subject: [PATCH 1/7] Make cartodb-postgresql python3 compatible - encoding string with python3 - adapt HTTPConnection signature to python3 --- scripts-available/CDB_Groups_API.sql | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts-available/CDB_Groups_API.sql b/scripts-available/CDB_Groups_API.sql index d4d9669..0c524fd 100644 --- a/scripts-available/CDB_Groups_API.sql +++ b/scripts-available/CDB_Groups_API.sql @@ -197,8 +197,17 @@ CREATE OR REPLACE FUNCTION @extschema@._CDB_Group_API_Auth(username text, password text) RETURNS TEXT AS $$ + import sys import base64 - return base64.encodestring('%s:%s' % (username, password)).replace('\n', '') + + data_to_encode = '%s:%s' % (username, password) + if sys.version_info[0] < 3: -- python 2.x + data_encoded = base64.encodestring(data_to_encode) + else: -- python 3.x + data_encoded = base64.b64encode(data_to_encode.encode()).decode() + + data_encoded = data_encoded.replace('\n', '') + return data_encoded $$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE; -- url must contain a '%s' placeholder that will be replaced by current_database, for security reasons. @@ -206,10 +215,12 @@ CREATE OR REPLACE FUNCTION @extschema@._CDB_Group_API_Request(method text, url text, body text, valid_return_codes int[]) RETURNS int AS $$ + python_v2 = True try: - import httplib as client + import httplib as client except: - from http import client + from http import client + python_v3 = False params = plpy.execute("select c.host, c.port, c.timeout, c.auth from @extschema@._CDB_Group_API_Conf() c;")[0] if params['host'] is None: @@ -222,7 +233,10 @@ $$ last_err = None while retry > 0: try: - conn = SD['groups_api_client'] = client.HTTPConnection(params['host'], params['port'], False, params['timeout']) + if python_v2: + conn = SD['groups_api_client'] = client.HTTPConnection(params['host'], params['port'], False, params['timeout']) + else: + conn = SD['groups_api_client'] = client.HTTPConnection(params['host'], port=params['port'], timeout=params['timeout']) database_name = plpy.execute("select current_database();")[0]['current_database'] conn.request(method, url.format(database_name), body, headers) response = conn.getresponse() From 55ebc73f9ea9962a08e48a02357e27742bdfa927 Mon Sep 17 00:00:00 2001 From: manmorjim Date: Tue, 11 Feb 2020 19:31:37 +0100 Subject: [PATCH 2/7] Remove comments to fix syntax errors --- scripts-available/CDB_Groups_API.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts-available/CDB_Groups_API.sql b/scripts-available/CDB_Groups_API.sql index 0c524fd..4203531 100644 --- a/scripts-available/CDB_Groups_API.sql +++ b/scripts-available/CDB_Groups_API.sql @@ -201,9 +201,9 @@ $$ import base64 data_to_encode = '%s:%s' % (username, password) - if sys.version_info[0] < 3: -- python 2.x + if sys.version_info[0] < 3: data_encoded = base64.encodestring(data_to_encode) - else: -- python 3.x + else: data_encoded = base64.b64encode(data_to_encode.encode()).decode() data_encoded = data_encoded.replace('\n', '') From c8410541a453e1fc7e5b2b18722a0debd12f3457 Mon Sep 17 00:00:00 2001 From: manmorjim Date: Wed, 12 Feb 2020 10:09:07 +0100 Subject: [PATCH 3/7] Fix variable naming --- scripts-available/CDB_Groups_API.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts-available/CDB_Groups_API.sql b/scripts-available/CDB_Groups_API.sql index 4203531..a0a3044 100644 --- a/scripts-available/CDB_Groups_API.sql +++ b/scripts-available/CDB_Groups_API.sql @@ -202,9 +202,9 @@ $$ data_to_encode = '%s:%s' % (username, password) if sys.version_info[0] < 3: - data_encoded = base64.encodestring(data_to_encode) + data_encoded = base64.encodestring(data_to_encode) else: - data_encoded = base64.b64encode(data_to_encode.encode()).decode() + data_encoded = base64.b64encode(data_to_encode.encode()).decode() data_encoded = data_encoded.replace('\n', '') return data_encoded @@ -220,7 +220,7 @@ $$ import httplib as client except: from http import client - python_v3 = False + python_v2 = False params = plpy.execute("select c.host, c.port, c.timeout, c.auth from @extschema@._CDB_Group_API_Conf() c;")[0] if params['host'] is None: From e37cdb4ca0fc49ce8aa8fc55a36408b9911a9e1d Mon Sep 17 00:00:00 2001 From: manmorjim Date: Wed, 12 Feb 2020 10:30:18 +0100 Subject: [PATCH 4/7] Update NEWS with changes for python3 compatibility --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 31a1901..e7e9a4d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +0.36.0 (2020-XX-XX) +* Make `_CDB_Group_API_Auth` python3 compatible by passing bytes representation instead of a string. +* Make `_CDB_Group_API_Request` python3 compatible by adapting the function signature of `HTTPConnection`. + 0.35.0 (2019-12-30) * Reapply the changes in 0.33.0 (the issue we were looking for was unrelated) * Reapply `Make PG12 depend on plpython3u instead of plpythonu` From 39c071f7904b604376ccd22c951e45d1d9358189 Mon Sep 17 00:00:00 2001 From: manmorjim Date: Wed, 12 Feb 2020 15:44:12 +0100 Subject: [PATCH 5/7] Release 0.36.0 --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c6f9f95..178978b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # cartodb/Makefile EXTENSION = cartodb -EXTVERSION = 0.35.0 +EXTVERSION = 0.36.0 SED = sed AWK = awk @@ -108,6 +108,7 @@ UPGRADABLE = \ 0.33.0 \ 0.34.0 \ 0.35.0 \ + 0.36.0 \ $(EXTVERSION)dev \ $(EXTVERSION)next \ $(END) From b9615a912f21305a08cec874a69f64ca7393329b Mon Sep 17 00:00:00 2001 From: manmorjim Date: Wed, 12 Feb 2020 18:55:44 +0100 Subject: [PATCH 6/7] Adding debug for `_CDB_Group_API_Auth` --- scripts-available/CDB_Groups_API.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts-available/CDB_Groups_API.sql b/scripts-available/CDB_Groups_API.sql index a0a3044..f5562a0 100644 --- a/scripts-available/CDB_Groups_API.sql +++ b/scripts-available/CDB_Groups_API.sql @@ -201,10 +201,13 @@ $$ import base64 data_to_encode = '%s:%s' % (username, password) + plpy.warning('DEBUG: _CDB_Group_API_Auth python v' + str(sys.version_info[0])) if sys.version_info[0] < 3: data_encoded = base64.encodestring(data_to_encode) else: + plpy.warning('DEBUG: _CDB_Group_API_Auth entra') data_encoded = base64.b64encode(data_to_encode.encode()).decode() + plpy.warning('DEBUG: _CDB_Group_API_Auth sale') data_encoded = data_encoded.replace('\n', '') return data_encoded From bd4eeb3f9e3416e7c4ecfa4fc3e756f351d122f6 Mon Sep 17 00:00:00 2001 From: manmorjim Date: Thu, 13 Feb 2020 17:12:12 +0100 Subject: [PATCH 7/7] Update NEWS with the release date --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index e7e9a4d..7a92276 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -0.36.0 (2020-XX-XX) +0.36.0 (2020-02-13) * Make `_CDB_Group_API_Auth` python3 compatible by passing bytes representation instead of a string. * Make `_CDB_Group_API_Request` python3 compatible by adapting the function signature of `HTTPConnection`.