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


Python Protocol.send_cmd方法代码示例

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


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

示例1: _connect

# 需要导入模块: from dulwich.protocol import Protocol [as 别名]
# 或者: from dulwich.protocol.Protocol import send_cmd [as 别名]
    def _connect(self, cmd, path):
        sockaddrs = socket.getaddrinfo(
            self._host, self._port, socket.AF_UNSPEC, socket.SOCK_STREAM)
        s = None
        err = socket.error("no address found for %s" % self._host)
        for (family, socktype, proto, canonname, sockaddr) in sockaddrs:
            s = socket.socket(family, socktype, proto)
            s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
            try:
                s.connect(sockaddr)
                break
            except socket.error as err:
                if s is not None:
                    s.close()
                s = None
        if s is None:
            raise err
        # -1 means system default buffering
        rfile = s.makefile('rb', -1)
        # 0 means unbuffered
        wfile = s.makefile('wb', 0)
        def close():
            rfile.close()
            wfile.close()
            s.close()

        proto = Protocol(rfile.read, wfile.write, close,
                         report_activity=self._report_activity)
        if path.startswith(b"/~"):
            path = path[1:]
        proto.send_cmd(b'git-' + cmd, path, b'host=' + self._host)
        return proto, lambda: _fileno_can_read(s)
开发者ID:michael-k,项目名称:dulwich,代码行数:34,代码来源:client.py

示例2: _connect

# 需要导入模块: from dulwich.protocol import Protocol [as 别名]
# 或者: from dulwich.protocol.Protocol import send_cmd [as 别名]
 def _connect(self, cmd, path):
     s = socket.socket(type=socket.SOCK_STREAM)
     s.connect((self._host, self._port))
     # -1 means system default buffering
     rfile = s.makefile("rb", -1)
     # 0 means unbuffered
     wfile = s.makefile("wb", 0)
     proto = Protocol(rfile.read, wfile.write, report_activity=self._report_activity)
     proto.send_cmd("git-%s" % cmd, path, "host=%s" % self._host)
     return proto, lambda: _fileno_can_read(s)
开发者ID:rcrowley,项目名称:dulwich,代码行数:12,代码来源:client.py

示例3: ProtocolTests

# 需要导入模块: from dulwich.protocol import Protocol [as 别名]
# 或者: from dulwich.protocol.Protocol import send_cmd [as 别名]
class ProtocolTests(TestCase):

    def setUp(self):
        self.rout = StringIO()
        self.rin = StringIO()
        self.proto = Protocol(self.rin.read, self.rout.write)

    def test_write_pkt_line_none(self):
        self.proto.write_pkt_line(None)
        self.assertEquals(self.rout.getvalue(), "0000")

    def test_write_pkt_line(self):
        self.proto.write_pkt_line("bla")
        self.assertEquals(self.rout.getvalue(), "0007bla")

    def test_read_pkt_line(self):
        self.rin.write("0008cmd ")
        self.rin.seek(0)
        self.assertEquals("cmd ", self.proto.read_pkt_line())

    def test_read_pkt_seq(self):
        self.rin.write("0008cmd 0005l0000")
        self.rin.seek(0)
        self.assertEquals(["cmd ", "l"], list(self.proto.read_pkt_seq()))

    def test_read_pkt_line_none(self):
        self.rin.write("0000")
        self.rin.seek(0)
        self.assertEquals(None, self.proto.read_pkt_line())

    def test_write_sideband(self):
        self.proto.write_sideband(3, "bloe")
        self.assertEquals(self.rout.getvalue(), "0009\x03bloe")

    def test_send_cmd(self):
        self.proto.send_cmd("fetch", "a", "b")
        self.assertEquals(self.rout.getvalue(), "000efetch a\x00b\x00")

    def test_read_cmd(self):
        self.rin.write("0012cmd arg1\x00arg2\x00")
        self.rin.seek(0)
        self.assertEquals(("cmd", ["arg1", "arg2"]), self.proto.read_cmd())

    def test_read_cmd_noend0(self):
        self.rin.write("0011cmd arg1\x00arg2")
        self.rin.seek(0)
        self.assertRaises(AssertionError, self.proto.read_cmd)
开发者ID:SRabbelier,项目名称:hg-git,代码行数:49,代码来源:test_protocol.py


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