python脚本实现RouterOS软路由中文编码转换,RouterOS使用中文备注
作者:myluzh 分类: RouterOS 长度:568 阅读:1724
用的就是url gb2313编码
import urllib
from urllib import parse
def url_gb2312(t_type, text):
if t_type == "encode":
text = urllib.parse.quote(text.encode('gb2312'))
text = text.replace("%", "\\")
return text
if t_type == "decode":
text = text.replace("\\", "%")
text = urllib.parse.unquote(text, encoding='gb2312')
return text
# 编码
t = url_gb2312("encode", "哈哈哈")
print(t) # 输出 \B9\FE\B9\FE\B9\FE
# 解码
t = url_gb2312("decode", "\B9\FE\B9\FE\B9\FE")
print(t) # 输出 哈哈哈