From 606302fcb32d33804ee65131c031debe10510c67 Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Mon, 4 Sep 2023 23:01:10 +0800 Subject: [PATCH 1/5] feat: `get_image_bytes` --- aiotieba/__version__.py | 2 +- aiotieba/api/get_images/__init__.py | 2 +- aiotieba/api/get_images/_api.py | 9 +++++++-- aiotieba/client.py | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/aiotieba/__version__.py b/aiotieba/__version__.py index 3bdbbae2..a9144f85 100644 --- a/aiotieba/__version__.py +++ b/aiotieba/__version__.py @@ -1 +1 @@ -__version__ = "3.7.2" +__version__ = "3.7.3a0" diff --git a/aiotieba/api/get_images/__init__.py b/aiotieba/api/get_images/__init__.py index 23ca3a44..8da709c2 100644 --- a/aiotieba/api/get_images/__init__.py +++ b/aiotieba/api/get_images/__init__.py @@ -1 +1 @@ -from ._api import null_ret_factory, parse_body, request +from ._api import null_ret_factory, parse_body, request, request_bytes diff --git a/aiotieba/api/get_images/_api.py b/aiotieba/api/get_images/_api.py index a2978522..77cd35a9 100644 --- a/aiotieba/api/get_images/_api.py +++ b/aiotieba/api/get_images/_api.py @@ -35,10 +35,15 @@ def parse_body(body: bytes) -> "np.ndarray": return image -async def request(http_core: HttpCore, url: yarl.URL) -> "np.ndarray": +async def request_bytes(http_core: HttpCore, url: yarl.URL) -> bytes: request = http_core.pack_web_get_request(url, []) __log__ = "url={url}" # noqa: F841 - body = await http_core.net_core.send_request(request, read_bufsize=512 * 1024, headers_checker=headers_checker) + body = await http_core.net_core.send_request(request, read_bufsize=256 * 1024, headers_checker=headers_checker) + return body + + +async def request(http_core: HttpCore, url: yarl.URL) -> "np.ndarray": + body = await request_bytes(http_core, url) return parse_body(body) diff --git a/aiotieba/client.py b/aiotieba/client.py index 3001ca59..0270a977 100644 --- a/aiotieba/client.py +++ b/aiotieba/client.py @@ -924,6 +924,20 @@ async def get_ats(self, pn: int = 1) -> get_ats.Ats: return await get_ats.request(self._http_core, pn) + @handle_exception(bytes) + async def get_image_bytes(self, img_url: str) -> bytes: + """ + 从链接获取静态图像的原始字节流 + + Args: + img_url (str): 图像链接 + + Returns: + bytes: 未解码的原始字节流 + """ + + return await get_images.request_bytes(self._http_core, yarl.URL(img_url)) + @handle_exception(get_images.null_ret_factory) async def get_image(self, img_url: str) -> "np.ndarray": """ From e3b5b396d230fdbfe7568c5dc039df2fa23fc3bc Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Wed, 13 Sep 2023 17:21:22 +0800 Subject: [PATCH 2/5] fix: invalid tbp --- aiotieba/api/get_comments/_classdef.py | 6 ++++++ aiotieba/api/get_posts/_classdef.py | 9 +++++++++ aiotieba/api/get_threads/_classdef.py | 6 ++++++ tests/test_get_comments.py | 8 -------- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/aiotieba/api/get_comments/_classdef.py b/aiotieba/api/get_comments/_classdef.py index 5cdce5d2..e48caf5a 100644 --- a/aiotieba/api/get_comments/_classdef.py +++ b/aiotieba/api/get_comments/_classdef.py @@ -84,6 +84,9 @@ def _frags(): self._tiebapluses.append(frag) self._texts.append(frag) yield frag + # outdated tiebaplus + elif _type == 34: + continue else: from ...logging import get_logger as LOG @@ -1270,6 +1273,9 @@ def _frags(): self._tiebapluses.append(frag) self._texts.append(frag) yield frag + # outdated tiebaplus + elif _type == 34: + continue else: from ...logging import get_logger as LOG diff --git a/aiotieba/api/get_posts/_classdef.py b/aiotieba/api/get_posts/_classdef.py index 7553a434..d7c2034b 100644 --- a/aiotieba/api/get_posts/_classdef.py +++ b/aiotieba/api/get_posts/_classdef.py @@ -328,6 +328,9 @@ def _frags(): self._tiebapluses.append(frag) self._texts.append(frag) yield frag + # outdated tiebaplus + elif _type == 34: + continue else: from ...logging import get_logger as LOG @@ -499,6 +502,9 @@ def _frags(): self._tiebapluses.append(frag) self._texts.append(frag) yield frag + # outdated tiebaplus + elif _type == 34: + continue else: from ...logging import get_logger as LOG @@ -1644,6 +1650,9 @@ def _frags(): self._tiebapluses.append(frag) self._texts.append(frag) yield frag + # outdated tiebaplus + elif _type == 34: + continue else: from ...logging import get_logger as LOG diff --git a/aiotieba/api/get_threads/_classdef.py b/aiotieba/api/get_threads/_classdef.py index a0afc7cd..9e14676b 100644 --- a/aiotieba/api/get_threads/_classdef.py +++ b/aiotieba/api/get_threads/_classdef.py @@ -218,6 +218,9 @@ def _frags(): self._tiebapluses.append(frag) self._texts.append(frag) yield frag + # outdated tiebaplus + elif _type == 34: + continue else: from ...logging import get_logger as LOG @@ -870,6 +873,9 @@ def _frags(): self._tiebapluses.append(frag) self._texts.append(frag) yield frag + # outdated tiebaplus + elif _type == 34: + continue else: from ...logging import get_logger as LOG diff --git a/tests/test_get_comments.py b/tests/test_get_comments.py index a8e20090..19604b93 100644 --- a/tests/test_get_comments.py +++ b/tests/test_get_comments.py @@ -89,14 +89,6 @@ async def test_Comments(client: tb.Client): assert frag.desc != '' assert frag.id == 'image_emoticon3' - # FragTiebaplus - frag = post.contents.tiebapluses[0] - assert frag.text != '' - assert frag.url != '' - frag = post.contents.tiebapluses[1] - assert frag.text != '' - assert frag.url != '' - ##### Comment ##### comment = comments[0] From 8ed280034fd4ab80ae13cf8f18f5fb339d271009 Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Wed, 13 Sep 2023 18:39:31 +0800 Subject: [PATCH 3/5] chore: bump version to 3.7.3a1 --- aiotieba/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiotieba/__version__.py b/aiotieba/__version__.py index a9144f85..73d94503 100644 --- a/aiotieba/__version__.py +++ b/aiotieba/__version__.py @@ -1 +1 @@ -__version__ = "3.7.3a0" +__version__ = "3.7.3a1" From 529dc1342577b6295fa1e84cc1598a4686c061ba Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Fri, 6 Oct 2023 16:42:46 +0800 Subject: [PATCH 4/5] chore: bump client version to 12.48.1.1 --- aiotieba/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiotieba/const.py b/aiotieba/const.py index 9b8ad1d7..7f46f4b4 100644 --- a/aiotieba/const.py +++ b/aiotieba/const.py @@ -1,4 +1,4 @@ -MAIN_VERSION = "12.46.3.0" +MAIN_VERSION = "12.48.1.1" POST_VERSION = "12.35.1.0" APP_SECURE_SCHEME = "https" From 80e7ea7ea21de3325ca788762bc90e9d52e193a3 Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Mon, 23 Oct 2023 10:18:57 +0800 Subject: [PATCH 5/5] chore: bimp version to 3.7.3 --- aiotieba/__version__.py | 2 +- aiotieba/const.py | 2 +- pyproject.toml | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/aiotieba/__version__.py b/aiotieba/__version__.py index 73d94503..221485ae 100644 --- a/aiotieba/__version__.py +++ b/aiotieba/__version__.py @@ -1 +1 @@ -__version__ = "3.7.3a1" +__version__ = "3.7.3" diff --git a/aiotieba/const.py b/aiotieba/const.py index 7f46f4b4..c1d236dc 100644 --- a/aiotieba/const.py +++ b/aiotieba/const.py @@ -1,4 +1,4 @@ -MAIN_VERSION = "12.48.1.1" +MAIN_VERSION = "12.49.1.0" POST_VERSION = "12.35.1.0" APP_SECURE_SCHEME = "https" diff --git a/pyproject.toml b/pyproject.toml index 64821b95..ad9d9e2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,10 +54,10 @@ speedup = [ "pysimdjson<6,>=3.1.1;python_version=='3.9'", "pysimdjson<6,>=4.0.3;python_version=='3.10'", "pysimdjson<6,>=5.0.1;python_version>='3.11'", - "uvloop<0.18,>=0.14.0;python_version=='3.8' and sys_platform!='win32'", - "uvloop<0.18,>=0.15.0;python_version=='3.9' and sys_platform!='win32'", - "uvloop<0.18,>=0.16.0;python_version=='3.10' and sys_platform!='win32'", - "uvloop<0.18,>=0.17.0;python_version>='3.11' and sys_platform!='win32'", + "uvloop<0.20,>=0.14.0;python_version=='3.8' and sys_platform!='win32'", + "uvloop<0.20,>=0.15.0;python_version=='3.9' and sys_platform!='win32'", + "uvloop<0.20,>=0.16.0;python_version=='3.10' and sys_platform!='win32'", + "uvloop<0.20,>=0.17.0;python_version>='3.11' and sys_platform!='win32'", ] [tool.setuptools.packages.find]