changeset: 76052:42b29aea1c98 parent: 76050:c5cf48752d81 parent: 76051:273d7502ced1 user: Antoine Pitrou date: Sun Apr 01 17:25:49 2012 +0200 files: Lib/multiprocessing/connection.py Lib/test/test_multiprocessing.py Misc/NEWS description: Issue #14151: Raise a ValueError, not a NameError, when trying to create a multiprocessing Client or Listener with an AF_PIPE type address under non-Windows platforms. Patch by Popa Claudiu. diff -r c5cf48752d81 -r 42b29aea1c98 Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py Sun Apr 01 17:40:17 2012 +0300 +++ b/Lib/multiprocessing/connection.py Sun Apr 01 17:25:49 2012 +0200 @@ -104,6 +104,13 @@ else: raise ValueError('unrecognized family') +def _validate_family(family): + ''' + Checks if the family is valid for the current environment. + ''' + if sys.platform != 'win32' and family == 'AF_PIPE': + raise ValueError('Family %s is not recognized.' % family) + def address_type(address): ''' @@ -436,6 +443,7 @@ or default_family address = address or arbitrary_address(family) + _validate_family(family) if family == 'AF_PIPE': self._listener = PipeListener(address, backlog) else: @@ -473,6 +481,7 @@ Returns a connection to the address of a `Listener` ''' family = family or address_type(address) + _validate_family(family) if family == 'AF_PIPE': c = PipeClient(address) else: diff -r c5cf48752d81 -r 42b29aea1c98 Lib/test/test_multiprocessing.py --- a/Lib/test/test_multiprocessing.py Sun Apr 01 17:40:17 2012 +0300 +++ b/Lib/test/test_multiprocessing.py Sun Apr 01 17:25:49 2012 +0200 @@ -2638,8 +2638,20 @@ p.join() +# +# Issue 14151: Test invalid family on invalid environment +# + +class TestInvalidFamily(unittest.TestCase): + + @unittest.skipIf(WIN32, "skipped on Windows") + def test_invalid_family(self): + with self.assertRaises(ValueError): + multiprocessing.connection.Listener(r'\\.\test') + + testcases_other = [OtherTest, TestInvalidHandle, TestInitializers, - TestStdinBadfiledescriptor, TestWait] + TestStdinBadfiledescriptor, TestWait, TestInvalidFamily] # # diff -r c5cf48752d81 -r 42b29aea1c98 Misc/NEWS --- a/Misc/NEWS Sun Apr 01 17:40:17 2012 +0300 +++ b/Misc/NEWS Sun Apr 01 17:25:49 2012 +0200 @@ -40,6 +40,10 @@ Library ------- +- Issue #14151: Raise a ValueError, not a NameError, when trying to create + a multiprocessing Client or Listener with an AF_PIPE type address under + non-Windows platforms. Patch by Popa Claudiu. + - Issue #14300: Under Windows, sockets created using socket.dup() now allow overlapped I/O. Patch by sbt.

AltStyle によって変換されたページ (->オリジナル) /