@@ -39,6 +39,9 @@ module instead.
3939#endif
4040/* end 2.2 compatibility macros */
4141
42+ #define IS_BASESTRING (o ) \
43+ PyObject_TypeCheck(o, &PyBaseString_Type)
44+
4245static PyObject * error_obj ; /* CSV exception */
4346static PyObject * dialects ; /* Dialect registry */
4447
@@ -230,11 +233,7 @@ _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
230233 else {
231234 if (src == Py_None )
232235 * target = NULL ;
233- else if (!PyString_Check (src )
234- #ifdef Py_USING_UNICODE
235- && !PyUnicode_Check (src )
236- #endif
237- ) {
236+ else if (!IS_BASESTRING (src )) {
238237 PyErr_Format (PyExc_TypeError ,
239238 "\"%s\" must be an string" , name );
240239 return -1 ;
@@ -298,11 +297,7 @@ dialect_instantiate(PyObject *dialect)
298297{
299298 Py_INCREF (dialect );
300299 /* If dialect is a string, look it up in our registry */
301- if (PyString_Check (dialect )
302- #ifdef Py_USING_UNICODE
303- || PyUnicode_Check (dialect )
304- #endif
305- ) {
300+ if (IS_BASESTRING (dialect )) {
306301 PyObject * new_dia ;
307302 new_dia = get_dialect_from_registry (dialect );
308303 Py_DECREF (dialect );
@@ -1372,11 +1367,7 @@ csv_register_dialect(PyObject *module, PyObject *args)
13721367
13731368 if (!PyArg_UnpackTuple (args , "" , 2 , 2 , & name_obj , & dialect_obj ))
13741369 return NULL ;
1375- if (!PyString_Check (name_obj )
1376- #ifdef Py_USING_UNICODE
1377- && !PyUnicode_Check (name_obj )
1378- #endif
1379- ) {
1370+ if (!IS_BASESTRING (name_obj )) {
13801371 PyErr_SetString (PyExc_TypeError ,
13811372 "dialect name must be a string or unicode" );
13821373 return NULL ;
0 commit comments