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. Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx> --- Purely mechanical change, using: find . -name '*.py' -exec sed -i -e 's,[ \t][ \t]*!=[ \t][ \t]*None, is not None,g' '{}' \+ find . -name '*.py' -exec sed -i -e 's,[ \t][ \t]*==[ \t][ \t]*None, is None,g' '{}' \+ docs/apibuild.py | 254 ++++++++++++++++----------------- docs/index.py | 178 +++++++++++------------ examples/python/consolecallback.py | 2 +- examples/python/dominfo.py | 2 +- examples/python/domrestore.py | 2 +- examples/python/domsave.py | 2 +- examples/python/domstart.py | 4 +- python/generator.py | 30 ++-- python/libvirt-override-virConnect.py | 2 +- python/libvirt-override-virStream.py | 4 +- 10 files changed, 240 insertions(+), 240 deletions(-) diff --git a/docs/apibuild.py b/docs/apibuild.py index 5c55d79..ab6b0b4 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -111,7 +111,7 @@ class identifier: self.extra = extra self.lineno = lineno self.static = 0 - if conditionals == None or len(conditionals) == 0: + if conditionals is None or len(conditionals) == 0: self.conditionals = None else: self.conditionals = conditionals[:] @@ -123,13 +123,13 @@ class identifier: r = "%s %s:" % (self.type, self.name) if self.static: r = r + " static" - if self.module != None: + if self.module is not None: r = r + " from %s" % (self.module) - if self.info != None: + if self.info is not None: r = r + " " + `self.info` - if self.extra != None: + if self.extra is not None: r = r + " " + `self.extra` - if self.conditionals != None: + if self.conditionals is not None: r = r + " " + `self.conditionals` return r @@ -149,7 +149,7 @@ class identifier: def set_static(self, static): self.static = static def set_conditionals(self, conditionals): - if conditionals == None or len(conditionals) == 0: + if conditionals is None or len(conditionals) == 0: self.conditionals = None else: self.conditionals = conditionals[:] @@ -178,17 +178,17 @@ class identifier: if self.name == debugsym and not quiet: print "=> update %s : %s" % (debugsym, (module, type, info, extra, conditionals)) - if header != None and self.header == None: + if header is not None and self.header is None: self.set_header(module) - if module != None and (self.module == None or self.header == self.module): + if module is not None and (self.module is None or self.header == self.module): self.set_module(module) - if type != None and self.type == None: + if type is not None and self.type is None: self.set_type(type) - if info != None: + if info is not None: self.set_info(info) - if extra != None: + if extra is not None: self.set_extra(extra) - if conditionals != None: + if conditionals is not None: self.set_conditionals(conditionals) class index: @@ -217,10 +217,10 @@ class index: d = identifier(name, header, module, type, lineno, info, extra, conditionals) self.identifiers[name] = d - if d != None and static == 1: + if d is not None and static == 1: d.set_static(1) - if d != None and name != None and type != None: + if d is not None and name is not None and type is not None: self.references[name] = d if name == debugsym and not quiet: @@ -239,10 +239,10 @@ class index: d = identifier(name, header, module, type, lineno, info, extra, conditionals) self.identifiers[name] = d - if d != None and static == 1: + if d is not None and static == 1: d.set_static(1) - if d != None and name != None and type != None: + if d is not None and name is not None and type is not None: if type == "function": self.functions[name] = d elif type == "functype": @@ -432,7 +432,7 @@ class CLexer: else: line = self.line self.line = "" - if line == None: + if line is None: return None if line[0] == '#': @@ -461,7 +461,7 @@ class CLexer: tok = tok + line if found == 0: line = self.getline() - if line == None: + if line is None: return None self.last = ('string', tok) return self.last @@ -486,7 +486,7 @@ class CLexer: tok = tok + line if found == 0: line = self.getline() - if line == None: + if line is None: return None self.last = ('comment', tok) return self.last @@ -598,7 +598,7 @@ class CParser: self.is_header = 0 self.input = open(filename) self.lexer = CLexer(self.input) - if idx == None: + if idx is None: self.index = index() else: self.index = idx @@ -707,7 +707,7 @@ class CParser: com = token[1] if self.top_comment == "": self.top_comment = com - if self.comment == None or com[0] == '*': + if self.comment is None or com[0] == '*': self.comment = com else: self.comment = self.comment + com @@ -731,7 +731,7 @@ class CParser: args = [] desc = "" - if self.comment == None: + if self.comment is None: if not quiet: self.warning("Missing comment for type %s" % (name)) return((args, desc)) @@ -780,7 +780,7 @@ class CParser: args = [] desc = "" - if self.comment == None: + if self.comment is None: if not quiet: self.warning("Missing comment for macro %s" % (name)) return((args, desc)) @@ -860,7 +860,7 @@ class CParser: desc = "" retdesc = "" - if self.comment == None: + if self.comment is None: if not quiet: self.warning("Missing comment for function %s" % (name)) return(((ret[0], retdesc), args, desc)) @@ -958,7 +958,7 @@ class CParser: # i = 0 while i < nbargs: - if args[i][2] == None and args[i][0] != "void" and args[i][1] != None: + if args[i][2] is None and args[i][0] != "void" and args[i][1] is not None: self.warning("Function comment for %s lacks description of arg %s" % (name, args[i][1])) i = i + 1 if retdesc == "" and ret[0] != "void": @@ -975,7 +975,7 @@ class CParser: name = token[1] if name == "#include": token = self.lexer.token() - if token == None: + if token is None: return None if token[0] == 'preproc': self.index_add(token[1], self.filename, not self.is_header, @@ -984,14 +984,14 @@ class CParser: return token if name == "#define": token = self.lexer.token() - if token == None: + if token is None: return None if token[0] == 'preproc': # TODO macros with arguments name = token[1] lst = [] token = self.lexer.token() - while token != None and token[0] == 'preproc' and \ + while token is not None and token[0] == 'preproc' and \ token[1][0] != '#': lst.append(token[1]) token = self.lexer.token() @@ -1059,7 +1059,7 @@ class CParser: self.conditionals = self.conditionals[:-1] self.defines = self.defines[:-1] token = self.lexer.token() - while token != None and token[0] == 'preproc' and \ + while token is not None and token[0] == 'preproc' and \ token[1][0] != '#': token = self.lexer.token() return token @@ -1076,7 +1076,7 @@ class CParser: global ignored_words token = self.lexer.token() - while token != None: + while token is not None: if token[0] == 'comment': token = self.parseComment(token) continue @@ -1088,7 +1088,7 @@ class CParser: return token elif token[0] == "name" and token[1] == "__attribute": token = self.lexer.token() - while token != None and token[1] != ";": + while token is not None and token[1] != ";": token = self.lexer.token() return token elif token[0] == "name" and ignored_words.has_key(token[1]): @@ -1109,20 +1109,20 @@ class CParser: # Parse a typedef, it records the type and its name. # def parseTypedef(self, token): - if token == None: + if token is None: return None token = self.parseType(token) - if token == None: + if token is None: self.error("parsing typedef") return None base_type = self.type type = base_type #self.debug("end typedef type", token) - while token != None: + while token is not None: if token[0] == "name": name = token[1] signature = self.signature - if signature != None: + if signature is not None: type = string.split(type, '(')[0] d = self.mergeFunctionComment(name, ((type, None), signature), 1) @@ -1143,15 +1143,15 @@ class CParser: self.error("parsing typedef: expecting a name") return token #self.debug("end typedef", token) - if token != None and token[0] == 'sep' and token[1] == ',': + if token is not None and token[0] == 'sep' and token[1] == ',': type = base_type token = self.token() - while token != None and token[0] == "op": + while token is not None and token[0] == "op": type = type + token[1] token = self.token() - elif token != None and token[0] == 'sep' and token[1] == ';': + elif token is not None and token[0] == 'sep' and token[1] == ';': break - elif token != None and token[0] == 'name': + elif token is not None and token[0] == 'name': type = base_type continue else: @@ -1165,7 +1165,7 @@ class CParser: # the balancing } included # def parseBlock(self, token): - while token != None: + while token is not None: if token[0] == "sep" and token[1] == "{": token = self.token() token = self.parseBlock(token) @@ -1205,7 +1205,7 @@ class CParser: def parseStruct(self, token): fields = [] #self.debug("start parseStruct", token) - while token != None: + while token is not None: if token[0] == "sep" and token[1] == "{": token = self.token() token = self.parseTypeBlock(token) @@ -1220,7 +1220,7 @@ class CParser: #self.debug("before parseType", token) token = self.parseType(token) #self.debug("after parseType", token) - if token != None and token[0] == "name": + if token is not None and token[0] == "name": fname = token[1] token = self.token() if token[0] == "sep" and token[1] == ";": @@ -1236,12 +1236,12 @@ class CParser: self.comment = None else: self.error("parseStruct: expecting ;", token) - elif token != None and token[0] == "sep" and token[1] == "{": + elif token is not None and token[0] == "sep" and token[1] == "{": token = self.token() token = self.parseTypeBlock(token) - if token != None and token[0] == "name": + if token is not None and token[0] == "name": token = self.token() - if token != None and token[0] == "sep" and token[1] == ";": + if token is not None and token[0] == "sep" and token[1] == ";": token = self.token() else: self.error("parseStruct: expecting ;", token) @@ -1260,7 +1260,7 @@ class CParser: def parseUnion(self, token): fields = [] # self.debug("start parseUnion", token) - while token != None: + while token is not None: if token[0] == "sep" and token[1] == "{": token = self.token() token = self.parseTypeBlock(token) @@ -1275,7 +1275,7 @@ class CParser: # self.debug("before parseType", token) token = self.parseType(token) # self.debug("after parseType", token) - if token != None and token[0] == "name": + if token is not None and token[0] == "name": fname = token[1] token = self.token() if token[0] == "sep" and token[1] == ";": @@ -1286,12 +1286,12 @@ class CParser: self.comment = None else: self.error("parseUnion: expecting ;", token) - elif token != None and token[0] == "sep" and token[1] == "{": + elif token is not None and token[0] == "sep" and token[1] == "{": token = self.token() token = self.parseTypeBlock(token) - if token != None and token[0] == "name": + if token is not None and token[0] == "name": token = self.token() - if token != None and token[0] == "sep" and token[1] == ";": + if token is not None and token[0] == "sep" and token[1] == ";": token = self.token() else: self.error("parseUnion: expecting ;", token) @@ -1313,14 +1313,14 @@ class CParser: self.comment = None comment = "" value = "0" - while token != None: + while token is not None: if token[0] == "sep" and token[1] == "{": token = self.token() token = self.parseTypeBlock(token) elif token[0] == "sep" and token[1] == "}": - if name != None: + if name is not None: self.cleanupComment() - if self.comment != None: + if self.comment is not None: comment = self.comment self.comment = None self.enums.append((name, value, comment)) @@ -1328,8 +1328,8 @@ class CParser: return token elif token[0] == "name": self.cleanupComment() - if name != None: - if self.comment != None: + if name is not None: + if self.comment is not None: comment = string.strip(self.comment) self.comment = None self.enums.append((name, value, comment)) @@ -1451,7 +1451,7 @@ class CParser: # the balancing } # def parseTypeBlock(self, token): - while token != None: + while token is not None: if token[0] == "sep" and token[1] == "{": token = self.token() token = self.parseTypeBlock(token) @@ -1472,7 +1472,7 @@ class CParser: self.struct_fields = [] self.union_fields = [] self.signature = None - if token == None: + if token is None: return token while token[0] == "name" and ( @@ -1524,13 +1524,13 @@ class CParser: if token[0] == "name": nametok = token token = self.token() - if token != None and token[0] == "sep" and token[1] == "{": + if token is not None and token[0] == "sep" and token[1] == "{": token = self.token() token = self.parseStruct(token) - elif token != None and token[0] == "op" and token[1] == "*": + elif token is not None and token[0] == "op" and token[1] == "*": self.type = self.type + " " + nametok[1] + " *" token = self.token() - while token != None and token[0] == "op" and token[1] == "*": + while token is not None and token[0] == "op" and token[1] == "*": self.type = self.type + " *" token = self.token() if token[0] == "name": @@ -1539,11 +1539,11 @@ class CParser: else: self.error("struct : expecting name", token) return token - elif token != None and token[0] == "name" and nametok != None: + elif token is not None and token[0] == "name" and nametok is not None: self.type = self.type + " " + nametok[1] return token - if nametok != None: + if nametok is not None: self.lexer.push(token) token = nametok return token @@ -1558,14 +1558,14 @@ class CParser: if token[0] == "name": nametok = token token = self.token() - if token != None and token[0] == "sep" and token[1] == "{": + if token is not None and token[0] == "sep" and token[1] == "{": token = self.token() token = self.parseUnion(token) - elif token != None and token[0] == "name" and nametok != None: + elif token is not None and token[0] == "name" and nametok is not None: self.type = self.type + " " + nametok[1] return token - if nametok != None: + if nametok is not None: self.lexer.push(token) token = nametok return token @@ -1577,13 +1577,13 @@ class CParser: self.type = self.type + " " + token[1] self.enums = [] token = self.token() - if token != None and token[0] == "sep" and token[1] == "{": + if token is not None and token[0] == "sep" and token[1] == "{": token = self.token() token = self.parseEnumBlock(token) else: self.error("parsing enum: expecting '{'", token) enum_type = None - if token != None and token[0] != "name": + if token is not None and token[0] != "name": self.lexer.push(token) token = ("name", "enum") else: @@ -1595,24 +1595,24 @@ class CParser: return token elif token[0] == "name" and token[1] == "VIR_ENUM_DECL": token = self.token() - if token != None and token[0] == "sep" and token[1] == "(": + if token is not None and token[0] == "sep" and token[1] == "(": token = self.token() token = self.parseVirEnumDecl(token) else: self.error("parsing VIR_ENUM_DECL: expecting '('", token) - if token != None: + if token is not None: self.lexer.push(token) token = ("name", "virenumdecl") return token elif token[0] == "name" and token[1] == "VIR_ENUM_IMPL": token = self.token() - if token != None and token[0] == "sep" and token[1] == "(": + if token is not None and token[0] == "sep" and token[1] == "(": token = self.token() token = self.parseVirEnumImpl(token) else: self.error("parsing VIR_ENUM_IMPL: expecting '('", token) - if token != None: + if token is not None: self.lexer.push(token) token = ("name", "virenumimpl") return token @@ -1627,7 +1627,7 @@ class CParser: token) return token token = self.token() - while token != None and (token[0] == "op" or + while token is not None and (token[0] == "op" or token[0] == "name" and token[1] == "const"): self.type = self.type + " " + token[1] token = self.token() @@ -1635,22 +1635,22 @@ class CParser: # # if there is a parenthesis here, this means a function type # - if token != None and token[0] == "sep" and token[1] == '(': + if token is not None and token[0] == "sep" and token[1] == '(': self.type = self.type + token[1] token = self.token() - while token != None and token[0] == "op" and token[1] == '*': + while token is not None and token[0] == "op" and token[1] == '*': self.type = self.type + token[1] token = self.token() - if token == None or token[0] != "name" : + if token is None or token[0] != "name" : self.error("parsing function type, name expected", token) return token self.type = self.type + token[1] nametok = token token = self.token() - if token != None and token[0] == "sep" and token[1] == ')': + if token is not None and token[0] == "sep" and token[1] == ')': self.type = self.type + token[1] token = self.token() - if token != None and token[0] == "sep" and token[1] == '(': + if token is not None and token[0] == "sep" and token[1] == '(': token = self.token() type = self.type token = self.parseSignature(token) @@ -1668,25 +1668,25 @@ class CParser: # # do some lookahead for arrays # - if token != None and token[0] == "name": + if token is not None and token[0] == "name": nametok = token token = self.token() - if token != None and token[0] == "sep" and token[1] == '[': + if token is not None and token[0] == "sep" and token[1] == '[': self.type = self.type + " " + nametok[1] - while token != None and token[0] == "sep" and token[1] == '[': + while token is not None and token[0] == "sep" and token[1] == '[': self.type = self.type + token[1] token = self.token() - while token != None and token[0] != 'sep' and \ + while token is not None and token[0] != 'sep' and \ token[1] != ']' and token[1] != ';': self.type = self.type + token[1] token = self.token() - if token != None and token[0] == 'sep' and token[1] == ']': + if token is not None and token[0] == 'sep' and token[1] == ']': self.type = self.type + token[1] token = self.token() else: self.error("parsing array type, ']' expected", token) return token - elif token != None and token[0] == "sep" and token[1] == ':': + elif token is not None and token[0] == "sep" and token[1] == ':': # remove :12 in case it's a limited int size token = self.token() token = self.token() @@ -1700,25 +1700,25 @@ class CParser: # up to the ')' included def parseSignature(self, token): signature = [] - if token != None and token[0] == "sep" and token[1] == ')': + if token is not None and token[0] == "sep" and token[1] == ')': self.signature = [] token = self.token() return token - while token != None: + while token is not None: token = self.parseType(token) - if token != None and token[0] == "name": + if token is not None and token[0] == "name": signature.append((self.type, token[1], None)) token = self.token() - elif token != None and token[0] == "sep" and token[1] == ',': + elif token is not None and token[0] == "sep" and token[1] == ',': token = self.token() continue - elif token != None and token[0] == "sep" and token[1] == ')': + elif token is not None and token[0] == "sep" and token[1] == ')': # only the type was provided if self.type == "...": signature.append((self.type, "...", None)) else: signature.append((self.type, None, None)) - if token != None and token[0] == "sep": + if token is not None and token[0] == "sep": if token[1] == ',': token = self.token() continue @@ -1813,17 +1813,17 @@ class CParser: static = 0 if token[1] == 'extern': token = self.token() - if token == None: + if token is None: return token if token[0] == 'string': if token[1] == 'C': token = self.token() - if token == None: + if token is None: return token if token[0] == 'sep' and token[1] == "{": token = self.token() # print 'Entering extern "C line ', self.lineno() - while token != None and (token[0] != 'sep' or + while token is not None and (token[0] != 'sep' or token[1] != "}"): if token[0] == 'name': token = self.parseGlobal(token) @@ -1840,7 +1840,7 @@ class CParser: elif token[1] == 'static': static = 1 token = self.token() - if token == None or token[0] != 'name': + if token is None or token[0] != 'name': return token if token[1] == 'typedef': @@ -1849,22 +1849,22 @@ class CParser: else: token = self.parseType(token) type_orig = self.type - if token == None or token[0] != "name": + if token is None or token[0] != "name": return token type = type_orig self.name = token[1] token = self.token() - while token != None and (token[0] == "sep" or token[0] == "op"): + while token is not None and (token[0] == "sep" or token[0] == "op"): if token[0] == "sep": if token[1] == "[": type = type + token[1] token = self.token() - while token != None and (token[0] != "sep" or \ + while token is not None and (token[0] != "sep" or \ token[1] != ";"): type = type + token[1] token = self.token() - if token != None and token[0] == "op" and token[1] == "=": + if token is not None and token[0] == "op" and token[1] == "=": # # Skip the initialization of the variable # @@ -1874,15 +1874,15 @@ class CParser: token = self.parseBlock(token) else: self.comment = None - while token != None and (token[0] != "sep" or \ + while token is not None and (token[0] != "sep" or \ (token[1] != ';' and token[1] != ',')): token = self.token() self.comment = None - if token == None or token[0] != "sep" or (token[1] != ';' and + if token is None or token[0] != "sep" or (token[1] != ';' and token[1] != ','): self.error("missing ';' or ',' after value") - if token != None and token[0] == "sep": + if token is not None and token[0] == "sep": if token[1] == ";": self.comment = None token = self.token() @@ -1897,7 +1897,7 @@ class CParser: elif token[1] == "(": token = self.token() token = self.parseSignature(token) - if token == None: + if token is None: return None if token[0] == "sep" and token[1] == ";": self.checkLongLegacyFunction(self.name, type, self.signature) @@ -1920,10 +1920,10 @@ class CParser: "variable", type) type = type_orig token = self.token() - while token != None and token[0] == "sep": + while token is not None and token[0] == "sep": type = type + token[1] token = self.token() - if token != None and token[0] == "name": + if token is not None and token[0] == "name": self.name = token[1] token = self.token() else: @@ -1935,7 +1935,7 @@ class CParser: if not quiet: print "Parsing %s" % (self.filename) token = self.token() - while token != None: + while token is not None: if token[0] == 'name': token = self.parseGlobal(token) else: @@ -1977,7 +1977,7 @@ class docBuilder: print >>sys.stderr, "Error:", msg def indexString(self, id, str): - if str == None: + if str is None: return str = string.replace(str, "'", ' ') str = string.replace(str, '"', ' ') @@ -2069,17 +2069,17 @@ class docBuilder: id = self.idx.enums[name] output.write(" <enum name='%s' file='%s'" % (name, self.modulename_file(id.header))) - if id.info != None: + if id.info is not None: info = id.info - if info[0] != None and info[0] != '': + if info[0] is not None and info[0] != '': try: val = eval(info[0]) except: val = info[0] output.write(" value='%s'" % (val)) - if info[2] != None and info[2] != '': + if info[2] is not None and info[2] != '': output.write(" type='%s'" % info[2]) - if info[1] != None and info[1] != '': + if info[1] is not None and info[1] != '': output.write(" info='%s'" % escape(info[1])) output.write("/>\n") @@ -2087,15 +2087,15 @@ class docBuilder: id = self.idx.macros[name] output.write(" <macro name='%s' file='%s'>\n" % (name, self.modulename_file(id.header))) - if id.info != None: + if id.info is not None: try: (args, desc) = id.info - if desc != None and desc != "": + if desc is not None and desc != "": output.write(" <info><![CDATA[%s]]></info>\n" % (desc)) self.indexString(name, desc) for arg in args: (name, desc) = arg - if desc != None and desc != "": + if desc is not None and desc != "": output.write(" <arg name='%s' info='%s'/>\n" % ( name, escape(desc))) self.indexString(name, desc) @@ -2110,7 +2110,7 @@ class docBuilder: output.write(" <union>\n") for f in field[3]: desc = f[2] - if desc == None: + if desc is None: desc = '' else: desc = escape(desc) @@ -2133,7 +2133,7 @@ class docBuilder: for field in self.idx.structs[name].info: desc = field[2] self.indexString(name, desc) - if desc == None: + if desc is None: desc = '' else: desc = escape(desc) @@ -2151,7 +2151,7 @@ class docBuilder: name, self.modulename_file(id.header), id.info)) try: desc = id.extra - if desc != None and desc != "": + if desc is not None and desc != "": output.write(">\n <info><![CDATA[%s]]></info>\n" % (desc)) output.write(" </typedef>\n") else: @@ -2161,7 +2161,7 @@ class docBuilder: def serialize_variable(self, output, name): id = self.idx.variables[name] - if id.info != None: + if id.info is not None: output.write(" <variable name='%s' file='%s' type='%s'/>\n" % ( name, self.modulename_file(id.header), id.info)) else: @@ -2179,7 +2179,7 @@ class docBuilder: # # Processing of conditionals modified by Bill 1/1/05 # - if id.conditionals != None: + if id.conditionals is not None: apstr = "" for cond in id.conditionals: if apstr != "": @@ -2190,10 +2190,10 @@ class docBuilder: (ret, params, desc) = id.info output.write(" <info><![CDATA[%s]]></info>\n" % (desc)) self.indexString(name, desc) - if ret[0] != None: + if ret[0] is not None: if ret[0] == "void": output.write(" <return type='void'/>\n") - elif (ret[1] == None or ret[1] == '') and not ignored_functions.has_key(name): + elif (ret[1] is None or ret[1] == '') and not ignored_functions.has_key(name): self.error("Missing documentation for return of function `%s'" % name) else: output.write(" <return type='%s' info='%s'/>\n" % ( @@ -2202,7 +2202,7 @@ class docBuilder: for param in params: if param[0] == 'void': continue - if (param[2] == None or param[2] == ''): + if (param[2] is None or param[2] == ''): if ignored_functions.has_key(name): output.write(" <arg name='%s' type='%s' info=''/>\n" % (param[1], param[0])) else: @@ -2219,7 +2219,7 @@ class docBuilder: module = self.modulename_file(file) output.write(" <file name='%s'>\n" % (module)) dict = self.headers[file] - if dict.info != None: + if dict.info is not None: for data in ('Summary', 'Description', 'Author'): try: output.write(" <%s>%s</%s>\n" % ( @@ -2352,12 +2352,12 @@ class docBuilder: ids.sort() for id in ids: if id[0] != letter: - if letter != None: + if letter is not None: output.write(" </letter>\n") letter = id[0] output.write(" <letter name='%s'>\n" % (letter)) output.write(" <ref name='%s'/>\n" % (id)) - if letter != None: + if letter is not None: output.write(" </letter>\n") def serialize_xrefs_references(self, output): @@ -2383,8 +2383,8 @@ class docBuilder: if len(index[id]) > 30: continue if id[0] != letter: - if letter == None or count > 200: - if letter != None: + if letter is None or count > 200: + if letter is not None: output.write(" </letter>\n") output.write(" </chunk>\n") count = 0 @@ -2392,7 +2392,7 @@ class docBuilder: output.write(" <chunk name='chunk%s'>\n" % (chunk)) first_letter = id[0] chunk = chunk + 1 - elif letter != None: + elif letter is not None: output.write(" </letter>\n") letter = id[0] output.write(" <letter name='%s'>\n" % (letter)) @@ -2407,7 +2407,7 @@ class docBuilder: output.write(" <ref name='%s'/>\n" % (token)) count = count + 1 output.write(" </word>\n") - if letter != None: + if letter is not None: output.write(" </letter>\n") output.write(" </chunk>\n") if count != 0: diff --git a/docs/index.py b/docs/index.py index ce5180f..2f0ad26 100755 --- a/docs/index.py +++ b/docs/index.py @@ -127,9 +127,9 @@ DB=None def createTable(db, name): global TABLES - if db == None: + if db is None: return -1 - if name == None: + if name is None: return -1 c = db.cursor() @@ -147,7 +147,7 @@ def createTable(db, name): def checkTables(db, verbose = 1): global TABLES - if db == None: + if db is None: return -1 c = db.cursor() nbtables = c.execute("show tables") @@ -191,7 +191,7 @@ def checkTables(db, verbose = 1): def openMySQL(db="libvir", passwd=None, verbose = 1): global DB - if passwd == None: + if passwd is None: try: passwd = os.environ["MySQL_PASS"] except: @@ -199,7 +199,7 @@ def openMySQL(db="libvir", passwd=None, verbose = 1): sys.exit(1) DB = MySQLdb.connect(passwd=passwd, db=db) - if DB == None: + if DB is None: return -1 ret = checkTables(DB, verbose) return ret @@ -207,13 +207,13 @@ def openMySQL(db="libvir", passwd=None, verbose = 1): def updateWord(name, symbol, relevance): global DB - if DB == None: + if DB is None: openMySQL() - if DB == None: + if DB is None: return -1 - if name == None: + if name is None: return -1 - if symbol == None: + if symbol is None: return -1 c = DB.cursor() @@ -238,15 +238,15 @@ def updateSymbol(name, module, type, desc): global DB updateWord(name, name, 50) - if DB == None: + if DB is None: openMySQL() - if DB == None: + if DB is None: return -1 - if name == None: + if name is None: return -1 - if module == None: + if module is None: return -1 - if type == None: + if type is None: return -1 try: @@ -299,11 +299,11 @@ def addFunctype(name, module, desc = ""): def addPage(resource, title): global DB - if DB == None: + if DB is None: openMySQL() - if DB == None: + if DB is None: return -1 - if resource == None: + if resource is None: return -1 c = DB.cursor() @@ -327,17 +327,17 @@ def addPage(resource, title): def updateWordHTML(name, resource, desc, id, relevance): global DB - if DB == None: + if DB is None: openMySQL() - if DB == None: + if DB is None: return -1 - if name == None: + if name is None: return -1 - if resource == None: + if resource is None: return -1 - if id == None: + if id is None: id = "" - if desc == None: + if desc is None: desc = "" else: try: @@ -367,11 +367,11 @@ def updateWordHTML(name, resource, desc, id, relevance): def checkXMLMsgArchive(url): global DB - if DB == None: + if DB is None: openMySQL() - if DB == None: + if DB is None: return -1 - if url == None: + if url is None: return -1 c = DB.cursor() @@ -379,7 +379,7 @@ def checkXMLMsgArchive(url): ret = c.execute( """SELECT ID FROM archives WHERE resource='%s'""" % (url)) row = c.fetchone() - if row == None: + if row is None: return -1 except: return -1 @@ -389,13 +389,13 @@ def checkXMLMsgArchive(url): def addXMLMsgArchive(url, title): global DB - if DB == None: + if DB is None: openMySQL() - if DB == None: + if DB is None: return -1 - if url == None: + if url is None: return -1 - if title == None: + if title is None: title = "" else: title = string.replace(title, "'", " ") @@ -408,7 +408,7 @@ def addXMLMsgArchive(url, title): cmd = """SELECT ID FROM archives WHERE resource='%s'""" % (url) ret = c.execute(cmd) row = c.fetchone() - if row == None: + if row is None: print "addXMLMsgArchive failed to get the ID: %s" % (url) return -1 except: @@ -420,13 +420,13 @@ def addXMLMsgArchive(url, title): def updateWordArchive(name, id, relevance): global DB - if DB == None: + if DB is None: openMySQL() - if DB == None: + if DB is None: return -1 - if name == None: + if name is None: return -1 - if id == None: + if id is None: return -1 c = DB.cursor() @@ -533,9 +533,9 @@ def splitIdentifier(str): def addWord(word, module, symbol, relevance): global wordsDict - if word == None or len(word) < 3: + if word is None or len(word) < 3: return -1 - if module == None or symbol == None: + if module is None or symbol is None: return -1 if dropWords.has_key(word): return 0 @@ -544,7 +544,7 @@ def addWord(word, module, symbol, relevance): if wordsDict.has_key(word): d = wordsDict[word] - if d == None: + if d is None: return 0 if len(d) > 500: wordsDict[word] = None @@ -559,7 +559,7 @@ def addWord(word, module, symbol, relevance): return relevance def addString(str, module, symbol, relevance): - if str == None or len(str) < 3: + if str is None or len(str) < 3: return -1 ret = 0 str = cleanupWordsString(str) @@ -573,9 +573,9 @@ def addString(str, module, symbol, relevance): def addWordHTML(word, resource, id, section, relevance): global wordsDictHTML - if word == None or len(word) < 3: + if word is None or len(word) < 3: return -1 - if resource == None or section == None: + if resource is None or section is None: return -1 if dropWords.has_key(word): return 0 @@ -586,14 +586,14 @@ def addWordHTML(word, resource, id, section, relevance): if wordsDictHTML.has_key(word): d = wordsDictHTML[word] - if d == None: + if d is None: print "skipped %s" % (word) return 0 try: (r,i,s) = d[resource] - if i != None: + if i is not None: id = i - if s != None: + if s is not None: section = s relevance = relevance + r except: @@ -605,7 +605,7 @@ def addWordHTML(word, resource, id, section, relevance): return relevance def addStringHTML(str, resource, id, section, relevance): - if str == None or len(str) < 3: + if str is None or len(str) < 3: return -1 ret = 0 str = cleanupWordsString(str) @@ -626,9 +626,9 @@ def addStringHTML(str, resource, id, section, relevance): def addWordArchive(word, id, relevance): global wordsDictArchive - if word == None or len(word) < 3: + if word is None or len(word) < 3: return -1 - if id == None or id == -1: + if id is None or id == -1: return -1 if dropWords.has_key(word): return 0 @@ -637,7 +637,7 @@ def addWordArchive(word, id, relevance): if wordsDictArchive.has_key(word): d = wordsDictArchive[word] - if d == None: + if d is None: print "skipped %s" % (word) return 0 try: @@ -652,7 +652,7 @@ def addWordArchive(word, id, relevance): return relevance def addStringArchive(str, id, relevance): - if str == None or len(str) < 3: + if str is None or len(str) < 3: return -1 ret = 0 str = cleanupWordsString(str) @@ -683,9 +683,9 @@ def loadAPI(filename): return doc def foundExport(file, symbol): - if file == None: + if file is None: return 0 - if symbol == None: + if symbol is None: return 0 addFunction(symbol, file) l = splitIdentifier(symbol) @@ -697,7 +697,7 @@ def analyzeAPIFile(top): count = 0 name = top.prop("name") cur = top.children - while cur != None: + while cur is not None: if cur.type == 'text': cur = cur.next continue @@ -712,7 +712,7 @@ def analyzeAPIFiles(top): count = 0 cur = top.children - while cur != None: + while cur is not None: if cur.type == 'text': cur = cur.next continue @@ -725,10 +725,10 @@ def analyzeAPIFiles(top): def analyzeAPIEnum(top): file = top.prop("file") - if file == None: + if file is None: return 0 symbol = top.prop("name") - if symbol == None: + if symbol is None: return 0 addEnum(symbol, file) @@ -740,10 +740,10 @@ def analyzeAPIEnum(top): def analyzeAPIConst(top): file = top.prop("file") - if file == None: + if file is None: return 0 symbol = top.prop("name") - if symbol == None: + if symbol is None: return 0 addConst(symbol, file) @@ -755,10 +755,10 @@ def analyzeAPIConst(top): def analyzeAPIType(top): file = top.prop("file") - if file == None: + if file is None: return 0 symbol = top.prop("name") - if symbol == None: + if symbol is None: return 0 addType(symbol, file) @@ -769,10 +769,10 @@ def analyzeAPIType(top): def analyzeAPIFunctype(top): file = top.prop("file") - if file == None: + if file is None: return 0 symbol = top.prop("name") - if symbol == None: + if symbol is None: return 0 addFunctype(symbol, file) @@ -783,10 +783,10 @@ def analyzeAPIFunctype(top): def analyzeAPIStruct(top): file = top.prop("file") - if file == None: + if file is None: return 0 symbol = top.prop("name") - if symbol == None: + if symbol is None: return 0 addStruct(symbol, file) @@ -795,7 +795,7 @@ def analyzeAPIStruct(top): addWord(word, file, symbol, 10) info = top.prop("info") - if info != None: + if info is not None: info = string.replace(info, "'", " ") info = string.strip(info) l = string.split(info) @@ -806,17 +806,17 @@ def analyzeAPIStruct(top): def analyzeAPIMacro(top): file = top.prop("file") - if file == None: + if file is None: return 0 symbol = top.prop("name") - if symbol == None: + if symbol is None: return 0 symbol = string.replace(symbol, "'", " ") symbol = string.strip(symbol) info = None cur = top.children - while cur != None: + while cur is not None: if cur.type == 'text': cur = cur.next continue @@ -829,7 +829,7 @@ def analyzeAPIMacro(top): for word in l: addWord(word, file, symbol, 10) - if info == None: + if info is None: addMacro(symbol, file) print "Macro %s description has no <info>" % (symbol) return 0 @@ -845,17 +845,17 @@ def analyzeAPIMacro(top): def analyzeAPIFunction(top): file = top.prop("file") - if file == None: + if file is None: return 0 symbol = top.prop("name") - if symbol == None: + if symbol is None: return 0 symbol = string.replace(symbol, "'", " ") symbol = string.strip(symbol) info = None cur = top.children - while cur != None: + while cur is not None: if cur.type == 'text': cur = cur.next continue @@ -863,23 +863,23 @@ def analyzeAPIFunction(top): info = cur.content elif cur.name == "return": rinfo = cur.prop("info") - if rinfo != None: + if rinfo is not None: rinfo = string.replace(rinfo, "'", " ") rinfo = string.strip(rinfo) addString(rinfo, file, symbol, 7) elif cur.name == "arg": ainfo = cur.prop("info") - if ainfo != None: + if ainfo is not None: ainfo = string.replace(ainfo, "'", " ") ainfo = string.strip(ainfo) addString(ainfo, file, symbol, 5) name = cur.prop("name") - if name != None: + if name is not None: name = string.replace(name, "'", " ") name = string.strip(name) addWord(name, file, symbol, 7) cur = cur.next - if info == None: + if info is None: print "Function %s description has no <info>" % (symbol) addFunction(symbol, file, "") else: @@ -898,7 +898,7 @@ def analyzeAPISymbols(top): count = 0 cur = top.children - while cur != None: + while cur is not None: if cur.type == 'text': cur = cur.next continue @@ -923,14 +923,14 @@ def analyzeAPISymbols(top): def analyzeAPI(doc): count = 0 - if doc == None: + if doc is None: return -1 root = doc.getRootElement() if root.name != "api": print "Unexpected root name" return -1 cur = root.children - while cur != None: + while cur is not None: if cur.type == 'text': cur = cur.next continue @@ -1056,7 +1056,7 @@ def analyzeHTMLPages(): import time def getXMLDateArchive(t = None): - if t == None: + if t is None: t = time.time() T = time.gmtime(t) month = time.strftime("%B", T) @@ -1065,7 +1065,7 @@ def getXMLDateArchive(t = None): return url def scanXMLMsgArchive(url, title, force = 0): - if url == None or title == None: + if url is None or title is None: return 0 ID = checkXMLMsgArchive(url) @@ -1082,7 +1082,7 @@ def scanXMLMsgArchive(url, title, force = 0): doc = libxml2.htmlParseFile(url, None) except: doc = None - if doc == None: + if doc is None: print "Failed to parse %s" % (url) return 0 @@ -1105,7 +1105,7 @@ def scanXMLDateArchive(t = None, force = 0): doc = libxml2.htmlParseFile(url, None) except: doc = None - if doc == None: + if doc is None: print "Failed to parse %s" % (url) return -1 ctxt = doc.xpathNewContext() @@ -1114,16 +1114,16 @@ def scanXMLDateArchive(t = None, force = 0): newmsg = 0 for anchor in anchors: href = anchor.prop("href") - if href == None or href[0:3] != "msg": + if href is None or href[0:3] != "msg": continue try: links = links + 1 msg = libxml2.buildURI(href, url) title = anchor.content - if title != None and title[0:4] == 'Re: ': + if title is not None and title[0:4] == 'Re: ': title = title[4:] - if title != None and title[0:6] == '[xml] ': + if title is not None and title[0:6] == '[xml] ': title = title[6:] newmsg = newmsg + scanXMLMsgArchive(msg, title, force) @@ -1148,7 +1148,7 @@ def analyzeArchives(t = None, force = 0): skipped = 0 for word in wordsDictArchive.keys(): refs = wordsDictArchive[word] - if refs == None: + if refs is None: skipped = skipped + 1 continue for id in refs.keys(): @@ -1168,7 +1168,7 @@ def analyzeHTMLTop(): skipped = 0 for word in wordsDictHTML.keys(): refs = wordsDictHTML[word] - if refs == None: + if refs is None: skipped = skipped + 1 continue for resource in refs.keys(): @@ -1197,7 +1197,7 @@ def analyzeAPITop(): skipped = 0 for word in wordsDict.keys(): refs = wordsDict[word] - if refs == None: + if refs is None: skipped = skipped + 1 continue for (module, symbol) in refs.keys(): diff --git a/examples/python/consolecallback.py b/examples/python/consolecallback.py index 23316ce..d8e33a9 100644 --- a/examples/python/consolecallback.py +++ b/examples/python/consolecallback.py @@ -29,7 +29,7 @@ class Console(object): def check_console(console): if (console.state[0] == libvirt.VIR_DOMAIN_RUNNING or console.state[0] == libvirt.VIR_DOMAIN_PAUSED): - if console.stream == None: + if console.stream is None: console.stream = console.connection.newStream(libvirt.VIR_STREAM_NONBLOCK) console.domain.openConsole(None, console.stream, 0) console.stream.eventAddCallback(libvirt.VIR_STREAM_EVENT_READABLE, stream_callback, console) diff --git a/examples/python/dominfo.py b/examples/python/dominfo.py index 0d3238b..bfa3ca3 100755 --- a/examples/python/dominfo.py +++ b/examples/python/dominfo.py @@ -35,7 +35,7 @@ name = sys.argv[1] # Connect to libvirt conn = libvirt.openReadOnly(None) -if conn == None: +if conn is None: print 'Failed to open connection to the hypervisor' sys.exit(1) diff --git a/examples/python/domrestore.py b/examples/python/domrestore.py index ccc82f6..fffc90f 100755 --- a/examples/python/domrestore.py +++ b/examples/python/domrestore.py @@ -21,7 +21,7 @@ dir = sys.argv[1] imgs = os.listdir(dir) conn = libvirt.open(None) -if conn == None: +if conn is None: print 'Failed to open connection to the hypervisor' sys.exit(1) diff --git a/examples/python/domsave.py b/examples/python/domsave.py index 12ffac1..bac4536 100755 --- a/examples/python/domsave.py +++ b/examples/python/domsave.py @@ -19,7 +19,7 @@ if len(sys.argv) != 2: dir = sys.argv[1] conn = libvirt.open(None) -if conn == None: +if conn is None: print 'Failed to open connection to the hypervisor' sys.exit(1) diff --git a/examples/python/domstart.py b/examples/python/domstart.py index b1e89b8..b14fad1 100755 --- a/examples/python/domstart.py +++ b/examples/python/domstart.py @@ -33,7 +33,7 @@ if len(sys.argv) != 2: (name, xmldesc) = read_domain(sys.argv[1]) conn = libvirt.open(None) -if conn == None: +if conn is None: print 'Failed to open connection to the hypervisor' sys.exit(1) @@ -43,7 +43,7 @@ except libvirt.libvirtError: print "Starting domain %s ... " % name, sys.stdout.flush() dom = conn.createLinux(xmldesc, 0) - if dom == None: + if dom is None: print "failed" sys.exit(1) else: diff --git a/python/generator.py b/python/generator.py index 427cebc..6c7414a 100755 --- a/python/generator.py +++ b/python/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/python/libvirt-override-virConnect.py b/python/libvirt-override-virConnect.py index 044faa0..4ba3d30 100644 --- a/python/libvirt-override-virConnect.py +++ b/python/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/python/libvirt-override-virStream.py b/python/libvirt-override-virStream.py index b5cec2a..53000da 100644 --- a/python/libvirt-override-virStream.py +++ b/python/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): -- 1.7.9.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list