コード例 #1
0
ファイル: strategy_base.py プロジェクト: faroncoder/flumotion
    def abort(self):
        """
        After calling this method the session will just stop caching
        and return None when trying to read. Used when pipelining is wanted.
        """
        if self._state < self.REQUESTING or self._state >= self.CACHED:
            return

        self.log("Aborting caching session for %s", self.url)

        self.strategy._onSessionCanceled(self)
        self.cache_stats.onCopyCancelled(self.size, self._bytes)

        self._close()

        error = fileprovider.FileError("Caching aborted")
        self._fireError(error)

        if self._request:
            self.debug("Caching aborted for %s", self.url)
            self._request.cancel()
            self._request = None
        else:
            self.debug("Caching aborted before starting to cache")

        self._state = self.ABORTED
コード例 #2
0
ファイル: strategy_base.py プロジェクト: faroncoder/flumotion
 def streamNotAvailable(self, getter, code, message):
     self.log("Stream to be cached is not available: %s", message)
     self._close()
     if code == common.STREAM_NOTFOUND:
         self._error(fileprovider.NotFoundError(message))
     elif code == common.STREAM_FORBIDDEN:
         self._error(fileprovider.AccessError(message))
     else:
         self._error(fileprovider.FileError(message))
コード例 #3
0
ファイル: strategy_base.py プロジェクト: faroncoder/flumotion
    def onInfo(self, getter, info):
        if self._state == self.BUFFERING:
            # We are resuming while waiting for a temporary file,
            # so we still don't want to accumulate data
            self._request.pause()
            return

        if self._state != self.REQUESTING:
            # Already canceled, or recovering from disconnection
            return

        if info.size != (info.length - self._bytes):
            self.log("Unexpected stream size: %s / %s bytes "
                     "(Already got %s bytes)",
                     info.size, info.length, self._bytes)
            self._close()
            msg = "Unexpected resource size: %d" % info.size
            self._error(fileprovider.FileError(msg))
            return

        self._state = self.BUFFERING

        self.mimeType = self.mimetypes.fromPath(self.url.path)
        self.mtime = info.mtime
        self.size = info.size

        self.log("Caching session with type %s, size %s, mtime %s for %s",
                 self.mimeType, self.size, self.mtime, self.url)

        self._file = StringIO() # To wait until we got the real one

        self.log("Requesting temporary file for %s", self.url)
        d = self.strategy.cachemgr.newTempFile(self.url.path, info.size,
                                               info.mtime)

        # But we don't want to accumulate data
        # but it is possible to receive a small amount of data
        # even after calling pause(), so we need buffering.
        self._request.pause()

        # We have got meta data, so callback
        self._fireInfo(self)
        self._fireStarted(self)

        self.debug("Start buffering %s", self.url)
        d.addCallback(self._gotTempFile)
コード例 #4
0
ファイル: strategy_base.py プロジェクト: faroncoder/flumotion
    def serverError(self, getter, code, message):
        assert self._deferred is not None, "Not retrieving anything"
        if code == common.RANGE_NOT_SATISFIABLE:
            # Simulate EOF
            self._deferred.callback("")
            self._cleanup()
            return
        if code in (common.SERVER_DISCONNECTED, common.SERVER_TIMEOUT):
            self.warning("Block request error: %s (%s)", message, code)
            if self._resumes > 0:
                self._resumes -= 1
                self.debug("Resuming block retrieval from offset %d "
                           "with size %d (%d tries left)",
                           self._offset, self._size, self._resumes)

                self._retrieve()
                return
            self.debug("Too much resuming intents, stopping "
                       "after %d of %d", self._offset, self._size)
        self._deferred.errback(fileprovider.FileError(message))
        self._cleanup()
コード例 #5
0
 def _filterErrors(self, failure):
     if failure.check(strategy_base.ConditionError):
         raise fileprovider.FileError(failure.getErrorMessage())
     return failure