本文整理汇总了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)
示例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))
示例3: addReader
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import addReader [as 别名]
def addReader(self, reader):
self._readers[reader] = True
示例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)
示例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)
示例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)
示例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()