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


Python storage.Bucket类代码示例

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


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

示例1: WriteZipFile

def WriteZipFile(filename):
    """
    保存所有kvdb数据,压缩成zip然后aes cbc加密
    """
    FileBuffer = io.BytesIO()
    datalist = FindKVDBKeys()
    if datalist:
        zfile = zipfile.ZipFile(FileBuffer,mode='w')
        for data in datalist:
            # bytedata = (data + "tttttttt").encode(encoding="utf-8")
            bytedata = kv.get(str(data))
            if bytedata:
                # print(bytedata)
                zfile.writestr(str(data),bytedata)
        zfile.close() 
        key = config.keyDataBackUp
        iv = Random.new().read(AES.block_size)
        cipher = AES.new(key, AES.MODE_ECB)
        CryptIV = cipher.encrypt(iv)
        cipher = AES.new(key, AES.MODE_CBC, iv)
        bytebuffer = FileBuffer.getvalue()
        lendata = 16 - len(bytebuffer)%16
        bytebuffer = bytebuffer + chr(lendata)*lendata
        #print(bytebuffer)
        CryptData = CryptIV + cipher.encrypt(bytebuffer)
        bucket = Bucket('backup')
        # print(FileBuffer.getvalue())
        bucket.put_object(filename,CryptData)
        FileBuffer.close()
开发者ID:zhangningningcn,项目名称:weixinsendmail,代码行数:29,代码来源:kvbackup.py

示例2: put_obj2storage

def put_obj2storage(file_name="", data="", expires="365", type=None, encoding=None, domain_name=STORAGE_DOMAIN_NAME):
    whichStorage = int(getAttr("DEFAULT_STORAGE"))
    if whichStorage == 0:
        bucket = Bucket(domain_name)
        bucket.put_object(file_name, data, content_type=type, content_encoding=encoding)
        return bucket.generate_url(file_name)
    elif whichStorage == 1:
        import qiniu.conf, qiniu.rs, qiniu.io

        qiniu.conf.ACCESS_KEY = getAttr("QNKEY")
        qiniu.conf.SECRET_KEY = getAttr("QNSECRET")
        policy = qiniu.rs.PutPolicy(getAttr("QNSTORAGE"))
        uptoken = policy.token()
        key = file_name
        if key[0] == "/":
            key = key[1:]
        ret, err = qiniu.io.put(uptoken, key, data)
        if err is not None:
            print "err = ", err
            return ""
        ###下面返回的网址有可能不同,有的是 xxxx.u.qiniudn.com 请改为自己的
        return "http://%s/%s" % (getAttr("QNDOMAIN"), key)
    else:
        # 可后续扩展其他云存储
        pass
    return ""
开发者ID:yobin,项目名称:saepy-log,代码行数:26,代码来源:admin.py

示例3: delPic

def delPic(request,id):
	if isUser(request):
		if request.method == "POST":
			try:
				pic_id = request.POST.get('del_pic_id','')
				pic = Pictures.objects.get(id=pic_id)
			except Exception, e:
				raise e
			if 'SERVER_SOFTWARE' in os.environ:
				try:
					from sae.storage import Bucket
					bucket = Bucket('media')
					pic_path = str(id) + '/' + pic.pic_src[pic.pic_src.rindex("/")+1:]
					bucket.delete_object(pic_path)
					pic.delete()
				except Exception, e:
					raise e
			else:
				try:
					os.remove(pic.pic_src[1:])
					# print pic.pic_src[1:pic.pic_src.rindex("/")+1]
					if not os.listdir(pic.pic_src[1:pic.pic_src.rindex("/")+1]):
						os.rmdir(pic.pic_src[1:pic.pic_src.rindex("/")+1])
					pic.delete()
				except Exception, e:
					raise e
开发者ID:wtq2255,项目名称:uuweb,代码行数:26,代码来源:views.py

示例4: get

    def get(self, request, *args, **kwargs):
        from sae.deferredjob import MySQLExport, DeferredJob
        from sae.storage import Bucket as SBucket
        import time
        import datetime

        export_bucket = 'xkongbackup'
        bucket = SBucket(export_bucket)

        now = time.strftime('%Y_%m_%d_%H_%M_%S')
        filename = 'app_ninan_%s.zip' % now

        deferred_job = DeferredJob()
        job = MySQLExport(export_bucket, filename, 'note_note',
                          'backends/backupsuccess/')
        deferred_job.add(job)

        resp = {'touch': filename}

        #  Delete all files in this bucket created a month ago
        a_month_ago = datetime.datetime.now() - datetime.timedelta(days=30)

        for object_ in bucket.list():
            last_modified = object_['last_modified']
            if last_modified:
                mtime = datetime.datetime.strptime(last_modified,
                                                   '%Y-%m-%dT%H:%M:%S.%f')
            else:
                continue

            if object_['content_type'] is not None and mtime < a_month_ago:
                bucket.delete_object(object_['name'])

        return self.render_to_response(resp)
