|
@@ -275,7 +275,11 @@ PyObject *build_string_vector(const struct String_vector *sv)
|
|
if (ret) {
|
|
if (ret) {
|
|
int i;
|
|
int i;
|
|
for (i=0;i<sv->count;++i) {
|
|
for (i=0;i<sv->count;++i) {
|
|
|
|
+#if PY_MAJOR_VERSION >= 3
|
|
|
|
+ PyObject *s = PyUnicode_FromString(sv->data[i]);
|
|
|
|
+#else
|
|
PyObject *s = PyString_FromString(sv->data[i]);
|
|
PyObject *s = PyString_FromString(sv->data[i]);
|
|
|
|
+#endif
|
|
if (!s) {
|
|
if (!s) {
|
|
if (ret != Py_None) {
|
|
if (ret != Py_None) {
|
|
Py_DECREF(ret);
|
|
Py_DECREF(ret);
|
|
@@ -381,9 +385,15 @@ int parse_acls(struct ACL_vector *acls, PyObject *pyacls)
|
|
a = PyList_GetItem(pyacls, i);
|
|
a = PyList_GetItem(pyacls, i);
|
|
// a is now a dictionary
|
|
// a is now a dictionary
|
|
PyObject *perms = PyDict_GetItemString( a, "perms" );
|
|
PyObject *perms = PyDict_GetItemString( a, "perms" );
|
|
|
|
+#if PY_MAJOR_VERSION >= 3
|
|
|
|
+ acls->data[i].perms = (int32_t)(PyLong_AsLong(perms));
|
|
|
|
+ acls->data[i].id.id = strdup( PyUnicode_AsUnicode( PyDict_GetItemString( a, "id" ) ) );
|
|
|
|
+ acls->data[i].id.scheme = strdup( PyUnicode_AsUnicode( PyDict_GetItemString( a, "scheme" ) ) );
|
|
|
|
+#else
|
|
acls->data[i].perms = (int32_t)(PyInt_AsLong(perms));
|
|
acls->data[i].perms = (int32_t)(PyInt_AsLong(perms));
|
|
acls->data[i].id.id = strdup( PyString_AsString( PyDict_GetItemString( a, "id" ) ) );
|
|
acls->data[i].id.id = strdup( PyString_AsString( PyDict_GetItemString( a, "id" ) ) );
|
|
acls->data[i].id.scheme = strdup( PyString_AsString( PyDict_GetItemString( a, "scheme" ) ) );
|
|
acls->data[i].id.scheme = strdup( PyString_AsString( PyDict_GetItemString( a, "scheme" ) ) );
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
@@ -1432,7 +1442,14 @@ PyObject *pyzoo_set_log_stream(PyObject *self, PyObject *args)
|
|
PyErr_SetString(PyExc_ValueError, "Must supply a Python object to set_log_stream");
|
|
PyErr_SetString(PyExc_ValueError, "Must supply a Python object to set_log_stream");
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
- if (!PyFile_Check(pystream)) {
|
|
|
|
|
|
+
|
|
|
|
+#if PY_MAJOR_VERSION >= 3
|
|
|
|
+ extern PyTypeObject PyIOBase_Type;
|
|
|
|
+ if (!PyObject_IsInstance(pystream, (PyObject *)&PyIOBase_Type)) {
|
|
|
|
+#else
|
|
|
|
+ if(!PyFile_Check(pystream)) {
|
|
|
|
+#endif
|
|
|
|
+
|
|
PyErr_SetString(PyExc_ValueError, "Must supply a file object to set_log_stream");
|
|
PyErr_SetString(PyExc_ValueError, "Must supply a file object to set_log_stream");
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
@@ -1443,7 +1460,14 @@ PyObject *pyzoo_set_log_stream(PyObject *self, PyObject *args)
|
|
|
|
|
|
log_stream = pystream;
|
|
log_stream = pystream;
|
|
Py_INCREF(log_stream);
|
|
Py_INCREF(log_stream);
|
|
- zoo_set_log_stream(PyFile_AsFile(log_stream));
|
|
|
|
|
|
+
|
|
|
|
+#if PY_MAJOR_VERSION >= 3
|
|
|
|
+ int fd = PyObject_AsFileDescriptor(log_stream);
|
|
|
|
+ FILE *fp = fdopen(fd, "w");
|
|
|
|
+#else
|
|
|
|
+ FILE *fp = PyFile_AsFile(log_stream);
|
|
|
|
+#endif
|
|
|
|
+ zoo_set_log_stream(fp);
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
Py_INCREF(Py_None);
|
|
return Py_None;
|
|
return Py_None;
|
|
@@ -1505,6 +1529,20 @@ static PyMethodDef ZooKeeperMethods[] = {
|
|
{NULL, NULL}
|
|
{NULL, NULL}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+#if PY_MAJOR_VERSION >= 3
|
|
|
|
+static struct PyModuleDef zookeeper_moddef = {
|
|
|
|
+ PyModuleDef_HEAD_INIT,
|
|
|
|
+ "zookeeper",
|
|
|
|
+ NULL,
|
|
|
|
+ 0,
|
|
|
|
+ ZooKeeperMethods,
|
|
|
|
+ 0,
|
|
|
|
+ 0,
|
|
|
|
+ 0,
|
|
|
|
+ 0
|
|
|
|
+};
|
|
|
|
+#endif
|
|
|
|
+
|
|
#define ADD_INTCONSTANT(x) PyModule_AddIntConstant(module, #x, ZOO_##x)
|
|
#define ADD_INTCONSTANT(x) PyModule_AddIntConstant(module, #x, ZOO_##x)
|
|
#define ADD_INTCONSTANTZ(x) PyModule_AddIntConstant(module, #x, Z##x)
|
|
#define ADD_INTCONSTANTZ(x) PyModule_AddIntConstant(module, #x, Z##x)
|
|
|
|
|
|
@@ -1512,10 +1550,18 @@ static PyMethodDef ZooKeeperMethods[] = {
|
|
Py_INCREF(x); \
|
|
Py_INCREF(x); \
|
|
PyModule_AddObject(module, #x, x);
|
|
PyModule_AddObject(module, #x, x);
|
|
|
|
|
|
-
|
|
|
|
|
|
+#if PY_MAJOR_VERSION >= 3
|
|
|
|
+PyMODINIT_FUNC PyInit_zookeeper(void) {
|
|
|
|
+#else
|
|
PyMODINIT_FUNC initzookeeper(void) {
|
|
PyMODINIT_FUNC initzookeeper(void) {
|
|
|
|
+#endif
|
|
PyEval_InitThreads();
|
|
PyEval_InitThreads();
|
|
- PyObject *module = Py_InitModule("zookeeper", ZooKeeperMethods );
|
|
|
|
|
|
+
|
|
|
|
+#if PY_MAJOR_VERSION >= 3
|
|
|
|
+ PyObject *module = PyModule_Create(&zookeeper_moddef);
|
|
|
|
+#else
|
|
|
|
+ PyObject *module = Py_InitModule("zookeeper", ZooKeeperMethods);
|
|
|
|
+#endif
|
|
if (init_zhandles(32) == 0) {
|
|
if (init_zhandles(32) == 0) {
|
|
return; // TODO: Is there any way to raise an exception here?
|
|
return; // TODO: Is there any way to raise an exception here?
|
|
}
|
|
}
|
|
@@ -1611,4 +1657,8 @@ PyMODINIT_FUNC initzookeeper(void) {
|
|
ADD_EXCEPTION(ClosingException);
|
|
ADD_EXCEPTION(ClosingException);
|
|
ADD_EXCEPTION(NothingException);
|
|
ADD_EXCEPTION(NothingException);
|
|
ADD_EXCEPTION(SessionMovedException);
|
|
ADD_EXCEPTION(SessionMovedException);
|
|
|
|
+
|
|
|
|
+#if PY_MAJOR_VERSION >= 3
|
|
|
|
+ return module;
|
|
|
|
+#endif
|
|
}
|
|
}
|