| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| """ |
| 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. |
| |
| """ |
|
|
| from collections.abc import MutableMapping |
|
|
| from .helpers import check_non_empty_string |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| class CopyConditions(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(*args, **kwargs) |
|
|
| 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): |
| """Set ETag match condition.""" |
| check_non_empty_string(etag) |
| self._store["X-Amz-Copy-Source-If-Match"] = etag |
|
|
| def set_match_etag_except(self, etag): |
| """Set ETag not match condition.""" |
| check_non_empty_string(etag) |
| self._store["X-Amz-Copy-Source-If-None-Match"] = etag |
|
|
| def set_unmodified_since(self, mod_time): |
| """Set unmodified since condition.""" |
| 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): |
| """Set modified since condition.""" |
| time = mod_time.strftime("%a, %d %b %Y %H:%M:%S GMT") |
| self._store["X-Amz-Copy-Source-If-Modified-Since"] = time |
|
|