1 Star 0 Fork 2

reggie/udp_broadcast

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
broadcast_result.py 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
reggie 提交于 2022-05-09 15:06 . (all): format code
# *_*coding:utf-8 *_*
# @Author : Reggie
# @Time : 2022/5/9 14:10
import abc
from version import VERSION
class ResultNotFoundError(Exception):
pass
class BaseResult(object):
@abc.abstractmethod
def to_dict(self, *args, **kwargs):
return NotImplemented
class Result(BaseResult):
def __init__(self, action, code, params, message, data):
self.action = action
self.code = code
self.params = params
self.message = message
self.data = data
def to_dict(self):
return {
"action": self.action,
"params": self.params,
"code": self.code,
"data": self.data,
"message": self.message
}
@property
def dict(self):
return self.to_dict()
def __repr__(self):
result = ""
dict_info = self.to_dict()
keys = sorted(dict_info.keys(), key=lambda x: x)
for k in keys:
result += "%s:\t%s\n" % (k, dict_info[k])
return result
version_result = {
VERSION: Result
}
def result(*args, version=VERSION, **kwargs):
try:
return version_result[version](*args, **kwargs)
except KeyError:
raise ResultNotFoundError("version result not found")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/reggiepy/udp_broadcast.git
[email protected]:reggiepy/udp_broadcast.git
reggiepy
udp_broadcast
udp_broadcast
master

搜索帮助