comparison _mysql_connections.c @ 42:fdf0cabb27be MySQLdb

Member stuff is stable post py2.2, so remove the MyMember* workarounds
author kylev
date Tue, 17 Feb 2009 05:55:24 +0000
parents fbf2470ea3d4
children
comparison
equal deleted inserted replaced
41:e80676c3505f 42:fdf0cabb27be
1316 _mysql_ConnectionObject_use_result__doc__ 1316 _mysql_ConnectionObject_use_result__doc__
1317 }, 1317 },
1318 {NULL, NULL} /* sentinel */ 1318 {NULL, NULL} /* sentinel */
1319 }; 1319 };
1320 1320
1321 static MyMemberlist(_mysql_ConnectionObject_memberlist)[] = { 1321 static struct PyMemberDef _mysql_ConnectionObject_memberlist[] = {
1322 MyMember( 1322 {
1323 "open", 1323 "open",
1324 T_INT, 1324 T_INT,
1325 offsetof(_mysql_ConnectionObject,open), 1325 offsetof(_mysql_ConnectionObject, open),
1326 RO, 1326 RO,
1327 "True if connection is open" 1327 "True if connection is open"
1328 ), 1328 },
1329 MyMember( 1329 {
1330 "converter", 1330 "converter",
1331 T_OBJECT, 1331 T_OBJECT,
1332 offsetof(_mysql_ConnectionObject,converter), 1332 offsetof(_mysql_ConnectionObject, converter),
1333 0, 1333 0,
1334 "Type conversion mapping" 1334 "Type conversion mapping"
1335 ), 1335 },
1336 MyMember( 1336 {
1337 "server_capabilities", 1337 "server_capabilities",
1338 T_UINT, 1338 T_UINT,
1339 offsetof(_mysql_ConnectionObject,connection.server_capabilities), 1339 offsetof(_mysql_ConnectionObject, connection.server_capabilities),
1340 RO, 1340 RO,
1341 "Capabilites of server; consult MySQLdb.constants.CLIENT" 1341 "Capabilites of server; consult MySQLdb.constants.CLIENT"
1342 ), 1342 },
1343 MyMember( 1343 {
1344 "port", 1344 "port",
1345 T_UINT, 1345 T_UINT,
1346 offsetof(_mysql_ConnectionObject,connection.port), 1346 offsetof(_mysql_ConnectionObject, connection.port),
1347 RO, 1347 RO,
1348 "TCP/IP port of the server connection" 1348 "TCP/IP port of the server connection"
1349 ), 1349 },
1350 MyMember( 1350 {
1351 "client_flag", 1351 "client_flag",
1352 T_UINT, 1352 T_UINT,
1353 RO, 1353 RO,
1354 offsetof(_mysql_ConnectionObject,connection.client_flag), 1354 offsetof(_mysql_ConnectionObject, connection.client_flag),
1355 "Client flags; refer to MySQLdb.constants.CLIENT" 1355 "Client flags; refer to MySQLdb.constants.CLIENT"
1356 ), 1356 },
1357 {NULL} /* Sentinel */ 1357 {NULL} /* Sentinel */
1358 }; 1358 };
1359 1359
1360 static PyObject * 1360 static PyObject *
1361 _mysql_ConnectionObject_getattr( 1361 _mysql_ConnectionObject_getattr(
1362 _mysql_ConnectionObject *self, 1362 _mysql_ConnectionObject *self,
1363 char *name) 1363 char *name)
1364 { 1364 {
1365 PyObject *res; 1365 PyObject *res;
1366 struct PyMemberDef *l;
1366 1367
1367 res = Py_FindMethod(_mysql_ConnectionObject_methods, (PyObject *)self, name); 1368 res = Py_FindMethod(_mysql_ConnectionObject_methods, (PyObject *)self, name);
1368 if (res != NULL) 1369 if (res != NULL)
1369 return res; 1370 return res;
1370 PyErr_Clear(); 1371 PyErr_Clear();
1371 if (strcmp(name, "closed") == 0) 1372 if (strcmp(name, "closed") == 0)
1372 return PyInt_FromLong((long)!(self->open)); 1373 return PyInt_FromLong((long)!(self->open));
1373 #if PY_VERSION_HEX < 0x02020000 1374
1374 return PyMember_Get((char *)self, _mysql_ConnectionObject_memberlist, name); 1375 for (l = _mysql_ConnectionObject_memberlist; l->name != NULL; l++) {
1375 #else 1376 if (strcmp(l->name, name) == 0)
1376 { 1377 return PyMember_GetOne((char *)self, l);
1377 MyMemberlist(*l);
1378 for (l = _mysql_ConnectionObject_memberlist; l->name != NULL; l++) {
1379 if (strcmp(l->name, name) == 0)
1380 return PyMember_GetOne((char *)self, l);
1381 }
1382 PyErr_SetString(PyExc_AttributeError, name);
1383 return NULL;
1384 } 1378 }
1385 #endif 1379
1380 PyErr_SetString(PyExc_AttributeError, name);
1381 return NULL;
1386 } 1382 }
1387 1383
1388 static int 1384 static int
1389 _mysql_ConnectionObject_setattr( 1385 _mysql_ConnectionObject_setattr(
1390 _mysql_ConnectionObject *self, 1386 _mysql_ConnectionObject *self,
1391 char *name, 1387 char *name,
1392 PyObject *v) 1388 PyObject *v)
1393 { 1389 {
1390 struct PyMemberDef *l;
1391
1394 if (v == NULL) { 1392 if (v == NULL) {
1395 PyErr_SetString(PyExc_AttributeError, 1393 PyErr_SetString(PyExc_AttributeError,
1396 "can't delete connection attributes"); 1394 "can't delete connection attributes");
1397 return -1; 1395 return -1;
1398 } 1396 }
1399 #if PY_VERSION_HEX < 0x02020000 1397
1400 return PyMember_Set((char *)self, _mysql_ConnectionObject_memberlist, name, v); 1398 for (l = _mysql_ConnectionObject_memberlist; l->name != NULL; l++)
1401 #else 1399 if (strcmp(l->name, name) == 0)
1402 { 1400 return PyMember_SetOne((char *)self, l, v);
1403 MyMemberlist(*l); 1401
1404 for (l = _mysql_ConnectionObject_memberlist; l->name != NULL; l++)
1405 if (strcmp(l->name, name) == 0)
1406 return PyMember_SetOne((char *)self, l, v);
1407 }
1408 PyErr_SetString(PyExc_AttributeError, name); 1402 PyErr_SetString(PyExc_AttributeError, name);
1409 return -1; 1403 return -1;
1410 #endif
1411 } 1404 }
1412 1405
1413 PyTypeObject _mysql_ConnectionObject_Type = { 1406 PyTypeObject _mysql_ConnectionObject_Type = {
1414 PyObject_HEAD_INIT(NULL) 1407 PyObject_HEAD_INIT(NULL)
1415 0, 1408 0,
1461 0, /* (getiterfunc) tp_iter */ 1454 0, /* (getiterfunc) tp_iter */
1462 0, /* (iternextfunc) tp_iternext */ 1455 0, /* (iternextfunc) tp_iternext */
1463 1456
1464 /* Attribute descriptor and subclassing stuff */ 1457 /* Attribute descriptor and subclassing stuff */
1465 (struct PyMethodDef *)_mysql_ConnectionObject_methods, /* tp_methods */ 1458 (struct PyMethodDef *)_mysql_ConnectionObject_methods, /* tp_methods */
1466 (MyMemberlist(*))_mysql_ConnectionObject_memberlist, /* tp_members */ 1459 (struct PyMemberDef *)_mysql_ConnectionObject_memberlist, /* tp_members */
1467 0, /* (struct getsetlist *) tp_getset; */ 1460 0, /* (struct getsetlist *) tp_getset; */
1468 0, /* (struct _typeobject *) tp_base; */ 1461 0, /* (struct _typeobject *) tp_base; */
1469 0, /* (PyObject *) tp_dict */ 1462 0, /* (PyObject *) tp_dict */
1470 0, /* (descrgetfunc) tp_descr_get */ 1463 0, /* (descrgetfunc) tp_descr_get */
1471 0, /* (descrsetfunc) tp_descr_set */ 1464 0, /* (descrsetfunc) tp_descr_set */