Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5dff936

Browse files
committed
Make PL/Python tests more compatible with Python 3
This changes a bunch of incidentially used constructs in the PL/Pythonregression tests to equivalent constructs in cases where Python 3 no longersupports the old syntax. Support for older Python versions is unchanged.
1 parent8bed238 commit5dff936

15 files changed

+60
-48
lines changed

‎src/pl/plpython/expected/plpython_error.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ CONTEXT: PL/Python function "exception_index_invalid_nested"
4545
*/
4646
CREATE FUNCTION invalid_type_uncaught(a text) RETURNS text
4747
AS
48-
'ifnot SD.has_key("plan"):
48+
'if "plan" not in SD:
4949
q = "SELECT fname FROM users WHERE lname = $1"
5050
SD["plan"] = plpy.prepare(q, [ "test" ])
5151
rv = plpy.execute(SD["plan"], [ a ])
@@ -64,7 +64,7 @@ CONTEXT: PL/Python function "invalid_type_uncaught"
6464
*/
6565
CREATE FUNCTION invalid_type_caught(a text) RETURNS text
6666
AS
67-
'ifnot SD.has_key("plan"):
67+
'if "plan" not in SD:
6868
q = "SELECT fname FROM users WHERE lname = $1"
6969
try:
7070
SD["plan"] = plpy.prepare(q, [ "test" ])
@@ -87,7 +87,7 @@ CONTEXT: PL/Python function "invalid_type_caught"
8787
*/
8888
CREATE FUNCTION invalid_type_reraised(a text) RETURNS text
8989
AS
90-
'ifnot SD.has_key("plan"):
90+
'if "plan" not in SD:
9191
q = "SELECT fname FROM users WHERE lname = $1"
9292
try:
9393
SD["plan"] = plpy.prepare(q, [ "test" ])
@@ -108,7 +108,7 @@ CONTEXT: PL/Python function "invalid_type_reraised"
108108
*/
109109
CREATE FUNCTION valid_type(a text) RETURNS text
110110
AS
111-
'ifnot SD.has_key("plan"):
111+
'if "plan" not in SD:
112112
SD["plan"] = plpy.prepare("SELECT fname FROM users WHERE lname = $1", [ "text" ])
113113
rv = plpy.execute(SD["plan"], [ a ])
114114
if len(rv):

‎src/pl/plpython/expected/plpython_error_2.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ CONTEXT: PL/Python function "exception_index_invalid_nested"
4545
*/
4646
CREATE FUNCTION invalid_type_uncaught(a text) RETURNS text
4747
AS
48-
'ifnot SD.has_key("plan"):
48+
'if "plan" not in SD:
4949
q = "SELECT fname FROM users WHERE lname = $1"
5050
SD["plan"] = plpy.prepare(q, [ "test" ])
5151
rv = plpy.execute(SD["plan"], [ a ])
@@ -64,7 +64,7 @@ CONTEXT: PL/Python function "invalid_type_uncaught"
6464
*/
6565
CREATE FUNCTION invalid_type_caught(a text) RETURNS text
6666
AS
67-
'ifnot SD.has_key("plan"):
67+
'if "plan" not in SD:
6868
q = "SELECT fname FROM users WHERE lname = $1"
6969
try:
7070
SD["plan"] = plpy.prepare(q, [ "test" ])
@@ -87,7 +87,7 @@ CONTEXT: PL/Python function "invalid_type_caught"
8787
*/
8888
CREATE FUNCTION invalid_type_reraised(a text) RETURNS text
8989
AS
90-
'ifnot SD.has_key("plan"):
90+
'if "plan" not in SD:
9191
q = "SELECT fname FROM users WHERE lname = $1"
9292
try:
9393
SD["plan"] = plpy.prepare(q, [ "test" ])
@@ -108,7 +108,7 @@ CONTEXT: PL/Python function "invalid_type_reraised"
108108
*/
109109
CREATE FUNCTION valid_type(a text) RETURNS text
110110
AS
111-
'ifnot SD.has_key("plan"):
111+
'if "plan" not in SD:
112112
SD["plan"] = plpy.prepare("SELECT fname FROM users WHERE lname = $1", [ "text" ])
113113
rv = plpy.execute(SD["plan"], [ a ])
114114
if len(rv):

‎src/pl/plpython/expected/plpython_global.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
--
44
CREATE FUNCTION global_test_one() returns text
55
AS
6-
'ifnot SD.has_key("global_test"):
6+
'if "global_test" not in SD:
77
SD["global_test"] = "set by global_test_one"
8-
ifnot GD.has_key("global_test"):
8+
if "global_test" not in GD:
99
GD["global_test"] = "set by global_test_one"
1010
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]'
1111
LANGUAGE plpythonu;
1212
CREATE FUNCTION global_test_two() returns text
1313
AS
14-
'ifnot SD.has_key("global_test"):
14+
'if "global_test" not in SD:
1515
SD["global_test"] = "set by global_test_two"
16-
ifnot GD.has_key("global_test"):
16+
if "global_test" not in GD:
1717
GD["global_test"] = "set by global_test_two"
1818
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]'
1919
LANGUAGE plpythonu;
2020
CREATE FUNCTION static_test() returns int4
2121
AS
22-
'ifSD.has_key("call"):
22+
'if "call" in SD:
2323
SD["call"] = SD["call"] + 1
2424
else:
2525
SD["call"] = 1

‎src/pl/plpython/expected/plpython_import.out

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ CREATE FUNCTION import_succeed() returns text
1717
import cmath
1818
import errno
1919
import math
20-
import md5
2120
import operator
2221
import random
2322
import re
24-
import sha
2523
import string
2624
import time
2725
except Exception, ex:
@@ -31,15 +29,23 @@ return "succeeded, as expected"'
3129
LANGUAGE plpythonu;
3230
CREATE FUNCTION import_test_one(p text) RETURNS text
3331
AS
34-
'import sha
35-
digest = sha.new(p)
32+
'try:
33+
import hashlib
34+
digest = hashlib.sha1(p.encode("ascii"))
35+
except ImportError:
36+
import sha
37+
digest = sha.new(p)
3638
return digest.hexdigest()'
3739
LANGUAGE plpythonu;
3840
CREATE FUNCTION import_test_two(u users) RETURNS text
3941
AS
40-
'import sha
41-
plain = u["fname"] + u["lname"]
42-
digest = sha.new(plain);
42+
'plain = u["fname"] + u["lname"]
43+
try:
44+
import hashlib
45+
digest = hashlib.sha1(plain.encode("ascii"))
46+
except ImportError:
47+
import sha
48+
digest = sha.new(plain);
4349
return "sha hash of " + plain + " is " + digest.hexdigest()'
4450
LANGUAGE plpythonu;
4551
-- import python modules

‎src/pl/plpython/expected/plpython_setof.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ return [ content ]*count
1313
$$ LANGUAGE plpythonu;
1414
CREATE FUNCTION test_setof_as_tuple(count integer, content text) RETURNS SETOF text AS $$
1515
t = ()
16-
for i inxrange(count):
16+
for i inrange(count):
1717
t += ( content, )
1818
return t
1919
$$ LANGUAGE plpythonu;

‎src/pl/plpython/expected/plpython_spi.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CREATE FUNCTION nested_call_three(a text) RETURNS text
1919
-- some spi stuff
2020
CREATE FUNCTION spi_prepared_plan_test_one(a text) RETURNS text
2121
AS
22-
'ifnot SD.has_key("myplan"):
22+
'if "myplan" not in SD:
2323
q = "SELECT count(*) FROM users WHERE lname = $1"
2424
SD["myplan"] = plpy.prepare(q, [ "text" ])
2525
try:
@@ -32,7 +32,7 @@ return None
3232
LANGUAGE plpythonu;
3333
CREATE FUNCTION spi_prepared_plan_test_nested(a text) RETURNS text
3434
AS
35-
'ifnot SD.has_key("myplan"):
35+
'if "myplan" not in SD:
3636
q = "SELECT spi_prepared_plan_test_one(''%s'') as count" % a
3737
SD["myplan"] = plpy.prepare(q)
3838
try:

