Python twisted.internet.reactor 模块,addReader() 实例源码

我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用twisted.internet.reactor.addReader()

项目:packet-queue    作者:google    | 项目源码 | 文件源码
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)
项目:enigma2    作者:OpenLD    | 项目源码 | 文件源码
def __init__(self):
        from twisted.internet import reactor
        self.nls = Netlink.NetlinkSocket()
        reactor.addReader(self)
项目:pyrepl    作者:dajose    | 项目源码 | 文件源码
def twistedinteract(self):
        from twisted.internet import reactor
        from twisted.internet.abstract import FileDescriptor
        import signal
        outerself = self
        class Me(FileDescriptor):
            def fileno(self):
                """ We want to select on FD 0 """
                return 0

            def doRead(self):
                """called when input is ready"""
                try:
                    outerself.handle1()
                except EOFError:
                    reactor.stop()

        reactor.addReader(Me())
        reactor.callWhenRunning(signal.signal,
                                signal.SIGINT,
                                signal.default_int_handler)
        self.prepare()
        try:
            reactor.run()
        finally:
            self.restore()
项目:enigma2    作者:Openeight    | 项目源码 | 文件源码
def __init__(self):
        from twisted.internet import reactor
        self.nls = Netlink.NetlinkSocket()
        reactor.addReader(self)
项目:enigma2    作者:BlackHole    | 项目源码 | 文件源码
def __init__(self):
        from twisted.internet import reactor
        self.nls = Netlink.NetlinkSocket()
        reactor.addReader(self)
项目:SEF    作者:ahmadnourallah    | 项目源码 | 文件源码
def start_dns_queue(self):
        self.q = nfqueue.queue()
        self.q.set_callback(self.nfqueue_callback)
        self.q.fast_open(0, socket.AF_INET)
        self.q.set_queue_maxlen(5000)
        reactor.addReader(self)
        self.q.set_mode(nfqueue.NFQNL_COPY_PACKET)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def twistedinteract(self):
        from twisted.internet import reactor
        from twisted.internet.abstract import FileDescriptor
        import signal
        outerself = self
        class Me(FileDescriptor):
            def fileno(self):
                """ We want to select on FD 0 """
                return 0

            def doRead(self):
                """called when input is ready"""
                try:
                    outerself.handle1()
                except EOFError:
                    reactor.stop()

        reactor.addReader(Me())
        reactor.callWhenRunning(signal.signal,
                                signal.SIGINT,
                                signal.default_int_handler)
        self.prepare()
        try:
            reactor.run()
        finally:
            self.restore()
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def addReader(self, reader):
        self._readers[reader] = True
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_removeAllSkipsInternalReaders(self):
        """
        Any L{IReadDescriptors} in L{PosixReactorBase._internalReaders} are
        left alone by L{PosixReactorBase._removeAll}.
        """
        reactor = TrivialReactor()
        extra = object()
        reactor._internalReaders.add(extra)
        reactor.addReader(extra)
        reactor._removeAll(reactor._readers, reactor._writers)
        self._checkWaker(reactor)
        self.assertIn(extra, reactor._internalReaders)
        self.assertIn(extra, reactor._readers)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_removeAllReturnsRemovedDescriptors(self):
        """
        L{PosixReactorBase._removeAll} returns a list of removed
        L{IReadDescriptor} and L{IWriteDescriptor} objects.
        """
        reactor = TrivialReactor()
        reader = object()
        writer = object()
        reactor.addReader(reader)
        reactor.addWriter(writer)
        removed = reactor._removeAll(
            reactor._readers, reactor._writers)
        self.assertEqual(set(removed), set([reader, writer]))
        self.assertNotIn(reader, reactor._readers)
        self.assertNotIn(writer, reactor._writers)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def addReader(self, reader):
        """
        Ignore the reader.  This is necessary because the waker will be
        added.  However, we won't actually monitor it for any events.
        """
项目:SEF    作者:hossamhasanin    | 项目源码 | 文件源码
def start_dns_queue(self):
        self.q = nfqueue.queue()
        self.q.set_callback(self.nfqueue_callback)
        self.q.fast_open(0, socket.AF_INET)
        self.q.set_queue_maxlen(5000)
        reactor.addReader(self)
        self.q.set_mode(nfqueue.NFQNL_COPY_PACKET)
项目:LANs.py    作者:wi-fi-analyzer    | 项目源码 | 文件源码
def __init__(self, args):
        self.q = nfqueue.queue()
        self.q.set_callback(Parser(args).start)
        self.q.fast_open(0, socket.AF_INET)
        self.q.set_queue_maxlen(5000)
        reactor.addReader(self)
        self.q.set_mode(nfqueue.NFQNL_COPY_PACKET)
        print '[*] Flushed firewall and forwarded traffic to the queue; waiting for data'
项目:enigma2-openpli-fulan    作者:Taapat    | 项目源码 | 文件源码
def __init__(self):
        from twisted.internet import reactor
        self.nls = Netlink.NetlinkSocket()
        reactor.addReader(self)