当前位置: 首页>>代码示例>>Python>>正文


Python basic.FileSender类代码示例

本文整理汇总了Python中twisted.protocols.basic.FileSender的典型用法代码示例。如果您正苦于以下问题:Python FileSender类的具体用法?Python FileSender怎么用?Python FileSender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileSender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_GET

    def render_GET(self, request):
        #log.debug("request from %s: %s" % (self.userid, request.args))
        if 'f' in request.args:
            fn = request.args['f'][0]
            info = self.fileserver.storage.get_extra(fn, self.userid)
            if info:
                (filename, mime, md5sum) = info
                log.debug("sending file type %s, path %s, md5sum %s" % (mime, filename, md5sum))
                genfilename = utils.generate_filename(mime)
                request.setHeader('content-type', mime)
                request.setHeader('content-length', os.path.getsize(filename))
                request.setHeader('content-disposition', 'attachment; filename="%s"' % (genfilename))
                request.setHeader('x-md5sum', md5sum)

                # stream file to the client
                fp = open(filename, 'rb')
                d = FileSender().beginFileTransfer(fp, request)
                def finished(ignored):
                    fp.close()
                    request.finish()
                d.addErrback(err).addCallback(finished)
                return server.NOT_DONE_YET

            # file not found in extra storage
            else:
                return self.not_found(request)

        return self.bad_request(request)
开发者ID:BillTheBest,项目名称:pyserver,代码行数:28,代码来源:fileserver.py

示例2: sendFile

def sendFile(request, filename, tb_path, ctype):
    """Send file to user.

    Send file to user using producers and consumers system.

    :param: filename (string)
    :param: filepath (string)
    :param: ctype (string) the value for content-type HTTP header

    """
    request.setHeader(b'content-type', ctype)
    request.setHeader(
        b'content-disposition', 'attachment; filename=%s' %
        filename
    )

    fp = FilePath(tb_path).child(filename).open()

    d = FileSender().beginFileTransfer(fp, request)

    def cbFinished(ignored):
        fp.close()
        request.finish()

    d.addErrback(err).addCallback(cbFinished)
开发者ID:DaveDaCoda,项目名称:Tor2web,代码行数:25,代码来源:gettor.py

示例3: render_GET

    def render_GET(self, request):
        # no auth here on purpose, to allow anyone to view, even across home
        # servers.

        # TODO: A little crude here, we could do this better.
        filename = request.path.split('/')[-1]
        # be paranoid
        filename = re.sub("[^0-9A-z.-_]", "", filename)

        file_path = self.directory + "/" + filename

        logger.debug("Searching for %s", file_path)

        if os.path.isfile(file_path):
            # filename has the content type
            base64_contentype = filename.split(".")[1]
            content_type = base64.urlsafe_b64decode(base64_contentype)
            logger.info("Sending file %s", file_path)
            f = open(file_path, 'rb')
            request.setHeader('Content-Type', content_type)
            d = FileSender().beginFileTransfer(f, request)

            # after the file has been sent, clean up and finish the request
            def cbFinished(ignored):
                f.close()
                request.finish()
            d.addCallback(cbFinished)
        else:
            respond_with_json_bytes(
                request,
                404,
                json.dumps(cs_error("Not found", code=Codes.NOT_FOUND)),
                send_cors=True)

        return server.NOT_DONE_YET
开发者ID:winsontan520,项目名称:synapse,代码行数:35,代码来源:content_repository.py

示例4: getshared_cb

        def getshared_cb(data):
            if len(data) == 0:
                error = { 'status': {'error': "Invalid Request",
                                     'message': "File does not exist."} }
                request.write(json.dumps(error, sort_keys=True, encoding="utf-8"))
                request.finish()
                return

            file_path = str(data[0][0]) + "/" + fileid
            if not os.path.exists(file_path):
                error = { 'status': {'error': "Invalid Request",
                                     'message': "File does not exist."} }
                request.write(json.dumps(error, sort_keys=True, encoding="utf-8"))
                request.finish()

            request.write(str(data[0][1])) # writing key
            iv_plain = self.sid.decryptData(data[0][2]) # writing IV
            print iv_plain
            iv = self.sid.encryptData(iv_plain, pubkey)
            request.write(iv)
            file = open(file_path ,"r")
            sender = FileSender()
            sender.CHUNK_SIZE = 200
            df = sender.beginFileTransfer(file, request)

            df.addErrback(err)
            df.addCallback(finishTrnf_cb, file)
开发者ID:mlaz,项目名称:security2014-15,代码行数:27,代码来源:sfbx_storage.py

示例5: start_stream

 def start_stream():
     file_sender = FileSender()
     d = file_sender.beginFileTransfer(file_handle, lbry_file_creator)
     d.addCallback(lambda _: stop_file(lbry_file_creator))
     d.addCallback(lambda _: make_stream_desc_file(lbry_file_creator.stream_hash))
     d.addCallback(lambda _: lbry_file_creator.stream_hash)
     return d
开发者ID:lbryio,项目名称:lbry,代码行数:7,代码来源:EncryptedFileCreator.py

示例6: render_GET

    def render_GET(self, request):
        log.debug("request from %s: %s" % (self.userid, request.args))
        if "f" in request.args:
            fn = request.args["f"][0]
            info = self.fileserver.storage.get(fn, False)
            if info:
                filename, mime, md5sum = info
                log.debug("sending file type %s, path %s, md5sum %s" % (mime, filename, md5sum))
                genfilename = util.generate_filename(mime)
                request.setHeader("content-type", mime)
                request.setHeader("content-length", os.path.getsize(filename))
                request.setHeader("content-disposition", 'attachment; filename="%s"' % (genfilename))
                request.setHeader("x-md5sum", md5sum)

                # stream file to the client
                fp = open(filename, "rb")
                d = FileSender().beginFileTransfer(fp, request)

                def finished(ignored):
                    fp.close()
                    request.finish()

                d.addErrback(log.error).addCallback(finished)
                return server.NOT_DONE_YET

            # file not found in extra storage
            else:
                return self._quick_response(request, 404, "not found")

        return self._quick_response(request, 400, "bad request")
