Commit 37f21ed1 authored by Peter Eisentraut's avatar Peter Eisentraut

Remove support for Python older than 2.6

Supporting very old Python versions is a maintenance burden,
especially with the several variant test files to maintain for Python
<2.6.

Since we have dropped support for older OpenSSL versions in
7b283d0e, RHEL 5 is now effectively
desupported, and that was also the only mainstream operating system
still using Python versions before 2.6, so it's a good time to drop
those as well.
Reviewed-by: default avatarTom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/98b69261-298c-13d2-f34d-836fd9c29b21%402ndquadrant.com
parent f5d28710
...@@ -37,8 +37,8 @@ python_majorversion=`echo "$python_fullversion" | sed '[s/^\([0-9]*\).*/\1/]'` ...@@ -37,8 +37,8 @@ python_majorversion=`echo "$python_fullversion" | sed '[s/^\([0-9]*\).*/\1/]'`
python_minorversion=`echo "$python_fullversion" | sed '[s/^[0-9]*\.\([0-9]*\).*/\1/]'` python_minorversion=`echo "$python_fullversion" | sed '[s/^[0-9]*\.\([0-9]*\).*/\1/]'`
python_version=`echo "$python_fullversion" | sed '[s/^\([0-9]*\.[0-9]*\).*/\1/]'` python_version=`echo "$python_fullversion" | sed '[s/^\([0-9]*\.[0-9]*\).*/\1/]'`
# Reject unsupported Python versions as soon as practical. # Reject unsupported Python versions as soon as practical.
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 4; then if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 6; then
AC_MSG_ERROR([Python version $python_version is too old (version 2.4 or later is required)]) AC_MSG_ERROR([Python version $python_version is too old (version 2.6 or later is required)])
fi fi
AC_MSG_CHECKING([for Python distutils module]) AC_MSG_CHECKING([for Python distutils module])
......
...@@ -9616,8 +9616,8 @@ python_majorversion=`echo "$python_fullversion" | sed 's/^\([0-9]*\).*/\1/'` ...@@ -9616,8 +9616,8 @@ python_majorversion=`echo "$python_fullversion" | sed 's/^\([0-9]*\).*/\1/'`
python_minorversion=`echo "$python_fullversion" | sed 's/^[0-9]*\.\([0-9]*\).*/\1/'` python_minorversion=`echo "$python_fullversion" | sed 's/^[0-9]*\.\([0-9]*\).*/\1/'`
python_version=`echo "$python_fullversion" | sed 's/^\([0-9]*\.[0-9]*\).*/\1/'` python_version=`echo "$python_fullversion" | sed 's/^\([0-9]*\.[0-9]*\).*/\1/'`
# Reject unsupported Python versions as soon as practical. # Reject unsupported Python versions as soon as practical.
if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 4; then if test "$python_majorversion" -lt 3 -a "$python_minorversion" -lt 6; then
as_fn_error $? "Python version $python_version is too old (version 2.4 or later is required)" "$LINENO" 5 as_fn_error $? "Python version $python_version is too old (version 2.6 or later is required)" "$LINENO" 5
fi fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python distutils module" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python distutils module" >&5
......
...@@ -196,7 +196,7 @@ su - postgres ...@@ -196,7 +196,7 @@ su - postgres
language, you need a <productname>Python</productname> language, you need a <productname>Python</productname>
installation with the header files and installation with the header files and
the <application>distutils</application> module. The minimum the <application>distutils</application> module. The minimum
required version is <productname>Python</productname> 2.4. required version is <productname>Python</productname> 2.6.
<productname>Python 3</productname> is supported if it's <productname>Python 3</productname> is supported if it's
version 3.1 or later; but see version 3.1 or later; but see
<xref linkend="plpython-python23"/> <xref linkend="plpython-python23"/>
......
...@@ -1335,9 +1335,8 @@ $$ LANGUAGE plpythonu; ...@@ -1335,9 +1335,8 @@ $$ LANGUAGE plpythonu;
<para> <para>
Context managers syntax using the <literal>with</literal> keyword Context managers syntax using the <literal>with</literal> keyword
is available by default in Python 2.6. If using PL/Python with an is available by default in Python 2.6. For compatibility with
older Python version, it is still possible to use explicit older Python versions, you can call the
subtransactions, although not as transparently. You can call the
subtransaction manager's <literal>__enter__</literal> and subtransaction manager's <literal>__enter__</literal> and
<literal>__exit__</literal> functions using the <literal>__exit__</literal> functions using the
<literal>enter</literal> and <literal>exit</literal> convenience <literal>enter</literal> and <literal>exit</literal> convenience
...@@ -1367,17 +1366,6 @@ plpy.execute(plan, [result]) ...@@ -1367,17 +1366,6 @@ plpy.execute(plan, [result])
$$ LANGUAGE plpythonu; $$ LANGUAGE plpythonu;
</programlisting> </programlisting>
</para> </para>
<note>
<para>
Although context managers were implemented in Python 2.5, to use
the <literal>with</literal> syntax in that version you need to
use a <ulink
url="https://docs.python.org/release/2.5/ref/future.html">future
statement</ulink>. Because of implementation details, however,
you cannot use future statements in PL/Python functions.
</para>
</note>
</sect2> </sect2>
</sect1> </sect1>
......
Guide to alternative expected files: Guide to alternative expected files:
plpython_error_0.out Python 2.4 and older
plpython_error_5.out Python 3.5 and newer plpython_error_5.out Python 3.5 and newer
plpython_unicode.out server encoding != SQL_ASCII plpython_unicode.out server encoding != SQL_ASCII
plpython_unicode_3.out server encoding == SQL_ASCII plpython_unicode_3.out server encoding == SQL_ASCII
plpython_subtransaction_0.out Python 2.4 and older (without with statement)
plpython_subtransaction_5.out Python 2.5 (without with statement)
plpython_types_3.out Python 3.x plpython_types_3.out Python 3.x
This diff is collapsed.
...@@ -5,71 +5,6 @@ ...@@ -5,71 +5,6 @@
CREATE TABLE subtransaction_tbl ( CREATE TABLE subtransaction_tbl (
i integer i integer
); );
-- Explicit case for Python <2.6
CREATE FUNCTION subtransaction_test(what_error text = NULL) RETURNS text
AS $$
import sys
subxact = plpy.subtransaction()
subxact.__enter__()
exc = True
try:
try:
plpy.execute("INSERT INTO subtransaction_tbl VALUES (1)")
plpy.execute("INSERT INTO subtransaction_tbl VALUES (2)")
if what_error == "SPI":
plpy.execute("INSERT INTO subtransaction_tbl VALUES ('oops')")
elif what_error == "Python":
raise Exception("Python exception")
except:
exc = False
subxact.__exit__(*sys.exc_info())
raise
finally:
if exc:
subxact.__exit__(None, None, None)
$$ LANGUAGE plpythonu;
SELECT subtransaction_test();
subtransaction_test
---------------------
(1 row)
SELECT * FROM subtransaction_tbl;
i
---
1
2
(2 rows)
TRUNCATE subtransaction_tbl;
SELECT subtransaction_test('SPI');
ERROR: spiexceptions.InvalidTextRepresentation: invalid input syntax for type integer: "oops"
LINE 1: INSERT INTO subtransaction_tbl VALUES ('oops')
^
QUERY: INSERT INTO subtransaction_tbl VALUES ('oops')
CONTEXT: Traceback (most recent call last):
PL/Python function "subtransaction_test", line 11, in <module>
plpy.execute("INSERT INTO subtransaction_tbl VALUES ('oops')")
PL/Python function "subtransaction_test"
SELECT * FROM subtransaction_tbl;
i
---
(0 rows)
TRUNCATE subtransaction_tbl;
SELECT subtransaction_test('Python');
ERROR: Exception: Python exception
CONTEXT: Traceback (most recent call last):
PL/Python function "subtransaction_test", line 13, in <module>
raise Exception("Python exception")
PL/Python function "subtransaction_test"
SELECT * FROM subtransaction_tbl;
i
---
(0 rows)
TRUNCATE subtransaction_tbl;
-- Context manager case for Python >=2.6
CREATE FUNCTION subtransaction_ctx_test(what_error text = NULL) RETURNS text CREATE FUNCTION subtransaction_ctx_test(what_error text = NULL) RETURNS text
AS $$ AS $$
with plpy.subtransaction(): with plpy.subtransaction():
......
This diff is collapsed.
This diff is collapsed.
...@@ -242,12 +242,6 @@ PLy_traceback(PyObject *e, PyObject *v, PyObject *tb, ...@@ -242,12 +242,6 @@ PLy_traceback(PyObject *e, PyObject *v, PyObject *tb,
PG_TRY(); PG_TRY();
{ {
/*
* Ancient versions of Python (circa 2.3) contain a bug whereby
* the fetches below can fail if the error indicator is set.
*/
PyErr_Clear();
lineno = PyObject_GetAttrString(tb, "tb_lineno"); lineno = PyObject_GetAttrString(tb, "tb_lineno");
if (lineno == NULL) if (lineno == NULL)
elog(ERROR, "could not get line number from Python traceback"); elog(ERROR, "could not get line number from Python traceback");
......
...@@ -59,16 +59,6 @@ ...@@ -59,16 +59,6 @@
#include <Python.h> #include <Python.h>
#endif #endif
/*
* Py_ssize_t compat for Python <= 2.4
*/
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#endif
/* /*
* Python 2/3 strings/unicode/bytes handling. Python 2 has strings * Python 2/3 strings/unicode/bytes handling. Python 2 has strings
* and unicode, Python 3 has strings, which are unicode on the C * and unicode, Python 3 has strings, which are unicode on the C
...@@ -80,15 +70,6 @@ typedef int Py_ssize_t; ...@@ -80,15 +70,6 @@ typedef int Py_ssize_t;
* string to a Python string it converts the C string from the * string to a Python string it converts the C string from the
* PostgreSQL server encoding to a Python Unicode object. * PostgreSQL server encoding to a Python Unicode object.
*/ */
#if PY_VERSION_HEX < 0x02060000
/* This is exactly the compatibility layer that Python 2.6 uses. */
#define PyBytes_AsString PyString_AsString
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
#define PyBytes_Size PyString_Size
#define PyObject_Bytes PyObject_Str
#endif
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
#define PyString_Check(x) 0 #define PyString_Check(x) 0
#define PyString_AsString(x) PLyUnicode_AsString(x) #define PyString_AsString(x) PLyUnicode_AsString(x)
...@@ -104,16 +85,6 @@ typedef int Py_ssize_t; ...@@ -104,16 +85,6 @@ typedef int Py_ssize_t;
#define PyInt_AsLong(x) PyLong_AsLong(x) #define PyInt_AsLong(x) PyLong_AsLong(x)
#endif #endif
/*
* PyVarObject_HEAD_INIT was added in Python 2.6. Its use is
* necessary to handle both Python 2 and 3. This replacement
* definition is for Python <=2.5
*/
#ifndef PyVarObject_HEAD_INIT
#define PyVarObject_HEAD_INIT(type, size) \
PyObject_HEAD_INIT(type) size,
#endif
/* Python 3 removed the Py_TPFLAGS_HAVE_ITER flag */ /* Python 3 removed the Py_TPFLAGS_HAVE_ITER flag */
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
#define Py_TPFLAGS_HAVE_ITER 0 #define Py_TPFLAGS_HAVE_ITER 0
......
...@@ -8,43 +8,6 @@ CREATE TABLE subtransaction_tbl ( ...@@ -8,43 +8,6 @@ CREATE TABLE subtransaction_tbl (
i integer i integer
); );
-- Explicit case for Python <2.6
CREATE FUNCTION subtransaction_test(what_error text = NULL) RETURNS text
AS $$
import sys
subxact = plpy.subtransaction()
subxact.__enter__()
exc = True
try:
try:
plpy.execute("INSERT INTO subtransaction_tbl VALUES (1)")
plpy.execute("INSERT INTO subtransaction_tbl VALUES (2)")
if what_error == "SPI":
plpy.execute("INSERT INTO subtransaction_tbl VALUES ('oops')")
elif what_error == "Python":
raise Exception("Python exception")
except:
exc = False
subxact.__exit__(*sys.exc_info())
raise
finally:
if exc:
subxact.__exit__(None, None, None)
$$ LANGUAGE plpythonu;
SELECT subtransaction_test();
SELECT * FROM subtransaction_tbl;
TRUNCATE subtransaction_tbl;
SELECT subtransaction_test('SPI');
SELECT * FROM subtransaction_tbl;
TRUNCATE subtransaction_tbl;
SELECT subtransaction_test('Python');
SELECT * FROM subtransaction_tbl;
TRUNCATE subtransaction_tbl;
-- Context manager case for Python >=2.6
CREATE FUNCTION subtransaction_ctx_test(what_error text = NULL) RETURNS text CREATE FUNCTION subtransaction_ctx_test(what_error text = NULL) RETURNS text
AS $$ AS $$
with plpy.subtransaction(): with plpy.subtransaction():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment