Fix a couple of inconsistencies in the public interface (#1102)

* Create `_NOT_A_REQUEST` when needed. Currently, modifications    
  in the raised exception would be "global".    
* `retries` parameters were actually attempts. This has been fixed    
  to actually be the amount of retries, so 0 now means don't retry.    
* Helper function to deal with retries instead of using a range with    
  different styles every time.
This commit is contained in:
Dmitry D. Chernov
2019-02-07 04:41:45 +10:00
committed by Lonami
parent c9e9b82eac
commit c8f16a4e89
5 changed files with 50 additions and 30 deletions

View File

@@ -72,6 +72,21 @@ def strip_text(text, entities):
return text
def retry_range(retries):
"""
Generates an integer sequence starting from 1. If `retries` is
negative or ``None`` then sequence is infinite, otherwise it will
end at `retries + 1`.
"""
yield 1
if retries is None:
retries = -1
attempt = 0
while attempt != retries:
attempt += 1
yield 1 + attempt
# endregion
# region Cryptographic related utils