开发者ID:xkong,项目名称:ninantrash,代码行数:34,代码来源:views.py

示例5: inPageAmazon

 def inPageAmazon(self, params):
     try:
         conn = Connection(accesskey='ym51nzx10z', secretkey='h0kxmzj2ly13jjj1m0jjly41li1wimizzz2w2m32', retries=3)
         bucket = Bucket('amazon', conn)
         page = bucket.get_object_contents(params['category'] + '/' + params['in_page'])
     except Exception, e:
         print e
开发者ID:pantaovay,项目名称:easyebook,代码行数:7,代码来源:util.py

示例6: get

 def get(self, sub_path):
     from sae.storage import Bucket
     bucket = Bucket('oerp')                                  # 从云平台拿到一个Bucket容器
     #imagebinary = meta['body']
     response = bucket.get_object_contents(sub_path, chunk_size=10)    # 取文件    bucket.get_object_contents(u'oerp', r'/uploadimg/' + sub_path)
     self.set_header('Content-Type', 'text/xml; charset=utf-8')
     self.write(response.next())
开发者ID:dloveff,项目名称:TornadoProjecResouces,代码行数:7,代码来源:updoad.py

示例7: sae_save_file

def sae_save_file( f , storage_name , file_name = None ):
    from sae.storage import Bucket
    bucket = Bucket(storage_name)
    print bucket
    if file_name is None: 
        file_name = f._get_name()
    return bucket.put_object(file_name, f)
开发者ID:superyxo,项目名称:mysite-main,代码行数:7,代码来源:__init__.py

示例8: post

    def post(self, id):
        id = int(id)
        from sae.storage import Bucket

        bucket = Bucket('audio')
        fid = str(self.current_user) + datetime.now().strftime('/%Y-%m-%dT%H-%M-%S')
        name = fid + '.wav'
        #length = int(request.get_header('content-length',0))

        bucket.put_object(name, self.request.body)

        name = bucket.generate_url(name)

        sss = Session()
        model = RoomChat()
        model.room_id = id
        model.content_type = 'audio'
        model.content = name
        model.user_name = self.user.name
        model.user_id = self.current_user
        model.create_at = datetime.now()

        sss.add(model)
        sss.commit()

        ls = GetTop.ajax(id)
        self.render_list(*ls)
开发者ID:lusionx,项目名称:sae-lxpy-1,代码行数:27,代码来源:room.py

示例9: exportImport

def exportImport(filename,tp):
	result={}
	# for client debug
	if settings.DEBUG:
		data = xlrd.open_workbook(settings.MEDIA_ROOT+filename)
	# for sae
	else:
		bucket = Bucket('resources')
		obj = bucket.get_object_contents(filename)
		data=xlrd.open_workbook(file_contents=obj)
	table = data.sheets()[0]
	# check the column
	ncols=table.ncols
	nrows=table.nrows
	# for student
	if (tp==0 and (not ncols==11)) or (tp==1 and (not ncols==9)):
		result['status']='failured'
		result['tip']='excel列数不对'
	elif nrows<2:
		result['status']='failured'
		result['tip']='至少需要一条记录'
	else:
		statistic=executeImport(table,tp)
		result['status']='success'
		result['tip']='导入成功,共 %d 人,成功导入 %d 人,跳过 %d 人' \
		% (statistic['sum'],statistic['count'],statistic['existed'])
		result['usernames']=statistic['usernames']
	# delete the uploaded temp file
	#  for client debug
	if settings.DEBUG:
		os.remove(settings.MEDIA_ROOT+filename)
	#  for sae
	else:
		bucket.delete_object(filename)
	return result
开发者ID:hityangzhen,项目名称:Olearning,代码行数:35,代码来源:MyExcel.py

