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


Python protocol.ReceivableProtocol类代码示例

本文整理汇总了Python中dulwich.protocol.ReceivableProtocol的典型用法代码示例。如果您正苦于以下问题:Python ReceivableProtocol类的具体用法?Python ReceivableProtocol怎么用?Python ReceivableProtocol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: handle

    def handle(self):
        proto = ReceivableProtocol(self.connection.recv, self.wfile.write)
        command, args = proto.read_cmd()
        logger.info('Handling %s request, args=%s', command, args)

        cls = self.handlers.get(command, None)
        if not callable(cls):
            raise GitProtocolError('Invalid service %s' % command)
        h = cls(self.server.backend, args, proto)
        h.handle()
开发者ID:briarfox,项目名称:dulwich,代码行数:10,代码来源:server.py

示例2: setUp

    def setUp(self):
        TestCase.setUp(self)
        self.rout = BytesIO()
        self.rin = ReceivableBytesIO()

        def _closeit():
            self.rout.close()
            self.rin.close()

        self.proto = ReceivableProtocol(self.rin.recv, self.rout.write, _closeit)
        self.proto._rbufsize = 8
        self.addCleanup(self.proto.close)
开发者ID:TDC-bob,项目名称:dulwich-py3k,代码行数:12,代码来源:test_protocol.py

示例3: setUp

 def setUp(self):
     TestCase.setUp(self)
     self.rout = StringIO()
     self.rin = ReceivableStringIO()
     self.proto = ReceivableProtocol(self.rin.recv, self.rout.write)
     self.proto._rbufsize = 8
开发者ID:AaronO,项目名称:dulwich,代码行数:6,代码来源:test_protocol.py

示例4: ReceivableProtocolTests

class ReceivableProtocolTests(BaseProtocolTests, TestCase):

    def setUp(self):
        TestCase.setUp(self)
        self.rout = BytesIO()
        self.rin = ReceivableBytesIO()

        def _closeit():
            self.rout.close()
            self.rin.close()

        self.proto = ReceivableProtocol(self.rin.recv, self.rout.write, _closeit)
        self.proto._rbufsize = 8
        self.addCleanup(self.proto.close)

    def test_eof(self):
        # Allow blocking reads past EOF just for this test. The only parts of
        # the protocol that might check for EOF do not depend on the recv()
        # semantics anyway.
        self.rin.allow_read_past_eof = True
        BaseProtocolTests.test_eof(self)

    def test_recv(self):
        all_data = b'1234567' * 10  # not a multiple of bufsize
        self.rin.write(all_data)
        self.rin.seek(0)
        data = b''
        # We ask for 8 bytes each time and actually read 7, so it should take
        # exactly 10 iterations.
        for _ in range(10):
            data += self.proto.recv(10)
        # any more reads would block
        self.assertRaises(AssertionError, self.proto.recv, 10)
        self.assertEqual(all_data, data)

    def test_recv_read(self):
        all_data = b'1234567'  # recv exactly in one call
        self.rin.write(all_data)
        self.rin.seek(0)
        self.assertEqual(b'1234', self.proto.recv(4))
        self.assertEqual(b'567', self.proto.read(3))
        self.assertRaises(AssertionError, self.proto.recv, 10)

    def test_read_recv(self):
        all_data = b'12345678abcdefg'
        self.rin.write(all_data)
        self.rin.seek(0)
        self.assertEqual(b'1234', self.proto.read(4))
        self.assertEqual(b'5678abc', self.proto.recv(8))
        self.assertEqual(b'defg', self.proto.read(4))
        self.assertRaises(AssertionError, self.proto.recv, 10)

    def test_mixed(self):
        # arbitrary non-repeating string
        all_data = ','.join(str(i) for i in range(100)).encode('utf-8')
        self.rin.write(all_data)
        self.rin.seek(0)
        data = b''

        for i in range(1, 100):
            data += self.proto.recv(i)
            # if we get to the end, do a non-blocking read instead of blocking
            if len(data) + i > len(all_data):
                data += self.proto.recv(i)
                # ReceivableBytesIO leaves off the last byte unless we ask
                # nicely
                data += self.proto.recv(1)
                break
            else:
                data += self.proto.read(i)
        else:
            # didn't break, something must have gone wrong
            self.fail()

        self.assertEqual(all_data, data)
开发者ID:TDC-bob,项目名称:dulwich-py3k,代码行数:75,代码来源:test_protocol.py

示例5: ReceivableProtocolTests

class ReceivableProtocolTests(BaseProtocolTests, TestCase):

    def setUp(self):
        TestCase.setUp(self)
        self.rout = StringIO()
        self.rin = ReceivableStringIO()
        self.proto = ReceivableProtocol(self.rin.recv, self.rout.write)
        self.proto._rbufsize = 8

    def test_recv(self):
        all_data = "1234567" * 10  # not a multiple of bufsize
        self.rin.write(all_data)
        self.rin.seek(0)
        data = ""
        # We ask for 8 bytes each time and actually read 7, so it should take
        # exactly 10 iterations.
        for _ in xrange(10):
            data += self.proto.recv(10)
        # any more reads would block
        self.assertRaises(AssertionError, self.proto.recv, 10)
        self.assertEquals(all_data, data)

    def test_recv_read(self):
        all_data = "1234567"  # recv exactly in one call
        self.rin.write(all_data)
        self.rin.seek(0)
        self.assertEquals("1234", self.proto.recv(4))
        self.assertEquals("567", self.proto.read(3))
        self.assertRaises(AssertionError, self.proto.recv, 10)

    def test_read_recv(self):
        all_data = "12345678abcdefg"
        self.rin.write(all_data)
        self.rin.seek(0)
        self.assertEquals("1234", self.proto.read(4))
        self.assertEquals("5678abc", self.proto.recv(8))
        self.assertEquals("defg", self.proto.read(4))
        self.assertRaises(AssertionError, self.proto.recv, 10)

    def test_mixed(self):
        # arbitrary non-repeating string
        all_data = ",".join(str(i) for i in xrange(100))
        self.rin.write(all_data)
        self.rin.seek(0)
        data = ""

        for i in xrange(1, 100):
            data += self.proto.recv(i)
            # if we get to the end, do a non-blocking read instead of blocking
            if len(data) + i > len(all_data):
                data += self.proto.recv(i)
                # ReceivableStringIO leaves off the last byte unless we ask
                # nicely
                data += self.proto.recv(1)
                break
            else:
                data += self.proto.read(i)
        else:
            # didn't break, something must have gone wrong
            self.fail()

        self.assertEquals(all_data, data)
开发者ID:tmc,项目名称:dulwich,代码行数:62,代码来源:test_protocol.py


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