当前位置: 首页>>代码示例>>Python>>正文


Python reactor.addReader方法代码示例

本文整理汇总了Python中twisted.internet.reactor.addReader方法的典型用法代码示例。如果您正苦于以下问题:Python reactor.addReader方法的具体用法?Python reactor.addReader怎么用?Python reactor.addReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.reactor的用法示例。


在下文中一共展示了reactor.addReader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: configure

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import addReader [as 别名]
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) 
开发者ID:google,项目名称:packet-queue,代码行数:24,代码来源:nfqueue.py

示例2: test_listener_ignores_ENOENT_when_removing_itself_from_reactor

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import addReader [as 别名]
def test_listener_ignores_ENOENT_when_removing_itself_from_reactor(self):
        listener = PostgresListenerService()

        self.patch(reactor, "addReader")
        self.patch(reactor, "removeReader")

        # removeReader() is going to have a nasty accident.
        enoent = IOError("ENOENT")
        enoent.errno = errno.ENOENT
        reactor.removeReader.side_effect = enoent

        # The listener starts and stops without issue.
        yield listener.startService()
        yield listener.stopService()

        # addReader() and removeReader() were both called.
        self.assertThat(reactor.addReader, MockCalledOnceWith(listener))
        self.assertThat(reactor.removeReader, MockCalledOnceWith(listener)) 
开发者ID:maas,项目名称:maas,代码行数:20,代码来源:test_listener.py

示例3: addReader

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import addReader [as 别名]
def addReader(self, reader):
        self._readers[reader] = True 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:4,代码来源:test_posixbase.py

示例4: test_removeAllSkipsInternalReaders

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import addReader [as 别名]
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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:test_posixbase.py

示例5: test_removeAllReturnsRemovedDescriptors

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import addReader [as 别名]
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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:test_posixbase.py

示例6: startReading

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import addReader [as 别名]
def startReading(self):
        """Add this listener to the reactor."""
        self.connectionFileno = self.connection.connection.fileno()
        reactor.addReader(self) 
开发者ID:maas,项目名称:maas,代码行数:6,代码来源:listener.py

示例7: test_tryConnection_adds_self_to_reactor

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import addReader [as 别名]
def test_tryConnection_adds_self_to_reactor(self):
        listener = PostgresListenerService()

        # Spy on calls to reactor.addReader.
        self.patch(reactor, "addReader").side_effect = reactor.addReader

        yield listener.tryConnection()
        try:
            self.assertThat(reactor.addReader, MockCalledOnceWith(listener))
        finally:
            yield listener.stopService() 
开发者ID:maas,项目名称:maas,代码行数:13,代码来源:test_listener.py


注:本文中的twisted.internet.reactor.addReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。