本文整理汇总了Python中twisted.internet.interfaces.IProducer方法的典型用法代码示例。如果您正苦于以下问题:Python interfaces.IProducer方法的具体用法?Python interfaces.IProducer怎么用?Python interfaces.IProducer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.interfaces
的用法示例。
在下文中一共展示了interfaces.IProducer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: registerProducer
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IProducer [as 别名]
def registerProducer(self, producer, streaming):
"""
Register a producer and start asking it for data if it is
non-streaming.
@type producer: L{IProducer <interfaces.IProducer>}
@param producer: A producer.
@type streaming: L{bool}
@param streaming: A flag indicating whether the producer provides a
streaming interface.
"""
self.myproducer = producer
self.streaming = streaming
if not streaming:
self.prodProducer()
示例2: registerProducer
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IProducer [as 别名]
def registerProducer(self, producer, streaming):
"""
Register to receive data from a producer.
This sets self to be a consumer for a producer. When this object runs
out of data (as when a send(2) call on a socket succeeds in moving the
last data from a userspace buffer into a kernelspace buffer), it will
ask the producer to resumeProducing().
For L{IPullProducer} providers, C{resumeProducing} will be called once
each time data is required.
For L{IPushProducer} providers, C{pauseProducing} will be called
whenever the write buffer fills up and C{resumeProducing} will only be
called when it empties.
@type producer: L{IProducer} provider
@param producer: The L{IProducer} that will be producing data.
@type streaming: L{bool}
@param streaming: C{True} if C{producer} provides L{IPushProducer},
C{False} if C{producer} provides L{IPullProducer}.
@raise RuntimeError: If a producer is already registered.
@return: L{None}
"""
if self._requestProducer is not None:
raise RuntimeError(
"Cannot register producer %s, because producer %s was never "
"unregistered." % (producer, self._requestProducer))
if not streaming:
producer = _PullToPush(producer, self)
self._requestProducer = producer
self._requestProducerStreaming = streaming
if not streaming:
producer.startStreaming()
示例3: test_interface
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IProducer [as 别名]
def test_interface(self):
"""
L{basic.FileSender} implements the L{IPullProducer} interface.
"""
sender = basic.FileSender()
self.assertTrue(verifyObject(IProducer, sender))
示例4: pauseProducing
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IProducer [as 别名]
def pauseProducing(self):
"""IProducer implementation tracking if we should pause output"""
self._paused = True
示例5: resumeProducing
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IProducer [as 别名]
def resumeProducing(self):
"""IProducer implementation tracking when we should resume output"""
self._paused = False
示例6: stopProducing
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IProducer [as 别名]
def stopProducing(self):
"""IProducer implementation tracking when we should stop"""
self._paused = True
self._should_stop = True
示例7: pause_reading
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IProducer [as 别名]
def pause_reading(self):
# interfaces are the stupedist crap ever
if (hasattr(interfaces.IProducer, "providedBy") and
not interfaces.IProducer.providedBy(self.transport)):
print "No producer", self.ip, self.port, self.transport
return
# not explicitly needed, but iocpreactor has a bug where the author is a moron
if self.paused:
return
self.transport.pauseProducing()
self.paused = True
示例8: resume_reading
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IProducer [as 别名]
def resume_reading(self):
if (hasattr(interfaces.IProducer, "providedBy") and
not interfaces.IProducer.providedBy(self.transport)):
print "No producer", self.ip, self.port, self.transport
return
# not explicitly needed, but iocpreactor has a bug where the author is a moron
if not self.paused:
return
self.paused = False
try:
self.transport.resumeProducing()
except Exception, e:
# I bet these are harmless
print "resumeProducing error", type(e), e