From 4148095610bdf67f741a078c3c005d05a0fc2439 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Thu, 13 Jun 2019 10:11:24 +0500 Subject: [PATCH] Use a custom wrapper around time() --- project_amber/handlers/session.py | 2 +- project_amber/helpers/__init__.py | 8 ++++++++ project_amber/helpers/auth.py | 2 +- project_amber/helpers/task.py | 3 +-- 4 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 project_amber/helpers/__init__.py diff --git a/project_amber/handlers/session.py b/project_amber/handlers/session.py index e87001a..f5c9b59 100644 --- a/project_amber/handlers/session.py +++ b/project_amber/handlers/session.py @@ -1,10 +1,10 @@ from json import dumps -from time import time from flask import request from project_amber.const import MATURE_SESSION, MSG_IMMATURE_SESSION, EMPTY_RESP from project_amber.errors import Forbidden +from project_amber.helpers import time from project_amber.helpers.auth import handleChecks, getSessions, getSession,\ removeSessionById from project_amber.logging import log diff --git a/project_amber/helpers/__init__.py b/project_amber/helpers/__init__.py new file mode 100644 index 0000000..39b965a --- /dev/null +++ b/project_amber/helpers/__init__.py @@ -0,0 +1,8 @@ +from time import time as time_lib + +def time() -> int: + """ + Wrapper around `time.time()`. Converts the result to `int` to prevent + getting fractions of seconds on some platforms. + """ + return int(time_lib()) diff --git a/project_amber/helpers/auth.py b/project_amber/helpers/auth.py index 5ae12b4..e0bdcd7 100644 --- a/project_amber/helpers/auth.py +++ b/project_amber/helpers/auth.py @@ -1,6 +1,5 @@ from hashlib import sha256 from base64 import b64encode -from time import time from bcrypt import hashpw, gensalt, checkpw from flask import request @@ -8,6 +7,7 @@ from project_amber.const import MSG_NO_TOKEN, MSG_INVALID_TOKEN, \ MSG_USER_NOT_FOUND, MSG_USER_EXISTS from project_amber.db import db +from project_amber.helpers import time from project_amber.errors import Unauthorized, BadRequest, NotFound, \ InternalServerError, Conflict from project_amber.logging import log diff --git a/project_amber/helpers/task.py b/project_amber/helpers/task.py index a40bc7d..4868452 100644 --- a/project_amber/helpers/task.py +++ b/project_amber/helpers/task.py @@ -1,8 +1,7 @@ -from time import time - from project_amber.const import MSG_TASK_NOT_FOUND, MSG_TASK_DANGEROUS from project_amber.db import db from project_amber.errors import NotFound, BadRequest +from project_amber.helpers import time from project_amber.models.task import Task def addTask(text: str, status: int, uid: int) -> int: