Where a string is desired, test for PyBaseString_Type derived type,

rather than using PyString_Check/PyUnicode_Check.
This commit is contained in:
Andrew McNamara 2005-01-10 12:22:48 +00:00
parent 9fa0946771
commit 37d2bdfa76
1 changed files with 6 additions and 15 deletions

View File

@ -39,6 +39,9 @@ module instead.
#endif #endif
/* end 2.2 compatibility macros */ /* end 2.2 compatibility macros */
#define IS_BASESTRING(o) \
PyObject_TypeCheck(o, &PyBaseString_Type)
static PyObject *error_obj; /* CSV exception */ static PyObject *error_obj; /* CSV exception */
static PyObject *dialects; /* Dialect registry */ static PyObject *dialects; /* Dialect registry */
@ -230,11 +233,7 @@ _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
else { else {
if (src == Py_None) if (src == Py_None)
*target = NULL; *target = NULL;
else if (!PyString_Check(src) else if (!IS_BASESTRING(src)) {
#ifdef Py_USING_UNICODE
&& !PyUnicode_Check(src)
#endif
) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"\"%s\" must be an string", name); "\"%s\" must be an string", name);
return -1; return -1;
@ -298,11 +297,7 @@ dialect_instantiate(PyObject *dialect)
{ {
Py_INCREF(dialect); Py_INCREF(dialect);
/* If dialect is a string, look it up in our registry */ /* If dialect is a string, look it up in our registry */
if (PyString_Check(dialect) if (IS_BASESTRING(dialect)) {
#ifdef Py_USING_UNICODE
|| PyUnicode_Check(dialect)
#endif
) {
PyObject * new_dia; PyObject * new_dia;
new_dia = get_dialect_from_registry(dialect); new_dia = get_dialect_from_registry(dialect);
Py_DECREF(dialect); Py_DECREF(dialect);
@ -1372,11 +1367,7 @@ csv_register_dialect(PyObject *module, PyObject *args)
if (!PyArg_UnpackTuple(args, "", 2, 2, &name_obj, &dialect_obj)) if (!PyArg_UnpackTuple(args, "", 2, 2, &name_obj, &dialect_obj))
return NULL; return NULL;
if (!PyString_Check(name_obj) if (!IS_BASESTRING(name_obj)) {
#ifdef Py_USING_UNICODE
&& !PyUnicode_Check(name_obj)
#endif
) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"dialect name must be a string or unicode"); "dialect name must be a string or unicode");
return NULL; return NULL;