diff --git a/mythplugins/mytharchive/mythburn/scripts/mythburn.py b/mythplugins/mytharchive/mythburn/scripts/mythburn.py index f2485048a1e..692a4191a65 100755 --- a/mythplugins/mytharchive/mythburn/scripts/mythburn.py +++ b/mythplugins/mytharchive/mythburn/scripts/mythburn.py @@ -1,6 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -from __future__ import unicode_literals # python 3 doesn't have a unicode type try: @@ -115,7 +113,7 @@ except: # Some hardcoded values for ioctl calls, # not available on python > 3.5, see include/linux/cdrom.h - class CDROM(object): + class CDROM: CDS_NO_INFO = 0 CDS_NO_DISC = 1 CDS_TRAY_OPEN = 2 @@ -257,7 +255,7 @@ def simple_fix_rtl(str): ############################################################# # class to hold a font definition -class FontDef(object): +class FontDef: def __init__(self, name=None, fontFile=None, size=19, color="white", effect="normal", shadowColor="black", shadowSize=1): self.name = name self.fontFile = fontFile @@ -308,10 +306,7 @@ def drawText(self, text, color=None): def write(text, progress=True): """Simple place to channel all text output through""" - if sys.version_info == 2: - sys.stdout.write((text + "\n").encode("utf-8", "replace")) - else: - sys.stdout.write(text + "\n") + sys.stdout.write(text + "\n") sys.stdout.flush() if progress == True and progresslog != "": @@ -2026,7 +2021,7 @@ def extractVideoFrame(source, destination, seconds): return (long(0),long(0)) else: return myimage.size - except IOError: + except OSError: return (long(0),long(0)) ############################################################# @@ -2146,7 +2141,7 @@ def encodeNuvToMPEG2(chanid, starttime, mediafile, destvideofile, folder, profil """Encodes a nuv video source file to MPEG2 video and AC3 audio, using mythtranscode & mythffmpeg""" # make sure mythtranscode hasn't left some stale fifos hanging around - if ((doesFileExist(os.path.join(folder, "audout")) or doesFileExist(os.path.join(folder, "vidout")))): + if (doesFileExist(os.path.join(folder, "audout")) or doesFileExist(os.path.join(folder, "vidout"))): fatalError("Something is wrong! Found one or more stale fifo's from mythtranscode\n" "Delete the fifos in '%s' and start again" % folder) diff --git a/mythplugins/mythgame/mythgame/scripts/giantbomb.py b/mythplugins/mythgame/mythgame/scripts/giantbomb.py index fd823cc489e..a98640c0380 100755 --- a/mythplugins/mythgame/mythgame/scripts/giantbomb.py +++ b/mythplugins/mythgame/mythgame/scripts/giantbomb.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: UTF-8 -*- # ---------------------- # Name: giantbomb.py # Python Script @@ -129,29 +128,21 @@ import re -IS_PY2 = sys.version_info[0] == 2 - try: - if IS_PY2: - from StringIO import StringIO - else: - from io import StringIO + from io import StringIO from lxml import etree except Exception as e: - sys.stderr.write(u'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e) + sys.stderr.write('\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e) sys.exit(1) -if IS_PY2: - stdio_type = file -else: - import io - stdio_type = io.TextIOWrapper - unicode = str - unichr = chr +import io +stdio_type = io.TextIOWrapper +unicode = str +unichr = chr -class OutStreamEncoder(object): +class OutStreamEncoder: """Wraps a stream with an encoder """ def __init__(self, outstream, encoding=None): @@ -187,7 +178,7 @@ def __getattr__(self, attr): version+=str(digit)+'.' version = version[:-1] if version < '2.7.2': - sys.stderr.write(u''' + sys.stderr.write(''' ! Error - The installed version of the "lxml" python library "libxml" version is too old. At least "libxml" version 2.7.2 must be installed. Your version is (%s). ''' % version) @@ -218,22 +209,22 @@ def main(): # api.giantbomb.com api key provided for Mythtv apikey = "b5883a902a8ed88b15ce21d07787c94fd6ad9f33" - parser = OptionParser(usage=u"%prog usage: giantbomb -hdluvMD [parameters]\n \n\nFor details on using giantbomb from the command execute './giantbomb.py -u'. For details on the meaning of the XML element tags see the wiki page at:\nhttps://www.mythtv.org/wiki/MythTV_Universal_Metadata_Format") + parser = OptionParser(usage="%prog usage: giantbomb -hdluvMD [parameters]\n \n\nFor details on using giantbomb from the command execute './giantbomb.py -u'. For details on the meaning of the XML element tags see the wiki page at:\nhttps://www.mythtv.org/wiki/MythTV_Universal_Metadata_Format") parser.add_option( "-d", "--debug", action="store_true", default=False, dest="debug", - help=u"Show debugging info") + help="Show debugging info") parser.add_option( "-u", "--usage", action="store_true", default=False, dest="usage", - help=u"Display examples for executing the giantbomb script") + help="Display examples for executing the giantbomb script") parser.add_option( "-v", "--version", action="store_true", default=False, dest="version", - help=u"Display version and author") - parser.add_option( "-l", "--language", metavar="LANGUAGE", default=u'en', dest="language", - help=u"Select data that matches the specified language. At this time giantbomb.com only supports 'en' English.") - parser.add_option( "-a", "--area", metavar="AREA", default=u"gb", dest="area", - help=u"Select data that matches the specified country. This option is currently not used.") + help="Display version and author") + parser.add_option( "-l", "--language", metavar="LANGUAGE", default='en', dest="language", + help="Select data that matches the specified language. At this time giantbomb.com only supports 'en' English.") + parser.add_option( "-a", "--area", metavar="AREA", default="gb", dest="area", + help="Select data that matches the specified country. This option is currently not used.") parser.add_option( "-M", "--gamelist", action="store_true", default=False, dest="gamelist", - help=u"Get matching Movie list") + help="Get matching Movie list") parser.add_option( "-D", "--gamedata", action="store_true", default=False, dest="gamedata", - help=u"Get Movie metadata including graphic URLs") + help="Get Movie metadata including graphic URLs") opts, args = parser.parse_args() @@ -249,7 +240,7 @@ def main(): # Process version command line requests if opts.version: - version = etree.XML(u'') + version = etree.XML('') etree.SubElement(version, "name").text = __title__ etree.SubElement(version, "author").text = __author__ etree.SubElement(version, "thumbnail").text = 'giantbomb.png' @@ -269,7 +260,7 @@ def main(): sys.stderr.write("! Error: There must be one value for any option. Your options are (%s)\n" % (args)) sys.exit(1) - if args[0] == u'': + if args[0] == '': sys.stderr.write("! Error: There must be a non-empty argument, yours is empty.\n") sys.exit(1) diff --git a/mythplugins/mythgame/mythgame/scripts/giantbomb/giantbomb_api.py b/mythplugins/mythgame/mythgame/scripts/giantbomb/giantbomb_api.py index d4522cccd45..90a76bca12f 100644 --- a/mythplugins/mythgame/mythgame/scripts/giantbomb/giantbomb_api.py +++ b/mythplugins/mythgame/mythgame/scripts/giantbomb/giantbomb_api.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: UTF-8 -*- # ---------------------- # Name: giantbomb_api.py Simple-to-use Python interface to the GiantBomb's API (api.giantbomb.com) # Python Script @@ -28,15 +27,10 @@ import requests from copy import deepcopy -IS_PY2 = sys.version_info[0] == 2 -if not IS_PY2: - unicode = str - unichr = chr - from .giantbomb_exceptions import (GiantBombBaseError, GiantBombHttpError, GiantBombXmlError, GiantBombGameNotFound,) -class OutStreamEncoder(object): +class OutStreamEncoder: """Wraps a stream with an encoder""" def __init__(self, outstream, encoding=None): self.out = outstream @@ -47,7 +41,7 @@ def __init__(self, outstream, encoding=None): def write(self, obj): """Wraps the output stream, encoding Unicode strings with the specified encoding""" - if isinstance(obj, unicode): + if isinstance(obj, str): obj = obj.encode(self.encoding) if IS_PY2: self.out.write(obj) @@ -68,7 +62,7 @@ def __getattr__(self, attr): from io import StringIO from lxml import etree except Exception as e: - sys.stderr.write(u'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e) + sys.stderr.write('\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e) sys.exit(1) # Check that the lxml library is current enough @@ -80,7 +74,7 @@ def __getattr__(self, attr): version+=str(digit)+'.' version = version[:-1] if version < '2.7.2': - sys.stderr.write(u''' + sys.stderr.write(''' ! Error - The installed version of the "lxml" python library "libxml" version is too old. At least "libxml" version 2.7.2 must be installed. Your version is (%s). ''' % version) @@ -106,16 +100,16 @@ def __init__(self, self.config['apikey'] = apikey self.config['debug'] = debug - self.config['searchURL'] = u'https://www.giantbomb.com/api/search' - self.config['dataURL'] = u'https://www.giantbomb.com/api/game/%s' + self.config['searchURL'] = 'https://www.giantbomb.com/api/search' + self.config['dataURL'] = 'https://www.giantbomb.com/api/game/%s' # giantbomb.com now requires a unique 'User-Agent': self.config['headers'] = {"User-Agent": 'MythTV giantbomb grabber 0.2'} - self.error_messages = {'GiantBombHttpError': u"! Error: A connection error to api.giantbomb.com was raised (%s)\n", 'GiantBombXmlError': u"! Error: Invalid XML was received from api.giantbomb.com (%s)\n", 'GiantBombBaseError': u"! Error: An error was raised (%s)\n", } + self.error_messages = {'GiantBombHttpError': "! Error: A connection error to api.giantbomb.com was raised (%s)\n", 'GiantBombXmlError': "! Error: Invalid XML was received from api.giantbomb.com (%s)\n", 'GiantBombBaseError': "! Error: An error was raised (%s)\n", } self.baseProcessingDir = os.path.dirname( os.path.realpath( __file__ )) - self.pubDateFormat = u'%a, %d %b %Y %H:%M:%S GMT' + self.pubDateFormat = '%a, %d %b %Y %H:%M:%S GMT' self.xmlParser = etree.XMLParser(remove_blank_text=True) self.supportedJobList = ["actor", "author", "producer", "executive producer", "director", "cinematographer", "composer", "editor", "casting", "voice actor", "music", "writer", "technical director", "design director", ] @@ -151,9 +145,9 @@ def fixup(m): if text[:2] == "&#": try: if text[:3] == "&#x": - return unichr(int(text[3:-1], 16)) + return chr(int(text[3:-1], 16)) else: - return unichr(int(text[2:-1])) + return chr(int(text[2:-1])) except ValueError: pass elif text[:1] == "&": @@ -165,14 +159,14 @@ def fixup(m): if entity: if entity[:2] == "&#": try: - return unichr(int(entity[2:-1])) + return chr(int(entity[2:-1])) except ValueError: pass else: - return unicode(entity, "iso-8859-1") + return str(entity, "iso-8859-1") return text # leave as is if IS_PY2: - text23 = self.ampReplace(re.sub(u"(?s)<[^>]*>|&#?\w+;", fixup, self.textUtf8(text))).replace(u'\n',u' ') + text23 = self.ampReplace(re.sub(r"(?s)<[^>]*>|&#?\w+;", fixup, self.textUtf8(text))).replace('\n',' ') else: text23 = self.ampReplace(re.sub(r"(?s)<[^>]*>|&#?\w+;", fixup, self.textUtf8(text))).replace('\n',' ') return text23 @@ -183,9 +177,9 @@ def textUtf8(self, text): if text is None: return text try: - return unicode(text, 'utf8') + return str(text, 'utf8') except UnicodeDecodeError: - return u'' + return '' except (UnicodeEncodeError, TypeError): return text # end textUtf8() @@ -195,7 +189,7 @@ def ampReplace(self, text): '''Replace all "&" characters with "&" ''' text = self.textUtf8(text) - return text.replace(u'&',u'~~~~~').replace(u'&',u'&').replace(u'~~~~~', u'&') + return text.replace('&','~~~~~').replace('&','&').replace('~~~~~', '&') # end ampReplace() @@ -204,8 +198,8 @@ def htmlToString(self, context, html): return the string without HTML tags or LFs ''' if not len(html): - return u"" - return self.massageText(html).strip().replace(u'\n', u' ').replace(u'’', u"'").replace(u'“', u"'") + return "" + return self.massageText(html).strip().replace('\n', ' ').replace('’', "'").replace('“', "'") # end htmlToString() def getHtmlData(self, context, *args): @@ -231,7 +225,7 @@ def getHtmlData(self, context, *args): return filteredData[0] else: return filteredData[0].text - return u'' + return '' # end getHtmlData() def pubDate(self, context, *inputArgs): @@ -243,19 +237,19 @@ def pubDate(self, context, *inputArgs): args = [] for arg in inputArgs: args.append(arg) - if args[0] == u'': + if args[0] == '': return datetime.datetime.now().strftime(self.pubDateFormat) index = args[0].find('+') if index == -1: index = args[0].find('-') if index != -1 and index > 5: args[0] = args[0][:index].strip() - args[0] = args[0].replace(',', u'').replace('.', u'') + args[0] = args[0].replace(',', '').replace('.', '') try: if len(args) > 2: pubdate = time.strptime(args[0], args[2]) elif len(args) > 1: - args[1] = args[1].replace(',', u'').replace('.', u'') + args[1] = args[1].replace(',', '').replace('.', '') if args[1].find('GMT') != -1: args[1] = args[1][:args[1].find('GMT')].strip() args[0] = args[0][:args[0].rfind(' ')].strip() @@ -273,7 +267,7 @@ def pubDate(self, context, *inputArgs): else: return datetime.datetime.now().strftime(self.pubDateFormat) except Exception as err: - sys.stderr.write(u'! Error: pubDate variables(%s) error(%s)\n' % (args, err)) + sys.stderr.write('! Error: pubDate variables(%s) error(%s)\n' % (args, err)) return args[0] # end pubDate() @@ -296,16 +290,16 @@ def futureReleaseDate(self, context, gameElement): else: month = None except: - return u'' + return '' if not year: - return u'' + return '' if month and not quarter: - pubdate = time.strptime((u'%s-%s-01' % (year, month)), '%Y-%m-%d') + pubdate = time.strptime(('%s-%s-01' % (year, month)), '%Y-%m-%d') elif not month and quarter: - month = str((int(quarter)*3)) - pubdate = time.strptime((u'%s-%s-01' % (year, month)), '%Y-%m-%d') + month = str(int(quarter)*3) + pubdate = time.strptime(('%s-%s-01' % (year, month)), '%Y-%m-%d') else: - pubdate = time.strptime((u'%s-12-01' % (year, )), '%Y-%m-%d') + pubdate = time.strptime(('%s-12-01' % (year, )), '%Y-%m-%d') return time.strftime('%Y-%m-%d', pubdate) # end futureReleaseDate() @@ -319,7 +313,7 @@ def makeImageElement(typeImage, url, thumb): ''' Create a single Image element return the image element ''' - imageElement = etree.XML(u"") + imageElement = etree.XML("") imageElement.attrib['type'] = typeImage imageElement.attrib['url'] = url imageElement.attrib['thumb'] = thumb @@ -332,22 +326,22 @@ def makeImageElement(typeImage, url, thumb): imageList = superImageFilter(imageElement) if len(imageList): for image in imageList: - self.imageElements.append(makeImageElement('coverart', image, image.replace(u'super', u'thumb'))) - htmlElement = self.getHtmlData('dummy', etree.tostring(args[1][0], method="text", encoding=unicode).strip()) + self.imageElements.append(makeImageElement('coverart', image, image.replace('super', 'thumb'))) + htmlElement = self.getHtmlData('dummy', etree.tostring(args[1][0], method="text", encoding=str).strip()) if len(htmlElement): for image in htmlElement[0].xpath('.//a/img/@src'): if image.find('screen') == -1: continue if image.find('thumb') == -1: continue - self.imageElements.append(makeImageElement('screenshot', image.replace(u'thumb', u'super'), image)) + self.imageElements.append(makeImageElement('screenshot', image.replace('thumb', 'super'), image)) if len(args) > 2: for imageElement in args[2]: imageList = superImageFilter(imageElement) if len(imageList): for image in imageList: - self.imageElements.append(makeImageElement('screenshot', image, image.replace(u'super', u'thumb'))) + self.imageElements.append(makeImageElement('screenshot', image, image.replace('super', 'thumb'))) if not len(self.imageElements): return False @@ -428,10 +422,10 @@ def gameSearch(self, gameTitle): try: queryResult = etree.fromstring(res.content) except Exception as errmsg: - sys.stderr.write(u"! Error: Invalid XML was received from www.giantbomb.com (%s)\n" % errmsg) + sys.stderr.write("! Error: Invalid XML was received from www.giantbomb.com (%s)\n" % errmsg) sys.exit(1) - queryXslt = etree.XSLT(etree.parse(u'%s/XSLT/giantbombQuery.xsl' % self.baseProcessingDir)) + queryXslt = etree.XSLT(etree.parse('%s/XSLT/giantbombQuery.xsl' % self.baseProcessingDir)) gamebombXpath = etree.FunctionNamespace('https://www.mythtv.org/wiki/MythTV_Universal_Metadata_Format') gamebombXpath.prefix = 'gamebombXpath' self.buildFuncDict() @@ -465,10 +459,10 @@ def gameData(self, gameId): try: videoResult = etree.fromstring(res.content) except Exception as errmsg: - sys.stderr.write(u"! Error: Invalid XML was received from www.giantbomb.com (%s)\n" % errmsg) + sys.stderr.write("! Error: Invalid XML was received from www.giantbomb.com (%s)\n" % errmsg) sys.exit(1) - gameXslt = etree.XSLT(etree.parse(u'%s/XSLT/giantbombGame.xsl' % self.baseProcessingDir)) + gameXslt = etree.XSLT(etree.parse('%s/XSLT/giantbombGame.xsl' % self.baseProcessingDir)) gamebombXpath = etree.FunctionNamespace('https://www.mythtv.org/wiki/MythTV_Universal_Metadata_Format') gamebombXpath.prefix = 'gamebombXpath' self.buildFuncDict() @@ -493,10 +487,10 @@ def main(): api_key = "b5883a902a8ed88b15ce21d07787c94fd6ad9f33" gamebomb = gamedbQueries(api_key) # Output a dictionary of matching movie titles - gamebomb.gameSearch(u'Grand') + gamebomb.gameSearch('Grand') print() # Output a dictionary of matching movie details for GiantBomb number '19995' - gamebomb.gameData(u'19995') + gamebomb.gameData('19995') # end main() if __name__ == '__main__': diff --git a/mythplugins/mythgame/mythgame/scripts/giantbomb/giantbomb_exceptions.py b/mythplugins/mythgame/mythgame/scripts/giantbomb/giantbomb_exceptions.py index ce7eb4542f2..7dd7c862ef9 100644 --- a/mythplugins/mythgame/mythgame/scripts/giantbomb/giantbomb_exceptions.py +++ b/mythplugins/mythgame/mythgame/scripts/giantbomb/giantbomb_exceptions.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: UTF-8 -*- # ---------------------- # Name: giantbomb_exceptions - Custom exceptions used or raised by giantbomb_api # Python Script diff --git a/mythtv/bindings/python/MythTV/__init__.py b/mythtv/bindings/python/MythTV/__init__.py index 886d68d08f0..1985bf77c29 100644 --- a/mythtv/bindings/python/MythTV/__init__.py +++ b/mythtv/bindings/python/MythTV/__init__.py @@ -1,4 +1,3 @@ - __all_exceptions__ = ['MythError', 'MythDBError', 'MythBEError', \ 'MythFEError', 'MythFileError', 'MythTZError'] diff --git a/mythtv/bindings/python/MythTV/_conn_mysqldb.py b/mythtv/bindings/python/MythTV/_conn_mysqldb.py index 6f50433036b..03027bc466e 100644 --- a/mythtv/bindings/python/MythTV/_conn_mysqldb.py +++ b/mythtv/bindings/python/MythTV/_conn_mysqldb.py @@ -8,7 +8,7 @@ with warnings.catch_warnings(): warnings.simplefilter('ignore') import MySQLdb, MySQLdb.cursors -if (MySQLdb.version_info < (1,2,3)) and (sys.version_info >= (2,7)): +if MySQLdb.version_info < (1,2,3): raise ImportError('MySQLdb is too old for this version of Python') __version__ = tuple(['MySQLdb']+list(MySQLdb.version_info)) @@ -32,7 +32,7 @@ class LoggedCursor( MySQLdb.cursors.Cursor ): Custom cursor, offering logging and error handling """ def __init__(self, connection): - super(LoggedCursor, self).__init__(connection) + super().__init__(connection) self.log = None self.ping = ref(self._ping121) if MySQLdb.version_info >= (1, 2, 2): @@ -73,8 +73,8 @@ def execute(self, query, args=None): self.log_query(query, args) try: if args is None: - return super(LoggedCursor, self).execute(query) - return super(LoggedCursor, self).execute(query, args) + return super().execute(query) + return super().execute(query, args) except Exception as e: raise MythDBError(MythDBError.DB_RAW, e.args) @@ -99,7 +99,7 @@ def executemany(self, query, args): query = self._sanitize(query) self.log_query(query, args) try: - return super(LoggedCursor, self).executemany(query, args) + return super().executemany(query, args) except Exception as e: raise MythDBError(MythDBError.DB_RAW, e.args) diff --git a/mythtv/bindings/python/MythTV/altdict.py b/mythtv/bindings/python/MythTV/altdict.py index a7080480d53..8df0a71fda0 100644 --- a/mythtv/bindings/python/MythTV/altdict.py +++ b/mythtv/bindings/python/MythTV/altdict.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Provides tweaked dict-type classes.""" from MythTV.exceptions import MythError diff --git a/mythtv/bindings/python/MythTV/connections.py b/mythtv/bindings/python/MythTV/connections.py index 9ecd2645776..21ee7e85eb4 100644 --- a/mythtv/bindings/python/MythTV/connections.py +++ b/mythtv/bindings/python/MythTV/connections.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Provides basic connection classes.""" from MythTV.static import SCHEMA_VERSION, PROTO_VERSION, PROTO_TOKEN, BACKEND_SEP @@ -18,7 +17,6 @@ import queue import json import re -from builtins import str # Note: Support for oursql was removed in MythTV v32 try: @@ -27,7 +25,7 @@ except: raise MythError("No viable database module found.") -class _Connection_Pool( object ): +class _Connection_Pool: """ Provides a scaling connection pool to access a shared resource. """ @@ -119,7 +117,7 @@ def __init__(self, dbconn): self._refs = {} self.log(MythLog.DATABASE, MythLog.INFO, - "Attempting connection: {0}".format(dbconn.ident)) + "Attempting connection: {}".format(dbconn.ident)) try: _Connection_Pool.__init__(self) except: @@ -171,7 +169,7 @@ def __exit__(self, type, value, traceback): cursor.commit() cursor.close() -class BEConnection( object ): +class BEConnection: """ This is the basic backend connection object. You probably don't want to use this directly. @@ -196,7 +194,7 @@ def __init__(self, backend, port, localname=None, try: self.connect() - except socket.error as e: + except OSError as e: self.log.logTB(MythLog.SOCKET) self.connected = False self.log(MythLog.GENERAL, MythLog.CRIT, @@ -340,13 +338,13 @@ def __init__(self, backend, port, localname=None, deadline=10.0, level=2): self.threadrunning = False self.eventqueue = queue.Queue() - super(BEEventConnection, self).__init__(backend, port, localname, + super().__init__(backend, port, localname, False, deadline) def connect(self): if self.connected: return - super(BEEventConnection, self).connect() + super().connect() if len(self._regevents) and (not self.threadrunning): start_new_thread(self.eventloop, ()) @@ -435,9 +433,9 @@ def eventloop(self): def backendCommand(self, data, deadline=None): if self._announced: return "" - return super(BEEventConnection, self).backendCommand(data, deadline) + return super().backendCommand(data, deadline) -class FEConnection( object ): +class FEConnection: """ This is the basic frontend connection object. You probably dont want to use this directly. @@ -544,13 +542,13 @@ def recv(self, deadline=None): prompt = re.compile(b'([\r\n.]*)\r\n# ') try: res = self.socket.dlexpect(prompt, deadline=deadline) - except socket.error: + except OSError: raise MythFEError(MythError.FE_CONNECTION, self.host, self.port) except KeyboardInterrupt: raise return prompt.split(res)[0].decode('utf-8') -class XMLConnection( object ): +class XMLConnection: """ XMLConnection(backend=None, db=None, port=None) -> Backend status object @@ -608,7 +606,7 @@ def _request(self, path='', **keyvars): url = 'http://{0.host}:{0.port}/{1}'.format(self, path) if keyvars: url += '?' + '&'.join( - ['{0}={1}'.format(k,urllib.request.quote(v)) + ['{}={}'.format(k,urllib.request.quote(v)) for k,v in keyvars.items()]) self.log(self.log.NETWORK, self.log.DEBUG, 'Generating request', url) return self._Request(url) @@ -618,7 +616,7 @@ def getConnectionInfo(self, pin=0): dbconn = {'SecurityPin':pin} try: dat = self._request('Myth/GetConnectionInfo', \ - Pin='{0:0>4}'.format(pin)).readJSON() + Pin='{:0>4}'.format(pin)).readJSON() return dat['ConnectionInfo']['Database'] except: return {} diff --git a/mythtv/bindings/python/MythTV/database.py b/mythtv/bindings/python/MythTV/database.py index d2a6763835d..6db56968983 100644 --- a/mythtv/bindings/python/MythTV/database.py +++ b/mythtv/bindings/python/MythTV/database.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ Provides connection cache and data handlers for accessing the database. """ @@ -19,7 +17,6 @@ import time as _pyt import weakref import os -from builtins import int, str class DBData( DictData, MythSchema ): @@ -274,7 +271,7 @@ class DBDataWrite( DBData ): @classmethod def _setClassDefs(cls, db=None): db = DBCache(db) - super(DBDataWrite, cls)._setClassDefs(db) + super()._setClassDefs(db) if cls._defaults is None: cls._defaults = {} create = cls._create_normal @@ -797,8 +794,8 @@ def _picklelist(self): self._populate() return [a.values()+[a._cref] for a in self.copy()] -class DatabaseConfig( object ): - class _WakeOnLanConfig( object ): +class DatabaseConfig: + class _WakeOnLanConfig: def __init__(self): self.enabled = False self.waittime = 0 @@ -902,17 +899,17 @@ def test(self, log): obj.confdir = confdir if obj.readXML(confdir): log(log.GENERAL, log.DEBUG, - "Trying database credentials from: {0}"\ + "Trying database credentials from: {}"\ .format(os.path.join(confdir,'config.xml'))) yield obj elif obj.readOldXML(confdir): log(log.GENERAL, log.DEBUG, - "Trying old format database credentials from: {0}"\ + "Trying old format database credentials from: {}"\ .format(os.path.join(confdir,'config.xml'))) yield obj else: log(log.GENERAL, log.DEBUG, - "Failed to read database credentials from: {0}"\ + "Failed to read database credentials from: {}"\ .format(os.path.join(confdir,'config.xml'))) homedir = os.environ.get('HOME', '') @@ -921,17 +918,17 @@ def test(self, log): obj.confdir = os.path.join(homedir, '.mythtv') if obj.readXML(os.path.join(homedir,'.mythtv')): log(log.GENERAL, log.DEBUG, - "Trying database credentials from: {0}"\ + "Trying database credentials from: {}"\ .format(os.path.join(homedir,'config.xml'))) yield obj elif obj.readOldXML(os.path.join(homedir, '.mythtv')): log(log.GENERAL, log.DEBUG, - "Trying old format database credentials from: {0}"\ + "Trying old format database credentials from: {}"\ .format(os.path.join(homedir,'config.xml'))) yield obj else: log(log.GENERAL, log.DEBUG, - "Failed to read database credentials from: {0}"\ + "Failed to read database credentials from: {}"\ .format(os.path.join(homedir,'config.xml'))) # try UPnP @@ -939,12 +936,12 @@ def test(self, log): obj = self.copy() if obj.readUPNP(conn): log(log.GENERAL, log.DEBUG, - "Trying database credentials from: {0}"\ + "Trying database credentials from: {}"\ .format(conn.host)) yield obj else: log(log.GENERAL, log.DEBUG, - "Failed to read database credentials from: {0}"\ + "Failed to read database credentials from: {}"\ .format(conn.host)) # try defaults if user did not specify anything @@ -1055,7 +1052,7 @@ def writeXML(self, log): confdir = os.environ.get('MYTHCONFDIR', '') if confdir and (confdir != '/'): - log(log.GENERAL, log.DEBUG, "Writing new database credentials: {0}"\ + log(log.GENERAL, log.DEBUG, "Writing new database credentials: {}"\ .format(os.path.join(confdir,'config.xml'))) fp = open(os.path.join(confdir,'config.xml'), 'w') self.confdir = confdir @@ -1063,7 +1060,7 @@ def writeXML(self, log): homedir = os.environ.get('HOME', '') if homedir and (homedir != '/'): log(log.GENERAL, log.DEBUG, - "Writing new database credentials: {0}"\ + "Writing new database credentials: {}"\ .format(os.path.join(homedir,'config.xml'))) fp = open(os.path.join(homedir, '.mythtv', 'config.xml'), 'w') self.confdir = os.path.join(homedir, '.mythtv') diff --git a/mythtv/bindings/python/MythTV/dataheap.py b/mythtv/bindings/python/MythTV/dataheap.py index 6025bfaa92f..0392ac5932c 100644 --- a/mythtv/bindings/python/MythTV/dataheap.py +++ b/mythtv/bindings/python/MythTV/dataheap.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ Provides data access classes for accessing and managing MythTV data """ @@ -67,7 +65,7 @@ def __new__(cls, attr, parent=None, imagetype=None): # return a dumb string return str.__new__(str, attr) else: - return super(Artwork, cls).__new__(cls) + return super().__new__(cls) def __init__(self, attr, parent=None, imagetype=None): self.attr = attr @@ -128,7 +126,7 @@ class Record( CMPRecord, DBDataWrite, RECTYPE ): @classmethod def _setClassDefs(cls, db=None): db = DBCache(db) - super(Record, cls)._setClassDefs(db) + super()._setClassDefs(db) defaults = cls._template('Default', db=db) for k,v in list(defaults.items()): cls._defaults[k] = v @@ -962,7 +960,7 @@ class Video( CMPVideo, VideoSchema, DBDataWrite ): @classmethod def _setClassDefs(cls, db=None): db = DBCache(db) - super(Video, cls)._setClassDefs(db) + super()._setClassDefs(db) cls._fill_cm(db) @classmethod diff --git a/mythtv/bindings/python/MythTV/exceptions.py b/mythtv/bindings/python/MythTV/exceptions.py index 21e80f46c34..3ed8114e3ed 100644 --- a/mythtv/bindings/python/MythTV/exceptions.py +++ b/mythtv/bindings/python/MythTV/exceptions.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Provides custom error codes""" from MythTV.static import ERRCODES @@ -191,7 +190,7 @@ def __init__(self, *args): if args[0] == self.TZ_ERROR: self.ename = 'TZ_ERROR' self.ecode, self.reason = args - self.args = ("Error processing time zone: {0}".format(self.reason)) + self.args = ("Error processing time zone: {}".format(self.reason)) elif args[0] == self.TZ_INVALID_FILE: self.ename = 'TZ_INVALID_FILE' self.ecode, = args diff --git a/mythtv/bindings/python/MythTV/logging.py b/mythtv/bindings/python/MythTV/logging.py index f09422fef53..b46dae39915 100644 --- a/mythtv/bindings/python/MythTV/logging.py +++ b/mythtv/bindings/python/MythTV/logging.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Provides managed logging.""" from MythTV.static import LOGLEVEL, LOGMASK, LOGFACILITY @@ -250,7 +249,7 @@ def __new__(cls, *args, **kwargs): # abuse the __new__ constructor to set some immutable class attributes # before the class is instantiated cls._initlogger() - return super(MythLog, cls).__new__(cls) + return super().__new__(cls) def __init__(self, module='pythonbindings', db=None): self.module = module @@ -286,7 +285,7 @@ def _setfile(cls, filename): @classmethod def _setpath(cls, filepath): cls._initlogger() - cls._setfile(os.path.join(filepath, "{0}.{1}.{2}.log"\ + cls._setfile(os.path.join(filepath, "{}.{}.{}.log"\ .format(argv[0].split('/')[-1], datetime.now().strftime('%Y%m%d%H%M%S'), os.getpid()))) @@ -459,17 +458,17 @@ def _logfile(self, mask, level, message, detail): def _logsyslog(self, mask, level, message, detail): syslog.syslog(level, - message + (' -- {0}'.format(detail) if detail else '')) + message + (' -- {}'.format(detail) if detail else '')) def _logjournallog(self, mask, level, message, detail): if detail: - detail = ' -- {0}'.format(detail) + detail = ' -- {}'.format(detail) else: detail = '' application = argv[0] if '/' in application: application = application.rsplit('/', 1)[1] - msg = ("[{0}]: {1}{2}".format(self.module, message, detail)) + msg = ("[{}]: {}{}".format(self.module, message, detail)) journal.send(msg, PRIORITY=level, SYSLOG_IDENTIFIER=application ) def __call__(self, mask, level, message, detail=None): diff --git a/mythtv/bindings/python/MythTV/methodheap.py b/mythtv/bindings/python/MythTV/methodheap.py index 7bfdf16e77d..5552bbf45f0 100644 --- a/mythtv/bindings/python/MythTV/methodheap.py +++ b/mythtv/bindings/python/MythTV/methodheap.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ Provides base classes for accessing MythTV """ @@ -425,7 +423,7 @@ class BEEventMonitor( BECache ): def __init__(self, backend=None, blockshutdown=False, systemevents=False, db=None): self.systemevents = systemevents - super(BEEventMonitor, self).__init__(backend, blockshutdown, True, db) + super().__init__(backend, blockshutdown, True, db) def _listhandlers(self): return [self.eventMonitor] @@ -440,7 +438,7 @@ def eventMonitor(self, event=None): self.log(MythLog.ALL, MythLog.INFO, event) class MythSystemEvent( BECache ): - class systemeventhandler( object ): + class systemeventhandler: # decorator class for system events bs = BACKEND_SEP.replace('[',r'\[').replace(']',r'\]') re_process = re.compile(bs.join([ @@ -506,7 +504,7 @@ def _listhandlers(self): def __init__(self, backend=None, blockshutdown=False, db=None, enablehandler=True): - super(MythSystemEvent, self).__init__(backend, blockshutdown, True, db) + super().__init__(backend, blockshutdown, True, db) if enablehandler: self._events.append(self._generic_handler) @@ -521,7 +519,7 @@ def _generic_handler(self, event): class Frontend( FEConnection ): _db = None - class _Jump( object ): + class _Jump: def __str__(self): return str(self.list()) def __repr__(self): return str(self) @@ -554,7 +552,7 @@ def list(self): self._populate() return self._points.items() - class _Key( object ): + class _Key: _keymap = { 9:'tab', 10:'enter', 27:'escape', 32:'space', 92:'backslash', 127:'backspace', 258:'down', 259:'up', 260:'left', @@ -915,7 +913,7 @@ def searchGuide(self, init=False, key=None, value=None): if key.endswith('date'): prefix = {'on':'=', 'before':'<', 'after':'>'} if key[:-4] in prefix: - return ('DATE(program.starttime){0}?'.format(prefix[key[:-4]]), + return ('DATE(program.starttime){}?'.format(prefix[key[:-4]]), value, 0) if key == 'startbefore': @@ -1017,7 +1015,7 @@ def scanVideos(self): """ obj.scanVideo() --> list of new, moved, and deleted Videos """ - startvids = dict([(vid.intid, vid) for vid in Video.getAllEntries(db=self)]) + startvids = {vid.intid: vid for vid in Video.getAllEntries(db=self)} be = MythBE(db=self) r = re.compile(re.escape(BACKEND_SEP).\ diff --git a/mythtv/bindings/python/MythTV/msearch.py b/mythtv/bindings/python/MythTV/msearch.py index 99d14a277a7..3d42c0f5eea 100644 --- a/mythtv/bindings/python/MythTV/msearch.py +++ b/mythtv/bindings/python/MythTV/msearch.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Provides tools for UPNP searches""" from MythTV.exceptions import MythError @@ -7,7 +6,7 @@ from time import time import socket -class MSearch( object ): +class MSearch: """ Opens a socket for performing UPNP searches. """ @@ -25,7 +24,7 @@ def __init__(self): self.sock.bind(('', port)) self.addr = (addr, port) listening = True - except socket.error as e: + except OSError as e: if port < 1910: port += 1 else: @@ -65,7 +64,7 @@ def search(self, timeout=5.0, filter=None): while (time() MythBackend connection object @@ -44,7 +42,7 @@ class BECache( object ): and returns the response. """ - class _ConnHolder( object ): + class _ConnHolder: blockshutdown = 0 command = None event = None @@ -746,7 +744,7 @@ def allocateEventLock(self, regex): regex = re.compile(regex) return EventLock(regex, self.hostname, self.db) - class _ProgramQuery( object ): + class _ProgramQuery: def __init__(self, query, header_length=0, sorted=False, recstatus=None, handler=None): self.query = query @@ -1071,7 +1069,7 @@ def __init__(self, regex, backend=None, db=None): self.regex = regex self._lock = allocate_lock() self._lock.acquire() - super(EventLock, self).__init__(backend, False, True, db) + super().__init__(backend, False, True, db) def _listhandlers(self): return [self._unlock] diff --git a/mythtv/bindings/python/MythTV/services_api/__init__.py b/mythtv/bindings/python/MythTV/services_api/__init__.py index c9dab4baf1c..3130cb449f1 100644 --- a/mythtv/bindings/python/MythTV/services_api/__init__.py +++ b/mythtv/bindings/python/MythTV/services_api/__init__.py @@ -1,2 +1 @@ -# -*- coding: utf-8 -*- """ MythTV Services API interface. """ diff --git a/mythtv/bindings/python/MythTV/services_api/send.py b/mythtv/bindings/python/MythTV/services_api/send.py index 621a9af8fa1..2d597e21f22 100644 --- a/mythtv/bindings/python/MythTV/services_api/send.py +++ b/mythtv/bindings/python/MythTV/services_api/send.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """API Client.""" from os import fdopen @@ -21,7 +19,7 @@ from .mythversions import MYTHTV_VERSION_LIST -class Send(object): +class Send: """Services API.""" def __init__(self, host, port=6544): diff --git a/mythtv/bindings/python/MythTV/services_api/utilities.py b/mythtv/bindings/python/MythTV/services_api/utilities.py index c8f95e86c2a..56da6d96cd5 100644 --- a/mythtv/bindings/python/MythTV/services_api/utilities.py +++ b/mythtv/bindings/python/MythTV/services_api/utilities.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """API utilities.""" from datetime import datetime, timedelta diff --git a/mythtv/bindings/python/MythTV/static.py b/mythtv/bindings/python/MythTV/static.py index 434c3ec94ca..bc775ccdddf 100644 --- a/mythtv/bindings/python/MythTV/static.py +++ b/mythtv/bindings/python/MythTV/static.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ Contains static and global variables for MythTV Python Bindings. Version information is placed in '_versions.py'. @@ -7,7 +5,7 @@ from MythTV._versions import * -class MARKUP( object ): +class MARKUP: MARK_UNSET = -10 MARK_TMP_CUT_END = -5 MARK_TMP_CUT_START = -4 @@ -37,7 +35,7 @@ class MARKUP( object ): MARK_UTIL_PROGSTART = 40 MARK_UTIL_LASTPLAYPOS = 41 -class RECTYPE( object ): +class RECTYPE: kNotRecording = 0 kSingleRecord = 1 kDailyRecord = 2 @@ -51,7 +49,7 @@ class RECTYPE( object ): #kFindWeeklyRecord = 10 (Obsolete) kTemplateRecord = 11 -class RECSEARCHTYPE( object ): +class RECSEARCHTYPE: kNoSearch = 0 kPowerSearch = 1 kTitleSearch = 2 @@ -59,7 +57,7 @@ class RECSEARCHTYPE( object ): kPeopleSearch = 4 kManualSearch = 5 -class RECSTATUS( object ): +class RECSTATUS: rsPending = -15 rsFailing = -14 rsTuning = -10 @@ -86,7 +84,7 @@ class RECSTATUS( object ): rsNeverRecord = 11 rsOffline = 12 -class AUDIO_PROPS( object ): +class AUDIO_PROPS: AUD_UNKNOWN = 0x00 AUD_STEREO = 0x01 AUD_MONO = 0x02 @@ -95,7 +93,7 @@ class AUDIO_PROPS( object ): AUD_HARDHEAR = 0x10 AUD_VISUALIMPAIR = 0x20 -class VIDEO_PROPS( object ): +class VIDEO_PROPS: VID_UNKNOWN = 0x0000 VID_WIDESCREEN = 0x0001 VID_HDTV = 0x0002 @@ -109,14 +107,14 @@ class VIDEO_PROPS( object ): VID_PROGRESSIVE = 0x0200 VID_DAMAGED = 0x0400 -class SUBTITLE_TYPES( object ): +class SUBTITLE_TYPES: SUB_UNKNOWN = 0x00 SUB_HARDHEAR = 0x01 SUB_NORMAL = 0x02 SUB_ONSCREEN = 0x04 SUB_SIGNED = 0x08 -class CAST_ROLES( object ): +class CAST_ROLES: UNKNOWN = 0x0000 ACTOR = 0x0001 DIRECTOR = 0x0002 @@ -130,7 +128,7 @@ class CAST_ROLES( object ): COMMENTATOR = 0x0200 GUEST = 0x0400 -class JOBTYPE( object ): +class JOBTYPE: NONE = 0x0000 SYSTEMJOB = 0x00ff TRANSCODE = 0x0001 @@ -143,21 +141,21 @@ class JOBTYPE( object ): USERJOB3 = 0x0400 USERJOB4 = 0x0800 -class JOBCMD( object ): +class JOBCMD: RUN = 0x0000 PAUSE = 0x0001 RESUME = 0x0002 STOP = 0x0004 RESTART = 0x0008 -class JOBFLAG( object ): +class JOBFLAG: NO_FLAGS = 0x0000 USE_CUTLIST = 0x0001 LIVE_REC = 0x0002 EXTERNAL = 0x0004 REBUILD = 0x0008 -class JOBSTATUS( object ): +class JOBSTATUS: UNKNOWN = 0x0000 QUEUED = 0x0001 PENDING = 0x0002 @@ -174,7 +172,7 @@ class JOBSTATUS( object ): ERRORED = 0x0130 CANCELLED = 0x0140 -class LOGMASK( object ): +class LOGMASK: ALL = 0b111111111111111111111111111 MOST = 0b011111111110111111111111111 NONE = 0b000000000000000000000000000 @@ -207,7 +205,7 @@ class LOGMASK( object ): SYSTEM = 0b010000000000000000000000000 TIMESTAMP = 0b100000000000000000000000000 -class LOGLEVEL( object ): +class LOGLEVEL: ANY = -1 EMERG = 0 ALERT = 1 @@ -219,7 +217,7 @@ class LOGLEVEL( object ): DEBUG = 7 UNKNOWN = 8 -class LOGFACILITY( object ): +class LOGFACILITY: KERN = 1 USER = 2 MAIL = 3 @@ -238,7 +236,7 @@ class LOGFACILITY( object ): LOCAL6 = 16 LOCAL7 = 17 -class ERRCODES( object ): +class ERRCODES: GENERIC = 0 SYSTEM = 1 SOCKET = 2 @@ -265,7 +263,7 @@ class ERRCODES( object ): TZ_CONVERSION_ERROR = 253 TZ_VERSION_ERROR = 254 -class MythSchema( object ): +class MythSchema: _schema_value = 'DBSchemaVer' _schema_local = SCHEMA_VERSION _schema_name = 'Database' @@ -274,7 +272,7 @@ class MythSchema( object ): class VideoSchema( MythSchema ): pass -class MusicSchema( object ): +class MusicSchema: _schema_value = 'MusicDBSchemaVer' _schema_local = MUSICSCHEMA_VERSION _schema_name = 'MythMusic' diff --git a/mythtv/bindings/python/MythTV/system.py b/mythtv/bindings/python/MythTV/system.py index 6623b10c217..943e356fc42 100644 --- a/mythtv/bindings/python/MythTV/system.py +++ b/mythtv/bindings/python/MythTV/system.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ Provides base classes for managing system calls. """ @@ -26,7 +24,7 @@ class System( DBCache ): """ logmodule = 'Python system call handler' - class Process( object ): + class Process: def __init__(self, cmd, useshell, log): self.cmd = cmd self.log = log @@ -348,7 +346,7 @@ def _processMetadata(self, xml): yield self.cls(item) def command(self, *args): - return self._processMetadata(super(Grabber, self).command(*args)) + return self._processMetadata(super().command(*args)) def search(self, phrase, subtitle=None, tolerance=None, func=None): """ diff --git a/mythtv/bindings/python/MythTV/utility/altdict.py b/mythtv/bindings/python/MythTV/utility/altdict.py index 0656b1add72..145909a6bcd 100644 --- a/mythtv/bindings/python/MythTV/utility/altdict.py +++ b/mythtv/bindings/python/MythTV/utility/altdict.py @@ -11,7 +11,6 @@ # For the classes 'DictInvert' and 'DictInvertCI', please use the imports # 'from MythTV.altdict import DictInvert, DictInvertCI' -from builtins import map, zip from warnings import warn class OrdDict( dict ): diff --git a/mythtv/bindings/python/MythTV/utility/dequebuffer.py b/mythtv/bindings/python/MythTV/utility/dequebuffer.py index a4b229f0328..e05773fe194 100644 --- a/mythtv/bindings/python/MythTV/utility/dequebuffer.py +++ b/mythtv/bindings/python/MythTV/utility/dequebuffer.py @@ -24,7 +24,7 @@ def __init__(self, group=None, target=None, name=None, args=(), kwargs={}): self.inputqueue = Queue() self.idletime = time() - super(_PollingThread, self).__init__(group, + super().__init__(group, target, name, args, kwargs) def add_pipe(self, buff, pipe, mode): self.inputqueue.put((buff, pipe, mode)) @@ -96,7 +96,7 @@ def __init__(self, group=None, target=None, name=None, args=(), kwargs={}): self.inputqueue = Queue() self.idletime = time() - super(_PollingThread, self).__init__(group, + super().__init__(group, target, name, args, kwargs) def add_pipe(self, buff, pipe, mode): self.inputqueue.put((buff, pipe, mode)) @@ -158,14 +158,14 @@ def run(self): else: self.idletime = time() -class DequeBuffer( object ): +class DequeBuffer: """ This is a chunked buffer, storing a sequence of buffer objects in a deque, allowing for FIFO operations outside the limited 64K system buffer, and the efficient freeing of memory without needing to rewrite a large contiguous buffer object. """ - class _Buffer( object ): + class _Buffer: """ This subclass contains a buffer object and a read/write lock, as well as independent read and write positions. diff --git a/mythtv/bindings/python/MythTV/utility/dicttoxml.py b/mythtv/bindings/python/MythTV/utility/dicttoxml.py index 3c1d2eb8754..79f33000eb7 100644 --- a/mythtv/bindings/python/MythTV/utility/dicttoxml.py +++ b/mythtv/bindings/python/MythTV/utility/dicttoxml.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ Converts a Python dictionary or other native data type into a valid XML string. @@ -8,7 +6,6 @@ This module works with both Python 2 and 3. """ -from __future__ import unicode_literals __version__ = '1.7.4' version = __version__ @@ -17,7 +14,7 @@ try: from collections.abc import Iterable except ImportError: - from collections import Iterable + from collections.abc import Iterable import numbers import logging from xml.dom.minidom import parseString diff --git a/mythtv/bindings/python/MythTV/utility/dt.py b/mythtv/bindings/python/MythTV/utility/dt.py index de04d537c98..9a6ec6f1765 100644 --- a/mythtv/bindings/python/MythTV/utility/dt.py +++ b/mythtv/bindings/python/MythTV/utility/dt.py @@ -351,29 +351,29 @@ def fromDatetime(cls, dt, tzinfo=None): def now(cls, tz=None): if tz is None: tz = cls.localTZ() - obj = super(datetime, cls).now(tz) + obj = super().now(tz) return cls.fromDatetime(obj) @classmethod def utcnow(cls): - obj = super(datetime, cls).utcnow() + obj = super().utcnow() return obj.replace(tzinfo=cls.UTCTZ()) @classmethod def fromtimestamp(cls, timestamp, tz=None): if tz is None: tz = cls.localTZ() - obj = super(datetime, cls).fromtimestamp(float(timestamp), tz) + obj = super().fromtimestamp(float(timestamp), tz) return cls.fromDatetime(obj) @classmethod def utcfromtimestamp(cls, timestamp): - obj = super(datetime, cls).utcfromtimestamp(float(timestamp)) + obj = super().utcfromtimestamp(float(timestamp)) return obj.replace(tzinfo=cls.UTCTZ()) @classmethod def strptime(cls, datestring, format, tzinfo=None): - obj = super(datetime, cls).strptime(datestring, format) + obj = super().strptime(datestring, format) return cls.fromDatetime(obj, tzinfo) # new class methods for interfacing with MythTV @@ -394,7 +394,7 @@ def frommythtime(cls, mtime, tz=None): def fromIso(cls, isotime, sep='T', tz=None): match = cls._reiso.match(isotime) if match is None: - raise TypeError("time data '{0}' does not match ISO 8601 format" \ + raise TypeError("time data '{}' does not match ISO 8601 format" \ .format(isotime)) dt = [int(a) for a in match.groups()[:5]] @@ -425,7 +425,7 @@ def fromIso(cls, isotime, sep='T', tz=None): def fromRfc(cls, rfctime, tz=None): match = cls._rerfc.match(rfctime) if match is None: - raise TypeError("time data '{0}' does not match RFC 822 format"\ + raise TypeError("time data '{}' does not match RFC 822 format"\ .format(rfctime)) year = int(match.group('year')) @@ -526,7 +526,7 @@ def utcisoformat(self): return self.astimezone(self.UTCTZ()).isoformat().split('+')[0] def astimezone(self, tz): - return self.fromDatetime(super(datetime, self).astimezone(tz)) + return self.fromDatetime(super().astimezone(tz)) def asnaiveutc(self): return self.astimezone(self.UTCTZ()).replace(tzinfo=None) diff --git a/mythtv/bindings/python/MythTV/utility/enum.py b/mythtv/bindings/python/MythTV/utility/enum.py index 0f12d6cce58..c127183ee72 100644 --- a/mythtv/bindings/python/MythTV/utility/enum.py +++ b/mythtv/bindings/python/MythTV/utility/enum.py @@ -10,10 +10,9 @@ # removed after the release of MythTV v32! # Please use the class 'IntEnum' from the module 'enum' provided by python3. -from builtins import int from warnings import warn -class EnumValue( object ): +class EnumValue: _next = 0 _storage = [] def __init__(self, name, value=None, friendly_name=None): @@ -30,8 +29,8 @@ def _incr(cls, value): if value is not None: if cls._next: # this should be zero - raise RuntimeError(("Cannot mix specified and auto-increment " - "values in same Enum")) + raise RuntimeError("Cannot mix specified and auto-increment " + "values in same Enum") return value # increment and continue self._next += 1 @@ -58,7 +57,7 @@ def __getattr__(cls, key): return cls(cls._values[key].value) raise AttributeError(key) -class BaseEnum( object, metaclass=EnumType ): +class BaseEnum(metaclass=EnumType ): def __init__(self, mode): warn("Class 'BaseEnum' and it descendants will be removed after MythTV v32 release, " diff --git a/mythtv/bindings/python/MythTV/utility/mixin.py b/mythtv/bindings/python/MythTV/utility/mixin.py index 118182de6b5..2e1d8cfc657 100644 --- a/mythtv/bindings/python/MythTV/utility/mixin.py +++ b/mythtv/bindings/python/MythTV/utility/mixin.py @@ -4,7 +4,7 @@ # Description: Provides mixin's for assorted methods #------------------------------ -class CMPVideo( object ): +class CMPVideo: """ Utility class providing comparison operators between data objects containing video metadata. @@ -223,12 +223,12 @@ def __lt__(self, other): if not (hasattr(self, 'chanid') or hasattr(other, 'chanid')): # either object is not a recording-related object # fall through to video matching - return super(CMPRecord, self).__lt__(other) + return super().__lt__(other) # select attributes to use for comparison l,r = self.__choose_comparison(self, other) if None in (l,r): - return super(CMPRecord, self).__lt__(other) + return super().__lt__(other) # generate comparison function, and return result check = lambda s,o: (s.chanid, s[l]) < (o.chanid, o[l]) @@ -244,11 +244,11 @@ def __eq__(self, other): pass if not (hasattr(self, 'chanid') or hasattr(other, 'chanid')): - return super(CMPRecord, self).__eq__(other) + return super().__eq__(other) l,r = self.__choose_comparison(self, other) if None in (l,r): - return super(CMPRecord, self).__eq__(other) + return super().__eq__(other) check = lambda s,o: (s.chanid, s[l]) == (o.chanid, o[l]) self._eq__[type(other)] = check @@ -263,11 +263,11 @@ def __gt__(self, other): pass if not (hasattr(self, 'chanid') or hasattr(other, 'chanid')): - return super(CMPRecord, self).__gt__(other) + return super().__gt__(other) l,r = self.__choose_comparison(self, other) if None in (l,r): - return super(CMPRecord, self).__gt__(other) + return super().__gt__(other) check = lambda s,o: (s.chanid, s[l]) > (o.chanid, o[l]) self._gt__[type(other)] = check diff --git a/mythtv/bindings/python/MythTV/utility/other.py b/mythtv/bindings/python/MythTV/utility/other.py index 497bff767e0..4e4e603ebcc 100644 --- a/mythtv/bindings/python/MythTV/utility/other.py +++ b/mythtv/bindings/python/MythTV/utility/other.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Provides decorator classes for assorted functions""" from MythTV.logging import MythLog @@ -7,17 +6,15 @@ from io import BytesIO from select import select from time import time -from builtins import map import weakref import socket import re import sys -from builtins import range def _donothing(*args, **kwargs): pass -class SchemaUpdate( object ): +class SchemaUpdate: # TODO: do locking and lock checking # if interactive terminal, ask for update permission # perform database backup (partial?) @@ -67,7 +64,7 @@ def run(self): def create(self): raise MythDBError('Schema creation failed, method not defined.') -class databaseSearch( object ): +class databaseSearch: # decorator class for database searches """ Decorator class @@ -113,7 +110,7 @@ class databaseSearch( object ): 4-field -- Special response consisting of: (see example in methodheap.py:MythDB.searchRecorded) """ - class Join( object ): + class Join: def __init__(self, table=None, tableto=None, fields=None, \ fieldsto=None, fieldsfrom=None): if (table is None) or (tableto is None) or \ @@ -331,7 +328,7 @@ def dlrecv(self, bufsize, flags=0, deadline=None): p = buff.tell() try: buff.write(self.recv(bufsize-buff.tell(), flags)) - except socket.error as e: + except OSError as e: raise MythError(MythError.SOCKET, e.args) if buff.tell() == p: # no data read from a 'ready' socket, connection terminated @@ -363,7 +360,7 @@ def dlexpect(self, pattern, flags=0, deadline=None): p = buff.tell() try: buff.write(self.recv(100, flags)) - except socket.error as e: + except OSError as e: raise MythError(MythError.SOCKET, e.args) if buff.tell() == p: # no data read from a 'ready' socket, connection terminated @@ -394,10 +391,10 @@ def sendheader(self, data, flags=0): length = b'%-8d' % len(data) data = b"".join([length, data]) self.send(data, flags) - except socket.error as e: + except OSError as e: raise MythError(MythError.SOCKET, e.args) -class MARKUPLIST( object ): +class MARKUPLIST: """ Utility class for building seek/cutlists from video markup data. """ @@ -445,7 +442,7 @@ def levenshtein(s1, s2): return previous_row[-1] -class ParseEnum( object ): +class ParseEnum: _static = None def __str__(self): return str([k for k,v in self.iteritems() if v==True]) @@ -511,8 +508,8 @@ def __init__(self, parent, field_name, editable=True): if field[:4] != 'set(': raise MythDBError("ParseSet error. "+\ "Field '%s' not of type 'set()'" % self._field) - self._enum = dict([(t,2**i) for i,t in enumerate([type.strip("'")\ - for type in field[4:-1].split(',')])]) + self._enum = {t:2**i for i,t in enumerate([type.strip("'")\ + for type in field[4:-1].split(',')])} self._static = not editable def __getattr__(self, name): @@ -569,7 +566,7 @@ def check_ipv6(n): try: socket.inet_pton(socket.AF_INET6, n) return True - except socket.error: + except OSError: return False def resolve_ip(host, port): @@ -589,7 +586,7 @@ def py3_str(value, ignore_errors=False): except TypeError: # Wasn't a bytes object, no need to decode return str(value) -class QuickProperty( object ): +class QuickProperty: def __init__(self, maskedvar, default=None, handler=None): self.varname = maskedvar self.default = default diff --git a/mythtv/bindings/python/MythTV/utility/singleton.py b/mythtv/bindings/python/MythTV/utility/singleton.py index 7a2657b786b..11571f1da06 100644 --- a/mythtv/bindings/python/MythTV/utility/singleton.py +++ b/mythtv/bindings/python/MythTV/utility/singleton.py @@ -11,13 +11,13 @@ class Singleton( type ): """ def __new__(mcs, name, bases, kwargs): if '__slots__' in kwargs: - kwargs['__slots__']['_{0}__instance'.format(name)] = None + kwargs['__slots__']['_{}__instance'.format(name)] = None else: - kwargs['_{0}__instance'.format(name)] = None + kwargs['_{}__instance'.format(name)] = None return type.__new__(mcs, name, bases, kwargs) def __call__(cls, *args, **kwargs): - attr = '_{0}__instance'.format(cls.__name__) + attr = '_{}__instance'.format(cls.__name__) inst = getattr(cls, attr) if inst: return inst @@ -32,13 +32,13 @@ class InputSingleton( type ): """ def __new__(mcs, name, bases, kwargs): if '__slots__' in kwargs: - kwargs['__slots__']['_{0}__instance'.format(name)] = {} + kwargs['__slots__']['_{}__instance'.format(name)] = {} else: - kwargs['_{0}__instance'.format(name)] = {} + kwargs['_{}__instance'.format(name)] = {} return type.__new__(mcs, name, bases, kwargs) def __call__(cls, *args, **kwargs): - attr = '_{0}__instance'.format(cls.__name__) + attr = '_{}__instance'.format(cls.__name__) insts = getattr(cls, attr) from inspect import getcallargs @@ -57,13 +57,13 @@ class CmpSingleton( type ): """ def __new__(mcs, name, bases, kwargs): if '__slots__' in kwargs: - kwargs['__slots__']['_{0}__instance'.format(name)] = [] + kwargs['__slots__']['_{}__instance'.format(name)] = [] else: - kwargs['_{0}__instance'.format(name)] = [] + kwargs['_{}__instance'.format(name)] = [] return type.__new__(mcs, name, bases, kwargs) def __call__(cls, *args, **kwargs): - attr = '_{0}__instance'.format(cls.__name__) + attr = '_{}__instance'.format(cls.__name__) insts = getattr(cls, attr) obj = type.__call__(cls, *args, **kwargs) for inst in insts: diff --git a/mythtv/bindings/python/MythTV/wikiscripts/__init__.py b/mythtv/bindings/python/MythTV/wikiscripts/__init__.py index cbc611a36bb..a04b814851f 100644 --- a/mythtv/bindings/python/MythTV/wikiscripts/__init__.py +++ b/mythtv/bindings/python/MythTV/wikiscripts/__init__.py @@ -1,4 +1,3 @@ - from .wikiscripts import * diff --git a/mythtv/bindings/python/MythTV/wikiscripts/wikiscripts.py b/mythtv/bindings/python/MythTV/wikiscripts/wikiscripts.py index ec25f39e3df..87d18855737 100644 --- a/mythtv/bindings/python/MythTV/wikiscripts/wikiscripts.py +++ b/mythtv/bindings/python/MythTV/wikiscripts/wikiscripts.py @@ -1,4 +1,3 @@ -# -*- coding: UTF-8 -*- #---------------------- try: @@ -27,7 +26,6 @@ import sys import stat -from builtins import input BASEURL = 'https://www.mythtv.org/wiki' @@ -35,8 +33,8 @@ def getScripts(): return Script.getAll() def getPage(**kwargs): - url = "{0}?{1}".format(BASEURL, - '&'.join(['{0}={1}'.format(k,v) for k,v in list(kwargs.items())])) + url = "{}?{}".format(BASEURL, + '&'.join(['{}={}'.format(k,v) for k,v in list(kwargs.items())])) return lxml.html.parse(urlopen(url)).getroot() def getWhatLinksHere(page): @@ -47,7 +45,7 @@ def getWhatLinksHere(page): links.append('_'.join(link.find('a').text.split(' '))) return links -class Script( object ): +class Script: _cache = None _queue = Queue.Queue() _pool = [] @@ -104,7 +102,7 @@ def __cmp__(self, other): return 0 def __repr__(self): - return '