abstract-security 0.78__tar.gz → 0.80__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {abstract_security-0.78 → abstract_security-0.80}/PKG-INFO +1 -1
- {abstract_security-0.78 → abstract_security-0.80}/setup.py +1 -1
- abstract_security-0.80/src/abstract_security/__init__.py +2 -0
- abstract_security-0.80/src/abstract_security/envs/imports.py +1 -0
- abstract_security-0.80/src/abstract_security/imports/imports.py +4 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/time_utils/imports/imports.py +1 -1
- abstract_security-0.80/src/abstract_security/imports/time_utils/time_utils.py +62 -0
- abstract_security-0.80/src/abstract_security/logins/__init__.py +2 -0
- abstract_security-0.80/src/abstract_security/logins/imports/__init__.py +3 -0
- abstract_security-0.80/src/abstract_security/logins/imports/constants.py +2 -0
- abstract_security-0.80/src/abstract_security/logins/imports/init_imports.py +2 -0
- abstract_security-0.80/src/abstract_security/logins/imports/module_imports.py +1 -0
- abstract_security-0.80/src/abstract_security/logins/pass_utils.py +46 -0
- abstract_security-0.80/src/abstract_security/logins/token_utils.py +41 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security.egg-info/PKG-INFO +1 -1
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security.egg-info/SOURCES.txt +12 -3
- abstract_security-0.80/tests/test.py +3 -0
- abstract_security-0.78/src/abstract_security/imports/imports.py +0 -10
- abstract_security-0.78/src/abstract_security/imports/time_utils/time_utils.py +0 -392
- abstract_security-0.78/tests/test.py +0 -8
- {abstract_security-0.78 → abstract_security-0.80}/README.md +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/pyproject.toml +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/setup.cfg +0 -0
- {abstract_security-0.78/src/abstract_security → abstract_security-0.80/src/abstract_security/envs}/__init__.py +0 -0
- {abstract_security-0.78/src/abstract_security → abstract_security-0.80/src/abstract_security/envs}/abstractEnv.py +0 -0
- {abstract_security-0.78/src/abstract_security → abstract_security-0.80/src/abstract_security/envs}/envy_it.py +0 -0
- {abstract_security-0.78/src/abstract_security → abstract_security-0.80/src/abstract_security/envs}/utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/class_utils/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/class_utils/abstract_classes.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/class_utils/caller_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/class_utils/class_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/class_utils/function_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/class_utils/global_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/class_utils/imports/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/class_utils/imports/imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/class_utils/imports/utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/class_utils/module_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/compare_utils/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/compare_utils/best_match.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/compare_utils/compare_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/compare_utils/find_value.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/compare_utils/imports/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/compare_utils/imports/constants.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/compare_utils/imports/imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/compare_utils/imports/module_imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/directory_utils/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/directory_utils/directory_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/directory_utils/imports/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/directory_utils/imports/imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/directory_utils/imports/module_imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/directory_utils/name_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/directory_utils/size_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/directory_utils/utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/imports/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/imports/imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/imports/utils/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/imports/utils/utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/list_utils/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/list_utils/list_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/path_utils/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/path_utils/gvfs_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/path_utils/imports/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/path_utils/imports/imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/path_utils/imports/module_imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/path_utils/path_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/safe_utils/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/safe_utils/imports/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/safe_utils/imports/imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/safe_utils/imports/module_imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/safe_utils/safe_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/ssh_utils/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/ssh_utils/classes.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/ssh_utils/cmd_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/ssh_utils/imports/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/ssh_utils/imports/imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/ssh_utils/imports/module_imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/ssh_utils/imports/utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/ssh_utils/pexpect_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/ssh_utils/type_checks.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/string_utils/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/string_utils/clean_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/string_utils/eat_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/string_utils/imports/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/string_utils/imports/imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/string_utils/imports/module_imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/string_utils/imports/utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/string_utils/replace_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/time_utils/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/time_utils/imports/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/time_utils/imports/module_imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/alpha_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/get_type.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/imports/__init__.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/imports/constants.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/imports/imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/imports/module_imports.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/imports/utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/is_type.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/make_type.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/mime_types.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/type_utils/num_utils.py +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security.egg-info/dependency_links.txt +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security.egg-info/requires.txt +0 -0
- {abstract_security-0.78 → abstract_security-0.80}/src/abstract_security.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: abstract_security
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.80
|
|
4
4
|
Summary: The `abstract_security` module is a Python utility that provides functionality for managing environment variables and securely loading sensitive information from `.env` files. It is designed to simplify the process of accessing and managing environment variables within your Python applications.
|
|
5
5
|
Home-page: https://github.com/AbstractEndeavors/abstract_security
|
|
6
6
|
Author: putkoff
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name='abstract_security',
|
|
8
|
-
version='0.
|
|
8
|
+
version='0.80',
|
|
9
9
|
author='putkoff',
|
|
10
10
|
author_email="partners@abstractendeavors.com",
|
|
11
11
|
description='The `abstract_security` module is a Python utility that provides functionality for managing environment variables and securely loading sensitive information from `.env` files. It is designed to simplify the process of accessing and managing environment variables within your Python applications.',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from ..imports import *
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from .imports import *
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# -------------------------
|
|
5
|
+
# CORE (single source of truth)
|
|
6
|
+
# -------------------------
|
|
7
|
+
def now() -> datetime:
|
|
8
|
+
return datetime.now(timezone.utc)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def add_delta(
|
|
12
|
+
dt: datetime = None,
|
|
13
|
+
*,
|
|
14
|
+
days=0,
|
|
15
|
+
hours=0,
|
|
16
|
+
minutes=0,
|
|
17
|
+
seconds=0,
|
|
18
|
+
milliseconds=0
|
|
19
|
+
) -> datetime:
|
|
20
|
+
dt = dt or now()
|
|
21
|
+
|
|
22
|
+
return dt + timedelta(
|
|
23
|
+
days=days,
|
|
24
|
+
hours=hours,
|
|
25
|
+
minutes=minutes,
|
|
26
|
+
seconds=seconds,
|
|
27
|
+
milliseconds=milliseconds
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# -------------------------
|
|
32
|
+
# TIMESTAMP ADAPTERS
|
|
33
|
+
# -------------------------
|
|
34
|
+
def to_timestamp(dt: datetime = None) -> float:
|
|
35
|
+
dt = dt or now()
|
|
36
|
+
return dt.timestamp()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def from_timestamp(ts: float) -> datetime:
|
|
40
|
+
return datetime.fromtimestamp(ts, tz=timezone.utc)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# -------------------------
|
|
44
|
+
# STRING ADAPTERS
|
|
45
|
+
# -------------------------
|
|
46
|
+
def to_iso(dt: datetime = None) -> str:
|
|
47
|
+
return (dt or now()).isoformat()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def from_string(date_str: str, fmt: str) -> datetime:
|
|
51
|
+
return datetime.strptime(date_str, fmt).replace(tzinfo=timezone.utc)
|
|
52
|
+
|
|
53
|
+
def get_sleep(seconds: float = 0.0):
|
|
54
|
+
try:
|
|
55
|
+
seconds = float(seconds)
|
|
56
|
+
except (TypeError, ValueError):
|
|
57
|
+
raise ValueError(f"Invalid sleep value: {seconds}")
|
|
58
|
+
|
|
59
|
+
if seconds <= 0:
|
|
60
|
+
return
|
|
61
|
+
|
|
62
|
+
time.sleep(seconds)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from ...envs import get_env_value
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from .imports import getpass,bcrypt,secrets,string as _string
|
|
2
|
+
|
|
3
|
+
def generate_salt(rounds=None):
|
|
4
|
+
rounds = rounds or 10
|
|
5
|
+
salt = bcrypt.gensalt(rounds=rounds)
|
|
6
|
+
return salt
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def verify_password(password: str, hashed: str) -> bool:
|
|
10
|
+
"""
|
|
11
|
+
Verify a plaintext password against a bcrypt hash.
|
|
12
|
+
"""
|
|
13
|
+
if not password or not hashed:
|
|
14
|
+
return False
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
return bcrypt.checkpw(
|
|
18
|
+
password.encode("utf-8"),
|
|
19
|
+
hashed.encode("utf-8")
|
|
20
|
+
)
|
|
21
|
+
except ValueError:
|
|
22
|
+
# invalid hash format
|
|
23
|
+
return False
|
|
24
|
+
|
|
25
|
+
def bcrypt_plain_text(plaintext_pwd,rounds=None):
|
|
26
|
+
salt = generate_salt(rounds=rounds)
|
|
27
|
+
plaintext_pwd = plaintext_pwd.encode("utf-8")
|
|
28
|
+
encrypted_bcrypt_hash = bcrypt.hashpw(plaintext_pwd,salt)
|
|
29
|
+
bcrypt_hash = encrypted_bcrypt_hash.decode("utf-8")
|
|
30
|
+
return bcrypt_hash
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def hash_password(password: str, rounds: int = 12) -> str:
|
|
34
|
+
"""
|
|
35
|
+
Hash a plaintext password using bcrypt.
|
|
36
|
+
"""
|
|
37
|
+
if not password:
|
|
38
|
+
raise ValueError("Password cannot be empty")
|
|
39
|
+
|
|
40
|
+
salt = bcrypt.gensalt(rounds=rounds)
|
|
41
|
+
return bcrypt.hashpw(password.encode("utf-8"), salt).decode("utf-8")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def generate_password(length=16) -> str:
|
|
45
|
+
alphabet = _string.ascii_letters + _string.digits
|
|
46
|
+
return ''.join(secrets.choice(alphabet) for _ in range(length))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from .imports import (
|
|
2
|
+
add_delta,
|
|
3
|
+
get_env_value,
|
|
4
|
+
JWT_ALGORITHM,
|
|
5
|
+
JWT_EXP_DELTA_SECONDS
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
def get_token_exp(seconds=None):
|
|
9
|
+
return add_delta(seconds=seconds or JWT_EXP_DELTA_SECONDS)
|
|
10
|
+
|
|
11
|
+
def get_app_secret():
|
|
12
|
+
APP_SECRET = get_env_value("JWT_SECRET")
|
|
13
|
+
if not APP_SECRET:
|
|
14
|
+
raise RuntimeError("JWT_SECRET environment variable is required")
|
|
15
|
+
return APP_SECRET
|
|
16
|
+
|
|
17
|
+
def generate_token(**payload) -> str:
|
|
18
|
+
payload["exp"]= payload.get("exp",get_token_exp())
|
|
19
|
+
return jwt.encode(payload, get_app_secret(), algorithm=JWT_ALGORITHM)
|
|
20
|
+
|
|
21
|
+
def decode_token(token: str) -> dict:
|
|
22
|
+
app_secret = get_app_secret()
|
|
23
|
+
return jwt.decode(token, app_secret, algorithms=[JWT_ALGORITHM])
|
|
24
|
+
|
|
25
|
+
def generate_user_token(username: str=None,
|
|
26
|
+
is_admin: bool=None,
|
|
27
|
+
exp:int=None) -> str:
|
|
28
|
+
token_js = {"username": username or 'guest',
|
|
29
|
+
"is_admin": is_admin or False,
|
|
30
|
+
"exp":exp or get_token_exp()}
|
|
31
|
+
return generate_token(**token_js)
|
|
32
|
+
|
|
33
|
+
def generate_download_token(username: str =None,
|
|
34
|
+
rel_path: str =None,
|
|
35
|
+
exp:int=None) -> str:
|
|
36
|
+
token_js = {"sub": username,
|
|
37
|
+
"path": rel_path,
|
|
38
|
+
"exp":exp or get_token_exp()}
|
|
39
|
+
|
|
40
|
+
return generate_token(**token_js)
|
|
41
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: abstract_security
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.80
|
|
4
4
|
Summary: The `abstract_security` module is a Python utility that provides functionality for managing environment variables and securely loading sensitive information from `.env` files. It is designed to simplify the process of accessing and managing environment variables within your Python applications.
|
|
5
5
|
Home-page: https://github.com/AbstractEndeavors/abstract_security
|
|
6
6
|
Author: putkoff
|
{abstract_security-0.78 → abstract_security-0.80}/src/abstract_security.egg-info/SOURCES.txt
RENAMED
|
@@ -3,14 +3,16 @@ pyproject.toml
|
|
|
3
3
|
setup.cfg
|
|
4
4
|
setup.py
|
|
5
5
|
src/abstract_security/__init__.py
|
|
6
|
-
src/abstract_security/abstractEnv.py
|
|
7
|
-
src/abstract_security/envy_it.py
|
|
8
|
-
src/abstract_security/utils.py
|
|
9
6
|
src/abstract_security.egg-info/PKG-INFO
|
|
10
7
|
src/abstract_security.egg-info/SOURCES.txt
|
|
11
8
|
src/abstract_security.egg-info/dependency_links.txt
|
|
12
9
|
src/abstract_security.egg-info/requires.txt
|
|
13
10
|
src/abstract_security.egg-info/top_level.txt
|
|
11
|
+
src/abstract_security/envs/__init__.py
|
|
12
|
+
src/abstract_security/envs/abstractEnv.py
|
|
13
|
+
src/abstract_security/envs/envy_it.py
|
|
14
|
+
src/abstract_security/envs/imports.py
|
|
15
|
+
src/abstract_security/envs/utils.py
|
|
14
16
|
src/abstract_security/imports/__init__.py
|
|
15
17
|
src/abstract_security/imports/imports.py
|
|
16
18
|
src/abstract_security/imports/class_utils/__init__.py
|
|
@@ -90,4 +92,11 @@ src/abstract_security/imports/type_utils/imports/constants.py
|
|
|
90
92
|
src/abstract_security/imports/type_utils/imports/imports.py
|
|
91
93
|
src/abstract_security/imports/type_utils/imports/module_imports.py
|
|
92
94
|
src/abstract_security/imports/type_utils/imports/utils.py
|
|
95
|
+
src/abstract_security/logins/__init__.py
|
|
96
|
+
src/abstract_security/logins/pass_utils.py
|
|
97
|
+
src/abstract_security/logins/token_utils.py
|
|
98
|
+
src/abstract_security/logins/imports/__init__.py
|
|
99
|
+
src/abstract_security/logins/imports/constants.py
|
|
100
|
+
src/abstract_security/logins/imports/init_imports.py
|
|
101
|
+
src/abstract_security/logins/imports/module_imports.py
|
|
93
102
|
tests/test.py
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
from ...imports import os
|
|
2
|
-
from dotenv import load_dotenv
|
|
3
|
-
from ...ssh_utils import is_file
|
|
4
|
-
from ...string_utils import eatAll,eatInner,eatOuter
|
|
5
|
-
from ...safe_utils import safe_split
|
|
6
|
-
from ...compare_utils import line_contains
|
|
7
|
-
from ...type_utils import is_list,is_bool
|
|
8
|
-
from ...directory_utils import get_slash,path_join,if_not_last_child_join,get_home_folder,simple_path_join
|
|
9
|
-
DEFAULT_FILE_NAME = '.env'
|
|
10
|
-
DEFAULT_KEY = 'MY_PASSWORD'
|
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
time_utils.py
|
|
3
|
-
|
|
4
|
-
This module provides utility functions for working with timestamps and time-related operations.
|
|
5
|
-
|
|
6
|
-
Usage:
|
|
7
|
-
import abstract_utilities.time_utils as time_utils
|
|
8
|
-
|
|
9
|
-
Functions:
|
|
10
|
-
- get_sleep(sleep_timer): Pause the execution of the program for a specified duration.
|
|
11
|
-
- get_time_stamp() -> float: Returns the current timestamp in seconds.
|
|
12
|
-
- get_milisecond_time_stamp() -> float: Returns the current timestamp in milliseconds.
|
|
13
|
-
- get_day(now=get_time_stamp()) -> str: Returns the current day of the week.
|
|
14
|
-
- get_time(now=get_time_stamp()) -> str: Returns the current time.
|
|
15
|
-
- get_date(now=get_time_stamp()) -> str: Returns the current date.
|
|
16
|
-
- save_last_time(now=get_time_stamp()) -> str: Saves the last timestamp to a file.
|
|
17
|
-
- get_day_seconds() -> float: Returns the number of seconds in a day.
|
|
18
|
-
- get_week_seconds() -> float: Returns the number of seconds in a week.
|
|
19
|
-
- get_hour_seconds() -> float: Returns the number of seconds in an hour.
|
|
20
|
-
- get_minute_seconds() -> float: Returns the number of seconds in a minute.
|
|
21
|
-
- get_second() -> float: Returns the value of one second.
|
|
22
|
-
- get_24_hr_start(now=get_time_stamp()) -> int: Returns the timestamp for the start of the current day.
|
|
23
|
-
|
|
24
|
-
This module is part of the `abstract_utilities` package.
|
|
25
|
-
|
|
26
|
-
Author: putkoff
|
|
27
|
-
Date: 05/31/2023
|
|
28
|
-
Version: 0.1.2
|
|
29
|
-
"""
|
|
30
|
-
|
|
31
|
-
from .imports import *
|
|
32
|
-
def sleep_count_down(sleep_time):
|
|
33
|
-
while sleep_time>float(0):
|
|
34
|
-
sleep_time -= float(1)
|
|
35
|
-
print(f"{max(sleep_time,0)} seconds till start")
|
|
36
|
-
get_sleep(1)
|
|
37
|
-
def sleep_timer(last_time: Union[str, float], wait_limit: Union[float, int] = 0) -> None:
|
|
38
|
-
"""
|
|
39
|
-
Pause execution for a specified amount of time, calculated based on time differences.
|
|
40
|
-
|
|
41
|
-
Parameters:
|
|
42
|
-
last_time (str or float): The reference time or timestamp.
|
|
43
|
-
wait_limit (float or int, optional): The maximum wait time in seconds. Defaults to 0.
|
|
44
|
-
|
|
45
|
-
Returns:
|
|
46
|
-
None
|
|
47
|
-
"""
|
|
48
|
-
curr_time = get_time_stamp()
|
|
49
|
-
time_difference = curr_time - float(last_time)
|
|
50
|
-
if time_difference < wait_limit:
|
|
51
|
-
sleep_length = float(wait_limit - time_difference)
|
|
52
|
-
get_sleep(sleep_timer=sleep_length)
|
|
53
|
-
def get_sleep(sleep_timer: Union[int, float] = 0):
|
|
54
|
-
"""
|
|
55
|
-
Pause the execution of the program for a specified duration.
|
|
56
|
-
|
|
57
|
-
This function pauses the program's execution for the given amount of time
|
|
58
|
-
before continuing. The sleep duration can be specified in seconds as an integer
|
|
59
|
-
or a floating-point number.
|
|
60
|
-
|
|
61
|
-
Args:
|
|
62
|
-
sleep_timer (int or float, optional): The duration in seconds to pause the execution.
|
|
63
|
-
If not provided or set to 0, the function does nothing.
|
|
64
|
-
|
|
65
|
-
Example:
|
|
66
|
-
get_sleep(2) # Pause the program for 2 seconds.
|
|
67
|
-
"""
|
|
68
|
-
if isinstance(sleep_timer,int):
|
|
69
|
-
sleep_timer=float(sleep_timer)
|
|
70
|
-
if isinstance(sleep_timer,float):
|
|
71
|
-
time.sleep(sleep_timer)
|
|
72
|
-
def get_time_stamp() -> float:
|
|
73
|
-
"""
|
|
74
|
-
Returns the current timestamp in seconds.
|
|
75
|
-
|
|
76
|
-
Returns:
|
|
77
|
-
float: The current timestamp.
|
|
78
|
-
"""
|
|
79
|
-
return datetime.now().timestamp()
|
|
80
|
-
def get_date_time_str(date_str,military_time_str):
|
|
81
|
-
return f"{date_str} {military_time_str}"
|
|
82
|
-
def get_time_obj(date_time_str):
|
|
83
|
-
return datetime.strptime(date_time_str, '%Y-%m-%d %H:%M')
|
|
84
|
-
def get_current_year() -> int:
|
|
85
|
-
"""
|
|
86
|
-
Get the current year.
|
|
87
|
-
|
|
88
|
-
Returns:
|
|
89
|
-
int: The current year as an integer.
|
|
90
|
-
"""
|
|
91
|
-
now = datetime.now()
|
|
92
|
-
current_year = now.year
|
|
93
|
-
return current_year
|
|
94
|
-
|
|
95
|
-
def get_24_hr_start(now=get_time_stamp()) -> int:
|
|
96
|
-
"""
|
|
97
|
-
Returns the timestamp for the start of the current day.
|
|
98
|
-
|
|
99
|
-
Args:
|
|
100
|
-
now (float): The timestamp. Defaults to the current timestamp.
|
|
101
|
-
|
|
102
|
-
Returns:
|
|
103
|
-
int: The timestamp for the start of the current day.
|
|
104
|
-
"""
|
|
105
|
-
return int(now) - int(get_day_seconds())
|
|
106
|
-
|
|
107
|
-
def create_timestamp(date_str, military_time_str):
|
|
108
|
-
"""
|
|
109
|
-
Converts a date string and military time string to a timestamp.
|
|
110
|
-
|
|
111
|
-
Args:
|
|
112
|
-
date_str (str): The date string in the format 'YYYY-MM-DD'.
|
|
113
|
-
military_time_str (str): The military time string in the format 'HH:MM'.
|
|
114
|
-
|
|
115
|
-
Returns:
|
|
116
|
-
int: The timestamp corresponding to the date and time.
|
|
117
|
-
"""
|
|
118
|
-
date_time_str = get_date_time_str(date_str,military_time_str)
|
|
119
|
-
return int(get_time_obj(date_time_str).timestamp())
|
|
120
|
-
|
|
121
|
-
def get_milisecond_time_stamp():
|
|
122
|
-
"""
|
|
123
|
-
Returns the current timestamp in milliseconds.
|
|
124
|
-
|
|
125
|
-
Returns:
|
|
126
|
-
float: The current timestamp in milliseconds.
|
|
127
|
-
"""
|
|
128
|
-
return datetime.now().timestamp() * 1000
|
|
129
|
-
|
|
130
|
-
def get_day(now=get_time_stamp()):
|
|
131
|
-
"""
|
|
132
|
-
Returns the current day of the week.
|
|
133
|
-
|
|
134
|
-
Args:
|
|
135
|
-
now (float): The timestamp. Defaults to the current timestamp.
|
|
136
|
-
|
|
137
|
-
Returns:
|
|
138
|
-
str: The current day of the week.
|
|
139
|
-
"""
|
|
140
|
-
return datetime.fromtimestamp(now).strftime("%A")
|
|
141
|
-
|
|
142
|
-
def get_time(now=get_time_stamp()):
|
|
143
|
-
"""
|
|
144
|
-
Returns the current time.
|
|
145
|
-
|
|
146
|
-
Args:
|
|
147
|
-
now (float): The timestamp. Defaults to the current timestamp.
|
|
148
|
-
|
|
149
|
-
Returns:
|
|
150
|
-
str: The current time.
|
|
151
|
-
"""
|
|
152
|
-
return str(datetime.fromtimestamp(now))[10:]
|
|
153
|
-
|
|
154
|
-
def get_date(now=get_time_stamp()):
|
|
155
|
-
"""
|
|
156
|
-
Returns the current date.
|
|
157
|
-
|
|
158
|
-
Args:
|
|
159
|
-
now (float): The timestamp. Defaults to the current timestamp.
|
|
160
|
-
|
|
161
|
-
Returns:
|
|
162
|
-
str: The current date.
|
|
163
|
-
"""
|
|
164
|
-
return str(datetime.fromtimestamp(now))[:10]
|
|
165
|
-
|
|
166
|
-
def save_last_time(now=get_time_stamp()):
|
|
167
|
-
"""
|
|
168
|
-
Saves the last timestamp to a file.
|
|
169
|
-
|
|
170
|
-
Args:
|
|
171
|
-
now (float): The timestamp. Defaults to the current timestamp.
|
|
172
|
-
|
|
173
|
-
Returns:
|
|
174
|
-
str: The filename where the timestamp is saved.
|
|
175
|
-
"""
|
|
176
|
-
return pen(str(now), 'last.txt')
|
|
177
|
-
|
|
178
|
-
def get_day_seconds():
|
|
179
|
-
"""
|
|
180
|
-
Returns the number of seconds in a day.
|
|
181
|
-
|
|
182
|
-
Returns:
|
|
183
|
-
float: The number of seconds in a day.
|
|
184
|
-
"""
|
|
185
|
-
return float(24 * 60 * 60)
|
|
186
|
-
|
|
187
|
-
def get_week_seconds():
|
|
188
|
-
"""
|
|
189
|
-
Returns the number of seconds in a week.
|
|
190
|
-
|
|
191
|
-
Returns:
|
|
192
|
-
float: The number of seconds in a week.
|
|
193
|
-
"""
|
|
194
|
-
return float(7 * 24 * 60 * 60)
|
|
195
|
-
|
|
196
|
-
def get_hour_seconds():
|
|
197
|
-
"""
|
|
198
|
-
Returns the number of seconds in an hour.
|
|
199
|
-
|
|
200
|
-
Returns:
|
|
201
|
-
float: The number of seconds in an hour.
|
|
202
|
-
"""
|
|
203
|
-
return float(60 * 60)
|
|
204
|
-
|
|
205
|
-
def get_minute_seconds():
|
|
206
|
-
"""
|
|
207
|
-
Returns the number of seconds in a minute.
|
|
208
|
-
|
|
209
|
-
Returns:
|
|
210
|
-
float: The number of seconds in a minute.
|
|
211
|
-
"""
|
|
212
|
-
return float(60)
|
|
213
|
-
|
|
214
|
-
def get_second():
|
|
215
|
-
"""
|
|
216
|
-
Returns the value of one second.
|
|
217
|
-
|
|
218
|
-
Returns:
|
|
219
|
-
float: The value of one second.
|
|
220
|
-
"""
|
|
221
|
-
return float(1)
|
|
222
|
-
|
|
223
|
-
def all_combinations_of_strings(strings):
|
|
224
|
-
"""
|
|
225
|
-
Generate all possible combinations of the input strings.
|
|
226
|
-
Each combination is a concatenation of the input strings in different orders.
|
|
227
|
-
|
|
228
|
-
:param strings: A list of strings for which we want to generate all combinations.
|
|
229
|
-
:return: A list of strings representing all possible combinations.
|
|
230
|
-
"""
|
|
231
|
-
from itertools import permutations
|
|
232
|
-
|
|
233
|
-
# Generate all permutations of the input list
|
|
234
|
-
all_perms = permutations(strings)
|
|
235
|
-
|
|
236
|
-
# Concatenate strings in each permutation to form the combinations
|
|
237
|
-
combinations = [''.join(perm) for perm in all_perms]
|
|
238
|
-
|
|
239
|
-
return combinations
|
|
240
|
-
def all_date_formats():
|
|
241
|
-
date_formats=[]
|
|
242
|
-
for part in all_combinations_of_strings(list("Ymd")):
|
|
243
|
-
for seperator in ['/','-','_']:
|
|
244
|
-
date_range='%'
|
|
245
|
-
for piece in list(str(part)):
|
|
246
|
-
date_range+=f"{piece}{seperator}%"
|
|
247
|
-
for times in ["%H:%M:%S.%f","%H:%M:%S"]:
|
|
248
|
-
date_format = f"{date_range[:-2]} {times}"
|
|
249
|
-
if date_format not in date_formats:
|
|
250
|
-
date_formats.append(date_format)
|
|
251
|
-
return date_formats
|
|
252
|
-
|
|
253
|
-
def get_time_string(data):
|
|
254
|
-
strin = 0
|
|
255
|
-
for string in ["Timestamp","Data_Time_Stamp"]:
|
|
256
|
-
strings = data.get(string)
|
|
257
|
-
if strin:
|
|
258
|
-
pass
|
|
259
|
-
return strings
|
|
260
|
-
def convert_date_to_timestamp(date_string,date_format=[]):
|
|
261
|
-
date_formats = all_date_formats()
|
|
262
|
-
date_string = str(date_string)
|
|
263
|
-
date_formats = make_list(date_format)+date_formats
|
|
264
|
-
for date_format in date_formats:
|
|
265
|
-
try:
|
|
266
|
-
date_object = datetime.strptime(date_string, date_format)
|
|
267
|
-
return date_object.timestamp()
|
|
268
|
-
except ValueError:
|
|
269
|
-
continue
|
|
270
|
-
print(f"Date format not recognized: {date_string}")
|
|
271
|
-
return None
|
|
272
|
-
def get_rounded_hour_datetime(timeStamp=None,hours=0):
|
|
273
|
-
"""
|
|
274
|
-
Returns the current datetime rounded down to the nearest hour,
|
|
275
|
-
with an optional adjustment by a specified number of hours.
|
|
276
|
-
|
|
277
|
-
:param hours: Number of hours to adjust the rounded datetime by.
|
|
278
|
-
Defaults to 0 (no adjustment).
|
|
279
|
-
:return: A datetime object for the adjusted, rounded-down hour.
|
|
280
|
-
"""
|
|
281
|
-
now = get_convert_timestamp_to_datetime(timeStamp or datetime.now())
|
|
282
|
-
# Round down to the nearest hour
|
|
283
|
-
rounded_hour = now.replace(minute=0, second=0, microsecond=0)
|
|
284
|
-
# Adjust by the specified number of hours
|
|
285
|
-
adjusted_datetime = rounded_hour + timedelta(hours=hours)
|
|
286
|
-
return adjusted_datetime
|
|
287
|
-
|
|
288
|
-
def get_current_time_with_delta(days=0, hours=0, minutes=0, seconds=0,milliseconds=0):
|
|
289
|
-
# Get the current datetime
|
|
290
|
-
current_time = get_time_stamp()
|
|
291
|
-
|
|
292
|
-
# Create a timedelta with the specified duration
|
|
293
|
-
delta = timedelta(days=days, hours=hours, minutes=minutes,seconds=seconds, milliseconds=milliseconds)
|
|
294
|
-
|
|
295
|
-
# Add the delta to the current time
|
|
296
|
-
new_time = current_time + delta
|
|
297
|
-
|
|
298
|
-
return new_time
|
|
299
|
-
def get_time_stamp_date():
|
|
300
|
-
return datetime.now()
|
|
301
|
-
|
|
302
|
-
def get_time_stamp_now():
|
|
303
|
-
return datetime.datetime.now()
|
|
304
|
-
|
|
305
|
-
def get_timestamp():
|
|
306
|
-
return time.time()
|
|
307
|
-
|
|
308
|
-
def get_hours_ago_datetime(hours=1):
|
|
309
|
-
return get_time_stamp() - get_time_delta_hour(hours=hours)
|
|
310
|
-
|
|
311
|
-
def get_hours_ago(hours=1):
|
|
312
|
-
hours_ago = get_hours_ago_datetime(hours=1)
|
|
313
|
-
return hours_ago.timestamp()
|
|
314
|
-
|
|
315
|
-
def get_daily_output(timeStamp=None):
|
|
316
|
-
timeStamp = get_convert_timestamp_to_datetime(convert_date_to_timestamp(timeStamp or get_time_stamp()))
|
|
317
|
-
return timeStamp.strftime('%m-%d-%Y')
|
|
318
|
-
|
|
319
|
-
def get_hourly_output(timeStamp=None):
|
|
320
|
-
timeStamp = get_convert_timestamp_to_datetime(convert_date_to_timestamp(timeStamp or get_time_stamp()))
|
|
321
|
-
return timeStamp.strftime('%H') + '00'
|
|
322
|
-
|
|
323
|
-
def get_hour_time_stamp(hours=0):
|
|
324
|
-
return convert_date_to_timestamp(f"{get_rounded_hour_datetime(hours=hours)}")
|
|
325
|
-
|
|
326
|
-
def get_variable_time_stamp(days=0,hours=0,minutes=0,seconds=0):
|
|
327
|
-
return convert_date_to_timestamp(f"{get_daily_output()} 0:0:00")+(days*(60*60*24))+(hours*(60*60))+(minutes*60)+seconds
|
|
328
|
-
|
|
329
|
-
def get_variable_datetime(days=0,hours=0,minutes=0,seconds=0):
|
|
330
|
-
timeStamp = get_variable_time_stamp(days=0,hours=0,minutes=0,seconds=0)
|
|
331
|
-
return get_convert_timestamp_to_datetime(timeStamp)
|
|
332
|
-
def get_convert_datetime_to_timeStamp(timeStamp):
|
|
333
|
-
timeStamp = timeStamp or get_timestamp()
|
|
334
|
-
if not is_number(timeStamp):
|
|
335
|
-
timeStamp = convert_date_to_timestamp(timeStamp)
|
|
336
|
-
return timeStamp
|
|
337
|
-
def get_convert_timestamp_to_datetime(timeStamp=None):
|
|
338
|
-
timeStamp = timeStamp or get_time_stamp()
|
|
339
|
-
if is_number(timeStamp):
|
|
340
|
-
timeStamp = datetime.fromtimestamp(timeStamp)
|
|
341
|
-
return timeStamp
|
|
342
|
-
def is_within_day(timeStamp):
|
|
343
|
-
return is_between_range(get_convert_timestamp(timeStamp),get_day_time_stamp(),get_day_time_stamp(days=1))
|
|
344
|
-
def is_within_hour(timeStamp):
|
|
345
|
-
return is_between_range(get_convert_timestamp(timeStamp),get_hour_time_stamp(),get_hour_time_stamp(hours=1))
|
|
346
|
-
|
|
347
|
-
def is_between_range(target,start,end):
|
|
348
|
-
if target >= start and target <=end:
|
|
349
|
-
return True
|
|
350
|
-
return False
|
|
351
|
-
def get_creation_time_of_file(file_path):
|
|
352
|
-
if os.path.isfile(file_path):
|
|
353
|
-
creation_time = os.path.getctime(file_path)
|
|
354
|
-
return datetime.datetime.fromtimestamp(creation_time)
|
|
355
|
-
|
|
356
|
-
def timestamp_to_milliseconds(timestamp):
|
|
357
|
-
try:
|
|
358
|
-
t = datetime.strptime(timestamp, "%H:%M:%S.%f")
|
|
359
|
-
return (t.hour * 3600 + t.minute * 60 + t.second) * 1000 + int(t.microsecond / 1000)
|
|
360
|
-
except ValueError:
|
|
361
|
-
raise ValueError(f"Invalid timestamp format: {timestamp}")
|
|
362
|
-
|
|
363
|
-
def parse_timestamp(ts_str):
|
|
364
|
-
parts = ts_str.split(":")
|
|
365
|
-
return (int(parts[0]) * 60 + int(parts[1])) * 1000 if len(parts) == 2 else int(parts[0]) * 1000
|
|
366
|
-
def format_timestamp(ms):
|
|
367
|
-
"""Convert milliseconds to a formatted timestamp (HH:MM:SS.mmm)."""
|
|
368
|
-
td = timedelta(milliseconds=ms)
|
|
369
|
-
hours, remainder = divmod(td.seconds, 3600)
|
|
370
|
-
minutes, seconds = divmod(remainder, 60)
|
|
371
|
-
milliseconds = td.microseconds // 1000
|
|
372
|
-
return f"{hours:02d}:{minutes:02d}:{seconds:02d}.{milliseconds:03d}"
|
|
373
|
-
|
|
374
|
-
def get_time_now_iso():
|
|
375
|
-
return datetime.now().isoformat()
|
|
376
|
-
def is_valid_time(comp_timestamp, timestamp=None, before=True):
|
|
377
|
-
if timestamp is None:
|
|
378
|
-
return True
|
|
379
|
-
return (timestamp >= comp_timestamp) if before else (timestamp <= comp_timestamp)
|
|
380
|
-
|
|
381
|
-
# Function: get_time_stamp
|
|
382
|
-
# Function: get_milisecond_time_stamp
|
|
383
|
-
# Function: get_day
|
|
384
|
-
# Function: get_time
|
|
385
|
-
# Function: get_date
|
|
386
|
-
# Function: save_last_time
|
|
387
|
-
# Function: get_day_seconds
|
|
388
|
-
# Function: get_week_seconds
|
|
389
|
-
# Function: get_hour_seconds
|
|
390
|
-
# Function: get_minute_seconds
|
|
391
|
-
# Function: get_second
|
|
392
|
-
# Function: get_24_hr_start
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/imports/__init__.py
RENAMED
|
File without changes
|
{abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/imports/imports.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{abstract_security-0.78 → abstract_security-0.80}/src/abstract_security/imports/ssh_utils/classes.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{abstract_security-0.78 → abstract_security-0.80}/src/abstract_security.egg-info/requires.txt
RENAMED
|
File without changes
|
{abstract_security-0.78 → abstract_security-0.80}/src/abstract_security.egg-info/top_level.txt
RENAMED
|
File without changes
|