/usr/lib/python3/dist-packages/twisted/internet/test
NameSizeModeActions
fake_CAs/-0755rm
__pycache__/-0755rm
connectionmixins.py201840644editdlrm
fakeendpoint.py16630644editdlrm
modulehelpers.py16720644editdlrm
process_cli.py5470644editdlrm
process_connectionlost.py1260644editdlrm
process_gireactornocompat.py8160644editdlrm
process_helper.py12820644editdlrm
reactormixins.py146090644editdlrm
test_abstract.py19760644editdlrm
test_address.py82660644editdlrm
test_asyncioreactor.py93270644editdlrm
test_base.py136840644editdlrm
test_baseprocess.py25880644editdlrm
test_core.py111250644editdlrm
test_default.py34190644editdlrm
test_defer_await.py65140644editdlrm
test_defer_yieldfrom.py48480644editdlrm
test_endpoints.py1487200644editdlrm
test_epollreactor.py73220644editdlrm
test_error.py10900644editdlrm
test_fdset.py134970644editdlrm
test_filedescriptor.py27610644editdlrm
test_gireactor.py65160644editdlrm
test_glibbase.py22170644editdlrm
test_inlinecb.py114820644editdlrm
test_inotify.py185620644editdlrm
test_iocp.py77000644editdlrm
test_kqueuereactor.py18530644editdlrm
test_main.py13310644editdlrm
test_newtls.py65320644editdlrm
test_pollingfile.py12970644editdlrm
test_posixbase.py97180644editdlrm
test_posixprocess.py112030644editdlrm
test_process.py367320644editdlrm
test_protocol.py185200644editdlrm
test_resolver.py196100644editdlrm
test_serialport.py19880644editdlrm
test_sigchld.py39220644editdlrm
test_socket.py94430644editdlrm
test_stdio.py65970644editdlrm
test_tcp.py1066210644editdlrm
test_testing.py162390644editdlrm
test_threads.py87340644editdlrm
test_time.py37580644editdlrm
test_tls.py133490644editdlrm
test_udp.py168810644editdlrm
test_udp_internals.py48370644editdlrm
test_unix.py348540644editdlrm
test_win32events.py64730644editdlrm
test_win32serialport.py53300644editdlrm
_posixifaces.py43910644editdlrm
_win32ifaces.py39750644editdlrm
__init__.py1120644editdlrm
Edit: /usr/lib/python3/dist-packages/twisted/internet/test/test_udp_internals.py (4837B)
# Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Tests for the internal implementation details of L{twisted.internet.udp}. """ import socket from twisted.internet import udp from twisted.internet.protocol import DatagramProtocol from twisted.python.runtime import platformType from twisted.trial import unittest if platformType == "win32": from errno import WSAEWOULDBLOCK as EWOULDBLOCK # type: ignore[attr-defined] else: from errno import EWOULDBLOCK class StringUDPSocket: """ A fake UDP socket object, which returns a fixed sequence of strings and/or socket errors. Useful for testing. @ivar retvals: A C{list} containing either strings or C{socket.error}s. @ivar connectedAddr: The address the socket is connected to. """ def __init__(self, retvals): self.retvals = retvals self.connectedAddr = None def connect(self, addr): self.connectedAddr = addr def recvfrom(self, size): """ Return (or raise) the next value from C{self.retvals}. """ ret = self.retvals.pop(0) if isinstance(ret, socket.error): raise ret return ret, None class KeepReads(DatagramProtocol): """ Accumulate reads in a list. """ def __init__(self): self.reads = [] def datagramReceived(self, data, addr): self.reads.append(data) class ErrorsTests(unittest.SynchronousTestCase): """ Error handling tests for C{udp.Port}. """ def test_socketReadNormal(self): """ Socket reads with some good data followed by a socket error which can be ignored causes reading to stop, and no log messages to be logged. """ # Add a fake error to the list of ignorables: udp._sockErrReadIgnore.append(-7000) self.addCleanup(udp._sockErrReadIgnore.remove, -7000) protocol = KeepReads() port = udp.Port(None, protocol) # Normal result, no errors port.socket = StringUDPSocket( [b"result", b"123", socket.error(-7000), b"456", socket.error(-7000)] ) port.doRead() # Read stops on error: self.assertEqual(protocol.reads, [b"result", b"123"]) port.doRead() self.assertEqual(protocol.reads, [b"result", b"123", b"456"]) def test_readImmediateError(self): """ If the socket is unconnected, socket reads with an immediate connection refusal are ignored, and reading stops. The protocol's C{connectionRefused} method is not called. """ # Add a fake error to the list of those that count as connection # refused: udp._sockErrReadRefuse.append(-6000) self.addCleanup(udp._sockErrReadRefuse.remove, -6000) protocol = KeepReads() # Fail if connectionRefused is called: protocol.connectionRefused = lambda: 1 / 0 port = udp.Port(None, protocol) # Try an immediate "connection refused" port.socket = StringUDPSocket( [b"a", socket.error(-6000), b"b", socket.error(EWOULDBLOCK)] ) port.doRead() # Read stops on error: self.assertEqual(protocol.reads, [b"a"]) # Read again: port.doRead() self.assertEqual(protocol.reads, [b"a", b"b"]) def test_connectedReadImmediateError(self): """ If the socket connected, socket reads with an immediate connection refusal are ignored, and reading stops. The protocol's C{connectionRefused} method is called. """ # Add a fake error to the list of those that count as connection # refused: udp._sockErrReadRefuse.append(-6000) self.addCleanup(udp._sockErrReadRefuse.remove, -6000) protocol = KeepReads() refused = [] protocol.connectionRefused = lambda: refused.append(True) port = udp.Port(None, protocol) port.socket = StringUDPSocket( [b"a", socket.error(-6000), b"b", socket.error(EWOULDBLOCK)] ) port.connect("127.0.0.1", 9999) # Read stops on error: port.doRead() self.assertEqual(protocol.reads, [b"a"]) self.assertEqual(refused, [True]) # Read again: port.doRead() self.assertEqual(protocol.reads, [b"a", b"b"]) self.assertEqual(refused, [True]) def test_readUnknownError(self): """ Socket reads with an unknown socket error are raised. """ protocol = KeepReads() port = udp.Port(None, protocol) # Some good data, followed by an unknown error port.socket = StringUDPSocket([b"good", socket.error(-1337)]) self.assertRaises(socket.error, port.doRead) self.assertEqual(protocol.reads, [b"good"])