Python twisted.internet.interfaces.IConsumer() Examples
The following are 25
code examples of twisted.internet.interfaces.IConsumer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.internet.interfaces
, or try the search function
.
Example #1
Source File: ftp.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: _newclient.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #3
Source File: ftp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #4
Source File: _newclient.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #5
Source File: _newclient.py From python-for-android with Apache License 2.0 | 6 votes |
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)
Example #6
Source File: ftp.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #7
Source File: util.py From ccs-calendarserver with Apache License 2.0 | 6 votes |
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())
Example #8
Source File: ftp.py From learn_python3_spider with MIT License | 5 votes |
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. """
Example #9
Source File: ftp.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
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} """
Example #10
Source File: ftp.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
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. """
Example #11
Source File: ftp.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def sendListResponse(self, name, response): self.sendLine(self._formatOneListResponse(name, *response)) # Proxy IConsumer to our transport
Example #12
Source File: ftp.py From python-for-android with Apache License 2.0 | 5 votes |
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} """
Example #13
Source File: ftp.py From python-for-android with Apache License 2.0 | 5 votes |
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. """
Example #14
Source File: ftp.py From python-for-android with Apache License 2.0 | 5 votes |
def sendListResponse(self, name, response): self.sendLine(self._formatOneListResponse(name, *response)) # Proxy IConsumer to our transport
Example #15
Source File: test_newclient.py From python-for-android with Apache License 2.0 | 5 votes |
def test_interface(self): """ L{ChunkedEncoder} instances provide L{IConsumer}. """ self.assertTrue( verifyObject(IConsumer, ChunkedEncoder(StringTransport())))
Example #16
Source File: stream.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
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
Example #17
Source File: hostapd_control.py From Paradrop with Apache License 2.0 | 5 votes |
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 #
Example #18
Source File: ftp.py From learn_python3_spider with MIT License | 5 votes |
def sendListResponse(self, name, response): self.sendLine(self._formatOneListResponse(name, *response)) # Proxy IConsumer to our transport
Example #19
Source File: test_endpoints.py From learn_python3_spider with MIT License | 5 votes |
def test_verifyConsumer(self): """ L{_ProcessEndpointTransport}s provide L{IConsumer}. """ verifyObject(IConsumer, self.endpointTransport)
Example #20
Source File: test_newclient.py From learn_python3_spider with MIT License | 5 votes |
def test_interface(self): """ L{ChunkedEncoder} instances provide L{IConsumer}. """ self.assertTrue( verifyObject(IConsumer, ChunkedEncoder(StringTransport())))
Example #21
Source File: ftp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
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. """
Example #22
Source File: ftp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def sendListResponse(self, name, response): self.sendLine(self._formatOneListResponse(name, *response)) # Proxy IConsumer to our transport
Example #23
Source File: test_endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def test_verifyConsumer(self): """ L{_ProcessEndpointTransport}s provide L{IConsumer}. """ verifyObject(IConsumer, self.endpointTransport)
Example #24
Source File: test_newclient.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def test_interface(self): """ L{ChunkedEncoder} instances provide L{IConsumer}. """ self.assertTrue( verifyObject(IConsumer, ChunkedEncoder(StringTransport())))
Example #25
Source File: generic_ws.py From Paradrop with Apache License 2.0 | 5 votes |
def onMessage(self, payload, isBinary): if self.consumer is not None: self.consumer.write(payload) # # IConsumer interface #