Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/distutils/command/bdist_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ def _make_spec_file(self):
'',
'%' + rpm_opt,])
if val:
spec_file.extend(open(val, 'r').read().split('\n'))
with open(val) as f:
spec_file.extend(f.read().split('\n'))
else:
spec_file.append(default)

Expand Down
74 changes: 38 additions & 36 deletions Lib/distutils/command/bdist_wininst.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,47 +247,49 @@ def create_exe(self, arcname, fullname, bitmap=None):
self.announce("creating %s" % installer_name)

if bitmap:
bitmapdata = open(bitmap, "rb").read()
with open(bitmap, "rb") as f:
bitmapdata = f.read()
bitmaplen = len(bitmapdata)
else:
bitmaplen = 0

file = open(installer_name, "wb")
file.write(self.get_exe_bytes())
if bitmap:
file.write(bitmapdata)

# Convert cfgdata from unicode to ascii, mbcs encoded
if isinstance(cfgdata, str):
cfgdata = cfgdata.encode("mbcs")

# Append the pre-install script
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.
with open(self.pre_install_script, "r",
encoding="latin-1") as script:
script_data = script.read().encode("latin-1")
cfgdata = cfgdata + script_data + b"\n\0"
else:
# empty pre-install script
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, str):
cfgdata = cfgdata.encode("mbcs")

# Append the pre-install script
cfgdata = cfgdata + b"\0"
file.write(cfgdata)

# The 'magic number' 0x1234567B is used to make sure that the
# binary layout of 'cfgdata' is what the wininst.exe binary
# expects. If the layout changes, increment that number, make
# the corresponding changes to the wininst.exe sources, and
# recompile them.
header = struct.pack("<iii",
0x1234567B, # tag
len(cfgdata), # length
bitmaplen, # number of bytes in bitmap
)
file.write(header)
file.write(open(arcname, "rb").read())
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.
with open(self.pre_install_script, "r",
encoding="latin-1") as script:
script_data = script.read().encode("latin-1")
Comment thread
methane marked this conversation as resolved.
cfgdata = cfgdata + script_data + b"\n\0"
else:
# empty pre-install script
cfgdata = cfgdata + b"\0"
file.write(cfgdata)

# The 'magic number' 0x1234567B is used to make sure that the
# binary layout of 'cfgdata' is what the wininst.exe binary
# expects. If the layout changes, increment that number, make
# the corresponding changes to the wininst.exe sources, and
# recompile them.
header = struct.pack("<iii",
0x1234567B, # tag
len(cfgdata), # length
bitmaplen, # number of bytes in bitmap
)
file.write(header)
with open(arcname, "rb") as f:
file.write(f.read())

def get_installer_filename(self, fullname):
# Factored out to allow overriding in subclasses
Expand Down
5 changes: 3 additions & 2 deletions Lib/distutils/command/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ def upload_file(self, command, pyversion, filename):
data['comment'] = ''

if self.sign:
data['gpg_signature'] = (os.path.basename(filename) + ".asc",
open(filename+".asc", "rb").read())
with open(filename + ".asc", "rb") as f:
data['gpg_signature'] = (os.path.basename(filename) + ".asc",
f.read())

# set up the authentication
user_pass = (self.username + ":" + self.password).encode('ascii')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix potential resource warnings in distutils. Patch by Mickaël Schoentgen.