]> granicus.if.org Git - handbrake/commitdiff
make: More Python 3 compatibility fixes.
authorBradley Sepos <bradley@bradleysepos.com>
Tue, 26 Feb 2019 21:25:58 +0000 (16:25 -0500)
committerBradley Sepos <bradley@bradleysepos.com>
Tue, 26 Feb 2019 21:30:12 +0000 (16:30 -0500)
make/df-fetch.py
make/df-verify.py

index cfea5256c0a7ca5c90399892dfb16a5aa68c7539..efdd6e0547f805acd425464da068734a7d1f3571 100644 (file)
@@ -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:
index eb29f4bc91e98c79955166eb2790db2f28a6db2a..f370d930a3f00e82dc88130f6d9081b03f9aabc5 100644 (file)
@@ -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)