‎src/pl/plpython/expected/plpython_test.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ select stupid();
1010
-- test multiple arguments
1111
CREATE FUNCTION argument_test_one(u users, a1 text, a2 text) RETURNS text
1212
AS
13-
'keys = u.keys()
13+
'keys =list(u.keys())
1414
keys.sort()
1515
out = []
1616
for key in keys:

‎src/pl/plpython/expected/plpython_trigger.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ CREATE TABLE trigger_test
6969
(i int, v text );
7070
CREATE FUNCTION trigger_data() returns trigger language plpythonu as $$
7171

72-
ifTD.has_key('relid'):
72+
if 'relid' in TD:
7373
TD['relid'] = "bogus:12345"
7474

75-
skeys = TD.keys()
75+
skeys =list(TD.keys())
7676
skeys.sort()
7777
for key in skeys:
7878
val = TD[key]

‎src/pl/plpython/sql/plpython_error.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ SELECT exception_index_invalid_nested();
3737
*/
3838
CREATEFUNCTIONinvalid_type_uncaught(atext) RETURNStext
3939
AS
40-
'ifnot SD.has_key("plan"):
40+
'if "plan" not in SD:
4141
q = "SELECT fname FROM users WHERE lname = $1"
4242
SD["plan"] = plpy.prepare(q, [ "test" ])
4343
rv = plpy.execute(SD["plan"], [ a ])
@@ -55,7 +55,7 @@ SELECT invalid_type_uncaught('rick');
5555
*/
5656
CREATEFUNCTIONinvalid_type_caught(atext) RETURNStext
5757
AS
58-
'ifnot SD.has_key("plan"):
58+
'if "plan" not in SD:
5959
q = "SELECT fname FROM users WHERE lname = $1"
6060
try:
6161
SD["plan"] = plpy.prepare(q, [ "test" ])
@@ -77,7 +77,7 @@ SELECT invalid_type_caught('rick');
7777
*/
7878
CREATEFUNCTIONinvalid_type_reraised(atext) RETURNStext
7979
AS
80-
'ifnot SD.has_key("plan"):
80+
'if "plan" not in SD:
8181
q = "SELECT fname FROM users WHERE lname = $1"
8282
try:
8383
SD["plan"] = plpy.prepare(q, [ "test" ])
@@ -97,7 +97,7 @@ SELECT invalid_type_reraised('rick');
9797
*/
9898
CREATEFUNCTIONvalid_type(atext) RETURNStext
9999
AS
100-
'ifnot SD.has_key("plan"):
100+
'if "plan" not in SD:
101101
SD["plan"] = plpy.prepare("SELECT fname FROM users WHERE lname = $1", [ "text" ])
102102
rv = plpy.execute(SD["plan"], [ a ])
103103
if len(rv):

‎src/pl/plpython/sql/plpython_global.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44

55
CREATEFUNCTIONglobal_test_one() returnstext
66
AS
7-
'ifnot SD.has_key("global_test"):
7+
'if "global_test" not in SD:
88
SD["global_test"] = "set by global_test_one"
9-
ifnot GD.has_key("global_test"):
9+
if "global_test" not in GD:
1010
GD["global_test"] = "set by global_test_one"
1111
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]'
1212
LANGUAGE plpythonu;
1313

1414
CREATEFUNCTIONglobal_test_two() returnstext
1515
AS
16-
'ifnot SD.has_key("global_test"):
16+
'if "global_test" not in SD:
1717
SD["global_test"] = "set by global_test_two"
18-
ifnot GD.has_key("global_test"):
18+
if "global_test" not in GD:
1919
GD["global_test"] = "set by global_test_two"
2020
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]'
2121
LANGUAGE plpythonu;
2222

