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

Python etree.tostring函数代码示例

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

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



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

示例1: 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:tumf,项目名称:swift3,代码行数:7,代码来源:response.py


示例2: GET

    def GET(self, req):
        """
        Handle GET Service request
        """
        resp = req.get_response(self.app, query={'format': 'json'})

        containers = loads(resp.body)
        # we don't keep the creation time of a backet (s3cmd doesn't
        # work without that) so we use something bogus.
        elem = Element('ListAllMyBucketsResult')

        owner = SubElement(elem, 'Owner')
        SubElement(owner, 'ID').text = req.user_id
        SubElement(owner, 'DisplayName').text = req.user_id

        buckets = SubElement(elem, 'Buckets')
        for c in containers:
            bucket = SubElement(buckets, 'Bucket')
            SubElement(bucket, 'Name').text = c['name']
            SubElement(bucket, 'CreationDate').text = \
                '2009-02-03T16:45:09.000Z'

        body = tostring(elem)

        return HTTPOk(content_type='application/xml', body=body)
开发者ID:yinyinbigdata,项目名称:swift3-stackforge,代码行数:25,代码来源:service.py


示例3: 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:swiftstack,项目名称:swift3-stackforge,代码行数:7,代码来源:test_etree.py


示例4: 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'},
                            body=xml)
        status, headers, body = self.call_swift3(req)
        self.assertEquals(status.split()[0], '200')

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


示例5: _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 = md5(body).digest().encode('base64').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_swift3(req)
开发者ID:sivakrishnan47,项目名称:swift3,代码行数:26,代码来源:test_multi_delete.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:KoreaCloudObjectStorage,项目名称:swift3,代码行数:7,代码来源:test_multi_delete.py


示例7: to_xml

    def to_xml(self):
        conf_elem = Element('LifecycleConfiguration')
        for rule in self.rules:
            rule_elem = SubElement(conf_elem, 'Rule')
            rule.to_xml(rule_elem)

        return tostring(conf_elem)
开发者ID:ichi-shin,项目名称:swift3,代码行数:7,代码来源:acl.py


示例8: _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:erwasambo,项目名称:swift3,代码行数:7,代码来源:test_multi_upload.py


示例9: POST

    def POST(self, req):
        """
        Handles Initiate Multipart Upload.
        """

        # Create a unique S3 upload id from UUID to avoid duplicates.
        upload_id = unique_id()

        container = req.container_name + MULTIUPLOAD_SUFFIX
        try:
            req.get_response(self.app, 'PUT', container, '')
        except BucketAlreadyExists:
            pass

        obj = '%s/%s' % (req.object_name, upload_id)

        req.get_response(self.app, 'PUT', container, obj, body='')

        result_elem = Element('InitiateMultipartUploadResult')
        SubElement(result_elem, 'Bucket').text = req.container_name
        SubElement(result_elem, 'Key').text = req.object_name
        SubElement(result_elem, 'UploadId').text = upload_id

        body = tostring(result_elem)

        return HTTPOk(body=body, content_type='application/xml')
开发者ID:tumf,项目名称:swift3,代码行数:26,代码来源:multi_upload.py


示例10: POST

    def POST(self, req):
        if not req.object_name:
            raise InvalidRequest('A key must be specified')

        # Create a unique S3 upload id from UUID to avoid duplicates.
        upload_id = unique_id()

        container = req.container_name + '+segments'
        try:
            req.put_swift_container(self.app, container=container)
        except BucketAlreadyExists:
            pass
        req.put_upload_status(self.app, upload_id)

        #
        # Return the S3 response
        #
        result_elem = Element('InitiateMultipartUploadResult')
        SubElement(result_elem, 'Bucket').text = req.container_name
        SubElement(result_elem, 'Key').text = req.object_name
        SubElement(result_elem, 'UploadId').text = upload_id

        body = tostring(result_elem)

        return HTTPOk(body=body, content_type='application/xml')
开发者ID:ichi-shin,项目名称:swift3,代码行数:25,代码来源:multi_upload.py


示例11: PUT

    def PUT(self, req):
        if 'uploadId' not in req.params:
            raise InvalidArgument('ResourceType', 'partNumber',
                                  'Unexpected query string parameter')

        try:
            partNumber = int(req.params['partNumber'])
            if partNumber < 1 or utils.MAX_MAX_PARTS < partNumber:
                raise Exception()
        except Exception:
            err_msg = 'Part number must be an integer between 1 and ' \
                '%d, inclusive' % utils.MAX_MAX_PARTS
            raise InvalidArgument('partNumber', req.params['partNumber'],
                                  err_msg)

        upload_id = req.params['uploadId']
        _check_owner_from_upload_id(self.app, req, upload_id)

        container = req.container_name + '+segments'
        obj = '%s/%s/%d' % (req.object_name, upload_id,
                            int(req.params['partNumber']))
        resp = req.put_swift_object(self.app, container=container, obj=obj,
                                    access_check=True)

        if req.copy_source is not None:
            result_elem = Element('CopyPartResult', use_s3ns=False)
            SubElement(result_elem, 'LastModified').text = \
                resp.last_modified.isoformat()[:-6] + '.000Z'
            SubElement(result_elem, 'ETag').text = resp.etag
            resp.body = tostring(result_elem)

        resp.status = 200
        resp.etag = resp.etag  # add '"'
        return resp
开发者ID:ichi-shin,项目名称:swift3,代码行数:34,代码来源:multi_upload.py


