mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-16 17:10:32 +03:00
Dropped project wide type to define encodings table
This commit is contained in:
parent
8f17ccf784
commit
1839806c3c
|
@ -59,11 +59,6 @@ extern HIDDEN PyObject *psycoEncodings;
|
||||||
/* SQL NULL */
|
/* SQL NULL */
|
||||||
extern HIDDEN PyObject *psyco_null;
|
extern HIDDEN PyObject *psyco_null;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char *pgenc;
|
|
||||||
char *pyenc;
|
|
||||||
} encodingPair;
|
|
||||||
|
|
||||||
/* Exceptions docstrings */
|
/* Exceptions docstrings */
|
||||||
#define Error_doc \
|
#define Error_doc \
|
||||||
"Base class for error exceptions."
|
"Base class for error exceptions."
|
||||||
|
|
|
@ -503,11 +503,11 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* psyco_encodings_fill
|
/* Fill the module's postgresql<->python encoding table */
|
||||||
|
static struct {
|
||||||
Fill the module's postgresql<->python encoding table */
|
char *pgenc;
|
||||||
|
char *pyenc;
|
||||||
static encodingPair encodings[] = {
|
} enctable[] = {
|
||||||
{"ABC", "cp1258"},
|
{"ABC", "cp1258"},
|
||||||
{"ALT", "cp866"},
|
{"ALT", "cp866"},
|
||||||
{"BIG5", "big5"},
|
{"BIG5", "big5"},
|
||||||
|
@ -589,15 +589,25 @@ static encodingPair encodings[] = {
|
||||||
*
|
*
|
||||||
* Return 0 on success, else -1 and set an exception.
|
* Return 0 on success, else -1 and set an exception.
|
||||||
*/
|
*/
|
||||||
static int psyco_encodings_fill(PyObject *dict)
|
RAISES_NEG static int
|
||||||
|
encodings_init(PyObject *module)
|
||||||
{
|
{
|
||||||
PyObject *value = NULL;
|
PyObject *value = NULL;
|
||||||
encodingPair *enc;
|
int i;
|
||||||
int rv = -1;
|
int rv = -1;
|
||||||
|
|
||||||
for (enc = encodings; enc->pgenc != NULL; enc++) {
|
Dprintf("psycopgmodule: initializing encodings table");
|
||||||
if (!(value = Text_FromUTF8(enc->pyenc))) { goto exit; }
|
|
||||||
if (0 != PyDict_SetItemString(dict, enc->pgenc, value)) { goto exit; }
|
if (!(psycoEncodings = PyDict_New())) { goto exit; }
|
||||||
|
Py_INCREF(psycoEncodings);
|
||||||
|
PyModule_AddObject(module, "encodings", psycoEncodings);
|
||||||
|
|
||||||
|
for (i = 0; enctable[i].pgenc != NULL; i++) {
|
||||||
|
if (!(value = Text_FromUTF8(enctable[i].pyenc))) { goto exit; }
|
||||||
|
if (0 > PyDict_SetItemString(
|
||||||
|
psycoEncodings, enctable[i].pgenc, value)) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
Py_CLEAR(value);
|
Py_CLEAR(value);
|
||||||
}
|
}
|
||||||
rv = 0;
|
rv = 0;
|
||||||
|
@ -945,16 +955,13 @@ INIT_MODULE(_psycopg)(void)
|
||||||
if (!module) { goto exit; }
|
if (!module) { goto exit; }
|
||||||
|
|
||||||
/* other mixed initializations of module-level variables */
|
/* other mixed initializations of module-level variables */
|
||||||
if (!(psycoEncodings = PyDict_New())) { goto exit; }
|
|
||||||
if (0 != psyco_encodings_fill(psycoEncodings)) { goto exit; }
|
|
||||||
if (!(psyco_null = Bytes_FromString("NULL"))) { goto exit; }
|
if (!(psyco_null = Bytes_FromString("NULL"))) { goto exit; }
|
||||||
|
|
||||||
if (0 > add_module_constants(module)) { goto exit; }
|
if (0 > add_module_constants(module)) { goto exit; }
|
||||||
if (0 > add_module_types(module)) { goto exit; }
|
if (0 > add_module_types(module)) { goto exit; }
|
||||||
|
|
||||||
/* encodings dictionary in module dictionary */
|
/* encodings dictionary in module dictionary */
|
||||||
Py_INCREF(psycoEncodings);
|
if (0 > encodings_init(module)) { goto exit; }
|
||||||
PyModule_AddObject(module, "encodings", psycoEncodings);
|
|
||||||
|
|
||||||
dict = PyModule_GetDict(module);
|
dict = PyModule_GetDict(module);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user