def __init__(self, headers): self.expires = None self.mtime = None self.length = 0 self.start = 0 self.size = 0 self.mimeType = None headers = InsensitiveDict(headers) encoding = headers.get("Transfer-Encoding", None) if encoding == 'chunked': raise errors.FlumotionError("Chunked transfer not supported") expires = headers.get("Expires", None) if expires is not None: try: self.expires = http.stringToDatetime(expires) except: self.expires = 0 lastmod = headers.get("Last-Modified", None) if lastmod is not None: self.mtime = http.stringToDatetime(lastmod) range = headers.get("Content-Range", None) length = headers.get("Content-Length", None) if range is not None: start, end, total = http.parseContentRange(range) self.start = start self.length = total if length is not None: self.size = int(length) else: self.size = end - start elif length is not None: self.length = int(length) self.size = int(length) else: raise errors.FlumotionError("Can't get length/size from headers", headers) ctype = headers.get("Content-Type", None) if ctype is not None: self.mimeType, _pdict = cgi.parse_header(ctype)
def genDef(): if self.__first: self.__first = False return defer.fail(errors.FlumotionError()) else: return defer.succeed(None)
def runInWorker(self, workerName, moduleName, functionName, *args, **kwargs): """ Run the given function and arguments on the selected worker. The given function should return a L{messages.Result}. @param workerName: name of the worker to run the function in @type workerName: string @param moduleName: name of the module where the function is found @type moduleName: string @param functionName: name of the function to run @type functionName: string @returns: a deferred firing the Result's value. @rtype: L{twisted.internet.defer.Deferred} """ self.debug('runInWorker(moduleName=%r, functionName=%r)' % (moduleName, functionName)) admin = self._adminModel if not admin: self.warning('skipping runInWorker, no admin') return defer.fail(errors.FlumotionError('no admin')) if not workerName: self.warning('skipping runInWorker, no worker') return defer.fail(errors.FlumotionError('no worker')) def callback(result): self.debug('runInWorker callbacked a result') self.clear_msg(functionName) if not isinstance(result, messages.Result): msg = messages.Error(T_( N_("Internal error: could not run check code on worker.")), debug=( 'function %r returned a non-Result %r' % (functionName, result))) self.add_msg(msg) self.taskFinished(True) raise errors.RemoteRunError(functionName, 'Internal error.') for m in result.messages: self.debug('showing msg %r' % m) self.add_msg(m) if result.failed: self.debug('... that failed') self.taskFinished(True) raise errors.RemoteRunFailure(functionName, 'Result failed') self.debug('... that succeeded') self.taskFinished() return result.value def errback(failure): self.debug('runInWorker errbacked, showing error msg') if failure.check(errors.RemoteRunError): debug = failure.value else: debug = "Failure while running %s.%s:\n%s" % ( moduleName, functionName, failure.getTraceback()) msg = messages.Error(T_( N_("Internal error: could not run check code on worker.")), debug=debug) self.add_msg(msg) self.taskFinished(True) raise errors.RemoteRunError(functionName, 'Internal error.') self.waitForTask('run in worker: %s.%s(%r, %r)' % (moduleName, functionName, args, kwargs)) d = admin.workerRun(workerName, moduleName, functionName, *args, **kwargs) d.addErrback(errback) d.addCallback(callback) return d
def checkMiss(_): if (_ == "cacheMiss"): return raise errors.FlumotionError("an error")