本文整理汇总了Python中twisted.protocols.basic.FileSender类的典型用法代码示例。如果您正苦于以下问题:Python FileSender类的具体用法?Python FileSender怎么用?Python FileSender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileSender类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: render_POST
def render_POST(self, request):
# Read POST into a temporary file
tmpfile = tempfile.TemporaryFile()
while True:
data = request.content.read(512 * 1024)
if not data:
break
tmpfile.write(data)
tmpfile.seek(0)
# Decrypt it
decrypted = self.server.key_manager.decrypt_file(tmpfile)
request.setHeader("content-type", "text/plain")
# Make sure we know the client
if not self.server.key_manager.is_gpg_key_in_ring(decrypted.key_id):
print("WARNING: Unknown client (Key ID: %s)" % (decrypted.key_id))
request.setResponseCode(511)
return "ERROR: I'm sorry sir, I don't know any Mr. %s" % (str(decrypted.key_id))
tmpfile.close()
# JSON parse
op = json.loads(decrypted.data)
# Operations
if op["op"] == "ping":
return self.server.key_manager.crypt("PONG", decrypted.key_id)
elif op["op"] == "get channel list":
channels = self.server.channel_manager.get_local_channels()
channels_json = json.dumps(channels)
channels_crypted = self.server.key_manager.crypt(channels_json, decrypted.key_id)
return channels_crypted
elif op["op"] == "get file list":
files = self.server.channel_manager.get_local_files(op["channels"])
files_json = json.dumps(files)
return self.server.key_manager.crypt(files_json, decrypted.key_id)
elif op["op"] == "download file":
f = self.server.channel_manager.get_filestream(op["channel"], op["file"])
p = self.server.key_manager.crypt_file_popen(f, decrypted.key_id)
d = FileSender().beginFileTransfer(p.stdout, request)
def cbFinished(ignored):
p.kill()
p.wait()
request.finish()
d.addErrback(err).addCallback(cbFinished)
return server.NOT_DONE_YET
开发者ID:pasalo,项目名称:common,代码行数:54,代码来源:HTTPS.py
示例17: connectionMade
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,代码行数:11,代码来源:serverConnections.py
示例18: connectionMade
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,代码行数:12,代码来源:filesender.py
示例19: render
def render(self,request):
self.isLeaf = False
#print request
#print dir(request)
print request.path
if (request.path.split('.')[-1] == 'mkv'):
print request.path.split('.')[-1]
request.setHeader('Content-Type',"application/x-mpegurl")
if (self.converter.checkStatus(request.path)):
self.converter.start('../../Torrents',request.path)
#f = open('playlist.m3u8','rb')
#print f.read()
#f.close()
#f = open('playlist.m3u8','rb')
#def cbFinished(ignored):
#f.close()
#request.finish()
playlist = self.converter.getPlaylist()
print playlist
return playlist
#d = FileSender().beginFileTransfer(f,request)
#d.addErrback(err).addCallback(cbFinished)
#return NOT_DONE_YET
elif(request.path.split('.')[-1] == 'ts'):
request.setHeader('Content-Type','video/MP2T')
print (request.path + '<--------')
self.converter.updateRecentSeg(request.path)
f = open(request.path[1:],'rb')
def cbFinished(ignored):
f.close()
request.finish()
d = FileSender().beginFileTransfer(f,request)
d.addErrback(err).addCallback(cbFinished)
return NOT_DONE_YET
else:
print ('travelled well')
print self.path
request.setHeader('Content-Type','video/octet-stream')
self.isLeaf = False
return static.File.render(self,request)
"""f = open(self.path+request.path,'rb')
开发者ID:Stashiocat,项目名称:VidiiUStreamer,代码行数:53,代码来源:serverCore.py
示例20: connectionMade
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,代码行数:13,代码来源:new_server.py
注:本文中的twisted.protocols.basic.FileSender类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论