• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python client.get_object函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中swiftclient.client.get_object函数的典型用法代码示例。如果您正苦于以下问题:Python get_object函数的具体用法?Python get_object怎么用?Python get_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_object函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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}&param2=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)
开发者ID:Nicolepcx,项目名称:storlets,代码行数:35,代码来源:test_test_storlet.py


示例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)
开发者ID:openstack,项目名称:storlets,代码行数:27,代码来源:test_test_storlet.py


示例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')
开发者ID:Ahiknsr,项目名称:swift,代码行数:26,代码来源:test_container_sync.py


示例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
开发者ID:bkawula,项目名称:django-swiftbrowser,代码行数:31,代码来源:__init__.py


示例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')
开发者ID:jgmerritt,项目名称:swift,代码行数:29,代码来源:test_object_conditional_requests.py


示例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
开发者ID:Seagate,项目名称:knobs,代码行数:27,代码来源:benchmarker-swift-read.py


示例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)
开发者ID:openstack,项目名称:storlets,代码行数:8,代码来源:test_test_storlet.py


示例8: object_info

def object_info(container,obj):
    headers, content = client.get_object(url = storageURL,
                                         token = authtoken,
                                         container = container,
                                         name = obj
                                        )
    return headers, content
开发者ID:daokhactuan48,项目名称:Admin-Dashboard,代码行数:7,代码来源:swift_test.py


示例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')
开发者ID:Open-I-Beam,项目名称:swift-storlets,代码行数:28,代码来源:metadata_storlet_test.py


示例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')
开发者ID:openstack,项目名称:storlets,代码行数:27,代码来源:test_metadata_storlet.py


示例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")
开发者ID:AlphaStaxLLC,项目名称:python-swiftclient,代码行数:17,代码来源:test_swiftclient.py


示例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
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:58,代码来源:utils.py


示例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}&param2=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
开发者ID:ymoatti,项目名称:swift-storlets,代码行数:45,代码来源:sys_test.py


示例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()
开发者ID:bigdig,项目名称:swift,代码行数:9,代码来源:test_reconstructor_revert.py


示例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)
开发者ID:openstack,项目名称:storlets,代码行数:9,代码来源:test_simple_storlet.py


示例16: 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


示例17: invoke_identity_on_get_SLO

def invoke_identity_on_get_SLO(url, token):
    metadata = {'X-Run-Storlet': IDENTITY_STORLET_NAME }
    response = dict()
    headers, body = c.get_object(url, token,
                                 'myobjects','assembly',
                                 query_string = None,
                                 response_dict=response,
                                 resp_chunk_size=1048576,
                                 headers=metadata)
    compare_slo_to_chunks(body)
开发者ID:Open-I-Beam,项目名称:swift-storlets,代码行数:10,代码来源:SLO_test.py


示例18: _test_get_range

 def _test_get_range(self, start, end, expected):
     srange = 'bytes=%d-%d' % (start, end)
     headers = {'X-Run-Storlet': self.storlet_name,
                'X-Storlet-Range': srange}
     junk, content = c.get_object(self.url, self.token,
                                  'myobjects',
                                  'small',
                                  headers=headers,
                                  response_dict=dict())
     self.assertEqual(content, expected)
开发者ID:openstack,项目名称:storlets,代码行数:10,代码来源:test_identity_storlet.py


示例19: get_obj

def get_obj(request, container, object_name):
    """Download an object from Swift
    :param container: container of swift where object is stored
    :param object_name: ID of object
    :return: object bytestream
    """
    try:
        storage_url, auth_token = _get_auth_data(request.session)
        try:
            obj_headers, obj = client.get_object(storage_url, auth_token, container, object_name)
        except swift_exception.ClientException as e:
            storage_url, auth_token = _reauthorize(request)
            obj_headers, obj = client.get_object(storage_url, auth_token, container, object_name)
        filetype = obj_headers['x-object-meta-format'].lower()
        filename = obj_headers['x-object-meta-name']
        header = obj_headers
        # print obj_headers
        if 'download' in request.GET:
            if request.GET['download']:
                extension = ''
                if len(filename.split('.')) > 1:
                    extension = '.' + filename.split('.')[-1]
                filename = request.GET['download'] + extension
            header['Content-Disposition'] = 'attachment;filename="%s"' % filename
        else:
            header['Content-Disposition'] = 'inline;filename="%s"' % filename
        if filetype == 'pdf':
            header['X-Frame-Options'] = ''
            return Response(obj, headers=header, content_type='application/pdf')
        content_type = ''
        if filetype in video_formats:
            content_type = 'video/' + filetype
        if filetype in image_types:
            content_type = 'image/' + filetype
        if content_type:
            return Response(obj, headers=header, content_type=content_type)
        return Response(obj, headers=header)
    except swift_exception.ClientException as e:
        print e
        return Response('Please Contact Your Administrator', status=status.HTTP_401_UNAUTHORIZED)
    except Exception as e:
        print e
        return Response(e.message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
开发者ID:InBetween,项目名称:AssetManager,代码行数:43,代码来源:views.py


示例20: read

    def read(self, read_bytes=None, offset=None):
        ''' Read the object from swift if not read_bytes read the whole
        object'''
        headers = {}
        if read_bytes is not None and offset is not None:
            headers["Range"] = "bytes=%s-%s" % (offset, offset + read_bytes)

        return get_object(self.swift_info["url"], self.token,
               self.swift_info["container"], self.swift_info["object"],
               headers=headers)[1][:read_bytes]
开发者ID:LabAdvComp,项目名称:tukey_middleware,代码行数:10,代码来源:object_info.py



注:本文中的swiftclient.client.get_object函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python client.head_account函数代码示例发布时间:2022-05-27
下一篇:
Python client.get_container函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap