Attention

You are looking at outdated documentation for version 2.x. A newer version is available.

wsgidav.samples.virtual_dav_provider

Description

Sample implementation of a DAV provider that provides a browsable, multi-categorized resource tree.

Note that this is simply an example with no concrete real world benefit. But it demonstrates some techniques to customize WsgiDAV.

Compared to a published file system, we have these main differences:

  1. A resource like My doc 1 has several attributes like key, orga, tags, status, description. Also there may be a list of attached files.
  2. These attributes are used to dynamically create a virtual hierarchy. For example, if status is draft, a collection <share>/by_status/draft/ is created and the resource is mapped to <share>/by_status/draft/My doc 1.
  3. The resource My doc 1 is rendered as a collection, that contains some virtual descriptive files and the attached files.
  4. The same resource may be referenced using different paths For example <share>/by_tag/cool/My doc 1, <share>/by_tag/hot/My doc 1, and <share>/by_key/1 map to the same resource. Only the latter is considered the real-path, all others are virtual-paths.
  5. The attributes are exposed as live properties, like “{virtres:}key”, “{virtres:}tags”, and “{virtres:}description”. Some of them are even writable. Note that modifying an attribute may also change the dynamically created tree structure. For example changing “{virtres:}status” from ‘draft’ to ‘published’ will make the resource appear as <share>/by_status/published/My doc 1.
  6. This provider implements native delete/move/copy methods, to change the semantics of these operations for the virtual ‘/by_tag/’ collection. For example issuing a DELETE on <share>/by_tag/cool/My doc 1 will simply remove the ‘cool’ tag from that resource.
  7. Virtual collections and artifacts cannot be locked. However a resource can be locked. For example locking <share>/by_tag/cool/My doc 1 will also lock <share>/by_key/1.
  8. Some paths may be hidden, i.e. by_key is not browsable (but can be referenced) TODO: is this WebDAV compliant?

The database is a simple hard coded variable _resourceData, that contains a list of resource description dictionaries.

A resource is served as an collection, which is generated on-the-fly and contains some virtual files (artifacts).

In general, a URL is interpreted like this:

<share>/<category-type>/<category-key>/<resource-name>/<artifact-name>

An example layout:

<share>/
    by_tag/
        cool/
            My doc 1/
                .Info.html
                .Info.txt
                .Description.txt
                MySpec.pdf
                MySpec.doc
            My doc 2/
        hot/
            My doc 1/
            My doc 2/
        nice/
            My doc 2/
            My doc 3
    by_orga/
        development/
            My doc 3/
        marketing/
            My doc 1/
            My doc 2/
    by_status/
        draft/
            My doc 2
        published/
            My doc 1
            My doc 3
    by_key/
        1/
        2/
        3/

When accessed using WebDAV, the following URLs both return the same resource ‘My doc 1’:

<share>/by_tag/cool/My doc 1
<share>/by_tag/hot/My doc 1
<share>/by_key/1

Classes

CategoryCollection(path, environ, catType) Resolve ‘/catType/cat’ URLs, for example ‘/by_tag/cool’.
CategoryTypeCollection(path, environ) Resolve ‘/catType’ URLs, for example ‘/by_tag’.
RootCollection(environ) Resolve top-level requests ‘/’.
VirtualArtifact(path, environ, data) A virtual file, containing resource descriptions.
VirtualResFile(path, environ, data, filePath) Represents an existing file, that is a member of a VirtualResource.
VirtualResource(path, environ, data) A virtual ‘resource’, displayed as a collection of artifacts and files.
VirtualResourceProvider() DAV provider that serves a VirtualResource derived structure.

Other Members

BUFFER_SIZE This is a dummy ‘database’, that serves as an example source for the VirtualResourceProvider.
DAVCollection(path, environ) A DAVCollection is a _DAVResource, that has members (like a ‘folder’ on a filesystem).
DAVError(statusCode[, contextinfo, …]) General error class that is used to signal HTTP and WEBDAV errors.
DAVNonCollection(path, environ) A DAVNonCollection is a _DAVResource, that has content (like a ‘file’ on a filesystem).
DAVProvider() Abstract base class for DAV resource providers.
FILE_FOLDER str(object=’‘) -> string
HTTP_FORBIDDEN int(x=0) -> int or long int(x, base=10) -> int or long
HTTP_INTERNAL_ERROR int(x=0) -> int or long int(x, base=10) -> int or long
PRECONDITION_CODE_ProtectedProperty str(object=’‘) -> string
compat Tool functions to support Python 2 and 3.
joinUri(uri, *segments) Append segments to URI.
os OS routines for NT or Posix depending on what system we’re on.
stat Constants/functions for interpreting results of os.stat() and os.lstat().
util Miscellaneous support functions for WsgiDAV.