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


Python FileSender.CHUNK_SIZE方法代码示例

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


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

示例1: getshared_cb

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import CHUNK_SIZE [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 CHUNK_SIZE [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: lineReceived

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import CHUNK_SIZE [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

示例4: connectionMade

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import CHUNK_SIZE [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

示例5: _start_transfer

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import CHUNK_SIZE [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

示例6: connectionMade

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import CHUNK_SIZE [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

示例7: connectionMade

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import CHUNK_SIZE [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

示例8: sendFile

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import CHUNK_SIZE [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

示例9: send_file

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import CHUNK_SIZE [as 别名]
            def send_file(result):
                filename = result[0][0].strip()
                filepath = os.path.join(common.file_dir, filename)
                print "send file ", filepath
                try:
                    outfile = open(filepath, 'rb')
                except IOError:
                    print "no such file"
                    return
                else:
                    s = outfile.read()
                    outfile.seek(0)
                    filesize = len(s)
                    crc = crc32(s)
                    line = '2#%s|%s|%s' % (filename, filesize, crc)
                    self.sendLine(line)

                def transfer_completed(lastsent):
                    outfile.close()

                sender = FileSender()
                sender.CHUNK_SIZE = common.chunk_size
                d = sender.beginFileTransfer(outfile, self.transport)
                d.addCallback(transfer_completed)
开发者ID:wuzhe,项目名称:medicalook,代码行数:26,代码来源:medproto.py

示例10: upload_file

# 需要导入模块: from twisted.protocols.basic import FileSender [as 别名]
# 或者: from twisted.protocols.basic.FileSender import CHUNK_SIZE [as 别名]
def upload_file(file, transport):
  sender = FileSender()
  sender.CHUNK_SIZE = 2 ** 16
  return sender.beginFileTransfer(file, transport)
开发者ID:darka,项目名称:p2pfs,代码行数:6,代码来源:helpers.py


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