Merge pull request #396 from CartoDB/pg12_compatibility
Make cartodb-postgresql python3 compatible (again)
This commit is contained in:
commit
998402e531
3
Makefile
3
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)
|
||||
|
4
NEWS.md
4
NEWS.md
@ -1,3 +1,7 @@
|
||||
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`.
|
||||
|
||||
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`
|
||||
|
@ -197,8 +197,20 @@ 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)
|
||||
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
|
||||
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
|
||||
|
||||
-- url must contain a '%s' placeholder that will be replaced by current_database, for security reasons.
|
||||
@ -206,10 +218,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_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:
|
||||
@ -222,7 +236,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()
|
||||
|
Loading…
Reference in New Issue
Block a user