Skip to content

Commit c1e934e

Browse files
PEP 7hroncok
authored andcommitted
ifs and fors with space after, no spaces inside the paren
1 parent bb13952 commit c1e934e

File tree

5 files changed

+48
-48
lines changed

5 files changed

+48
-48
lines changed

python-ethtool/etherinfo.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ static void callback_nl_link(struct nl_object *obj, void *arg)
5858
struct rtnl_link *link = (struct rtnl_link *) obj;
5959
char hwaddr[130];
6060

61-
if( (ethi == NULL) || (ethi->hwaddress != NULL) ) {
61+
if ((ethi == NULL) || (ethi->hwaddress != NULL)) {
6262
return;
6363
}
6464

6565
memset(&hwaddr, 0, 130);
6666
nl_addr2str(rtnl_link_get_addr(link), hwaddr, sizeof(hwaddr));
67-
if( ethi->hwaddress ) {
67+
if (ethi->hwaddress) {
6868
Py_XDECREF(ethi->hwaddress);
6969
}
7070
ethi->hwaddress = PyStr_FromFormat("%s", hwaddr);
@@ -85,15 +85,15 @@ static void callback_nl_address(struct nl_object *obj, void *arg)
8585
PyObject *addr_obj = NULL;
8686
int af_family = -1;
8787

88-
if( py_addrlist == NULL ) {
88+
if (py_addrlist == NULL) {
8989
return;
9090
}
9191

9292
/* Ensure that we're processing only known address types.
9393
* Currently only IPv4 and IPv6 is handled
9494
*/
9595
af_family = rtnl_addr_get_family(rtaddr);
96-
if( af_family != AF_INET && af_family != AF_INET6 ) {
96+
if (af_family != AF_INET && af_family != AF_INET6) {
9797
return;
9898
}
9999

@@ -125,20 +125,20 @@ static int _set_device_index(PyEtherInfo *self)
125125
* As we don't expect it to change, we're reusing a "cached"
126126
* interface index if we have that
127127
*/
128-
if( self->index < 0 ) {
129-
if( (errno = rtnl_link_alloc_cache(get_nlc(), AF_UNSPEC, &link_cache)) < 0) {
128+
if (self->index < 0) {
129+
if ((errno = rtnl_link_alloc_cache(get_nlc(), AF_UNSPEC, &link_cache)) < 0) {
130130
PyErr_SetString(PyExc_OSError, nl_geterror(errno));
131131
return 0;
132132
}
133133
link = rtnl_link_get_by_name(link_cache, PyStr_AsString(self->device));
134-
if( !link ) {
134+
if (!link) {
135135
errno = ENODEV;
136136
PyErr_SetFromErrno(PyExc_IOError);
137137
nl_cache_free(link_cache);
138138
return 0;
139139
}
140140
self->index = rtnl_link_get_ifindex(link);
141-
if( self->index <= 0 ) {
141+
if (self->index <= 0) {
142142
errno = ENODEV;
143143
PyErr_SetFromErrno(PyExc_IOError);
144144
rtnl_link_put(link);
@@ -172,29 +172,29 @@ int get_etherinfo_link(PyEtherInfo *self)
172172
struct rtnl_link *link;
173173
int err = 0;
174174

175-
if( !self ) {
175+
if (!self) {
176176
return 0;
177177
}
178178

179179
/* Open a NETLINK connection on-the-fly */
180-
if( !open_netlink(self) ) {
180+
if (!open_netlink(self)) {
181181
PyErr_Format(PyExc_RuntimeError,
182182
"Could not open a NETLINK connection for %s",
183183
PyStr_AsString(self->device));
184184
return 0;
185185
}
186186

187-
if( _set_device_index(self) != 1) {
187+
if (_set_device_index(self) != 1) {
188188
return 0;
189189
}
190190

191191
/* Extract MAC/hardware address of the interface */
192-
if( (err = rtnl_link_alloc_cache(get_nlc(), AF_UNSPEC, &link_cache)) < 0) {
192+
if ((err = rtnl_link_alloc_cache(get_nlc(), AF_UNSPEC, &link_cache)) < 0) {
193193
PyErr_SetString(PyExc_OSError, nl_geterror(err));
194194
return 0;
195195
}
196196
link = rtnl_link_alloc();
197-
if( !link ) {
197+
if (!link) {
198198
errno = ENOMEM;
199199
PyErr_SetFromErrno(PyExc_OSError);
200200
return 0;
@@ -226,12 +226,12 @@ PyObject * get_etherinfo_address(PyEtherInfo *self, nlQuery query)
226226
PyObject *addrlist = NULL;
227227
int err = 0;
228228

229-
if( !self ) {
229+
if (!self) {
230230
return NULL;
231231
}
232232

233233
/* Open a NETLINK connection on-the-fly */
234-
if( !open_netlink(self) ) {
234+
if (!open_netlink(self)) {
235235
PyErr_Format(PyExc_RuntimeError,
236236
"Could not open a NETLINK connection for %s",
237237
PyStr_AsString(self->device));
@@ -244,22 +244,22 @@ PyObject * get_etherinfo_address(PyEtherInfo *self, nlQuery query)
244244

245245
/* Query the for requested info via NETLINK */
246246
/* Extract IP address information */
247-
if( (err = rtnl_addr_alloc_cache(get_nlc(), &addr_cache)) < 0) {
247+
if ((err = rtnl_addr_alloc_cache(get_nlc(), &addr_cache)) < 0) {
248248
PyErr_SetString(PyExc_OSError, nl_geterror(err));
249249
nl_cache_free(addr_cache);
250250
return NULL;
251251
}
252252

253253
addr = rtnl_addr_alloc();
254254

255-
if( !addr ) {
255+
if (!addr) {
256256
errno = ENOMEM;
257257
PyErr_SetFromErrno(PyExc_OSError);
258258
return NULL;
259259
}
260260
rtnl_addr_set_ifindex(addr, self->index);
261261

262-
switch( query ) {
262+
switch( query) {
263263
case NLQRY_ADDR4:
264264
rtnl_addr_set_family(addr, AF_INET);
265265
break;

python-ethtool/etherinfo_obj.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ PyObject *_ethtool_etherinfo_str(PyEtherInfo *self)
9292
PyObject *ret = NULL;
9393
PyObject *ipv4addrs = NULL, *ipv6addrs = NULL;
9494

95-
if( !self ) {
95+
if (!self) {
9696
PyErr_SetString(PyExc_AttributeError, "No data available");
9797
return NULL;
9898
}
@@ -101,21 +101,21 @@ PyObject *_ethtool_etherinfo_str(PyEtherInfo *self)
101101

102102
ret = PyStr_FromFormat("Device %s:\n", PyStr_AsString(self->device));
103103

104-
if( self->hwaddress ) {
104+
if (self->hwaddress) {
105105
ret = PyStr_Concat(ret,
106106
PyStr_FromFormat("\tMAC address: %s\n",
107107
PyStr_AsString(self->hwaddress)));
108108
}
109109

110110
ipv4addrs = get_etherinfo_address(self, NLQRY_ADDR4);
111-
if( ipv4addrs ) {
111+
if (ipv4addrs) {
112112
Py_ssize_t i;
113113
for (i = 0; i < PyList_Size(ipv4addrs); i++) {
114114
PyNetlinkIPaddress *py_addr = (PyNetlinkIPaddress *)PyList_GetItem(ipv4addrs, i);
115115
PyObject *tmp = PyStr_FromFormat("\tIPv4 address: ");
116116
tmp = PyStr_Concat(tmp, py_addr->local);
117117
tmp = PyStr_Concat(tmp, PyStr_FromFormat("/%d", py_addr->prefixlen));
118-
if (py_addr->ipv4_broadcast ) {
118+
if (py_addr->ipv4_broadcast) {
119119
tmp = PyStr_Concat(tmp,
120120
PyStr_FromFormat("\tBroadcast: %s\n",
121121
PyStr_AsString(py_addr->ipv4_broadcast)));
@@ -128,7 +128,7 @@ PyObject *_ethtool_etherinfo_str(PyEtherInfo *self)
128128
}
129129

130130
ipv6addrs = get_etherinfo_address(self, NLQRY_ADDR6);
131-
if( ipv6addrs ) {
131+
if (ipv6addrs) {
132132
Py_ssize_t i;
133133
for (i = 0; i < PyList_Size(ipv6addrs); i++) {
134134
PyNetlinkIPaddress *py_addr = (PyNetlinkIPaddress *)PyList_GetItem(ipv6addrs, i);
@@ -152,7 +152,7 @@ PyObject *_ethtool_etherinfo_str(PyEtherInfo *self)
152152
* @return Returns a Python tuple list of NetlinkIP4Address objects
153153
*/
154154
static PyObject *_ethtool_etherinfo_get_ipv4_addresses(PyEtherInfo *self, PyObject *notused) {
155-
if( !self ) {
155+
if (!self) {
156156
PyErr_SetString(PyExc_AttributeError, "No data available");
157157
return NULL;
158158
}
@@ -170,7 +170,7 @@ static PyObject *_ethtool_etherinfo_get_ipv4_addresses(PyEtherInfo *self, PyObje
170170
* @return Returns a Python tuple list of NetlinkIP6Address objects
171171
*/
172172
static PyObject *_ethtool_etherinfo_get_ipv6_addresses(PyEtherInfo *self, PyObject *notused) {
173-
if( !self ) {
173+
if (!self) {
174174
PyErr_SetString(PyExc_AttributeError, "No data available");
175175
return NULL;
176176
}
@@ -197,7 +197,7 @@ static PyObject *get_device(PyObject *obj, void *info)
197197
{
198198
PyEtherInfo *self = (PyEtherInfo *) obj;
199199

200-
if( self->device ) {
200+
if (self->device) {
201201
Py_INCREF(self->device);
202202
return self->device;
203203
}
@@ -209,7 +209,7 @@ static PyObject *get_mac_addr(PyObject *obj, void *info)
209209
PyEtherInfo *self = (PyEtherInfo *) obj;
210210

211211
get_etherinfo_link(self);
212-
if( self->hwaddress ) {
212+
if (self->hwaddress) {
213213
Py_INCREF(self->hwaddress);
214214
}
215215
return self->hwaddress;

python-ethtool/ethtool.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static PyObject *get_devices(PyObject *self __unused, PyObject *args __unused)
9191
/* skip over first two lines */
9292
ret = fgets(buffer, 256, fd);
9393
ret = fgets(buffer, 256, fd);
94-
if( !ret ) {
94+
if (!ret) {
9595
return PyErr_SetFromErrno(PyExc_OSError);
9696
}
9797

@@ -222,32 +222,32 @@ static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
222222
}
223223

224224
/* Parse input arguments if we got them */
225-
if( inargs != NULL ) {
226-
if( PyStr_Check(inargs) ) { /* Input argument is just a string */
225+
if (inargs != NULL) {
226+
if (PyStr_Check(inargs)) { /* Input argument is just a string */
227227
fetch_devs_len = 1;
228228
fetch_devs = calloc(1, sizeof(char *));
229229
fetch_devs[0] = PyStr_AsString(inargs);
230230

231-
} else if( PyTuple_Check(inargs) ) { /* Input argument is a tuple list with devices */
231+
} else if (PyTuple_Check(inargs)) { /* Input argument is a tuple list with devices */
232232
int j = 0;
233233

234234
fetch_devs_len = PyTuple_Size(inargs);
235235
fetch_devs = calloc(fetch_devs_len+1, sizeof(char *));
236-
for( i = 0; i < fetch_devs_len; i++ ) {
236+
for (i = 0; i < fetch_devs_len; i++) {
237237
PyObject *elmt = PyTuple_GetItem(inargs, i);
238-
if( elmt && PyStr_Check(elmt) ) {
238+
if (elmt && PyStr_Check(elmt)) {
239239
fetch_devs[j++] = PyStr_AsString(elmt);
240240
}
241241
}
242242
fetch_devs_len = j;
243-
} else if( PyList_Check(inargs) ) { /* Input argument is a list with devices */
243+
} else if (PyList_Check(inargs)) { /* Input argument is a list with devices */
244244
int j = 0;
245245

246246
fetch_devs_len = PyList_Size(inargs);
247247
fetch_devs = calloc(fetch_devs_len+1, sizeof(char *));
248-
for( i = 0; i < fetch_devs_len; i++ ) {
248+
for (i = 0; i < fetch_devs_len; i++) {
249249
PyObject *elmt = PyList_GetItem(inargs, i);
250-
if( elmt && PyStr_Check(elmt) ) {
250+
if (elmt && PyStr_Check(elmt)) {
251251
fetch_devs[j++] = PyStr_AsString(elmt);
252252
}
253253
}
@@ -260,15 +260,15 @@ static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
260260
}
261261

262262
devlist = PyList_New(0);
263-
for( i = 0; i < fetch_devs_len; i++ ) {
263+
for (i = 0; i < fetch_devs_len; i++) {
264264
PyEtherInfo *dev = NULL;
265265

266266
/* Store the device name and a reference to the NETLINK connection for
267267
* objects to use when quering for device info
268268
*/
269269

270270
dev = PyObject_New(PyEtherInfo, &PyEtherInfo_Type);
271-
if( !dev ) {
271+
if (!dev) {
272272
PyErr_SetFromErrno(PyExc_OSError);
273273
free(fetch_devs);
274274
return NULL;

python-ethtool/netlink-address.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ PyNetlinkIPaddress_from_rtnl_addr(struct rtnl_addr *addr)
7979
/* Set ipv4_broadcast: */
8080
py_obj->ipv4_broadcast = NULL;
8181
brdcst = rtnl_addr_get_broadcast(addr);
82-
if( py_obj->family == AF_INET && brdcst ) {
82+
if (py_obj->family == AF_INET && brdcst) {
8383
memset(&buf, 0, sizeof(buf));
8484
if (!inet_ntop(AF_INET, nl_addr_get_binary_addr(brdcst),
8585
buf, sizeof(buf))) {
@@ -209,7 +209,7 @@ make_python_address_from_rtnl_addr(struct rtnl_addr *addr)
209209
{
210210
assert(addr);
211211

212-
switch( rtnl_addr_get_family(addr) ) {
212+
switch( rtnl_addr_get_family(addr)) {
213213

214214
case AF_INET:
215215
case AF_INET6:

python-ethtool/netlink.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ static unsigned int nlconnection_users = 0; /* How many NETLINK users are activ
3939
*/
4040
int open_netlink(PyEtherInfo *ethi)
4141
{
42-
if( !ethi ) {
42+
if (!ethi) {
4343
return 0;
4444
}
4545

4646
/* Reuse already established NETLINK connection, if a connection exists */
47-
if( nlconnection ) {
47+
if (nlconnection) {
4848
/* If this object has not used NETLINK earlier, tag it as a user */
49-
if( !ethi->nlc_active ) {
49+
if (!ethi->nlc_active) {
5050
pthread_mutex_lock(&nlc_counter_mtx);
5151
nlconnection_users++;
5252
pthread_mutex_unlock(&nlc_counter_mtx);
@@ -57,12 +57,12 @@ int open_netlink(PyEtherInfo *ethi)
5757

5858
/* No earlier connections exists, establish a new one */
5959
nlconnection = nl_socket_alloc();
60-
if( nlconnection != NULL ) {
61-
if( nl_connect(nlconnection, NETLINK_ROUTE) < 0 ) {
60+
if (nlconnection != NULL) {
61+
if (nl_connect(nlconnection, NETLINK_ROUTE) < 0) {
6262
return 0;
6363
}
6464
/* Force O_CLOEXEC flag on the NETLINK socket */
65-
if( fcntl(nl_socket_get_fd(nlconnection), F_SETFD, FD_CLOEXEC) == -1 ) {
65+
if (fcntl(nl_socket_get_fd(nlconnection), F_SETFD, FD_CLOEXEC) == -1) {
6666
fprintf(stderr,
6767
"**WARNING** Failed to set O_CLOEXEC on NETLINK socket: %s\n",
6868
strerror(errno));
@@ -99,7 +99,7 @@ struct nl_sock * get_nlc()
9999
*/
100100
void close_netlink(PyEtherInfo *ethi)
101101
{
102-
if( !ethi || !nlconnection ) {
102+
if (!ethi || !nlconnection) {
103103
return;
104104
}
105105

@@ -110,7 +110,7 @@ void close_netlink(PyEtherInfo *ethi)
110110
pthread_mutex_unlock(&nlc_counter_mtx);
111111

112112
/* Don't close the connection if there are more users */
113-
if( nlconnection_users > 0) {
113+
if (nlconnection_users > 0) {
114114
return;
115115
}
116116

0 commit comments

Comments
 (0)