]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #14151: Raise a ValueError, not a NameError, when trying to create
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 1 Apr 2012 15:19:09 +0000 (17:19 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 1 Apr 2012 15:19:09 +0000 (17:19 +0200)
a multiprocessing Client or Listener with an AF_PIPE type address under
non-Windows platforms.  Patch by Popa Claudiu.

Lib/multiprocessing/connection.py
Lib/test/test_multiprocessing.py
Misc/NEWS

index df00f1d90664ce3a4cf9d55d9f2bf4d63e6737c4..fa6f7b39019020e4b31682863af7a7cde01c86db 100644 (file)
@@ -94,6 +94,13 @@ def arbitrary_address(family):
     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):
     '''
@@ -126,6 +133,7 @@ class Listener(object):
                  or default_family
         address = address or arbitrary_address(family)
 
+        _validate_family(family)
         if family == 'AF_PIPE':
             self._listener = PipeListener(address, backlog)
         else:
@@ -163,6 +171,7 @@ def Client(address, family=None, authkey=None):
     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:
index 8edb4208640cb065a8cc366963c9c1835a40baeb..8de7a8d1d0c3eebfb3df8b1bda5a49477651da77 100644 (file)
@@ -2319,8 +2319,20 @@ class TestStdinBadfiledescriptor(unittest.TestCase):
         flike.flush()
         assert sio.getvalue() == 'foo'
 
+
+#
+# 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]
+                   TestStdinBadfiledescriptor, TestInvalidFamily]
 
 #
 #
index 4bf3a916b6ba74625af71712b0c75bcafff3bcc5..2fa911e4bbaaca6d3a5ad4cba9fb78da9288d972 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,10 @@ Core and Builtins
 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 #13872: socket.detach() now marks the socket closed (as mirrored
   in the socket repr()).  Patch by Matt Joiner.