2323

2424
CREATEFUNCTIONstatic_test() returns int4
2525
AS
26-
'ifSD.has_key("call"):
26+
'if "call" in SD:
2727
SD["call"] = SD["call"] + 1
2828
else:
2929
SD["call"] = 1

‎src/pl/plpython/sql/plpython_import.sql

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ CREATE FUNCTION import_succeed() returns text
2020
import cmath
2121
import errno
2222
import math
23-
import md5
2423
import operator
2524
import random
2625
import re
27-
import sha
2826
import string
2927
import time
3028
except Exception, ex:
@@ -35,16 +33,24 @@ return "succeeded, as expected"'
3533

3634
CREATEFUNCTIONimport_test_one(ptext) RETURNStext
3735
AS
38-
'import sha
39-
digest = sha.new(p)
36+
'try:
37+
import hashlib
38+
digest = hashlib.sha1(p.encode("ascii"))
39+
except ImportError:
40+
import sha
41+
digest = sha.new(p)
4042
return digest.hexdigest()'
4143
LANGUAGE plpythonu;
4244

4345
CREATEFUNCTIONimport_test_two(u users) RETURNStext
4446
AS
45-
'import sha
46-
plain = u["fname"] + u["lname"]
47-
digest = sha.new(plain);
47+
'plain = u["fname"] + u["lname"]
48+
try:
49+
import hashlib
50+
digest = hashlib.sha1(plain.encode("ascii"))
51+
except ImportError:
52+
import sha
53+
digest = sha.new(plain);
4854
return "sha hash of " + plain + " is " + digest.hexdigest()'
4955
LANGUAGE plpythonu;
5056

‎src/pl/plpython/sql/plpython_setof.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $$ LANGUAGE plpythonu;
1515

1616
CREATEFUNCTIONtest_setof_as_tuple(countinteger, contenttext) RETURNS SETOFtextAS $$
1717
t= ()
18-
for iinxrange(count):
18+
for iinrange(count):
1919
t+= ( content, )
2020
return t
2121
$$ LANGUAGE plpythonu;

‎src/pl/plpython/sql/plpython_spi.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CREATE FUNCTION nested_call_three(a text) RETURNS text
2525

2626
CREATEFUNCTIONspi_prepared_plan_test_one(atext) RETURNStext
2727
AS
28-
'ifnot SD.has_key("myplan"):
28+
'if "myplan" not in SD:
2929
q = "SELECT count(*) FROM users WHERE lname = $1"
3030
SD["myplan"] = plpy.prepare(q, [ "text" ])
3131
try:
@@ -39,7 +39,7 @@ return None
3939

4040
CREATEFUNCTIONspi_prepared_plan_test_nested(atext) RETURNStext
4141
AS
42-
'ifnot SD.has_key("myplan"):
42+
'if "myplan" not in SD:
4343
q = "SELECT spi_prepared_plan_test_one(''%s'') as count" % a
4444
SD["myplan"] = plpy.prepare(q)
4545
try:

‎src/pl/plpython/sql/plpython_test.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ select stupid();
99
-- test multiple arguments
1010
CREATEFUNCTIONargument_test_one(u users, a1text, a2text) RETURNStext
1111
AS
12-
'keys = u.keys()
12+
'keys =list(u.keys())
1313
keys.sort()
1414
out = []
1515
for key in keys:

‎src/pl/plpython/sql/plpython_trigger.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ CREATE TABLE trigger_test
6969

7070
CREATEFUNCTIONtrigger_data() returns trigger language plpythonuas $$
7171

72-
ifTD.has_key('relid'):
72+
if'relid'in TD:
7373
TD['relid']="bogus:12345"
7474

75-
skeys=TD.keys()
75+
skeys=list(TD.keys())
7676
skeys.sort()
7777
for keyin skeys:
7878
val= TD[key]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp