fix: aaaaaaa
This commit is contained in:
parent
4b99d6d87d
commit
3f4477ea79
@ -21,36 +21,14 @@ from Difficult_Rocket.utils import tools
|
|||||||
from Difficult_Rocket.exception.language import *
|
from Difficult_Rocket.exception.language import *
|
||||||
|
|
||||||
|
|
||||||
class Translated:
|
class Translates:
|
||||||
def __init__(self, value: Union[list, tuple, dict, str], raise_error: bool = False):
|
def __init__(self, value: Union[Dict[str, Any], list, tuple, str], raise_error: bool = False, get_list: list = None, final: bool = False):
|
||||||
self.value = value
|
|
||||||
self.raise_error = raise_error
|
|
||||||
self.item_names = []
|
|
||||||
|
|
||||||
def __getattr__(self, item):
|
|
||||||
if hasattr(object, item):
|
|
||||||
return getattr(object, item)
|
|
||||||
self.item_names.append(item)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __getitem__(self, item):
|
|
||||||
self.item_names.append(item)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
if not self.item_names:
|
|
||||||
return self.value
|
|
||||||
else:
|
|
||||||
return f'{self.value}.{".".join(self.item_names)}'
|
|
||||||
|
|
||||||
|
|
||||||
class Translating:
|
|
||||||
def __init__(self, value: Union[Dict[str, Any], list, tuple], raise_error: bool = False, get_list: list = None):
|
|
||||||
self.value: Union[Dict[str, Any], list, tuple] = value
|
self.value: Union[Dict[str, Any], list, tuple] = value
|
||||||
self.raise_error = raise_error
|
self.raise_error = raise_error
|
||||||
self.get_list = get_list or []
|
self.get_list = get_list or []
|
||||||
|
self.final = final
|
||||||
|
|
||||||
def __getitem__(self, item: Union[str, Hashable]) -> Union["Translating", Translated]:
|
def __getitem__(self, item: Union[str, Hashable]) -> Union["Translates"]:
|
||||||
cache_get_list = self.get_list.copy()
|
cache_get_list = self.get_list.copy()
|
||||||
cache_get_list.append(item)
|
cache_get_list.append(item)
|
||||||
try:
|
try:
|
||||||
@ -65,69 +43,12 @@ class Translating:
|
|||||||
f'{last_frame.f_code.co_filename}:{last_frame.f_lineno}'
|
f'{last_frame.f_code.co_filename}:{last_frame.f_lineno}'
|
||||||
print(call_info)
|
print(call_info)
|
||||||
if not self.raise_error:
|
if not self.raise_error:
|
||||||
return Translated('.'.join(cache_get_list), raise_error=False)
|
return Translates(value='.'.join(cache_get_list), raise_error=False, final=True)
|
||||||
else:
|
else:
|
||||||
raise TranslateKeyNotFound(item_names=cache_get_list)
|
raise TranslateKeyNotFound(item_names=cache_get_list)
|
||||||
return Translating(value=cache, raise_error=self.raise_error, get_list=cache_get_list)
|
return Translates(value=cache, raise_error=self.raise_error, get_list=cache_get_list)
|
||||||
|
|
||||||
def __getattr__(self, item: Union[str, Hashable]) -> Union["Translating", Translated]:
|
def __getattr__(self, item: Union[str, Hashable]) -> Union["Translates"]:
|
||||||
if hasattr(object, item):
|
|
||||||
return getattr(object, item)
|
|
||||||
return self.__getitem__(item)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return str(self.value)
|
|
||||||
|
|
||||||
class Translated:
|
|
||||||
def __init__(self, value: Union[list, tuple, dict, str], raise_error: bool = False):
|
|
||||||
self.value = value
|
|
||||||
self.raise_error = raise_error
|
|
||||||
self.item_names = []
|
|
||||||
|
|
||||||
def __getattr__(self, item):
|
|
||||||
if hasattr(object, item):
|
|
||||||
return getattr(object, item)
|
|
||||||
self.item_names.append(item)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __getitem__(self, item):
|
|
||||||
self.item_names.append(item)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
if not self.item_names:
|
|
||||||
return self.value
|
|
||||||
else:
|
|
||||||
return f'{self.value}.{".".join(self.item_names)}'
|
|
||||||
|
|
||||||
|
|
||||||
class Translating:
|
|
||||||
def __init__(self, value: Union[Dict[str, Any], list, tuple], raise_error: bool = False, get_list: list = None):
|
|
||||||
self.value: Union[Dict[str, Any], list, tuple] = value
|
|
||||||
self.raise_error = raise_error
|
|
||||||
self.get_list = get_list or []
|
|
||||||
|
|
||||||
def __getitem__(self, item: Union[str, Hashable]) -> Union["Translating", Translated]:
|
|
||||||
cache_get_list = self.get_list.copy()
|
|
||||||
cache_get_list.append(item)
|
|
||||||
try:
|
|
||||||
cache = self.value[item]
|
|
||||||
except (KeyError, TypeError):
|
|
||||||
if DEBUG_PRINT:
|
|
||||||
frame = inspect.currentframe()
|
|
||||||
last_frame = frame.f_back
|
|
||||||
if last_frame.f_code == self.__getattr__.__code__:
|
|
||||||
last_frame = last_frame.f_back
|
|
||||||
call_info = f'Translate Not Found at {last_frame.f_code.co_name} by {".".join(cache_get_list)} at:' \
|
|
||||||
f'{last_frame.f_code.co_filename}:{last_frame.f_lineno}'
|
|
||||||
print(call_info)
|
|
||||||
if not self.raise_error:
|
|
||||||
return Translated('.'.join(cache_get_list), raise_error=False)
|
|
||||||
else:
|
|
||||||
raise GetItemError(item_names=cache_get_list)
|
|
||||||
return Translating(value=cache, raise_error=self.raise_error, get_list=cache_get_list)
|
|
||||||
|
|
||||||
def __getattr__(self, item: Union[str, Hashable]) -> Union["Translating", Translated]:
|
|
||||||
if hasattr(object, item):
|
if hasattr(object, item):
|
||||||
return getattr(object, item)
|
return getattr(object, item)
|
||||||
return self.__getitem__(item)
|
return self.__getitem__(item)
|
||||||
|
@ -39,11 +39,15 @@
|
|||||||
- `开发平台 1 - Windows 10`
|
- `开发平台 1 - Windows 10`
|
||||||
- `Python 3.8.10`
|
- `Python 3.8.10`
|
||||||
- `Windows10 x64`
|
- `Windows10 x64`
|
||||||
- `pillow 9.2.0`
|
- `pillow 9.3.0`
|
||||||
- `pyperclip 1.8.2`
|
- `pyperclip 1.8.2`
|
||||||
- `pyglet 2.0`
|
- `pyglet 2.0`
|
||||||
|
- `psutil 5.9.4`
|
||||||
|
- `objprint 0.2.2`
|
||||||
|
- `rtoml 0.9.0`
|
||||||
|
- `pymunk 6.4.0`
|
||||||
- `xmltodict 0.12.0`
|
- `xmltodict 0.12.0`
|
||||||
- `tomlkit 0.11.5`
|
- `tomlkit 0.11.6`
|
||||||
- `AMD R5 5600X`
|
- `AMD R5 5600X`
|
||||||
- `AMD RX 550 4G`
|
- `AMD RX 550 4G`
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user