Changeset 582


Ignore:
Timestamp:
Nov 21, 2015, 6:51:18 PM (4 years ago)
Author:
cito
Message:

Make the module name available on the class

That's a bit more reasonable than returning it in the getattr method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/pgmodule.c

    r581 r582  
    5555
    5656/* default values */
    57 #define MODULE_NAME                     "pg"
    58 #define MODULE_NAME_DB          "pgdb"
    5957#define PG_ARRAYSIZE                    1
    6058
     
    960958        if (!strcmp(name, "error"))
    961959                return PyStr_FromString(PQerrorMessage(self->pgcnx->cnx));
    962 
    963         /* module name */
    964         if (!strcmp(name, "__module__"))
    965                 return PyStr_FromString(MODULE_NAME);
    966960
    967961        /* seeks name in methods (fallback) */
     
    22542248#endif
    22552249
    2256         /* module name */
    2257         if (!strcmp(name, "__module__"))
    2258                 return PyStr_FromString(MODULE_NAME);
    2259 
    22602250        return PyObject_GenericGetAttr((PyObject *) self, nameobj);
    22612251}
     
    28682858        if (!strcmp(name, "nfields"))
    28692859                return PyInt_FromLong(self->num_fields);
    2870 
    2871         /* module name */
    2872         if (!strcmp(name, "__module__"))
    2873                 return PyStr_FromString(MODULE_NAME_DB);
    28742860
    28752861        /* seeks name in methods (fallback) */
     
    35323518        }
    35333519
    3534         /* module name */
    3535         if (!strcmp(name, "__module__"))
    3536                 return PyStr_FromString(MODULE_NAME);
    3537 
    35383520        return PyObject_GenericGetAttr((PyObject *) self, nameobj);
    35393521}
     
    42174199MODULE_INIT_FUNC(_pg)
    42184200{
    4219         PyObject   *mod, *dict, *v;
     4201        PyObject   *mod, *dict, *s;
    42204202
    42214203        /* Create the module and add the functions */
     
    42474229                ) return NULL;
    42484230
     4231        /* make the module names available */
     4232        s = PyStr_FromString("pg");
     4233        PyDict_SetItemString(connType.tp_dict, "__module__", s);
     4234        PyDict_SetItemString(noticeType.tp_dict, "__module__", s);
     4235        PyDict_SetItemString(queryType.tp_dict, "__module__", s);
     4236#ifdef LARGE_OBJECTS
     4237        PyDict_SetItemString(largeType.tp_dict, "__module__", s);
     4238#endif
     4239        Py_DECREF(s);
     4240        s = PyStr_FromString("pgdb");
     4241        PyDict_SetItemString(sourceType.tp_dict, "__module__", s);
     4242        Py_DECREF(s);
     4243
    42494244        dict = PyModule_GetDict(mod);
    42504245
     
    42854280
    42864281        /* Make the version available */
    4287         v = PyStr_FromString(PyPgVersion);
    4288         PyDict_SetItemString(dict, "version", v);
    4289         PyDict_SetItemString(dict, "__version__", v);
    4290         Py_DECREF(v);
     4282        s = PyStr_FromString(PyPgVersion);
     4283        PyDict_SetItemString(dict, "version", s);
     4284        PyDict_SetItemString(dict, "__version__", s);
     4285        Py_DECREF(s);
    42914286
    42924287        /* results type for queries */
Note: See TracChangeset for help on using the changeset viewer.