satori-python-core 0.13.0__tar.gz → 0.13.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: satori-python-core
3
- Version: 0.13.0
3
+ Version: 0.13.2
4
4
  Summary: Satori Protocol SDK for python, specify common part
5
5
  Home-page: https://github.com/RF-Tar-Railt/satori-python
6
6
  Author-Email: RF-Tar-Railt <rf_tar_railt@qq.com>
@@ -23,7 +23,7 @@ classifiers = [
23
23
  "Programming Language :: Python :: 3.12",
24
24
  "Operating System :: OS Independent",
25
25
  ]
26
- version = "0.13.0"
26
+ version = "0.13.2"
27
27
 
28
28
  [project.license]
29
29
  text = "MIT"
@@ -25,6 +25,7 @@ from .element import Superscript as Superscript
25
25
  from .element import Text as Text
26
26
  from .element import Underline as Underline
27
27
  from .element import Video as Video
28
+ from .element import select as select
28
29
  from .element import transform as transform
29
30
  from .model import ArgvInteraction as ArgvInteraction
30
31
  from .model import ButtonInteraction as ButtonInteraction
@@ -42,4 +43,4 @@ from .model import Role as Role
42
43
  from .model import Upload as Upload
43
44
  from .model import User as User
44
45
 
45
- __version__ = "0.13.0"
46
+ __version__ = "0.13.2"
@@ -2,11 +2,12 @@ from base64 import b64encode
2
2
  from dataclasses import InitVar, dataclass, field, fields
3
3
  from io import BytesIO
4
4
  from pathlib import Path
5
- from typing import Any, ClassVar, Dict, List, Optional, Tuple, TypeVar, Union, get_args
5
+ from typing import Any, ClassVar, Dict, List, Optional, Tuple, Type, TypeVar, Union, get_args, overload
6
6
  from typing_extensions import override
7
7
 
8
8
  from .parser import Element as RawElement
9
9
  from .parser import escape, param_case
10
+ from .parser import select as select_raw
10
11
 
11
12
  TE = TypeVar("TE", bound="Element")
12
13
 
@@ -566,6 +567,32 @@ def transform(elements: List[RawElement]) -> List[Element]:
566
567
  return msg
567
568
 
568
569
 
570
+ @overload
571
+ def select(elements: Union[Element, List[Element]], query: Type[TE]) -> List[TE]: ...
572
+
573
+
574
+ @overload
575
+ def select(elements: Union[Element, List[Element]], query: str) -> List[Element]: ...
576
+
577
+
578
+ def select(elements: Union[Element, List[Element]], query: Union[Type[TE], str]):
579
+ if not elements:
580
+ return []
581
+ if isinstance(elements, Element):
582
+ elements = [elements]
583
+ if isinstance(query, str):
584
+ return transform(select_raw("".join(map(str, elements)), query))
585
+ if query is Element:
586
+ return elements
587
+ results = []
588
+ for elem in elements:
589
+ if isinstance(elem, query):
590
+ results.append(elem)
591
+ if elem.children:
592
+ results.extend(select(elem.children, query))
593
+ return results
594
+
595
+
569
596
  class E:
570
597
  text = Text
571
598
  at = At
@@ -598,5 +625,7 @@ class E:
598
625
  link_button = Button.link
599
626
  input_button = Button.input
600
627
 
628
+ select = select
629
+
601
630
  def __new__(cls, *args, **kwargs):
602
631
  raise TypeError("E is not instantiable")