--
MikealRogers - 05 Feb 2007
Installing davclient
davclient can be installed via python setuptools
easy_install.
It requires either python2.5 or python2.4 with ElementTree installed.
The source is all avaliable at
http://svn.osafoundation.org/tools/davclient/
Using davclient
import davclient
client = davclient.DAVClient('http://www.example-dav-server.com')
or for ssl
client = davclient.DAVClient('https://www.example-dav-server.com')
Authentication
You can set basic auth for the duration of the use of your client instance by calling client.set_basic_auth('user', 'pass')
client.set_basic_auth('username', 'password')
Setting Headers
You can set a specific header for the duration of the use of your client instance by modifying client.headers dictionary.
client.headers['new_header_for_session'] = 'useful_example'
Calling HTTP Methods with DAVClient instance
Call dav method on client as attribute method.
All methods optionally support a "headers" keyword. When called this will add any additionally specified headers to request.
- client.get(path, headers=None)
- HTTP GET method. Returns string body.
- client.head(path, headers=None)
- HTTP HEAD method.
- client.put(path, body=None, f=None, headers=None)
- HTTP PUT method. Takes either a string body or an open file object.
- client.post(path, body=None, headers=None)
- HTTP POST method. Takes string body. -- A future release will support a multipart post api.
- client.mkcol(path, headers=None)
- HTTP MKCOL method. Takes a single path as the collection to be created.
- client.makecollection = client.mkcol
- makecollection is a pointer to mkcol
- client.delete(path, headers=None)
- HTTP DELETE method. Takes a single path as the resource to be removed.
- client.copy(source, destination, body=None, depth='infinity', overwrite=True, headers=None)
- HTTP COPY method. Takes a resource path for source and destination to be copied. Default depth is infinity but can be optionally change. Overwrite defaults to True but can be optionally changed.
- client.copy_collection(source, destination, depth='infinity', overwrite=True, headers=None)
- HTTP COPY method on collection. Takes a resource path for source and destination collection to be copied. Default depth is infinity but can be optionally change. Overwrite defaults to True but can be optionally changed.
- client.move(source, destination, body=None, depth='infinity', overwrite=True, headers=None)
- HTTP MOVE method. Takes a resource path for source and destination to be copied. Default depth is infinity but can be optionally change. Overwrite defaults to True but can be optionally changed.
- client.move_collection(source, destination, depth='infinity', overwrite=True, headers=None)
- HTTP MOVE method on collection. Takes a resource path for source and destination to be copied. Default depth is infinity but can be optionally change. Overwrite defaults to True but can be optionally changed.
- client.propfind(path, properties='allprop', namespace='DAV:', depth=None, headers=None)
- HTTP PROPFIND method. properties defaults to "allprop" but can optionally be changed. Default property namespace is "DAV:" but can be optionally changed. Returns a dictionary of the properties found. Dict keys ommit namespace if they are in the "DAV:" namespace, otherwise the keys will be '{http://example.com/ns}key'.
- client.propatch(path, set_props=None, remove_props=None, namespace='DAV:', headers=None)
- HTTP PROPATCH method. Takes an a dict for set_props or list for remove_props. Default namespace for properties is "DAV:" but can be optionally changed.
- client.set_lock(path, owner, locktype='exclusive', lockscope='write', depth=None, headers=None)
- HTTP LOCK method set for specified user.
- client.refresh_lock(path, token, headers=None)
- HTTP LOCK method refreshed for specified user.
- client.unlock(path, token, headers=None)
- HTTP UNLOCK on resource for token.
Niceties
The HTTPResponse instance (defined in python stdlib httplib.HTTPResonse ) is set as an attribute of the client after each successful request.
client.response
All HTTPResponse attributes are addressable. HTTPResponse.read() has already been called and it's result is assigned to client.response.body.
client.response.status
client.response.getheaders()
client.response.body
DAVClient attempts to create an ElementTree object from the response body string. If successfull the object is addressable under client.response.tree.
client.response.tree
<verbatim></verbatim>
<nop>