Exemplo n.º 1
0
    def add_channel(self, map=None):
        """See async.dispatcher

        This hook keeps track of opened channels.
        """
        DualModeChannel.add_channel(self, map)
        self.__class__.active_channels[self._fileno] = self
Exemplo n.º 2
0
    def add_channel(self, map=None):
        """See async.dispatcher

        This hook keeps track of opened channels.
        """
        DualModeChannel.add_channel(self, map)
        self.__class__.active_channels[self._fileno] = self
Exemplo n.º 3
0
    def del_channel(self, map=None):
        """See async.dispatcher

        This hook keeps track of closed channels.
        """
        DualModeChannel.del_channel(self, map)
        ac = self.__class__.active_channels
        fd = self._fileno
        if fd in ac:
            del ac[fd]
Exemplo n.º 4
0
    def del_channel(self, map=None):
        """See async.dispatcher

        This hook keeps track of closed channels.
        """
        DualModeChannel.del_channel(self, map)
        ac = self.__class__.active_channels
        fd = self._fileno
        if fd in ac:
            del ac[fd]
Exemplo n.º 5
0
 def close(self):
     """Notifies the control channel when the data connection closes."""
     c = self.control_channel
     try:
         if c is not None and c.connected and not self.reported:
             self.reportDefault()
     finally:
         self.control_channel = None
         DualModeChannel.close(self)
         if c is not None:
             c.closedData()
Exemplo n.º 6
0
 def close(self):
     """Notifies the control channel when the data connection closes."""
     c = self.control_channel
     try:
         if c is not None and c.connected and not self.reported:
             self.reportDefault()
     finally:
         self.control_channel = None
         DualModeChannel.close(self)
         if c is not None:
             c.closedData()
    def test_channels_accept_iterables(self):
        # Channels accept iterables (they special-case strings).

        from zope.server.tests.test_serverbase import FakeSocket
        socket = FakeSocket()
        channel = DualModeChannel(socket, ('localhost', 42))

        written = channel.write(b"First")
        self.assertEqual(5, written)

        channel.flush()
        self.assertEqual(socket.data.decode('ascii'),
                         'First')

        written = channel.write([b"\n", b"Second", b"\n", b"Third"])
        self.assertEqual(13, written)

        channel.flush()
        self.assertEqual(socket.data.decode('ascii'),
                         "First\n"
                         "Second\n"
                         "Third")

        def count():
            yield b'\n1\n2\n3\n'
            yield b'I love to count. Ha ha ha.'

        written = channel.write(count())
        self.assertEqual(written, 33)

        channel.flush()
        self.assertEqual(socket.data.decode('ascii'),
                         "First\n"
                         "Second\n"
                         "Third\n"
                         "1\n"
                         "2\n"
                         "3\n"
                         "I love to count. Ha ha ha.")
    def test_handle_read_non_async(self):
        channel = DualModeChannel(None, None)

        channel.set_sync()
        # Does nothing, no side effects
        channel.handle_read()
Exemplo n.º 9
0
 def __init__(self, control_channel):
     self.control_channel = control_channel
     self.reported = False
     self.closed = False
     DualModeChannel.__init__(self, None, None, control_channel.adj)
 def __init__(self):
     DualModeChannel.__init__(self, None, None)
Exemplo n.º 11
0
 def __init__(self, server, conn, addr, adj=None):
     """See async.dispatcher"""
     DualModeChannel.__init__(self, conn, addr, adj)
     self.server = server
     self.last_activity = t = self.creation_time
     self.check_maintenance(t)
Exemplo n.º 12
0
    def test_handle_read_will_close(self):
        channel = DualModeChannel(None, None)

        channel.close_when_done()
        # Does nothing, no side effects
        channel.handle_read()
Exemplo n.º 13
0
    def test_handle_read_non_async(self):
        channel = DualModeChannel(None, None)

        channel.set_sync()
        # Does nothing, no side effects
        channel.handle_read()
Exemplo n.º 14
0
 def __init__(self, server, conn, addr, adj=None):
     """See async.dispatcher"""
     DualModeChannel.__init__(self, conn, addr, adj)
     self.server = server
     self.last_activity = t = self.creation_time
     self.check_maintenance(t)
    def test_handle_read_will_close(self):
        channel = DualModeChannel(None, None)

        channel.close_when_done()
        # Does nothing, no side effects
        channel.handle_read()
Exemplo n.º 16
0
 def __init__(self, control_channel):
     self.control_channel = control_channel
     self.reported = False
     self.closed = False
     DualModeChannel.__init__(self, None, None, control_channel.adj)
Exemplo n.º 17
0
    def test_channels_accept_iterables(self):
        # Channels accept iterables (they special-case strings).

        from zope.server.tests.test_serverbase import FakeSocket
        socket = FakeSocket()
        channel = DualModeChannel(socket, ('localhost', 42))

        written = channel.write(b"First")
        self.assertEqual(5, written)

        channel.flush()
        self.assertEqual(socket.data.decode('ascii'), 'First')

        written = channel.write([b"\n", b"Second", b"\n", b"Third"])
        self.assertEqual(13, written)

        channel.flush()
        self.assertEqual(socket.data.decode('ascii'), "First\n"
                         "Second\n"
                         "Third")

        def count():
            yield b'\n1\n2\n3\n'
            yield b'I love to count. Ha ha ha.'

        written = channel.write(count())
        self.assertEqual(written, 33)

        channel.flush()
        self.assertEqual(
            socket.data.decode('ascii'), "First\n"
            "Second\n"
            "Third\n"
            "1\n"
            "2\n"
            "3\n"
            "I love to count. Ha ha ha.")
Exemplo n.º 18
0
 def __init__(self):
     DualModeChannel.__init__(self, None, None)