Skip to content

Commit

Permalink
0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt authored Jan 11, 2022
1 parent 705b003 commit d170c2f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions arclet/alconna/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""杂物堆"""


from typing import Any, Union, Type
from arclet.alconna.types import ArgPattern, _AnyParam, NonTextElement, Empty, AnyStr, AnyDigit, AnyFloat, Bool, \
AnyUrl, AnyIP, AnyParam


def split_once(text: str, separate: str): # 相当于另类的pop, 不会改变本来的字符串
"""单次分隔字符串"""
out_text = ""
Expand Down Expand Up @@ -44,3 +49,25 @@ def split(text: str, separate: str = " ", max_split: int = -1):
if text:
text_list.append(text)
return text_list


def arg_check(item: Any) -> Union[ArgPattern, _AnyParam, Type[NonTextElement], Empty]:
"""对 Args 里参数类型的检查, 将一般数据类型转为 Args 使用的类型"""
_check_list = {
str: AnyStr,
int: AnyDigit,
float: AnyFloat,
bool: Bool,
Ellipsis: Empty,
"url": AnyUrl,
"ip": AnyIP,
"": AnyParam,
"...": Empty
}
if _check_list.get(item):
return _check_list.get(item)
if item is None:
return Empty
if isinstance(item, str):
return ArgPattern(item)
return item

0 comments on commit d170c2f

Please sign in to comment.