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

Python etree.fromstring函数代码示例

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

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



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

示例1: test_bucket_versioning_GET

 def test_bucket_versioning_GET(self):
     req = Request.blank('/bucket?versioning',
                         environ={'REQUEST_METHOD': 'GET'},
                         headers={'Authorization': 'AWS test:tester:hmac',
                                  'Date': self.get_date_header()})
     status, headers, body = self.call_swift3(req)
     fromstring(body, 'VersioningConfiguration')
开发者ID:notmyname,项目名称:swift3,代码行数:7,代码来源:test_versioning.py


示例2: test_service

    def test_service(self):
        # GET Service(without bucket)
        status, headers, body = self.conn.make_request('GET')
        self.assertEquals(status, 200)

        self.assertCommonResponseHeaders(headers)
        self.assertTrue(headers['content-type'] is not None)
        # TODO; requires consideration
        # self.assertEquasl(headers['transfer-encoding'], 'chunked')

        elem = fromstring(body, 'ListAllMyBucketsResult')
        buckets = elem.findall('./Buckets/Bucket')
        self.assertEquals(list(buckets), [])
        owner = elem.find('Owner')
        self.assertEquals(self.conn.user_id, owner.find('ID').text)
        self.assertEquals(self.conn.user_id, owner.find('DisplayName').text)

        # GET Service(with Bucket)
        req_buckets = ('bucket', 'bucket2')
        for bucket in req_buckets:
            self.conn.make_request('PUT', bucket)
        status, headers, body = self.conn.make_request('GET')
        self.assertEquals(status, 200)

        elem = fromstring(body, 'ListAllMyBucketsResult')
        resp_buckets = elem.findall('./Buckets/Bucket')
        self.assertEquals(len(list(resp_buckets)), 2)
        for b in resp_buckets:
            self.assertTrue(b.find('Name').text in req_buckets)
            self.assertTrue(b.find('CreationDate') is not None)
开发者ID:sivakrishnan47,项目名称:swift3,代码行数:30,代码来源:test_service.py


示例3: test_bucket_object_versions_GET_common_prefix

 def test_bucket_object_versions_GET_common_prefix(self):
     req = Request.blank('/bucket?versions&prefix=photos/2006/&delimiter=/',
                         environ={'REQUEST_METHOD': 'GET'},
                         headers={'Authorization': 'AWS test:tester:hmac'})
     status, headers, body = self.call_swift3(req)
     fromstring(body, 'ListVersionsResult')
     self.assertEquals(status.split()[0], '200')
开发者ID:ichi-shin,项目名称:swift3,代码行数:7,代码来源:test_versioning.py


示例4: test_object_versioning_GET

 def test_object_versioning_GET(self):
     req = Request.blank('/bucket/object?versioning',
                         environ={'REQUEST_METHOD': 'GET'},
                         headers={'Authorization': 'AWS test:tester:hmac'})
     status, headers, body = self.call_swift3(req)
     self.assertEquals(status.split()[0], '200')
     fromstring(body, 'VersioningConfiguration')
开发者ID:KoreaCloudObjectStorage,项目名称:swift3,代码行数:7,代码来源:test_versioning.py


示例5: test_object_list_parts_same_max_marts_as_objects_num

 def test_object_list_parts_same_max_marts_as_objects_num(self):
     req = Request.blank('/bucket/object?uploadId=X&max-parts=3',
                         environ={'REQUEST_METHOD': 'GET'},
                         headers={'Authorization': 'AWS test:tester:hmac'})
     status, headers, body = self.call_swift3(req)
     fromstring(body, 'ListPartsResult')
     self.assertEquals(status.split()[0], '200')
开发者ID:ichi-shin,项目名称:swift3,代码行数:7,代码来源:test_multi_upload.py


示例6: test_xml_namespace

    def test_xml_namespace(self):
        def test_xml(ns, prefix):
            return '<A %(ns)s><%(prefix)sB>C</%(prefix)sB></A>' % \
                ({'ns': ns, 'prefix': prefix})

        # No namespace is same as having the S3 namespace.
        xml = test_xml('', '')
        elem = etree.fromstring(xml)
        self.assertEqual(elem.find('./B').text, 'C')

        # The S3 namespace is handled as no namespace.
        xml = test_xml('xmlns="%s"' % etree.XMLNS_S3, '')
        elem = etree.fromstring(xml)
        self.assertEqual(elem.find('./B').text, 'C')

        xml = test_xml('xmlns:s3="%s"' % etree.XMLNS_S3, 's3:')
        elem = etree.fromstring(xml)
        self.assertEqual(elem.find('./B').text, 'C')

        # Any namespaces without a prefix work as no namespace.
        xml = test_xml('xmlns="http://example.com/"', '')
        elem = etree.fromstring(xml)
        self.assertEqual(elem.find('./B').text, 'C')

        xml = test_xml('xmlns:s3="http://example.com/"', 's3:')
        elem = etree.fromstring(xml)
        self.assertIsNone(elem.find('./B'))
开发者ID:swiftstack,项目名称:swift3-stackforge,代码行数:27,代码来源:test_etree.py


