def copyFile(self, path, producer): """ Copy a file to this machine. """ fh = open(path, 'wb', 0) #from StringIO import StringIO #fh = StringIO() consumer = FileConsumer(fh) consumer.registerProducer(producer, True) return producer.startProducing(consumer)
def writeFile_cb(data): # path = <OwnerPBoxId>/<FileId> if not os.path.exists(str(pboxid)): os.mkdir(str(pboxid)) file = open(str(pboxid) + "/" + str(data[0][0]), "w") prod = FD2FileProducer(request) cons = FileConsumer(file) cons.registerProducer(prod, True) d = prod.startProducing(cons) d.addCallback(finishRequest_cb, file) return NOT_DONE_YET
def writeFile_cb(data): # path = <OwnerPBoxId>/<FileId> if not os.path.exists(str(pboxid)): os.mkdir(str(pboxid)) file = open(str(pboxid) + "/" + str(data[0][0]) ,"w") prod = FD2FileProducer(request) cons = FileConsumer(file) cons.registerProducer(prod, True) d = prod.startProducing(cons) d.addCallback(finishRequest_cb, file) return NOT_DONE_YET
def handleGetShared_cb(response, f): finished = Deferred() finished.addCallback(self.writeFile_cb, s) cons = FileConsumer(f) response.deliverBody(FileDownload(finished, cons)) print "Downloading file..." return finished
def writeFile_cb(data, ownerid): if len(data) != 0: error = { 'status': {'error': "Invalid Request", 'message': "File unreachable."} } request.write(json.dumps(error, sort_keys=True, encoding="utf-8")) request.finish() return # path = <OwnerPBoxId>/<FileId> file = open(str(ownerid) + "/" + fileid ,"w") prod = FD2FileProducer(request) cons = FileConsumer(file) cons.registerProducer(prod, True) d = prod.startProducing(cons) d.addCallback(finishRequest_cb, file) return NOT_DONE_YET
def cbRequest(response, file): print 'Response version:', response.version print 'Response code:', response.code print 'Response phrase:', response.phrase print 'Response headers:' print pformat(list(response.headers.getAllRawHeaders())) finished = Deferred() cons = FileConsumer(file) response.deliverBody(FileDownload(finished, cons)) return finished
def writeFile_cb(data, ownerid): if len(data) != 0: error = { 'status': { 'error': "Invalid Request", 'message': "File unreachable." } } request.write( json.dumps(error, sort_keys=True, encoding="utf-8")) request.finish() return # path = <OwnerPBoxId>/<FileId> file = open(str(ownerid) + "/" + fileid, "w") prod = FD2FileProducer(request) cons = FileConsumer(file) cons.registerProducer(prod, True) d = prod.startProducing(cons) d.addCallback(finishRequest_cb, file) return NOT_DONE_YET