3636/** the Decimal object **/
3737
3838static PyObject *
39- pdecimal_str (pdecimalObject * self )
39+ pdecimal_getquoted (pdecimalObject * self , PyObject * args )
4040{
4141 PyObject * check , * res = NULL ;
4242 check = PyObject_CallMethod (self -> wrapped , "is_finite" , NULL );
@@ -45,7 +45,7 @@ pdecimal_str(pdecimalObject *self)
4545 goto end ;
4646 }
4747 else if (check ) {
48- res = Text_FromUTF8 ("'NaN'::numeric" );
48+ res = Bytes_FromString ("'NaN'::numeric" );
4949 goto end ;
5050 }
5151
@@ -57,7 +57,7 @@ pdecimal_str(pdecimalObject *self)
5757 goto end ;
5858 }
5959 if (PyObject_IsTrue (check )) {
60- res = Text_FromUTF8 ("'NaN'::numeric" );
60+ res = Bytes_FromString ("'NaN'::numeric" );
6161 goto end ;
6262 }
6363
@@ -66,21 +66,29 @@ pdecimal_str(pdecimalObject *self)
6666 goto end ;
6767 }
6868 if (PyObject_IsTrue (check )) {
69- res = Text_FromUTF8 ("'NaN'::numeric" );
69+ res = Bytes_FromString ("'NaN'::numeric" );
7070 goto end ;
7171 }
7272
7373 res = PyObject_Str (self -> wrapped );
74+ #if PY_MAJOR_VERSION > 2
75+ /* unicode to bytes in Py3 */
76+ if (res ) {
77+ PyObject * tmp = PyUnicode_AsUTF8String (res );
78+ Py_DECREF (res );
79+ res = tmp ;
80+ }
81+ #endif
7482
7583end :
7684 Py_XDECREF (check );
7785 return res ;
7886}
7987
8088static PyObject *
81- pdecimal_getquoted (pdecimalObject * self , PyObject * args )
89+ pdecimal_str (pdecimalObject * self )
8290{
83- return pdecimal_str ( self );
91+ return psycopg_ensure_text ( pdecimal_getquoted ( self , NULL ) );
8492}
8593
8694static PyObject *
0 commit comments