本文整理汇总了Python中twisted.internet.interfaces.IConsumer方法的典型用法代码示例。如果您正苦于以下问题:Python interfaces.IConsumer方法的具体用法?Python interfaces.IConsumer怎么用?Python interfaces.IConsumer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.interfaces
的用法示例。
在下文中一共展示了interfaces.IConsumer方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writeTo
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def writeTo(self, transport):
"""
Format this L{Request} as an HTTP/1.1 request and write it to the given
transport. If bodyProducer is not None, it will be associated with an
L{IConsumer}.
@param transport: The transport to which to write.
@type transport: L{twisted.internet.interfaces.ITransport} provider
@return: A L{Deferred} which fires with L{None} when the request has
been completely written to the transport or with a L{Failure} if
there is any problem generating the request bytes.
"""
if self.bodyProducer is None:
# If the method semantics anticipate a body, include a
# Content-Length even if it is 0.
# https://tools.ietf.org/html/rfc7230#section-3.3.2
if self.method in (b"PUT", b"POST"):
self._writeToEmptyBodyContentLength(transport)
else:
self._writeHeaders(transport, None)
elif self.bodyProducer.length is UNKNOWN_LENGTH:
return self._writeToBodyProducerChunked(transport)
else:
return self._writeToBodyProducerContentLength(transport)
示例2: receiveFromConnection
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def receiveFromConnection(self, commands, protocol):
"""
Retrieves a file or listing generated by the given command,
feeding it to the given protocol.
@param commands: list of strings of FTP commands to execute then receive
the results of (e.g. C{LIST}, C{RETR})
@param protocol: A L{Protocol} B{instance} e.g. an
L{FTPFileListProtocol}, or something that can be adapted to one.
Typically this will be an L{IConsumer} implementation.
@return: L{Deferred}.
"""
protocol = interfaces.IProtocol(protocol)
wrapper = ProtocolWrapper(protocol, defer.Deferred())
return self._openDataConnection(commands, wrapper)
示例3: start
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def start(self, protocol):
this = self
class Consumer(object):
implements(IConsumer)
def registerProducer(self, producer, streaming):
protocol.makeConnection(producer)
this._maybeLoopDelivery()
def write(self, data):
protocol.dataReceived(data)
def unregisterProducer(self):
this._done(protocol)
self.beginFileTransfer(self.filePath.open(), Consumer())
示例4: writeTo
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def writeTo(self, transport):
"""
Format this L{Request} as an HTTP/1.1 request and write it to the given
transport. If bodyProducer is not None, it will be associated with an
L{IConsumer}.
@return: A L{Deferred} which fires with C{None} when the request has
been completely written to the transport or with a L{Failure} if
there is any problem generating the request bytes.
"""
if self.bodyProducer is not None:
if self.bodyProducer.length is UNKNOWN_LENGTH:
return self._writeToChunked(transport)
else:
return self._writeToContentLength(transport)
else:
self._writeHeaders(transport, None)
return succeed(None)
示例5: receiveFromConnection
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def receiveFromConnection(self, commands, protocol):
"""
Retrieves a file or listing generated by the given command,
feeding it to the given protocol.
@param command: list of strings of FTP commands to execute then receive
the results of (e.g. LIST, RETR)
@param protocol: A L{Protocol} *instance* e.g. an
L{FTPFileListProtocol}, or something that can be adapted to one.
Typically this will be an L{IConsumer} implemenation.
@returns: L{Deferred}.
"""
protocol = interfaces.IProtocol(protocol)
wrapper = ProtocolWrapper(protocol, defer.Deferred())
return self._openDataConnection(commands, wrapper)
示例6: bindAddress
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def bindAddress(self):
"""
Choose a path for the client side of the UNIX socket.
This should be unique to avoid errors.
- Use the tmp directory, so that they are sure to be cleaned up.
- Use the PID for uniqueness if the daemon is restarted.
- Use the counter for uniqueness across multiple requests.
"""
return "/tmp/hostapd-{}-{}.sock".format(os.getpid(), self.instance)
#
# IConsumer interface
#
示例7: onMessage
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def onMessage(self, payload, isBinary):
if self.consumer is not None:
self.consumer.write(payload)
#
# IConsumer interface
#
示例8: test_interface
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def test_interface(self):
"""
L{ChunkedEncoder} instances provide L{IConsumer}.
"""
self.assertTrue(
verifyObject(IConsumer, ChunkedEncoder(StringTransport())))
示例9: test_verifyConsumer
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def test_verifyConsumer(self):
"""
L{_ProcessEndpointTransport}s provide L{IConsumer}.
"""
verifyObject(IConsumer, self.endpointTransport)
示例10: sendListResponse
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def sendListResponse(self, name, response):
self.sendLine(self._formatOneListResponse(name, *response))
# Proxy IConsumer to our transport
示例11: send
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def send(consumer):
"""
Produce the contents of the given path to the given consumer. This
method may only be invoked once on each provider.
@type consumer: C{IConsumer}
@return: A Deferred which fires when the file has been
consumed completely.
"""
示例12: close
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def close(self):
"""Called by reader of stream when it is done reading."""
self.buffer = []
self.closed = True
if self.producer is not None:
self.producer.stopProducing()
self.producer = None
self.deferred = None
# IConsumer implementation
示例13: sendListResponse
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def sendListResponse(self, name, response):
self.sendLine(self._formatOneListResponse(name, *response))
# Proxy IConsumer to our transport
示例14: receive
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IConsumer [as 别名]
def receive():
"""
Create a consumer which will write to this file. This method may
only be invoked once on each provider.
@rtype: C{Deferred} of C{IConsumer}
"""