OXIESEC PANEL
- Current Dir:
/
/
usr
/
lib
/
python3
/
dist-packages
/
twisted
/
internet
/
test
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
03/31/2022 06:22:38 AM
rwxr-xr-x
📄
__init__.py
112 bytes
09/08/2017 10:38:36 AM
rw-r--r--
📁
__pycache__
-
03/31/2022 06:22:39 AM
rwxr-xr-x
📄
_awaittests.py.3only
4.37 KB
09/08/2017 10:38:35 AM
rw-r--r--
📄
_posixifaces.py
4.58 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
_win32ifaces.py
3.79 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
_yieldfromtests.py.3only
4.17 KB
09/08/2017 10:38:35 AM
rw-r--r--
📄
connectionmixins.py
19.71 KB
09/08/2017 10:38:36 AM
rw-r--r--
📁
fake_CAs
-
03/31/2022 06:22:38 AM
rwxr-xr-x
📄
fakeendpoint.py
1.52 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
modulehelpers.py
1.69 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
process_cli.py
664 bytes
09/08/2017 10:38:36 AM
rw-r--r--
📄
process_connectionlost.py
119 bytes
09/08/2017 10:38:36 AM
rw-r--r--
📄
process_gireactornocompat.py
721 bytes
09/08/2017 10:38:36 AM
rw-r--r--
📄
process_helper.py
1.06 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
reactormixins.py
13.72 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_abstract.py
1.98 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_address.py
11.45 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_base.py
10.98 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_baseprocess.py
2.55 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_core.py
11 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_coroutines.py
1.67 KB
09/08/2017 10:38:35 AM
rw-r--r--
📄
test_default.py
3.46 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_endpoints.py
143.15 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_epollreactor.py
7.16 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_fdset.py
13.18 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_filedescriptor.py
2.74 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_gireactor.py
8.83 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_glibbase.py
2.23 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_inlinecb.py
4.55 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_inotify.py
16.29 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_iocp.py
5.05 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_kqueuereactor.py
1.87 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_main.py
1.4 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_newtls.py
6.54 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_pollingfile.py
1.25 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_posixbase.py
9.31 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_posixprocess.py
10.9 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_process.py
31.29 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_protocol.py
18.29 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_resolver.py
19.58 KB
09/08/2017 10:38:35 AM
rw-r--r--
📄
test_serialport.py
1.9 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_sigchld.py
3.84 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_socket.py
9.11 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_stdio.py
6.3 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_tcp.py
83 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_threads.py
7.93 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_time.py
3.63 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_tls.py
12.32 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_udp.py
16.74 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_udp_internals.py
4.79 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_unix.py
33.94 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_win32events.py
6.35 KB
09/08/2017 10:38:36 AM
rw-r--r--
📄
test_win32serialport.py
5.16 KB
09/08/2017 10:38:35 AM
rw-r--r--
Editing: test_udp_internals.py
Close
# Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Tests for the internal implementation details of L{twisted.internet.udp}. """ from __future__ import division, absolute_import import socket from twisted.trial import unittest from twisted.internet.protocol import DatagramProtocol from twisted.internet import udp from twisted.python.runtime import platformType if platformType == 'win32': from errno import WSAEWOULDBLOCK as EWOULDBLOCK else: from errno import EWOULDBLOCK class StringUDPSocket(object): """ 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"])