diff --git a/CHANGES.md b/CHANGES.md index 0befb056..24175c01 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -37,6 +37,7 @@ * Change py2 octal literals into the new py2/3 syntax * Change py2 iteritems to py2/3 compatible statements using six library * Change py2 queue, httplib, cookielib and xmlrpclib to py2/3 compatible calls using six +* Change py2 file and reload functions to py2/3 compatible open and reload_module functions * Change Kodi notifier to use requests as opposed to urllib * Change to consolidate scene exceptions and name cache code * Change check_url function to use requests instead of httplib library diff --git a/SickBeard.py b/SickBeard.py index 99d2b016..f50cac3e 100755 --- a/SickBeard.py +++ b/SickBeard.py @@ -49,6 +49,7 @@ except: sys.exit(1) sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib'))) +from six.moves import reload_module # We only need this for compiling an EXE and I will just always do that on 2.6+ if sys.hexversion >= 0x020600F0: @@ -140,7 +141,7 @@ class SickGear(object): sickbeard.SYS_ENCODING = 'UTF-8' if not hasattr(sys, 'setdefaultencoding'): - reload(sys) + reload_module(sys) try: # pylint: disable=E1101 @@ -412,7 +413,7 @@ class SickGear(object): pid = str(os.getpid()) logger.log(u'Writing PID: %s to %s' % (pid, self.PIDFILE)) try: - file(self.PIDFILE, 'w').write('%s\n' % pid) + open(self.PIDFILE, 'w').write('%s\n' % pid) except IOError as e: logger.log_error_and_exit( u'Unable to write PID file: %s Error: %s [%s]' % (self.PIDFILE, e.strerror, e.errno)) @@ -422,9 +423,9 @@ class SickGear(object): sys.stderr.flush() devnull = getattr(os, 'devnull', '/dev/null') - stdin = file(devnull, 'r') - stdout = file(devnull, 'a+') - stderr = file(devnull, 'a+') + stdin = open(devnull, 'r') + stdout = open(devnull, 'a+') + stderr = open(devnull, 'a+') os.dup2(stdin.fileno(), sys.stdin.fileno()) os.dup2(stdout.fileno(), sys.stdout.fileno()) os.dup2(stderr.fileno(), sys.stderr.fileno()) diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 883becf6..fc4b0caf 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -1015,7 +1015,7 @@ def mapIndexersToShow(showObj): def touchFile(fname, atime=None): if None != atime: try: - with file(fname, 'a'): + with open(fname, 'a'): os.utime(fname, (atime, atime)) return True except: diff --git a/sickbeard/network_timezones.py b/sickbeard/network_timezones.py index dca1a8f3..b5eeec4f 100644 --- a/sickbeard/network_timezones.py +++ b/sickbeard/network_timezones.py @@ -27,6 +27,7 @@ import os import re import datetime from six import iteritems +from six.moves import reload_module # regex to parse time (12/24 hour format) time_regex = re.compile(r'(\d{1,2})(([:.](\d{2,2}))? ?([PA][. ]? ?M)|[:.](\d{2,2}))\b', flags=re.IGNORECASE) @@ -126,7 +127,7 @@ def _update_zoneinfo(): # rename downloaded file ek.ek(os.rename, zonefile_tmp, zonefile) # load the new zoneinfo - reload(lib.dateutil.zoneinfo) + reload_module(lib.dateutil.zoneinfo) sb_timezone = tz.tzlocal() except: _remove_zoneinfo_failed(zonefile_tmp) diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 61661f2f..6d14b7c0 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -154,7 +154,7 @@ class BaseHandler(RequestHandler): if api: mime_type, encoding = MimeTypes().guess_type(static_image_path) self.set_header('Content-Type', mime_type) - with file(static_image_path, 'rb') as img: + with open(static_image_path, 'rb') as img: return img.read() else: static_image_path = os.path.normpath(static_image_path.replace(sickbeard.CACHE_DIR, '/cache'))