def __evaluateResponse(self, method, response):
     """ Evaluates the response of the WebDAV server. """
     
     status, reason = response.status, response.reason
     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().strip())
         
         # identify authentication CODE_UNAUTHORIZED, throw appropriate exception
         if status == Constants.CODE_UNAUTHORIZED:
             raise AuthorizationError(reason, status, response.msg["www-authenticate"])
         
         response.close()
         raise WebdavError(reason, status)
     
     if status == Constants.CODE_MULTISTATUS:
         content = response.read()
         ## check for UTF-8 encoding
         try:
             response.root = Parser().parse(content)
         except ExpatError, error:
             errorMessage = "Invalid XML document has been returned.\nReason: '%s'" % str(error.args)
             raise WebdavError(errorMessage)
         try:
             response.msr = MultiStatusResponse(response.root)
         except ResponseFormatError:
             raise WebdavError("Invalid WebDAV response.")
         response.close()
         self.logger.debug("RESPONSE (Multi-Status): " + unicode(response.msr).strip())
Beispiel #2
0
 def __evaluateResponse(self, method, response):
     """ Evaluates the response of the WebDAV server. """
     
     status, reason = response.status, response.reason
     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())
         response.close()
         raise WebdavError(reason, status)
     
     if status == Constants.CODE_MULTISTATUS:
         content = response.read()
         ## check for UTF-8 encodig
         response.root = Parser().parse(content)
         try:
             response.msr = MultiStatusResponse(response.root)
         except ResponseFormatError:
             raise WebdavError("Invalid WebDAV response.")
         response.close()
         self.logger.debug("RESPONSE (Multi-Status): " + unicode(response.msr))
     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())
         response.close()
     return response
Beispiel #3
0
 def __init__(self, filename):
     """
     Load the file and parse it. If the file does not exist, create
     an empty <freevo> node.
     """
     Parser.__init__(self)
     self.filename = filename
     if not vfs.isfile(filename):
         self.tree = XMLnode('freevo')
     else:
         self.tree = None
         cache = vfs.getoverlay(filename + '.raw')
         if os.path.isfile(filename) and os.path.isfile(cache) and \
                os.stat(cache)[stat.ST_MTIME] >= os.stat(filename)[stat.ST_MTIME]:
             self.tree = util.read_pickle(cache)
         if not self.tree:
             f = vfs.open(filename)
             self.tree = self.parse(f)
             f.close()
             if self.tree:
                 util.save_pickle(self.tree, cache)
Beispiel #4
0
 def __init__(self, filename):
     """
     Load the file and parse it. If the file does not exist, create
     an empty <freevo> node.
     """
     Parser.__init__(self)
     self.filename = filename
     if not vfs.isfile(filename):
         self.tree = XMLnode('freevo')
     else:
         self.tree = None
         cache = vfs.getoverlay(filename + '.raw')
         if os.path.isfile(filename) and os.path.isfile(cache) and \
                os.stat(cache)[stat.ST_MTIME] >= os.stat(filename)[stat.ST_MTIME]:
             self.tree = util.read_pickle(cache)
         if not self.tree:
             f = vfs.open(filename)
             self.tree = self.parse(f)
             f.close()
             if self.tree:
                 util.save_pickle(self.tree, cache)