Exemplo n.º 1
0
def parseGetBucketAcl(xml):
    root = ET.fromstring(xml)
    owner_id = root.find('.//ID')
    owner_id = owner_id.text if owner_id is not None else None
    owner_name = root.find('.//DisplayName')
    owner_name = owner_name.text if owner_name is not None else None
    owner = Owner(owner_id=owner_id, owner_name=owner_name)  # 创建Owner对象
    grants = root.findall('./AccessControlList/Grant')
    return ACL(owner=owner, grants=parseGrants(grants))  # 返回ACL的对象
Exemplo n.º 2
0
def parseListParts(xml):
    root = ET.fromstring(xml)

    bucketName = root.find('.//Bucket')
    bucketName = common_util.toString(bucketName.text) if bucketName is not None else None
    objectKey = root.find('.//Key')
    objectKey = common_util.toString(objectKey.text) if objectKey is not None else None
    uploadId = root.find('.//UploadId')
    uploadId = common_util.toString(uploadId.text) if uploadId is not None else None

    storageClass = root.find('.//StorageClass')
    storageClass = common_util.toString(storageClass.text) if storageClass is not None else None
    partNumbermarker = root.find('.//PartNumberMarker')
    partNumbermarker = common_util.toInt(partNumbermarker.text) if partNumbermarker is not None else None
    nextPartNumberMarker = root.find('.//NextPartNumberMarker')
    nextPartNumberMarker = common_util.toInt(nextPartNumberMarker.text) if nextPartNumberMarker is not None else None
    maxParts = root.find('.//MaxParts')
    maxParts = common_util.toInt(maxParts) if maxParts is not None else None
    isTruncated = root.find('.//IsTruncated')
    isTruncated = common_util.toBool(isTruncated.text) if isTruncated is not None else None

    initiatorid = root.find('.//Initiator/ID')
    initiatorid = common_util.toString(initiatorid.text) if initiatorid is not None else None
    displayname = root.find('.//Initiator/DisplayName')
    displayname = common_util.toString(displayname.text) if displayname is not None else None

    initiator = Initiator(id=initiatorid, name=displayname)

    ownerid = root.find('.//Owner/ID')
    ownerid = common_util.toString(ownerid.text) if ownerid is not None else None
    ownername = root.find('.//Owner/DisplayName')
    ownername = common_util.toString(ownername.text) if ownername is not None else None

    owner = Owner(owner_id=ownerid, owner_name=ownername)

    part_list = root.findall('./Part')
    parts = []
    if part_list:
        for part in part_list:
            partnumber = part.find('./PartNumber')
            partnumber = common_util.toInt(partnumber.text) if partnumber is not None else None
            modifieddate = part.find('./LastModified')
            modifieddate = UTCToLocal(modifieddate.text) if modifieddate is not None else None
            etag = part.find('./ETag')
            etag = common_util.toString(etag.text) if etag is not None else None
            size = part.find('./Size')
            size = common_util.toLong(size.text) if size is not None else None
            __part = Part(partNumber=partnumber, lastModified=modifieddate, etag=etag, size=size)
            parts.append(__part)

    return ListPartsResponse(bucketName=bucketName, objectKey=objectKey, uploadId=uploadId, initiator=initiator, owner=owner, storageClass=storageClass,
                             partNumberMarker=partNumbermarker, nextPartNumberMarker=nextPartNumberMarker, maxParts=maxParts, isTruncated=isTruncated, parts=parts)  # 返回ListPartsResponse的对象
Exemplo n.º 3
0
def SetObjectAcl():
    Lowner = Owner(owner_id='B67ExxxxDE62C', owner_name='usr')

    Lgrantee = Grantee(grantee_id='729AxxxxFBBDF', grantee_name='usr', group=None)

    Lgrant = Grant(grantee=Lgrantee, permission=Permission.READ)

    Lgrants = [Lgrant]

    Lacl = ACL(owner=Lowner, grants=Lgrants)

    resp = TestObs.setObjectAcl(bucketName='bucket001', objectKey='test.txt', acl=None, versionId=None,
                                aclControl=HeadPermission.PUBLIC_READ_WRITE)
    print('common msg:status:', resp.status, ',errorCode:', resp.errorCode, ',errorMessage:', resp.errorMessage)
