summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Bley <cbley@av-test.de>2013-08-22 11:16:03 +0200
committerClaudio Bley <cbley@av-test.de>2013-08-23 08:12:26 +0200
commitd101d3bce8c59583c5713215b6a7fb2f7376a1fc (patch)
treecbeaa7759899a4295ba7d628920261ff3b76987e
parent2d533bde3bad357a070b2703fed7292eb2e2fb55 (diff)
downloadlibvirt-python-split-d101d3bce8c59583c5713215b6a7fb2f7376a1fc.tar.gz
libvirt-python-split-d101d3bce8c59583c5713215b6a7fb2f7376a1fc.tar.xz
libvirt-python-split-d101d3bce8c59583c5713215b6a7fb2f7376a1fc.zip
Test for object identity when checking for None in Python
Consistently use "is" or "is not" to compare variables to None, because doing so is preferrable, as per PEP 8 (http://www.python.org/dev/peps/pep-0008/#programming-recommendations): > Comparisons to singletons like None should always be done with is or > is not, never the equality operators.
-rwxr-xr-xgenerator.py30
-rw-r--r--libvirt-override-virConnect.py2
-rw-r--r--libvirt-override-virStream.py4
3 files changed, 18 insertions, 18 deletions
diff --git a/generator.py b/generator.py
index 427cebc..6c7414a 100755
--- a/generator.py
+++ b/generator.py
@@ -136,7 +136,7 @@ class docParser(xml.sax.handler.ContentHandler):
print "end %s" % tag
if tag == 'function':
# fuctions come from source files, hence 'virerror.c'
- if self.function != None:
+ if self.function is not None:
if (self.function_module == "libvirt" or
self.function_module == "virevent" or
self.function_module == "virerror"):
@@ -641,9 +641,9 @@ def print_function_wrapper(module, name, output, export, include):
(f, t, n, c) = py_types[arg[1]]
if (f == 'z') and (name in foreign_encoding_args) and (num_bufs == 0):
f = 't#'
- if f != None:
+ if f is not None:
format = format + f
- if t != None:
+ if t is not None:
format_args = format_args + ", &pyobj_%s" % (arg[0])
c_args = c_args + " PyObject *pyobj_%s;\n" % (arg[0])
c_convert = c_convert + \
@@ -686,7 +686,7 @@ def print_function_wrapper(module, name, output, export, include):
elif py_types.has_key(ret[0]):
(f, t, n, c) = py_types[ret[0]]
c_return = " %s c_retval;\n" % (ret[0])
- if file == "python_accessor" and ret[2] != None:
+ if file == "python_accessor" and ret[2] is not None:
c_call = "\n c_retval = %s->%s;\n" % (args[0][0], ret[2])
else:
c_call = "\n c_retval = %s(%s);\n" % (name, c_call)
@@ -708,7 +708,7 @@ def print_function_wrapper(module, name, output, export, include):
unknown_types[ret[0]] = [name]
return -1
- if cond != None and cond != "":
+ if cond is not None and cond != "":
include.write("#if %s\n" % cond)
export.write("#if %s\n" % cond)
output.write("#if %s\n" % cond)
@@ -729,14 +729,14 @@ def print_function_wrapper(module, name, output, export, include):
if file == "python":
# Those have been manually generated
- if cond != None and cond != "":
+ if cond is not None and cond != "":
include.write("#endif\n")
export.write("#endif\n")
output.write("#endif\n")
return 1
if file == "python_accessor" and ret[0] != "void" and ret[2] is None:
# Those have been manually generated
- if cond != None and cond != "":
+ if cond is not None and cond != "":
include.write("#endif\n")
export.write("#endif\n")
output.write("#endif\n")
@@ -771,7 +771,7 @@ def print_function_wrapper(module, name, output, export, include):
output.write(" LIBVIRT_END_ALLOW_THREADS;\n")
output.write(ret_convert)
output.write("}\n\n")
- if cond != None and cond != "":
+ if cond is not None and cond != "":
include.write("#endif /* %s */\n" % cond)
export.write("#endif /* %s */\n" % cond)
output.write("#endif /* %s */\n" % cond)
@@ -1313,7 +1313,7 @@ def buildWrappers(module):
classes.write("#\n")
classes.write("# WARNING WARNING WARNING WARNING\n")
classes.write("#\n")
- if extra != None:
+ if extra is not None:
classes.writelines(extra.readlines())
classes.write("#\n")
classes.write("# WARNING WARNING WARNING WARNING\n")
@@ -1321,7 +1321,7 @@ def buildWrappers(module):
classes.write("# Automatically written part of python bindings for libvirt\n")
classes.write("#\n")
classes.write("# WARNING WARNING WARNING WARNING\n")
- if extra != None:
+ if extra is not None:
extra.close()
if function_classes.has_key("None"):
@@ -1460,7 +1460,7 @@ def buildWrappers(module):
destruct=None
if classes_destructors.has_key(classname):
classes.write(" def __del__(self):\n")
- classes.write(" if self._o != None:\n")
+ classes.write(" if self._o is not None:\n")
classes.write(" libvirtmod.%s(self._o)\n" %
classes_destructors[classname])
classes.write(" self._o = None\n\n")
@@ -1776,7 +1776,7 @@ def qemuBuildWrappers(module):
fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n")
fd.write("#\n")
- if extra != None:
+ if extra is not None:
fd.writelines(extra.readlines())
fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n")
@@ -1784,7 +1784,7 @@ def qemuBuildWrappers(module):
fd.write("# Automatically written part of python bindings for libvirt\n")
fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n")
- if extra != None:
+ if extra is not None:
extra.close()
fd.write("try:\n")
@@ -1888,7 +1888,7 @@ def lxcBuildWrappers(module):
fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n")
fd.write("#\n")
- if extra != None:
+ if extra is not None:
fd.writelines(extra.readlines())
fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n")
@@ -1896,7 +1896,7 @@ def lxcBuildWrappers(module):
fd.write("# Automatically written part of python bindings for libvirt\n")
fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n")
- if extra != None:
+ if extra is not None:
extra.close()
fd.write("try:\n")
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
index 044faa0..4ba3d30 100644
--- a/libvirt-override-virConnect.py
+++ b/libvirt-override-virConnect.py
@@ -7,7 +7,7 @@
except AttributeError:
pass
- if self._o != None:
+ if self._o is not None:
libvirtmod.virConnectClose(self._o)
self._o = None
diff --git a/libvirt-override-virStream.py b/libvirt-override-virStream.py
index b5cec2a..53000da 100644
--- a/libvirt-override-virStream.py
+++ b/libvirt-override-virStream.py
@@ -5,7 +5,7 @@
except AttributeError:
pass
- if self._o != None:
+ if self._o is not None:
libvirtmod.virStreamFree(self._o)
self._o = None
@@ -103,7 +103,7 @@
the request would block, integer -2 is returned.
"""
ret = libvirtmod.virStreamRecv(self._o, nbytes)
- if ret == None: raise libvirtError ('virStreamRecv() failed')
+ if ret is None: raise libvirtError ('virStreamRecv() failed')
return ret
def send(self, data):