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

Python etree.tostring函数代码示例

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

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



在下文中一共展示了tostring函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _gen_comp_xml

 def _gen_comp_xml(self, etags):
     elem = Element('CompleteMultipartUpload')
     for i, etag in enumerate(etags):
         elem_part = SubElement(elem, 'Part')
         SubElement(elem_part, 'PartNumber').text = str(i + 1)
         SubElement(elem_part, 'ETag').text = etag
     return tostring(elem)
开发者ID:jgmerritt,项目名称:swift,代码行数:7,代码来源:test_multi_upload.py


示例2: append_copy_resp_body

 def append_copy_resp_body(self, controller_name, last_modified):
     elem = Element('Copy%sResult' % controller_name)
     SubElement(elem, 'LastModified').text = last_modified
     SubElement(elem, 'ETag').text = '"%s"' % self.etag
     self.headers['Content-Type'] = 'application/xml'
     self.body = tostring(elem)
     self.etag = None
开发者ID:mahak,项目名称:swift,代码行数:7,代码来源:s3response.py


示例3: _test_object_multi_DELETE

    def _test_object_multi_DELETE(self, account):
        self.keys = ['Key1', 'Key2']
        self.swift.register(
            'DELETE', '/v1/AUTH_test/bucket/%s' % self.keys[0],
            swob.HTTPNoContent, {}, None)
        self.swift.register(
            'DELETE', '/v1/AUTH_test/bucket/%s' % self.keys[1],
            swob.HTTPNotFound, {}, None)

        elem = Element('Delete')
        for key in self.keys:
            obj = SubElement(elem, 'Object')
            SubElement(obj, 'Key').text = key
        body = tostring(elem, use_s3ns=False)
        content_md5 = base64.b64encode(md5(body).digest()).strip()

        req = Request.blank('/bucket?delete',
                            environ={'REQUEST_METHOD': 'POST'},
                            headers={'Authorization': 'AWS %s:hmac' % account,
                                     'Date': self.get_date_header(),
                                     'Content-MD5': content_md5},
                            body=body)
        req.date = datetime.now()
        req.content_type = 'text/plain'

        return self.call_s3api(req)
开发者ID:mahak,项目名称:swift,代码行数:26,代码来源:test_multi_delete.py


示例4: test_tostring_with_nonascii_text

 def test_tostring_with_nonascii_text(self):
     elem = etree.Element('Test')
     sub = etree.SubElement(elem, 'FOO')
     sub.text = '\xef\xbc\xa1'
     self.assertTrue(isinstance(sub.text, str))
     xml_string = etree.tostring(elem)
     self.assertTrue(isinstance(xml_string, str))
开发者ID:jgmerritt,项目名称:swift,代码行数:7,代码来源:test_etree.py


示例5: test_bucket_acl_PUT

    def test_bucket_acl_PUT(self):
        elem = Element('AccessControlPolicy')
        owner = SubElement(elem, 'Owner')
        SubElement(owner, 'ID').text = 'id'
        acl = SubElement(elem, 'AccessControlList')
        grant = SubElement(acl, 'Grant')
        grantee = SubElement(grant, 'Grantee', nsmap={'xsi': XMLNS_XSI})
        grantee.set('{%s}type' % XMLNS_XSI, 'Group')
        SubElement(grantee, 'URI').text = \
            'http://acs.amazonaws.com/groups/global/AllUsers'
        SubElement(grant, 'Permission').text = 'READ'

        xml = tostring(elem)
        req = Request.blank('/bucket?acl',
                            environ={'REQUEST_METHOD': 'PUT'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()},
                            body=xml)
        status, headers, body = self.call_s3api(req)
        self.assertEqual(status.split()[0], '200')

        req = Request.blank('/bucket?acl',
                            environ={'REQUEST_METHOD': 'PUT',
                                     'wsgi.input': StringIO(xml)},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header(),
                                     'Transfer-Encoding': 'chunked'})
        self.assertIsNone(req.content_length)
        self.assertIsNone(req.message_length())
        status, headers, body = self.call_s3api(req)
        self.assertEqual(status.split()[0], '200')
开发者ID:jgmerritt,项目名称:swift,代码行数:31,代码来源:test_acl.py


示例6: _gen_invalid_multi_delete_xml

    def _gen_invalid_multi_delete_xml(self, hasObjectTag=False):
        elem = Element('Delete')
        if hasObjectTag:
            obj = SubElement(elem, 'Object')
            SubElement(obj, 'Key').text = ''

        return tostring(elem, use_s3ns=False)
