[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.220,2.221
Jeremy Hylton
jhylton@users.sourceforge.net
2001年7月30日 15:45:21 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv29344
Modified Files:
bltinmodule.c
Log Message:
Do for hasattr() what was done for getattr()
Namely, an exception is raised if the second arg to hasattr() is not a
string or Unicode.
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.220
retrieving revision 2.221
diff -C2 -d -r2.220 -r2.221
*** bltinmodule.c 2001年07月30日 22:39:31 2.220
--- bltinmodule.c 2001年07月30日 22:45:19 2.221
***************
*** 945,948 ****
--- 945,959 ----
if (!PyArg_ParseTuple(args, "OO:hasattr", &v, &name))
return NULL;
+ if (PyUnicode_Check(name)) {
+ name = _PyUnicode_AsDefaultEncodedString(name, NULL);
+ if (name == NULL)
+ return NULL;
+ }
+
+ if (!PyString_Check(name)) {
+ PyErr_SetString(PyExc_TypeError,
+ "attribute name must be string");
+ return NULL;
+ }
v = PyObject_GetAttr(v, name);
if (v == NULL) {