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


Python interfaces.IConsumer方法代码示例

本文整理汇总了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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:_newclient.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:ftp.py

示例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()) 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:18,代码来源:util.py

示例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) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:_newclient.py

示例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) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:18,代码来源:ftp.py

示例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
    # 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:16,代码来源:hostapd_control.py

示例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
    # 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:9,代码来源:generic_ws.py

示例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()))) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:test_newclient.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:test_endpoints.py

示例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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:6,代码来源:ftp.py

示例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.
        """ 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:ftp.py

示例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 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:12,代码来源:stream.py

示例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 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:7,代码来源:ftp.py

示例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}
        """ 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:9,代码来源:ftp.py


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