summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Houghton <alastair@alastairs-place.net>2014-04-28 17:04:00 +0100
committerAlastair Houghton <alastair@alastairs-place.net>2014-04-28 17:04:00 +0100
commitf87507200874cfafda149cee4c7cdb8f784320b3 (patch)
treebbd59b8001cc55d4705dcb4ed14a6acefc6918f7
parent7de06e6d1856c9dc15aba442bbdbdc1d0c27c9a6 (diff)
downloadnetifaces-git-f87507200874cfafda149cee4c7cdb8f784320b3.tar.gz
Use Python 3 print function, not print statement. Also, avoid declaring variables mid-function in C code, since some compilers don't like it.
-rw-r--r--netifaces.c53
-rw-r--r--setup.py40
2 files changed, 50 insertions, 43 deletions
diff --git a/netifaces.c b/netifaces.c
index 91f876f..05ea30b 100644
--- a/netifaces.c
+++ b/netifaces.c
@@ -400,11 +400,14 @@ compare_bits (const void *pva,
static int
add_to_family (PyObject *result, int family, PyObject *dict)
{
+ PyObject *py_family;
+ PyObject *list;
+
if (!PyDict_Size (dict))
return TRUE;
- PyObject *py_family = PyInt_FromLong (family);
- PyObject *list = PyDict_GetItem (result, py_family);
+ py_family = PyInt_FromLong (family);
+ list = PyDict_GetItem (result, py_family);
if (!py_family) {
Py_DECREF (dict);
@@ -713,34 +716,36 @@ ifaddrs (PyObject *self, PyObject *args)
}
}
- PyObject *dict;
+ {
+ PyObject *dict;
- dict = PyDict_New ();
+ dict = PyDict_New ();
+
+ if (!dict) {
+ Py_XDECREF (addr);
+ Py_XDECREF (mask);
+ Py_XDECREF (bcast);
+ Py_DECREF (result);
+ free (pAdapterAddresses);
+ return NULL;
+ }
+
+ if (addr)
+ PyDict_SetItemString (dict, "addr", addr);
+ if (mask)
+ PyDict_SetItemString (dict, "netmask", mask);
+ if (bcast)
+ PyDict_SetItemString (dict, "broadcast", bcast);
- if (!dict) {
Py_XDECREF (addr);
Py_XDECREF (mask);
Py_XDECREF (bcast);
- Py_DECREF (result);
- free (pAdapterAddresses);
- return NULL;
- }
-
- if (addr)
- PyDict_SetItemString (dict, "addr", addr);
- if (mask)
- PyDict_SetItemString (dict, "netmask", mask);
- if (bcast)
- PyDict_SetItemString (dict, "broadcast", bcast);
-
- Py_XDECREF (addr);
- Py_XDECREF (mask);
- Py_XDECREF (bcast);
- if (!add_to_family (result, family, dict)) {
- Py_DECREF (result);
- free ((void *)pAdapterAddresses);
- return NULL;
+ if (!add_to_family (result, family, dict)) {
+ Py_DECREF (result);
+ free ((void *)pAdapterAddresses);
+ return NULL;
+ }
}
}
}
diff --git a/setup.py b/setup.py
index eefe10d..714c127 100644
--- a/setup.py
+++ b/setup.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
import setuptools
import os
import sys
@@ -47,7 +49,7 @@ class my_build_ext(build_ext):
if os.path.exists(name):
os.unlink(name)
thefile = open(name, 'w')
- print >>thefile, contents
+ print(contents, file=thefile)
thefile.close()
sys.stdout.flush()
@@ -107,7 +109,7 @@ class my_build_ext(build_ext):
self.conftestidx = 0
- print "checking for getifaddrs...",
+ print("checking for getifaddrs...", end='')
result = results.get('have_getifaddrs', None)
if result is not None:
@@ -137,14 +139,14 @@ class my_build_ext(build_ext):
result = False
if result:
- print "found. %s" % cached
+ print("found. %s" % cached)
self.compiler.define_macro('HAVE_GETIFADDRS', 1)
else:
- print "not found. %s" % cached
+ print("not found. %s" % cached)
results['have_getifaddrs'] = result
- print "checking for getnameinfo...",
+ print("checking for getnameinfo...", end='')
result = results.get('have_getnameinfo', None)
if result is not None:
@@ -185,15 +187,15 @@ class my_build_ext(build_ext):
result = False
if result:
- print "found. %s" % cached
+ print("found. %s" % cached)
self.compiler.define_macro('HAVE_GETNAMEINFO', 1)
else:
- print "not found. %s" % cached
+ print("not found. %s" % cached)
results['have_getnameinfo'] = result
if not results['have_getifaddrs']:
- print "checking for socket IOCTLs...",
+ print("checking for socket IOCTLs...", end='')
result = results.get('have_socket_ioctls', None)
if result is not None:
@@ -249,16 +251,16 @@ class my_build_ext(build_ext):
result.append(ioctl)
if result:
- print "%r. %s" % (result, cached)
+ print("%r. %s" % (result, cached))
for ioctl in result:
self.compiler.define_macro('HAVE_%s' % ioctl, 1)
self.compiler.define_macro('HAVE_SOCKET_IOCTLS', 1)
else:
- print "not found. %s" % cached
+ print("not found. %s" % cached)
results['have_socket_ioctls'] = result
- print "checking for optional header files...",
+ print("checking for optional header files...", end='')
result = results.get('have_headers', None)
if result is not None:
@@ -288,17 +290,17 @@ class my_build_ext(build_ext):
result.append(header)
if result:
- print "%s. %s" % (' '.join(result), cached)
+ print("%s. %s" % (' '.join(result), cached))
for header in result:
macro = header.upper().replace('.', '_').replace('/', '_')
self.compiler.define_macro('HAVE_%s' % macro, 1)
else:
- print "none found. %s" % cached
+ print("none found. %s" % cached)
optional_headers = result
results['have_headers'] = result
- print "checking whether struct sockaddr has a length field...",
+ print("checking whether struct sockaddr has a length field...", end='')
result = results.get('have_sockaddr_sa_len', None)
if result is not None:
@@ -321,10 +323,10 @@ class my_build_ext(build_ext):
result = self.test_build(testrig)
if result:
- print 'yes. %s' % cached
+ print('yes. %s' % cached)
self.compiler.define_macro('HAVE_SOCKADDR_SA_LEN', 1)
else:
- print 'no. %s' % cached
+ print('no. %s' % cached)
results['have_sockaddr_sa_len'] = result
@@ -334,7 +336,7 @@ class my_build_ext(build_ext):
# however, unfortunately, getifaddrs() doesn't return the
# lengths, because they're in the sa_len field on just about
# everything but Linux.
- print "checking which sockaddr_xxx structs are defined...",
+ print("checking which sockaddr_xxx structs are defined...", end='')
result = results.get('have_sockaddrs', None)
if result is not None:
@@ -374,12 +376,12 @@ class my_build_ext(build_ext):
result.append(sockaddr)
if result:
- print '%s. %s' % (' '.join(result), cached)
+ print('%s. %s' % (' '.join(result), cached))
for sockaddr in result:
self.compiler.define_macro('HAVE_SOCKADDR_%s' \
% sockaddr.upper(), 1)
else:
- print 'none! %s' % cached
+ print('none! %s' % cached)
results['have_sockaddrs'] = result