diff -r adfec512fb32 Lib/test/test_posix.py --- a/Lib/test/test_posix.py Sun Jun 02 12:00:45 2013 -0700 +++ b/Lib/test/test_posix.py Mon Jun 03 15:14:06 2013 +0300 @@ -13,6 +13,7 @@ import platform import pwd import shutil +import socket import stat import tempfile import unittest @@ -54,6 +55,30 @@ posix_func() self.assertRaises(TypeError, posix_func, 1) + @unittest.skipUnless(hasattr(socket, 'sethostname'), + "test needs socket.sethostname()") + def test_uname_result(self): + # issue #18109 + # checking posix.uname_result for UnicodeDecodeError + # at invalid hostnames (by RFC952) + oldhn = socket.gethostname() + newhn = 'hât' + try: + socket.sethostname(newhn) + except OSError as e: + if e.errno == errno.EPERM: + self.skipTest("test should be run as root") + else: + raise + + try: + self.assertEqual(posix.uname().nodename, newhn) + except UnicodeDecodeError: # test failed, restore hostname + socket.sethostname(oldhn) + raise + + socket.sethostname(oldhn) + if hasattr(posix, 'getresuid'): def test_getresuid(self): user_ids = posix.getresuid() diff -r adfec512fb32 Misc/ACKS --- a/Misc/ACKS Sun Jun 02 12:00:45 2013 -0700 +++ b/Misc/ACKS Mon Jun 03 15:14:06 2013 +0300 @@ -66,6 +66,7 @@ Jeff Balogh Manuel Balsera Matt Bandy +Dmi Baranov Michael J. Barber Daniel Barclay Nicolas Bareil diff -r adfec512fb32 Modules/posixmodule.c --- a/Modules/posixmodule.c Sun Jun 02 12:00:45 2013 -0700 +++ b/Modules/posixmodule.c Mon Jun 03 15:14:06 2013 +0300 @@ -4257,7 +4257,7 @@ #define SET(i, field) \ { \ - PyObject *o = PyUnicode_DecodeASCII(field, strlen(field), NULL); \ + PyObject *o = PyUnicode_DecodeLocaleAndSize(field, strlen(field), NULL); \ if (!o) { \ Py_DECREF(value); \ return NULL; \