开发者ID:mahak,项目名称:swift,代码行数:7,代码来源:test_multi_delete.py


示例7: test_object_multi_DELETE_quiet

    def test_object_multi_DELETE_quiet(self):
        self.swift.register('DELETE', '/v1/AUTH_test/bucket/Key1',
                            swob.HTTPNoContent, {}, None)
        self.swift.register('DELETE', '/v1/AUTH_test/bucket/Key2',
                            swob.HTTPNotFound, {}, None)

        elem = Element('Delete')
        SubElement(elem, 'Quiet').text = 'true'
        for key in ['Key1', 'Key2']:
            obj = SubElement(elem, 'Object')
            SubElement(obj, 'Key').text = key
        body = tostring(elem, use_s3ns=False)
        content_md5 = base64.b64encode(md5(body).digest()).strip()

        req = Request.blank('/bucket?delete',
                            environ={'REQUEST_METHOD': 'POST'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header(),
                                     'Content-MD5': content_md5},
                            body=body)
        status, headers, body = self.call_s3api(req)
        self.assertEqual(status.split()[0], '200')

        elem = fromstring(body)
        self.assertEqual(len(elem.findall('Deleted')), 0)
开发者ID:mahak,项目名称:swift,代码行数:25,代码来源:test_multi_delete.py


示例8: _test_object_acl_PUT

    def _test_object_acl_PUT(self, account, permission='FULL_CONTROL'):
        acl = ACL(self.default_owner, [Grant(User(account), permission)])
        req = Request.blank('/bucket/object?acl',
                            environ={'REQUEST_METHOD': 'PUT'},
                            headers={'Authorization': 'AWS %s:hmac' % account,
                                     'Date': self.get_date_header()},
                            body=tostring(acl.elem()))

        return self.call_s3api(req)
开发者ID:jgmerritt,项目名称:swift,代码行数:9,代码来源:test_s3_acl.py


示例9: _gen_multi_delete_xml

    def _gen_multi_delete_xml(self, objects, quiet=None):
        elem = Element('Delete')
        if quiet:
            SubElement(elem, 'Quiet').text = quiet
        for key in objects:
            obj = SubElement(elem, 'Object')
            SubElement(obj, 'Key').text = key

        return tostring(elem, use_s3ns=False)
开发者ID:mahak,项目名称:swift,代码行数:9,代码来源:test_multi_delete.py


示例10: test_bucket_acl_PUT_with_other_owner

 def test_bucket_acl_PUT_with_other_owner(self):
     req = Request.blank('/bucket?acl',
                         environ={'REQUEST_METHOD': 'PUT'},
                         headers={'Authorization': 'AWS test:tester:hmac',
                                  'Date': self.get_date_header()},
                         body=tostring(
                             ACLPrivate(
                                 Owner(id='test:other',
                                       name='test:other')).elem()))
     status, headers, body = self.call_s3api(req)
     self.assertEqual(self._get_error_code(body), 'AccessDenied')
开发者ID:jgmerritt,项目名称:swift,代码行数:11,代码来源:test_s3_acl.py


示例11: GET

    def GET(self, req):
        """
        Handles GET Bucket logging.
        """
        req.get_response(self.app, method='HEAD')

        # logging disabled
        elem = Element('BucketLoggingStatus')
        body = tostring(elem)

        return HTTPOk(body=body, content_type='application/xml')
开发者ID:jgmerritt,项目名称:swift,代码行数:11,代码来源:logging.py


示例12: _body_iter

    def _body_iter(self):
        error_elem = Element('Error')
        SubElement(error_elem, 'Code').text = self._code
        SubElement(error_elem, 'Message').text = self._msg
        if 'swift.trans_id' in self.environ:
            request_id = self.environ['swift.trans_id']
            SubElement(error_elem, 'RequestId').text = request_id

        self._dict_to_etree(error_elem, self.info)

        yield tostring(error_elem, use_s3ns=False)
开发者ID:matthewoliver,项目名称:swift,代码行数:11,代码来源:s3response.py


示例13: _make_xml

def _make_xml(grantee):
    owner = 'test:tester'
    permission = 'READ'
    elem = Element('AccessControlPolicy')
    elem_owner = SubElement(elem, 'Owner')
    SubElement(elem_owner, 'ID').text = owner
    SubElement(elem_owner, 'DisplayName').text = owner
    acl_list_elem = SubElement(elem, 'AccessControlList')
    elem_grant = SubElement(acl_list_elem, 'Grant')
    elem_grant.append(grantee)
    SubElement(elem_grant, 'Permission').text = permission
    return tostring(elem)
开发者ID:jgmerritt,项目名称:swift,代码行数:12,代码来源:test_s3_acl.py


示例14: GET

    def GET(self, req):
        """
        Handles GET Bucket location.
        """
        req.get_response(self.app, method='HEAD')

        elem = Element('LocationConstraint')
        if self.conf.location != 'US':
            elem.text = self.conf.location
        body = tostring(elem)

        return HTTPOk(body=body, content_type='application/xml')
开发者ID:jgmerritt,项目名称:swift,代码行数:12,代码来源:location.py


示例15: GET

    def GET(self, req):
        """
        Handles GET Bucket acl and GET Object acl.
        """
        resp = req.get_response(self.app)

        acl = resp.object_acl if req.is_object_request else resp.bucket_acl

        resp = HTTPOk()
        resp.body = tostring(acl.elem())

        return resp
开发者ID:jgmerritt,项目名称:swift,代码行数:12,代码来源:s3_acl.py


示例16: _test_bucket_PUT_with_location

    def _test_bucket_PUT_with_location(self, root_element):
        elem = Element(root_element)
        SubElement(elem, 'LocationConstraint').text = 'US'
        xml = tostring(elem)

        req = Request.blank('/bucket',
                            environ={'REQUEST_METHOD': 'PUT'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()},
                            body=xml)
        status, headers, body = self.call_s3api(req)
        self.assertEqual(status.split()[0], '200')
开发者ID:jgmerritt,项目名称:swift,代码行数:12,代码来源:test_bucket.py


示例17: _gen_error_body

    def _gen_error_body(self, error, elem, delete_list):
        for key, version in delete_list:
            if version is not None:
                # TODO: delete the specific version of the object
                raise S3NotImplemented()

            error_elem = SubElement(elem, 'Error')
            SubElement(error_elem, 'Key').text = key
            SubElement(error_elem, 'Code').text = error.__class__.__name__
            SubElement(error_elem, 'Message').text = error._msg

        return tostring(elem)
开发者ID:mahak,项目名称:swift,代码行数:12,代码来源:multi_delete.py


示例18: test_bucket_PUT_with_location_error

    def test_bucket_PUT_with_location_error(self):
        elem = Element('CreateBucketConfiguration')
        SubElement(elem, 'LocationConstraint').text = 'XXX'
        xml = tostring(elem)

        req = Request.blank('/bucket',
                            environ={'REQUEST_METHOD': 'PUT'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()},
                            body=xml)
        status, headers, body = self.call_s3api(req)
        self.assertEqual(self._get_error_code(body),
                         'InvalidLocationConstraint')
开发者ID:jgmerritt,项目名称:swift,代码行数:13,代码来源:test_bucket.py


示例19: test_grant_with_both_header_and_xml

 def test_grant_with_both_header_and_xml(self):
     req = Request.blank('/bucket/object?acl',
                         environ={'REQUEST_METHOD': 'PUT'},
                         headers={'Authorization': 'AWS test:tester:hmac',
                                  'Date': self.get_date_header(),
                                  'x-amz-grant-full-control':
                                  'id=test:tester'},
                         body=tostring(
                             ACLPrivate(
                                 Owner(id='test:tester',
                                       name='test:tester')).elem()))
     status, headers, body = self.call_s3api(req)
     self.assertEqual(self._get_error_code(body), 'UnexpectedContent')
开发者ID:jgmerritt,项目名称:swift,代码行数:13,代码来源:test_s3_acl.py


示例20: test_object_multi_DELETE_without_md5

    def test_object_multi_DELETE_without_md5(self):
        elem = Element('Delete')
        for key in ['Key1', 'Key2']:
            obj = SubElement(elem, 'Object')
            SubElement(obj, 'Key').text = key
        body = tostring(elem, use_s3ns=False)

        req = Request.blank('/bucket?delete',
                            environ={'REQUEST_METHOD': 'POST'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()},
                            body=body)
        status, headers, body = self.call_s3api(req)
        self.assertEqual(self._get_error_code(body), 'InvalidRequest')
开发者ID:mahak,项目名称:swift,代码行数:14,代码来源:test_multi_delete.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python staticweb.filter_factory函数代码示例发布时间:2022-05-27
下一篇:
Python etree.fromstring函数代码示例发布时间: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