satori-python-core 1.3.5__tar.gz → 1.3.6__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: 1.3.5
3
+ Version: 1.3.6
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>
@@ -21,7 +21,7 @@ classifiers = [
21
21
  "Programming Language :: Python :: 3.14",
22
22
  "Operating System :: OS Independent",
23
23
  ]
24
- version = "1.3.5"
24
+ version = "1.3.6"
25
25
 
26
26
  [project.license]
27
27
  text = "MIT"
@@ -45,7 +45,7 @@ from .model import Role as Role
45
45
  from .model import Upload as Upload
46
46
  from .model import User as User
47
47
 
48
- __version__ = "1.3.5"
48
+ __version__ = "1.3.6"
49
49
 
50
50
 
51
51
  MessageReceipt = MessageObject
@@ -129,7 +129,7 @@ class Element:
129
129
  args = {**self._attrs}
130
130
  elem = f"{self.__class__.__name__}(" + ", ".join(f"{k}={v!r}" for k, v in args.items())
131
131
  if self._children:
132
- elem += ", { " + ", ".join(repr(i) for i in self._children) + " }"
132
+ elem += ", [" + ", ".join(repr(i) for i in self._children) + "]"
133
133
  return elem + ")"
134
134
 
135
135
  def __call__(self, *content: "str | Element"):
@@ -257,7 +257,6 @@ class Link(Element):
257
257
  class Resource(Element):
258
258
  src: str
259
259
  title: str | None = None
260
- extra: InitVar[dict[str, Any] | None] = None
261
260
  cache: bool | None = None
262
261
  timeout: int | None = None
263
262
 
@@ -271,14 +270,15 @@ class Resource(Element):
271
270
  raw: bytes | BytesIO | None = None,
272
271
  mime: str | None = None,
273
272
  name: str | None = None,
273
+ width: int | None = None,
274
+ height: int | None = None,
274
275
  duration: float | None = None,
275
276
  poster: str | None = None,
276
- extra: dict[str, Any] | None = None,
277
277
  cache: bool | None = None,
278
278
  timeout: int | None = None,
279
279
  **kwargs,
280
280
  ) -> Self:
281
- data: dict[str, Any] = {"extra": extra, **kwargs}
281
+ data: dict[str, Any] = {**kwargs}
282
282
  if url is not None:
283
283
  data |= {"src": url}
284
284
  elif path:
@@ -296,6 +296,10 @@ class Resource(Element):
296
296
  raise ValueError(f"{cls} need at least one of url, path and raw")
297
297
  if name is not None:
298
298
  data["title"] = name
299
+ if width is not None and cls in (Image, Video):
300
+ data["width"] = width
301
+ if height is not None and cls in (Image, Video):
302
+ data["height"] = height
299
303
  if duration is not None and cls is Audio:
300
304
  data["duration"] = duration
301
305
  if poster is not None and cls in (Video, Audio, File):
@@ -304,11 +308,7 @@ class Resource(Element):
304
308
  data["cache"] = cache
305
309
  if timeout is not None:
306
310
  data["timeout"] = timeout
307
- return cls(**data)
308
-
309
- def __post_init__(self, extra: dict[str, Any] | None = None):
310
- if extra:
311
- self._attrs.update(extra)
311
+ return cls.unpack(data)
312
312
 
313
313
 
314
314
  @dataclass(repr=False)
@@ -582,7 +582,7 @@ class Custom(Element):
582
582
  attrs: dict[str, Any] | None = None,
583
583
  children: Sequence[str | Element] | None = None,
584
584
  ):
585
- self.type = type
585
+ self._type = type
586
586
  if not hasattr(self, "_attrs"):
587
587
  self._attrs = attrs or {}
588
588
  else:
@@ -595,7 +595,21 @@ class Custom(Element):
595
595
  @property
596
596
  @override
597
597
  def tag(self) -> str:
598
- return self.type
598
+ return self._type
599
+
600
+ def __repr__(self) -> str:
601
+ if not self._attrs:
602
+ self._attrs = {k: v for k, v in self.__dict__.items() if not k.startswith("_")}
603
+ args = {**self._attrs}
604
+ elem = (
605
+ f"{self.__class__.__name__}({self._type!r}"
606
+ + ", {"
607
+ + ", ".join(f"{k!r}: {v!r}" for k, v in args.items())
608
+ + "}"
609
+ )
610
+ if self._children:
611
+ elem += ", [" + ", ".join(repr(i) for i in self._children) + "]"
612
+ return elem + ")"
599
613
 
600
614
 
601
615
  @dataclass(repr=False)