From: Bradley Sepos Date: Tue, 26 Feb 2019 21:25:58 +0000 (-0500) Subject: make: More Python 3 compatibility fixes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=63144e78716b185fdb0fd0575dfce385a3719302;p=handbrake make: More Python 3 compatibility fixes. --- diff --git a/make/df-fetch.py b/make/df-fetch.py index cfea5256c..efdd6e054 100644 --- a/make/df-fetch.py +++ b/make/df-fetch.py @@ -1,8 +1,6 @@ ############################################################################### ## -## Coded for minimum version of Python 2.7 . -## -## Python3 is incompatible. +## This script is coded for Python 2.7 through Python 3.x ## ## Authors: konablend ## @@ -16,7 +14,11 @@ import os import signal import sys import time -import urllib2 + +try: + from urllib.request import urlopen +except ImportError: + from urllib2 import urlopen sys.dont_write_bytecode = True sys.path.insert(0, os.path.join(sys.path[0], 'lib')) @@ -176,12 +178,12 @@ class URL(object): if filename: tool.infof('downloading %s to %s\n' % (self.url,filename)) ftmp = tool.mktmpname(filename) - hout = open(ftmp, 'w') + hout = open(ftmp, 'wb') ensure.unlink_ftmp = lambda: os.unlink(ftmp) ensure.close_hout = lambda: hout.close() else: tool.infof('downloading %s\n' % (self.url)) - hin = urllib2.urlopen(self.url, None, 30) + hin = urlopen(self.url, None, 30) ensure.close_hin = lambda: hin.close() info = hin.info() try: diff --git a/make/df-verify.py b/make/df-verify.py index eb29f4bc9..f370d930a 100644 --- a/make/df-verify.py +++ b/make/df-verify.py @@ -1,8 +1,6 @@ ############################################################################### ## -## Coded for minimum version of Python 2.7 . -## -## Python3 is incompatible. +## This script is coded for Python 2.7 through Python 3.x ## ## Authors: konablend ## @@ -50,7 +48,7 @@ class Tool(hb_distfile.Tool): def _scan(self, filename): self.verbosef('scanning %s\n' % filename) hasher = hashlib.sha256() - with open(filename, 'r') as o: + with open(filename, 'rb') as o: data_total = 0 while True: data = o.read(65536)