使用传输格式的命令行工具
transito的Python项目详细描述
使用传输格式的命令行工具
- 免费软件:ISC许可证
- 文档:https://transito.readthedocs.org。
功能
- 转换为并形成json、edn、transit
- 从stdin或文件中读取内容
用法
$ transito -h usage: transito [-h] {t2j,j2t,e2t,t2e,http} ... Transit CLI positional arguments: {t2j,j2t,e2t,t2e,http} t2j convert transit to json j2t convert json to transit e2t convert edn to transit t2e convert transit to edn http make http requests with transit data optional arguments: -h, --help show this help message and exit
转换
将传输从文件转换为json:
$ transito t2j examples/ex1.transit [":keyword", "~lala", 1, 1.2, true, null, [], ["hi", "a"]]
将传输从stdin转换为json:
$ transito t2j - ["~#list",["~:keyword","~$lala",1,1.2,true,null,[],["hi",["~#char","a"]]]] [":keyword", "~lala", 1, 1.2, true, null, [], ["hi", "a"]]
注意
第一行是输入,然后按enter和ctrl+d
来自另一个命令的管道:
$ echo '["~#list",["~:keyword","~$lala",1,1.2,true,null,[],["hi",["~#char","a"]]]]' | transito t2j - [":keyword", "~lala", 1, 1.2, true, null, [], ["hi", "a"]]
EDN相同:
$ transito t2e examples/ex1.transit (keyword lala 1 1.2 true nil [] ["hi" \a])
$ echo '["~#list",["~:keyword","~$lala",1,1.2,true,null,[],["hi",["~#char","a"]]]]' | transito t2e - (keyword lala 1 1.2 true nil [] ["hi" \a])
$ transito t2e - ["~#list",["~:keyword","~$lala",1,1.2,true,null,[],["hi",["~#char","a"]]]] (keyword lala 1 1.2 true nil [] ["hi" \a])
你应该有这个想法,一些以transit作为输出,以防万一:
$ transito e2t - (keyword lala 1 1.2 true nil [] ["hi" \a]) ["~#list",["~$keyword","~$lala",1,1.2,true,null,[],["hi",["~#char","a"]]]] $ transito t2j - ["~#list",["~$keyword","~$lala",1,1.2,true,null,[],["hi",["~#char","a"]]]] ["~keyword", "~lala", 1, 1.2, true, null, [], ["hi", "a"]]
注意
到json的转换是有损耗的,这意味着为了不崩溃 序列化关键字、符号和字符时,我们会进行有损序列化, 字符是字符串,关键字是以:开头的字符串,符号是 以~开头的字符串。
此翻译的目的是提供一种查看edn或transit的方法 作为json,不应用于将此数据发送到生产系统。
http请求
您可以发出一个http请求,该请求支持transit、json或edn,但可以写入和 以更可读的方式读取请求和响应,例如,使 请求写入将在发送前转换为传输的edn, 如果可能,响应将转换为EDN,使其更具可读性:
$ echo '(increment {:value 20})' | transito http post http://localhost:8080/action e2t - Status: 200 Content-Type: application/transit+json Content-Length: 28 {:value [:count]}
你可能会问,是不是完成了?是的,是的。
历史记录
0.1.3(2015-12-01)
- 在edn中添加对具有命名空间的关键字的支持
0.1.2(2015-26-11)
- 修复http响应上传输的edn编码
0.1.1(2015-25-11)
- 添加对http请求的支持
- 修复edn中的关键字序列化
0.1.0(2015-25-11)
- pypi上的第一个版本。