mirror of
https://github.com/python/cpython.git
synced 2025-09-30 04:15:43 +00:00
This commit is contained in:
parent
9d752aa5e6
commit
95b4da2be4
3 changed files with 43 additions and 7 deletions
|
@ -827,11 +827,26 @@ class SysLogHandler(logging.Handler):
|
||||||
self.unixsocket = False
|
self.unixsocket = False
|
||||||
if socktype is None:
|
if socktype is None:
|
||||||
socktype = socket.SOCK_DGRAM
|
socktype = socket.SOCK_DGRAM
|
||||||
self.socket = socket.socket(socket.AF_INET, socktype)
|
host, port = address
|
||||||
|
ress = socket.getaddrinfo(host, port, 0, socktype)
|
||||||
|
if not ress:
|
||||||
|
raise OSError("getaddrinfo returns an empty list")
|
||||||
|
for res in ress:
|
||||||
|
af, socktype, proto, _, sa = res
|
||||||
|
err = sock = None
|
||||||
|
try:
|
||||||
|
sock = socket.socket(af, socktype, proto)
|
||||||
if socktype == socket.SOCK_STREAM:
|
if socktype == socket.SOCK_STREAM:
|
||||||
self.socket.connect(address)
|
sock.connect(sa)
|
||||||
|
break
|
||||||
|
except OSError as exc:
|
||||||
|
err = exc
|
||||||
|
if sock is not None:
|
||||||
|
sock.close()
|
||||||
|
if err is not None:
|
||||||
|
raise err
|
||||||
|
self.socket = sock
|
||||||
self.socktype = socktype
|
self.socktype = socktype
|
||||||
self.formatter = None
|
|
||||||
|
|
||||||
def _connect_unixsocket(self, address):
|
def _connect_unixsocket(self, address):
|
||||||
use_socktype = self.socktype
|
use_socktype = self.socktype
|
||||||
|
|
|
@ -1663,7 +1663,7 @@ class SysLogHandlerTest(BaseTest):
|
||||||
server.ready.wait()
|
server.ready.wait()
|
||||||
hcls = logging.handlers.SysLogHandler
|
hcls = logging.handlers.SysLogHandler
|
||||||
if isinstance(server.server_address, tuple):
|
if isinstance(server.server_address, tuple):
|
||||||
self.sl_hdlr = hcls(('localhost', server.port))
|
self.sl_hdlr = hcls((server.server_address[0], server.port))
|
||||||
else:
|
else:
|
||||||
self.sl_hdlr = hcls(server.server_address)
|
self.sl_hdlr = hcls(server.server_address)
|
||||||
self.log_output = ''
|
self.log_output = ''
|
||||||
|
@ -1723,6 +1723,24 @@ class UnixSysLogHandlerTest(SysLogHandlerTest):
|
||||||
SysLogHandlerTest.tearDown(self)
|
SysLogHandlerTest.tearDown(self)
|
||||||
support.unlink(self.address)
|
support.unlink(self.address)
|
||||||
|
|
||||||
|
@unittest.skipUnless(support.IPV6_ENABLED,
|
||||||
|
'IPv6 support required for this test.')
|
||||||
|
@unittest.skipUnless(threading, 'Threading required for this test.')
|
||||||
|
class IPv6SysLogHandlerTest(SysLogHandlerTest):
|
||||||
|
|
||||||
|
"""Test for SysLogHandler with IPv6 host."""
|
||||||
|
|
||||||
|
server_class = TestUDPServer
|
||||||
|
address = ('::1', 0)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.server_class.address_family = socket.AF_INET6
|
||||||
|
super(IPv6SysLogHandlerTest, self).setUp()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.server_class.address_family = socket.AF_INET
|
||||||
|
super(IPv6SysLogHandlerTest, self).tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(threading, 'Threading required for this test.')
|
@unittest.skipUnless(threading, 'Threading required for this test.')
|
||||||
class HTTPHandlerTest(BaseTest):
|
class HTTPHandlerTest(BaseTest):
|
||||||
"""Test for HTTPHandler."""
|
"""Test for HTTPHandler."""
|
||||||
|
@ -4378,7 +4396,7 @@ def test_main():
|
||||||
QueueHandlerTest, ShutdownTest, ModuleLevelMiscTest, BasicConfigTest,
|
QueueHandlerTest, ShutdownTest, ModuleLevelMiscTest, BasicConfigTest,
|
||||||
LoggerAdapterTest, LoggerTest, SMTPHandlerTest, FileHandlerTest,
|
LoggerAdapterTest, LoggerTest, SMTPHandlerTest, FileHandlerTest,
|
||||||
RotatingFileHandlerTest, LastResortTest, LogRecordTest,
|
RotatingFileHandlerTest, LastResortTest, LogRecordTest,
|
||||||
ExceptionTest, SysLogHandlerTest, HTTPHandlerTest,
|
ExceptionTest, SysLogHandlerTest, IPv6SysLogHandlerTest, HTTPHandlerTest,
|
||||||
NTEventLogHandlerTest, TimedRotatingFileHandlerTest,
|
NTEventLogHandlerTest, TimedRotatingFileHandlerTest,
|
||||||
UnixSocketHandlerTest, UnixDatagramHandlerTest, UnixSysLogHandlerTest,
|
UnixSocketHandlerTest, UnixDatagramHandlerTest, UnixSysLogHandlerTest,
|
||||||
MiscTestCase
|
MiscTestCase
|
||||||
|
|
|
@ -45,6 +45,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- bpo-30378: Fix the problem that logging.handlers.SysLogHandler cannot
|
||||||
|
handle IPv6 addresses.
|
||||||
|
|
||||||
- bpo-29960: Preserve generator state when _random.Random.setstate()
|
- bpo-29960: Preserve generator state when _random.Random.setstate()
|
||||||
raises an exception. Patch by Bryan Olson.
|
raises an exception. Patch by Bryan Olson.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue