本文整理汇总了Python中sae.storage.Bucket类的典型用法代码示例。如果您正苦于以下问题:Python Bucket类的具体用法?Python Bucket怎么用?Python Bucket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bucket类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: delete_img
def delete_img(con, pid, title):
if 'SERVER_SOFTWARE' in os.environ:
p = get_product_detail(con, title)
bucket = Bucket('domain1')
for url in p.img_list:
img_name = url.split("/")[-1]
bucket.delete_object(img_name)
print "delete bucket object", img_name
sql = "delete from {0} where pid ={1}".format(IMG_TABLE, pid)
execute_non_query(con, sql)
开发者ID:myang321,项目名称:EIA,代码行数:10,代码来源:database_setup.py
示例17: save_img
def save_img(uid,device_name,file1):
filename = file1.name
timestamp=filename.split(".")[0]
url="www.baidu.com"
if 'SERVER_SOFTWARE' in os.environ:
bucket = Bucket('domain2')
bucket.put_object(filename, file1)
url = bucket.generate_url(filename)
image=Img.create(uid=uid,timestamp=timestamp,device_name=device_name,url=url)
image.save()
开发者ID:myang321,项目名称:FinderServer,代码行数:10,代码来源:utils.py
示例18: initialize
def initialize(*args):
global trie, FREQ, total, min_freq, initialized
if len(args)==0:
dictionary = DICTIONARY
else:
dictionary = args[0]
with DICT_LOCK:
if initialized:
return
if trie:
del trie
trie = None
t1 = time.time()
cache_file = 'jieba.cache'
default_dict = dictionary
default_bucket = getattr(settings, 'STORAGE_BUCKET_NAME')
bucket = Bucket(default_bucket)
cache_file_content = bucket.get_object_contents(dictionary)
dict_stamp = bucket.stat_object(default_dict)['timestamp']
load_from_cache_fail = True
try:
cache_stamp = bucket.stat_object(cache_file)['timestamp']
except:
cache_exists = False
else:
if cache_stamp > dict_stamp:
logger.debug("loading model from cache %s" % cache_file)
try:
cache_content = bucket.get_object_contents(cache_file)
trie,FREQ,total,min_freq = marshal.loads(cache_content)
load_from_cache_fail = False
except:
load_from_cache_fail = True
if load_from_cache_fail:
trie,FREQ,total = gen_trie(cache_file_content)
FREQ = dict([(k,log(float(v)/total)) for k,v in FREQ.iteritems()]) #normalize
min_freq = min(FREQ.itervalues())
logger.debug("dumping model to file cache %s" % cache_file)
try:
tmp_suffix = "."+str(random.random())
cache_file = 'dict' + tmp_suffix + '.cache'
cache_file = os.path.join(tempfile.gettempdir(), cache_file)
with open(cache_file,'wb') as temp_cache_file:
marshal.dump((trie,FREQ,total,min_freq),temp_cache_file)
if cache_exists:
bucket.delete_object('jieba.cache')
bucket.put_object('jieba.cache', open(cache_file, 'rb'))
except:
logger.error("dump cache file failed.")
logger.exception("")
initialized = True
logger.debug("loading model cost %s seconds." % (time.time() - t1))
logger.debug("Trie has been built succesfully.")
开发者ID:xkong,项目名称:saejieba,代码行数:60,代码来源:__init__.py
示例19: edit0
def edit0(request):
pname = pcomment = pmood = newname = 0
from sae.storage import Bucket
bucket = Bucket('abc')
if request.POST:
if request.POST.has_key('correct'):
if request.GET.has_key('atitle'):
pname = request.GET['atitle']
pn = t.objects.all()
if (len(pn)!= 0):
pname = pn[0].title
for i in pn:
i.delete()
we = imagess.objects.filter(title = pname)
if (len(we)!= 0):
img = bucket.get_object_contents('stati/'+pname)
im = Image.open(StringIO.StringIO(img))
imgout = StringIO.StringIO()
im.save(imgout,"jpeg")
img_data = imgout.getvalue()
we[0].title = request.POST['cname']+'.jpg'
newname = we[0].title
if (newname != pname):
ne = t(title = newname)
ne.save()
bucket.put_object('stati/'+newname, img_data)
im = Image.open(StringIO.StringIO(img))
out = im.resize((128, 128))
imgout = StringIO.StringIO()
out.save(imgout,"jpeg")
img_data = imgout.getvalue()
bucket.put_object('manage/'+newname, img_data)
bucket.delete_object('manage/'+pname)
bucket.delete_object('stati/'+pname)
pname = newname
we[0].comment = request.POST['ccomment']
we[0].mood = request.POST['cmood']
we[0].save()
pname = request.POST['cname']+'.jpg'
pcomment = request.POST['ccomment']
pmood = request.POST['cmood']
elif request.GET.has_key('atitle'):
if (pname == 0):
pname = request.GET['atitle']
p = t(title = pname)
p.save()
we = imagess.objects.filter(title = pname)
if (len(we)!= 0):
pcomment = we[0].comment
pmood = we[0].mood
if (pname!=0):
pname = pname[:-4]
return render_to_response('editt.html',{'pname':pname,'newname':newname, \
'pmood': pmood, 'pcomment':pcomment},context_instance=RequestContext(request))
开发者ID:450534021,项目名称:gxhlchfzxy,代码行数:55,代码来源:edit.py
示例20: upload_storage
def upload_storage(bucketname=BUCKET, savename="test.txt", filedata=None):
if bucketname and savename and filedata:
if DEBUG:
return None
from sae.storage import Bucket
bucket = Bucket(bucketname)
if savename[0]=="/":
savename = savename[1:]
bucket.put_object(savename, filedata)
return bucket.generate_url(savename)
else:
return False
开发者ID:kerneltravel,项目名称:ijd8,代码行数:12,代码来源:views.py
注:本文中的sae.storage.Bucket类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论