定义来自 `zope.app.file` 模块的文件和图像对象的WebDAV数据模型。
项目描述
zope.app.file webdav集成
>>> import z3c.etree >>> from zope.app.file.file import File>>> etree = z3c.etree.getEngine()
在根目录中创建一个名为textfile.txt的内容对象。
>>> f = File('%s\n' %('x' * 10) * 5, 'text/plain')
>>> getRootFolder()['testfile.txt'] = f
GET
为了使WebDAV客户端能够获取符合DAV资源的数据,需要设置内容对象的默认视图。
>>> resp = http("""
... GET /testfile.txt HTTP/1.1
... """, handle_errors = False)
>>> resp.getStatus()
200
>>> resp.getHeader('content-type')
'text/plain'
>>> resp.getHeader('content-length')
'55'
>>> print resp.getBody()
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
PUT
???
PROPFIND
查询文件对象的WebDAV数据模型。以下属性目前构成了zope.file的数据模型
{DAV:}creationdate
{DAV:}displayname
{DAV:}getcontentlength
{DAV:}getcontenttype
{DAV:}getlastmodified
{DAV:}resourcetype
查询测试文件的全部属性。
>>> resp = webdav(""" ... PROPFIND /testfile.txt HTTP/1.1 ... """, handle_errors = False)>>> print resp.getBody() #doctest:+XMLDATA <multistatus xmlns="DAV:"> <response> <href>https:///testfile.txt</href> <propstat> <prop> <creationdate /> <displayname /> <getlastmodified /> <getcontenttype>text/plain</getcontenttype> <getcontentlength>55</getcontentlength> <resourcetype /> </prop> <status>HTTP/1.1 200 Ok</status> </propstat> </response> </multistatus>
在文件对象上,{DAV:}getetag 和 {DAV:}getcontentlanguage 属性(尚未)定义。
>>> resp.getMSProperty('https:///testfile.txt', '{DAV:}getetag')
Traceback (most recent call last):
...
KeyError: "'{DAV:}getetag' property not found for resource https:///testfile.txt (200)"
>>> resp.getMSProperty(
... 'https:///testfile.txt', '{DAV:}getcontentlanguage')
Traceback (most recent call last):
...
KeyError: "'{DAV:}getcontentlanguage' property not found for resource https:///testfile.txt (200)"
PROPPATCH
我们需要登录才能更新属性。
>>> reqbody = """<propertyupdate xmlns="DAV:">
... <set>
... <prop>
... <displayname>Test title</displayname>
... </prop>
... </set>
... </propertyupdate>"""
>>> resp = webdav("""
... PROPPATCH /testfile.txt HTTP/1.1
... Content-Type: application/xml
... Content-Length: %d
...
... %s""" %(len(reqbody), reqbody))
>>> resp.getStatus()
401
现在更新文件的标题。
>>> resp = webdav("""
... PROPPATCH /testfile.txt HTTP/1.1
... Authorization: Basic mgr:mgrpw
... Content-Type: application/xml
... Content-Length: %d
...
... %s""" %(len(reqbody), reqbody), handle_errors = False)
>>> resp.getStatus()
207
>>> resp.getHeader('content-type')
'application/xml'
>>> print resp.getBody() #doctest:+XMLDATA
<multistatus xmlns="DAV:">
<response>
<href>https:///testfile.txt</href>
<propstat>
<prop>
<displayname />
</prop>
<status>HTTP/1.1 200 Ok</status>
</propstat>
</response>
</multistatus>
使用PROPFIND检索displayname属性,并注意差异。
>>> reqbody = """<propfind xmlns="DAV:">
... <prop>
... <displayname />
... </prop>
... </propfind>
... """
>>> resp = webdav("""
... PROPFIND /testfile.txt HTTP/1.1
... Content-type: application/xml
... Content-Length: %d
...
... %s""" %(len(reqbody), reqbody), handle_errors = False)
>>> resp.getStatus()
207
>>> resp.getHeader('content-type')
'application/xml'
>>> print resp.getBody() #doctest:+XMLDATA
<multistatus xmlns="DAV:">
<response>
<href>https:///testfile.txt</href>
<propstat>
<prop>
<displayname>Test title</displayname>
</prop>
<status>HTTP/1.1 200 Ok</status>
</propstat>
</response>
</multistatus>
{DAV:}getcontentlength 属性是一个实时属性,因此我们无法修改它。
>>> reqbody = """<propertyupdate xmlns="DAV:">
... <set>
... <prop>
... <getcontentlength>24</getcontentlength>
... </prop>
... </set>
... </propertyupdate>"""
>>> resp = webdav("""
... PROPPATCH /testfile.txt HTTP/1.1
... Authorization: Basic mgr:mgrpw
... Content-type: application/xml
... Content-length: %d
...
... %s""" %(len(reqbody), reqbody))
>>> resp.getStatus()
207
>>> resp.getHeader('content-type')
'application/xml'
>>> print resp.getBody() #doctest:+XMLDATA
<multistatus xmlns="DAV:">
<response>
<href>https:///testfile.txt</href>
<propstat>
<prop>
<getcontentlength />
</prop>
<status>HTTP/1.1 403 Forbidden</status>
</propstat>
</response>
</multistatus>
不可见属性
在我们的资源上设置两个已死属性。
>>> reqbody = """<propertyupdate xmlns="DAV:"> ... <set> ... <prop> ... <E:prop1 xmlns:E="examplens:">PROPERTY 1</E:prop1> ... <E:prop2 xmlns:E="examplens:">PROPERTY 2</E:prop2> ... </prop> ... </set> ... </propertyupdate> ... """ >>> resp = webdav(""" ... PROPPATCH /testfile.txt HTTP/1.1 ... Authorization: Basic mgr:mgrpw ... Content-type: application/xml ... Content-length: %d ... ... %s""" %(len(reqbody), reqbody), handle_errors = True)>>> resp.getStatus() 207 >>> resp.getHeader('content-type') 'application/xml' >>> print resp.getBody() #doctest:+XMLDATA <multistatus xmlns="DAV:"> <response> <href>https:///testfile.txt</href> <propstat> <prop> <ns1:prop1 xmlns:ns1="examplens:" /> <ns1:prop2 xmlns:ns1="examplens:" /> </prop> <status>HTTP/1.1 200 Ok</status> </propstat> </response> </multistatus>
查询这些新属性。
>>> reqbody = """<propfind xmlns="DAV:">
... <prop xmlns:E="examplens:" >
... <E:prop1 />
... <E:prop2 />
... </prop>
... </propfind>
... """
>>> resp = webdav("""
... PROPFIND /testfile.txt HTTP/1.1
... Content-type: application/xml
... Content-length: %d
...
... %s""" %(len(reqbody), reqbody))
>>> resp.getStatus()
207
>>> resp.getHeader('content-type')
'application/xml'
>>> print resp.getBody() #doctest:+XMLDATA
<multistatus xmlns="DAV:">
<response>
<href>https:///testfile.txt</href>
<propstat>
<prop>
<E:prop1 xmlns:E="examplens:">PROPERTY 1</E:prop1>
<E:prop2 xmlns:E="examplens:">PROPERTY 2</E:prop2>
</prop>
<status>HTTP/1.1 200 Ok</status>
</propstat>
</response>
</multistatus>
更新第一个属性并删除第二个。
>>> reqbody = """<propertyupdate xmlns="DAV:">
... <set>
... <prop>
... <E:prop1 xmlns:E="examplens:">Only opaque property</E:prop1>
... </prop>
... </set>
... <remove>
... <prop>
... <E:prop2 xmlns:E="examplens:" />
... </prop>
... </remove>
... </propertyupdate>"""
>>> resp = webdav("""
... PROPPATCH /testfile.txt HTTP/1.1
... Authorization: Basic mgr:mgrpw
... Content-type: application/xml
... Content-length: %d
...
... %s""" %(len(reqbody), reqbody))
>>> resp.getStatus()
207
>>> resp.getHeader('content-type')
'application/xml'
>>> print resp.getBody() #doctest:+XMLDATA
<multistatus xmlns="DAV:">
<response>
<href>https:///testfile.txt</href>
<propstat>
<prop>
<E:prop1 xmlns:E="examplens:" />
<E:prop2 xmlns:E="examplens:" />
</prop>
<status>HTTP/1.1 200 Ok</status>
</propstat>
</response>
</multistatus>
现在检查不可见属性是否已成功更新。
>>> reqbody = """<propfind xmlns="DAV:">
... <prop xmlns:E="examplens:" >
... <E:prop1 />
... <E:prop2 />
... </prop>
... </propfind>
... """
>>> resp = webdav("""
... PROPFIND /testfile.txt HTTP/1.1
... Content-type: application/xml
... Content-length: %d
...
... %s""" %(len(reqbody), reqbody))
>>> resp.getStatus()
207
>>> resp.getHeader('content-type')
'application/xml'
>>> print resp.getBody() #doctest:+XMLDATA
<multistatus xmlns="DAV:">
<response>
<href>https:///testfile.txt</href>
<propstat>
<prop>
<ns1:prop1 xmlns:ns1="examplens:">Only opaque property</ns1:prop1>
</prop>
<status>HTTP/1.1 200 Ok</status>
</propstat>
<propstat>
<prop>
<ns1:prop2 xmlns:ns1="examplens:" />
</prop>
<status>HTTP/1.1 404 Not Found</status>
</propstat>
</response>
</multistatus>
z3c.davapp.zopeappfile中的变更
项目详情
下载文件
下载适用于您平台的应用程序。如果您不确定选择哪一个,请了解有关安装包的更多信息。
源分发
z3c.davapp.zopeappfile-1.0b1.tar.gz (4.8 kB 查看哈希值)
关闭
z3c.davapp.zopeappfile-1.0b1.tar.gz的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 41e2cef0c20715bb5c5b6a6808cb30fa58133b87f6f85a67f02bd0a273b6b7e7 |
|
| MD5 | d485cc18881bdbbb7fd5ee6f3936dee3 |
|
| BLAKE2b-256 | dcce0a2430cad5cbb0b02da38148e8e99e35cc81a72c0f76c950fb670e905034 |