Skip to content

Commit

Permalink
Compare to None using identity is operator
Browse files Browse the repository at this point in the history
This is a trivial change that replaces `==` operator with `is` operator, following PEP 8 guideline:

> Comparisons to singletons like None should always be done with is or is not, never the equality operators.

https://legacy.python.org/dev/peps/pep-0008/#programming-recommendations
  • Loading branch information
janisozaur authored and Bill Meek committed Apr 23, 2020
1 parent 957d1db commit 2e7e9e8
Show file tree
Hide file tree
Showing 31 changed files with 146 additions and 146 deletions.
18 changes: 9 additions & 9 deletions mythplugins/mytharchive/mythburn/scripts/mythburn.py
Expand Up @@ -269,16 +269,16 @@ def __init__(self, name=None, fontFile=None, size=19, color="white", effect="nor
self.font = None

def getFont(self):
if self.font == None:
if self.font is None:
self.font = ImageFont.truetype(self.fontFile, int(self.size))

return self.font

def drawText(self, text, color=None):
if self.font == None:
if self.font is None:
self.font = ImageFont.truetype(self.fontFile, int(self.size))

if color == None:
if color is None:
color = self.color

textwidth, textheight = self.font.getsize(text)
Expand Down Expand Up @@ -1170,15 +1170,15 @@ def paintText(draw, image, text, node, color = None,
"""Takes a piece of text and draws it onto an image inside a bounding box."""
#The text is wider than the width of the bounding box

if x == None:
if x is None:
x = getScaledAttribute(node, "x")
y = getScaledAttribute(node, "y")
width = getScaledAttribute(node, "w")
height = getScaledAttribute(node, "h")

font = themeFonts[node.attributes["font"].value]

if color == None:
if color is None:
if node.hasAttribute("colour"):
color = node.attributes["colour"].value
elif node.hasAttribute("color"):
Expand Down Expand Up @@ -3498,7 +3498,7 @@ def drawThemeItem(page, itemsonthispage, itemnum, menuitem, bgimage, draw,
else:
write( "Dont know how to process %s" % node.nodeName)

if drawmask == None:
if drawmask is None:
return

#Draw the selection mask for this item
Expand Down Expand Up @@ -3685,7 +3685,7 @@ def createMenu(screensize, screendpi, numberofitems):
picture = Image.open(imagefile, "r").resize((previeww[itemsonthispage-1], previewh[itemsonthispage-1]))
picture = picture.convert("RGBA")
imagemaskfile = os.path.join(previewpath, "mask-i%d.png" % itemsonthispage)
if previewmask[itemsonthispage-1] != None:
if previewmask[itemsonthispage-1] is not None:
bgimage.paste(picture, (previewx[itemsonthispage-1], previewy[itemsonthispage-1]), previewmask[itemsonthispage-1])
else:
bgimage.paste(picture, (previewx[itemsonthispage-1], previewy[itemsonthispage-1]))
Expand Down Expand Up @@ -3886,7 +3886,7 @@ def createChapterMenu(screensize, screendpi, numberofitems):
picture = Image.open(imagefile, "r").resize((previeww[previewchapter], previewh[previewchapter]))
picture = picture.convert("RGBA")
imagemaskfile = os.path.join(previewpath, "mask-i%d.png" % previewchapter)
if previewmask[previewchapter] != None:
if previewmask[previewchapter] is not None:
bgimage.paste(picture, (previewx[previewchapter], previewy[previewchapter]), previewmask[previewchapter])
else:
bgimage.paste(picture, (previewx[previewchapter], previewy[previewchapter]))
Expand Down Expand Up @@ -4035,7 +4035,7 @@ def createDetailsPage(screensize, screendpi, numberofitems):
picture = Image.open(imagefile, "r").resize((previeww, previewh))
picture = picture.convert("RGBA")
imagemaskfile = os.path.join(previewpath, "mask-i%d.png" % 1)
if previewmask != None:
if previewmask is not None:
bgimage.paste(picture, (previewx, previewy), previewmask)
else:
bgimage.paste(picture, (previewx, previewy))
Expand Down
12 changes: 6 additions & 6 deletions mythplugins/mythgame/mythgame/scripts/giantbomb/giantbomb_api.py
Expand Up @@ -167,7 +167,7 @@ def fixup(m):


def textUtf8(self, text):
if text == None:
if text is None:
return text
try:
return unicode(text, 'utf8')
Expand Down Expand Up @@ -268,15 +268,15 @@ def futureReleaseDate(self, context, gameElement):
return If there is not enough information to make a date then return an empty string
'''
try:
if gameElement.find('expected_release_year').text != None:
if gameElement.find('expected_release_year').text is not None:
year = gameElement.find('expected_release_year').text
else:
year = None
if gameElement.find('expected_release_quarter').text != None:
if gameElement.find('expected_release_quarter').text is not None:
quarter = gameElement.find('expected_release_quarter').text
else:
quarter = None
if gameElement.find('expected_release_month').text != None:
if gameElement.find('expected_release_month').text is not None:
month = gameElement.find('expected_release_month').text
else:
month = None
Expand Down Expand Up @@ -416,7 +416,7 @@ def gameSearch(self, gameTitle):

items = queryXslt(queryResult)

if items.getroot() != None:
if items.getroot() is not None:
if len(items.xpath('//item')):
sys.stdout.write(etree.tostring(items, encoding='UTF-8', method="xml", xml_declaration=True, pretty_print=True, ))
sys.exit(0)
Expand Down Expand Up @@ -446,7 +446,7 @@ def gameData(self, gameId):
gamebombXpath[key] = self.FuncDict[key]
items = gameXslt(videoResult)

if items.getroot() != None:
if items.getroot() is not None:
if len(items.xpath('//item')):
sys.stdout.write(etree.tostring(items, encoding='UTF-8', method="xml", xml_declaration=True, pretty_print=True, ))
sys.exit(0)
Expand Down
4 changes: 2 additions & 2 deletions mythtv/bindings/python/MythTV/ttvdb/tvdbXslt.py
Expand Up @@ -218,7 +218,7 @@ def imageElements(self, context, *args):
for image in xpathFilter(args[0][0]):
# print("im %r" % image)
# print(etree.tostring(image, method="xml", xml_declaration=False, pretty_print=True, ))
if image.find('fileName') == None:
if image.find('fileName') is None:
continue
# print("im2 %r" % image)
tmpElement = etree.XML(u'<image></image>')
Expand All @@ -242,7 +242,7 @@ def imageElements(self, context, *args):
# end imageElements()

def textUtf8(self, text):
if text == None:
if text is None:
return text
try:
return unicode(text, 'utf8')
Expand Down
2 changes: 1 addition & 1 deletion mythtv/bindings/python/MythTV/ttvdb/tvdb_api.py
Expand Up @@ -1081,7 +1081,7 @@ def _getShowData(self, sid, language):

self._setShowData(sid, tag, value)
# set language
if language == None:
if language is None:
language = self.config['language']
self._setShowData(sid, u'language', language)

Expand Down
2 changes: 1 addition & 1 deletion mythtv/bindings/python/tmdb3/tmdb3/cache_file.py
Expand Up @@ -384,7 +384,7 @@ def _write(self, data):
# write storage slot definitions
prev = None
for d in data:
if prev == None:
if prev is None:
d.position = 4 + 16*size
else:
d.position = prev.position + prev.size
Expand Down
32 changes: 16 additions & 16 deletions mythtv/contrib/imports/mirobridge/mirobridge.py
Expand Up @@ -537,7 +537,7 @@ def _can_int(x):
>>> _can_int("A test")
False
"""
if x == None:
if x is None:
return False
try:
int(x)
Expand Down Expand Up @@ -571,7 +571,7 @@ def sanitiseFileName(name):
return a sanitised valid file name
'''
global filename_char_filter
if name == None or name == u'':
if name is None or name == u'':
return u'_'
for char in filename_char_filter:
name = name.replace(char, u'_')
Expand Down Expand Up @@ -793,7 +793,7 @@ def rtnAbsolutePath(relpath, filetype=u'mythvideo'):
return an absolute path and file name
return the relpath sting if the file does not actually exist in the absolute path location
'''
if relpath == None or relpath == u'':
if relpath is None or relpath == u'':
return relpath

# There is a chance that this is already an absolute path
Expand Down Expand Up @@ -1264,7 +1264,7 @@ def getStartEndTimes(duration, downloadedTime):
starttime.strftime('%Y-%m-%d %H:%M:%S'),
starttime.strftime('%Y%m%d%H%M%S')]

if downloadedTime != None:
if downloadedTime is not None:
try:
dummy = downloadedTime.strftime('%Y-%m-%d')
except ValueError:
Expand Down Expand Up @@ -1416,7 +1416,7 @@ def createRecordedRecords(item):
ffmpeg_details = metadata.getVideoDetails(item[u'videoFilename'])
start_end = getStartEndTimes(ffmpeg_details[u'duration'], item[u'downloadedTime'])

if item[u'releasedate'] == None:
if item[u'releasedate'] is None:
item[u'releasedate'] = item[u'downloadedTime']
try:
dummy = item[u'releasedate'].strftime('%Y-%m-%d')
Expand Down Expand Up @@ -1444,12 +1444,12 @@ def createRecordedRecords(item):
tmp_recorded[u'hostname'] = localhostname
tmp_recorded[u'lastmodified'] = tmp_recorded[u'endtime']
tmp_recorded[u'filesize'] = item[u'size']
if item[u'releasedate'] != None:
if item[u'releasedate'] is not None:
tmp_recorded[u'originalairdate'] = item[u'releasedate'].strftime('%Y-%m-%d')

basename = setSymbolic(item[u'videoFilename'], u'default', u"%s_%s" % \
(channel_id, start_end[2]), allow_symlink=True)
if basename != None:
if basename is not None:
tmp_recorded[u'basename'] = basename
else:
logger.critical(u"The file (%s) must exist to create a recorded record" % \
Expand All @@ -1472,7 +1472,7 @@ def createRecordedRecords(item):

tmp_recordedprogram[u'category'] = u"Miro"
tmp_recordedprogram[u'category_type'] = u"series"
if item[u'releasedate'] != None:
if item[u'releasedate'] is not None:
tmp_recordedprogram[u'airdate'] = item[u'releasedate'].strftime('%Y')
tmp_recordedprogram[u'originalairdate'] = item[u'releasedate'].strftime('%Y-%m-%d')
tmp_recordedprogram[u'stereo'] = ffmpeg_details[u'stereo']
Expand Down Expand Up @@ -1524,14 +1524,14 @@ def createVideometadataRecord(item):
for key in details.keys():
videometadata[key] = details[key]

if item[u'releasedate'] == None:
if item[u'releasedate'] is None:
item[u'releasedate'] = item[u'downloadedTime']
try:
dummy = item[u'releasedate'].strftime('%Y-%m-%d')
except ValueError:
item[u'releasedate'] = item[u'downloadedTime']

if item[u'releasedate'] != None:
if item[u'releasedate'] is not None:
videometadata[u'year'] = item[u'releasedate'].strftime('%Y')
videometadata[u'releasedate'] = item[u'releasedate'].strftime('%Y-%m-%d')
videometadata[u'length'] = ffmpeg_details[u'duration']/60
Expand All @@ -1544,7 +1544,7 @@ def createVideometadataRecord(item):
videofile = setSymbolic(item[u'videoFilename'], u'mythvideo', "%s/%s - %s" % \
(sympath, sanitiseFileName(item[u'channelTitle']),
sanitiseFileName(item[u'title'])), allow_symlink=True)
if videofile != None:
if videofile is not None:
videometadata[u'filename'] = videofile
if not local_only and videometadata[u'filename'][0] != u'/':
videometadata[u'host'] = localhostname.lower()
Expand All @@ -1565,14 +1565,14 @@ def createVideometadataRecord(item):
elif item[u'channel_icon'] and not item[u'channelTitle'].lower() in channel_icon_override:
filename = setSymbolic(item[u'channel_icon'], u'posterdir', u"%s" % \
(sanitiseFileName(item[u'channelTitle'])))
if filename != None:
if filename is not None:
videometadata[u'coverfile'] = filename
else:
if item[u'item_icon']:
filename = setSymbolic(item[u'item_icon'], u'posterdir', u"%s - %s" % \
(sanitiseFileName(item[u'channelTitle']),
sanitiseFileName(item[u'title'])))
if filename != None:
if filename is not None:
videometadata[u'coverfile'] = filename
else:
videometadata[u'coverfile'] = item[u'channel_icon']
Expand All @@ -1582,7 +1582,7 @@ def createVideometadataRecord(item):
filename = setSymbolic(item[u'screenshot'], u'episodeimagedir', u"%s - %s" % \
(sanitiseFileName(item[u'channelTitle']),
sanitiseFileName(item[u'title'])))
if filename != None:
if filename is not None:
videometadata[u'screenshot'] = filename
else:
if item[u'screenshot']:
Expand Down Expand Up @@ -1818,7 +1818,7 @@ def updateMythRecorded(items):
# Add new Miro unwatched videos to MythTV'd data base
for item in items_copy:
# Do not create records for Miro video files when Miro has a corrupt or missing file name
if item[u'videoFilename'] == None:
if item[u'videoFilename'] is None:
continue
# Do not create records for Miro video files that do not exist
if not os.path.isfile(os.path.realpath(item[u'videoFilename'])):
Expand Down Expand Up @@ -2021,7 +2021,7 @@ def updateMythVideo(items):
result = takeScreenShot(item[u'videoFilename'], screenshot_mythvideo, size_limit=False)
except:
result = None
if result != None:
if result is not None:
item[u'screenshot'] = screenshot_mythvideo
tmp_array = createVideometadataRecord(item)
videometadata = tmp_array[0]
Expand Down
2 changes: 1 addition & 1 deletion mythtv/contrib/imports/mirobridge/mirobridge/metadata.py
Expand Up @@ -169,7 +169,7 @@ def getMetadata(self, title):
# If there is no Record rule then check ttvdb.com
if not len(recordedRules_array):
inetref = self.searchTvdb(title)
if inetref != None: # Create a new rule for this Miro Channel title
if inetref is not None: # Create a new rule for this Miro Channel title
ttvdbGraphics['inetref'] = inetref
self.makeRecordRule['title'] = title
self.makeRecordRule['inetref'] = inetref
Expand Down
Expand Up @@ -280,7 +280,7 @@ def do_mythtv_getunwatched(self, line):
continue

# Any item without a proper file name needs to be removed as Miro metadata is corrupt
if it.get_filename() == None:
if it.get_filename() is None:
it.expire()
self.statistics[u'Miro_videos_deleted']+=1
logging.info(u'Unwatched video (%s) has been removed from Miro as item had no valid file name' % it.get_title())
Expand Down Expand Up @@ -314,7 +314,7 @@ def do_mythtv_getwatched(self, line):
continue

# Any item without a proper file name needs to be removed as Miro metadata is corrupt
if it.get_filename() == None:
if it.get_filename() is None:
it.expire()
self.statistics[u'Miro_videos_deleted']+=1
logging.info(u'Watched video (%s) has been removed from Miro as item had no valid file name' % it.get_title())
Expand Down
Expand Up @@ -292,7 +292,7 @@ def do_mythtv_getunwatched(self, line):

# Any item without a proper file name needs to be removed
# as Miro metadata is corrupt
if it.get_filename() == None:
if it.get_filename() is None:
it.expire()
self.statistics[u'Miro_videos_deleted']+=1
logging.info(
Expand Down Expand Up @@ -327,7 +327,7 @@ def do_mythtv_getwatched(self, line):
continue

# Any item without a proper file name needs to be removed as Miro metadata is corrupt
if it.get_filename() == None:
if it.get_filename() is None:
it.expire()
self.statistics[u'Miro_videos_deleted']+=1
logging.info(
Expand Down
Expand Up @@ -132,7 +132,7 @@ def get_priv_uuid(self):
def UuidDb():
"""Simple singleton wrapper with lazy initialization"""
global _uuid_db_instance
if _uuid_db_instance == None:
if _uuid_db_instance is None:
import config
from smolt import get_config_attr
_uuid_db_instance = _UuidDb(get_config_attr("UUID_DB", os.path.expanduser('~/.smolt/uuiddb.cfg')))
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/scripts/hardwareprofile/sendProfile.py
Expand Up @@ -286,7 +286,7 @@ def mention_profile_web_view(opts, pub_uuid, admin):


def get_proxies(opts):
if opts.httpproxy == None:
if opts.httpproxy is None:
proxies = dict()
else:
proxies = {'http':opts.httpproxy}
Expand Down
4 changes: 2 additions & 2 deletions mythtv/programs/scripts/hardwareprofile/smolt.py
Expand Up @@ -376,7 +376,7 @@ def ignoreDevice(device):
ignore = 1
if device.bus == 'Unknown' or device.bus == 'unknown':
return 1
if device.vendorid in (0, None) and device.type == None:
if device.vendorid in (0, None) and device.type is None:
return 1
if device.bus == 'usb' and device.driver == 'hub':
return 1
Expand All @@ -388,7 +388,7 @@ def ignoreDevice(device):
return 1
if device.bus == 'block' and device.type == 'DISK':
return 1
if device.bus == 'usb_device' and device.type == None:
if device.bus == 'usb_device' and device.type is None:
return 1
return 0

Expand Down

0 comments on commit 2e7e9e8

Please sign in to comment.