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


Python basic.LineReceiver方法代码示例

本文整理汇总了Python中twisted.protocols.basic.LineReceiver方法的典型用法代码示例。如果您正苦于以下问题:Python basic.LineReceiver方法的具体用法?Python basic.LineReceiver怎么用?Python basic.LineReceiver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.protocols.basic的用法示例。


在下文中一共展示了basic.LineReceiver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dataReceived

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def dataReceived(self, data):
        """
        This hack is to support mIRC, which sends LF only, even though the RFC
        says CRLF.  (Also, the flexibility of LineReceiver to turn "line mode"
        on and off was not required.)
        """
        if isinstance(data, bytes):
            data = data.decode("utf-8")
        lines = (self.buffer + data).split(LF)
        # Put the (possibly empty) element after the last LF back in the
        # buffer
        self.buffer = lines.pop()

        for line in lines:
            if len(line) <= 2:
                # This is a blank line, at best.
                continue
            if line[-1] == CR:
                line = line[:-1]
            prefix, command, params = parsemsg(line)
            # mIRC is a big pile of doo-doo
            command = command.upper()
            # DEBUG: log.msg( "%s %s %s" % (prefix, command, params))

            self.handleCommand(command, prefix, params) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:irc.py

示例2: test_clearLineBuffer

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def test_clearLineBuffer(self):
        """
        L{LineReceiver.clearLineBuffer} removes all buffered data and returns
        it as a C{bytes} and can be called from beneath C{dataReceived}.
        """
        class ClearingReceiver(basic.LineReceiver):
            def lineReceived(self, line):
                self.line = line
                self.rest = self.clearLineBuffer()

        protocol = ClearingReceiver()
        protocol.dataReceived(b'foo\r\nbar\r\nbaz')
        self.assertEqual(protocol.line, b'foo')
        self.assertEqual(protocol.rest, b'bar\r\nbaz')

        # Deliver another line to make sure the previously buffered data is
        # really gone.
        protocol.dataReceived(b'quux\r\n')
        self.assertEqual(protocol.line, b'quux')
        self.assertEqual(protocol.rest, b'') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_basic.py

示例3: rawDataReceived

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def rawDataReceived(self, data):
        if self.timeout > 0:
            self.resetTimeout()

        self._pendingSize -= len(data)
        if self._pendingSize > 0:
            self._pendingBuffer.write(data)
        else:
            passon = ''
            if self._pendingSize < 0:
                data, passon = data[:self._pendingSize], data[self._pendingSize:]
            self._pendingBuffer.write(data)
            rest = self._pendingBuffer
            self._pendingBuffer = None
            self._pendingSize = None
            rest.seek(0, 0)
            self._parts.append(rest.read())
            self.setLineMode(passon.lstrip('\r\n'))

#    def sendLine(self, line):
#        print 'S:', repr(line)
#        return basic.LineReceiver.sendLine(self, line) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:imap4.py

示例4: dataReceived

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def dataReceived(self, data):
        """
        Data was received from the network.  Process it.
        """
        # If we're currently handling a request, buffer this data.
        if self._handlingRequest:
            self._dataBuffer.append(data)
            if (
                    (sum(map(len, self._dataBuffer)) >
                     self._optimisticEagerReadSize)
                    and not self._waitingForTransport
            ):
                # If we received more data than a small limit while processing
                # the head-of-line request, apply TCP backpressure to our peer
                # to get them to stop sending more request data until we're
                # ready.  See docstring for _optimisticEagerReadSize above.
                self._networkProducer.pauseProducing()
            return
        return basic.LineReceiver.dataReceived(self, data) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:21,代码来源:http.py

示例5: test_notQuiteMaximumLineLengthUnfinished

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def test_notQuiteMaximumLineLengthUnfinished(self):
        """
        C{LineReceiver} doesn't disconnect the transport it if
        receives a non-finished line whose length, counting the
        delimiter, is longer than its C{MAX_LENGTH} but shorter than
        its C{MAX_LENGTH} + len(delimiter). (When the first part that
        exceeds the max is the beginning of the delimiter.)
        """
        proto = basic.LineReceiver()
        # '\r\n' is the default, but we set it just to be explicit in
        # this test.
        proto.delimiter = b'\r\n'
        transport = proto_helpers.StringTransport()
        proto.makeConnection(transport)
        proto.dataReceived((b'x' * proto.MAX_LENGTH)
                           + proto.delimiter[:len(proto.delimiter)-1])
        self.assertFalse(transport.disconnecting) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:19,代码来源:test_basic.py

