This commit is contained in:
@@ -3,24 +3,30 @@ from pathlib import Path
|
||||
import json
|
||||
import logging
|
||||
import inspect
|
||||
from typing import List
|
||||
|
||||
from .shared import DEBUG, DEBUG_LOGGING, DEBUG_DUMP, DEBUG_TRACE, DEBUG_OBJECT_TRACE, DEBUG_OBJECT_TRACE_CALLSTACK
|
||||
from .config import config, read_config, write_config
|
||||
from .enums.colors import BColors
|
||||
from .path_manager import LOCATIONS
|
||||
from .hacking import merge_args
|
||||
|
||||
"""
|
||||
IO functions
|
||||
"""
|
||||
|
||||
def _apply_color(msg: str, color: BColors) -> str:
|
||||
if not isinstance(msg, str):
|
||||
msg = str(msg)
|
||||
|
||||
if color is BColors.ENDC:
|
||||
return msg
|
||||
return color.value + msg + BColors.ENDC.value
|
||||
|
||||
|
||||
def output(msg: str, color: BColors = BColors.ENDC):
|
||||
print(_apply_color(msg, color))
|
||||
@merge_args(print)
|
||||
def output(*msg: List[str], color: BColors = BColors.ENDC, **kwargs):
|
||||
print(*(_apply_color(s, color) for s in msg), **kwargs)
|
||||
|
||||
|
||||
def user_input(msg: str, color: BColors = BColors.ENDC):
|
||||
|
||||
@@ -78,7 +78,14 @@ def _merge(
|
||||
drop_args = []
|
||||
if drop_kwonlyargs is None:
|
||||
drop_kwonlyargs = []
|
||||
source_spec = inspect.getfullargspec(source)
|
||||
|
||||
is_builtin = False
|
||||
try:
|
||||
source_spec = inspect.getfullargspec(source)
|
||||
except TypeError:
|
||||
is_builtin = True
|
||||
source_spec = inspect.FullArgSpec(type(source).__name__, [], [], [], [], [], [])
|
||||
|
||||
dest_spec = inspect.getfullargspec(dest)
|
||||
|
||||
if source_spec.varargs or source_spec.varkw:
|
||||
@@ -128,13 +135,15 @@ def _merge(
|
||||
'co_kwonlyargcount': len(kwonlyargs_merged),
|
||||
'co_posonlyargcount': dest.__code__.co_posonlyargcount,
|
||||
'co_nlocals': len(args_all),
|
||||
'co_flags': source.__code__.co_flags,
|
||||
'co_varnames': args_all,
|
||||
'co_filename': dest.__code__.co_filename,
|
||||
'co_name': dest.__code__.co_name,
|
||||
'co_firstlineno': dest.__code__.co_firstlineno,
|
||||
}
|
||||
|
||||
if hasattr(source, "__code__"):
|
||||
replace_kwargs['co_flags'] = source.__code__.co_flags
|
||||
|
||||
if PY310:
|
||||
replace_kwargs['co_linetable'] = dest.__code__.co_linetable
|
||||
else:
|
||||
@@ -151,7 +160,7 @@ def _merge(
|
||||
len(kwonlyargs_merged),
|
||||
_blank.__code__.co_nlocals,
|
||||
_blank.__code__.co_stacksize,
|
||||
source.__code__.co_flags,
|
||||
source.__code__.co_flags if hasattr(source, "__code__") else dest.__code__.co_flags,
|
||||
_blank.__code__.co_code, (), (),
|
||||
args_all, dest.__code__.co_filename,
|
||||
dest.__code__.co_name,
|
||||
@@ -171,6 +180,9 @@ def _merge(
|
||||
dest_ret = dest.__annotations__['return']
|
||||
|
||||
for v in ('__kwdefaults__', '__annotations__'):
|
||||
if not hasattr(source, v):
|
||||
continue
|
||||
|
||||
out = getattr(source, v)
|
||||
if out is None:
|
||||
out = {}
|
||||
|
||||
@@ -32,8 +32,9 @@ def unify(string: str) -> str:
|
||||
string = translit(string, reversed=True)
|
||||
except LanguageDetectionError:
|
||||
pass
|
||||
|
||||
return string.lower()
|
||||
|
||||
string = unify_punctuation(string)
|
||||
return string.lower().strip()
|
||||
|
||||
|
||||
def fit_to_file_system(string: Union[str, Path], hidden_ok: bool = False) -> Union[str, Path]:
|
||||
|
||||
Reference in New Issue
Block a user