Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5203bcf1ea | ||
|
|
f1e3bc8559 | ||
|
|
b97ca6f064 | ||
|
|
d1ea9874da | ||
|
|
3cd3f87d68 | ||
|
|
582937b866 | ||
|
|
2b8240c156 | ||
|
|
abf4b7ac89 |
@@ -1,7 +1,7 @@
|
|||||||
# MARK: Project info
|
# MARK: Project info
|
||||||
[project]
|
[project]
|
||||||
name = "corelibs"
|
name = "corelibs"
|
||||||
version = "0.18.0"
|
version = "0.19.1"
|
||||||
description = "Collection of utils for Python scripts"
|
description = "Collection of utils for Python scripts"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import json
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
def dump_data(data: dict[Any, Any] | list[Any] | str | None) -> str:
|
def dump_data(data: Any) -> str:
|
||||||
"""
|
"""
|
||||||
dump formated output from dict/list
|
dump formated output from dict/list
|
||||||
|
|
||||||
|
|||||||
@@ -57,12 +57,12 @@ def find_in_array_from_list(
|
|||||||
f"Either Key '{search.get('key', '')}' or "
|
f"Either Key '{search.get('key', '')}' or "
|
||||||
f"Value '{search.get('value', '')}' is missing or empty"
|
f"Value '{search.get('value', '')}' is missing or empty"
|
||||||
)
|
)
|
||||||
keys.append(str(search['key']))
|
|
||||||
# if double key -> abort
|
# if double key -> abort
|
||||||
if search.get("key") in keys:
|
if search.get("key") in keys:
|
||||||
raise KeyError(
|
raise KeyError(
|
||||||
f"Key {search.get('key', '')} already exists in search_params"
|
f"Key {search.get('key', '')} already exists in search_params"
|
||||||
)
|
)
|
||||||
|
keys.append(str(search['key']))
|
||||||
|
|
||||||
return_items: list[dict[str, Any]] = []
|
return_items: list[dict[str, Any]] = []
|
||||||
for si_idx, search_item in enumerate(data):
|
for si_idx, search_item in enumerate(data):
|
||||||
|
|||||||
@@ -32,4 +32,6 @@ def jmespath_search(search_data: dict[Any, Any] | list[Any], search_params: str)
|
|||||||
raise ValueError(f"Type error for search_params: {excp}") from excp
|
raise ValueError(f"Type error for search_params: {excp}") from excp
|
||||||
return search_result
|
return search_result
|
||||||
|
|
||||||
|
# TODO: compile jmespath setup
|
||||||
|
|
||||||
# __END__
|
# __END__
|
||||||
|
|||||||
@@ -229,7 +229,8 @@ class LogParent:
|
|||||||
if log_error:
|
if log_error:
|
||||||
self.logger.log(
|
self.logger.log(
|
||||||
LoggingLevel.ERROR.value,
|
LoggingLevel.ERROR.value,
|
||||||
f"<=EXCEPTION> {msg}", *args, extra=dict(extra) | {'console': True}, stacklevel=2
|
f"<=EXCEPTION> {msg} [{extra['stack_trace']}]",
|
||||||
|
*args, extra=dict(extra) | {'console': True}, stacklevel=2
|
||||||
)
|
)
|
||||||
self.logger.log(LoggingLevel.EXCEPTION.value, msg, *args, exc_info=True, extra=extra, stacklevel=2)
|
self.logger.log(LoggingLevel.EXCEPTION.value, msg, *args, exc_info=True, extra=extra, stacklevel=2)
|
||||||
|
|
||||||
|
|||||||
20
src/corelibs/requests_handling/auth_helpers.py
Normal file
20
src/corelibs/requests_handling/auth_helpers.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
"""
|
||||||
|
Various HTTP auth helpers
|
||||||
|
"""
|
||||||
|
|
||||||
|
from base64 import b64encode
|
||||||
|
|
||||||
|
|
||||||
|
def basic_auth(username: str, password: str) -> str:
|
||||||
|
"""
|
||||||
|
setup basic auth, for debug
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
username {str} -- _description_
|
||||||
|
password {str} -- _description_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str -- _description_
|
||||||
|
"""
|
||||||
|
token = b64encode(f"{username}:{password}".encode('utf-8')).decode("ascii")
|
||||||
|
return f'Basic {token}'
|
||||||
52
test-run/json_handling/jmespath_helper.py
Normal file
52
test-run/json_handling/jmespath_helper.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
jmes path testing
|
||||||
|
"""
|
||||||
|
|
||||||
|
from corelibs.debug_handling.dump_data import dump_data
|
||||||
|
from corelibs.json_handling.jmespath_helper import jmespath_search
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""
|
||||||
|
Comment
|
||||||
|
"""
|
||||||
|
__set = {
|
||||||
|
'a': 'b',
|
||||||
|
'foobar': [1, 2, 'a'],
|
||||||
|
'bar': {
|
||||||
|
'a': 1,
|
||||||
|
'b': 'c'
|
||||||
|
},
|
||||||
|
'baz': [
|
||||||
|
{
|
||||||
|
'aa': 1,
|
||||||
|
'ab': 'cc'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'ba': 2,
|
||||||
|
'bb': 'dd'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'foo': {
|
||||||
|
'a': [1, 2, 3],
|
||||||
|
'b': ['a', 'b', 'c']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__get = [
|
||||||
|
'a',
|
||||||
|
'bar.a',
|
||||||
|
'foo.a',
|
||||||
|
'baz[].aa'
|
||||||
|
]
|
||||||
|
for __jmespath in __get:
|
||||||
|
result = jmespath_search(__set, __jmespath)
|
||||||
|
print(f"GET {__jmespath}: {dump_data(result)}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
|
# __END__
|
||||||
Reference in New Issue
Block a user