1717from six .moves .urllib .parse import quote , unquote , urlencode
1818from six import text_type , binary_type
1919from hashlib import md5
20- from dicttoxml import dicttoxml
2120from .streambody import StreamBody
2221from .xml2dict import Xml2Dict
2322from .cos_auth import CosS3Auth
@@ -747,8 +746,7 @@ def delete_objects(self, Bucket, Delete={}, **kwargs):
747746 Delete=objects
748747 )
749748 """
750- lst = ['<Object>' , '</Object>' ] # 类型为list的标签
751- xml_config = format_xml (data = Delete , root = 'Delete' , lst = lst )
749+ xml_config = format_xml (data = Delete , root = 'Delete' )
752750 headers = mapped (kwargs )
753751 headers ['Content-MD5' ] = get_md5 (xml_config )
754752 headers ['Content-Type' ] = 'application/xml'
@@ -1141,12 +1139,9 @@ def put_object_acl(self, Bucket, Key, AccessControlPolicy={}, **kwargs):
11411139 GrantRead='id="qcs::cam::uin/123:uin/456",id="qcs::cam::uin/123:uin/123"'
11421140 )
11431141 """
1144- lst = [ # 类型为list的标签
1145- '<Grant>' ,
1146- '</Grant>' ]
11471142 xml_config = ""
11481143 if AccessControlPolicy :
1149- xml_config = format_xml (data = AccessControlPolicy , root = 'AccessControlPolicy' , lst = lst )
1144+ xml_config = format_xml (data = AccessControlPolicy , root = 'AccessControlPolicy' )
11501145 headers = mapped (kwargs )
11511146 params = {'acl' : '' }
11521147 url = self ._conf .uri (bucket = Bucket , path = Key )
@@ -1610,12 +1605,9 @@ def put_bucket_acl(self, Bucket, AccessControlPolicy={}, **kwargs):
16101605 GrantRead='id="qcs::cam::uin/123:uin/456",id="qcs::cam::uin/123:uin/123"'
16111606 )
16121607 """
1613- lst = [ # 类型为list的标签
1614- '<Grant>' ,
1615- '</Grant>' ]
16161608 xml_config = ""
16171609 if AccessControlPolicy :
1618- xml_config = format_xml (data = AccessControlPolicy , root = 'AccessControlPolicy' , lst = lst )
1610+ xml_config = format_xml (data = AccessControlPolicy , root = 'AccessControlPolicy' )
16191611 headers = mapped (kwargs )
16201612 params = {'acl' : '' }
16211613 url = self ._conf .uri (bucket = Bucket )
@@ -1699,18 +1691,7 @@ def put_bucket_cors(self, Bucket, CORSConfiguration={}, **kwargs):
16991691 CORSConfiguration=cors_config
17001692 )
17011693 """
1702- lst = [ # 类型为list的标签
1703- '<CORSRule>' ,
1704- '<AllowedOrigin>' ,
1705- '<AllowedMethod>' ,
1706- '<AllowedHeader>' ,
1707- '<ExposeHeader>' ,
1708- '</CORSRule>' ,
1709- '</AllowedOrigin>' ,
1710- '</AllowedMethod>' ,
1711- '</AllowedHeader>' ,
1712- '</ExposeHeader>' ]
1713- xml_config = format_xml (data = CORSConfiguration , root = 'CORSConfiguration' , lst = lst )
1694+ xml_config = format_xml (data = CORSConfiguration , root = 'CORSConfiguration' )
17141695 headers = mapped (kwargs )
17151696 headers ['Content-MD5' ] = get_md5 (xml_config )
17161697 headers ['Content-Type' ] = 'application/xml'
@@ -1833,17 +1814,7 @@ def put_bucket_lifecycle(self, Bucket, LifecycleConfiguration={}, **kwargs):
18331814 )
18341815 """
18351816 # 类型为list的标签
1836- lst = [
1837- '<Rule>' ,
1838- '<Tag>' ,
1839- '<Transition>' ,
1840- '<NoncurrentVersionTransition>' ,
1841- '</NoncurrentVersionTransition>' ,
1842- '</Transition>' ,
1843- '</Tag>' ,
1844- '</Rule>'
1845- ]
1846- xml_config = format_xml (data = LifecycleConfiguration , root = 'LifecycleConfiguration' , lst = lst )
1817+ xml_config = format_xml (data = LifecycleConfiguration , root = 'LifecycleConfiguration' )
18471818 headers = mapped (kwargs )
18481819 headers ['Content-MD5' ] = get_md5 (xml_config )
18491820 headers ['Content-Type' ] = 'application/xml'
@@ -2068,8 +2039,7 @@ def put_bucket_replication(self, Bucket, ReplicationConfiguration={}, **kwargs):
20682039 ReplicationConfiguration=replication_config
20692040 )
20702041 """
2071- lst = ['<Rule>' , '</Rule>' ] # 类型为list的标签
2072- xml_config = format_xml (data = ReplicationConfiguration , root = 'ReplicationConfiguration' , lst = lst )
2042+ xml_config = format_xml (data = ReplicationConfiguration , root = 'ReplicationConfiguration' )
20732043 headers = mapped (kwargs )
20742044 headers ['Content-MD5' ] = get_md5 (xml_config )
20752045 headers ['Content-Type' ] = 'application/xml'
@@ -2197,7 +2167,12 @@ def put_bucket_website(self, Bucket, WebsiteConfiguration={}, **kwargs):
21972167 WebsiteConfiguration=website_config
21982168 )
21992169 """
2200- xml_config = format_xml (data = WebsiteConfiguration , root = 'WebsiteConfiguration' , parent_child = True )
2170+ # 重构 WebsiteConfiguration['RoutingRules']
2171+ WebsiteConfigurationCpy = copy .deepcopy (WebsiteConfiguration )
2172+ if 'RoutingRules' in WebsiteConfigurationCpy .keys ():
2173+ WebsiteConfigurationCpy ['RoutingRules' ] = {'RoutingRule' : WebsiteConfigurationCpy ['RoutingRules' ]}
2174+
2175+ xml_config = format_xml (data = WebsiteConfigurationCpy , root = 'WebsiteConfiguration' )
22012176 headers = mapped (kwargs )
22022177 headers ['Content-MD5' ] = get_md5 (xml_config )
22032178 headers ['Content-Type' ] = 'application/xml'
@@ -2496,8 +2471,7 @@ def put_bucket_domain(self, Bucket, DomainConfiguration={}, **kwargs):
24962471 DomainConfiguration=domain_config
24972472 )
24982473 """
2499- lst = ['<DomainRule>' , '</DomainRule>' ] # 类型为list的标签
2500- xml_config = format_xml (data = DomainConfiguration , root = 'DomainConfiguration' , lst = lst )
2474+ xml_config = format_xml (data = DomainConfiguration , root = 'DomainConfiguration' )
25012475 headers = mapped (kwargs )
25022476 headers ['Content-MD5' ] = get_md5 (xml_config )
25032477 headers ['Content-Type' ] = 'application/xml'
@@ -2600,8 +2574,7 @@ def put_bucket_domain_certificate(self, Bucket, DomainCertificateConfiguration,
26002574 DomainCertificateConfiguration=domain_cert_config
26012575 )
26022576 """
2603- lst = ['<DomainList>' , '</DomainList>' ] # 类型为list的标签
2604- xml_config = format_xml (data = DomainCertificateConfiguration , root = 'DomainCertificate' , lst = lst )
2577+ xml_config = format_xml (data = DomainCertificateConfiguration , root = 'DomainCertificate' )
26052578 headers = mapped (kwargs )
26062579 headers ['Content-MD5' ] = get_md5 (xml_config )
26072580 headers ['Content-Type' ] = 'application/xml'
@@ -2714,8 +2687,7 @@ def put_bucket_origin(self, Bucket, OriginConfiguration={}, **kwargs):
27142687 OriginConfiguration=origin_config
27152688 )
27162689 """
2717- lst = ['<OriginRule>' , '</OriginRule>' ] # 类型为list的标签
2718- xml_config = format_xml (data = OriginConfiguration , root = 'OriginConfiguration' , lst = lst )
2690+ xml_config = format_xml (data = OriginConfiguration , root = 'OriginConfiguration' )
27192691 headers = mapped (kwargs )
27202692 headers ['Content-MD5' ] = get_md5 (xml_config )
27212693 headers ['Content-Type' ] = 'application/xml'
@@ -2848,9 +2820,8 @@ def put_bucket_inventory(self, Bucket, Id, InventoryConfiguration={}, **kwargs):
28482820 InventoryConfiguration=inventory_config
28492821 )
28502822 """
2851- lst = ['<Field>' , '</Field>' ] # 类型为list的标签
28522823 InventoryConfiguration ['Id' ] = Id
2853- xml_config = format_xml (data = InventoryConfiguration , root = 'InventoryConfiguration' , lst = lst )
2824+ xml_config = format_xml (data = InventoryConfiguration , root = 'InventoryConfiguration' )
28542825 headers = mapped (kwargs )
28552826 headers ['Content-MD5' ] = get_md5 (xml_config )
28562827 headers ['Content-Type' ] = 'application/xml'
@@ -2965,8 +2936,7 @@ def put_object_tagging(self, Bucket, Key, Tagging={}, **kwargs):
29652936 Tagging=tagging_set
29662937 )
29672938 """
2968- lst = ['<Tag>' , '</Tag>' ] # 类型为list的标签
2969- xml_config = format_xml (data = Tagging , root = 'Tagging' , lst = lst )
2939+ xml_config = format_xml (data = Tagging , root = 'Tagging' )
29702940 headers = mapped (kwargs )
29712941 params = {'tagging' : '' }
29722942 if 'versionId' in headers :
@@ -3089,8 +3059,7 @@ def put_bucket_tagging(self, Bucket, Tagging={}, **kwargs):
30893059 Tagging=tagging_set
30903060 )
30913061 """
3092- lst = ['<Tag>' , '</Tag>' ] # 类型为list的标签
3093- xml_config = format_xml (data = Tagging , root = 'Tagging' , lst = lst )
3062+ xml_config = format_xml (data = Tagging , root = 'Tagging' )
30943063 headers = mapped (kwargs )
30953064 headers ['Content-MD5' ] = get_md5 (xml_config )
30963065 headers ['Content-Type' ] = 'application/xml'
@@ -3203,8 +3172,7 @@ def put_bucket_referer(self, Bucket, RefererConfiguration={}, **kwargs):
32033172 RefererConfiguration=referer_config
32043173 )
32053174 """
3206- lst = ['<Domain>' , '</Domain>' ] # 类型为list的标签
3207- xml_config = format_xml (data = RefererConfiguration , root = 'RefererConfiguration' , lst = lst )
3175+ xml_config = format_xml (data = RefererConfiguration , root = 'RefererConfiguration' )
32083176 headers = mapped (kwargs )
32093177 headers ['Content-MD5' ] = get_md5 (xml_config )
32103178 headers ['Content-Type' ] = 'application/xml'
@@ -4059,13 +4027,7 @@ def put_bucket_encryption(self, Bucket, ServerSideEncryptionConfiguration={}, **
40594027 :param kwargs(dict): 设置请求的headers.
40604028 :return: None.
40614029 """
4062- # 类型为list的标签
4063- lst = [
4064- '<Rule>' ,
4065- '</Rule>'
4066- ]
4067- xml_config = format_xml (data = ServerSideEncryptionConfiguration , root = 'ServerSideEncryptionConfiguration' ,
4068- lst = lst )
4030+ xml_config = format_xml (data = ServerSideEncryptionConfiguration , root = 'ServerSideEncryptionConfiguration' )
40694031 headers = mapped (kwargs )
40704032 params = {'encryption' : '' }
40714033 url = self ._conf .uri (bucket = Bucket )
@@ -6012,21 +5974,7 @@ def ci_auditing_image_batch(self, Bucket, Input, DetectType=None, BizType=None,
60125974 'Conf' : conf
60135975 }
60145976
6015- lst = [ # 类型为list的标签
6016- '<Input>' ,
6017- '<Object>' ,
6018- '<Url>' ,
6019- '<Interval>' ,
6020- '<MaxFrames>' ,
6021- '<DataId>' ,
6022- '</Input>' ,
6023- '</Object>' ,
6024- '</Url>' ,
6025- '</Interval>' ,
6026- '</MaxFrames>' ,
6027- '</DataId>' ]
6028-
6029- xml_request = format_xml (data = request , root = 'Request' , lst = lst )
5977+ xml_request = format_xml (data = request , root = 'Request' )
60305978 headers ['Content-Type' ] = 'application/xml'
60315979
60325980 path = 'image/auditing'
@@ -6586,7 +6534,7 @@ def ci_create_media_jobs(self, Bucket, Jobs={}, Lst={}, **kwargs):
65866534
65876535 :param Bucket(string): 存储桶名称.
65886536 :param Jobs(dict): 创建任务的配置.
6589- :param Lst(dict): 创建任务dict转xml时去除Key数组.
6537+ :param Lst(dict): 创建任务dict转xml时去除Key数组. TODO 替换成 xmltodict 库后可以将 Lst 参数去掉
65906538 :param kwargs(dict): 设置请求的headers.
65916539 :return(dict): 查询成功返回的结果,dict类型.
65926540
@@ -6613,7 +6561,7 @@ def ci_create_media_jobs(self, Bucket, Jobs={}, Lst={}, **kwargs):
66136561 headers = final_headers
66146562
66156563 params = format_values (params )
6616- xml_config = format_xml (data = Jobs , root = 'Request' , lst = Lst )
6564+ xml_config = format_xml (data = Jobs , root = 'Request' )
66176565 path = "/jobs"
66186566 url = self ._conf .uri (bucket = Bucket , path = path , endpoint = self ._conf ._endpoint_ci )
66196567 logger .info ("create_media_jobs result, url=:{url} ,headers=:{headers}, params=:{params}, xml_config=:{xml_config}" .format (
@@ -6640,7 +6588,7 @@ def ci_create_media_pic_jobs(self, Bucket, Jobs={}, Lst={}, **kwargs):
66406588
66416589 :param Bucket(string): 存储桶名称.
66426590 :param Jobs(dict): 创建任务的配置.
6643- :param Lst(dict): 创建任务dict转xml时去除Key数组.
6591+ :param Lst(dict): 创建任务dict转xml时去除Key数组. TODO 替换为 xmltodict 库后可以将 Lst 参数去掉
66446592 :param kwargs(dict): 设置请求的headers.
66456593 :return(dict): 查询成功返回的结果,dict类型.
66466594
@@ -6667,7 +6615,7 @@ def ci_create_media_pic_jobs(self, Bucket, Jobs={}, Lst={}, **kwargs):
66676615 headers = final_headers
66686616
66696617 params = format_values (params )
6670- xml_config = format_xml (data = Jobs , root = 'Request' , lst = Lst )
6618+ xml_config = format_xml (data = Jobs , root = 'Request' )
66716619 path = "/pic_jobs"
66726620 url = self ._conf .uri (bucket = Bucket , path = path , endpoint = self ._conf ._endpoint_ci )
66736621 logger .info ("create_media_pic_jobs result, url=:{url} ,headers=:{headers}, params=:{params}, xml_config=:{xml_config}" .format (
0 commit comments