| 1 |
How to write an interface class |
| 2 |
------------------------------- |
| 3 |
|
| 4 |
(this information might be a little out of date. See data.py for more |
| 5 |
details). |
| 6 |
|
| 7 |
The interface class of davserver is the interface between the actual data |
| 8 |
and the davserver. The davserver will ask this class every time it needs |
| 9 |
information about the underlying data (e.g. a filesystem or a database). |
| 10 |
|
| 11 |
So how do you write such a class? |
| 12 |
|
| 13 |
Simply take the existing class which models a normal unix filesystem |
| 14 |
and change it. You actually have implement the following methods: |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
get_childs(self, uri, filter=None) |
| 19 |
|
| 20 |
This method should return a list of all childs for the |
| 21 |
object specified by the given uri. |
| 22 |
|
| 23 |
The childs should be specified as normal URIs. |
| 24 |
|
| 25 |
|
| 26 |
get_props(self,uri,values=None,all=None,proplist=[]) |
| 27 |
|
| 28 |
This method will be called when the davserver needs information |
| 29 |
about properties for the object specified with the given uri. |
| 30 |
The parameters are as follows: |
| 31 |
|
| 32 |
values -- ?? cannot remember ;-) |
| 33 |
all -- if set to 1 return all properties |
| 34 |
proplist -- alternatively you can give get a list of |
| 35 |
properties to return |
| 36 |
|
| 37 |
The result of this method should be a dictionary of the form |
| 38 |
|
| 39 |
props[propname]=propvalue |
| 40 |
|
| 41 |
Note that in the example class this one is simply a dummy class |
| 42 |
as only DAV properties are handled which have their own methods |
| 43 |
(see below). |
| 44 |
|
| 45 |
|
| 46 |
get_data(self,uri) |
| 47 |
|
| 48 |
This method will be called when the content of an object is needed. |
| 49 |
Thus this method should return a data string. |
| 50 |
|
| 51 |
|
| 52 |
get_dav(self,uri,propname) |
| 53 |
|
| 54 |
This method will be called when the server needs access to a DAV |
| 55 |
property. In the example implementation it will simply delegate it |
| 56 |
to the corresponding _get_dav_<propname> method. You maybe should |
| 57 |
handle it the same way. |
| 58 |
|
| 59 |
|
| 60 |
_get_dav_<propname>(uri) |
| 61 |
|
| 62 |
These methods will be called by get_dav() when the value of a DAV |
| 63 |
property is needed. The defined properties are: |
| 64 |
|
| 65 |
- resourcetype (empty or <collection> if the object is a collection) |
| 66 |
- getcontentlength |
| 67 |
- getcontenttype |
| 68 |
- getlastmodified |
| 69 |
- creationdate |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
put(self,uri,data) |
| 74 |
|
| 75 |
This method will write data into the given object. |
| 76 |
It should return the result code (e.g. 424 if an error occured and |
| 77 |
None if everythin was ok). |
| 78 |
|
| 79 |
|
| 80 |
mkcol(self,uri) |
| 81 |
|
| 82 |
This method will be called when the MKCOL WEBDAV method was received |
| 83 |
by the server. The interface class has to test |
| 84 |
- if the parents of the uri all exists. If not, return 409 |
| 85 |
- if the object already exists. If so, return 405 |
| 86 |
- if it is allowed to create the collection. If not, return 403 |
| 87 |
If everything is ok, then create the new collection (aka directory) |
| 88 |
and return 201. |
| 89 |
|
| 90 |
|
| 91 |
rmcol(self,uri) |
| 92 |
|
| 93 |
This method is called when a collection needs to be removed. |
| 94 |
Only the collection should be removed, no children as the davserver |
| 95 |
is automatically iterating over all children and calling rm/rmcol |
| 96 |
for each of them (because it needs a result code for every deleted |
| 97 |
object). |
| 98 |
If the user is not allowed to delete the collection then an |
| 99 |
403 should be returned |
| 100 |
|
| 101 |
|
| 102 |
rm(self,uri) |
| 103 |
|
| 104 |
This is the same for single objects, the same as above applies. |
| 105 |
|
| 106 |
|
| 107 |
is_collection(self,uri) |
| 108 |
|
| 109 |
This one simply returns 1 if the object specified by the uri |
| 110 |
is an object or 0 if it isn't. |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
So these are basically the methods which need to get implemented. While writing |
| 115 |
this I also noticed some problems: |
| 116 |
|
| 117 |
- the actual user is not know to the interface class. This should be changed as |
| 118 |
it might be important when testing if an action is allowed or not. Also some |
| 119 |
implementations might need a user in order to decide what to return (e.g. |
| 120 |
GROUP.lounge will need this.) |
| 121 |
|
| 122 |
- the return of result codes is not standardized throughout the interface class. |
| 123 |
This should be changed. |
| 124 |
|
| 125 |
- The should be a super interface class to derive from in order to handle some |
| 126 |
common things like get_dav() or property handling in general. Some things |
| 127 |
then also might me moved from propfind.py/devserver.py into this class. |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
As the changes above might break existing code you have been warned with this |
| 132 |
message :) |
| 133 |
|