當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。