From d8d27e297d6891a44afb70fa624eab862c8145c4 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 17 Sep 2014 17:29:01 -0400 Subject: support python 2 --- .gitignore | 1 + vt100module.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/.gitignore b/.gitignore index 2a4a9ba..be8ce46 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__ /build/ /MANIFEST /dist/ +*.pyc diff --git a/vt100module.c b/vt100module.c index f564b87..ed0d808 100644 --- a/vt100module.c +++ b/vt100module.c @@ -76,7 +76,11 @@ static PyObject *py_vt100_get_string_formatted(PyObject *self, PyObject *args) vt100_screen_get_string_formatted(vt, &start, &end, &outstr, &outlen); +#if PY_MAJOR_VERSION == 3 return Py_BuildValue("y#", outstr, outlen); +#else + return Py_BuildValue("s#", outstr, outlen); +#endif } static PyObject *py_vt100_get_string_plaintext(PyObject *self, PyObject *args) @@ -92,7 +96,11 @@ static PyObject *py_vt100_get_string_plaintext(PyObject *self, PyObject *args) vt100_screen_get_string_plaintext(vt, &start, &end, &outstr, &outlen); +#if PY_MAJOR_VERSION == 3 return Py_BuildValue("y#", outstr, outlen); +#else + return Py_BuildValue("s#", outstr, outlen); +#endif } static PyObject *py_vt100_delete(PyObject *self, PyObject *args) @@ -118,6 +126,7 @@ static PyMethodDef vt100_methods[] = { { NULL, NULL, 0, NULL } }; +#if PY_MAJOR_VERSION == 3 static struct PyModuleDef vt100module = { PyModuleDef_HEAD_INIT, "vt100_raw", @@ -130,3 +139,9 @@ PyMODINIT_FUNC PyInit_vt100_raw() { return PyModule_Create(&vt100module); } +#else +PyMODINIT_FUNC initvt100_raw() +{ + (void) Py_InitModule("vt100_raw", vt100_methods); +} +#endif -- cgit v1.2.3-54-g00ecf