本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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)
示例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)