Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.0:Staging:D
net-snmp
net-snmp-python3.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File net-snmp-python3.patch of Package net-snmp
Index: net-snmp-5.7.3/python/setup.py =================================================================== --- net-snmp-5.7.3.orig/python/setup.py +++ net-snmp-5.7.3/python/setup.py @@ -9,9 +9,9 @@ intree=0 args = sys.argv[:] for arg in args: - if string.find(arg,'--basedir=') == 0: - basedir = string.split(arg,'=')[1] - sys.argv.remove(arg) + if arg.find('--basedir=') == 0: + basedir = arg.split('=')[1] + sys.argv.remove(arg) intree=1 if intree: Index: net-snmp-5.7.3/python/netsnmp/client.py =================================================================== --- net-snmp-5.7.3.orig/python/netsnmp/client.py +++ net-snmp-5.7.3/python/netsnmp/client.py @@ -1,3 +1,4 @@ +from __future__ import print_function import client_intf import string import re @@ -35,12 +36,12 @@ def _parse_session_args(kargs): 'TheirHostname':'', 'TrustCert':'' } - keys = kargs.keys() + keys = list(kargs.keys()) for key in keys: - if sessArgs.has_key(key): + if key in sessArgs: sessArgs[key] = kargs[key] else: - print >>stderr, "ERROR: unknown key", key + print("ERROR: unknown key", key, file=stderr) return sessArgs def STR(obj): @@ -127,7 +128,7 @@ class Session(object): sess_args = _parse_session_args(args) - for k,v in sess_args.items(): + for k,v in list(sess_args.items()): self.__dict__[k] = v Index: net-snmp-5.7.3/python/netsnmp/tests/test.py =================================================================== --- net-snmp-5.7.3.orig/python/netsnmp/tests/test.py +++ net-snmp-5.7.3/python/netsnmp/tests/test.py @@ -8,7 +8,7 @@ import time class BasicTests(unittest.TestCase): def testFuncs(self): - print "" + print("") var = netsnmp.Varbind('sysDescr.0') var = netsnmp.Varbind('sysDescr','0') var = netsnmp.Varbind( @@ -19,67 +19,67 @@ class BasicTests(unittest.TestCase): var = netsnmp.Varbind('.1.3.6.1.2.1.1.1','0') - print "---v1 GET tests -------------------------------------\n" + print("---v1 GET tests -------------------------------------\n") res = netsnmp.snmpget(var, Version = 1, DestHost='localhost', Community='public') - print "v1 snmpget result: ", res, "\n" + print("v1 snmpget result: ", res, "\n") - print "v1 get var: ", var.tag, var.iid, "=", var.val, '(',var.type,')' + print("v1 get var: ", var.tag, var.iid, "=", var.val, '(',var.type,')') - print "---v1 GETNEXT tests-------------------------------------\n" + print("---v1 GETNEXT tests-------------------------------------\n") res = netsnmp.snmpgetnext(var, Version = 1, DestHost='localhost', Community='public') - print "v1 snmpgetnext result: ", res, "\n" + print("v1 snmpgetnext result: ", res, "\n") - print "v1 getnext var: ", var.tag, var.iid, "=", var.val, '(',var.type,')' + print("v1 getnext var: ", var.tag, var.iid, "=", var.val, '(',var.type,')') - print "---v1 SET tests-------------------------------------\n" + print("---v1 SET tests-------------------------------------\n") var = netsnmp.Varbind('sysLocation','0', 'my new location') res = netsnmp.snmpset(var, Version = 1, DestHost='localhost', Community='public') - print "v1 snmpset result: ", res, "\n" + print("v1 snmpset result: ", res, "\n") - print "v1 set var: ", var.tag, var.iid, "=", var.val, '(',var.type,')' + print("v1 set var: ", var.tag, var.iid, "=", var.val, '(',var.type,')') - print "---v1 walk tests-------------------------------------\n" + print("---v1 walk tests-------------------------------------\n") vars = netsnmp.VarList(netsnmp.Varbind('system')) - print "v1 varlist walk in: " + print("v1 varlist walk in: ") for var in vars: - print " ",var.tag, var.iid, "=", var.val, '(',var.type,')' + print(" ",var.tag, var.iid, "=", var.val, '(',var.type,')') res = netsnmp.snmpwalk(vars, Version = 1, DestHost='localhost', Community='public') - print "v1 snmpwalk result: ", res, "\n" + print("v1 snmpwalk result: ", res, "\n") for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' + print(var.tag, var.iid, "=", var.val, '(',var.type,')') - print "---v1 walk 2-------------------------------------\n" + print("---v1 walk 2-------------------------------------\n") - print "v1 varbind walk in: " + print("v1 varbind walk in: ") var = netsnmp.Varbind('system') res = netsnmp.snmpwalk(var, Version = 1, DestHost='localhost', Community='public') - print "v1 snmpwalk result (should be = orig): ", res, "\n" + print("v1 snmpwalk result (should be = orig): ", res, "\n") - print var.tag, var.iid, "=", var.val, '(',var.type,')' + print(var.tag, var.iid, "=", var.val, '(',var.type,')') - print "---v1 multi-varbind test-------------------------------------\n" + print("---v1 multi-varbind test-------------------------------------\n") sess = netsnmp.Session(Version=1, DestHost='localhost', Community='public') @@ -88,16 +88,16 @@ class BasicTests(unittest.TestCase): netsnmp.Varbind('sysContact', 0), netsnmp.Varbind('sysLocation', 0)) vals = sess.get(vars) - print "v1 sess.get result: ", vals, "\n" + print("v1 sess.get result: ", vals, "\n") for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' + print(var.tag, var.iid, "=", var.val, '(',var.type,')') vals = sess.getnext(vars) - print "v1 sess.getnext result: ", vals, "\n" + print("v1 sess.getnext result: ", vals, "\n") for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' + print(var.tag, var.iid, "=", var.val, '(',var.type,')') vars = netsnmp.VarList(netsnmp.Varbind('sysUpTime'), netsnmp.Varbind('sysORLastChange'), @@ -106,28 +106,28 @@ class BasicTests(unittest.TestCase): netsnmp.Varbind('sysORUpTime')) vals = sess.getbulk(2, 8, vars) - print "v1 sess.getbulk result: ", vals, "\n" + print("v1 sess.getbulk result: ", vals, "\n") for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' + print(var.tag, var.iid, "=", var.val, '(',var.type,')') - print "---v1 set2-------------------------------------\n" + print("---v1 set2-------------------------------------\n") vars = netsnmp.VarList( netsnmp.Varbind('sysLocation', '0', 'my newer location')) res = sess.set(vars) - print "v1 sess.set result: ", res, "\n" + print("v1 sess.set result: ", res, "\n") - print "---v1 walk3-------------------------------------\n" + print("---v1 walk3-------------------------------------\n") vars = netsnmp.VarList(netsnmp.Varbind('system')) vals = sess.walk(vars) - print "v1 sess.walk result: ", vals, "\n" + print("v1 sess.walk result: ", vals, "\n") for var in vars: - print " ",var.tag, var.iid, "=", var.val, '(',var.type,')' + print(" ",var.tag, var.iid, "=", var.val, '(',var.type,')') - print "---v2c get-------------------------------------\n" + print("---v2c get-------------------------------------\n") sess = netsnmp.Session(Version=2, DestHost='localhost', @@ -140,22 +140,22 @@ class BasicTests(unittest.TestCase): netsnmp.Varbind('sysContact', 0), netsnmp.Varbind('sysLocation', 0)) vals = sess.get(vars) - print "v2 sess.get result: ", vals, "\n" + print("v2 sess.get result: ", vals, "\n") - print "---v2c getnext-------------------------------------\n" + print("---v2c getnext-------------------------------------\n") for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' - print "\n" + print(var.tag, var.iid, "=", var.val, '(',var.type,')') + print("\n") vals = sess.getnext(vars) - print "v2 sess.getnext result: ", vals, "\n" + print("v2 sess.getnext result: ", vals, "\n") for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' - print "\n" + print(var.tag, var.iid, "=", var.val, '(',var.type,')') + print("\n") - print "---v2c getbulk-------------------------------------\n" + print("---v2c getbulk-------------------------------------\n") vars = netsnmp.VarList(netsnmp.Varbind('sysUpTime'), netsnmp.Varbind('sysORLastChange'), @@ -164,30 +164,30 @@ class BasicTests(unittest.TestCase): netsnmp.Varbind('sysORUpTime')) vals = sess.getbulk(2, 8, vars) - print "v2 sess.getbulk result: ", vals, "\n" + print("v2 sess.getbulk result: ", vals, "\n") for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' - print "\n" + print(var.tag, var.iid, "=", var.val, '(',var.type,')') + print("\n") - print "---v2c set-------------------------------------\n" + print("---v2c set-------------------------------------\n") vars = netsnmp.VarList( netsnmp.Varbind('sysLocation','0','my even newer location')) res = sess.set(vars) - print "v2 sess.set result: ", res, "\n" + print("v2 sess.set result: ", res, "\n") - print "---v2c walk-------------------------------------\n" + print("---v2c walk-------------------------------------\n") vars = netsnmp.VarList(netsnmp.Varbind('system')) vals = sess.walk(vars) - print "v2 sess.walk result: ", vals, "\n" + print("v2 sess.walk result: ", vals, "\n") for var in vars: - print " ",var.tag, var.iid, "=", var.val, '(',var.type,')' + print(" ",var.tag, var.iid, "=", var.val, '(',var.type,')') - print "---v3 setup-------------------------------------\n" + print("---v3 setup-------------------------------------\n") sess = netsnmp.Session(Version=3, DestHost='localhost', SecLevel='authPriv', @@ -200,22 +200,22 @@ class BasicTests(unittest.TestCase): vars = netsnmp.VarList(netsnmp.Varbind('sysUpTime', 0), netsnmp.Varbind('sysContact', 0), netsnmp.Varbind('sysLocation', 0)) - print "---v3 get-------------------------------------\n" + print("---v3 get-------------------------------------\n") vals = sess.get(vars) - print "v3 sess.get result: ", vals, "\n" + print("v3 sess.get result: ", vals, "\n") for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' - print "\n" + print(var.tag, var.iid, "=", var.val, '(',var.type,')') + print("\n") - print "---v3 getnext-------------------------------------\n" + print("---v3 getnext-------------------------------------\n") vals = sess.getnext(vars) - print "v3 sess.getnext result: ", vals, "\n" + print("v3 sess.getnext result: ", vals, "\n") for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' - print "\n" + print(var.tag, var.iid, "=", var.val, '(',var.type,')') + print("\n") vars = netsnmp.VarList(netsnmp.Varbind('sysUpTime'), netsnmp.Varbind('sysORLastChange'), @@ -224,37 +224,37 @@ class BasicTests(unittest.TestCase): netsnmp.Varbind('sysORUpTime')) vals = sess.getbulk(2, 8, vars) - print "v3 sess.getbulk result: ", vals, "\n" + print("v3 sess.getbulk result: ", vals, "\n") for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' - print "\n" + print(var.tag, var.iid, "=", var.val, '(',var.type,')') + print("\n") - print "---v3 set-------------------------------------\n" + print("---v3 set-------------------------------------\n") vars = netsnmp.VarList( netsnmp.Varbind('sysLocation','0', 'my final destination')) res = sess.set(vars) - print "v3 sess.set result: ", res, "\n" + print("v3 sess.set result: ", res, "\n") - print "---v3 walk-------------------------------------\n" + print("---v3 walk-------------------------------------\n") vars = netsnmp.VarList(netsnmp.Varbind('system')) vals = sess.walk(vars) - print "v3 sess.walk result: ", vals, "\n" + print("v3 sess.walk result: ", vals, "\n") for var in vars: - print " ",var.tag, var.iid, "=", var.val, '(',var.type,')' + print(" ",var.tag, var.iid, "=", var.val, '(',var.type,')') class SetTests(unittest.TestCase): def testFuncs(self): - print "\n-------------- SET Test Start ----------------------------\n" + print("\n-------------- SET Test Start ----------------------------\n") var = netsnmp.Varbind('sysUpTime','0') res = netsnmp.snmpget(var, Version = 1, DestHost='localhost', Community='public') - print "uptime = ", res[0] + print("uptime = ", res[0]) var = netsnmp.Varbind('versionRestartAgent','0', 1) @@ -264,19 +264,19 @@ class SetTests(unittest.TestCase): var = netsnmp.Varbind('sysUpTime','0') res = netsnmp.snmpget(var, Version = 1, DestHost='localhost', Community='public') - print "uptime = ", res[0] + print("uptime = ", res[0]) var = netsnmp.Varbind('nsCacheEntry') res = netsnmp.snmpgetnext(var, Version = 1, DestHost='localhost', Community='public') - print "var = ", var.tag, var.iid, "=", var.val, '(',var.type,')' + print("var = ", var.tag, var.iid, "=", var.val, '(',var.type,')') var.val = 65 res = netsnmp.snmpset(var, Version = 1, DestHost='localhost', Community='public') res = netsnmp.snmpget(var, Version = 1, DestHost='localhost', Community='public') - print "var = ", var.tag, var.iid, "=", var.val, '(',var.type,')' + print("var = ", var.tag, var.iid, "=", var.val, '(',var.type,')') sess = netsnmp.Session(Version = 1, DestHost='localhost', Community='public') @@ -286,7 +286,7 @@ class SetTests(unittest.TestCase): netsnmp.Varbind('.1.3.6.1.6.3.12.1.2.1.9.116.101.115.116','', 4)) res = sess.set(vars) - print "res = ", res + print("res = ", res) vars = netsnmp.VarList(netsnmp.Varbind('snmpTargetAddrTDomain'), netsnmp.Varbind('snmpTargetAddrTAddress'), @@ -295,14 +295,14 @@ class SetTests(unittest.TestCase): res = sess.getnext(vars) for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' - print "\n" + print(var.tag, var.iid, "=", var.val, '(',var.type,')') + print("\n") vars = netsnmp.VarList(netsnmp.Varbind('.1.3.6.1.6.3.12.1.2.1.9.116.101.115.116','', 6)) res = sess.set(vars) - print "res = ", res + print("res = ", res) vars = netsnmp.VarList(netsnmp.Varbind('snmpTargetAddrTDomain'), netsnmp.Varbind('snmpTargetAddrTAddress'), @@ -311,10 +311,10 @@ class SetTests(unittest.TestCase): res = sess.getnext(vars) for var in vars: - print var.tag, var.iid, "=", var.val, '(',var.type,')' - print "\n" + print(var.tag, var.iid, "=", var.val, '(',var.type,')') + print("\n") - print "\n-------------- SET Test End ----------------------------\n" + print("\n-------------- SET Test End ----------------------------\n") if __name__=='__main__': Index: net-snmp-5.7.3/python/netsnmp/client_intf.c =================================================================== --- net-snmp-5.7.3.orig/python/netsnmp/client_intf.c +++ net-snmp-5.7.3/python/netsnmp/client_intf.c @@ -979,7 +979,11 @@ py_netsnmp_attr_string(PyObject *obj, ch PyObject *attr = PyObject_GetAttrString(obj, attr_name); if (attr) { int retval; +#if PY_MAJOR_VERSION >= 3 + retval = PyBytes_AsStringAndSize(attr, val, len); +#else retval = PyString_AsStringAndSize(attr, val, len); +#endif Py_DECREF(attr); return retval; } @@ -996,7 +1000,11 @@ py_netsnmp_attr_long(PyObject *obj, char if (obj && attr_name && PyObject_HasAttrString(obj, attr_name)) { PyObject *attr = PyObject_GetAttrString(obj, attr_name); if (attr) { +#if PY_MAJOR_VERSION >= 3 + val = PyLong_AsLong(attr); +#else val = PyInt_AsLong(attr); +#endif Py_DECREF(attr); } } @@ -1079,11 +1087,19 @@ __py_netsnmp_update_session_errors(PyObj py_netsnmp_attr_set_string(session, "ErrorStr", err_str, STRLEN(err_str)); +#if PY_MAJOR_VERSION >= 3 + tmp_for_conversion = PyLong_FromLong(err_num); +#else tmp_for_conversion = PyInt_FromLong(err_num); +#endif PyObject_SetAttrString(session, "ErrorNum", tmp_for_conversion); Py_DECREF(tmp_for_conversion); +#if PY_MAJOR_VERSION >= 3 + tmp_for_conversion = PyLong_FromLong(err_ind); +#else tmp_for_conversion = PyInt_FromLong(err_ind); +#endif PyObject_SetAttrString(session, "ErrorInd", tmp_for_conversion); Py_DECREF(tmp_for_conversion); } @@ -2607,13 +2623,28 @@ static PyMethodDef ClientMethods[] = { {NULL, NULL, 0, NULL} /* Sentinel */ }; +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef ClientModuleDef = { + PyModuleDef_HEAD_INIT, + "client_intf", + NULL, + -1, + ClientMethods, + NULL, + NULL, + NULL, + NULL +}; + +PyMODINIT_FUNC +PyInit_client_intf(void) +{ + return PyModule_Create(&ClientModuleDef); +} +#else PyMODINIT_FUNC initclient_intf(void) { (void) Py_InitModule("client_intf", ClientMethods); } - - - - - +#endif
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor