本文整理汇总了Python中swiftclient.client.get_object函数的典型用法代码示例。如果您正苦于以下问题:Python get_object函数的具体用法?Python get_object怎么用?Python get_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: invokeTestStorlet
def invokeTestStorlet(self, op, withlog=False):
headers = {'X-Run-Storlet': self.storlet_name}
if withlog is True:
headers['X-Storlet-Generate-Log'] = 'True'
params = 'op={0}¶m2=val2'.format(op)
resp_dict = dict()
try:
resp_headers, gf = c.get_object(self.url, self.token, 'myobjects',
'test_object', None, None, params,
resp_dict, headers)
get_text = gf
get_response_status = resp_dict.get('status')
if withlog is True:
resp_headers, gf = c.get_object(self.url, self.token,
'storletlog', 'test.log',
None, None, None, None,
headers)
self.assertEqual(resp_headers.get('status'), 200)
gf.read()
self.assertEqual(resp_headers.get('status') == 200)
if op == 'print':
self.assertEqual(get_response_status, 200)
self.assertTrue('op' in get_text)
self.assertTrue('print' in get_text)
self.assertTrue('param2' in get_text)
self.assertTrue('val2' in get_text)
except Exception:
get_response_status = resp_dict.get('status')
if op == 'crash':
self.assertTrue(get_response_status >= 500 or
get_response_status == 404)
示例2: test_storlet_acl_get_success
def test_storlet_acl_get_success(self):
headers = {'X-Run-Storlet': self.storlet_name}
headers.update(self.additional_headers)
exc_pattern = '^.*403 Forbidden.*$'
with self.assertRaisesRegexp(ClientException, exc_pattern):
swift_client.get_object(self.member_url, self.member_token,
'myobjects', 'test_object',
headers=headers)
headers = {'X-Storlet-Container-Read': self.conf.member_user,
'X-Storlet-Name': self.storlet_name}
swift_client.post_container(self.url,
self.token,
'myobjects',
headers)
swift_client.head_container(self.url,
self.token,
'myobjects')
headers = {'X-Run-Storlet': self.storlet_name}
headers.update(self.additional_headers)
resp_dict = dict()
swift_client.get_object(self.member_url,
self.member_token,
'myobjects', 'test_object',
response_dict=resp_dict,
headers=headers)
self.assertEqual(resp_dict['status'], 200)
示例3: test_sync_lazy_dkey
def test_sync_lazy_dkey(self):
# Create synced containers, but with no key at dest
source_container, dest_container =\
self._setup_synced_containers('secret', None)
# upload to source
object_name = 'object-%s' % uuid.uuid4()
client.put_object(self.url, self.token, source_container, object_name,
'test-body')
# cycle container-sync, nothing should happen
Manager(['container-sync']).once()
with self.assertRaises(ClientException) as err:
_junk, body = client.get_object(self.url, self.token,
dest_container, object_name)
self.assertEqual(err.exception.http_status, HTTP_NOT_FOUND)
# amend dest key
dest_headers = {'X-Container-Sync-Key': 'secret'}
client.put_container(self.url, self.token, dest_container,
headers=dest_headers)
# cycle container-sync, should replicate
Manager(['container-sync']).once()
_junk, body = client.get_object(self.url, self.token,
dest_container, object_name)
self.assertEqual(body, 'test-body')
示例4: delete_given_folder
def delete_given_folder(request, container, foldername):
""" Recursively delete all the objects in the given folder and then
delete the folder itself. """
storage_url = request.session.get('storage_url', '')
auth_token = request.session.get('auth_token', '')
# Get all objects within folder.
meta, objects = client.get_container(
storage_url, auth_token, container,
headers={"X-Forwarded-For": request.META.get('REMOTE_ADDR')},
delimiter='/', prefix=foldername)
# Recursive call to delete subfolders.
pseudofolders, objs = pseudofolder_object_list(objects, foldername)
for folder in pseudofolders:
delete_given_folder(request, container, folder[0])
# Delete all objects.
for obj in objs:
delete_given_object(request, container, obj["name"])
# Delete the folder itself.
try:
client.get_object(
storage_url, auth_token, container, foldername,
headers={"X-Forwarded-For": request.META.get('REMOTE_ADDR')})
delete_given_object(request, container, foldername)
except:
# If folder does not exist, pass
pass
示例5: _do_test
def _do_test(self, overwrite_contents):
self.brain.put_container()
self.brain.stop_primary_half()
# put object to only 1 of 3 primaries
self.brain.put_object(contents='VERIFY')
self.brain.start_primary_half()
# Restart services and attempt to overwrite
with self.assertRaises(client.ClientException) as exc_mgr:
self.brain.put_object(headers={'If-None-Match': '*'},
contents=overwrite_contents)
self.assertEqual(exc_mgr.exception.http_status, 412)
# make sure we're GETting from the servers that missed the original PUT
self.brain.stop_handoff_half()
# verify the PUT did not complete
with self.assertRaises(client.ClientException) as exc_mgr:
client.get_object(
self.url, self.token, self.container_name, self.object_name)
self.assertEqual(exc_mgr.exception.http_status, 404)
# for completeness, run replicators...
Manager(['object-replicator']).once()
# ...and verify the object was not overwritten
_headers, body = client.get_object(
self.url, self.token, self.container_name, self.object_name)
self.assertEqual(body, 'VERIFY')
示例6: _work
def _work(self, op):
running_ops = self.outstanding
self.outstanding += 1
t1 = time()
try:
# client = Connection(authurl='http://192.168.16.12:8080/auth/v1.0', user='test:tester', key='testing')
# client.put_object(self.container,'%s-%s' % (self.base, op), self.data)
get_object(self.storage_url, token=self.token, container=self.container, name='%s-%s' % (self.base, op))
t2 = time()
elapsed = (t2-t1) * 1000
self.outstanding -= 1
LOG.info("Operation #%d took %.2f ms (%.2f MB/s, %d ops outstanding on arrival)" % (op, elapsed, (self.data_size / (1024.*1024)) / (t2 - t1) , running_ops))
entry = { "Operation": op,
"Arrival-time": t1,
"Completion-time": t2,
"Elapsed": elapsed,
"Outstanding-on-arrival": running_ops,
"Outstanding-on-completion": self.outstanding }
print '%d, %f, %f, %.2f, %d, %d' % (op, t1, t2, elapsed, running_ops, self.outstanding)
return entry
except KeyboardInterrupt:
self.outstanding -= 1
self.running = False
return None
except Exception:
self.errors += 1
raise
示例7: test_storlet_acl_get_fail
def test_storlet_acl_get_fail(self):
headers = {'X-Run-Storlet': self.storlet_name}
headers.update(self.additional_headers)
exc_pattern = '^.*403 Forbidden.*$'
with self.assertRaisesRegexp(ClientException, exc_pattern):
swift_client.get_object(self.member_url, self.member_token,
'myobjects', 'test_object',
headers=headers)
示例8: object_info
def object_info(container,obj):
headers, content = client.get_object(url = storageURL,
token = authtoken,
container = container,
name = obj
)
return headers, content
示例9: invoke_storlet
def invoke_storlet(url, token,op, params = None, global_params = None):
if params != None:
querystring=''
for key in params:
querystring += '%s=%s,' % (key, params[key])
querystring = querystring[:-1]
else:
querystring = None
metadata = {'X-Run-Storlet': STORLET_NAME }
if op == 'GET':
# Get original object
original_headers, original_content = c.get_object(url, token,
'myobjects',
SOURCE_FILE,
response_dict=dict(),
headers=metadata)
assert(original_headers['X-Object-Meta-key1'.lower()] == '1')
assert(original_headers['X-Object-Meta-key2'.lower()] == '2')
assert(original_headers['X-Object-Meta-key3'.lower()] == '3')
assert(original_headers['X-Object-Meta-key4'.lower()] == '4')
assert(original_headers['X-Object-Meta-key5'.lower()] == '5')
assert(original_headers['X-Object-Meta-key6'.lower()] == '6')
assert(original_headers['X-Object-Meta-key7'.lower()] == '7')
assert(original_headers['X-Object-Meta-key8'.lower()] == '8')
assert(original_headers['X-Object-Meta-key9'.lower()] == '9')
assert(original_headers['X-Object-Meta-key10'.lower()] == '10')
assert(original_headers['X-Object-Meta-override_key'.lower()] == 'new_value')
示例10: test_metadata_get
def test_metadata_get(self, params=None, global_params=None):
if params is not None:
querystring = ''
for key in params:
querystring += '%s=%s,' % (key, params[key])
querystring = querystring[:-1]
else:
querystring = None
headers = {'X-Run-Storlet': self.storlet_name}
headers.update(self.additional_headers)
original_headers, original_content = \
c.get_object(self.url, self.token,
'myobjects', self.storlet_file,
response_dict=dict(), headers=headers)
self.assertEqual(original_headers['X-Object-Meta-key1'.lower()], '1')
self.assertEqual(original_headers['X-Object-Meta-key2'.lower()], '2')
self.assertEqual(original_headers['X-Object-Meta-key3'.lower()], '3')
self.assertEqual(original_headers['X-Object-Meta-key4'.lower()], '4')
self.assertEqual(original_headers['X-Object-Meta-key5'.lower()], '5')
self.assertEqual(original_headers['X-Object-Meta-key6'.lower()], '6')
self.assertEqual(original_headers['X-Object-Meta-key7'.lower()], '7')
self.assertEqual(original_headers['X-Object-Meta-key8'.lower()], '8')
self.assertEqual(original_headers['X-Object-Meta-key9'.lower()], '9')
self.assertEqual(original_headers['X-Object-Meta-key10'.lower()], '10')
omv = original_headers['X-Object-Meta-override_key'.lower()]
self.assertEqual(omv, 'new_value')
示例11: test_request_headers
def test_request_headers(self):
request_args = {}
def fake_request(method, url, body=None, headers=None):
request_args["method"] = method
request_args["url"] = url
request_args["body"] = body
request_args["headers"] = headers
return
conn = self.fake_http_connection(200)("http://www.test.com/")
conn[1].request = fake_request
headers = {"Range": "bytes=1-2"}
c.get_object("url_is_irrelevant", "TOKEN", "container", "object", http_conn=conn, headers=headers)
self.assertFalse(request_args["headers"] is None, "No headers in the request")
self.assertTrue("Range" in request_args["headers"], "No Range header in the request")
self.assertEqual(request_args["headers"]["Range"], "bytes=1-2")
示例12: download_collection
def download_collection(request, container, prefix=None, non_recursive=False):
""" Download the content of an entire container/pseudofolder
as a Zip file. """
storage_url = request.session.get('storage_url', '')
auth_token = request.session.get('auth_token', '')
delimiter = '/' if non_recursive else None
try:
x, objects = client.get_container(
storage_url,
auth_token,
container,
delimiter=delimiter,
prefix=prefix
)
except client.ClientException:
return HttpResponseForbidden()
x, objs = pseudofolder_object_list(objects, prefix)
# Do not provide download when the folder is empty.
if len(x) + len(objs) == 0:
messages.add_message(
request, messages.ERROR, _("Unable to download, no files found."))
if prefix: # Return user to object view
# remove the last prefix. ex "dir1/dir2/" -> "dir1"
prefix = prefix[0:prefix.rfind('/', 0, prefix.rfind('/'))]
return redirect(swiftbrowser.views.objectview, container=container,
prefix=prefix)
else: # Return user to the container view
return redirect(swiftbrowser.views.containerview)
output = StringIO()
zipf = zipfile.ZipFile(output, 'w')
for o in objs:
name = o['name']
try:
x, content = client.get_object(storage_url, auth_token, container,
name)
except client.ClientException:
return HttpResponseForbidden()
if prefix:
name = name[len(prefix):]
zipf.writestr(name, content)
zipf.close()
if prefix:
filename = prefix.split('/')[-2]
else:
filename = container
response = HttpResponse(output.getvalue(), 'application/zip')
response['Content-Disposition'] = 'attachment; filename="%s.zip"'\
% (filename)
output.close()
return response
示例13: invokeTestStorlet
def invokeTestStorlet(url, token, op, withlog=False):
headers = {'X-Run-Storlet':TEST_STORLET_NAME}
if withlog == True:
headers['X-Storlet-Generate-Log'] = 'True'
params = 'op={0}¶m2=val2'.format(op)
resp_dict = dict()
try:
resp_headers, gf = c.get_object(url, token, 'myobjects',
'test_object', None, None, params,
resp_dict, headers)
#print resp_dict
get_text = gf
#print get_text
get_response_status = resp_dict.get('status')
if withlog == True:
resp_headers, gf = c.get_object(url, token,
'storletlog', 'test.log',
None, None, None, None, headers)
assert resp_headers.get('status') == 200
text = gf.read()
assert resp_headers.get('status') == 200
#print text
if op == 'print':
assert get_response_status == 200
assert 'op' in get_text
assert 'print' in get_text
assert 'param2' in get_text
assert 'val2' in get_text
except Exception as e:
get_response_status = resp_dict.get('status')
if op == 'crash':
print get_response_status
assert get_response_status >= 500 or get_response_status == 404
if op == 'hold':
#print get_response_status
assert get_response_status >= 500 or get_response_status == 404
if op == 'print':
#print get_response_status
raise e
示例14: proxy_get
def proxy_get(self):
# GET object
headers, body = client.get_object(
self.url, self.token, self.container_name, self.object_name, resp_chunk_size=64 * 2 ** 10
)
resp_checksum = md5()
for chunk in body:
resp_checksum.update(chunk)
return resp_checksum.hexdigest()
示例15: test_get
def test_get(self):
resp = dict()
req_headers = {'X-Run-Storlet': self.storlet_name}
headers, content = client.get_object(
self.url, self.token, self.container, self.storlet_file,
response_dict=resp, headers=req_headers)
self.assertEqual(200, resp['status'])
self.assertEqual('simple', headers['x-object-meta-test'])
self.assertEqual(self.content, content)