Exemplo n.º 4
0
def SetBucketAcl():
    Lowner = Owner(owner_id='806BxxxxADB', owner_name='user')

    Lgrantee1 = Grantee(grantee_id='806BxxxxAADB', grantee_name='user', group=None)
    Lgrantee2 = Grantee(group=Group.LOG_DELIVERY)

    Lgrant1 = Grant(grantee=Lgrantee1, permission=Permission.READ)
    Lgrant2 = Grant(grantee=Lgrantee2, permission=Permission.READ_ACP)
    Lgrant3 = Grant(grantee=Lgrantee2, permission=Permission.WRITE)
    Lgrants = [Lgrant1, Lgrant2, Lgrant3]

    Lacl = ACL(owner=Lowner, grants=Lgrants)

    resp = TestObs.setBucketAcl(bucketName='bucket001', acl=Lacl, aclControl=None)
    # resp = TestObs.setBucketAcl(bucketName='bucket001', acl=None, aclControl=HeadPermission.PUBLIC_READ_WRITE)
    print('common msg:status:', resp.status, ',errorCode:', resp.errorCode, ',errorMessage:', resp.errorMessage)
Exemplo n.º 5
0
def parseListObjects(xml):
    root = ET.fromstring(xml)  # 获取xml文件的根节点root

    key_entries = []
    commonprefix_entries = []

    name = root.find('Name')
    name = name.text if name is not None else None
    prefix = find_item(root, 'Prefix')
    marker = find_item(root, 'Marker')
    delimiter = find_item(root, 'Delimiter')
    max_keys = find_item(root, 'MaxKeys')
    is_truncated = find_item(root, 'IsTruncated')
    next_marker = find_item(root, 'NextMarker')

    # 获取对象key的相关信息,在Contents节点中
    contents = root.findall('Contents')
    if contents is not None:
        for node in contents:
            key = find_item(node, 'Key')
            lastmodified = find_item(node, 'LastModified')
            etag = find_item(node, 'ETag')
            size = find_item(node, 'Size')
            storage = find_item(node, 'StorageClass')

            # 获取Owner相关信息
            owner_id = find_item(node, './/ID')
            owner_name = find_item(node, './/DisplayName')
            owner = Owner(owner_id=owner_id, owner_name=owner_name)  # 创建Owner对象
            key_entry = Content(key=key, lastmodified=UTCToLocal(lastmodified), etag=etag, size=common_util.toLong(size), owner=owner, storageClass=storage)
            key_entries.append(key_entry)  # 将对象添加到对象列表中

    # 获取CommonPrefixes的相关信息
    prefixes = root.findall('CommonPrefixes')
    if prefixes is not None:
        for p in prefixes:
            pre = find_item(p, 'Prefix')
            commonprefix = CommonPrefix(prefix=pre)
            commonprefix_entries.append(commonprefix)
    # 返回ListObjectsResponse的对象
    return ListObjectsResponse(name=name, prefix=prefix, marker=marker, delimiter=delimiter, max_keys=common_util.toInt(max_keys),
                               is_truncated=common_util.toBool(is_truncated), next_marker=next_marker, contents=key_entries, commonprefixs=commonprefix_entries)
Exemplo n.º 6
0
def parseListBuckets(xml):
    root = ET.fromstring(xml)  # 获取xml文件的根节点root
    owner_id = root.find('.//ID')
    owner_id = owner_id.text if owner_id is not None else None
    owner_name = root.find('.//DisplayName')
    owner_name = owner_name.text if owner_name is not None else None
    owner = Owner(owner_id=owner_id, owner_name=owner_name)  # 创建Owner对象

    buckets = root.find('Buckets').findall('Bucket')
    entries = []

    for bucket in buckets:
        name = bucket.find('Name')  # 获取bucket的名称
        name = name.text if name is not None else None
        d = bucket.find('CreationDate') # 获取bucket的创建日期
        d = d.text if d is not None else None
        create_date = UTCToLocal(d)  # 将创建日期转换为当地时间
        curr_bucket = Bucket(name=name, create_date=create_date)  # 创建bucket对象
        entries.append(curr_bucket)  # 向entries列表中添加bucket对象
    return ListBucketsResponse(buckets=entries, owner=owner)  # 返回ListBucketsResponse的对象
