本文整理汇总了Python中boto.gs.connection.GSConnection.delete_bucket方法的典型用法代码示例。如果您正苦于以下问题:Python GSConnection.delete_bucket方法的具体用法?Python GSConnection.delete_bucket怎么用?Python GSConnection.delete_bucket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.gs.connection.GSConnection
的用法示例。
在下文中一共展示了GSConnection.delete_bucket方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_1_basic
# 需要导入模块: from boto.gs.connection import GSConnection [as 别名]
# 或者: from boto.gs.connection.GSConnection import delete_bucket [as 别名]
#.........这里部分代码省略.........
# test a few variations on get_all_keys - first load some data
# for the first one, let's override the content type
phony_mimetype = 'application/x-boto-test'
headers = {'Content-Type': phony_mimetype}
k.name = 'foo/bar'
k.set_contents_from_string(s1, headers)
k.name = 'foo/bas'
k.set_contents_from_filename('foobar')
k.name = 'foo/bat'
k.set_contents_from_string(s1)
k.name = 'fie/bar'
k.set_contents_from_string(s1)
k.name = 'fie/bas'
k.set_contents_from_string(s1)
k.name = 'fie/bat'
k.set_contents_from_string(s1)
# try resetting the contents to another value
md5 = k.md5
k.set_contents_from_string(s2)
assert k.md5 != md5
os.unlink('foobar')
all = bucket.get_all_keys()
assert len(all) == 6
rs = bucket.get_all_keys(prefix='foo')
assert len(rs) == 3
rs = bucket.get_all_keys(prefix='', delimiter='/')
assert len(rs) == 2
rs = bucket.get_all_keys(maxkeys=5)
assert len(rs) == 5
# test the lookup method
k = bucket.lookup('foo/bar')
assert isinstance(k, bucket.key_class)
assert k.content_type == phony_mimetype
k = bucket.lookup('notthere')
assert k == None
# try some metadata stuff
k = bucket.new_key()
k.name = 'has_metadata'
mdkey1 = 'meta1'
mdval1 = 'This is the first metadata value'
k.set_metadata(mdkey1, mdval1)
mdkey2 = 'meta2'
mdval2 = 'This is the second metadata value'
k.set_metadata(mdkey2, mdval2)
# try a unicode metadata value
mdval3 = u'föö'
mdkey3 = 'meta3'
k.set_metadata(mdkey3, mdval3)
k.set_contents_from_string(s1)
k = bucket.lookup('has_metadata')
assert k.get_metadata(mdkey1) == mdval1
assert k.get_metadata(mdkey2) == mdval2
assert k.get_metadata(mdkey3) == mdval3
k = bucket.new_key()
k.name = 'has_metadata'
k.get_contents_as_string()
assert k.get_metadata(mdkey1) == mdval1
assert k.get_metadata(mdkey2) == mdval2
assert k.get_metadata(mdkey3) == mdval3
bucket.delete_key(k)
# test list and iterator
rs1 = bucket.list()
num_iter = 0
for r in rs1:
num_iter = num_iter + 1
rs = bucket.get_all_keys()
num_keys = len(rs)
assert num_iter == num_keys
# try a key with a funny character
k = bucket.new_key()
k.name = 'testnewline\n'
k.set_contents_from_string('This is a test')
rs = bucket.get_all_keys()
assert len(rs) == num_keys + 1
bucket.delete_key(k)
rs = bucket.get_all_keys()
assert len(rs) == num_keys
# try some acl stuff
bucket.set_acl('public-read')
acl = bucket.get_acl()
assert len(acl.entries.entry_list) == 2
bucket.set_acl('private')
acl = bucket.get_acl()
assert len(acl.entries.entry_list) == 1
k = bucket.lookup('foo/bar')
k.set_acl('public-read')
acl = k.get_acl()
assert len(acl.entries.entry_list) == 2
k.set_acl('private')
acl = k.get_acl()
assert len(acl.entries.entry_list) == 1
# now delete all keys in bucket
for k in bucket:
bucket.delete_key(k)
# now delete bucket
time.sleep(5)
c.delete_bucket(bucket)
print '--- tests completed ---'
示例2: test_1_basic
# 需要导入模块: from boto.gs.connection import GSConnection [as 别名]
# 或者: from boto.gs.connection.GSConnection import delete_bucket [as 别名]
#.........这里部分代码省略.........
k.set_contents_from_string(s2)
assert k.md5 != md5
# Test for stream API
fp2 = open('foobar', 'rb')
k.md5 = None
k.base64md5 = None
k.set_contents_from_stream(fp2, headers=headers)
fp = open('foobar1', 'wb')
k.get_contents_to_file(fp)
fp.close()
fp2.seek(0,0)
fp = open('foobar1', 'rb')
assert (fp2.read() == fp.read()), 'Chunked Transfer corrupted the Data'
fp.close()
fp2.close()
os.unlink('foobar1')
os.unlink('foobar')
all = bucket.get_all_keys()
assert len(all) == 6
rs = bucket.get_all_keys(prefix='foo')
assert len(rs) == 3
rs = bucket.get_all_keys(prefix='', delimiter='/')
assert len(rs) == 2
rs = bucket.get_all_keys(maxkeys=5)
assert len(rs) == 5
# test the lookup method
k = bucket.lookup('foo/bar')
assert isinstance(k, bucket.key_class)
assert k.content_type == phony_mimetype
k = bucket.lookup('notthere')
assert k == None
# try some metadata stuff
k = bucket.new_key()
k.name = 'has_metadata'
mdkey1 = 'meta1'
mdval1 = 'This is the first metadata value'
k.set_metadata(mdkey1, mdval1)
mdkey2 = 'meta2'
mdval2 = 'This is the second metadata value'
k.set_metadata(mdkey2, mdval2)
# try a unicode metadata value
mdval3 = u'föö'
mdkey3 = 'meta3'
k.set_metadata(mdkey3, mdval3)
k.set_contents_from_string(s1)
k = bucket.lookup('has_metadata')
assert k.get_metadata(mdkey1) == mdval1
assert k.get_metadata(mdkey2) == mdval2
assert k.get_metadata(mdkey3) == mdval3
k = bucket.new_key()
k.name = 'has_metadata'
k.get_contents_as_string()
assert k.get_metadata(mdkey1) == mdval1
assert k.get_metadata(mdkey2) == mdval2
assert k.get_metadata(mdkey3) == mdval3
bucket.delete_key(k)
# test list and iterator
rs1 = bucket.list()
num_iter = 0
for r in rs1:
num_iter = num_iter + 1
rs = bucket.get_all_keys()
num_keys = len(rs)
assert num_iter == num_keys
# try some acl stuff
bucket.set_acl('public-read')
acl = bucket.get_acl()
assert len(acl.entries.entry_list) == 2
bucket.set_acl('private')
acl = bucket.get_acl()
assert len(acl.entries.entry_list) == 1
k = bucket.lookup('foo/bar')
k.set_acl('public-read')
acl = k.get_acl()
assert len(acl.entries.entry_list) == 2
k.set_acl('private')
acl = k.get_acl()
assert len(acl.entries.entry_list) == 1
# try set/get raw logging subresource
empty_logging_str="<?xml version='1.0' encoding='UTF-8'?><Logging/>"
logging_str = (
"<?xml version='1.0' encoding='UTF-8'?><Logging>"
"<LogBucket>log-bucket</LogBucket>" +
"<LogObjectPrefix>example</LogObjectPrefix>" +
"</Logging>")
bucket.set_subresource('logging', logging_str);
assert bucket.get_subresource('logging') == logging_str;
# try disable/enable logging
bucket.disable_logging()
assert bucket.get_subresource('logging') == empty_logging_str
bucket.enable_logging('log-bucket', 'example')
assert bucket.get_subresource('logging') == logging_str;
# now delete all keys in bucket
for k in bucket:
bucket.delete_key(k)
# now delete bucket
time.sleep(5)
c.delete_bucket(bucket)
示例3: test_3_default_object_acls
# 需要导入模块: from boto.gs.connection import GSConnection [as 别名]
# 或者: from boto.gs.connection.GSConnection import delete_bucket [as 别名]
def test_3_default_object_acls(self):
"""test default object acls"""
c = GSConnection()
# create a new bucket
bucket_name = 'test-%d' % int(time.time())
bucket = c.create_bucket(bucket_name)
# now call get_bucket to see if it's really there
bucket = c.get_bucket(bucket_name)
bucket.set_def_acl('public-read')
acl = bucket.get_def_acl()
# save public-read acl for later test
public_read_acl = acl
assert acl.to_xml() == ('<AccessControlList><Entries><Entry>' +
'<Scope type="AllUsers"></Scope><Permission>READ</Permission>' +
'</Entry></Entries></AccessControlList>')
# back to private acl
bucket.set_def_acl('private')
acl = bucket.get_def_acl()
assert acl.to_xml() == '<AccessControlList></AccessControlList>'
# set default acl to an xml acl and verify it gets set
bucket.set_def_acl(public_read_acl)
acl = bucket.get_def_acl()
assert acl.to_xml() == ('<AccessControlList><Entries><Entry>' +
'<Scope type="AllUsers"></Scope><Permission>READ</Permission>' +
'</Entry></Entries></AccessControlList>')
# back to private acl
bucket.set_def_acl('private')
acl = bucket.get_def_acl()
assert acl.to_xml() == '<AccessControlList></AccessControlList>'
# delete bucket
c.delete_bucket(bucket)
# repeat default acl tests using boto's storage_uri interface
# create a new bucket
bucket_name = 'test-%d' % int(time.time())
uri = storage_uri('gs://' + bucket_name)
uri.create_bucket()
uri.set_def_acl('public-read')
acl = uri.get_def_acl()
# save public-read acl for later test
public_read_acl = acl
assert acl.to_xml() == ('<AccessControlList><Entries><Entry>' +
'<Scope type="AllUsers"></Scope><Permission>READ</Permission>' +
'</Entry></Entries></AccessControlList>')
# back to private acl
uri.set_def_acl('private')
acl = uri.get_def_acl()
assert acl.to_xml() == '<AccessControlList></AccessControlList>'
# set default acl to an xml acl and verify it gets set
uri.set_def_acl(public_read_acl)
acl = uri.get_def_acl()
assert acl.to_xml() == ('<AccessControlList><Entries><Entry>' +
'<Scope type="AllUsers"></Scope><Permission>READ</Permission>' +
'</Entry></Entries></AccessControlList>')
# back to private acl
uri.set_def_acl('private')
acl = uri.get_def_acl()
assert acl.to_xml() == '<AccessControlList></AccessControlList>'
# delete bucket
uri.delete_bucket()
print '--- tests completed ---'