示例10: POST

    def POST(self):
        context = web.input().context.encode('utf-8')
        taskid = web.input().taskid
        file_name = web.input().file_name

        # Only segement the title and keyword
        seg_content = []
        lines = context.split('\r')
        for line in lines:
            tmp = line.split('\t')
            seg_content.append(tmp[1])
            seg_content.append(tmp[2])

        results = get_seg_result('\t'.join(seg_content), keep_return=True)
        newcontent = assemble_result(context, results['filtered_result'], taskid=taskid, file_name=file_name)

        # log_message('Task ' + taskid + ' is excecuted (post), result: ' + '<br /> '.join(newcontent))

        # submit to server
        try:
            # payload = urllib.urlencode([('seg_result', ''.join(newcontent).encode('utf-8')), ('taskid', taskid), ])
            # req = urllib2.urlopen(SUBMIT_RESULT_URL, payload)
            # log_message('submit task ' + str(taskid) + ' to server' + req.read())
            from sae.storage import Bucket
            bucket = Bucket('mozillaup')
            bucket.put_object(file_name + '/' + str(taskid), ''.join(newcontent).encode('utf-8'))
            # log_message('submit task ' + str(taskid) + ' to bucket')
        except Exception, ex:
            print ex
            result = 'Encounter an error when submit task' + type(ex).__name__ + ' ' + str(ex.args)
            log_message(result)
开发者ID:PinZhang,项目名称:up-sae-segmentation,代码行数:31,代码来源:handlers.py

示例11: ReadZipFile

def ReadZipFile(filename):

    """
    从storage中读取数据,还原到kvdb中
    参数 filename 要还原数据的文件名
    """
    bucket = Bucket('backup')
    # print(filename)
    CryptData = bucket.get_object_contents(filename)
    # print(CryptData)
    # -FileBuffer.close()
    key = config.keyDataBackUp
    cipher = AES.new(key, AES.MODE_ECB)
    iv = cipher.decrypt(CryptData[:16])
    # print(str(iv))
    cipher = AES.new(key, AES.MODE_CBC, iv)
    bytebuffer = cipher.decrypt(CryptData[16:])
    lendata = ord(bytebuffer[-1])
    FileBuffer = io.BytesIO(bytebuffer[:-lendata])
    zfile = zipfile.ZipFile(FileBuffer,mode='r')
    namelist = zfile.namelist()
    for name in namelist:
        bytedata = zfile.read(name)
        kv.set(name,bytedata.decode("utf-8"))
        
    return u"数据已还原"
开发者ID:zhangningningcn,项目名称:weixinsendmail,代码行数:26,代码来源:kvbackup.py

示例12: inPage

 def inPage(self, site, filename):
     try:
         conn = Connection(accesskey='ym51nzx10z', secretkey='h0kxmzj2ly13jjj1m0jjly41li1wimizzz2w2m32', retries=3)
         bucket = Bucket(site, conn)
         page = bucket.get_object_contents(filename)
     except Exception, e:
         print e
开发者ID:pantaovay,项目名称:easyebook,代码行数:7,代码来源:util.py

示例13: upload_file_handle

def upload_file_handle(f,user_id):
    from sae.storage import Bucket
    bucket=Bucket('image')
    bucket.put()
    file_postfix=f.name.split('.')[-1]
    file_name=str(user_id)+'.'+file_postfix
    bucket.put_object(file_name, f.read())
    return 'http://sumioo-image.stor.sinaapp.com/'+file_name
开发者ID:sumioo,项目名称:demo,代码行数:8,代码来源:utils.py

示例14: save_with_bucket

 def save_with_bucket(self, _bucket, fname, fcontent):
     '''
     _bucket is customer bucket name
     '''
     bk = Bucket(_bucket)
     import StringIO
     b = StringIO.StringIO(fcontent)
     bk.put_object(fname, b.read())
     return bk.generate_url(fname)
开发者ID:snowleung,项目名称:sae_init,代码行数:9,代码来源:StorageAdapter.py

示例15: savePageAmazon

 def savePageAmazon(self, params):
     url = self.amazonUrlBase + self.amazonUrlMap.get(params['category']) + self.amazonUrlTail + params['id']
     page = self.getPage(url)
     try:
         conn = Connection(accesskey='ym51nzx10z', secretkey='h0kxmzj2ly13jjj1m0jjly41li1wimizzz2w2m32', retries=3)
         spider = Bucket('amazon', conn)
         spider.put_object(params['category'] + '/' + params['id'], page)
     except Exception, e:
         print e
开发者ID:pantaovay,项目名称:easyebook,代码行数:9,代码来源:util.py


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