Exemplo n.º 7
0
def parseListMultipartUploads(xml):
    root = ET.fromstring(xml)

    Bucket = root.find('./Bucket')
    Bucket = common_util.toString(Bucket.text) if Bucket is not None else None
    KeyMarker = root.find('./KeyMarker')
    KeyMarker = common_util.toString(KeyMarker.text) if KeyMarker is not None else None

    UploadIdMarker = root.find('./UploadIdMarker')
    UploadIdMarker = common_util.toString(UploadIdMarker.text) if UploadIdMarker is not None else None
    NextKeyMarker = root.find('./NextKeyMarker')
    NextKeyMarker = common_util.toString(NextKeyMarker.text) if NextKeyMarker is not None else None
    NextUploadIdMarker = root.find('./NextUploadIdMarker')
    NextUploadIdMarker = common_util.toString(NextUploadIdMarker.text) if NextUploadIdMarker is not None else None

    MaxUploads = root.find('./MaxUploads')
    MaxUploads = common_util.toInt(MaxUploads.text) if MaxUploads is not None else None

    IsTruncated = root.find('./IsTruncated')
    IsTruncated = common_util.toBool(IsTruncated.text) if IsTruncated is not None else None

    Prefix = root.find('./Prefix')
    prefix = common_util.toString(Prefix.text) if Prefix is not None else None
    delimiter = root.find('./Delimiter')
    delimiter = common_util.toString(delimiter.text) if delimiter is not None else None

    rules = root.findall('./Upload')
    uploadlist = []
    if rules:
        for rule in rules:
            Key = rule.find('./Key')
            Key = common_util.toString(Key.text) if Key is not None else None
            UploadId = rule.find('./UploadId')
            UploadId = common_util.toString(UploadId.text) if UploadId is not None else None

            ID = rule.find('./Initiator/ID')
            ID = common_util.toString(ID.text) if ID is not None else None

            DisplayName = rule.find('./Initiator/DisplayName')
            DisplayName = common_util.toString(DisplayName.text) if DisplayName is not None else None
            initiator = Initiator(id=ID, name=DisplayName)

            owner_id = rule.find('./Owner/ID')
            owner_id = common_util.toString(owner_id.text) if owner_id is not None else None
            owner_name = rule.find('./Owner/DisplayName')
            owner_name = common_util.toString(owner_name.text) if owner_name is not None else None
            ower = Owner(owner_id=owner_id, owner_name=owner_name)

            StorageClass = rule.find('./StorageClass')
            StorageClass = common_util.toString(StorageClass.text) if StorageClass is not None else None

            Initiated = rule.find('./Initiated')
            Initiated = UTCToLocal(Initiated.text) if Initiated is not None else None
            upload = Upload(key=Key, uploadID=UploadId, initiator=initiator, owner=ower, storageClass=StorageClass, initiated=Initiated)
            uploadlist.append(upload)
    common = root.findall('./CommonPrefixes')
    commonlist = []
    if common:
        for comm in common:
            comm_prefix = comm.find('./Prefix')
            comm_prefix = common_util.toString(comm_prefix.text) if comm_prefix is not None else None
            Comm_Prefix = CommonPrefix(prefix=comm_prefix)
            commonlist.append(Comm_Prefix)
    return ListMultipartUploadsResponse(bucket=Bucket, keyMarker=KeyMarker, uploadIdMarker=UploadIdMarker,
                                        nextKeyMarker=NextKeyMarker, nextUploadIdMarker=NextUploadIdMarker, maxUploads=MaxUploads,
                                        isTruncated=IsTruncated, prefix=prefix, delimiter=delimiter, upload=uploadlist, commonPrefixs=commonlist)
