PDEF Python Generatior

pdef-python的Python项目详细描述


pdef python
==
[pdef编译器的python代码生成器(https://github.com/pdef/pdef)
和描述符的python实现,json格式和http-rpc。

释放,
解压并在"generator"目录中运行:
``bash
$python setup.py install
`````

python generator将出现在已安装的生成器中:
``bash
$pdefc generate-h
用法:pdefc generate[…]
available生成器:
-python:python代码生成器,支持模块名,不支持前缀。
```

-python包:
``bash
$pip install pdef
````

最新版本。

(`package.module`)+`protocol.py`作为python模块名。
例如,` world.contines被转换成world/contines/protocol.py。
使用"--module"手动将pdef模块映射到python模块。
```bash
$pdefc generate python https://raw.github.com/pdef/pdef/1.1/example/world.yaml\
--module world.space:world撸space
--moduleworld:world_api
--out-generated
```

messages
----
generated messages实现``uu eq`、``uu copy`、``uu deepcopy`、和``uu str`` magic methods、
和合并方法。消息不是线程安全的。示例基于[pdef example package](https://github.com/pdef/pdef/tree/master/example)。

``python
human=human(id=1,name="john")
human.location=location(lat=30,lng=40)
human.birthday=datetime.datetime(1900,1,2)

import copy
another=copy.deepcopy(human)


assert copy==human
``````

messages支持合并哪些deep copies字段从源消息到目标消息。
``python
human=human(id=1,name="john")


another=human()
another.merge(human)


assert another==human
````

消息尝试不安全,并返回空字段的默认值。
如果空字段是集合或消息,则在第一个字段上将其初始化为空对象访问。
`` python
当字段为空时,所有属性都返回默认值。
human=human()
assert human.id==0
assert human.name==>

特殊属性允许检查字段是否存在。
assert not human.hashuman.has_name

==[人]
```

json格式
----
pdef使用内置的json解析器/序列化器:
``python
=human.from_json(s)

o_json(ident=none)

到类文件对象。
open('myfile.json','wt')为f:
human。to_json流(f,indent=none)
`````

使用"pdef.jsonformat"读/写其他pdef数据类型:
``python
3]
listd=pdef.descriptors.list0(pdef.descriptors.int32)
s=pdef.jsonformat.write(list0,listd)

是线程安全的。

基于[请求](http://www.python-requests.org/en/latest/)创建默认的http-rpc客户端。
``python
client=pdef.rpc\u client(world,url='http://example.com/world/')
world\u client=client.proxy()

\r执行远程方法。
humans=world.humans().all(limit=10,偏移量=0)

执行void远程方法。
world.switchDayNight()
````

没有原始结果转换为默认值。
``python
示例:
`` python
创建请求会话。
session=my_requests_session()

创建一个rpc客户端。
client=pdef.rpc_client(world,url='http://example.com/world/',session=session)

创建一个接口代理,将该客户端作为调用处理程序。
proxy=pdef.proxy(世界,调用处理程序=客户端)

=rpc_handler(world,world)
wsgi_app=pdef.wsgi_app(handler)
偏移量:
无限制和偏移量设置为0。
传递
````

以支持其他框架(如django、flask、flask、flask和等等)您需要将自定义请求
转换为"rpcrequests"并处理"rpcresults"。
``python
p<;path>;\.+)$','myapp.views.api'),



path=path)
rpc_req.query=request.get
rpc_req.post=request.post

处理rpc请求。
handler=get_rpc_handler()
成功,rpc_result=handler(rpc_req)

将rpc结果转换为django响应。
response=httpresponse(rpc_result.to_json(),content_type="application/json;charset=utf-8")
如果成功:
否则:
这是预期的应用程序异常。
响应。状态代码=422;不可处理的实体。

ivan.korobkov@gmail.com>;

2.0版apache许可证下的许可证(以下简称"许可证");
除非符合许可证,否则您不得使用此文件。
您可以在http://www.apache.org/licenses/license-2.0获取许可证副本,除非另有要求适用法律或书面同意,根据许可证分发的软件是在"按原样"的基础上分发的,
无任何明示或暗示的保证或条件。
请参阅许可证,了解管辖许可的特定语言和冰。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何拆分字符串(基于各种分隔符),但不保留空格?   解析。Json格式的txt文件和knime中的java   java Spring rest api为什么在rest api调用的响应中更改了数据类型   升华文本3抛出java。lang.ClassNotFoundException,而记事本++不存在   java Android指纹扫描仪在尝试5次后停止工作?   java Android如何设置精确的重复报警?   java如何使用HTTPGET connect为access API输入用户名和密码   java当测试报告显示没有测试失败时,Gradle为什么说“有失败的测试”?   用Gson实现java获取响应   MapReduce程序中函数错误的java不可映射参数   java spring安全性不符合自动代理的条件   java GWT使用异步回调进行同步/阻塞调用   java奇怪的类数组问题无法在jsp中显示   如何在java中使用PrinterJob使用epl打印条形码   java如何在JTable中居中单元格   将Java Mockito测试转换为Kotlin   html Java正则表达式模式匹配到多个相同标记   testCompile中缺少java Gradle(Android)多项目依赖项   在输入提示后输入字符串时发生java FileNotFoundException