From e41158d79e4bcb280ec94365226f9423f72d7b66 Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Fri, 9 Sep 2016 11:06:06 +0100 Subject: Make tempurl subcommand insist on whole number seconds Previously the tempurl subcommand would dump a traceback due to a TypeError if the seconds option was not an int value. With this patch it will now return the same error message as if the seconds option were negative or not a number. Also changes the error message to state that the seconds option should be a "whole number" rather than a "positive integer", since 0 is a valid value. Change-Id: Ie940d470f2be8006aa8eb7fe242f092457aeae21 Closes-Bug: #1621817 --- swiftclient/utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'swiftclient/utils.py') diff --git a/swiftclient/utils.py b/swiftclient/utils.py index 2e727ad..0d1104e 100644 --- a/swiftclient/utils.py +++ b/swiftclient/utils.py @@ -80,17 +80,19 @@ def generate_temp_url(path, seconds, key, method, absolute=False): :param absolute: if True then the seconds parameter is interpreted as an absolute Unix time, otherwise seconds is interpreted as a relative time offset from current time. - :raises: ValueError if seconds is not a positive integer or path is not to + :raises: ValueError if seconds is not a whole number or path is not to an object. - :raises: TypeError if seconds is not an integer :return: the path portion of a temporary URL """ try: + seconds = float(seconds) + if not seconds.is_integer(): + raise ValueError() seconds = int(seconds) + if seconds < 0: + raise ValueError() except ValueError: - raise TypeError('seconds must be an integer') - if seconds < 0: - raise ValueError('seconds must be a positive integer') + raise ValueError('seconds must be a whole number') if isinstance(path, six.binary_type): try: -- cgit v1.2.1