mypy: Address issues with openstack.object_store

Another small bug to be corrected here: SDKException does not have a
'response' attribute.

Change-Id: I084336ba41147f824b92dc07235e5f19b7ac4a9c
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2023-07-26 17:46:57 +01:00
parent 4f8d4102f5
commit 5d47d65d00
5 changed files with 36 additions and 31 deletions

View File

@ -66,7 +66,6 @@ repos:
| openstack/key_manager/.*
| openstack/load_balancer/.*
| openstack/message/.*
| openstack/object_store/.*
| openstack/orchestration/.*
| openstack/placement/.*
| openstack/shared_file_system/.*

View File

@ -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"""

View File

@ -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:

View File

@ -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")

View File

@ -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