diff options
-rw-r--r-- | CMakeLists.txt | 11 | ||||
-rw-r--r-- | pcilib/py.c | 56 | ||||
-rw-r--r-- | pyserver/api_server.py | 53 | ||||
-rw-r--r-- | pywrap/pcipywrap.c | 101 | ||||
-rw-r--r-- | pywrap/test_pcilib.py | 45 | ||||
-rw-r--r-- | xml/scripts/test_script.py | 10 | ||||
-rw-r--r-- | xml/test/test_prop_mt.py | 2 |
7 files changed, 166 insertions, 112 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 856e23c..bc9abc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,9 +38,10 @@ find_package(PkgConfig REQUIRED) find_package(Threads REQUIRED) if (NOT DISABLE_PYTHON) - - find_package(PythonLibs 2.7 REQUIRED) - find_package(PythonInterp 2 REQUIRED) + set(PYTHON_VERSION 2.7 CACHE PATH "python version") + + find_package(PythonLibs ${PYTHON_VERSION} REQUIRED) + find_package(PythonInterp ${PYTHON_VERSION} REQUIRED) find_package(SWIG REQUIRED) if (NOT PYTHON_VERSION_STRING VERSION_EQUAL PYTHONLIBS_VERSION_STRING) @@ -49,9 +50,9 @@ if (NOT DISABLE_PYTHON) # execute_process (COMMAND ${PYTHON_EXECUTABLE} -c "from sysconfig import get_path; print get_path('platlib')" OUTPUT_VARIABLE PYTHON_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process (COMMAND ${PYTHON_EXECUTABLE} -c "import site; print site.PREFIXES[-1]" OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process (COMMAND ${PYTHON_EXECUTABLE} -c "import site; print(site.PREFIXES[-1])" OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE) file (TO_CMAKE_PATH "${PYTHON_PREFIX}" PYTHON_PREFIX) - execute_process (COMMAND ${PYTHON_EXECUTABLE} -c "import site; print site.getsitepackages()[0]" OUTPUT_VARIABLE PYTHON_SITE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process (COMMAND ${PYTHON_EXECUTABLE} -c "import site; print(site.getsitepackages()[0])" OUTPUT_VARIABLE PYTHON_SITE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) file (TO_CMAKE_PATH "${PYTHON_SITE_DIR}" PYTHON_SITE_DIR) string (REGEX REPLACE "^${PYTHON_PREFIX}/" "${CMAKE_INSTALL_PREFIX}/" PYTHON_SITE_DIR "${PYTHON_SITE_DIR}") diff --git a/pcilib/py.c b/pcilib/py.c index 699cd59..b8f4800 100644 --- a/pcilib/py.c +++ b/pcilib/py.c @@ -49,8 +49,21 @@ void pcilib_log_python_error(const char *file, int line, pcilib_log_flags_t flag gstate = PyGILState_Ensure(); if (PyErr_Occurred()) { PyErr_Fetch(&pytype, &pyval, &pytraceback); - type = PyString_AsString(pytype); - val = PyString_AsString(pyval); + +#if PY_MAJOR_VERSION >= 3 + type = PyUnicode_AsUTF8(pytype); + val = PyUnicode_AsUTF8(pyval); +#else /*PY_MAJOR_VERSION >= 3*/ + PyObject *buf = PyUnicode_AsASCIIString(pytype); + type = PyString_AsString(buf); + Py_DecRef(buf); + + buf = PyUnicode_AsASCIIString(pyval); + val = PyString_AsString(buf); + Py_DecRef(buf); +#endif /*PY_MAJOR_VERSION >= 3*/ + + } PyGILState_Release(gstate); #endif /* HAVE_PYTHON */ @@ -101,7 +114,7 @@ int pcilib_init_py(pcilib_t *ctx) { if(!Py_IsInitialized()) { Py_Initialize(); - // Since python is being initializing from c programm, it needs to initialize threads to work properly with c threads + // Since python is being initializing from c programm, it needs to initialize threads to work properly with c threads PyEval_InitThreads(); PyEval_ReleaseLock(); ctx->py->finalyze = 1; @@ -125,8 +138,9 @@ int pcilib_init_py(pcilib_t *ctx) { return PCILIB_ERROR_FAILED; } - PyObject *mod_name = PyString_FromString("Pcilib"); - PyObject *pyctx = PyCObject_FromVoidPtr(ctx, NULL); + PyObject *mod_name = PyUnicode_FromString("Pcilib"); + PyObject *pyctx = PyCapsule_New(ctx, "pcilib", NULL); + ctx->py->pcilib_pywrap = PyObject_CallMethodObjArgs(pywrap, mod_name, pyctx, NULL); Py_XDECREF(pyctx); Py_XDECREF(mod_name); @@ -166,7 +180,8 @@ int pcilib_py_add_script_dir(pcilib_t *ctx, const char *dir) { return PCILIB_ERROR_FAILED; } - pynewdir = PyString_FromString(script_dir); + pynewdir = PyUnicode_FromString(script_dir); + if (!pynewdir) { pcilib_python_error("Can't create python string"); return PCILIB_ERROR_MEMORY; @@ -175,13 +190,13 @@ int pcilib_py_add_script_dir(pcilib_t *ctx, const char *dir) { // Checking if the directory already in the path pydict = PyDict_New(); if (pydict) { - pystr = PyString_FromString("cur"); + pystr = PyUnicode_FromString("cur"); if (pystr) { PyDict_SetItem(pydict, pystr, pynewdir); Py_DECREF(pystr); } - pystr = PyString_FromString("path"); + pystr = PyUnicode_FromString("path"); if (pystr) { PyDict_SetItem(pydict, pystr, pypath); Py_DECREF(pystr); @@ -292,13 +307,13 @@ int pcilib_py_get_transform_script_properties(pcilib_t *ctx, const char *script_ return PCILIB_ERROR_FAILED; } - pystr = PyString_FromString("read_from_register"); + pystr = PyUnicode_FromString("read_from_register"); if (pystr) { if (PyDict_Contains(dict, pystr)) mode |= PCILIB_ACCESS_R; Py_DECREF(pystr); } - pystr = PyString_FromString("write_to_register"); + pystr = PyUnicode_FromString("write_to_register"); if (pystr) { if (PyDict_Contains(dict, pystr)) mode |= PCILIB_ACCESS_W; Py_DECREF(pystr); @@ -322,7 +337,7 @@ pcilib_py_object *pcilib_get_value_as_pyobject(pcilib_t* ctx, pcilib_value_t *va switch(val->type) { case PCILIB_TYPE_LONG: ival = pcilib_get_value_as_int(ctx, val, &err); - if (!err) res = (PyObject*)PyInt_FromLong(ival); + if (!err) res = (PyObject*)PyLong_FromLong(ival); break; case PCILIB_TYPE_DOUBLE: fval = pcilib_get_value_as_float(ctx, val, &err); @@ -359,12 +374,25 @@ int pcilib_set_value_from_pyobject(pcilib_t* ctx, pcilib_value_t *val, pcilib_py PyGILState_STATE gstate; gstate = PyGILState_Ensure(); +#if PY_MAJOR_VERSION < 3 if (PyInt_Check(pyval)) { - err = pcilib_set_value_from_int(ctx, val, PyInt_AsLong(pyval)); + err = pcilib_set_value_from_int(ctx, val, PyInt_AsLong(pyval)); + } else if (PyString_Check(pyval)) { + err = pcilib_set_value_from_string(ctx, val, PyString_AsString(pyval)); + } else +#endif /*PY_MAJOR_VERSION >= 3*/ + if (PyLong_Check(pyval)) { + err = pcilib_set_value_from_int(ctx, val, PyLong_AsLong(pyval)); } else if (PyFloat_Check(pyval)) { err = pcilib_set_value_from_float(ctx, val, PyFloat_AsDouble(pyval)); - } else if (PyString_Check(pyval)) { - err = pcilib_set_value_from_string(ctx, val, PyString_AsString(pyval)); + } else if (PyUnicode_Check(pyval)) { +#if PY_MAJOR_VERSION >= 3 + err = pcilib_set_value_from_string(ctx, val, PyUnicode_AsUTF8(pyval)); +#else /*PY_MAJOR_VERSION >= 3*/ + PyObject *buf = PyUnicode_AsASCIIString(pyval); + err = pcilib_set_value_from_string(ctx, val, PyString_AsString(buf)); + Py_DecRef(buf); +#endif /*PY_MAJOR_VERSION >= 3*/ } else { PyGILState_Release(gstate); pcilib_error("Can't convert PyObject to polymorphic pcilib value"); diff --git a/pyserver/api_server.py b/pyserver/api_server.py index c170a19..736d521 100644 --- a/pyserver/api_server.py +++ b/pyserver/api_server.py @@ -6,10 +6,14 @@ import pcilib import time import json from optparse import OptionParser - from multiprocessing import Process -from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler -from SocketServer import ThreadingMixIn + +if sys.version_info >= (3,0): + from http.server import HTTPServer, BaseHTTPRequestHandler + from socketserver import ThreadingMixIn +else: + from SocketServer import ThreadingMixIn + from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler class MultiThreadedHTTPServer(ThreadingMixIn, HTTPServer): pass @@ -146,8 +150,8 @@ class PcilibServerHandler(BaseHTTPRequestHandler): #parse command arguments and convert them to string reg = str(data.get('reg', None)) bank = data.get('bank', None) - if not bank is None: - bank = str(bank) + if(not bank is None): + bank = str(bank) value = 0 try: @@ -178,10 +182,10 @@ class PcilibServerHandler(BaseHTTPRequestHandler): #parse command arguments and convert them to string reg = str(data.get('reg', None)) - value = str(data.get('value', None)) + value = data.get('value', None) bank = data.get('bank', None) - if not bank is None: - bank = str(bank) + if(not bank is None): + bank = str(bank) try: s.pcilib.write_register(value, reg, bank) @@ -230,10 +234,10 @@ class PcilibServerHandler(BaseHTTPRequestHandler): s.error('message doesnt contains "value" field, ' 'which is required for "set_property" command', data) return - + #parse command arguments and convert them to string prop = str(data.get('prop', None)) - value = str(data.get('value', None)) + value = data.get('value', None) try: s.pcilib.set_property(value, prop) @@ -340,7 +344,7 @@ class PcilibServerHandler(BaseHTTPRequestHandler): return #Success! Create and send reply - if(type(out) == bytearray): + if(type(out) == bytearray or type(out) == bytes): s.send_response(200) s.send_header('content-disposition', 'inline; filename=value') s.send_header('content-type', 'application/octet-stream') @@ -374,13 +378,13 @@ class PcilibServerHandler(BaseHTTPRequestHandler): # #Success! Create and send reply # s.wrapMessageAndSend({'status': 'ok'}, data) - + else: - s.error('command "' + command + '" undefined', data) - return + s.error('command "' + command + '" undefined', data) + return else: - s.error('message doesnt contains "command" field, which is required', data) - return + s.error('message doesnt contains "command" field, which is required', data) + return @@ -481,7 +485,10 @@ class PcilibServerHandler(BaseHTTPRequestHandler): s.send_response(200) s.send_header('content-type', 'text/plain') s.end_headers() - s.wfile.write(usage) + if sys.version_info >= (3,0): + s.wfile.write(bytes(usage, 'UTF-8')) + else: + s.wfile.write(usage) #Send error message with text description def error(s, info, received_message = None): @@ -498,8 +505,12 @@ class PcilibServerHandler(BaseHTTPRequestHandler): s.end_headers() if not received_message is None: message['received_message'] = received_message - s.wfile.write(json.dumps(message)) - + if sys.version_info >= (3,0): + s.wfile.write(bytes(json.dumps(message), 'UTF-8')) + else: + s.wfile.write(json.dumps(message)) + + class ApiServer(MultiThreadedHTTPServer): def __init__(self, device='/dev/fpga0', model=None, adress=('0.0.0.0', 9000)): #redirect logs to exeption @@ -534,7 +545,7 @@ if __name__ == '__main__': #start server httpd = ApiServer(DEVICE, MODEL, (HOST_NAME, PORT_NUMBER)) - print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER) + print(time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)) try: httpd.serve_forever() @@ -543,4 +554,4 @@ if __name__ == '__main__': httpd.server_close() - print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER) + print(time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)) diff --git a/pywrap/pcipywrap.c b/pywrap/pcipywrap.c index 0f6729e..a1092be 100644 --- a/pywrap/pcipywrap.c +++ b/pywrap/pcipywrap.c @@ -128,12 +128,12 @@ void add_pcilib_value_to_dict(pcilib_t* ctx, PyObject* dict, pcilib_value_t* val if(py_val) pcilib_pydict_set_item(dict, - PyString_FromString(name), + PyUnicode_FromString(name), py_val); else pcilib_pydict_set_item(dict, - PyString_FromString("defvalue"), - PyString_FromString("invalid")); + PyUnicode_FromString("defvalue"), + PyUnicode_FromString("invalid")); } PyObject * pcilib_convert_property_info_to_pyobject(pcilib_t* ctx, pcilib_property_info_t listItem) @@ -142,18 +142,18 @@ PyObject * pcilib_convert_property_info_to_pyobject(pcilib_t* ctx, pcilib_proper if(listItem.name) pcilib_pydict_set_item(pylistItem, - PyString_FromString("name"), - PyString_FromString(listItem.name)); + PyUnicode_FromString("name"), + PyUnicode_FromString(listItem.name)); if(listItem.description) pcilib_pydict_set_item(pylistItem, - PyString_FromString("description"), - PyString_FromString(listItem.description)); + PyUnicode_FromString("description"), + PyUnicode_FromString(listItem.description)); if(listItem.path) pcilib_pydict_set_item(pylistItem, - PyString_FromString("path"), - PyString_FromString(listItem.path)); + PyUnicode_FromString("path"), + PyUnicode_FromString(listItem.path)); //serialize types const char* type = "invalid"; @@ -175,40 +175,40 @@ PyObject * pcilib_convert_property_info_to_pyobject(pcilib_t* ctx, pcilib_proper break; } pcilib_pydict_set_item(pylistItem, - PyString_FromString("type"), - PyString_FromString(type)); + PyUnicode_FromString("type"), + PyUnicode_FromString(type)); //serialize modes PyObject* modes = PyList_New(0); if((listItem.mode & PCILIB_ACCESS_R ) == PCILIB_REGISTER_R) - pcilib_pylist_append(modes, PyString_FromString("R")); + pcilib_pylist_append(modes, PyUnicode_FromString("R")); if((listItem.mode & PCILIB_ACCESS_W ) == PCILIB_REGISTER_W) - pcilib_pylist_append(modes, PyString_FromString("W")); + pcilib_pylist_append(modes, PyUnicode_FromString("W")); if((listItem.mode & PCILIB_ACCESS_RW ) == PCILIB_REGISTER_RW) - pcilib_pylist_append(modes, PyString_FromString("RW")); + pcilib_pylist_append(modes, PyUnicode_FromString("RW")); if((listItem.mode & PCILIB_REGISTER_INCONSISTENT) == PCILIB_REGISTER_INCONSISTENT) - pcilib_pylist_append(modes, PyString_FromString("NO_CHK")); + pcilib_pylist_append(modes, PyUnicode_FromString("NO_CHK")); pcilib_pydict_set_item(pylistItem, - PyString_FromString("mode"), + PyUnicode_FromString("mode"), modes); //serialize flags PyObject* flags = PyList_New(0); if((listItem.flags & PCILIB_LIST_FLAG_CHILDS ) == PCILIB_LIST_FLAG_CHILDS) - pcilib_pylist_append(flags, PyString_FromString("childs")); + pcilib_pylist_append(flags, PyUnicode_FromString("childs")); pcilib_pydict_set_item(pylistItem, - PyString_FromString("flags"), + PyUnicode_FromString("flags"), flags); if(listItem.unit) pcilib_pydict_set_item(pylistItem, - PyString_FromString("unit"), - PyString_FromString(listItem.unit)); + PyUnicode_FromString("unit"), + PyUnicode_FromString(listItem.unit)); return pylistItem; } @@ -219,42 +219,42 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_regist if(listItem.name) pcilib_pydict_set_item(pylistItem, - PyString_FromString("name"), - PyString_FromString(listItem.name)); + PyUnicode_FromString("name"), + PyUnicode_FromString(listItem.name)); if(listItem.description) pcilib_pydict_set_item(pylistItem, - PyString_FromString("description"), - PyString_FromString(listItem.description)); + PyUnicode_FromString("description"), + PyUnicode_FromString(listItem.description)); if(listItem.bank) pcilib_pydict_set_item(pylistItem, - PyString_FromString("bank"), - PyString_FromString(listItem.bank)); + PyUnicode_FromString("bank"), + PyUnicode_FromString(listItem.bank)); //serialize modes PyObject* modes = PyList_New(0); if((listItem.mode & PCILIB_REGISTER_R) == PCILIB_REGISTER_R) - pcilib_pylist_append(modes, PyString_FromString("R")); + pcilib_pylist_append(modes, PyUnicode_FromString("R")); if((listItem.mode & PCILIB_REGISTER_W) == PCILIB_REGISTER_W) - pcilib_pylist_append(modes, PyString_FromString("W")); + pcilib_pylist_append(modes, PyUnicode_FromString("W")); if((listItem.mode & PCILIB_REGISTER_RW) == PCILIB_REGISTER_RW) - pcilib_pylist_append(modes, PyString_FromString("RW")); + pcilib_pylist_append(modes, PyUnicode_FromString("RW")); if((listItem.mode & PCILIB_REGISTER_W1C) == PCILIB_REGISTER_W1C) - pcilib_pylist_append(modes, PyString_FromString("W1C")); + pcilib_pylist_append(modes, PyUnicode_FromString("W1C")); if((listItem.mode & PCILIB_REGISTER_RW1C) == PCILIB_REGISTER_RW1C) - pcilib_pylist_append(modes, PyString_FromString("RW1C")); + pcilib_pylist_append(modes, PyUnicode_FromString("RW1C")); if((listItem.mode & PCILIB_REGISTER_W1I) == PCILIB_REGISTER_W1I) - pcilib_pylist_append(modes, PyString_FromString("W1I")); + pcilib_pylist_append(modes, PyUnicode_FromString("W1I")); if((listItem.mode & PCILIB_REGISTER_RW1I) == PCILIB_REGISTER_RW1I) - pcilib_pylist_append(modes, PyString_FromString("RW1I")); + pcilib_pylist_append(modes, PyUnicode_FromString("RW1I")); if((listItem.mode & PCILIB_REGISTER_INCONSISTENT) == PCILIB_REGISTER_INCONSISTENT) - pcilib_pylist_append(modes, PyString_FromString("NO_CHK")); + pcilib_pylist_append(modes, PyUnicode_FromString("NO_CHK")); pcilib_pydict_set_item(pylistItem, - PyString_FromString("mode"), + PyUnicode_FromString("mode"), modes); pcilib_value_t defval = {0}; @@ -273,7 +273,7 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_regist add_pcilib_value_to_dict(ctx, range, &minval, "min"); add_pcilib_value_to_dict(ctx, range, &maxval, "max"); pcilib_pydict_set_item(pylistItem, - PyString_FromString("range"), + PyUnicode_FromString("range"), range); } @@ -301,20 +301,20 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_regist if(listItem.values[j].name) pcilib_pydict_set_item(valuesItem, - PyString_FromString("name"), - PyString_FromString(listItem.values[j].name)); + PyUnicode_FromString("name"), + PyUnicode_FromString(listItem.values[j].name)); if(listItem.values[j].description) { pcilib_pydict_set_item(valuesItem, - PyString_FromString("description"), - PyString_FromString(listItem.values[j].description)); + PyUnicode_FromString("description"), + PyUnicode_FromString(listItem.values[j].description)); } pcilib_pylist_append(values, valuesItem); } pcilib_pydict_set_item(pylistItem, - PyString_FromString("values"), + PyUnicode_FromString("values"), values); } @@ -340,16 +340,17 @@ Pcipywrap *new_Pcipywrap(const char* fpga_device, const char* model) Pcipywrap *create_Pcipywrap(PyObject* ctx) { - if(!PyCObject_Check(ctx)) + if(!PyCapsule_CheckExact(ctx)) { - set_python_exception("Incorrect ctx type. Only PyCObject is allowed"); + set_python_exception("Incorrect ctx type. Only PyCapsule is allowed"); return NULL; } Pcipywrap *self; self = (Pcipywrap *) malloc(sizeof(Pcipywrap)); self->shared = 1; - self->ctx = PyCObject_AsVoidPtr(ctx); + self->ctx = PyCapsule_GetPointer(ctx, PyCapsule_GetName(ctx)); + return self; } @@ -415,7 +416,7 @@ PyObject* Pcipywrap_write_register(Pcipywrap *self, PyObject* val, const char *r return NULL; } - return PyInt_FromLong((long)1); + return PyLong_FromLong((long)1); } PyObject* Pcipywrap_get_property(Pcipywrap *self, const char *prop) @@ -453,7 +454,7 @@ PyObject* Pcipywrap_set_property(Pcipywrap *self, PyObject* val, const char *pro return NULL; } - return PyInt_FromLong((long)1); + return PyLong_FromLong((long)1); } PyObject* Pcipywrap_get_registers_list(Pcipywrap *self, const char *bank) @@ -542,7 +543,7 @@ PyObject* Pcipywrap_lock_global(Pcipywrap *self) return NULL; } - return PyInt_FromLong((long)1); + return PyLong_FromLong((long)1); } void Pcipywrap_unlock_global(Pcipywrap *self) @@ -570,7 +571,7 @@ PyObject* Pcipywrap_lock(Pcipywrap *self, const char *lock_id) return NULL; } - return PyInt_FromLong((long)1); + return PyLong_FromLong((long)1); } PyObject* Pcipywrap_try_lock(Pcipywrap *self, const char *lock_id) @@ -591,7 +592,7 @@ PyObject* Pcipywrap_try_lock(Pcipywrap *self, const char *lock_id) return NULL; } - return PyInt_FromLong((long)1); + return PyLong_FromLong((long)1); } PyObject* Pcipywrap_unlock(Pcipywrap *self, const char *lock_id) @@ -606,7 +607,7 @@ PyObject* Pcipywrap_unlock(Pcipywrap *self, const char *lock_id) } pcilib_unlock(lock); - return PyInt_FromLong((long)1); + return PyLong_FromLong((long)1); } diff --git a/pywrap/test_pcilib.py b/pywrap/test_pcilib.py index 69540ec..aed2dc3 100644 --- a/pywrap/test_pcilib.py +++ b/pywrap/test_pcilib.py @@ -55,17 +55,17 @@ class test_pcilib(): {'command': 'unlock_global'}, {'command': 'help'}] r = requests.get(url, data=json.dumps(payload[message]), headers=headers) - print json.dumps(r.json(), sort_keys=True, indent=3, separators=(',', ': ')) + print(json.dumps(r.json(), sort_keys=True, indent=3, separators=(',', ': '))) def testThreadSafeReadWrite(self): def threadFunc(): if random.randint(0, 100) >= (self.write_percentage * 100): ret = self.pcilib.get_property(self.prop) - print self.register, ':', ret + print(self.register, ':', ret) del ret else: val = random.randint(0, 65536) - print 'set value:', val + print('set value:', val) self.pcilib.set_property(val, self.prop) try: while(1): @@ -74,25 +74,25 @@ class test_pcilib(): thread_list[i].start() for i in range(0, self.num_threads): thread_list[i].join() - print 'cycle done' + print('cycle done') except KeyboardInterrupt: - print 'testing done' + print('testing done') pass def testMemoryLeak(self): try: while(1): - val = random.randint(0, 8096) + val = long(random.randint(0, 8096)) self.pcilib = pcilib.Pcilib(self.device, self.model) - print self.pcilib.get_property_list(self.branch) - print self.pcilib.get_register_info(self.register) - print self.pcilib.get_registers_list(); - print self.pcilib.write_register(val, self.register) - print self.pcilib.read_register(self.register) - print self.pcilib.set_property(val, self.prop) - print self.pcilib.get_property(self.prop) + print(self.pcilib.get_property_list(self.branch)) + print(self.pcilib.get_register_info(self.register)) + print(self.pcilib.get_registers_list()) + print(self.pcilib.write_register(val, self.register)) + print(self.pcilib.read_register(self.register)) + print(self.pcilib.set_property(val, self.prop)) + print(self.pcilib.get_property(self.prop)) except KeyboardInterrupt: - print 'testing done' + print('testing done') pass def testServer(self): @@ -111,14 +111,19 @@ class test_pcilib(): def sendRandomMessage(): message_number = random.randint(1, len(payload) - 1) - print 'message number: ', message_number + print('message number: ', message_number) payload[message_number]['value'] = random.randint(0, 8096) r = requests.get(url, data=json.dumps(payload[message_number]), headers=headers) - print json.dumps(r.json(), sort_keys=True, indent=4, separators=(',', ': ')) - + if(r.headers['content-type'] == 'application/json'): + print(json.dumps(r.json(), sort_keys=True, indent=3, separators=(',', ': '))) + else: + print(r.content) try: r = requests.get(url, data=json.dumps(payload[1]), headers=headers) - print json.dumps(r.json(), sort_keys=True, indent=3, separators=(',', ': ')) + if(r.headers['content-type'] == 'application/json'): + print(json.dumps(r.json(), sort_keys=True, indent=3, separators=(',', ': '))) + else: + print(r.content) while(1): time.sleep(self.server_message_delay) @@ -127,10 +132,10 @@ class test_pcilib(): thread_list[i].start() for i in range(0, self.num_threads): thread_list[i].join() - print 'cycle done' + print('cycle done') except KeyboardInterrupt: - print 'testing done' + print('testing done') pass if __name__ == '__main__': diff --git a/xml/scripts/test_script.py b/xml/scripts/test_script.py index 46a5b25..8f236e9 100644 --- a/xml/scripts/test_script.py +++ b/xml/scripts/test_script.py @@ -1,2 +1,10 @@ +import sys +if sys.version_info >= (3,0): + import binascii + def run(ctx, inpt): - return bytearray('111') + if sys.version_info >= (3,0): + return binascii.a2b_uu('111') + else: + return bytearray('111') + diff --git a/xml/test/test_prop_mt.py b/xml/test/test_prop_mt.py index a5e5fab..224a80c 100644 --- a/xml/test/test_prop_mt.py +++ b/xml/test/test_prop_mt.py @@ -10,7 +10,7 @@ def read_from_register(ctx, value): read_from_register.counter += 1 for i in range (0, 5): time.sleep(0.1) - print cur + print(cur) out = ctx.get_property('/test/prop3') / 2 ctx.unlock('lock12') |