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


Python FileSender.beginFileTransfer方法代码示例

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


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

示例1: getshared_cb

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
        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,代码行数:29,代码来源:sfbx_storage.py

示例2: connectionMade

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
 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,代码行数:9,代码来源:sender.py

示例3: start_stream

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
 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,代码行数:9,代码来源:EncryptedFileCreator.py

示例4: beginFileTransfer

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
	def beginFileTransfer(self, file, consumer, rangeBegin, rangeEnd, transform = None):
		if not rangeBegin < rangeEnd:
			raise ValueError('rangeBegin >= rangeEnd')
		self.rangeBegin = rangeBegin
		self.rangeEnd = rangeEnd
		if file:
			file.seek(rangeBegin)
		return FileSender.beginFileTransfer(self, file, consumer, transform)
开发者ID:claytonbench,项目名称:pstream,代码行数:10,代码来源:storage_helpers.py

示例5: lineReceived

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
 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,代码行数:10,代码来源:afsp.py

示例6: on_write_status

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
 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,代码行数:10,代码来源:status.py

示例7: _sendMail_data

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
    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,代码行数:11,代码来源:smtp.py

示例8: start_streaming

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
    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,代码行数:12,代码来源:LiveStreamCreator.py

示例9: connectionMade

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
 def connectionMade(self):
     """ """
     instruction = dict(file_size=self.insize,
                        original_file_path=self.path)
     instruction = json.dumps(instruction)
     self.transport.write(instruction+'\r\n')
     sender = FileSender()
     sender.CHUNK_SIZE = 2 ** 16
     d = sender.beginFileTransfer(self.infile, self.transport,
                                  self._monitor)
     d.addCallback(self.cbTransferCompleted)
开发者ID:rtm9zc,项目名称:OneDir,代码行数:13,代码来源:serverConnections.py

示例10: _start_transfer

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
 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,代码行数:13,代码来源:daemon.py

示例11: connectionMade

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
 def connectionMade(self):
     """ """
     fileHeader = session.Message(session.fileMsg)
     fileHeader.fileSize = self.insize
     fileHeader.fileName = self.relPath
     fileHeader.sessionID = self.sessionID
     self.transport.write(fileHeader.serialize() + '\r\n')
     sender = FileSender()
     sender.CHUNK_SIZE = 2 ** 16
     d = sender.beginFileTransfer(self.infile, self.transport,
                                  self._monitor)
     d.addCallback(self.cbTransferCompleted)
开发者ID:arminhammer,项目名称:teiler,代码行数:14,代码来源:filesender.py

示例12: connectionMade

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
    def connectionMade(self):
        """ """
        # try:
        instruction = dict(file_size=self.insize, original_file_path=self.path)
        instruction = json.dumps(instruction)
        # except ValueError:
        # "Accepting as delete command instead..."

        self.transport.write(instruction + "\r\n")
        sender = FileSender()
        sender.CHUNK_SIZE = 2 ** 16
        d = sender.beginFileTransfer(self.infile, self.transport, self._monitor)
        d.addCallback(self.cbTransferCompleted)
开发者ID:rtm9zc,项目名称:OneDir,代码行数:15,代码来源:new_server.py

示例13: read

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
    def read(self, write_func):
        def close_self(*args):
            self.close_read_handle(file_handle)
            return args[0]

        file_sender = FileSender()
        reader = HashBlobReader(write_func)
        file_handle = self.open_for_reading()
        if file_handle is not None:
            d = file_sender.beginFileTransfer(file_handle, reader)
            d.addCallback(close_self)
        else:
            d = defer.fail(ValueError("Could not read the blob"))
        return d
开发者ID:teran-mckinney,项目名称:lbry,代码行数:16,代码来源:HashBlob.py

示例14: FileReader

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
class FileReader(AccumulatingProtocol):
    def __init__(self, filename, transform=None, delay=0, verbose=False):
        self.f = open(filename, 'rb')
        self.transform = transform
        self.delay = delay
        self.producer = FileSender()
        self.logger = gogo.Gogo(__name__, verbose=verbose).logger

    def cleanup(self, *args):
        self.f.close()
        self.producer.stopProducing()

    def resumeProducing(self):
        chunk = self.file.read(self.CHUNK_SIZE) if self.file else ''

        if not chunk:
            self.file = None
            self.consumer.unregisterProducer()

            if self.deferred and self.delay:
                callLater(self.delay, self.deferred.callback, self.lastSent)
            elif self.deferred:
                self.deferred.callback(self.lastSent)

            self.deferred = None
            return

    def connectionLost(self, reason):
        self.logger.debug('connectionLost: %s', reason)
        self.cleanup()

    def connectionMade(self):
        self.logger.debug('Connection made from %s', self.transport.getPeer())
        args = (self.f, self.transport, self.transform)
        self.d = self.closedDeferred = self.producer.beginFileTransfer(*args)

        while not self.d.called:
            self.producer.resumeProducing()

        self.d.addErrback(self.logger.error)
        self.d.addBoth(self.cleanup)
开发者ID:Fuzzwah,项目名称:riko,代码行数:43,代码来源:io.py

示例15: sendFile

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import beginFileTransfer [as 别名]
    def sendFile(self, filename, callback = lambda x,y: (x,y)):
        d = self._mkHeaders(filename)

        print d['size']

        transport = self.transport
        end_callback = self.end_callback

        class ProgressMeter(object):
            def __init__(self, filename, callback):
                self.transferred = 0
                self.full = d['size']
                self.callback = callback
                self.cancelled = False
            def monitor(self, data):
                if self.cancelled:
                    print 'progressmeter: cancelled!'
                    transport.unregisterProducer()
                    transport.loseConnection()
                    end_callback()

                self.transferred += len(data)
                self.callback(self.transferred, self.full)
                return data

        self.fp = urllib.urlopen(filename)
        self.sentBytes = 0


        self.transport.write(base64.encodestring(json.dumps(d)))
        self.transport.write('\r\n')

        sender = FileSender()
        sender.CHUNK_SIZE = 2 ** 16

        pm = ProgressMeter(filename, callback)

        d = sender.beginFileTransfer(self.fp, self.transport, pm.monitor)

        d.addCallback(self.done)
        return pm
开发者ID:fin,项目名称:aether,代码行数:43,代码来源:protocol.py


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