开发者ID:carriercomm,项目名称:xmppserver,代码行数:30,代码来源:fileserver.py

示例7: connectionMade

 def connectionMade(self):
     self.transport.write('%s\r\n' % (self.insize))
     sender = FileSender()
     sender.CHUNK_SIZE = 2 ** 16
     d = sender.beginFileTransfer(self.infile, self.transport,
                                  self._monitor)
     d.addCallback(self.cbTransferCompleted)
开发者ID:mattvonrocketstein,项目名称:cortex,代码行数:7,代码来源:sender.py

示例8: sendFile

    def sendFile(self, dataObj):
        pycb.log(logging.INFO, "===== def sendFile of cbRequest.py")
        try:
            #etag = dataObj.get_md5()
            etag = pycb.config.bucket.get_md5()
            pycb.log(logging.INFO, "=====## md5(etag) is %s"%etag)
            if etag == None:
                etag = self.etag
            if etag == None:
                etag = self.calcMd5Sum(dataObj)
                dataObj.set_md5(etag)
            self.setHeader(self.request, 'ETag', '"%s"' % (etag))
            self.setResponseCode(self.request, 200, 'OK')

            fp = dataObj
            d = FileSender().beginFileTransfer(fp, self.request)
            def cbFinished(ignored):
                pycb.log(logging.INFO, "===== def cbFinished of cbRequest.py")
                fp.close()
                self.request.finish()
            d.addErrback(err).addCallback(cbFinished)

        except cbException, (ex):
            ex.sendErrorResponse(self.request, self.requestId)
            traceback.print_exc(file=sys.stdout)
            pycb.log(logging.ERROR, "Error sending file %s" % (str(ex)), traceback)
开发者ID:xxy-php,项目名称:code,代码行数:26,代码来源:cbRequest.py

示例9: lineReceived

 def lineReceived(self, line):
     print 'sender %s' % line
     line = line.strip()
     if line == OK:
         sender = FileSender()
         sender.CHUNK_SIZE = 2 ** 16
         deffered = sender.beginFileTransfer(self.fileObj, self.transport, None)
         deffered.addCallback(self.success).addErrback(self.error)
开发者ID:nqryn,项目名称:my-protocols,代码行数:8,代码来源:afsp.py

示例10: on_write_status

 def on_write_status(self, consumer):
     content = self.generate_content()
     buffer = StringIO(content)
     sender = FileSender()
     d = sender.beginFileTransfer(buffer, consumer)
     d.addCallbacks(lambda _: self.on_write_completed(consumer),
                    self.on_error)
     return d
开发者ID:Jakky89,项目名称:cuwo-mitm,代码行数:8,代码来源:status.py

示例11: _sendMail_data

    def _sendMail_data(self, code, resp):
        transfer = FileSender()

        deferred = transfer.beginFileTransfer(self._requestParams['file'], self.transport, self.transformChunk)
        deferred.addCallbacks(self.finishedFileTransfer, self.sendError)

        self._expected = SUCCESS
        self._okresponse = self._sendMail_sent
        self._failresponse = self._sendMail_fail
开发者ID:p0is0n,项目名称:mail-services,代码行数:9,代码来源:smtp.py

示例12: start_streaming

    def start_streaming(self):
        file_sender = FileSender()
        d = file_sender.beginFileTransfer(self.file_handle, self)

        def stop_stream():
            d = self.stop()
            return d

        d.addCallback(lambda _: stop_stream())
        return d
开发者ID:Xuiquaxa,项目名称:lbry,代码行数:10,代码来源:LiveStreamCreator.py

示例13: test_pullFileConsumer

 def test_pullFileConsumer(self):
     fileToSend = StringIO(fileData)
     clock = Clock()
     consumer = FileConsumer(clock)
     d = FileSender().beginFileTransfer(fileToSend, consumer)
     finished = []
     d.addCallback(finished.append)
     while not finished:
         clock.advance(1)
     self.assertEqual(consumer.value(), fileData)
开发者ID:habnabit,项目名称:txampproducer,代码行数:10,代码来源:test_integration.py

示例14: send_open_file

def send_open_file(openFile, request):
    '''Use FileSender to asynchronously send an open file

    [JBY] From: http://stackoverflow.com/questions/1538617/http-download-very-big-file'''
    dd = FileSender().beginFileTransfer(openFile, request)

    def cbFinished(ignored):
        openFile.close()
        request.finish()
    
    dd.addCallback(cbFinished).addErrback(err)
开发者ID:guoyr,项目名称:geo-caching,代码行数:11,代码来源:image_transfer_handler.py

示例15: _start_transfer

 def _start_transfer(self, _discard):
     if self.fileObj is None:
         self._failure((2, "NO_FILE_LOADED"))
     else:
         logging.info("Started file transfer")
         self.busy = True
         fileProducer = FileSender()
         fileProducer.CHUNK_SIZE = 65536
         def_obj = fileProducer.beginFileTransfer(file=self.fileObj, consumer=self.transport)
         def_obj.addCallback(self._done_transfer, True)
         def_obj.addErrback(self._done_transfer, False)
开发者ID:vasuman,项目名称:FiSH,代码行数:11,代码来源:daemon.py


注:本文中的twisted.protocols.basic.FileSender类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。