summaryrefslogtreecommitdiff
path: root/src/hash_template.c
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2013-07-14 17:37:30 -0700
committerDwayne Litzenberger <dlitz@dlitz.net>2013-07-14 19:14:35 -0700
commit27ef33b36779bc19b89dd77b976e5500cfabc144 (patch)
treeccfbee90a624af4fe1fe5b18043e8b88c838df2e /src/hash_template.c
parent54d438aaa6fad49527a043a8df0842104e817069 (diff)
downloadpycrypto-27ef33b36779bc19b89dd77b976e5500cfabc144.tar.gz
Py3k cleanup: Always use tp_getattro
Diffstat (limited to 'src/hash_template.c')
-rw-r--r--src/hash_template.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/src/hash_template.c b/src/hash_template.c
index 2572577..f3f116d 100644
--- a/src/hash_template.c
+++ b/src/hash_template.c
@@ -184,32 +184,25 @@ static PyMethodDef ALG_methods[] = {
};
static PyObject *
-#ifdef IS_PY3K
ALG_getattro(PyObject *self, PyObject *attr)
-#else
-ALG_getattr(PyObject *self, char *name)
-#endif
{
-#ifdef IS_PY3K
- if (!PyUnicode_Check(attr))
+ if (!PyString_Check(attr))
goto generic;
-
- if (PyUnicode_CompareWithASCIIString(attr, "digest_size")==0)
- return PyInt_FromLong(DIGEST_SIZE);
- if (PyUnicode_CompareWithASCIIString(attr, "name")==0)
- return PyUnicode_FromString(_MODULE_STRING); /* we should try to be compatible with hashlib here */
-#else
- if (strcmp(name, "digest_size")==0)
+
+ if (PyString_CompareWithASCIIString(attr, "digest_size")==0)
return PyInt_FromLong(DIGEST_SIZE);
- if (strcmp(name, "name")==0)
+ if (PyString_CompareWithASCIIString(attr, "name")==0)
return PyString_FromString(_MODULE_STRING); /* we should try to be compatible with hashlib here */
-#endif
-#ifdef IS_PY3K
generic:
+#if PYTHON_API_VERSION >= 1011 /* Python 2.2 and later */
return PyObject_GenericGetAttr(self, attr);
#else
- return Py_FindMethod(ALG_methods, self, name);
+ if (PyString_Check(attr) < 0) {
+ PyErr_SetObject(PyExc_AttributeError, attr);
+ return NULL;
+ }
+ return Py_FindMethod(ALG_methods, (PyObject *)self, PyString_AsString(attr));
#endif
}
@@ -221,16 +214,11 @@ static PyTypeObject ALGtype = {
/* methods */
(destructor) ALG_dealloc, /*tp_dealloc*/
0, /*tp_print*/
-#ifdef IS_PY3K
- 0, /*tp_getattr*/
-#else
- ALG_getattr, /*tp_getattr*/
-#endif
+ 0, /*tp_getattr*/
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*/
@@ -245,6 +233,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*/
ALG_methods, /*tp_methods*/