示例12: test_object_multi_DELETE

    def test_object_multi_DELETE(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')
        for key in ['Key1', 'Key2']:
            obj = SubElement(elem, 'Object')
            SubElement(obj, 'Key').text = key
        body = tostring(elem, use_s3ns=False)
        content_md5 = md5(body).digest().encode('base64').strip()

        req = Request.blank('/bucket?delete',
                            environ={'REQUEST_METHOD': 'POST'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Content-MD5': content_md5},
                            body=body)
        req.date = datetime.now()
        req.content_type = 'text/plain'
        status, headers, body = self.call_swift3(req)
        self.assertEquals(status.split()[0], '200')

        elem = fromstring(body)
        self.assertEquals(len(elem.findall('Deleted')), 2)
开发者ID:yinyinbigdata,项目名称:swift3-stackforge,代码行数:25,代码来源:test_multi_delete.py


示例13: _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},
                            body=tostring(acl.elem()))

        return self.call_swift3(req)
开发者ID:tumf,项目名称:swift3,代码行数:8,代码来源:test_s3_acl.py


示例14: _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:KoreaCloudObjectStorage,项目名称:swift3,代码行数:9,代码来源:test_multi_delete.py


示例15: GET

    def GET(self, req):
        """
        Handle GET Bucket (List Objects) request
        """
        if 'max-keys' in req.params:
            if req.params.get('max-keys').isdigit() is False:
                raise InvalidArgument('max-keys', req.params['max-keys'])

        max_keys = min(int(req.params.get('max-keys', MAX_BUCKET_LISTING)),
                       MAX_BUCKET_LISTING)

        query = {
            'format': 'json',
            'limit': max_keys + 1,
        }
        if 'marker' in req.params:
            query.update({'marker': req.params['marker']})
        if 'prefix' in req.params:
            query.update({'prefix': req.params['prefix']})
        if 'delimiter' in req.params:
            query.update({'delimiter': req.params['delimiter']})

        resp = req.get_response(self.app, query=query)

        objects = loads(resp.body)

        elem = Element('ListBucketResult')
        SubElement(elem, 'Prefix').text = req.params.get('prefix')
        SubElement(elem, 'Marker').text = req.params.get('marker')
        SubElement(elem, 'Delimiter').text = req.params.get('delimiter')
        if max_keys > 0 and len(objects) == max_keys + 1:
            is_truncated = 'true'
        else:
            is_truncated = 'false'
        SubElement(elem, 'IsTruncated').text = is_truncated
        SubElement(elem, 'MaxKeys').text = str(max_keys)
        SubElement(elem, 'Name').text = req.container_name

        for o in objects[:max_keys]:
            if 'subdir' not in o:
                contents = SubElement(elem, 'Contents')
                SubElement(contents, 'Key').text = o['name']
                SubElement(contents, 'LastModified').text = \
                    o['last_modified'] + 'Z'
                SubElement(contents, 'ETag').text = o['hash']
                SubElement(contents, 'Size').text = str(o['bytes'])
                add_canonical_user(contents, 'Owner', req.access_key)

        for o in objects[:max_keys]:
            if 'subdir' in o:
                common_prefixes = SubElement(elem, 'CommonPrefixes')
                SubElement(common_prefixes, 'Prefix').text = o['subdir']

        body = tostring(elem)

        return HTTPOk(body=body, content_type='application/xml')
开发者ID:charz,项目名称:swift3,代码行数:56,代码来源:bucket.py


示例16: 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'},
                         body=tostring(
                             ACLPrivate(
                                 Owner(id='test:other',
                                       name='test:other')).elem()))
     status, headers, body = self.call_swift3(req)
     self.assertEquals(self._get_error_code(body), 'AccessDenied')
开发者ID:tumf,项目名称:swift3,代码行数:10,代码来源:test_s3_acl.py


示例17: test_too_many_rules

    def test_too_many_rules(self):
        def add_rule(parent, rule_id):
            rule_elem = SubElement(parent, 'Rule')
            SubElement(rule_elem, 'ID').text = rule_id
            SubElement(rule_elem, 'Prefix').text = rule_id
            SubElement(rule_elem, 'Status').text = 'Enabled'
            expire_elem = SubElement(rule_elem, 'Expiration')
            SubElement(expire_elem, 'Days').text = '1'

        conf_elem = Element('LifecycleConfiguration')
        for n in range(1000):
            rule_id = 'rule%d_id' % n
            add_rule(conf_elem, rule_id)

        xml = tostring(conf_elem)
        LifecycleConf(xml=xml, ts=0)

        add_rule(conf_elem, 'rule1001_id')
        xml = tostring(conf_elem)
        self.assertRaises(MalformedXML, LifecycleConf, xml=xml, ts=0)
开发者ID:ichi-shin,项目名称:swift3,代码行数:20,代码来源:test_lifecycle.py


示例18: GET

    def GET(self, req):
        """
        Handles GET Bucket acl and GET Object acl.
        """
        resp = req.get_response(self.app)
        acl = getattr(resp, "%s_acl" % ("object" if req.is_object_request else "bucket"))

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

        return resp
开发者ID:sivakrishnan47,项目名称:swift3,代码行数:11,代码来源:s3_acl.py


示例19: GET

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

        # Just report there is no versioning configured here.
        elem = Element('VersioningConfiguration')
        body = tostring(elem)

        return HTTPOk(body=body, content_type="text/plain")
开发者ID:charz,项目名称:swift3,代码行数:11,代码来源:versioning.py


示例20: _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:tumf,项目名称:swift3,代码行数:11,代码来源:response.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python middleware.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