PL/Python patch for Universal Newline Support
От | Michael Fuhr |
---|---|
Тема | PL/Python patch for Universal Newline Support |
Дата | |
Msg-id | 20050319050847.GA90344@winnie.fuhr.org обсуждение исходный текст |
Ответы |
Re: PL/Python patch for Universal Newline Support
|
Список | pgsql-patches |
The attached patch mimics Universal Newline Support for PL/Python functions. For background, see PEP 278 and the recent "plpython function problem workaround" thread in pgsql-general: http://www.python.org/peps/pep-0278.html http://archives.postgresql.org/pgsql-general/2005-03/msg00823.php In short, embedded Python code must have lines that end in \n, not \r\n or \r. This patch adds logic to PLy_procedure_munge_source() to skip \r followed by \n, otherwise to convert \r to \n. I tested it in HEAD but REL8_0_STABLE has the same version of plpython.c (1.58), so it should work there as well. Should the PL/Python documentation mention this behavior? If so then I can resubmit with a documentation patch. How should I submit regression tests? Here's what I did: CREATE FUNCTION test_lf() RETURNS integer AS 'x=100\ny=23\nreturn x+y\n' LANGUAGE plpythonu; CREATE FUNCTION test_crlf() RETURNS integer AS 'x=100\r\ny=23\r\nreturn x+y\r\n' LANGUAGE plpythonu; CREATE FUNCTION test_cr() RETURNS integer AS 'x=100\ry=23\rreturn x+y\r' LANGUAGE plpythonu; Here's what an unpatched system does: SELECT test_lf(); test_lf --------- 123 (1 row) SELECT test_cr(); ERROR: plpython: could not compile function "test_cr" DETAIL: exceptions.SyntaxError: invalid syntax (line 2) SELECT test_crlf(); ERROR: plpython: could not compile function "test_crlf" DETAIL: exceptions.SyntaxError: invalid syntax (line 2) Here's a patched system: SELECT test_lf(); test_lf --------- 123 (1 row) SELECT test_cr(); test_cr --------- 123 (1 row) SELECT test_crlf(); test_crlf ----------- 123 (1 row) This patch doesn't address the indentation problem mentioned here: http://archives.postgresql.org/pgsql-general/2005-03/msg00762.php The solution to that problem is still being discussed. -- Michael Fuhr http://www.fuhr.org/~mfuhr/
Вложения
В списке pgsql-patches по дате отправления: