一个直接的webdav客户端,从easywebdav移植到aiohttp。
aioeasywebdav的Python项目详细描述
此项目作为基于请求的easyWebDav的端口启动( http://github.com/amnong/easywebdav)到python 3.5上的异步。它有 后来又增加了一些新功能。
功能
- 基本身份验证
- 创建目录,删除目录和文件
- 上载和下载文件
- 目录列表
- 支持客户端SSL证书
- 分段下载(同时流中有多个数据块)
- 与owncloud/nextcloud webdav一起使用时的md5校验和验证
- 通过回拨系统进行进度跟踪/报告
安装
使用Distribute安装:
pip install aioeasywebdav
快速启动
import aioeasywebdav loop = asyncio.get_event_loop() # Start off by creating a client object. Username and # password may be omitted if no authentication is needed. webdav = aioeasywebdav.connect('webdav.your-domain.com', username='myuser', password='mypass') # Do some stuff: loop.run_until_complete(webdav.mkdir('some_dir')) loop.run_until_complete(webdav.rmdir('another_dir')) async def fn(): await webdav.download('/remote/path/to/file', '/local/target/file') await webdav.upload('/local/path/to/file', '/remote/target/file') loop.run_until_complete(fn())
客户端对象API
这个api非常简单:
cd(path) ls(path=None) exists(remote_path) mkdir(path, safe=False) mkdirs(path) rmdir(path, safe=False) delete(file_path) upload(local_path_or_fileobj, remote_path) download(remote_path, local_path)
使用客户端SSL证书
webdav = aioeasywebdav.connect('secure.example.net', username='user', password='pass', protocol='https', cert="/path/to/your/certificate.pem") # Do some stuff: print(await webdav.ls())
请注意所有关于“证书”的选项和限制 来自Requests API的参数在此应用为 参数只传递!
开发aioEasyWebDAV
强烈建议使用虚拟环境:
virtualenv --no-site-packages aioeasywebdav_dev source aioeasywebdav_dev/bin/activate
以开发模式安装库:
EASYWEBDAV_DEV=1 python setup.py develop
命令的第一部分使setup.py安装开发 依赖关系,除了正常的依赖关系。
运行测试:
nosetests --with-yanc --nologcapture --nocapture tests
使用WebDAV服务器日志运行测试:
WEBDAV_LOGS=1 nosetests --with-yanc --nologcapture --nocapture -v tests