Skip to content

Commit 8b94b41

Browse files
authored
bpo-28167: Remove platform.linux_distribution (GH-6871)
* test_ssl: Remove skip_if_broken_ubuntu_ssl We no longer support OpenSSL 0.9.8.15.15. * bpo-28167: Remove platform.linux_distribution
1 parent 93f9a8a commit 8b94b41

File tree

5 files changed

+13
-290
lines changed

5 files changed

+13
-290
lines changed

Doc/library/platform.rst

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -243,33 +243,6 @@ Mac OS Platform
243243
Unix Platforms
244244
--------------
245245

246-
247-
.. function:: dist(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...))
248-
249-
This is another name for :func:`linux_distribution`.
250-
251-
.. deprecated-removed:: 3.5 3.8
252-
See alternative like the `distro <https://pypi.org/project/distro>`_ package.
253-
254-
.. function:: linux_distribution(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...), full_distribution_name=1)
255-
256-
Tries to determine the name of the Linux OS distribution name.
257-
258-
``supported_dists`` may be given to define the set of Linux distributions to
259-
look for. It defaults to a list of currently supported Linux distributions
260-
identified by their release file name.
261-
262-
If ``full_distribution_name`` is true (default), the full distribution read
263-
from the OS is returned. Otherwise the short name taken from
264-
``supported_dists`` is used.
265-
266-
Returns a tuple ``(distname,version,id)`` which defaults to the args given as
267-
parameters. ``id`` is the item in parentheses after the version number. It
268-
is usually the version codename.
269-
270-
.. deprecated-removed:: 3.5 3.8
271-
See alternative like the `distro <https://pypi.org/project/distro>`_ package.
272-
273246
.. function:: libc_ver(executable=sys.executable, lib='', version='', chunksize=2048)
274247

