提交 2a409511 编写于 作者: C Claudio Bley

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.
上级 6e172109
此差异已折叠。
...@@ -127,9 +127,9 @@ DB=None ...@@ -127,9 +127,9 @@ DB=None
def createTable(db, name): def createTable(db, name):
global TABLES global TABLES
if db == None: if db is None:
return -1 return -1
if name == None: if name is None:
return -1 return -1
c = db.cursor() c = db.cursor()
...@@ -147,7 +147,7 @@ def createTable(db, name): ...@@ -147,7 +147,7 @@ def createTable(db, name):
def checkTables(db, verbose = 1): def checkTables(db, verbose = 1):
global TABLES global TABLES
if db == None: if db is None:
return -1 return -1
c = db.cursor() c = db.cursor()
nbtables = c.execute("show tables") nbtables = c.execute("show tables")
...@@ -191,7 +191,7 @@ def checkTables(db, verbose = 1): ...@@ -191,7 +191,7 @@ def checkTables(db, verbose = 1):
def openMySQL(db="libvir", passwd=None, verbose = 1): def openMySQL(db="libvir", passwd=None, verbose = 1):
global DB global DB
if passwd == None: if passwd is None:
try: try:
passwd = os.environ["MySQL_PASS"] passwd = os.environ["MySQL_PASS"]
except: except:
...@@ -199,7 +199,7 @@ def openMySQL(db="libvir", passwd=None, verbose = 1): ...@@ -199,7 +199,7 @@ def openMySQL(db="libvir", passwd=None, verbose = 1):
sys.exit(1) sys.exit(1)
DB = MySQLdb.connect(passwd=passwd, db=db) DB = MySQLdb.connect(passwd=passwd, db=db)
if DB == None: if DB is None:
return -1 return -1
ret = checkTables(DB, verbose) ret = checkTables(DB, verbose)
return ret return ret
...@@ -207,13 +207,13 @@ def openMySQL(db="libvir", passwd=None, verbose = 1): ...@@ -207,13 +207,13 @@ def openMySQL(db="libvir", passwd=None, verbose = 1):
def updateWord(name, symbol, relevance): def updateWord(name, symbol, relevance):
global DB global DB
if DB == None: if DB is None:
openMySQL() openMySQL()
if DB == None: if DB is None:
return -1 return -1
if name == None: if name is None:
return -1 return -1
if symbol == None: if symbol is None:
return -1 return -1
c = DB.cursor() c = DB.cursor()
...@@ -238,15 +238,15 @@ def updateSymbol(name, module, type, desc): ...@@ -238,15 +238,15 @@ def updateSymbol(name, module, type, desc):
global DB global DB
updateWord(name, name, 50) updateWord(name, name, 50)
if DB == None: if DB is None:
openMySQL() openMySQL()
if DB == None: if DB is None:
return -1 return -1
if name == None: if name is None:
return -1 return -1
if module == None: if module is None:
return -1 return -1
if type == None: if type is None:
return -1 return -1
try: try:
...@@ -299,11 +299,11 @@ def addFunctype(name, module, desc = ""): ...@@ -299,11 +299,11 @@ def addFunctype(name, module, desc = ""):
def addPage(resource, title): def addPage(resource, title):
global DB global DB
if DB == None: if DB is None:
openMySQL() openMySQL()
if DB == None: if DB is None:
return -1 return -1
if resource == None: if resource is None:
return -1 return -1
c = DB.cursor() c = DB.cursor()
...@@ -327,17 +327,17 @@ def addPage(resource, title): ...@@ -327,17 +327,17 @@ def addPage(resource, title):
def updateWordHTML(name, resource, desc, id, relevance): def updateWordHTML(name, resource, desc, id, relevance):
global DB global DB
if DB == None: if DB is None:
openMySQL() openMySQL()
if DB == None: if DB is None:
return -1 return -1
if name == None: if name is None:
return -1 return -1
if resource == None: if resource is None:
return -1 return -1
if id == None: if id is None:
id = "" id = ""
if desc == None: if desc is None:
desc = "" desc = ""
else: else:
try: try:
...@@ -367,11 +367,11 @@ def updateWordHTML(name, resource, desc, id, relevance): ...@@ -367,11 +367,11 @@ def updateWordHTML(name, resource, desc, id, relevance):
def checkXMLMsgArchive(url): def checkXMLMsgArchive(url):
global DB global DB
if DB == None: if DB is None:
openMySQL() openMySQL()
if DB == None: if DB is None:
return -1 return -1
if url == None: if url is None:
return -1 return -1
c = DB.cursor() c = DB.cursor()
...@@ -379,7 +379,7 @@ def checkXMLMsgArchive(url): ...@@ -379,7 +379,7 @@ def checkXMLMsgArchive(url):
ret = c.execute( ret = c.execute(
"""SELECT ID FROM archives WHERE resource='%s'""" % (url)) """SELECT ID FROM archives WHERE resource='%s'""" % (url))
row = c.fetchone() row = c.fetchone()
if row == None: if row is None:
return -1 return -1
except: except:
return -1 return -1
...@@ -389,13 +389,13 @@ def checkXMLMsgArchive(url): ...@@ -389,13 +389,13 @@ def checkXMLMsgArchive(url):
def addXMLMsgArchive(url, title): def addXMLMsgArchive(url, title):
global DB global DB
if DB == None: if DB is None:
openMySQL() openMySQL()
if DB == None: if DB is None:
return -1 return -1
if url == None: if url is None:
return -1 return -1
if title == None: if title is None:
title = "" title = ""
else: else:
title = string.replace(title, "'", " ") title = string.replace(title, "'", " ")
...@@ -408,7 +408,7 @@ def addXMLMsgArchive(url, title): ...@@ -408,7 +408,7 @@ def addXMLMsgArchive(url, title):
cmd = """SELECT ID FROM archives WHERE resource='%s'""" % (url) cmd = """SELECT ID FROM archives WHERE resource='%s'""" % (url)
ret = c.execute(cmd) ret = c.execute(cmd)
row = c.fetchone() row = c.fetchone()
if row == None: if row is None:
print "addXMLMsgArchive failed to get the ID: %s" % (url) print "addXMLMsgArchive failed to get the ID: %s" % (url)
return -1 return -1
except: except:
...@@ -420,13 +420,13 @@ def addXMLMsgArchive(url, title): ...@@ -420,13 +420,13 @@ def addXMLMsgArchive(url, title):
def updateWordArchive(name, id, relevance): def updateWordArchive(name, id, relevance):
global DB global DB
if DB == None: if DB is None:
openMySQL() openMySQL()
if DB == None: if DB is None:
return -1 return -1
if name == None: if name is None:
return -1 return -1
if id == None: if id is None:
return -1 return -1
c = DB.cursor() c = DB.cursor()
...@@ -533,9 +533,9 @@ def splitIdentifier(str): ...@@ -533,9 +533,9 @@ def splitIdentifier(str):
def addWord(word, module, symbol, relevance): def addWord(word, module, symbol, relevance):
global wordsDict global wordsDict
if word == None or len(word) < 3: if word is None or len(word) < 3:
return -1 return -1
if module == None or symbol == None: if module is None or symbol is None:
return -1 return -1
if dropWords.has_key(word): if dropWords.has_key(word):
return 0 return 0
...@@ -544,7 +544,7 @@ def addWord(word, module, symbol, relevance): ...@@ -544,7 +544,7 @@ def addWord(word, module, symbol, relevance):
if wordsDict.has_key(word): if wordsDict.has_key(word):
d = wordsDict[word] d = wordsDict[word]
if d == None: if d is None:
return 0 return 0
if len(d) > 500: if len(d) > 500:
wordsDict[word] = None wordsDict[word] = None
...@@ -559,7 +559,7 @@ def addWord(word, module, symbol, relevance): ...@@ -559,7 +559,7 @@ def addWord(word, module, symbol, relevance):
return relevance return relevance
def addString(str, module, symbol, relevance): def addString(str, module, symbol, relevance):
if str == None or len(str) < 3: if str is None or len(str) < 3:
return -1 return -1
ret = 0 ret = 0
str = cleanupWordsString(str) str = cleanupWordsString(str)
...@@ -573,9 +573,9 @@ def addString(str, module, symbol, relevance): ...@@ -573,9 +573,9 @@ def addString(str, module, symbol, relevance):
def addWordHTML(word, resource, id, section, relevance): def addWordHTML(word, resource, id, section, relevance):
global wordsDictHTML global wordsDictHTML
if word == None or len(word) < 3: if word is None or len(word) < 3:
return -1 return -1
if resource == None or section == None: if resource is None or section is None:
return -1 return -1
if dropWords.has_key(word): if dropWords.has_key(word):
return 0 return 0
...@@ -586,14 +586,14 @@ def addWordHTML(word, resource, id, section, relevance): ...@@ -586,14 +586,14 @@ def addWordHTML(word, resource, id, section, relevance):
if wordsDictHTML.has_key(word): if wordsDictHTML.has_key(word):
d = wordsDictHTML[word] d = wordsDictHTML[word]
if d == None: if d is None:
print "skipped %s" % (word) print "skipped %s" % (word)
return 0 return 0
try: try:
(r,i,s) = d[resource] (r,i,s) = d[resource]
if i != None: if i is not None:
id = i id = i
if s != None: if s is not None:
section = s section = s
relevance = relevance + r relevance = relevance + r
except: except:
...@@ -605,7 +605,7 @@ def addWordHTML(word, resource, id, section, relevance): ...@@ -605,7 +605,7 @@ def addWordHTML(word, resource, id, section, relevance):
return relevance return relevance
def addStringHTML(str, resource, id, section, 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 return -1
ret = 0 ret = 0
str = cleanupWordsString(str) str = cleanupWordsString(str)
...@@ -626,9 +626,9 @@ def addStringHTML(str, resource, id, section, relevance): ...@@ -626,9 +626,9 @@ def addStringHTML(str, resource, id, section, relevance):
def addWordArchive(word, id, relevance): def addWordArchive(word, id, relevance):
global wordsDictArchive global wordsDictArchive
if word == None or len(word) < 3: if word is None or len(word) < 3:
return -1 return -1
if id == None or id == -1: if id is None or id == -1:
return -1 return -1
if dropWords.has_key(word): if dropWords.has_key(word):
return 0 return 0
...@@ -637,7 +637,7 @@ def addWordArchive(word, id, relevance): ...@@ -637,7 +637,7 @@ def addWordArchive(word, id, relevance):
if wordsDictArchive.has_key(word): if wordsDictArchive.has_key(word):
d = wordsDictArchive[word] d = wordsDictArchive[word]
if d == None: if d is None:
print "skipped %s" % (word) print "skipped %s" % (word)
return 0 return 0
try: try:
...@@ -652,7 +652,7 @@ def addWordArchive(word, id, relevance): ...@@ -652,7 +652,7 @@ def addWordArchive(word, id, relevance):
return relevance return relevance
def addStringArchive(str, id, relevance): def addStringArchive(str, id, relevance):
if str == None or len(str) < 3: if str is None or len(str) < 3:
return -1 return -1
ret = 0 ret = 0
str = cleanupWordsString(str) str = cleanupWordsString(str)
...@@ -683,9 +683,9 @@ def loadAPI(filename): ...@@ -683,9 +683,9 @@ def loadAPI(filename):
return doc return doc
def foundExport(file, symbol): def foundExport(file, symbol):
if file == None: if file is None:
return 0 return 0
if symbol == None: if symbol is None:
return 0 return 0
addFunction(symbol, file) addFunction(symbol, file)
l = splitIdentifier(symbol) l = splitIdentifier(symbol)
...@@ -697,7 +697,7 @@ def analyzeAPIFile(top): ...@@ -697,7 +697,7 @@ def analyzeAPIFile(top):
count = 0 count = 0
name = top.prop("name") name = top.prop("name")
cur = top.children cur = top.children
while cur != None: while cur is not None:
if cur.type == 'text': if cur.type == 'text':
cur = cur.next cur = cur.next
continue continue
...@@ -712,7 +712,7 @@ def analyzeAPIFiles(top): ...@@ -712,7 +712,7 @@ def analyzeAPIFiles(top):
count = 0 count = 0
cur = top.children cur = top.children
while cur != None: while cur is not None:
if cur.type == 'text': if cur.type == 'text':
cur = cur.next cur = cur.next
continue continue
...@@ -725,10 +725,10 @@ def analyzeAPIFiles(top): ...@@ -725,10 +725,10 @@ def analyzeAPIFiles(top):
def analyzeAPIEnum(top): def analyzeAPIEnum(top):
file = top.prop("file") file = top.prop("file")
if file == None: if file is None:
return 0 return 0
symbol = top.prop("name") symbol = top.prop("name")
if symbol == None: if symbol is None:
return 0 return 0
addEnum(symbol, file) addEnum(symbol, file)
...@@ -740,10 +740,10 @@ def analyzeAPIEnum(top): ...@@ -740,10 +740,10 @@ def analyzeAPIEnum(top):
def analyzeAPIConst(top): def analyzeAPIConst(top):
file = top.prop("file") file = top.prop("file")
if file == None: if file is None:
return 0 return 0
symbol = top.prop("name") symbol = top.prop("name")
if symbol == None: if symbol is None:
return 0 return 0
addConst(symbol, file) addConst(symbol, file)
...@@ -755,10 +755,10 @@ def analyzeAPIConst(top): ...@@ -755,10 +755,10 @@ def analyzeAPIConst(top):
def analyzeAPIType(top): def analyzeAPIType(top):
file = top.prop("file") file = top.prop("file")
if file == None: if file is None:
return 0 return 0
symbol = top.prop("name") symbol = top.prop("name")
if symbol == None: if symbol is None:
return 0 return 0
addType(symbol, file) addType(symbol, file)
...@@ -769,10 +769,10 @@ def analyzeAPIType(top): ...@@ -769,10 +769,10 @@ def analyzeAPIType(top):
def analyzeAPIFunctype(top): def analyzeAPIFunctype(top):
file = top.prop("file") file = top.prop("file")
if file == None: if file is None:
return 0 return 0
symbol = top.prop("name") symbol = top.prop("name")
if symbol == None: if symbol is None:
return 0 return 0
addFunctype(symbol, file) addFunctype(symbol, file)
...@@ -783,10 +783,10 @@ def analyzeAPIFunctype(top): ...@@ -783,10 +783,10 @@ def analyzeAPIFunctype(top):
def analyzeAPIStruct(top): def analyzeAPIStruct(top):
file = top.prop("file") file = top.prop("file")
if file == None: if file is None:
return 0 return 0
symbol = top.prop("name") symbol = top.prop("name")
if symbol == None: if symbol is None:
return 0 return 0
addStruct(symbol, file) addStruct(symbol, file)
...@@ -795,7 +795,7 @@ def analyzeAPIStruct(top): ...@@ -795,7 +795,7 @@ def analyzeAPIStruct(top):
addWord(word, file, symbol, 10) addWord(word, file, symbol, 10)
info = top.prop("info") info = top.prop("info")
if info != None: if info is not None:
info = string.replace(info, "'", " ") info = string.replace(info, "'", " ")
info = string.strip(info) info = string.strip(info)
l = string.split(info) l = string.split(info)
...@@ -806,17 +806,17 @@ def analyzeAPIStruct(top): ...@@ -806,17 +806,17 @@ def analyzeAPIStruct(top):
def analyzeAPIMacro(top): def analyzeAPIMacro(top):
file = top.prop("file") file = top.prop("file")
if file == None: if file is None:
return 0 return 0
symbol = top.prop("name") symbol = top.prop("name")
if symbol == None: if symbol is None:
return 0 return 0
symbol = string.replace(symbol, "'", " ") symbol = string.replace(symbol, "'", " ")
symbol = string.strip(symbol) symbol = string.strip(symbol)
info = None info = None
cur = top.children cur = top.children
while cur != None: while cur is not None:
if cur.type == 'text': if cur.type == 'text':
cur = cur.next cur = cur.next
continue continue
...@@ -829,7 +829,7 @@ def analyzeAPIMacro(top): ...@@ -829,7 +829,7 @@ def analyzeAPIMacro(top):
for word in l: for word in l:
addWord(word, file, symbol, 10) addWord(word, file, symbol, 10)
if info == None: if info is None:
addMacro(symbol, file) addMacro(symbol, file)
print "Macro %s description has no <info>" % (symbol) print "Macro %s description has no <info>" % (symbol)
return 0 return 0
...@@ -845,17 +845,17 @@ def analyzeAPIMacro(top): ...@@ -845,17 +845,17 @@ def analyzeAPIMacro(top):
def analyzeAPIFunction(top): def analyzeAPIFunction(top):
file = top.prop("file") file = top.prop("file")
if file == None: if file is None:
return 0 return 0
symbol = top.prop("name") symbol = top.prop("name")
if symbol == None: if symbol is None:
return 0 return 0
symbol = string.replace(symbol, "'", " ") symbol = string.replace(symbol, "'", " ")
symbol = string.strip(symbol) symbol = string.strip(symbol)
info = None info = None
cur = top.children cur = top.children
while cur != None: while cur is not None:
if cur.type == 'text': if cur.type == 'text':
cur = cur.next cur = cur.next
continue continue
...@@ -863,23 +863,23 @@ def analyzeAPIFunction(top): ...@@ -863,23 +863,23 @@ def analyzeAPIFunction(top):
info = cur.content info = cur.content
elif cur.name == "return": elif cur.name == "return":
rinfo = cur.prop("info") rinfo = cur.prop("info")
if rinfo != None: if rinfo is not None:
rinfo = string.replace(rinfo, "'", " ") rinfo = string.replace(rinfo, "'", " ")
rinfo = string.strip(rinfo) rinfo = string.strip(rinfo)
addString(rinfo, file, symbol, 7) addString(rinfo, file, symbol, 7)
elif cur.name == "arg": elif cur.name == "arg":
ainfo = cur.prop("info") ainfo = cur.prop("info")
if ainfo != None: if ainfo is not None:
ainfo = string.replace(ainfo, "'", " ") ainfo = string.replace(ainfo, "'", " ")
ainfo = string.strip(ainfo) ainfo = string.strip(ainfo)
addString(ainfo, file, symbol, 5) addString(ainfo, file, symbol, 5)
name = cur.prop("name") name = cur.prop("name")
if name != None: if name is not None:
name = string.replace(name, "'", " ") name = string.replace(name, "'", " ")
name = string.strip(name) name = string.strip(name)
addWord(name, file, symbol, 7) addWord(name, file, symbol, 7)
cur = cur.next cur = cur.next
if info == None: if info is None:
print "Function %s description has no <info>" % (symbol) print "Function %s description has no <info>" % (symbol)
addFunction(symbol, file, "") addFunction(symbol, file, "")
else: else:
...@@ -898,7 +898,7 @@ def analyzeAPISymbols(top): ...@@ -898,7 +898,7 @@ def analyzeAPISymbols(top):
count = 0 count = 0
cur = top.children cur = top.children
while cur != None: while cur is not None:
if cur.type == 'text': if cur.type == 'text':
cur = cur.next cur = cur.next
continue continue
...@@ -923,14 +923,14 @@ def analyzeAPISymbols(top): ...@@ -923,14 +923,14 @@ def analyzeAPISymbols(top):
def analyzeAPI(doc): def analyzeAPI(doc):
count = 0 count = 0
if doc == None: if doc is None:
return -1 return -1
root = doc.getRootElement() root = doc.getRootElement()
if root.name != "api": if root.name != "api":
print "Unexpected root name" print "Unexpected root name"
return -1 return -1
cur = root.children cur = root.children
while cur != None: while cur is not None:
if cur.type == 'text': if cur.type == 'text':
cur = cur.next cur = cur.next
continue continue
...@@ -1056,7 +1056,7 @@ def analyzeHTMLPages(): ...@@ -1056,7 +1056,7 @@ def analyzeHTMLPages():
import time import time
def getXMLDateArchive(t = None): def getXMLDateArchive(t = None):
if t == None: if t is None:
t = time.time() t = time.time()
T = time.gmtime(t) T = time.gmtime(t)
month = time.strftime("%B", T) month = time.strftime("%B", T)
...@@ -1065,7 +1065,7 @@ def getXMLDateArchive(t = None): ...@@ -1065,7 +1065,7 @@ def getXMLDateArchive(t = None):
return url return url
def scanXMLMsgArchive(url, title, force = 0): def scanXMLMsgArchive(url, title, force = 0):
if url == None or title == None: if url is None or title is None:
return 0 return 0
ID = checkXMLMsgArchive(url) ID = checkXMLMsgArchive(url)
...@@ -1082,7 +1082,7 @@ def scanXMLMsgArchive(url, title, force = 0): ...@@ -1082,7 +1082,7 @@ def scanXMLMsgArchive(url, title, force = 0):
doc = libxml2.htmlParseFile(url, None) doc = libxml2.htmlParseFile(url, None)
except: except:
doc = None doc = None
if doc == None: if doc is None:
print "Failed to parse %s" % (url) print "Failed to parse %s" % (url)
return 0 return 0
...@@ -1105,7 +1105,7 @@ def scanXMLDateArchive(t = None, force = 0): ...@@ -1105,7 +1105,7 @@ def scanXMLDateArchive(t = None, force = 0):
doc = libxml2.htmlParseFile(url, None) doc = libxml2.htmlParseFile(url, None)
except: except:
doc = None doc = None
if doc == None: if doc is None:
print "Failed to parse %s" % (url) print "Failed to parse %s" % (url)
return -1 return -1
ctxt = doc.xpathNewContext() ctxt = doc.xpathNewContext()
...@@ -1114,16 +1114,16 @@ def scanXMLDateArchive(t = None, force = 0): ...@@ -1114,16 +1114,16 @@ def scanXMLDateArchive(t = None, force = 0):
newmsg = 0 newmsg = 0
for anchor in anchors: for anchor in anchors:
href = anchor.prop("href") href = anchor.prop("href")
if href == None or href[0:3] != "msg": if href is None or href[0:3] != "msg":
continue continue
try: try:
links = links + 1 links = links + 1
msg = libxml2.buildURI(href, url) msg = libxml2.buildURI(href, url)
title = anchor.content title = anchor.content
if title != None and title[0:4] == 'Re: ': if title is not None and title[0:4] == 'Re: ':
title = title[4:] title = title[4:]
if title != None and title[0:6] == '[xml] ': if title is not None and title[0:6] == '[xml] ':
title = title[6:] title = title[6:]
newmsg = newmsg + scanXMLMsgArchive(msg, title, force) newmsg = newmsg + scanXMLMsgArchive(msg, title, force)
...@@ -1148,7 +1148,7 @@ def analyzeArchives(t = None, force = 0): ...@@ -1148,7 +1148,7 @@ def analyzeArchives(t = None, force = 0):
skipped = 0 skipped = 0
for word in wordsDictArchive.keys(): for word in wordsDictArchive.keys():
refs = wordsDictArchive[word] refs = wordsDictArchive[word]
if refs == None: if refs is None:
skipped = skipped + 1 skipped = skipped + 1
continue continue
for id in refs.keys(): for id in refs.keys():
...@@ -1168,7 +1168,7 @@ def analyzeHTMLTop(): ...@@ -1168,7 +1168,7 @@ def analyzeHTMLTop():
skipped = 0 skipped = 0
for word in wordsDictHTML.keys(): for word in wordsDictHTML.keys():
refs = wordsDictHTML[word] refs = wordsDictHTML[word]
if refs == None: if refs is None:
skipped = skipped + 1 skipped = skipped + 1
continue continue
for resource in refs.keys(): for resource in refs.keys():
...@@ -1197,7 +1197,7 @@ def analyzeAPITop(): ...@@ -1197,7 +1197,7 @@ def analyzeAPITop():
skipped = 0 skipped = 0
for word in wordsDict.keys(): for word in wordsDict.keys():
refs = wordsDict[word] refs = wordsDict[word]
if refs == None: if refs is None:
skipped = skipped + 1 skipped = skipped + 1
continue continue
for (module, symbol) in refs.keys(): for (module, symbol) in refs.keys():
......
...@@ -29,7 +29,7 @@ class Console(object): ...@@ -29,7 +29,7 @@ class Console(object):
def check_console(console): def check_console(console):
if (console.state[0] == libvirt.VIR_DOMAIN_RUNNING or if (console.state[0] == libvirt.VIR_DOMAIN_RUNNING or
console.state[0] == libvirt.VIR_DOMAIN_PAUSED): 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.stream = console.connection.newStream(libvirt.VIR_STREAM_NONBLOCK)
console.domain.openConsole(None, console.stream, 0) console.domain.openConsole(None, console.stream, 0)
console.stream.eventAddCallback(libvirt.VIR_STREAM_EVENT_READABLE, stream_callback, console) console.stream.eventAddCallback(libvirt.VIR_STREAM_EVENT_READABLE, stream_callback, console)
......
...@@ -35,7 +35,7 @@ name = sys.argv[1] ...@@ -35,7 +35,7 @@ name = sys.argv[1]
# Connect to libvirt # Connect to libvirt
conn = libvirt.openReadOnly(None) conn = libvirt.openReadOnly(None)
if conn == None: if conn is None:
print 'Failed to open connection to the hypervisor' print 'Failed to open connection to the hypervisor'
sys.exit(1) sys.exit(1)
......
...@@ -21,7 +21,7 @@ dir = sys.argv[1] ...@@ -21,7 +21,7 @@ dir = sys.argv[1]
imgs = os.listdir(dir) imgs = os.listdir(dir)
conn = libvirt.open(None) conn = libvirt.open(None)
if conn == None: if conn is None:
print 'Failed to open connection to the hypervisor' print 'Failed to open connection to the hypervisor'
sys.exit(1) sys.exit(1)
......
...@@ -19,7 +19,7 @@ if len(sys.argv) != 2: ...@@ -19,7 +19,7 @@ if len(sys.argv) != 2:
dir = sys.argv[1] dir = sys.argv[1]
conn = libvirt.open(None) conn = libvirt.open(None)
if conn == None: if conn is None:
print 'Failed to open connection to the hypervisor' print 'Failed to open connection to the hypervisor'
sys.exit(1) sys.exit(1)
......
...@@ -33,7 +33,7 @@ if len(sys.argv) != 2: ...@@ -33,7 +33,7 @@ if len(sys.argv) != 2:
(name, xmldesc) = read_domain(sys.argv[1]) (name, xmldesc) = read_domain(sys.argv[1])
conn = libvirt.open(None) conn = libvirt.open(None)
if conn == None: if conn is None:
print 'Failed to open connection to the hypervisor' print 'Failed to open connection to the hypervisor'
sys.exit(1) sys.exit(1)
...@@ -43,7 +43,7 @@ except libvirt.libvirtError: ...@@ -43,7 +43,7 @@ except libvirt.libvirtError:
print "Starting domain %s ... " % name, print "Starting domain %s ... " % name,
sys.stdout.flush() sys.stdout.flush()
dom = conn.createLinux(xmldesc, 0) dom = conn.createLinux(xmldesc, 0)
if dom == None: if dom is None:
print "failed" print "failed"
sys.exit(1) sys.exit(1)
else: else:
......
...@@ -136,7 +136,7 @@ class docParser(xml.sax.handler.ContentHandler): ...@@ -136,7 +136,7 @@ class docParser(xml.sax.handler.ContentHandler):
print "end %s" % tag print "end %s" % tag
if tag == 'function': if tag == 'function':
# fuctions come from source files, hence 'virerror.c' # fuctions come from source files, hence 'virerror.c'
if self.function != None: if self.function is not None:
if (self.function_module == "libvirt" or if (self.function_module == "libvirt" or
self.function_module == "virevent" or self.function_module == "virevent" or
self.function_module == "virerror"): self.function_module == "virerror"):
...@@ -641,9 +641,9 @@ def print_function_wrapper(module, name, output, export, include): ...@@ -641,9 +641,9 @@ def print_function_wrapper(module, name, output, export, include):
(f, t, n, c) = py_types[arg[1]] (f, t, n, c) = py_types[arg[1]]
if (f == 'z') and (name in foreign_encoding_args) and (num_bufs == 0): if (f == 'z') and (name in foreign_encoding_args) and (num_bufs == 0):
f = 't#' f = 't#'
if f != None: if f is not None:
format = format + f format = format + f
if t != None: if t is not None:
format_args = format_args + ", &pyobj_%s" % (arg[0]) format_args = format_args + ", &pyobj_%s" % (arg[0])
c_args = c_args + " PyObject *pyobj_%s;\n" % (arg[0]) c_args = c_args + " PyObject *pyobj_%s;\n" % (arg[0])
c_convert = c_convert + \ c_convert = c_convert + \
...@@ -686,7 +686,7 @@ def print_function_wrapper(module, name, output, export, include): ...@@ -686,7 +686,7 @@ def print_function_wrapper(module, name, output, export, include):
elif py_types.has_key(ret[0]): elif py_types.has_key(ret[0]):
(f, t, n, c) = py_types[ret[0]] (f, t, n, c) = py_types[ret[0]]
c_return = " %s c_retval;\n" % (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]) c_call = "\n c_retval = %s->%s;\n" % (args[0][0], ret[2])
else: else:
c_call = "\n c_retval = %s(%s);\n" % (name, c_call) c_call = "\n c_retval = %s(%s);\n" % (name, c_call)
...@@ -708,7 +708,7 @@ def print_function_wrapper(module, name, output, export, include): ...@@ -708,7 +708,7 @@ def print_function_wrapper(module, name, output, export, include):
unknown_types[ret[0]] = [name] unknown_types[ret[0]] = [name]
return -1 return -1
if cond != None and cond != "": if cond is not None and cond != "":
include.write("#if %s\n" % cond) include.write("#if %s\n" % cond)
export.write("#if %s\n" % cond) export.write("#if %s\n" % cond)
output.write("#if %s\n" % cond) output.write("#if %s\n" % cond)
...@@ -729,14 +729,14 @@ def print_function_wrapper(module, name, output, export, include): ...@@ -729,14 +729,14 @@ def print_function_wrapper(module, name, output, export, include):
if file == "python": if file == "python":
# Those have been manually generated # Those have been manually generated
if cond != None and cond != "": if cond is not None and cond != "":
include.write("#endif\n") include.write("#endif\n")
export.write("#endif\n") export.write("#endif\n")
output.write("#endif\n") output.write("#endif\n")
return 1 return 1
if file == "python_accessor" and ret[0] != "void" and ret[2] is None: if file == "python_accessor" and ret[0] != "void" and ret[2] is None:
# Those have been manually generated # Those have been manually generated
if cond != None and cond != "": if cond is not None and cond != "":
include.write("#endif\n") include.write("#endif\n")
export.write("#endif\n") export.write("#endif\n")
output.write("#endif\n") output.write("#endif\n")
...@@ -771,7 +771,7 @@ def print_function_wrapper(module, name, output, export, include): ...@@ -771,7 +771,7 @@ def print_function_wrapper(module, name, output, export, include):
output.write(" LIBVIRT_END_ALLOW_THREADS;\n") output.write(" LIBVIRT_END_ALLOW_THREADS;\n")
output.write(ret_convert) output.write(ret_convert)
output.write("}\n\n") output.write("}\n\n")
if cond != None and cond != "": if cond is not None and cond != "":
include.write("#endif /* %s */\n" % cond) include.write("#endif /* %s */\n" % cond)
export.write("#endif /* %s */\n" % cond) export.write("#endif /* %s */\n" % cond)
output.write("#endif /* %s */\n" % cond) output.write("#endif /* %s */\n" % cond)
...@@ -1313,7 +1313,7 @@ def buildWrappers(module): ...@@ -1313,7 +1313,7 @@ def buildWrappers(module):
classes.write("#\n") classes.write("#\n")
classes.write("# WARNING WARNING WARNING WARNING\n") classes.write("# WARNING WARNING WARNING WARNING\n")
classes.write("#\n") classes.write("#\n")
if extra != None: if extra is not None:
classes.writelines(extra.readlines()) classes.writelines(extra.readlines())
classes.write("#\n") classes.write("#\n")
classes.write("# WARNING WARNING WARNING WARNING\n") classes.write("# WARNING WARNING WARNING WARNING\n")
...@@ -1321,7 +1321,7 @@ def buildWrappers(module): ...@@ -1321,7 +1321,7 @@ def buildWrappers(module):
classes.write("# Automatically written part of python bindings for libvirt\n") classes.write("# Automatically written part of python bindings for libvirt\n")
classes.write("#\n") classes.write("#\n")
classes.write("# WARNING WARNING WARNING WARNING\n") classes.write("# WARNING WARNING WARNING WARNING\n")
if extra != None: if extra is not None:
extra.close() extra.close()
if function_classes.has_key("None"): if function_classes.has_key("None"):
...@@ -1460,7 +1460,7 @@ def buildWrappers(module): ...@@ -1460,7 +1460,7 @@ def buildWrappers(module):
destruct=None destruct=None
if classes_destructors.has_key(classname): if classes_destructors.has_key(classname):
classes.write(" def __del__(self):\n") 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.write(" libvirtmod.%s(self._o)\n" %
classes_destructors[classname]) classes_destructors[classname])
classes.write(" self._o = None\n\n") classes.write(" self._o = None\n\n")
...@@ -1776,7 +1776,7 @@ def qemuBuildWrappers(module): ...@@ -1776,7 +1776,7 @@ def qemuBuildWrappers(module):
fd.write("#\n") fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n") fd.write("# WARNING WARNING WARNING WARNING\n")
fd.write("#\n") fd.write("#\n")
if extra != None: if extra is not None:
fd.writelines(extra.readlines()) fd.writelines(extra.readlines())
fd.write("#\n") fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n") fd.write("# WARNING WARNING WARNING WARNING\n")
...@@ -1784,7 +1784,7 @@ def qemuBuildWrappers(module): ...@@ -1784,7 +1784,7 @@ def qemuBuildWrappers(module):
fd.write("# Automatically written part of python bindings for libvirt\n") fd.write("# Automatically written part of python bindings for libvirt\n")
fd.write("#\n") fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n") fd.write("# WARNING WARNING WARNING WARNING\n")
if extra != None: if extra is not None:
extra.close() extra.close()
fd.write("try:\n") fd.write("try:\n")
...@@ -1888,7 +1888,7 @@ def lxcBuildWrappers(module): ...@@ -1888,7 +1888,7 @@ def lxcBuildWrappers(module):
fd.write("#\n") fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n") fd.write("# WARNING WARNING WARNING WARNING\n")
fd.write("#\n") fd.write("#\n")
if extra != None: if extra is not None:
fd.writelines(extra.readlines()) fd.writelines(extra.readlines())
fd.write("#\n") fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n") fd.write("# WARNING WARNING WARNING WARNING\n")
...@@ -1896,7 +1896,7 @@ def lxcBuildWrappers(module): ...@@ -1896,7 +1896,7 @@ def lxcBuildWrappers(module):
fd.write("# Automatically written part of python bindings for libvirt\n") fd.write("# Automatically written part of python bindings for libvirt\n")
fd.write("#\n") fd.write("#\n")
fd.write("# WARNING WARNING WARNING WARNING\n") fd.write("# WARNING WARNING WARNING WARNING\n")
if extra != None: if extra is not None:
extra.close() extra.close()
fd.write("try:\n") fd.write("try:\n")
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
except AttributeError: except AttributeError:
pass pass
if self._o != None: if self._o is not None:
libvirtmod.virConnectClose(self._o) libvirtmod.virConnectClose(self._o)
self._o = None self._o = None
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
except AttributeError: except AttributeError:
pass pass
if self._o != None: if self._o is not None:
libvirtmod.virStreamFree(self._o) libvirtmod.virStreamFree(self._o)
self._o = None self._o = None
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
the request would block, integer -2 is returned. the request would block, integer -2 is returned.
""" """
ret = libvirtmod.virStreamRecv(self._o, nbytes) ret = libvirtmod.virStreamRecv(self._o, nbytes)
if ret == None: raise libvirtError ('virStreamRecv() failed') if ret is None: raise libvirtError ('virStreamRecv() failed')
return ret return ret
def send(self, data): def send(self, data):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册