首页 > 编程语言 > 详细

python测试dubbo接口

时间:2020-08-20 20:50:22      阅读:84      评论:0      收藏:0      [点我收藏+]
# coding=utf-8
import json
import telnetlib


class Dubbo(telnetlib.Telnet):
    prompt = dubbo>
    coding = utf-8

    def __init__(self, host=None, port=0):
        super().__init__(host, port)
        self.write(b\n)

    def command(self, flag, str_=""):
        data = self.read_until(flag.encode())
        self.write(str_.encode() + b"\n")
        return data

    def invoke(self, service_name, method_name, arg):
        command_str = "invoke {0}.{1}({2})".format(
            service_name, method_name, json.dumps(arg))
        self.command(Dubbo.prompt, command_str)
        data = self.command(Dubbo.prompt, "")
        data = data.decode(Dubbo.coding, errors=ignore).split(\n)[0].strip()
        return data

    def do(self, command_str):
        self.command(Dubbo.prompt, command_str)
        data = self.command(Dubbo.prompt, command_str)
        data = data.decode(Dubbo.coding, errors=ignore).split(\n)[0].strip()
        try:
            return json.loads(data)
        except:
            return data

 

python测试dubbo接口

原文:https://www.cnblogs.com/FengZiQ/p/13537571.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!