diff --git a/src/pl/plpython/expected/plpython_error.out b/src/pl/plpython/expected/plpython_error.out index 8454b05e5e..58f7b3a766 100644 --- a/src/pl/plpython/expected/plpython_error.out +++ b/src/pl/plpython/expected/plpython_error.out @@ -45,7 +45,7 @@ CONTEXT: PL/Python function "exception_index_invalid_nested" */ CREATE FUNCTION invalid_type_uncaught(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: q = "SELECT fname FROM users WHERE lname = $1" SD["plan"] = plpy.prepare(q, [ "test" ]) rv = plpy.execute(SD["plan"], [ a ]) @@ -64,7 +64,7 @@ CONTEXT: PL/Python function "invalid_type_uncaught" */ CREATE FUNCTION invalid_type_caught(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: q = "SELECT fname FROM users WHERE lname = $1" try: SD["plan"] = plpy.prepare(q, [ "test" ]) @@ -87,7 +87,7 @@ CONTEXT: PL/Python function "invalid_type_caught" */ CREATE FUNCTION invalid_type_reraised(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: q = "SELECT fname FROM users WHERE lname = $1" try: SD["plan"] = plpy.prepare(q, [ "test" ]) @@ -108,7 +108,7 @@ CONTEXT: PL/Python function "invalid_type_reraised" */ CREATE FUNCTION valid_type(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: SD["plan"] = plpy.prepare("SELECT fname FROM users WHERE lname = $1", [ "text" ]) rv = plpy.execute(SD["plan"], [ a ]) if len(rv): diff --git a/src/pl/plpython/expected/plpython_error_2.out b/src/pl/plpython/expected/plpython_error_2.out index 7d41c8a869..bcbf2e655c 100644 --- a/src/pl/plpython/expected/plpython_error_2.out +++ b/src/pl/plpython/expected/plpython_error_2.out @@ -45,7 +45,7 @@ CONTEXT: PL/Python function "exception_index_invalid_nested" */ CREATE FUNCTION invalid_type_uncaught(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: q = "SELECT fname FROM users WHERE lname = $1" SD["plan"] = plpy.prepare(q, [ "test" ]) rv = plpy.execute(SD["plan"], [ a ]) @@ -64,7 +64,7 @@ CONTEXT: PL/Python function "invalid_type_uncaught" */ CREATE FUNCTION invalid_type_caught(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: q = "SELECT fname FROM users WHERE lname = $1" try: SD["plan"] = plpy.prepare(q, [ "test" ]) @@ -87,7 +87,7 @@ CONTEXT: PL/Python function "invalid_type_caught" */ CREATE FUNCTION invalid_type_reraised(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: q = "SELECT fname FROM users WHERE lname = $1" try: SD["plan"] = plpy.prepare(q, [ "test" ]) @@ -108,7 +108,7 @@ CONTEXT: PL/Python function "invalid_type_reraised" */ CREATE FUNCTION valid_type(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: SD["plan"] = plpy.prepare("SELECT fname FROM users WHERE lname = $1", [ "text" ]) rv = plpy.execute(SD["plan"], [ a ]) if len(rv): diff --git a/src/pl/plpython/expected/plpython_global.out b/src/pl/plpython/expected/plpython_global.out index f20014b926..192e3e48a7 100644 --- a/src/pl/plpython/expected/plpython_global.out +++ b/src/pl/plpython/expected/plpython_global.out @@ -3,23 +3,23 @@ -- CREATE FUNCTION global_test_one() returns text AS -'if not SD.has_key("global_test"): +'if "global_test" not in SD: SD["global_test"] = "set by global_test_one" -if not GD.has_key("global_test"): +if "global_test" not in GD: GD["global_test"] = "set by global_test_one" return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' LANGUAGE plpythonu; CREATE FUNCTION global_test_two() returns text AS -'if not SD.has_key("global_test"): +'if "global_test" not in SD: SD["global_test"] = "set by global_test_two" -if not GD.has_key("global_test"): +if "global_test" not in GD: GD["global_test"] = "set by global_test_two" return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' LANGUAGE plpythonu; CREATE FUNCTION static_test() returns int4 AS -'if SD.has_key("call"): +'if "call" in SD: SD["call"] = SD["call"] + 1 else: SD["call"] = 1 diff --git a/src/pl/plpython/expected/plpython_import.out b/src/pl/plpython/expected/plpython_import.out index f1f665e052..7fcd926737 100644 --- a/src/pl/plpython/expected/plpython_import.out +++ b/src/pl/plpython/expected/plpython_import.out @@ -17,11 +17,9 @@ CREATE FUNCTION import_succeed() returns text import cmath import errno import math - import md5 import operator import random import re - import sha import string import time except Exception, ex: @@ -31,15 +29,23 @@ return "succeeded, as expected"' LANGUAGE plpythonu; CREATE FUNCTION import_test_one(p text) RETURNS text AS -'import sha -digest = sha.new(p) +'try: + import hashlib + digest = hashlib.sha1(p.encode("ascii")) +except ImportError: + import sha + digest = sha.new(p) return digest.hexdigest()' LANGUAGE plpythonu; CREATE FUNCTION import_test_two(u users) RETURNS text AS -'import sha -plain = u["fname"] + u["lname"] -digest = sha.new(plain); +'plain = u["fname"] + u["lname"] +try: + import hashlib + digest = hashlib.sha1(plain.encode("ascii")) +except ImportError: + import sha + digest = sha.new(plain); return "sha hash of " + plain + " is " + digest.hexdigest()' LANGUAGE plpythonu; -- import python modules diff --git a/src/pl/plpython/expected/plpython_setof.out b/src/pl/plpython/expected/plpython_setof.out index 03a97194c8..ebf896df01 100644 --- a/src/pl/plpython/expected/plpython_setof.out +++ b/src/pl/plpython/expected/plpython_setof.out @@ -13,7 +13,7 @@ return [ content ]*count $$ LANGUAGE plpythonu; CREATE FUNCTION test_setof_as_tuple(count integer, content text) RETURNS SETOF text AS $$ t = () -for i in xrange(count): +for i in range(count): t += ( content, ) return t $$ LANGUAGE plpythonu; diff --git a/src/pl/plpython/expected/plpython_spi.out b/src/pl/plpython/expected/plpython_spi.out index f4910d9d52..9cef3f2bb0 100644 --- a/src/pl/plpython/expected/plpython_spi.out +++ b/src/pl/plpython/expected/plpython_spi.out @@ -19,7 +19,7 @@ CREATE FUNCTION nested_call_three(a text) RETURNS text -- some spi stuff CREATE FUNCTION spi_prepared_plan_test_one(a text) RETURNS text AS -'if not SD.has_key("myplan"): +'if "myplan" not in SD: q = "SELECT count(*) FROM users WHERE lname = $1" SD["myplan"] = plpy.prepare(q, [ "text" ]) try: @@ -32,7 +32,7 @@ return None LANGUAGE plpythonu; CREATE FUNCTION spi_prepared_plan_test_nested(a text) RETURNS text AS -'if not SD.has_key("myplan"): +'if "myplan" not in SD: q = "SELECT spi_prepared_plan_test_one(''%s'') as count" % a SD["myplan"] = plpy.prepare(q) try: diff --git a/src/pl/plpython/expected/plpython_test.out b/src/pl/plpython/expected/plpython_test.out index 5cce4e290f..8bef675009 100644 --- a/src/pl/plpython/expected/plpython_test.out +++ b/src/pl/plpython/expected/plpython_test.out @@ -10,7 +10,7 @@ select stupid(); -- test multiple arguments CREATE FUNCTION argument_test_one(u users, a1 text, a2 text) RETURNS text AS -'keys = u.keys() +'keys = list(u.keys()) keys.sort() out = [] for key in keys: diff --git a/src/pl/plpython/expected/plpython_trigger.out b/src/pl/plpython/expected/plpython_trigger.out index 75914047ce..b60796dab5 100644 --- a/src/pl/plpython/expected/plpython_trigger.out +++ b/src/pl/plpython/expected/plpython_trigger.out @@ -69,10 +69,10 @@ CREATE TABLE trigger_test (i int, v text ); CREATE FUNCTION trigger_data() returns trigger language plpythonu as $$ -if TD.has_key('relid'): +if 'relid' in TD: TD['relid'] = "bogus:12345" -skeys = TD.keys() +skeys = list(TD.keys()) skeys.sort() for key in skeys: val = TD[key] diff --git a/src/pl/plpython/sql/plpython_error.sql b/src/pl/plpython/sql/plpython_error.sql index 04161bc25e..5ca68495be 100644 --- a/src/pl/plpython/sql/plpython_error.sql +++ b/src/pl/plpython/sql/plpython_error.sql @@ -37,7 +37,7 @@ SELECT exception_index_invalid_nested(); */ CREATE FUNCTION invalid_type_uncaught(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: q = "SELECT fname FROM users WHERE lname = $1" SD["plan"] = plpy.prepare(q, [ "test" ]) rv = plpy.execute(SD["plan"], [ a ]) @@ -55,7 +55,7 @@ SELECT invalid_type_uncaught('rick'); */ CREATE FUNCTION invalid_type_caught(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: q = "SELECT fname FROM users WHERE lname = $1" try: SD["plan"] = plpy.prepare(q, [ "test" ]) @@ -77,7 +77,7 @@ SELECT invalid_type_caught('rick'); */ CREATE FUNCTION invalid_type_reraised(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: q = "SELECT fname FROM users WHERE lname = $1" try: SD["plan"] = plpy.prepare(q, [ "test" ]) @@ -97,7 +97,7 @@ SELECT invalid_type_reraised('rick'); */ CREATE FUNCTION valid_type(a text) RETURNS text AS -'if not SD.has_key("plan"): +'if "plan" not in SD: SD["plan"] = plpy.prepare("SELECT fname FROM users WHERE lname = $1", [ "text" ]) rv = plpy.execute(SD["plan"], [ a ]) if len(rv): diff --git a/src/pl/plpython/sql/plpython_global.sql b/src/pl/plpython/sql/plpython_global.sql index e676ad6f43..32502b41ee 100644 --- a/src/pl/plpython/sql/plpython_global.sql +++ b/src/pl/plpython/sql/plpython_global.sql @@ -4,18 +4,18 @@ CREATE FUNCTION global_test_one() returns text AS -'if not SD.has_key("global_test"): +'if "global_test" not in SD: SD["global_test"] = "set by global_test_one" -if not GD.has_key("global_test"): +if "global_test" not in GD: GD["global_test"] = "set by global_test_one" return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' LANGUAGE plpythonu; CREATE FUNCTION global_test_two() returns text AS -'if not SD.has_key("global_test"): +'if "global_test" not in SD: SD["global_test"] = "set by global_test_two" -if not GD.has_key("global_test"): +if "global_test" not in GD: GD["global_test"] = "set by global_test_two" return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' LANGUAGE plpythonu; @@ -23,7 +23,7 @@ return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' CREATE FUNCTION static_test() returns int4 AS -'if SD.has_key("call"): +'if "call" in SD: SD["call"] = SD["call"] + 1 else: SD["call"] = 1 diff --git a/src/pl/plpython/sql/plpython_import.sql b/src/pl/plpython/sql/plpython_import.sql index 7830dd7362..477af328d1 100644 --- a/src/pl/plpython/sql/plpython_import.sql +++ b/src/pl/plpython/sql/plpython_import.sql @@ -20,11 +20,9 @@ CREATE FUNCTION import_succeed() returns text import cmath import errno import math - import md5 import operator import random import re - import sha import string import time except Exception, ex: @@ -35,16 +33,24 @@ return "succeeded, as expected"' CREATE FUNCTION import_test_one(p text) RETURNS text AS -'import sha -digest = sha.new(p) +'try: + import hashlib + digest = hashlib.sha1(p.encode("ascii")) +except ImportError: + import sha + digest = sha.new(p) return digest.hexdigest()' LANGUAGE plpythonu; CREATE FUNCTION import_test_two(u users) RETURNS text AS -'import sha -plain = u["fname"] + u["lname"] -digest = sha.new(plain); +'plain = u["fname"] + u["lname"] +try: + import hashlib + digest = hashlib.sha1(plain.encode("ascii")) +except ImportError: + import sha + digest = sha.new(plain); return "sha hash of " + plain + " is " + digest.hexdigest()' LANGUAGE plpythonu; diff --git a/src/pl/plpython/sql/plpython_setof.sql b/src/pl/plpython/sql/plpython_setof.sql index e036d569f2..53d91a9e7d 100644 --- a/src/pl/plpython/sql/plpython_setof.sql +++ b/src/pl/plpython/sql/plpython_setof.sql @@ -15,7 +15,7 @@ $$ LANGUAGE plpythonu; CREATE FUNCTION test_setof_as_tuple(count integer, content text) RETURNS SETOF text AS $$ t = () -for i in xrange(count): +for i in range(count): t += ( content, ) return t $$ LANGUAGE plpythonu; diff --git a/src/pl/plpython/sql/plpython_spi.sql b/src/pl/plpython/sql/plpython_spi.sql index c663298525..2157569f4c 100644 --- a/src/pl/plpython/sql/plpython_spi.sql +++ b/src/pl/plpython/sql/plpython_spi.sql @@ -25,7 +25,7 @@ CREATE FUNCTION nested_call_three(a text) RETURNS text CREATE FUNCTION spi_prepared_plan_test_one(a text) RETURNS text AS -'if not SD.has_key("myplan"): +'if "myplan" not in SD: q = "SELECT count(*) FROM users WHERE lname = $1" SD["myplan"] = plpy.prepare(q, [ "text" ]) try: @@ -39,7 +39,7 @@ return None CREATE FUNCTION spi_prepared_plan_test_nested(a text) RETURNS text AS -'if not SD.has_key("myplan"): +'if "myplan" not in SD: q = "SELECT spi_prepared_plan_test_one(''%s'') as count" % a SD["myplan"] = plpy.prepare(q) try: diff --git a/src/pl/plpython/sql/plpython_test.sql b/src/pl/plpython/sql/plpython_test.sql index d45299420f..4a7a687e66 100644 --- a/src/pl/plpython/sql/plpython_test.sql +++ b/src/pl/plpython/sql/plpython_test.sql @@ -9,7 +9,7 @@ select stupid(); -- test multiple arguments CREATE FUNCTION argument_test_one(u users, a1 text, a2 text) RETURNS text AS -'keys = u.keys() +'keys = list(u.keys()) keys.sort() out = [] for key in keys: diff --git a/src/pl/plpython/sql/plpython_trigger.sql b/src/pl/plpython/sql/plpython_trigger.sql index ce1a737a84..385fa93bda 100644 --- a/src/pl/plpython/sql/plpython_trigger.sql +++ b/src/pl/plpython/sql/plpython_trigger.sql @@ -69,10 +69,10 @@ CREATE TABLE trigger_test CREATE FUNCTION trigger_data() returns trigger language plpythonu as $$ -if TD.has_key('relid'): +if 'relid' in TD: TD['relid'] = "bogus:12345" -skeys = TD.keys() +skeys = list(TD.keys()) skeys.sort() for key in skeys: val = TD[key]