Skip to content

Commit 7eeab87

Browse files
authored
bpo-27903: Fix ResourceWarning in platform.dist() (GH-10792)
Fix ResourceWarning in platform.dist() and platform.linux_distribution() on SuSE and Caldera OpenLinux. Patch by Ville Skyttä.
1 parent e754159 commit 7eeab87

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

Lib/platform.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,27 +243,29 @@ def _dist_try_harder(distname, version, id):
243243
if os.path.exists('/var/adm/inst-log/info'):
244244
# SuSE Linux stores distribution information in that file
245245
distname = 'SuSE'
246-
for line in open('/var/adm/inst-log/info'):
247-
tv = line.split()
248-
if len(tv) == 2:
249-
tag, value = tv
250-
else:
251-
continue
252-
if tag == 'MIN_DIST_VERSION':
253-
version = value.strip()
254-
elif tag == 'DIST_IDENT':
255-
values = value.split('-')
256-
id = values[2]
246+
with open('/var/adm/inst-log/info') as f:
247+
for line in f:
248+
tv = line.split()
249+
if len(tv) == 2:
250+
tag, value = tv
251+
else:
252+
continue
253+
if tag == 'MIN_DIST_VERSION':
254+
version = value.strip()
255+
elif tag == 'DIST_IDENT':
256+
values = value.split('-')
257+
id = values[2]
257258
return distname, version, id
258259

259260
if os.path.exists('/etc/.installed'):
260261
# Caldera OpenLinux has some infos in that file (thanks to Colin Kong)
261-
for line in open('/etc/.installed'):
262-
pkg = line.split('-')
263-
if len(pkg) >= 2 and pkg[0] == 'OpenLinux':
264-
# XXX does Caldera support non Intel platforms ? If yes,
265-
# where can we find the needed id ?
266-
return 'OpenLinux', pkg[1], id
262+
with open('/etc/.installed') as f:
263+
for line in f:
264+
pkg = line.split('-')
265+
if len(pkg) >= 2 and pkg[0] == 'OpenLinux':
266+
# XXX does Caldera support non Intel platforms ? If yes,
267+
# where can we find the needed id ?
268+
return 'OpenLinux', pkg[1], id
267269

268270
if os.path.isdir('/usr/lib/setup'):
269271
# Check for slackware version tag file (thanks to Greg Andruk)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``ResourceWarning`` in :func:`platform.dist` on SuSE and Caldera
2+
OpenLinux. Patch by Ville Skyttä.

0 commit comments

Comments
 (0)