[Python-checkins] bpo-27903: Fix ResourceWarning in platform.dist() (GH-10792)
Victor Stinner
webhook-mailer at python.org
Thu Nov 29 06:31:12 EST 2018
https://github.com/python/cpython/commit/7eeab87263b831adbe617a4af7ec5b5d9296962a
commit: 7eeab87263b831adbe617a4af7ec5b5d9296962a
branch: 3.7
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-11-29T12:31:08+01:00
summary:
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ä.
files:
A Misc/NEWS.d/next/Library/2018-11-29-12-14-04.bpo-27903.ia8xgT.rst
M Lib/platform.py
diff --git a/Lib/platform.py b/Lib/platform.py
index 4482f479bfde..0c6fc03efa9f 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -243,27 +243,29 @@ def _dist_try_harder(distname, version, id):
if os.path.exists('/var/adm/inst-log/info'):
# SuSE Linux stores distribution information in that file
distname = 'SuSE'
- for line in open('/var/adm/inst-log/info'):
- tv = line.split()
- if len(tv) == 2:
- tag, value = tv
- else:
- continue
- if tag == 'MIN_DIST_VERSION':
- version = value.strip()
- elif tag == 'DIST_IDENT':
- values = value.split('-')
- id = values[2]
+ with open('/var/adm/inst-log/info') as f:
+ for line in f:
+ tv = line.split()
+ if len(tv) == 2:
+ tag, value = tv
+ else:
+ continue
+ if tag == 'MIN_DIST_VERSION':
+ version = value.strip()
+ elif tag == 'DIST_IDENT':
+ values = value.split('-')
+ id = values[2]
return distname, version, id
if os.path.exists('/etc/.installed'):
# Caldera OpenLinux has some infos in that file (thanks to Colin Kong)
- for line in open('/etc/.installed'):
- pkg = line.split('-')
- if len(pkg) >= 2 and pkg[0] == 'OpenLinux':
- # XXX does Caldera support non Intel platforms ? If yes,
- # where can we find the needed id ?
- return 'OpenLinux', pkg[1], id
+ with open('/etc/.installed') as f:
+ for line in f:
+ pkg = line.split('-')
+ if len(pkg) >= 2 and pkg[0] == 'OpenLinux':
+ # XXX does Caldera support non Intel platforms ? If yes,
+ # where can we find the needed id ?
+ return 'OpenLinux', pkg[1], id
if os.path.isdir('/usr/lib/setup'):
# Check for slackware version tag file (thanks to Greg Andruk)
diff --git a/Misc/NEWS.d/next/Library/2018-11-29-12-14-04.bpo-27903.ia8xgT.rst b/Misc/NEWS.d/next/Library/2018-11-29-12-14-04.bpo-27903.ia8xgT.rst
new file mode 100644
index 000000000000..8cdf75bc10c9
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-11-29-12-14-04.bpo-27903.ia8xgT.rst
@@ -0,0 +1,2 @@
+Fix ``ResourceWarning`` in :func:`platform.dist` on SuSE and Caldera
+OpenLinux. Patch by Ville Skyttä.
More information about the Python-checkins
mailing list