|
29 | 29 | Owner, |
30 | 30 | AccessControlList, |
31 | 31 | AbortMultipartUpload, |
32 | | - StorageTransition) |
| 32 | + StorageTransition, |
| 33 | + ObjectTagging, |
| 34 | + ObjectTaggingRule) |
33 | 35 |
|
34 | 36 | from .compat import urlunquote, to_unicode, to_string |
35 | 37 | from .utils import iso8601_to_unixtime, date_to_iso8601, iso8601_to_date |
@@ -422,21 +424,36 @@ def parse_lifecycle_storage_transitions(storage_transition_nodes): |
422 | 424 |
|
423 | 425 | return storage_transitions |
424 | 426 |
|
| 427 | +def parse_lifecycle_object_taggings(lifecycle_tagging_nodes, url_encoded): |
| 428 | + |
| 429 | + if lifecycle_tagging_nodes is None: |
| 430 | + return ObjectTagging() |
| 431 | + |
| 432 | + tagging_rule = ObjectTaggingRule() |
| 433 | + for tag_node in lifecycle_tagging_nodes: |
| 434 | + key = _find_object(tag_node, 'Key', url_encoded) |
| 435 | + value = _find_object(tag_node, 'Value', url_encoded) |
| 436 | + tagging_rule.add(key, value) |
| 437 | + |
| 438 | + return ObjectTagging(tagging_rule) |
425 | 439 |
|
426 | 440 | def parse_get_bucket_lifecycle(result, body): |
427 | 441 | root = ElementTree.fromstring(body) |
| 442 | + url_encoded = _is_url_encoding(root) |
428 | 443 |
|
429 | 444 | for rule_node in root.findall('Rule'): |
430 | 445 | expiration = parse_lifecycle_expiration(rule_node.find('Expiration')) |
431 | 446 | abort_multipart_upload = parse_lifecycle_abort_multipart_upload(rule_node.find('AbortMultipartUpload')) |
432 | 447 | storage_transitions = parse_lifecycle_storage_transitions(rule_node.findall('Transition')) |
| 448 | + tagging = parse_lifecycle_object_taggings(rule_node.findall('Tag'), url_encoded) |
433 | 449 | rule = LifecycleRule( |
434 | 450 | _find_tag(rule_node, 'ID'), |
435 | 451 | _find_tag(rule_node, 'Prefix'), |
436 | 452 | status=_find_tag(rule_node, 'Status'), |
437 | 453 | expiration=expiration, |
438 | 454 | abort_multipart_upload=abort_multipart_upload, |
439 | | - storage_transitions=storage_transitions |
| 455 | + storage_transitions=storage_transitions, |
| 456 | + tagging=tagging |
440 | 457 | ) |
441 | 458 | result.rules.append(rule) |
442 | 459 |
|
@@ -567,6 +584,13 @@ def to_put_bucket_lifecycle(bucket_lifecycle): |
567 | 584 | _add_text_child(storage_transition_node, 'CreatedBeforeDate', |
568 | 585 | date_to_iso8601(storage_transition.created_before_date)) |
569 | 586 |
|
| 587 | + tagging = rule.tagging |
| 588 | + if tagging: |
| 589 | + tagging_rule = tagging.tag_set.tagging_rule |
| 590 | + for key in tagging.tag_set.tagging_rule: |
| 591 | + tag_node = ElementTree.SubElement(rule_node, 'Tag') |
| 592 | + _add_text_child(tag_node, 'Key', key) |
| 593 | + _add_text_child(tag_node, 'Value', tagging_rule[key]) |
570 | 594 | return _node_to_string(root) |
571 | 595 |
|
572 | 596 |
|
@@ -741,3 +765,32 @@ def to_get_select_json_object_meta(json_meta_param): |
741 | 765 | raise SelectOperationClientError("The json_meta_param contains unsupported key " + key, "") |
742 | 766 |
|
743 | 767 | return _node_to_string(root) |
| 768 | + |
| 769 | +def to_put_object_tagging(object_tagging): |
| 770 | + root = ElementTree.Element("Tagging") |
| 771 | + tag_set = ElementTree.SubElement(root, "TagSet") |
| 772 | + |
| 773 | + for item in object_tagging.tag_set.tagging_rule: |
| 774 | + tag_xml = ElementTree.SubElement(tag_set, "Tag") |
| 775 | + _add_text_child(tag_xml, 'Key', item) |
| 776 | + _add_text_child(tag_xml, 'Value', object_tagging.tag_set.tagging_rule[item]) |
| 777 | + |
| 778 | + return _node_to_string(root) |
| 779 | + |
| 780 | +def parse_get_object_tagging(result, body): |
| 781 | + root = ElementTree.fromstring(body) |
| 782 | + url_encoded = _is_url_encoding(root) |
| 783 | + tagset_node = root.find('TagSet') |
| 784 | + |
| 785 | + if tagset_node is None: |
| 786 | + return result |
| 787 | + |
| 788 | + tagging_rules = ObjectTaggingRule() |
| 789 | + for tag_node in tagset_node.findall('Tag'): |
| 790 | + key = _find_object(tag_node, 'Key', url_encoded) |
| 791 | + value = _find_object(tag_node, 'Value', url_encoded) |
| 792 | + tagging_rules.add(key, value) |
| 793 | + |
| 794 | + result.tag_set = tagging_rules |
| 795 | + return result |
| 796 | + |
0 commit comments