mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	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.
This commit is contained in:
		
						commit
						93bba8fb8a
					
				
					 3 changed files with 26 additions and 1 deletions
				
			
		| 
						 | 
					@ -104,6 +104,13 @@ def arbitrary_address(family):
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        raise ValueError('unrecognized family')
 | 
					        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):
 | 
					def address_type(address):
 | 
				
			||||||
    '''
 | 
					    '''
 | 
				
			||||||
| 
						 | 
					@ -436,6 +443,7 @@ def __init__(self, address=None, family=None, backlog=1, authkey=None):
 | 
				
			||||||
                 or default_family
 | 
					                 or default_family
 | 
				
			||||||
        address = address or arbitrary_address(family)
 | 
					        address = address or arbitrary_address(family)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        _validate_family(family)
 | 
				
			||||||
        if family == 'AF_PIPE':
 | 
					        if family == 'AF_PIPE':
 | 
				
			||||||
            self._listener = PipeListener(address, backlog)
 | 
					            self._listener = PipeListener(address, backlog)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
| 
						 | 
					@ -473,6 +481,7 @@ def Client(address, family=None, authkey=None):
 | 
				
			||||||
    Returns a connection to the address of a `Listener`
 | 
					    Returns a connection to the address of a `Listener`
 | 
				
			||||||
    '''
 | 
					    '''
 | 
				
			||||||
    family = family or address_type(address)
 | 
					    family = family or address_type(address)
 | 
				
			||||||
 | 
					    _validate_family(family)
 | 
				
			||||||
    if family == 'AF_PIPE':
 | 
					    if family == 'AF_PIPE':
 | 
				
			||||||
        c = PipeClient(address)
 | 
					        c = PipeClient(address)
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2638,8 +2638,20 @@ def test_wait_integer(self):
 | 
				
			||||||
        p.join()
 | 
					        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,
 | 
					testcases_other = [OtherTest, TestInvalidHandle, TestInitializers,
 | 
				
			||||||
                   TestStdinBadfiledescriptor, TestWait]
 | 
					                   TestStdinBadfiledescriptor, TestWait, TestInvalidFamily]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,6 +40,10 @@ Core and Builtins
 | 
				
			||||||
Library
 | 
					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
 | 
					- Issue #14300: Under Windows, sockets created using socket.dup() now allow
 | 
				
			||||||
  overlapped I/O.  Patch by sbt.
 | 
					  overlapped I/O.  Patch by sbt.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue