事件驱动的ddp客户端
python-ddp的Python项目详细描述
#python-python-ddp
**安装**
``bash
$pip安装python-ddp
``
**目录**
-[历史沿革]
-[快速入门]
-[使用方法](使用方法)
-[快速入门]
-[快速入门]([快速入门]
-[使用方法]
-[合作者]([合作者]
>
嗨故事
**最新版本**0.1.5
-处理DDP版本_1_2;、_pre2_2;和_pre1_2;(感谢[@ppettit](https://github.com/ppettit))
-添加了[ejson](http://docs.meteor.com//full/ejson)支持(感谢[@tdamsma](https://github.com/tdamsma))
**版本**0.1.4
-bugfix-fix重新连接顺序(感谢[@ppettit](https://github.com/ppettit))
-错误修复-修复中断更改<;https://github.com/hharnisc/python ddp/commit/5998839866fccfee8a456cb5cbb2559a320f2203d>;(感谢[@ppettit](https://github.com/ppettit))
**版本**0.1.3
-错误修复-关闭的python meteor[第5期](https://github.com/hharnisc/python meteor/issues/5)
**版本**0.1.2
-错误修复-自动重新连接现在可以处理WebSocketException(感谢[@ppettit](https://github.com/ppettit))
**版本**0.1.1
-实现自动重新连接(自动重新连接默认情况下,CT打开)并重新连接事件发射器
**版本**0.1.0
-初始实现,添加调用、订阅和取消订阅功能导入ddpclient
client=ddpclient('ws://127.0.0.1:3000/websocket')
client.connect()
client.close()
`````
**在不自动重新连接的情况下建立连接**
``python
从ddpclient导入ddpclient
client=ddpclient('ws://127.0.0.1:3000/websocket',auto_重新连接=false)
client.connect()
```
**建立连接并使用不同的重新连接频率**
``python
从ddpclient import ddpclient
连接超时=1)
client.connect()
```
**调用远程函数**
``python
from ddpclient import ddpclient
print data
client=ddpclient('ws://127.0.0.1:3000/websocket')
client.connect()
client.call('somefunction',[1,2,3],回调函数)
```
**订阅和取消订阅**
```python
from ddpclient import ddpclient
打印数据
client.connect()
sub id=client.subscribe.subsubsubsubscribe(sub-id)
````
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` class init
uURL-连接到DDP服务器
**关键字参数**
u auto戋u reconnect戋-自动重新连接(默认值:true)
u auto戋u reconnect戋u timeout戋-每隔x秒重新连接(默认值:0.5)
u debug戋-打印大量调试信息(默认值:false)
r/>
在服务器上调用方法
**参数**
u方法-远程服务器方法
u参数-要发送到方法的命令数组
**关键字参数**
u回调-包含返回数据的回调函数,params,callback=none)
subcribe为集合添加/更改/删除事件
**arguments**
\u name撸要订阅的发布的名称
\u params撸要订阅的参数(解析为json)
**关键字参数**
当订阅完成时执行的。
unsubscribe from a collection
**arguments**
下面的文档假设您已经用以下代码实例化了一个客户机:从ddpclient导入ddpclient中的python
骗局客户机。on('connected,connected)
````
>连接的事件回调函数不带任何参数
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_关闭',
````
`socket ` closed` socket ` call back back采用以下参数
\u code-错误代码
\u reason-错误消息
``python
``def reconnectconnectconnected(self):
````````
"重新连接"回拨不接受
>将事件注册到回调函数
``python
defailed failed(colcollection,data):
print'*failed-data:{}'.format(str(data))
```` failed` callbackbackbackbackbackback采用了以下参数
版本smatch
将事件注册到回调函数
如果服务器和客户端无法就要使用的DDP版本达成一致,则会触发此事件,并且此事件是致命错误
`` python
def version\u mismatch(versions):
print'*version mismatch-versions:{}'。format(str(versions))
client.on('version\u mismatch',version\u mism
````
`版本不匹配`回调函数采用以下参数
//35 35 35 35 35 35 35
/>.item项用法:
print''-field{{}{}{{}'.format(key,value)
client.on('added,added)
`````
`added`回调函数采用以下参数
u collection-已被修改的集合
u id-集合项id
u field-项目字段
register{CA的事件llback函数
``python
def changed(self,collection,id,fields,cleared):
print'*changed{}{}{}}。format(collection,id)
表示key,value in fields。items():
print'-field{}{}。format(key,value)
表示key,value in cleared。items():
print'-cleared{}{}。format(key,value)
client.on('changed',changed)
```
`changed`回调接受以下参数
回调函数
`` python
deremoved(collection,id):
print'*remov{{{}{}{{}}.format(collection,id)
client.on('removed,removed)
``` ` `
` remov `回调函数采用了以下参数
//u collection ` ` ` ` ` `
` ` ` ` ` ` ` ` ` ` ` ` ` ` `
` remov ` ` remov ` `全部Of回调
供参考
``python
client.on('已连接,已连接)
client.on('套接字已关闭,已关闭)
client.on('已重新连接,已重新连接)
client.on('失败,已失败)
client.on('版本离子不匹配,版本不匹配)
client.on('added',added)
client.on('changed',changed)
client.on('removed',removed)
````
\collaborators
-[@ppettit](https://github.com/ppettit)
-[@tdamsma](https://github.com/tdamsma)
**安装**
``bash
$pip安装python-ddp
``
**目录**
-[历史沿革]
-[快速入门]
-[使用方法](使用方法)
-[快速入门]
-[快速入门]([快速入门]
-[使用方法]
-[合作者]([合作者]
>
嗨故事
**最新版本**0.1.5
-处理DDP版本_1_2;、_pre2_2;和_pre1_2;(感谢[@ppettit](https://github.com/ppettit))
-添加了[ejson](http://docs.meteor.com//full/ejson)支持(感谢[@tdamsma](https://github.com/tdamsma))
**版本**0.1.4
-bugfix-fix重新连接顺序(感谢[@ppettit](https://github.com/ppettit))
-错误修复-修复中断更改<;https://github.com/hharnisc/python ddp/commit/5998839866fccfee8a456cb5cbb2559a320f2203d>;(感谢[@ppettit](https://github.com/ppettit))
**版本**0.1.3
-错误修复-关闭的python meteor[第5期](https://github.com/hharnisc/python meteor/issues/5)
**版本**0.1.2
-错误修复-自动重新连接现在可以处理WebSocketException(感谢[@ppettit](https://github.com/ppettit))
**版本**0.1.1
-实现自动重新连接(自动重新连接默认情况下,CT打开)并重新连接事件发射器
**版本**0.1.0
-初始实现,添加调用、订阅和取消订阅功能导入ddpclient
client=ddpclient('ws://127.0.0.1:3000/websocket')
client.connect()
client.close()
`````
**在不自动重新连接的情况下建立连接**
``python
从ddpclient导入ddpclient
client=ddpclient('ws://127.0.0.1:3000/websocket',auto_重新连接=false)
client.connect()
```
**建立连接并使用不同的重新连接频率**
``python
从ddpclient import ddpclient
连接超时=1)
client.connect()
```
**调用远程函数**
``python
from ddpclient import ddpclient
client=ddpclient('ws://127.0.0.1:3000/websocket')
client.connect()
client.call('somefunction',[1,2,3],回调函数)
```
**订阅和取消订阅**
```python
from ddpclient import ddpclient
sub id=client.subscribe.subsubsubsubscribe(sub-id)
````
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` class init
uURL-连接到DDP服务器
**关键字参数**
u auto戋u reconnect戋-自动重新连接(默认值:true)
u auto戋u reconnect戋u timeout戋-每隔x秒重新连接(默认值:0.5)
u debug戋-打印大量调试信息(默认值:false)
r/>
在服务器上调用方法
**参数**
u方法-远程服务器方法
u参数-要发送到方法的命令数组
**关键字参数**
u回调-包含返回数据的回调函数,params,callback=none)
subcribe为集合添加/更改/删除事件
**arguments**
\u name撸要订阅的发布的名称
\u params撸要订阅的参数(解析为json)
**关键字参数**
当订阅完成时执行的。
unsubscribe from a collection
**arguments**
下面的文档假设您已经用以下代码实例化了一个客户机:从ddpclient导入ddpclient中的python
骗局客户机。on('connected,connected)
````
>连接的事件回调函数不带任何参数
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_关闭',
````
`socket ` closed` socket ` call back back采用以下参数
\u code-错误代码
\u reason-错误消息
``python
``def reconnectconnectconnected(self):
"重新连接"回拨不接受
>将事件注册到回调函数
``python
defailed failed(colcollection,data):
print'*failed-data:{}'.format(str(data))
```` failed` callbackbackbackbackbackback采用了以下参数
版本smatch
将事件注册到回调函数
如果服务器和客户端无法就要使用的DDP版本达成一致,则会触发此事件,并且此事件是致命错误
`` python
def version\u mismatch(versions):
print'*version mismatch-versions:{}'。format(str(versions))
client.on('version\u mismatch',version\u mism
````
`版本不匹配`回调函数采用以下参数
//35 35 35 35 35 35 35
/>.item项用法:
print''-field{{}{}{{}'.format(key,value)
client.on('added,added)
`````
`added`回调函数采用以下参数
u collection-已被修改的集合
u id-集合项id
u field-项目字段
register{CA的事件llback函数
``python
def changed(self,collection,id,fields,cleared):
print'*changed{}{}{}}。format(collection,id)
表示key,value in fields。items():
print'-field{}{}。format(key,value)
表示key,value in cleared。items():
print'-cleared{}{}。format(key,value)
client.on('changed',changed)
```
`changed`回调接受以下参数
回调函数
`` python
deremoved(collection,id):
print'*remov{{{}{}{{}}.format(collection,id)
client.on('removed,removed)
``` ` `
` remov `回调函数采用了以下参数
//u collection ` ` ` ` ` `
` ` ` ` ` ` ` ` ` ` ` ` ` ` `
` remov ` ` remov ` `全部Of回调
供参考
``python
client.on('已连接,已连接)
client.on('套接字已关闭,已关闭)
client.on('已重新连接,已重新连接)
client.on('失败,已失败)
client.on('版本离子不匹配,版本不匹配)
client.on('added',added)
client.on('changed',changed)
client.on('removed',removed)
````
\collaborators
-[@ppettit](https://github.com/ppettit)
-[@tdamsma](https://github.com/tdamsma)