示例7: test_bucket_GET_is_truncated

    def test_bucket_GET_is_truncated(self):
        bucket_name = 'junk'

        req = Request.blank('/%s?max-keys=5' % bucket_name,
                            environ={'REQUEST_METHOD': 'GET'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        elem = fromstring(body, 'ListBucketResult')
        self.assertEqual(elem.find('./IsTruncated').text, 'false')

        req = Request.blank('/%s?max-keys=4' % bucket_name,
                            environ={'REQUEST_METHOD': 'GET'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        elem = fromstring(body, 'ListBucketResult')
        self.assertEqual(elem.find('./IsTruncated').text, 'true')

        req = Request.blank('/subdirs?delimiter=/&max-keys=2',
                            environ={'REQUEST_METHOD': 'GET'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        elem = fromstring(body, 'ListBucketResult')
        self.assertEqual(elem.find('./IsTruncated').text, 'true')
        self.assertEqual(elem.find('./NextMarker').text, 'but/')
开发者ID:swiftstack,项目名称:swift3-stackforge,代码行数:27,代码来源:test_bucket.py


示例8: test_delete_multi_objects_with_quiet

    def test_delete_multi_objects_with_quiet(self):
        bucket = 'bucket'
        put_objects = ['obj']
        query = 'delete'

        # with Quiet true
        quiet = 'true'
        self._prepare_test_delete_multi_objects(bucket, put_objects)
        xml = self._gen_multi_delete_xml(put_objects, quiet)
        content_md5 = calculate_md5(xml)
        status, headers, body = \
            self.conn.make_request('POST', bucket, body=xml,
                                   headers={'Content-MD5': content_md5},
                                   query=query)
        self.assertEquals(status, 200)
        elem = fromstring(body, 'DeleteResult')
        resp_objects = elem.findall('Deleted')
        self.assertEquals(len(resp_objects), 0)

        # with Quiet false
        quiet = 'false'
        self._prepare_test_delete_multi_objects(bucket, put_objects)
        xml = self._gen_multi_delete_xml(put_objects, quiet)
        content_md5 = calculate_md5(xml)
        status, headers, body = \
            self.conn.make_request('POST', bucket, body=xml,
                                   headers={'Content-MD5': content_md5},
                                   query=query)
        self.assertEquals(status, 200)
        elem = fromstring(body, 'DeleteResult')
        resp_objects = elem.findall('Deleted')
        self.assertEquals(len(resp_objects), 1)
开发者ID:KoreaCloudObjectStorage,项目名称:swift3,代码行数:32,代码来源:test_multi_delete.py


示例9: test_bucket_multipart_uploads_GET_with_prefix

 def test_bucket_multipart_uploads_GET_with_prefix(self):
     req = Request.blank('/bucket/?uploads&prefix=X',
                         environ={'REQUEST_METHOD': 'GET'},
                         headers={'Authorization': 'AWS test:tester:hmac'})
     status, headers, body = self.call_swift3(req)
     fromstring(body, 'ListMultipartUploadsResult')
     self.assertEquals(status.split()[0], '200')
开发者ID:ichi-shin,项目名称:swift3,代码行数:7,代码来源:test_multi_upload.py


示例10: test_bucket_GET_v2_fetch_owner

    def test_bucket_GET_v2_fetch_owner(self):
        bucket_name = 'junk'
        req = Request.blank('/%s?list-type=2' % bucket_name,
                            environ={'REQUEST_METHOD': 'GET'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        self.assertEqual(status.split()[0], '200')

        elem = fromstring(body, 'ListBucketResult')
        name = elem.find('./Name').text
        self.assertEqual(name, bucket_name)

        objects = elem.iterchildren('Contents')
        for o in objects:
            self.assertIsNone(o.find('./Owner'))

        req = Request.blank('/%s?list-type=2&fetch-owner=true' % bucket_name,
                            environ={'REQUEST_METHOD': 'GET'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        self.assertEqual(status.split()[0], '200')

        elem = fromstring(body, 'ListBucketResult')
        name = elem.find('./Name').text
        self.assertEqual(name, bucket_name)

        objects = elem.iterchildren('Contents')
        for o in objects:
            self.assertIsNotNone(o.find('./Owner'))
开发者ID:swiftstack,项目名称:swift3-stackforge,代码行数:31,代码来源:test_bucket.py


示例11: test_bucket_GET_v2_with_delimiter_max_keys

    def test_bucket_GET_v2_with_delimiter_max_keys(self):
        bucket_name = 'junk'
        req = Request.blank(
            '/%s?list-type=2&delimiter=a&max-keys=2' % bucket_name,
            environ={'REQUEST_METHOD': 'GET'},
            headers={'Authorization': 'AWS test:tester:hmac',
                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        self.assertEqual(status.split()[0], '200')
        elem = fromstring(body, 'ListBucketResult')
        next_token = elem.find('./NextContinuationToken')
        self.assertIsNotNone(next_token)
        self.assertEqual(elem.find('./MaxKeys').text, '2')
        self.assertEqual(elem.find('./IsTruncated').text, 'true')

        req = Request.blank(
            '/%s?list-type=2&delimiter=a&max-keys=2&continuation-token=%s' %
            (bucket_name, next_token.text),
            environ={'REQUEST_METHOD': 'GET'},
            headers={'Authorization': 'AWS test:tester:hmac',
                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        self.assertEqual(status.split()[0], '200')
        elem = fromstring(body, 'ListBucketResult')
        names = [o.find('./Key').text for o in elem.iterchildren('Contents')]
        self.assertEqual(names[0], 'lily')
开发者ID:swiftstack,项目名称:swift3-stackforge,代码行数:26,代码来源:test_bucket.py


示例12: test_bucket_GET_v2_is_truncated

    def test_bucket_GET_v2_is_truncated(self):
        bucket_name = 'junk'

        req = Request.blank('/%s?list-type=2&max-keys=5' % bucket_name,
                            environ={'REQUEST_METHOD': 'GET'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        elem = fromstring(body, 'ListBucketResult')
        self.assertEqual(elem.find('./KeyCount').text, '5')
        self.assertEqual(elem.find('./IsTruncated').text, 'false')

        req = Request.blank('/%s?list-type=2&max-keys=4' % bucket_name,
                            environ={'REQUEST_METHOD': 'GET'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        elem = fromstring(body, 'ListBucketResult')
        self.assertIsNotNone(elem.find('./NextContinuationToken'))
        self.assertEqual(elem.find('./KeyCount').text, '4')
        self.assertEqual(elem.find('./IsTruncated').text, 'true')

        req = Request.blank('/subdirs?list-type=2&delimiter=/&max-keys=2',
                            environ={'REQUEST_METHOD': 'GET'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        elem = fromstring(body, 'ListBucketResult')
        self.assertIsNotNone(elem.find('./NextContinuationToken'))
        self.assertEqual(elem.find('./KeyCount').text, '2')
        self.assertEqual(elem.find('./IsTruncated').text, 'true')
开发者ID:swiftstack,项目名称:swift3-stackforge,代码行数:31,代码来源:test_bucket.py


示例13: test_bucket_object_versions_GET_version_id_marker

 def test_bucket_object_versions_GET_version_id_marker(self):
     req = Request.blank('/bucket?versions&version-id-marker=X',
                         environ={'REQUEST_METHOD': 'GET'},
                         headers={'Authorization': 'AWS test:tester:hmac'})
     status, headers, body = self.call_swift3(req)
     fromstring(body, 'ListVersionsResult')
     self.assertEquals(status.split()[0], '200')
开发者ID:ichi-shin,项目名称:swift3,代码行数:7,代码来源:test_versioning.py


示例14: test_bucket_GET_max_keys

    def test_bucket_GET_max_keys(self):
        bucket_name = 'junk'

        req = Request.blank('/%s?max-keys=5' % bucket_name,
                            environ={'REQUEST_METHOD': 'GET'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        elem = fromstring(body, 'ListBucketResult')
        self.assertEquals(elem.find('./MaxKeys').text, '5')
        _, path = self.swift.calls[-1]
        _, query_string = path.split('?')
        args = dict(cgi.parse_qsl(query_string))
        self.assert_(args['limit'] == '6')

        req = Request.blank('/%s?max-keys=5000' % bucket_name,
                            environ={'REQUEST_METHOD': 'GET'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()})
        status, headers, body = self.call_swift3(req)
        elem = fromstring(body, 'ListBucketResult')
        self.assertEquals(elem.find('./MaxKeys').text, '5000')
        _, path = self.swift.calls[-1]
        _, query_string = path.split('?')
        args = dict(cgi.parse_qsl(query_string))
        self.assertEquals(args['limit'], '1001')
开发者ID:tipabu,项目名称:swift3,代码行数:26,代码来源:test_bucket.py


示例15: test_object_multipart_upload_initiate

 def test_object_multipart_upload_initiate(self):
     req = Request.blank('/bucket/object?uploads',
                         environ={'REQUEST_METHOD': 'POST'},
                         headers={'Authorization':
                                  'AWS test:tester:hmac'})
     status, headers, body = self.call_swift3(req)
     fromstring(body, 'InitiateMultipartUploadResult')
     self.assertEquals(status.split()[0], '200')
开发者ID:yinyinbigdata,项目名称:swift3-stackforge,代码行数:8,代码来源:test_multi_upload.py


示例16: test_object_list_parts_invalid_part_number_marker

 def test_object_list_parts_invalid_part_number_marker(self):
     req = Request.blank('/bucket/object?uploadId=X&part-number-marker='
                         'invalid',
                         environ={'REQUEST_METHOD': 'GET'},
                         headers={'Authorization': 'AWS test:tester:hmac'})
     status, headers, body = self.call_swift3(req)
     fromstring(body, 'ListPartsResult')
     self.assertEquals(status.split()[0], '200')
开发者ID:ichi-shin,项目名称:swift3,代码行数:8,代码来源:test_multi_upload.py


示例17: test_get_bucket_v2_with_continuation_token

    def test_get_bucket_v2_with_continuation_token(self):
        bucket = 'bucket'
        put_objects = ('object', 'object2', 'subdir/object', 'subdir2/object',
                       'dir/subdir/object')
        self._prepare_test_get_bucket(bucket, put_objects)

        query = 'list-type=2&max-keys=3'
        expect_objects = ('dir/subdir/object', 'object', 'object2')
        status, headers, body = \
            self.conn.make_request('GET', bucket, query=query)
        self.assertEqual(status, 200)
        elem = fromstring(body, 'ListBucketResult')
        self.assertEqual(elem.find('MaxKeys').text, '3')
        self.assertEqual(elem.find('KeyCount').text, '3')
        self.assertEqual(elem.find('IsTruncated').text, 'true')
        next_cont_token_elem = elem.find('NextContinuationToken')
        self.assertIsNotNone(next_cont_token_elem)
        resp_objects = elem.findall('./Contents')
        self.assertEqual(len(list(resp_objects)), len(expect_objects))
        for i, o in enumerate(resp_objects):
            self.assertEqual(o.find('Key').text, expect_objects[i])
            self.assertTrue(o.find('LastModified').text is not None)
            self.assertRegexpMatches(
                o.find('LastModified').text,
                r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$')
            self.assertTrue(o.find('ETag').text is not None)
            self.assertTrue(o.find('Size').text is not None)
            self.assertEqual(o.find('StorageClass').text, 'STANDARD')
            self.assertIsNone(o.find('Owner/ID'))
            self.assertIsNone(o.find('Owner/DisplayName'))

        query = 'list-type=2&max-keys=3&continuation-token=%s' % \
            next_cont_token_elem.text
        expect_objects = ('subdir/object', 'subdir2/object')
        status, headers, body = \
            self.conn.make_request('GET', bucket, query=query)
        self.assertEqual(status, 200)
        elem = fromstring(body, 'ListBucketResult')
        self.assertEqual(elem.find('MaxKeys').text, '3')
        self.assertEqual(elem.find('KeyCount').text, '2')
        self.assertEqual(elem.find('IsTruncated').text, 'false')
        self.assertIsNone(elem.find('NextContinuationToken'))
        cont_token_elem = elem.find('ContinuationToken')
        self.assertEqual(cont_token_elem.text, next_cont_token_elem.text)
        resp_objects = elem.findall('./Contents')
        self.assertEqual(len(list(resp_objects)), len(expect_objects))
        for i, o in enumerate(resp_objects):
            self.assertEqual(o.find('Key').text, expect_objects[i])
            self.assertTrue(o.find('LastModified').text is not None)
            self.assertRegexpMatches(
                o.find('LastModified').text,
                r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$')
            self.assertTrue(o.find('ETag').text is not None)
            self.assertTrue(o.find('Size').text is not None)
            self.assertEqual(o.find('StorageClass').text, 'STANDARD')
            self.assertIsNone(o.find('Owner/ID'))
            self.assertIsNone(o.find('Owner/DisplayName'))
开发者ID:swiftstack,项目名称:swift3-stackforge,代码行数:57,代码来源:test_bucket.py


示例18: test_object_PUT_copy_to_itself

 def test_object_PUT_copy_to_itself(self):
     req = Request.blank(
         '/bucket/object',
         environ={'REQUEST_METHOD': 'PUT'},
         headers={'Authorization': 'AWS test:tester:hmac',
                  'X-Amz-Storage-Class': 'STANDARD',
                  'X-Amz-Copy-Source': '/bucket/object',
                  'x-amz-metadata-directive': 'REPLACE'})
     req.date = datetime.now()
     req.content_type = 'text/plain'
     status, headers, body = self.call_swift3(req)
     fromstring(body, 'CopyObjectResult')
     self.assertEquals(status.split()[0], '200')
开发者ID:ichi-shin,项目名称:swift3,代码行数:13,代码来源:test_obj.py


示例19: test_object_PUT_copy_without_slash_prefix

 def test_object_PUT_copy_without_slash_prefix(self):
     req = Request.blank(
         '/bucket/object',
         environ={'REQUEST_METHOD': 'PUT'},
         headers={'Authorization': 'AWS test:tester:hmac',
                  'X-Amz-Storage-Class': 'STANDARD',
                  'X-Amz-Copy-Source': 'some/source'})
     req.date = datetime.now()
     req.content_type = 'text/plain'
     status, headers, body = self.call_swift3(req)
     fromstring(body, 'CopyObjectResult')
     self.assertEquals(status.split()[0], '200')
     headers = [h for m, p, h in self.app.calls_with_headers
                if m == 'PUT' and p == '/v1/AUTH_test/bucket/object'][-1]
     self.assertEquals(int(headers['Content-Length']), len('copy source'))
开发者ID:ichi-shin,项目名称:swift3,代码行数:15,代码来源:test_obj.py


示例20: test_get_bucket_with_prefix

    def test_get_bucket_with_prefix(self):
        bucket = 'bucket'
        req_objects = ('object', 'object2', 'subdir/object', 'subdir2/object',
                       'dir/subdir/object')
        self._prepare_test_get_bucket(bucket, req_objects)

        prefix = 'object'
        query = 'prefix=%s' % prefix
        expect_objects = ('object', 'object2')
        status, headers, body = \
            self.conn.make_request('GET', bucket, query=query)
        self.assertEquals(status, 200)
        elem = fromstring(body, 'ListBucketResult')
        self.assertEquals(elem.find('Prefix').text, prefix)
        resp_objects = elem.findall('./Contents')
        self.assertEquals(len(list(resp_objects)), len(expect_objects))
        for i, o in enumerate(resp_objects):
            self.assertEquals(o.find('Key').text, expect_objects[i])
            self.assertTrue(o.find('LastModified').text is not None)
            self.assertRegexpMatches(
                o.find('LastModified').text,
                r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$')
            self.assertTrue(o.find('ETag').text is not None)
            self.assertTrue(o.find('Size').text is not None)
            self.assertEquals(o.find('StorageClass').text, 'STANDARD')
            self.assertTrue(o.find('Owner/ID').text, self.conn.user_id)
            self.assertTrue(o.find('Owner/DisplayName').text,
                            self.conn.user_id)
开发者ID:sivakrishnan47,项目名称:swift3,代码行数:28,代码来源:test_bucket.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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