Compatibility with CPython 2.5 though CPython 3.2
diff --git a/OpenSSL/crypto/x509name.c b/OpenSSL/crypto/x509name.c
index 4ff2c34..a62c957 100644
--- a/OpenSSL/crypto/x509name.c
+++ b/OpenSSL/crypto/x509name.c
@@ -202,13 +202,19 @@
char *buffer;
char *name;
- if (!PyString_CheckExact(nameobj) || !(name = PyString_AsString(nameobj))) {
+ if (!PyBytes_CheckExact(nameobj) && !PyUnicode_CheckExact(nameobj)) {
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
Py_TYPE(nameobj)->tp_name);
return -1;
}
+#ifdef PY3
+ name = PyBytes_AsString(PyUnicode_AsASCIIString(nameobj));
+#else
+ name = PyBytes_AsString(nameobj);
+#endif
+
if ((nid = OBJ_txt2nid(name)) == NID_undef)
{
/* Just like the case in the getattr function */
diff --git a/OpenSSL/ssl/connection.c b/OpenSSL/ssl/connection.c
index 993b628..5b304b1 100755
--- a/OpenSSL/ssl/connection.c
+++ b/OpenSSL/ssl/connection.c
@@ -336,7 +336,7 @@
int len, ret, err, flags;
char *buf;
-#if !defined(PYPY_VERSION) || PY_VERSION_HEX >= 0x02060000
+#if PY_VERSION_HEX >= 0x02060000
Py_buffer pbuf;
if (!PyArg_ParseTuple(args, "s*|i:send", &pbuf, &flags))
@@ -354,7 +354,7 @@
ret = SSL_write(self->ssl, buf, len);
MY_END_ALLOW_THREADS(self->tstate)
-#if !defined(PYPY_VERSION) || PY_VERSION_HEX >= 0x02060000
+#if PY_VERSION_HEX >= 0x02060000
PyBuffer_Release(&pbuf);
#endif
@@ -393,7 +393,7 @@
int len, ret, err, flags;
PyObject *pyret = Py_None;
-#if !defined(PYPY_VERSION) || PY_VERSION_HEX >= 0x02060000
+#if PY_VERSION_HEX >= 0x02060000
Py_buffer pbuf;
if (!PyArg_ParseTuple(args, "s*|i:sendall", &pbuf, &flags))
@@ -431,7 +431,7 @@
}
} while (len > 0);
-#if !defined(PYPY_VERSION) || PY_VERSION_HEX >= 0x02060000
+#if PY_VERSION_HEX >= 0x02060000
PyBuffer_Release(&pbuf);
#endif
diff --git a/OpenSSL/util.h b/OpenSSL/util.h
index 4cef481..e634b01 100644
--- a/OpenSSL/util.h
+++ b/OpenSSL/util.h
@@ -137,4 +137,8 @@
#define PyOpenSSL_LongToHex(o) PyNumber_ToBase(o, 16)
#endif
+#ifndef Py_TYPE
+#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+#endif
+
#endif