datafinder-team team mailing list archive
-
datafinder-team team
-
Mailing list archive
-
Message #00184
[Merge] lp:~btimby/python-webdav-lib/usability into lp:python-webdav-lib
Ben Timby has proposed merging lp:~btimby/python-webdav-lib/usability into lp:python-webdav-lib.
Requested reviews:
DataFinderTeam (datafinder-team)
For more details, see:
https://code.launchpad.net/~btimby/python-webdav-lib/usability/+merge/69337
Some smallchanges to usability.
readProperties() - new argument ignore404 causes missing properties to be ignored for multistatus replies (just return what DOES exist).
uploadContent()/downloadContent() - new argument extra_hdrs, allow additional HTTP headers to be sent.
--
https://code.launchpad.net/~btimby/python-webdav-lib/usability/+merge/69337
Your team DataFinderTeam is requested to review the proposed merge of lp:~btimby/python-webdav-lib/usability into lp:python-webdav-lib.
=== modified file 'src/webdav/Connection.py'
--- src/webdav/Connection.py 2011-02-17 21:38:20 +0000
+++ src/webdav/Connection.py 2011-07-26 17:56:41 +0000
@@ -132,7 +132,7 @@
self.logger.debug("Method: " + method + " Status %d: " % status + reason)
if status >= Constants.CODE_LOWEST_ERROR: # error has occured ?
- self.logger.debug("ERROR Response: " + response.read())
+ self.logger.debug("ERROR Response: " + response.read().strip())
# identify authentication CODE_UNAUTHORIZED, throw appropriate exception
if status == Constants.CODE_UNAUTHORIZED:
@@ -154,12 +154,12 @@
except ResponseFormatError:
raise WebdavError("Invalid WebDAV response.")
response.close()
- self.logger.debug("RESPONSE (Multi-Status): " + unicode(response.msr))
+ self.logger.debug("RESPONSE (Multi-Status): " + unicode(response.msr).strip())
elif method == 'LOCK' and status == Constants.CODE_SUCCEEDED:
response.parse_lock_response()
response.close()
elif method != 'GET' and method != 'PUT':
- self.logger.debug("RESPONSE Body: " + response.read())
+ self.logger.debug("RESPONSE Body: " + response.read().strip())
response.close()
return response
=== modified file 'src/webdav/WebdavClient.py'
--- src/webdav/WebdavClient.py 2010-09-24 23:24:10 +0000
+++ src/webdav/WebdavClient.py 2011-07-26 17:56:41 +0000
@@ -309,7 +309,7 @@
header = lockToken.toHeader()
self.connection.put(self.path, "", extra_hdrs=header)
- def uploadContent(self, content, lockToken=None):
+ def uploadContent(self, content, lockToken=None, extra_hdrs={}):
"""
Write binary data to permanent storage.
@@ -329,7 +329,7 @@
header["Content-length"] = len(content)
else:
header["Content-length"] = 0
-
+ header.update(extra_hdrs)
try:
response = self.connection.put(self.path, content, extra_hdrs=header)
finally:
@@ -353,11 +353,11 @@
header = lockToken.toHeader()
self.connection.putFile(self.path, newFile, header=header)
- def downloadContent(self):
+ def downloadContent(self, extra_hdrs={}):
"""
Read binary data from permanent storage.
"""
- response = self.connection.get(self.path)
+ response = self.connection.get(self.path, extra_hdrs=extra_hdrs)
# TODO: Other interface ? return self.connection.getfile()
return response
@@ -373,19 +373,22 @@
remoteFile.close()
localFile.close()
- def readProperties(self, *names):
+ def readProperties(self, *names, **kwargs):
"""
Reads the given properties.
@param names: a list of property names.
A property name is a (XmlNameSpace, propertyName) tuple.
+ @param ignore404: a boolean flag.
+ Indicates if an error should be raised for missing properties.
@return: a map from property names to DOM Element or String values.
"""
assert names, "Property names are missing."
+ ignore404 = kwargs.pop('ignore404', False)
body = createFindBody(names, self.defaultNamespace)
response = self.connection.propfind(self.path, body, depth=0)
properties = response.msr.values()[0]
- if properties.errorCount > 0:
+ if not ignore404 and properties.errorCount > 0 :
raise WebdavError("Property is missing on '%s': %s" % (self.path, properties.reason), properties.code)
return properties
Follow ups