mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Preliminary test for a BYTES adapter.
Allow returning unparsed bytes from databases with mixed encodings. See issue #519.
This commit is contained in:
parent
4a41c9a8cc
commit
f713dc9fc1
|
@ -35,7 +35,7 @@ This module holds all the extensions to the DBAPI-2.0 provided by psycopg.
|
||||||
import re as _re
|
import re as _re
|
||||||
|
|
||||||
from psycopg2._psycopg import ( # noqa
|
from psycopg2._psycopg import ( # noqa
|
||||||
BINARYARRAY, BOOLEAN, BOOLEANARRAY, DATE, DATEARRAY, DATETIMEARRAY,
|
BINARYARRAY, BOOLEAN, BOOLEANARRAY, BYTES, DATE, DATEARRAY, DATETIMEARRAY,
|
||||||
DECIMAL, DECIMALARRAY, FLOAT, FLOATARRAY, INTEGER, INTEGERARRAY,
|
DECIMAL, DECIMALARRAY, FLOAT, FLOATARRAY, INTEGER, INTEGERARRAY,
|
||||||
INTERVAL, INTERVALARRAY, LONGINTEGER, LONGINTEGERARRAY, ROWIDARRAY,
|
INTERVAL, INTERVALARRAY, LONGINTEGER, LONGINTEGERARRAY, ROWIDARRAY,
|
||||||
STRINGARRAY, TIME, TIMEARRAY, UNICODE, UNICODEARRAY,
|
STRINGARRAY, TIME, TIMEARRAY, UNICODE, UNICODEARRAY,
|
||||||
|
|
|
@ -75,18 +75,16 @@ typecast_FLOAT_cast(const char *s, Py_ssize_t len, PyObject *curs)
|
||||||
return flo;
|
return flo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** STRING - cast strings of any type to python string **/
|
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION < 3
|
/** BYTES - cast strings of any type to python bytes **/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
typecast_STRING_cast(const char *s, Py_ssize_t len, PyObject *curs)
|
typecast_BYTES_cast(const char *s, Py_ssize_t len, PyObject *curs)
|
||||||
{
|
{
|
||||||
if (s == NULL) { Py_RETURN_NONE; }
|
if (s == NULL) { Py_RETURN_NONE; }
|
||||||
return PyString_FromStringAndSize(s, len);
|
return Bytes_FromStringAndSize(s, len);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#define typecast_STRING_cast typecast_UNICODE_cast
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** UNICODE - cast strings of any type to a python unicode object **/
|
/** UNICODE - cast strings of any type to a python unicode object **/
|
||||||
|
|
||||||
|
@ -101,6 +99,16 @@ typecast_UNICODE_cast(const char *s, Py_ssize_t len, PyObject *curs)
|
||||||
return conn_decode(conn, s, len);
|
return conn_decode(conn, s, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** STRING - cast strings of any type to python string **/
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
|
#define typecast_STRING_cast typecast_BYTES_cast
|
||||||
|
#else
|
||||||
|
#define typecast_STRING_cast typecast_UNICODE_cast
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/** BOOLEAN - cast boolean value into right python object **/
|
/** BOOLEAN - cast boolean value into right python object **/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -3,7 +3,6 @@ static long int typecast_LONGINTEGER_types[] = {20, 0};
|
||||||
static long int typecast_INTEGER_types[] = {23, 21, 0};
|
static long int typecast_INTEGER_types[] = {23, 21, 0};
|
||||||
static long int typecast_FLOAT_types[] = {701, 700, 0};
|
static long int typecast_FLOAT_types[] = {701, 700, 0};
|
||||||
static long int typecast_DECIMAL_types[] = {1700, 0};
|
static long int typecast_DECIMAL_types[] = {1700, 0};
|
||||||
static long int typecast_UNICODE_types[] = {19, 18, 25, 1042, 1043, 0};
|
|
||||||
static long int typecast_STRING_types[] = {19, 18, 25, 1042, 1043, 0};
|
static long int typecast_STRING_types[] = {19, 18, 25, 1042, 1043, 0};
|
||||||
static long int typecast_BOOLEAN_types[] = {16, 0};
|
static long int typecast_BOOLEAN_types[] = {16, 0};
|
||||||
static long int typecast_DATETIME_types[] = {1114, 0};
|
static long int typecast_DATETIME_types[] = {1114, 0};
|
||||||
|
@ -39,8 +38,9 @@ static typecastObject_initlist typecast_builtins[] = {
|
||||||
{"INTEGER", typecast_INTEGER_types, typecast_INTEGER_cast, NULL},
|
{"INTEGER", typecast_INTEGER_types, typecast_INTEGER_cast, NULL},
|
||||||
{"FLOAT", typecast_FLOAT_types, typecast_FLOAT_cast, NULL},
|
{"FLOAT", typecast_FLOAT_types, typecast_FLOAT_cast, NULL},
|
||||||
{"DECIMAL", typecast_DECIMAL_types, typecast_DECIMAL_cast, NULL},
|
{"DECIMAL", typecast_DECIMAL_types, typecast_DECIMAL_cast, NULL},
|
||||||
{"UNICODE", typecast_UNICODE_types, typecast_UNICODE_cast, NULL},
|
{"UNICODE", typecast_STRING_types, typecast_UNICODE_cast, NULL},
|
||||||
{"STRING", typecast_STRING_types, typecast_STRING_cast, NULL},
|
{"STRING", typecast_STRING_types, typecast_STRING_cast, NULL},
|
||||||
|
{"BYTES", typecast_STRING_types, typecast_BYTES_cast, NULL},
|
||||||
{"BOOLEAN", typecast_BOOLEAN_types, typecast_BOOLEAN_cast, NULL},
|
{"BOOLEAN", typecast_BOOLEAN_types, typecast_BOOLEAN_cast, NULL},
|
||||||
{"DATETIME", typecast_DATETIME_types, typecast_DATETIME_cast, NULL},
|
{"DATETIME", typecast_DATETIME_types, typecast_DATETIME_cast, NULL},
|
||||||
{"DATETIMETZ", typecast_DATETIMETZ_types, typecast_DATETIMETZ_cast, NULL},
|
{"DATETIMETZ", typecast_DATETIMETZ_types, typecast_DATETIMETZ_cast, NULL},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user