本文整理汇总了Python中sinastorage.bucket.SCSBucket.get方法的典型用法代码示例。如果您正苦于以下问题:Python SCSBucket.get方法的具体用法?Python SCSBucket.get怎么用?Python SCSBucket.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sinastorage.bucket.SCSBucket
的用法示例。
在下文中一共展示了SCSBucket.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_put_file
# 需要导入模块: from sinastorage.bucket import SCSBucket [as 别名]
# 或者: from sinastorage.bucket.SCSBucket import get [as 别名]
def test_put_file(self):
scs = SCSBucket(self.bucket_name)
try:
scs.put_bucket('public-read-write')
except:
self.fail('create bucket:%s is failed'%self.bucket_name)
canned_acl = 'public-read-write' #快捷ACL
metadata = {} #自定义文件属性信息
metadata['author'] = 'dage'
metadata['home'] = 'tianjin'
metadata['age'] = '18'
mimetype = 'text/plain'
scs.putFile(key=self.object_key, filePath=self.local_file_name, acl=canned_acl
, metadata=metadata, mimetype=mimetype)
scsResponse = scs.get(self.object_key)
CHUNK = 16 * 1024
file_content = ''
from sinastorage.vendored import six
while True:
chunk = scsResponse.read(CHUNK)
if not chunk: break
if isinstance(chunk, six.text_type):
file_content += chunk
else:
file_content += chunk.decode("utf-8")
#assert file_content
# self.assertEqual(content, file_content, 'The uploaded file content is not metch local.%s'%file_content)
#assert metadata
self.assertEqual(metadata['author'], scsResponse.responseHeaders['x-amz-meta-author'], 'The response metadata[\'author\'] is not match')
self.assertEqual(metadata['home'], scsResponse.responseHeaders['x-amz-meta-home'], 'The response metadata[\'home\'] is not match')
self.assertEqual(metadata['age'], scsResponse.responseHeaders['x-amz-meta-age'], 'The response metadata[\'age\'] is not match')
#assert content-type
self.assertEqual(mimetype, scsResponse.responseHeaders['content-type'], 'The response content-type is not match')
#assert acl
aclResult = scs.acl_info(self.object_key)
self.assertTrue(ACL.ACL_GROUP_ANONYMOUSE in aclResult['ACL'], 'The acl dose not contains GRPS000000ANONYMOUSE group')
self.assertTrue(ACL.ACL_READ in aclResult['ACL'][ACL.ACL_GROUP_ANONYMOUSE], 'The acl GRPS000000ANONYMOUSE group hasn\'t read right')
self.assertTrue(ACL.ACL_WRITE in aclResult['ACL'][ACL.ACL_GROUP_ANONYMOUSE], 'The acl GRPS000000ANONYMOUSE group hasn\'t write right')
示例2: test_get_file
# 需要导入模块: from sinastorage.bucket import SCSBucket [as 别名]
# 或者: from sinastorage.bucket.SCSBucket import get [as 别名]
def test_get_file(self):
scs = SCSBucket(self.bucket_name)
try:
scs.put_bucket('public-read-write')
except:
self.fail('create bucket:%s is failed'%self.bucket_name)
scs.putFile(self.object_key, self.local_file_name)
scsResponse = scs.get(self.object_key)
CHUNK = 16 * 1024
with open(self.local_file_name+'.downloaded', 'wb') as fp:
while True:
chunk = scsResponse.read(CHUNK)
if not chunk: break
fp.write(bytes(chunk) )
import os
self.assertTrue(os.path.exists(self.local_file_name+'.downloaded'), 'The download file dose not exists')
self.assertEqual(str(os.stat(self.local_file_name).st_size),
scsResponse.responseHeaders['content-length'], 'The download file size dose not match local file')
示例3: test_put_content
# 需要导入模块: from sinastorage.bucket import SCSBucket [as 别名]
# 或者: from sinastorage.bucket.SCSBucket import get [as 别名]
def test_put_content(self):
scs = SCSBucket(self.bucket_name)
try:
scs.put_bucket('public-read-write')
except:
self.fail('create bucket:%s is failed'%self.bucket_name)
content = u'this is a file content text!!'
scs.put(self.object_key, content)
scsResponse = scs.get(self.object_key)
CHUNK = 16 * 1024
file_content = ''
from sinastorage.vendored import six
while True:
chunk = scsResponse.read(CHUNK)
if not chunk: break
if isinstance(chunk, six.text_type):
file_content += chunk
else:
file_content += chunk.decode("utf-8")
self.assertEqual(content, file_content, 'The uploaded file content is not match local.%s'%file_content)