Exemplo n.º 1
0
 def testDoubleProducer(self):
     fd = abstract.FileDescriptor()
     fd.connected = 1
     dp = DummyProducer()
     fd.registerProducer(dp, 0)
     self.assertEquals(dp.resumed, 1)
     self.assertRaises(RuntimeError, fd.registerProducer, DummyProducer(),
                       0)
Exemplo n.º 2
0
 def test_unconnectedFileDescriptor(self):
     """
     Verify that registering a producer when the connection has already
     been closed invokes its stopProducing() method.
     """
     fd = abstract.FileDescriptor()
     fd.disconnected = 1
     dp = DummyProducer()
     fd.registerProducer(dp, 0)
     self.assertEqual(dp.events, ['stop'])
Exemplo n.º 3
0
 def test_doubleProducer(self):
     """
     Verify that registering a non-streaming producer invokes its
     resumeProducing() method and that you can only register one producer
     at a time.
     """
     fd = abstract.FileDescriptor()
     fd.connected = 1
     dp = DummyProducer()
     fd.registerProducer(dp, 0)
     self.assertEqual(dp.events, ['resume'])
     self.assertRaises(RuntimeError, fd.registerProducer, DummyProducer(), 0)
Exemplo n.º 4
0
    def testSendingEmptyFile(self):
        fileSender = basic.FileSender()
        consumer = abstract.FileDescriptor()
        consumer.connected = 1
        emptyFile = BytesIO(b"")

        d = fileSender.beginFileTransfer(emptyFile, consumer, lambda x: x)

        # The producer will be immediately exhausted, and so immediately
        # unregistered
        self.assertIsNone(consumer.producer)

        # Which means the Deferred from FileSender should have been called
        self.assertTrue(d.called, "producer unregistered with deferred being called")
Exemplo n.º 5
0
    def testSendingEmptyFile(self):
        fileSender = basic.FileSender()
        consumer = abstract.FileDescriptor()
        consumer.connected = 1
        emptyFile = StringIO.StringIO('')

        d = fileSender.beginFileTransfer(emptyFile, consumer, lambda x: x)

        # The producer will be immediately exhausted, and so immediately
        # unregistered
        self.assertEqual(consumer.producer, None)

        # Which means the Deferred from FileSender should have been called
        self.failUnless(d.called, 
                        'producer unregistered with deferred being called')
Exemplo n.º 6
0
def configure(protocol, port, pipes, interface):
    remove_all()
    reactor.addSystemEventTrigger('after', 'shutdown', remove_all)

    # gets default (outward-facing) network interface (e.g. deciding which of
    # eth0, eth1, wlan0 is being used by the system to connect to the internet)
    if interface == "auto":
        interface = netifaces.gateways()['default'][netifaces.AF_INET][1]
    else:
        if interface not in netifaces.interfaces():
            raise ValueError("Given interface does not exist.", interface)

    add(protocol, port, interface)
    manager = libnetfilter_queue.Manager()

    manager.bind(UP_QUEUE, packet_handler(manager, pipes.up))
    manager.bind(DOWN_QUEUE, packet_handler(manager, pipes.down))

    reader = abstract.FileDescriptor()
    reader.doRead = manager.process
    reader.fileno = lambda: manager.fileno
    reactor.addReader(reader)
Exemplo n.º 7
0
 def testUnconnectedFileDescriptor(self):
     fd = abstract.FileDescriptor()
     fd.disconnected = 1
     dp = DummyProducer()
     fd.registerProducer(dp, 0)
     self.assertEquals(dp.stopped, 1)