From f62927c1dfee4af4a502e3f43c7610a74e324cba Mon Sep 17 00:00:00 2001 From: Pravin Kamble Date: Mon, 21 Aug 2023 21:41:01 +0530 Subject: [PATCH] update the throtting_duration_parser.py returning tuple instead of dict --- rest_framework/throttling.py | 2 +- rest_framework/utils/throttling_duration_parser.py | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/rest_framework/throttling.py b/rest_framework/throttling.py index a438bedd4..9acc2371d 100644 --- a/rest_framework/throttling.py +++ b/rest_framework/throttling.py @@ -103,7 +103,7 @@ class SimpleRateThrottle(BaseThrottle): if rate is None: return (None, None) num, period = rate.split('/') - quantity, unit = parse_quantity_and_unit(period).values() + quantity, unit = parse_quantity_and_unit(period) num_requests = int(num) duration = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}[unit[0]] total_duration = duration * int(quantity) diff --git a/rest_framework/utils/throttling_duration_parser.py b/rest_framework/utils/throttling_duration_parser.py index 923c4dc61..b8d2b30be 100644 --- a/rest_framework/utils/throttling_duration_parser.py +++ b/rest_framework/utils/throttling_duration_parser.py @@ -7,16 +7,15 @@ def parse_quantity_and_unit(quantity_unit_string): Returns: dict: A dictionary containing the parsed quantity and unit, with keys 'quantity' and 'unit'. - If the input string contains only a unit (e.g., "ms"), quantity will be set to 1. + If the input string contains only a unit (e.g., "m"), quantity will be set to 1. """ i = 0 - quantity_unit_dict = {} while i < len(quantity_unit_string) and quantity_unit_string[i].isnumeric(): i += 1 + if i == 0: - quantity_unit_dict['quantity'] = 1 - quantity_unit_dict['unit'] = quantity_unit_string + return (1, quantity_unit_string) else: - quantity_unit_dict['quantity'] = int(quantity_unit_string[:i]) - quantity_unit_dict['unit'] = quantity_unit_string[i:] - return quantity_unit_dict + quantity = int(quantity_unit_string[:i]) + unit = quantity_unit_string[i:] + return (quantity, unit)