|
1 | 1 | import datetime |
2 | 2 | from warnings import warn |
| 3 | +from six import raise_from |
3 | 4 |
|
4 | 5 | # In Python 2.7 collections.abc is a part of the collections module. |
5 | 6 | try: |
@@ -188,21 +189,29 @@ def access_expires(self): |
188 | 189 | delta = current_app.config['JWT_ACCESS_TOKEN_EXPIRES'] |
189 | 190 | if type(delta) is int: |
190 | 191 | delta = datetime.timedelta(seconds=delta) |
191 | | - if not isinstance(delta, datetime.timedelta) and delta is not False: |
192 | | - err = 'JWT_ACCESS_TOKEN_EXPIRES must be a ' \ |
193 | | - 'datetime.timedelta, int or False' |
194 | | - raise RuntimeError(err) |
| 192 | + if delta is not False: |
| 193 | + try: |
| 194 | + delta + datetime.datetime.now() |
| 195 | + except TypeError as e: |
| 196 | + err = ( |
| 197 | + "must be able to add JWT_ACCESS_TOKEN_EXPIRES to datetime.datetime" |
| 198 | + ) |
| 199 | + raise_from(RuntimeError(err), e) |
195 | 200 | return delta |
196 | 201 |
|
197 | 202 | @property |
198 | 203 | def refresh_expires(self): |
199 | 204 | delta = current_app.config['JWT_REFRESH_TOKEN_EXPIRES'] |
200 | 205 | if type(delta) is int: |
201 | 206 | delta = datetime.timedelta(seconds=delta) |
202 | | - if not isinstance(delta, datetime.timedelta) and delta is not False: |
203 | | - err = 'JWT_REFRESH_TOKEN_EXPIRES must be a ' \ |
204 | | - 'datetime.timedelta, int or False' |
205 | | - raise RuntimeError(err) |
| 207 | + if delta is not False: |
| 208 | + try: |
| 209 | + delta + datetime.datetime.now() |
| 210 | + except TypeError as e: |
| 211 | + err = ( |
| 212 | + "must be able to add JWT_REFRESH_TOKEN_EXPIRES to datetime.datetime" |
| 213 | + ) |
| 214 | + raise_from(RuntimeError(err), e) |
206 | 215 | return delta |
207 | 216 |
|
208 | 217 | @property |
|
0 commit comments