本文整理汇总了Python中swiftclient.client.post_object函数的典型用法代码示例。如果您正苦于以下问题:Python post_object函数的具体用法?Python post_object怎么用?Python post_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了post_object函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_unicode_ok
def test_unicode_ok(self):
conn = c.http_connection(u'http://www.test.com/')
args = (u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91')
text = u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91'
headers = {'X-Header1': text,
b'X-Header2': 'value',
'X-2': '1', 'X-3': {'a': 'b'}, 'a-b': '.x:yz mn:kl:qr',
'X-Object-Meta-Header-not-encoded': text,
b'X-Object-Meta-Header-encoded': 'value'}
resp = MockHttpResponse()
conn[1].getresponse = resp.fake_response
conn[1]._request = resp._fake_request
c.post_object(*args, headers=headers, http_conn=conn)
# Test for RFC-2616 encoded symbols
self.assertIn(('a-b', b".x:yz mn:kl:qr"), resp.buffer)
# Test unicode header
self.assertIn(('x-header1', text.encode('utf8')),
resp.buffer)
self.assertIn((b'x-object-meta-header-not-encoded',
text.encode('utf8')), resp.buffer)
self.assertIn((b'x-object-meta-header-encoded', b'value'),
resp.buffer)
self.assertIn((b'x-header2', b'value'), resp.buffer)
开发者ID:mgeisler,项目名称:python-swiftclient,代码行数:27,代码来源:test_swiftclient.py
示例2: setUp
def setUp(self):
super(TestReconstructorRebuild, self).setUp()
self.container_name = 'container-%s' % uuid.uuid4()
self.object_name = 'object-%s' % uuid.uuid4()
# sanity
self.assertEqual(self.policy.policy_type, EC_POLICY)
self.reconstructor = Manager(["object-reconstructor"])
# create EC container
headers = {'X-Storage-Policy': self.policy.name}
client.put_container(self.url, self.token, self.container_name,
headers=headers)
# PUT object and POST some metadata
contents = Body()
headers = {'x-object-meta-foo': 'meta-foo'}
self.headers_post = {'x-object-meta-bar': 'meta-bar'}
self.etag = client.put_object(self.url, self.token,
self.container_name,
self.object_name,
contents=contents, headers=headers)
client.post_object(self.url, self.token, self.container_name,
self.object_name, headers=dict(self.headers_post))
self.opart, self.onodes = self.object_ring.get_nodes(
self.account, self.container_name, self.object_name)
# stash frag etags and metadata for later comparison
self.frag_headers, self.frag_etags = self._assert_all_nodes_have_frag()
for node_index, hdrs in self.frag_headers.items():
# sanity check
self.assertIn(
'X-Backend-Durable-Timestamp', hdrs,
'Missing durable timestamp in %r' % self.frag_headers)
开发者ID:bebule,项目名称:swift,代码行数:35,代码来源:test_reconstructor_rebuild.py
示例3: convert
def convert(vid_format, videos, local_file, container, storage_url, auth_token, this_id, id_original, c):
temp_file = videos[vid_format]['temp_file']
headers = _get_video_headers(storage_url, auth_token, container, this_id)
conv = c.convert(local_file, temp_file, videos[vid_format]['options'])
for ftimecode in conv:
timecode = int(ftimecode * 100)
if timecode == 100:
break
video_keys[id_original][vid_format + 'status'] = int(timecode)
headers['X-Object-Meta-Status'] = timecode
client.post_object(storage_url, auth_token, container, this_id, headers=headers)
print "Converting %s (%f) ...%s\n" % (vid_format, timecode, local_file)
if os.path.exists(temp_file):
size = os.path.getsize(temp_file)
print '\n\nSIZE: ', size, '\n\n'
headers = _get_video_headers(storage_url, auth_token, container, this_id)
headers['X-Object-Meta-Content-Type'] = 'video/' + vid_format
headers['X-Object-Meta-Status'] = 100
try:
with open(temp_file, 'r+b') as f:
client.put_object(storage_url, auth_token, container, this_id, f, headers=headers)
except swift_exception.ClientException as e:
storage_url, auth_token = _reauthorize(request)
with open(temp_file, 'r+b') as f:
client.put_object(storage_url, auth_token, container, this_id, f, headers=headers)
video_keys[id_original][vid_format + 'status'] = 100
if os.path.exists(temp_file):
os.remove(temp_file)
开发者ID:InBetween,项目名称:AssetManager,代码行数:28,代码来源:views.py
示例4: test_server_error
def test_server_error(self):
body = 'c' * 60
c.http_connection = self.fake_http_connection(500, body=body)
args = ('http://www.test.com', 'asdf', 'asdf', 'asdf', {})
self.assertRaises(c.ClientException, c.post_object, *args)
try:
c.post_object(*args)
except c.ClientException as e:
self.assertEqual(e.http_response_content, body)
开发者ID:mgeisler,项目名称:python-swiftclient,代码行数:9,代码来源:test_swiftclient.py
示例5: commitMeta
def commitMeta(self):
if self._commitList != {}:
post_object(
self._url,
self._token,
Configuration.container_name,
self._objId,
self._commitList)
self._commitList = {}
开发者ID:icclab,项目名称:powdernote,代码行数:9,代码来源:MetaManager.py
示例6: test_sync_unexpired_object_metadata
def test_sync_unexpired_object_metadata(self):
# verify that metadata can be sync'd to a frag that has missed a POST
# and consequently that frag appears to be expired, when in fact the
# POST removed the x-delete-at header
client.put_container(self.url, self.token, self.container_name,
headers={'x-storage-policy': self.policy.name})
opart, onodes = self.object_ring.get_nodes(
self.account, self.container_name, self.object_name)
delete_at = int(time.time() + 3)
contents = 'body-%s' % uuid.uuid4()
headers = {'x-delete-at': delete_at}
client.put_object(self.url, self.token, self.container_name,
self.object_name, headers=headers, contents=contents)
# fail a primary
post_fail_node = random.choice(onodes)
post_fail_path = self.device_dir('object', post_fail_node)
self.kill_drive(post_fail_path)
# post over w/o x-delete-at
client.post_object(self.url, self.token, self.container_name,
self.object_name, {'content-type': 'something-new'})
# revive failed primary
self.revive_drive(post_fail_path)
# wait for the delete_at to pass, and check that it thinks the object
# is expired
timeout = time.time() + 5
while time.time() < timeout:
try:
direct_client.direct_head_object(
post_fail_node, opart, self.account, self.container_name,
self.object_name, headers={
'X-Backend-Storage-Policy-Index': int(self.policy)})
except direct_client.ClientException as err:
if err.http_status != 404:
raise
break
else:
time.sleep(0.1)
else:
self.fail('Failed to get a 404 from node with expired object')
self.assertEqual(err.http_status, 404)
self.assertIn('X-Backend-Timestamp', err.http_headers)
# but from the proxy we've got the whole story
headers, body = client.get_object(self.url, self.token,
self.container_name,
self.object_name)
self.assertNotIn('X-Delete-At', headers)
self.reconstructor.once()
# ... and all the nodes have the final unexpired state
for node in onodes:
headers = direct_client.direct_head_object(
node, opart, self.account, self.container_name,
self.object_name, headers={
'X-Backend-Storage-Policy-Index': int(self.policy)})
self.assertNotIn('X-Delete-At', headers)
开发者ID:mahak,项目名称:swift,代码行数:56,代码来源:test_reconstructor_rebuild.py
示例7: set_object_expiry_time
def set_object_expiry_time(request, container, objectname):
"""For the given object, set the x-delete-at. """
storage_url = request.session.get('storage_url', '')
auth_token = request.session.get('auth_token', '')
form = TimeForm(request.POST)
if form.is_valid():
days_to_expiry = float(form.cleaned_data['days'])
hours_to_expiry = float(form.cleaned_data['hours'])
# When these values are zero, remove expiration
if (days_to_expiry + hours_to_expiry == 0.0):
try:
client.post_object(
storage_url,
auth_token,
container,
objectname,
{})
messages.add_message(
request,
messages.INFO,
_("Object expiry time removed!"))
except Exception:
messages.error(request, "Error updating object expiry time.")
else:
seconds_to_expiry = int(time.time()) + int(
days_to_expiry * 24 * 3600
+ hours_to_expiry * 60 * 60)
try:
client.post_object(
storage_url,
auth_token,
container,
objectname,
{"x-delete-at": seconds_to_expiry})
messages.add_message(
request,
messages.INFO,
_("Object expiry time updated!"))
except Exception:
messages.error(request, "Error updating object expiry time.")
prefix = '/'.join(objectname.split('/')[:-1])
if prefix:
prefix += '/'
else:
messages.error(request, "Invalid form.")
return redirect(swiftbrowser.views.objectview, container, prefix)
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:53,代码来源:utils.py
示例8: test_unicode_ok
def test_unicode_ok(self):
conn = c.http_connection(u'http://www.test.com/')
args = (u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91')
headers = { #'X-Header1': u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
'X-2': 1, 'X-3': {'a': 'b'}, 'a-b': '.x:yz mn:kl:qr'}
resp = MockHttpResponse()
conn[1].getresponse = resp.fake_response
conn[1].send = resp.fake_send
c.post_object(*args, headers=headers, http_conn=conn)
# Test for RFC-2616 encoded symbols
self.assertTrue("a-b: .x:yz mn:kl:qr" in resp.buffer[0],
"[a-b: .x:yz mn:kl:qr] header is missing")
开发者ID:scottkmaxwell,项目名称:python-swiftclient,代码行数:16,代码来源:test_swiftclient.py
示例9: test_server_error
def test_server_error(self):
body = "c" * 60
c.http_connection = self.fake_http_connection(500, body=body)
args = ("http://www.test.com", "asdf", "asdf", "asdf", {})
self.assertRaises(c.ClientException, c.post_object, *args)
try:
value = c.post_object(*args)
except c.ClientException as e:
self.assertEquals(e.http_response_content, body)
开发者ID:benroeder,项目名称:python-swiftclient,代码行数:9,代码来源:test_swiftclient.py
示例10: _set_headers
def _set_headers(storage_url, auth_token, container, object_name, deleted, request):
try:
try:
header = client.head_object(storage_url, auth_token, container, object_name)
except swift_exception.ClientException as e:
storage_url, auth_token = _reauthorize(request)
header = client.head_object(storage_url, auth_token, container, object_name)
new_header = {'X-Object-Meta-Deleted': deleted,
'X-Object-Meta-Format': header['x-object-meta-format'],
'X-Object-Meta-Resolution': header['x-object-meta-resolution'],
'X-Object-Meta-Name': header['x-object-meta-name'],
'X-Object-Meta-Type': header['x-object-meta-type']
}
copy_of = None
if (header['x-object-meta-format'] in video_types) and (header['x-object-meta-type'] == 'original'):
new_header['X-Object-Meta-Mp4-Id'] = header['x-object-meta-mp4-id']
if 'x-object-meta-status' in header:
new_header['X-Object-Meta-Status'] = header['x-object-meta-status']
if header['x-object-meta-type'] == 'thumbnail':
new_header['X-Object-Meta-Original'] = header['x-object-meta-original']
copy_of = header['x-object-meta-original']
if header['x-object-meta-type'] == 'original':
new_header['X-Object-Meta-Thumb'] = header['x-object-meta-thumb']
if container == 'Video':
copy_of = [header['x-object-meta-thumb'], header['x-object-meta-mp4-id']]
else:
copy_of = header['x-object-meta-thumb']
if 'x-object-meta-preview-id' in header:
new_header['X-Object-Meta-Preview-Id'] = header['x-object-meta-preview-id']
copy_of = [header['x-object-meta-thumb'], header['x-object-meta-preview-id']]
try:
client.post_object(storage_url, auth_token, container, object_name, headers=new_header)
except swift_exception.ClientException as e:
storage_url, auth_token = _reauthorize(request)
client.post_object(storage_url, auth_token, container, object_name, headers=new_header)
return copy_of
except swift_exception.ClientException as e:
raise e
except Exception as e:
raise e
开发者ID:InBetween,项目名称:AssetManager,代码行数:43,代码来源:views.py
示例11: test_unicode_ok
def test_unicode_ok(self):
conn = c.http_connection(u"http://www.test.com/")
args = (
u"\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91",
"\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91",
u"\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91",
u"\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91",
)
text = u"\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91"
headers = {"X-Header1": text, "X-2": "1", "X-3": {"a": "b"}, "a-b": ".x:yz mn:kl:qr"}
resp = MockHttpResponse()
conn[1].getresponse = resp.fake_response
conn[1]._request = resp._fake_request
c.post_object(*args, headers=headers, http_conn=conn)
# Test for RFC-2616 encoded symbols
self.assertTrue((b"a-b", b"a-b: .x:yz mn:kl:qr"), resp.buffer)
# Test unicode header
self.assertIn((b"x-header1", text.encode("utf8")), resp.buffer)
开发者ID:AlphaStaxLLC,项目名称:python-swiftclient,代码行数:19,代码来源:test_swiftclient.py
示例12: _set_headers
def _set_headers(storage_url, auth_token, container, object_name, deleted):
try:
header = client.head_object(storage_url, auth_token, container, object_name)
new_header = {'X-Object-Meta-Deleted': deleted,
'X-Object-Meta-Format': header['x-object-meta-format'],
'X-Object-Meta-Resolution': header['x-object-meta-resolution'],
'X-Object-Meta-Name': header['x-object-meta-name'],
'X-Object-Meta-Type': header['x-object-meta-type']
}
copy_of = None
if header['x-object-meta-type'] == 'thumbnail':
new_header['X-Object-Meta-Original'] = header['x-object-meta-original']
copy_of = header['x-object-meta-original']
if header['x-object-meta-type'] == 'original':
new_header['X-Object-Meta-Thumb'] = header['x-object-meta-thumb']
copy_of = header['x-object-meta-thumb']
client.post_object(storage_url, auth_token, container, object_name, headers=new_header)
return copy_of
except swift_exception.ClientException as e:
raise e
except Exception as e:
raise e
开发者ID:anuj-inbetween,项目名称:swiftMiddleAPI,代码行数:22,代码来源:views.py
示例13: test_main
def test_main(self):
# create EC container
headers = {'X-Storage-Policy': self.policy.name}
client.put_container(self.url, self.token, self.container_name,
headers=headers)
# PUT object
contents = Body()
headers = {'x-object-meta-foo': 'meta-foo'}
headers_post = {'x-object-meta-bar': 'meta-bar'}
etag = client.put_object(self.url, self.token,
self.container_name,
self.object_name,
contents=contents, headers=headers)
client.post_object(self.url, self.token, self.container_name,
self.object_name, headers=headers_post)
del headers_post['X-Auth-Token'] # WTF, where did this come from?
# built up a list of node lists to kill data from,
# first try a single node
# then adjacent nodes and then nodes >1 node apart
opart, onodes = self.object_ring.get_nodes(
self.account, self.container_name, self.object_name)
single_node = [random.choice(onodes)]
adj_nodes = [onodes[0], onodes[-1]]
far_nodes = [onodes[0], onodes[-2]]
test_list = [single_node, adj_nodes, far_nodes]
for node_list in test_list:
for onode in node_list:
try:
self._check_node(onode, opart, etag, headers_post)
except AssertionError as e:
self.fail(
str(e) + '\n... for node %r of scenario %r' % (
self._format_node(onode),
[self._format_node(n) for n in node_list]))
开发者ID:2015-ucsc-hp,项目名称:swift,代码行数:38,代码来源:test_reconstructor_rebuild.py
示例14: test_revert_object
def test_revert_object(self):
# create EC container
headers = {"X-Storage-Policy": self.policy.name}
client.put_container(self.url, self.token, self.container_name, headers=headers)
# get our node lists
opart, onodes = self.object_ring.get_nodes(self.account, self.container_name, self.object_name)
hnodes = self.object_ring.get_more_nodes(opart)
# kill 2 a parity count number of primary nodes so we can
# force data onto handoffs, we do that by renaming dev dirs
# to induce 507
p_dev1 = self.device_dir("object", onodes[0])
p_dev2 = self.device_dir("object", onodes[1])
self.kill_drive(p_dev1)
self.kill_drive(p_dev2)
# PUT object
contents = Body()
headers = {"x-object-meta-foo": "meta-foo"}
headers_post = {"x-object-meta-bar": "meta-bar"}
client.put_object(
self.url, self.token, self.container_name, self.object_name, contents=contents, headers=headers
)
client.post_object(self.url, self.token, self.container_name, self.object_name, headers=headers_post)
del headers_post["X-Auth-Token"] # WTF, where did this come from?
# these primaries can't servce the data any more, we expect 507
# here and not 404 because we're using mount_check to kill nodes
for onode in (onodes[0], onodes[1]):
try:
self.direct_get(onode, opart)
except direct_client.DirectClientException as err:
self.assertEqual(err.http_status, 507)
else:
self.fail("Node data on %r was not fully destoryed!" % (onode,))
# now take out another primary
p_dev3 = self.device_dir("object", onodes[2])
self.kill_drive(p_dev3)
# this node can't servce the data any more
try:
self.direct_get(onodes[2], opart)
except direct_client.DirectClientException as err:
self.assertEqual(err.http_status, 507)
else:
self.fail("Node data on %r was not fully destoryed!" % (onode,))
# make sure we can still GET the object and its correct
# we're now pulling from handoffs and reconstructing
etag = self.proxy_get()
self.assertEqual(etag, contents.etag)
# rename the dev dirs so they don't 507 anymore
self.revive_drive(p_dev1)
self.revive_drive(p_dev2)
self.revive_drive(p_dev3)
# fire up reconstructor on handoff nodes only
for hnode in hnodes:
hnode_id = (hnode["port"] - 6000) / 10
self.reconstructor.once(number=hnode_id)
# first threee primaries have data again
for onode in (onodes[0], onodes[2]):
self.direct_get(onode, opart)
# check meta
meta = client.head_object(self.url, self.token, self.container_name, self.object_name)
for key in headers_post:
self.assertTrue(key in meta)
self.assertEqual(meta[key], headers_post[key])
# handoffs are empty
for hnode in hnodes:
try:
self.direct_get(hnode, opart)
except direct_client.DirectClientException as err:
self.assertEqual(err.http_status, 404)
else:
self.fail("Node data on %r was not fully destoryed!" % (hnode,))
开发者ID:bigdig,项目名称:swift,代码行数:82,代码来源:test_reconstructor_revert.py
示例15: test_ok
def test_ok(self):
c.http_connection = self.fake_http_connection(200)
args = ("http://www.test.com", "asdf", "asdf", "asdf", {})
c.post_object(*args)
开发者ID:AlphaStaxLLC,项目名称:python-swiftclient,代码行数:4,代码来源:test_swiftclient.py
示例16: post_object
def post_object(self, account_id, token, s_type, container, name, headers):
cnx = self.get_cnx(account_id, s_type)
sclient.post_object("", token, container, name, headers, http_conn=cnx)
开发者ID:RegBinder,项目名称:swiftsync,代码行数:3,代码来源:test_syncer.py
注:本文中的swiftclient.client.post_object函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论