]> granicus.if.org Git - postgresql/commit
Perform conversion from Python unicode to string/bytes object via UTF-8.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 6 Aug 2012 10:02:15 +0000 (13:02 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 6 Aug 2012 11:28:39 +0000 (14:28 +0300)
commit7fbe5aaaa8bd50e75474f8f671e66ec1b24a42ab
tree6da7a0066964d906a69f21e4dd233e91b6f1ab8e
parentbb49e3551b33a016f75095fe7388b25c332996c3
Perform conversion from Python unicode to string/bytes object via UTF-8.

We used to convert the unicode object directly to a string in the server
encoding by calling Python's PyUnicode_AsEncodedString function. In other
words, we used Python's routines to do the encoding. However, that has a
few problems. First of all, it required keeping a mapping table of Python
encoding names and PostgreSQL encodings. But the real killer was that Python
doesn't support EUC_TW and MULE_INTERNAL encodings at all.

Instead, convert the Python unicode object to UTF-8, and use PostgreSQL's
encoding conversion functions to convert from UTF-8 to server encoding. We
were already doing the same in the other direction in PLyUnicode_FromString,
so this is more consistent, too.

Note: This makes SQL_ASCII to behave more leniently. We used to map
SQL_ASCII to Python's 'ascii', which on Python means strict 7-bit ASCII
only, so you got an error if the python string contained anything but pure
ASCII. You no longer get an error; you get the UTF-8 representation of the
string instead.

Backpatch to 9.0, where these conversions were introduced.

Jan UrbaƄski
src/pl/plpython/expected/plpython_unicode_2.out [deleted file]
src/pl/plpython/expected/plpython_unicode_3.out [deleted file]
src/pl/plpython/plpython.c