__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
Tests for the internal implementation details of L{twisted.internet.udp}.
"""
from __future__ import annotations

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: list[bytes | socket.error]) -> None:
        self.retvals = retvals
        self.connectedAddr: object | None = None

    def connect(self, addr: object) -> None:
        self.connectedAddr = addr

    def recvfrom(self, size: int) -> tuple[bytes, None]:
        """
        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) -> None:
        self.reads: list[bytes] = []

    def datagramReceived(self, data: bytes, addr: object) -> None:
        self.reads.append(data)


class ErrorsTests(unittest.SynchronousTestCase):
    """
    Error handling tests for C{udp.Port}.
    """

    def test_socketReadNormal(self) -> None:
        """
        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) -> None:
        """
        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  # type: ignore[method-assign]

        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) -> None:
        """
        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)  # type: ignore[method-assign]

        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) -> None:
        """
        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"])

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
fake_CAs Folder 0755
__init__.py File 112 B 0644
_posixifaces.py File 4.29 KB 0644
_win32ifaces.py File 3.88 KB 0644
connectionmixins.py File 19.71 KB 0644
fakeendpoint.py File 1.62 KB 0644
modulehelpers.py File 1.63 KB 0644
process_cli.py File 547 B 0644
process_connectionlost.py File 126 B 0644
process_gireactornocompat.py File 792 B 0644
process_helper.py File 1.22 KB 0644
reactormixins.py File 16.05 KB 0644
test_abstract.py File 2.15 KB 0644
test_address.py File 8.07 KB 0644
test_asyncioreactor.py File 9.7 KB 0644
test_base.py File 14.44 KB 0644
test_baseprocess.py File 2.53 KB 0644
test_cfreactor.py File 3.09 KB 0644
test_core.py File 10.86 KB 0644
test_default.py File 3.5 KB 0644
test_defer_await.py File 6.66 KB 0644
test_defer_yieldfrom.py File 4.79 KB 0644
test_endpoints.py File 147.25 KB 0644
test_epollreactor.py File 7.15 KB 0644
test_error.py File 1.08 KB 0644
test_fdset.py File 13.18 KB 0644
test_filedescriptor.py File 2.7 KB 0644
test_gireactor.py File 7.18 KB 0644
test_glibbase.py File 3.02 KB 0644
test_inlinecb.py File 11.21 KB 0644
test_inotify.py File 18.13 KB 0644
test_iocp.py File 7.52 KB 0644
test_kqueuereactor.py File 1.93 KB 0644
test_main.py File 1.32 KB 0644
test_newtls.py File 6.38 KB 0644
test_pollingfile.py File 1.28 KB 0644
test_posixbase.py File 11.56 KB 0644
test_posixprocess.py File 10.94 KB 0644
test_process.py File 44.6 KB 0644
test_protocol.py File 18.08 KB 0644
test_reactormixins.py File 1.93 KB 0644
test_resolver.py File 19.15 KB 0644
test_serialport.py File 1.94 KB 0644
test_sigchld.py File 3.25 KB 0644
test_socket.py File 9.22 KB 0644
test_stdio.py File 6.18 KB 0644
test_tcp.py File 105.7 KB 0644
test_testing.py File 16.49 KB 0644
test_threads.py File 7.94 KB 0644
test_time.py File 3.57 KB 0644
test_tls.py File 12.54 KB 0644
test_udp.py File 16.48 KB 0644
test_udp_internals.py File 4.98 KB 0644
test_unix.py File 34.04 KB 0644
test_win32events.py File 6.3 KB 0644
test_win32serialport.py File 5.18 KB 0644
Filemanager