Commit 8c6577e1 by rfkelly0

DAVFS: use response text for error details, not response object itself.

This should make the errors easier to move around, e.g. pickling them and
sending them to a remote process. 
parent 5d76b968
...@@ -38,6 +38,9 @@ from fs.remote import RemoteFileBuffer ...@@ -38,6 +38,9 @@ from fs.remote import RemoteFileBuffer
from fs.contrib.davfs.util import * from fs.contrib.davfs.util import *
from fs.contrib.davfs.xmlobj import * from fs.contrib.davfs.xmlobj import *
import logging
logger = logging.getLogger("fs.contrib.davfs")
import errno import errno
_RETRYABLE_ERRORS = [errno.EADDRINUSE] _RETRYABLE_ERRORS = [errno.EADDRINUSE]
try: try:
...@@ -103,7 +106,7 @@ class DAVFS(FS): ...@@ -103,7 +106,7 @@ class DAVFS(FS):
raise PermissionDeniedError("listdir") raise PermissionDeniedError("listdir")
if resp.status != 207: if resp.status != 207:
msg = "server at %s doesn't speak WebDAV" % (self.url,) msg = "server at %s doesn't speak WebDAV" % (self.url,)
raise RemoteConnectionError("",msg=msg,details=resp) raise RemoteConnectionError("",msg=msg,details=resp.read())
finally: finally:
resp.close() resp.close()
self.url = resp.request_url self.url = resp.request_url
...@@ -223,6 +226,7 @@ class DAVFS(FS): ...@@ -223,6 +226,7 @@ class DAVFS(FS):
except KeyError: except KeyError:
msg = "unsupported protocol: '%s'" % (url.scheme,) msg = "unsupported protocol: '%s'" % (url.scheme,)
raise RemoteConnectionError(msg=msg) raise RemoteConnectionError(msg=msg)
#logger.debug("DAVFS >REQ %s %s/%s",method,url.hostname,url.path)
con = ConClass(url.hostname,url.port,timeout=self.timeout) con = ConClass(url.hostname,url.port,timeout=self.timeout)
self._add_connection(con) self._add_connection(con)
try: try:
...@@ -238,6 +242,7 @@ class DAVFS(FS): ...@@ -238,6 +242,7 @@ class DAVFS(FS):
if self.closed: if self.closed:
raise RemoteConnectionError("",msg="FS is closed") raise RemoteConnectionError("",msg="FS is closed")
resp = con.getresponse() resp = con.getresponse()
#logger.debug("DAVFS <RESP %s %s/%s",method,url.hostname,url.path)
self._cookiejar.extract_cookies(FakeResp(resp),FakeReq(con,url.scheme,url.path)) self._cookiejar.extract_cookies(FakeResp(resp),FakeReq(con,url.scheme,url.path))
except Exception, e: except Exception, e:
self._del_connection(con) self._del_connection(con)
...@@ -650,7 +655,7 @@ class DAVFS(FS): ...@@ -650,7 +655,7 @@ class DAVFS(FS):
return "".join(c.toxml() for c in propNode.childNodes) return "".join(c.toxml() for c in propNode.childNodes)
if ps.status.code == 404: if ps.status.code == 404:
return default return default
raise OperationFailedError("getxattr",details=response) raise OperationFailedError("getxattr",msres.render())
return default return default
def setxattr(self,path,name,value): def setxattr(self,path,name,value):
...@@ -711,14 +716,14 @@ class DAVFS(FS): ...@@ -711,14 +716,14 @@ class DAVFS(FS):
def raise_generic_error(response,opname,path): def raise_generic_error(response,opname,path):
if response.status == 404: if response.status == 404:
raise ResourceNotFoundError(path,details=response) raise ResourceNotFoundError(path,details=response.read())
if response.status in (401,403): if response.status in (401,403):
raise PermissionDeniedError(opname,details=response) raise PermissionDeniedError(opname,details=response.read())
if response.status == 423: if response.status == 423:
raise ResourceLockedError(path,opname=opname,details=response) raise ResourceLockedError(path,opname=opname,details=response.read())
if response.status == 501: if response.status == 501:
raise UnsupportedError(opname,details=response) raise UnsupportedError(opname,details=response.read())
if response.status == 405: if response.status == 405:
raise ResourceInvalidError(path,opname=opname,details=response) raise ResourceInvalidError(path,opname=opname,details=response.read())
raise OperationFailedError(opname,msg="Server Error: %s" % (response.status,),details=response) raise OperationFailedError(opname,msg="Server Error: %s" % (response.status,),details=response.read())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment