diff options
Diffstat (limited to 'src/stream_template.c')
-rw-r--r-- | src/stream_template.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/stream_template.c b/src/stream_template.c index 5ef1f1e..cb11a0c 100644 --- a/src/stream_template.c +++ b/src/stream_template.c @@ -189,36 +189,28 @@ static PyMethodDef ALGmethods[] = }; static PyObject * -#ifdef IS_PY3K ALGgetattro(PyObject *self, PyObject *attr) -#else -ALGgetattr(PyObject *self, char *name) -#endif { -#ifdef IS_PY3K - if (!PyUnicode_Check(attr)) + if (!PyString_Check(attr)) goto generic; - if (PyUnicode_CompareWithASCIIString(attr, "block_size") == 0) -#else - if (strcmp(name, "block_size") == 0) -#endif + if (PyString_CompareWithASCIIString(attr, "block_size") == 0) { return PyInt_FromLong(BLOCK_SIZE); } -#ifdef IS_PY3K - if (PyUnicode_CompareWithASCIIString(attr, "key_size") == 0) -#else - if (strcmp(name, "key_size") == 0) -#endif + if (PyString_CompareWithASCIIString(attr, "key_size") == 0) { return PyInt_FromLong(KEY_SIZE); } -#ifdef IS_PY3K generic: +#if PYTHON_API_VERSION >= 1011 /* Python 2.2 and later */ return PyObject_GenericGetAttr(self, attr); #else - return Py_FindMethod(ALGmethods, self, name); + if (PyString_Check(attr) < 0) { + PyErr_SetObject(PyExc_AttributeError, attr); + return NULL; + } + return Py_FindMethod(ALGmethods, (PyObject *)self, PyString_AsString(attr)); #endif } @@ -240,16 +232,11 @@ static PyTypeObject ALGtype = /* methods */ (destructor) ALGdealloc, /*tp_dealloc*/ 0, /*tp_print*/ -#ifdef IS_PY3K 0, /*tp_getattr*/ -#else - ALGgetattr, /*tp_getattr*/ -#endif 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ -#ifdef IS_PY3K 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ @@ -264,6 +251,7 @@ static PyTypeObject ALGtype = 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ +#if PYTHON_API_VERSION >= 1011 /* Python 2.2 and later */ 0, /*tp_iter*/ 0, /*tp_iternext*/ ALGmethods, /*tp_methods*/ |