示例6: dataReceived

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def dataReceived(self, data):
        """
        This hack is to support mIRC, which sends LF only, even though the RFC
        says CRLF.  (Also, the flexibility of LineReceiver to turn "line mode"
        on and off was not required.)
        """
        lines = (self.buffer + data).split(LF)
        # Put the (possibly empty) element after the last LF back in the
        # buffer
        self.buffer = lines.pop()

        for line in lines:
            if len(line) <= 2:
                # This is a blank line, at best.
                continue
            if line[-1] == CR:
                line = line[:-1]
            prefix, command, params = parsemsg(line)
            # mIRC is a big pile of doo-doo
            command = command.upper()
            # DEBUG: log.msg( "%s %s %s" % (prefix, command, params))

            self.handleCommand(command, prefix, params) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:25,代码来源:irc.py

示例7: test_clearLineBuffer

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def test_clearLineBuffer(self):
        """
        L{LineReceiver.clearLineBuffer} removes all buffered data and returns
        it as a C{str} and can be called from beneath C{dataReceived}.
        """
        class ClearingReceiver(basic.LineReceiver):
            def lineReceived(self, line):
                self.line = line
                self.rest = self.clearLineBuffer()

        protocol = ClearingReceiver()
        protocol.dataReceived('foo\r\nbar\r\nbaz')
        self.assertEqual(protocol.line, 'foo')
        self.assertEqual(protocol.rest, 'bar\r\nbaz')

        # Deliver another line to make sure the previously buffered data is
        # really gone.
        protocol.dataReceived('quux\r\n')
        self.assertEqual(protocol.line, 'quux')
        self.assertEqual(protocol.rest, '') 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:test_protocols.py

示例8: dataReceived

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def dataReceived(self, data):
        """This hack is to support mIRC, which sends LF only,
        even though the RFC says CRLF.  (Also, the flexibility
        of LineReceiver to turn "line mode" on and off was not
        required.)
        """
        lines = (self.buffer + data).split(LF)
        # Put the (possibly empty) element after the last LF back in the
        # buffer
        self.buffer = lines.pop()

        for line in lines:
            if len(line) <= 2:
                # This is a blank line, at best.
                continue
            if line[-1] == CR:
                line = line[:-1]
            prefix, command, params = parsemsg(line)
            # mIRC is a big pile of doo-doo
            command = command.upper()
            # DEBUG: log.msg( "%s %s %s" % (prefix, command, params))

            self.handleCommand(command, prefix, params) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:25,代码来源:irc.py

示例9: _reallySendLine

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def _reallySendLine(self, line):
        quoteLine = lowQuote(line)
        if isinstance(quoteLine, unicode):
            quoteLine = quoteLine.encode("utf-8")
        quoteLine += b'\r'
        return basic.LineReceiver.sendLine(self, quoteLine) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:irc.py

示例10: connectionLost

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def connectionLost(self, reason):
        basic.LineReceiver.connectionLost(self, reason)
        self.stopHeartbeat() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:5,代码来源:irc.py

示例11: dataReceived

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def dataReceived(self, data):
        try:
            if isinstance(data, unicode):
                data = data.encode("utf-8")
            basic.LineReceiver.dataReceived(self, data)
        except:
            log.err()
            self.invalidMessage() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:sip.py

示例12: sendLine

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def sendLine(self, line):
        """Throw up if the line is longer than 1022 characters"""
        if len(line) > self.MAX_LENGTH - 2:
            raise ValueError("DictClient tried to send a too long line")
        basic.LineReceiver.sendLine(self, line) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:dict.py

示例13: test_rawDataError

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def test_rawDataError(self):
        """
        C{LineReceiver.dataReceived} forwards errors returned by
        C{rawDataReceived}.
        """
        proto = basic.LineReceiver()
        proto.rawDataReceived = lambda data: RuntimeError("oops")
        transport = proto_helpers.StringTransport()
        proto.makeConnection(transport)
        proto.setRawMode()
        why = proto.dataReceived(b'data')
        self.assertIsInstance(why, RuntimeError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_basic.py

示例14: test_rawDataReceivedNotImplemented

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def test_rawDataReceivedNotImplemented(self):
        """
        When L{LineReceiver.rawDataReceived} is not overridden in a
        subclass, calling it raises C{NotImplementedError}.
        """
        proto = basic.LineReceiver()
        self.assertRaises(NotImplementedError, proto.rawDataReceived, 'foo') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_basic.py

示例15: test_longUnendedLine

# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import LineReceiver [as 别名]
def test_longUnendedLine(self):
        """
        If more bytes than C{LineReceiver.MAX_LENGTH} arrive containing no line
        delimiter, all of the bytes are passed as a single string to
        L{LineReceiver.lineLengthExceeded}.
        """
        excessive = b'x' * (self.proto.MAX_LENGTH * 2 + 2)
        self.proto.dataReceived(excessive)
        self.assertEqual([excessive], self.proto.longLines) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:test_basic.py


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