diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d6864407..094368644 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -66,7 +66,6 @@ repos: | openstack/key_manager/.* | openstack/load_balancer/.* | openstack/message/.* - | openstack/object_store/.* | openstack/orchestration/.* | openstack/placement/.* | openstack/shared_file_system/.* diff --git a/openstack/object_store/v1/_base.py b/openstack/object_store/v1/_base.py index a39286f5e..0b1c4dfed 100644 --- a/openstack/object_store/v1/_base.py +++ b/openstack/object_store/v1/_base.py @@ -11,6 +11,8 @@ # License for the specific language governing permissions and limitations # under the License. +import typing as ty + from openstack import exceptions from openstack import resource @@ -20,11 +22,11 @@ class BaseResource(resource.Resource): create_method = 'PUT' #: Metadata stored for this resource. *Type: dict* - metadata = dict() + metadata: ty.Dict[str, ty.Any] = {} - _custom_metadata_prefix = None - _system_metadata = dict() - _last_headers = dict() + _custom_metadata_prefix: str + _system_metadata: ty.Dict[str, ty.Any] = {} + _last_headers: ty.Dict[str, ty.Any] = {} def __init__(self, metadata=None, **attrs): """Process and save metadata known at creation stage""" diff --git a/openstack/object_store/v1/_proxy.py b/openstack/object_store/v1/_proxy.py index f66032f99..a63d9dc2c 100644 --- a/openstack/object_store/v1/_proxy.py +++ b/openstack/object_store/v1/_proxy.py @@ -769,15 +769,17 @@ class Proxy(proxy.Proxy): try: # caps = self.get_object_capabilities() caps = self.get_info() - except exceptions.SDKException as e: - if e.response.status_code in (404, 412): - server_max_file_size = DEFAULT_MAX_FILE_SIZE - self._connection.log.info( - "Swift capabilities not supported. " - "Using default max file size." - ) - else: - raise + except ( + exceptions.NotFoundException, + exceptions.PreconditionFailedException, + ): + server_max_file_size = DEFAULT_MAX_FILE_SIZE + self._connection.log.info( + "Swift capabilities not supported. " + "Using default max file size." + ) + except exceptions.SDKException: + raise else: server_max_file_size = caps.swift.get('max_file_size', 0) min_segment_size = caps.slo.get('min_segment_size', 0) @@ -935,8 +937,7 @@ class Proxy(proxy.Proxy): max_upload_count, expires, ) - data = data.encode('utf8') - sig = hmac.new(temp_url_key, data, sha1).hexdigest() + sig = hmac.new(temp_url_key, data.encode(), sha1).hexdigest() return (expires, sig) @@ -992,18 +993,17 @@ class Proxy(proxy.Proxy): try: t = time.strptime(seconds, f) except ValueError: - t = None + continue + + if f == EXPIRES_ISO8601_FORMAT: + timestamp = timegm(t) else: - if f == EXPIRES_ISO8601_FORMAT: - timestamp = timegm(t) - else: - # Use local time if UTC designator is missing. - timestamp = int(time.mktime(t)) + # Use local time if UTC designator is missing. + timestamp = int(time.mktime(t)) - absolute = True - break - - if t is None: + absolute = True + break + else: raise ValueError() else: if not timestamp.is_integer(): @@ -1046,6 +1046,7 @@ class Proxy(proxy.Proxy): method.upper(), ) + expiration: float | int if not absolute: expiration = _get_expiration(timestamp) else: @@ -1074,12 +1075,16 @@ class Proxy(proxy.Proxy): ).hexdigest() if iso8601: - expiration = time.strftime( + exp = time.strftime( EXPIRES_ISO8601_FORMAT, time.gmtime(expiration) ) + else: + exp = str(expiration) temp_url = u'{path}?temp_url_sig={sig}&temp_url_expires={exp}'.format( - path=path_for_body, sig=sig, exp=expiration + path=path_for_body, + sig=sig, + exp=exp, ) if ip_range: @@ -1143,7 +1148,7 @@ class Proxy(proxy.Proxy): return is_bulk_delete_supported = False - bulk_delete_max_per_request = None + bulk_delete_max_per_request = 1 try: caps = self.get_info() except exceptions.SDKException: diff --git a/openstack/resource.py b/openstack/resource.py index 4841036ee..9cc47c8b3 100644 --- a/openstack/resource.py +++ b/openstack/resource.py @@ -460,7 +460,7 @@ class Resource(dict): #: Plural form of key for resource. resources_key: ty.Optional[str] = None #: Key used for pagination links - pagination_key = None + pagination_key: ty.Optional[str] = None #: The ID of this resource. id = Body("id") diff --git a/setup.cfg b/setup.cfg index a9a8f5777..2b002bfda 100644 --- a/setup.cfg +++ b/setup.cfg @@ -60,7 +60,6 @@ exclude = (?x)( | openstack/key_manager | openstack/load_balancer | openstack/message - | openstack/object_store | openstack/orchestration | openstack/placement | openstack/shared_file_system