275248
Tries to determine the libc version against which the file executable (defaults

Lib/platform.py

Lines changed: 5 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@
132132
# Standard Unix uses /dev/null
133133
DEV_NULL = '/dev/null'
134134

135-
# Directory to search for configuration information on Unix.
136-
# Constant used by test_platform to test linux_distribution().
137-
_UNIXCONFDIR = '/etc'
138-
139135
### Platform specific APIs
140136

141137
_libc_search = re.compile(b'(__libc_init)'
@@ -249,138 +245,6 @@ def _dist_try_harder(distname, version, id):
249245

250246
return distname, version, id
251247

252-
_release_filename = re.compile(r'(\w+)[-_](release|version)', re.ASCII)
253-
_lsb_release_version = re.compile(r'(.+)'
254-
r' release '
255-
r'([\d.]+)'
256-
r'[^(]*(?:\((.+)\))?', re.ASCII)
257-
_release_version = re.compile(r'([^0-9]+)'
258-
r'(?: release )?'
259-
r'([\d.]+)'
260-
r'[^(]*(?:\((.+)\))?', re.ASCII)
261-
262-
# See also http://www.novell.com/coolsolutions/feature/11251.html
263-
# and http://linuxmafia.com/faq/Admin/release-files.html
264-
# and http://data.linux-ntfs.org/rpm/whichrpm
265-
# and http://www.die.net/doc/linux/man/man1/lsb_release.1.html
266-
267-
_supported_dists = (
268-
'SuSE', 'debian', 'fedora', 'redhat', 'centos',
269-
'mandrake', 'mandriva', 'rocks', 'slackware', 'yellowdog', 'gentoo',
270-
'UnitedLinux', 'turbolinux', 'arch', 'mageia')
271-
272-
def _parse_release_file(firstline):
273-
274-
# Default to empty 'version' and 'id' strings. Both defaults are used
275-
# when 'firstline' is empty. 'id' defaults to empty when an id can not
276-
# be deduced.
277-
version = ''
278-
id = ''
279-
280-
# Parse the first line
281-
m = _lsb_release_version.match(firstline)
282-
if m is not None:
283-
# LSB format: "distro release x.x (codename)"
284-
return tuple(m.groups())
285-
286-
# Pre-LSB format: "distro x.x (codename)"
287-
m = _release_version.match(firstline)
288-
if m is not None:
289-
return tuple(m.groups())
290-
291-
# Unknown format... take the first two words
292-
l = firstline.strip().split()
293-
if l:
294-
version = l[0]
295-
if len(l) > 1:
296-
id = l[1]
297-
return '', version, id
298-
299-
def linux_distribution(distname='', version='', id='',
300-
301-
supported_dists=_supported_dists,
302-
full_distribution_name=1):
303-
import warnings
304-
warnings.warn("dist() and linux_distribution() functions are deprecated "
305-
"in Python 3.5", DeprecationWarning, stacklevel=2)
306-
return _linux_distribution(distname, version, id, supported_dists,
307-
full_distribution_name)
308-
309-
def _linux_distribution(distname, version, id, supported_dists,
310-
full_distribution_name):
311-
312-
""" Tries to determine the name of the Linux OS distribution name.
313-
314-
The function first looks for a distribution release file in
315-
/etc and then reverts to _dist_try_harder() in case no
316-
suitable files are found.
317-
318-
supported_dists may be given to define the set of Linux
319-
distributions to look for. It defaults to a list of currently
320-
supported Linux distributions identified by their release file
321-
name.
322-
323-
If full_distribution_name is true (default), the full
324-
distribution read from the OS is returned. Otherwise the short
325-
name taken from supported_dists is used.
326-
327-
Returns a tuple (distname, version, id) which default to the
328-
args given as parameters.
329-
330-
"""
331-
try:
332-
etc = os.listdir(_UNIXCONFDIR)
333-
except OSError:
334-
# Probably not a Unix system
335-
return distname, version, id
336-
etc.sort()
337-
for file in etc:
338-
m = _release_filename.match(file)
339-
if m is not None:
340-
_distname, dummy = m.groups()
341-
if _distname in supported_dists:
342-
distname = _distname
343-
break
344-
else:
345-
return _dist_try_harder(distname, version, id)
346-
347-
# Read the first line
348-
with open(os.path.join(_UNIXCONFDIR, file), 'r',
349-
encoding='utf-8', errors='surrogateescape') as f:
350-
firstline = f.readline()
351-
_distname, _version, _id = _parse_release_file(firstline)
352-
353-
if _distname and full_distribution_name:
354-
distname = _distname
355-
if _version:
356-
version = _version
357-
if _id:
358-
id = _id
359-
return distname, version, id
360-
361-
# To maintain backwards compatibility:
362-
363-
def dist(distname='', version='', id='',
364-
365-
supported_dists=_supported_dists):
366-
367-
""" Tries to determine the name of the Linux OS distribution name.
368-
369-
The function first looks for a distribution release file in
370-
/etc and then reverts to _dist_try_harder() in case no
371-
suitable files are found.
372-
373-
Returns a tuple (distname, version, id) which default to the
374-
args given as parameters.
375-
376-
"""
377-
import warnings
378-
warnings.warn("dist() and linux_distribution() functions are deprecated "
379-
"in Python 3.5", DeprecationWarning, stacklevel=2)
380-
return _linux_distribution(distname, version, id,
381-
supported_dists=supported_dists,
382-
full_distribution_name=0)
383-
384248
def popen(cmd, mode='r', bufsize=-1):
385249

386250
""" Portable popen() interface.
@@ -1338,26 +1202,11 @@ def platform(aliased=0, terse=0):
13381202
platform = _platform(system, release, version, csd)
13391203

13401204
elif system in ('Linux',):
1341-
# Linux based systems
1342-
with warnings.catch_warnings():
1343-
# see issue #1322 for more information
1344-
warnings.filterwarnings(
1345-
'ignore',
1346-
r'dist\(\) and linux_distribution\(\) '
1347-
'functions are deprecated .*',
1348-
DeprecationWarning,
1349-
)
1350-
distname, distversion, distid = dist('')
1351-
if distname and not terse:
1352-
platform = _platform(system, release, machine, processor,
1353-
'with',
1354-
distname, distversion, distid)
1355-
else:
1356-
# If the distribution name is unknown check for libc vs. glibc
1357-
libcname, libcversion = libc_ver(sys.executable)
1358-
platform = _platform(system, release, machine, processor,
1359-
'with',
1360-
libcname+libcversion)
1205+
# check for libc vs. glibc
1206+
libcname, libcversion = libc_ver(sys.executable)
1207+
platform = _platform(system, release, machine, processor,
1208+
'with',
1209+
libcname+libcversion)
13611210
elif system == 'Java':
13621211
# Java platforms
13631212
r, v, vminfo, (os_name, os_version, os_arch) = java_ver()

Lib/test/test_platform.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,6 @@ def test_mac_ver_with_fork(self):
259259
self.assertEqual(cpid, pid)
260260
self.assertEqual(sts, 0)
261261

262-
def test_dist(self):
263-
with warnings.catch_warnings():
264-
warnings.filterwarnings(
265-
'ignore',
266-
r'dist\(\) and linux_distribution\(\) '
267-
'functions are deprecated .*',
268-
PendingDeprecationWarning,
269-
)
270-
res = platform.dist()
271-
272262
def test_libc_ver(self):
273263
import os
274264
if os.path.isdir(sys.executable) and \
@@ -279,23 +269,6 @@ def test_libc_ver(self):
279269
executable = sys.executable
280270
res = platform.libc_ver(executable)
281271

282-
def test_parse_release_file(self):
283-
284-
for input, output in (
285-
# Examples of release file contents:
286-
('SuSE Linux 9.3 (x86-64)', ('SuSE Linux ', '9.3', 'x86-64')),
287-
('SUSE LINUX 10.1 (X86-64)', ('SUSE LINUX ', '10.1', 'X86-64')),
288-
('SUSE LINUX 10.1 (i586)', ('SUSE LINUX ', '10.1', 'i586')),
289-
('Fedora Core release 5 (Bordeaux)', ('Fedora Core', '5', 'Bordeaux')),
290-
('Red Hat Linux release 8.0 (Psyche)', ('Red Hat Linux', '8.0', 'Psyche')),
291-
('Red Hat Linux release 9 (Shrike)', ('Red Hat Linux', '9', 'Shrike')),
292-
('Red Hat Enterprise Linux release 4 (Nahant)', ('Red Hat Enterprise Linux', '4', 'Nahant')),
293-
('CentOS release 4', ('CentOS', '4', None)),
294-
('Rocks release 4.2.1 (Cydonia)', ('Rocks', '4.2.1', 'Cydonia')),
295-
('', ('', '', '')), # If there's nothing there.
296-
):
297-
self.assertEqual(platform._parse_release_file(input), output)
298-
299272
def test_popen(self):
300273
mswindows = (sys.platform == "win32")
301274

@@ -328,43 +301,5 @@ def test_popen(self):
328301
returncode = ret >> 8
329302
self.assertEqual(returncode, len(data))
330303

331-
def test_linux_distribution_encoding(self):
332-
# Issue #17429
333-
with tempfile.TemporaryDirectory() as tempdir:
334-
filename = os.path.join(tempdir, 'fedora-release')
335-
with open(filename, 'w', encoding='utf-8') as f:
336-
f.write('Fedora release 19 (Schr\xf6dinger\u2019s Cat)\n')
337-
338-
with mock.patch('platform._UNIXCONFDIR', tempdir):
339-
with warnings.catch_warnings():
340-
warnings.filterwarnings(
341-
'ignore',
342-
r'dist\(\) and linux_distribution\(\) '
343-
'functions are deprecated .*',
344-
PendingDeprecationWarning,
345-
)
346-
distname, version, distid = platform.linux_distribution()
347-
348-
self.assertEqual(distname, 'Fedora')
349-
self.assertEqual(version, '19')
350-
self.assertEqual(distid, 'Schr\xf6dinger\u2019s Cat')
351-
352-
353-
class DeprecationTest(unittest.TestCase):
354-
355-
def test_dist_deprecation(self):
356-
with self.assertWarns(DeprecationWarning) as cm:
357-
platform.dist()
358-
self.assertEqual(str(cm.warning),
359-
'dist() and linux_distribution() functions are '
360-
'deprecated in Python 3.5')
361-
362-
def test_linux_distribution_deprecation(self):
363-
with self.assertWarns(DeprecationWarning) as cm:
364-
platform.linux_distribution()
365-
self.assertEqual(str(cm.warning),
366-
'dist() and linux_distribution() functions are '
367-
'deprecated in Python 3.5')
368-
369304
if __name__ == '__main__':
370305
unittest.main()

0 commit comments

Comments
 (0)