diff options
Diffstat (limited to 'distutils2/command/bdist_wininst.py')
| -rw-r--r-- | distutils2/command/bdist_wininst.py | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/distutils2/command/bdist_wininst.py b/distutils2/command/bdist_wininst.py index ce06c1c..8de798e 100644 --- a/distutils2/command/bdist_wininst.py +++ b/distutils2/command/bdist_wininst.py @@ -2,7 +2,6 @@ import sys import os -import codecs from distutils2.command.cmd import Command from distutils2.errors import PackagingOptionError, PackagingPlatformError @@ -246,40 +245,33 @@ class bdist_wininst(Command): logger.info("creating %s", installer_name) if bitmap: - fp = open(bitmap, "rb") - try: + with open(bitmap, "rb") as fp: bitmapdata = fp.read() - finally: - fp.close() bitmaplen = len(bitmapdata) else: bitmaplen = 0 - file = open(installer_name, "wb") - try: + with open(installer_name, "wb") as file: file.write(self.get_exe_bytes()) if bitmap: file.write(bitmapdata) # Convert cfgdata from unicode to ascii, mbcs encoded - if isinstance(cfgdata, unicode): + if isinstance(cfgdata, str): cfgdata = cfgdata.encode("mbcs") # Append the pre-install script - cfgdata = cfgdata + "\0" + cfgdata = cfgdata + b"\0" if self.pre_install_script: # We need to normalize newlines, so we open in text mode and # convert back to bytes. "latin-1" simply avoids any possible # failures. - fp = codecs.open(self.pre_install_script, encoding="latin-1") - try: + with open(self.pre_install_script, encoding="latin-1") as fp: script_data = fp.read().encode("latin-1") - finally: - fp.close() - cfgdata = cfgdata + script_data + "\n\0" + cfgdata = cfgdata + script_data + b"\n\0" else: # empty pre-install script - cfgdata = cfgdata + "\0" + cfgdata = cfgdata + b"\0" file.write(cfgdata) # The 'magic number' 0x1234567B is used to make sure that the @@ -293,13 +285,8 @@ class bdist_wininst(Command): bitmaplen, # number of bytes in bitmap ) file.write(header) - fp = open(arcname, "rb") - try: + with open(arcname, "rb") as fp: file.write(fp.read()) - finally: - fp.close() - finally: - file.close() def get_installer_filename(self, fullname): # Factored out to allow overriding in subclasses @@ -354,9 +341,5 @@ class bdist_wininst(Command): sfix = '' filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix)) - fp = open(filename, "rb") - try: - content = fp.read() - finally: - fp.close() - return content + with open(filename, "rb") as fp: + return fp.read() |
