SleekXMPP是一个优雅的Python库,用于XMPP(也称为Jabber、Google Talk等)。
项目描述
SleekXMPP是Python 2.6/3.1+的MIT许可证XMPP库,并在Kevin Smith、Remko Tronçon和Peter Saint-Andre的《XMPP: definitive guide》的示例中有所展示。如果您是从阅读definitive guide到达这里的,请参阅有关将示例更新到SleekXMPP最新版本的说明。
SleekXMPP的设计目标和理念是
- 依赖项数量少
SleekXMPP的安装和使用应该尽可能简单,无需处理长的依赖链。
为了减少依赖项的数量,SleekXMPP在thirdparty目录中包含了一些第三方模块。从该模块导入时,首先尝试导入已安装的现有版本,然后加载包装版本,如果可能的话。
- 每个XEP都是一个插件
遵循Python的“包含电池”方法,目标是提供对当前所有活动XEPs(最终和草案)的支持。由于XEP支持是通过易于创建的插件实现的,因此希望也为实现和创建实验性XEPs提供一个坚实的基础。
- 令人愉悦的工作体验
尽可能多,SleekXMPP应允许使用合理的默认值和适当的抽象来“直接工作”。XML可以很丑陋,但不必如此。
获取代码
从PyPI获取最新稳定版本
pip install sleekxmpp
SleekXMPP的最新源代码可以在Github上找到。发布版本可以在master分支中找到,而最新开发版本在develop分支中。
安装DNSPython
如果您使用Python3并希望使用dnspython,您将需要检出并安装python3分支
git clone http://github.com/rthalley/dnspython cd dnspython git checkout python3 python3 setup.py install
讨论
有一个邮件列表和XMPP聊天室可供讨论和使用SleekXMPP的帮助。
文档和测试
文档可以在代码中找到,也可以在/docs中的Sphinx项目中找到。要生成Sphinx文档,请按照以下命令操作。HTML输出将在docs/_build/html中。
cd docs make html open _build/html/index.html
运行SleekXMPP的测试套件
python testall.py
SleekXMPP样板
使用SleekXMPP的项目通常会遵循设置客户端/组件连接和配置的基本模式。以下是SleekXMPP项目所需的样板文件的精髓。有关SleekXMPP项目的更详细的原型,请参阅文档或示例目录。
import logging from sleekxmpp import ClientXMPP from sleekxmpp.exceptions import IqError, IqTimeout class EchoBot(ClientXMPP): def __init__(self, jid, password): ClientXMPP.__init__(self, jid, password) self.add_event_handler("session_start", self.session_start) self.add_event_handler("message", self.message) # If you wanted more functionality, here's how to register plugins: # self.register_plugin('xep_0030') # Service Discovery # self.register_plugin('xep_0199') # XMPP Ping # Here's how to access plugins once you've registered them: # self['xep_0030'].add_feature('echo_demo') # If you are working with an OpenFire server, you will # need to use a different SSL version: # import ssl # self.ssl_version = ssl.PROTOCOL_SSLv3 def session_start(self, event): self.send_presence() self.get_roster() # Most get_*/set_* methods from plugins use Iq stanzas, which # can generate IqError and IqTimeout exceptions # # try: # self.get_roster() # except IqError as err: # logging.error('There was an error getting the roster') # logging.error(err.iq['error']['condition']) # self.disconnect() # except IqTimeout: # logging.error('Server is taking too long to respond') # self.disconnect() def message(self, msg): if msg['type'] in ('chat', 'normal'): msg.reply("Thanks for sending\n%(body)s" % msg).send() if __name__ == '__main__': # Ideally use optparse or argparse to get JID, # password, and log level. logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s') xmpp = EchoBot('somejid@example.com', 'use_getpass') xmpp.connect() xmpp.process(block=True)
致谢
- 主要作者: Nathan Fritz
-
Nathan也是XMPPHP和Seesmic-AS3-XMPP的作者,并且曾是XMPP理事会的成员。
- 合著者: Lance Stout
- 贡献者
Brian Beggs (macdiesel)
Dann Martens (dannmartens)
Florent Le Coz (louiz)
Kevin Smith (Kev,http://kismith.co.uk)
Remko Tronçon (remko,http://el-tramo.be)
Te-jé Rogers (te-je)
Thom Nichols (tomstrummer)
项目详情
sleekxmpp-1.3.3.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d213c1de71d92505f95ced0460ee0f84fdc4ddcacb7d7dd343739ed4028e5569 |
|
MD5 | 92f51b09378e7ff74874f4914a8a1018 |
|
BLAKE2b-256 | 13ca2a73521df7696b4cf9a9820cd61097c1c88cbb9da67a712146e622426ca1 |