Exemplo n.º 8
0
def parseListVersions(xml):

    root = ET.fromstring(xml)
    Name = root.find('./Name')
    Name =  Name.text if Name is not None else None
    Prefix = root.find('./Prefix')
    Prefix = Prefix.text if Prefix is not None else None
    KeyMarker = root.find('./KeyMarker')
    KeyMarker = KeyMarker.text if KeyMarker is not None else None
    VersionIdMarker = root.find('./VersionIdMarker')
    VersionIdMarker = VersionIdMarker.text if VersionIdMarker is not None else None
    NextKeyMarker = root.find('./NextKeyMarker')
    NextKeyMarker = NextKeyMarker.text if NextKeyMarker is not None else None
    NextVersionIdMarker = root.find('./NextVersionIdMarker')
    NextVersionIdMarker = NextVersionIdMarker.text if NextVersionIdMarker is not None else None
    MaxKeys = root.find('./MaxKeys')
    MaxKeys = MaxKeys.text if MaxKeys is not None else None
    IsTruncated = root.find('./IsTruncated')
    IsTruncated = IsTruncated.text if IsTruncated is not None else None

    head = ObjectVersionHead(name=Name, prefix=Prefix, keyMarker=KeyMarker, versionIdMarker=VersionIdMarker,
                             nextKeyMarker=NextKeyMarker, nextVersionIdMarker=NextVersionIdMarker, maxKeys=common_util.toInt(MaxKeys),
                             isTruncated=common_util.toBool(IsTruncated))

    versions = root.findall('./Version')
    version_list = []
    for version in versions:
        Key = version.find('./Key')
        Key = Key.text if Key is not None else None
        VersionId = version.find('./VersionId')
        VersionId = VersionId.text if VersionId is not None else None
        IsLatest = version.find('./IsLatest')
        IsLatest = IsLatest.text if IsLatest is not None else None
        LastModified = version.find('./LastModified')
        LastModified = LastModified.text if LastModified is not None else None
        ETag = version.find('./ETag')
        ETag = ETag.text if ETag is not None else None
        Size = version.find('./Size')
        Size = Size.text if Size is not None else None
        owner = version.find('./Owner')
        Owners = None
        if owner is not None:
            ID = version.find('.//ID')
            ID = ID.text if ID is not None else None
            DisplayName = version.find('.//DisplayName')
            DisplayName = DisplayName.text if DisplayName is not None else None
            Owners = Owner(owner_id=ID, owner_name=DisplayName)

        StorageClass = version.find('./StorageClass')
        StorageClass = StorageClass.text if StorageClass is not None else None

        Version = ObjectVersion(key=Key, versionId=VersionId, isLatest=common_util.toBool(IsLatest), lastModified=UTCToLocal(LastModified), eTag=ETag, size=common_util.toLong(Size), owner=Owners,
                                storageClass=StorageClass)
        version_list.append(Version)

    markers = root.findall('./DeleteMarker')
    marker_list = []
    for marker in markers:
        Key = marker.find('./Key')
        Key = Key.text if Key is not None else None
        VersionId = marker.find('./VersionId')
        VersionId = VersionId.text if VersionId is not None else None
        IsLatest = marker.find('./IsLatest')
        IsLatest = IsLatest.text if IsLatest is not None else None
        LastModified = marker.find('./LastModified')
        LastModified = LastModified.text if LastModified is not None else None
        owner = marker.find('./Owner')
        Owners = None
        if owner is not None:
            ID = marker.find('.//ID')
            ID = ID.text if ID is not None else None
            DisplayName = marker.find('.//DisplayName')
            DisplayName = DisplayName.text if DisplayName is not None else None
            Owners = Owner(owner_id=ID, owner_name=DisplayName)

        Marker = ObjectDeleteMarker(key=Key, versionId=VersionId, isLatest=common_util.toBool(IsLatest), lastModified=UTCToLocal(LastModified), owner=Owners)
        marker_list.append(Marker)

    prefixs = root.findall('./CommonPrefixes')
    prefix_list = []
    for prefix in prefixs:
        Prefix = prefix.find('./Prefix')
        Prefix = Prefix.text if Prefix is not None else None
        Pre = CommonPrefix(prefix=Prefix)
        prefix_list.append(Pre)
    ret = ObjectVersions(head=head, markers=marker_list, commonPrefixs=prefix_list)
    ret.versions=version_list
    return ret