本文整理汇总了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()
示例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 ""
示例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
示例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)
示例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
示例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())
示例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)
示例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)
示例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
示例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)
示例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"数据已还原"
示例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
示例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
示例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)
示例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