Repository navigation
Expand file tree
/
Copy pathcopy_conditions.py
More file actions
91 lines (74 loc) · 2.61 KB
/
Copy pathcopy_conditions.py
File metadata and controls
91 lines (74 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# -*- coding: utf-8 -*-
# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2016 MinIO, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
minio.copy_conditions
~~~~~~~~~~~~~~~
This module contains :class:`CopyConditions <CopyConditions>` implementation.
:copyright: (c) 2016 by MinIO, Inc.
:license: Apache 2.0, see LICENSE for more details.
"""
import collections
from .helpers import is_non_empty_string
# CopyCondition explanation:
# http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html
#
# Example:
#
# copyCondition {
# key: "x-amz-copy-if-modified-since",
# value: "Tue, 15 Nov 1994 12:45:26 GMT",
#
class CopyConditions(collections.MutableMapping):
"""
A :class:`CopyConditions <CopyConditions>` collection of
supported CopyObject conditions.
- x-amz-copy-source-if-match
- x-amz-copy-source-if-none-match
- x-amz-copy-source-if-unmodified-since
- x-amz-copy-source-if-modified-since
"""
def __init__(self, *args, **kwargs):
self._store = dict()
self.update(dict(*args, **kwargs)) # use the free update to set keys
def __getitem__(self, key):
return self._store[key]
def __setitem__(self, key, value):
self._store[key] = value
def __delitem__(self, key):
del self._store[key]
def __iter__(self):
return iter(self._store)
def __len__(self):
return len(self._store)
def set_match_etag(self, etag):
"""
"""
is_non_empty_string(etag)
self._store['X-Amz-Copy-Source-If-Match'] = etag
def set_match_etag_except(self, etag):
"""
"""
is_non_empty_string(etag)
self._store['X-Amz-Copy-Source-If-None-Match'] = etag
def set_unmodified_since(self, mod_time):
"""
"""
time = mod_time.strftime('%a, %d %b %Y %H:%M:%S GMT')
self._store['X-Amz-Copy-Source-If-Unmodified-Since'] = time
def set_modified_since(self, mod_time):
"""
"""
time = mod_time.strftime('%a, %d %b %Y %H:%M:%S GMT')
self._store['X-Amz-Copy-Source-If-Modified-Since'] = time