Skip to content

Commit

Permalink
feat: drop support for Python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
lumina37 committed Aug 11, 2024
1 parent 76628e7 commit e9ee6a2
Show file tree
Hide file tree
Showing 32 changed files with 46 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

strategy:
matrix:
python-version: ["3.8", "3.12"]
python-version: ["3.9", "3.12"]

steps:
- name: Checkout develop
Expand Down
3 changes: 2 additions & 1 deletion aiotieba/api/_classdef/container.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Generic, Iterator, SupportsIndex, TypeVar, overload
from collections.abc import Iterator
from typing import Generic, SupportsIndex, TypeVar, overload

TypeContainer = TypeVar('TypeContainer')

Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_ats/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import dataclasses as dcs
from collections.abc import Mapping
from functools import cached_property
from typing import Mapping

from ...enums import PrivLike, PrivReply
from ...exception import TbErrorExt
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_bawu_perm/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping

from ...enums import BawuPermType
from ...exception import TbErrorExt
Expand Down
4 changes: 2 additions & 2 deletions aiotieba/api/get_bawu_postlogs/_classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import bs4

from ...exception import TbErrorExt
from ...helper import default_datetime, removeprefix
from ...helper import default_datetime
from .._classdef import Containers
from .._classdef.contents import _IMAGEHASH_EXP

Expand Down Expand Up @@ -101,7 +101,7 @@ def from_tbdata(data_tag: bs4.element.Tag) -> Postlog:
pid = 0
text = f"{title}\n{text}"
else:
title = removeprefix(title, '回复:')
title = title.removeprefix('回复:')

if media_list_item := text_item.next_sibling:
medias = [Media_postlog.from_tbdata(tag) for tag in media_list_item.find_all('a')]
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_blacklist/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import dataclasses as dcs
from collections.abc import Mapping
from functools import cached_property
from typing import Mapping

from ...enums import BlacklistType
from ...exception import TbErrorExt
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_blocks/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping

import bs4

Expand Down
3 changes: 1 addition & 2 deletions aiotieba/api/get_comments/_classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from ...enums import Gender, PrivLike, PrivReply
from ...exception import TbErrorExt
from ...helper import removeprefix
from .._classdef import Containers, TypeMessage
from .._classdef.contents import (
_IMAGEHASH_EXP,
Expand Down Expand Up @@ -277,7 +276,7 @@ def from_tbdata(data_proto: TypeMessage) -> None:
contents.texts = contents.texts[2:]
if contents.texts:
first_text_frag = contents.texts[0]
first_text_frag.text = removeprefix(first_text_frag.text, ' :')
first_text_frag.text = first_text_frag.text.removeprefix(' :')

pid = data_proto.id
user = UserInfo_c.from_tbdata(data_proto.author)
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_fans/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import dataclasses as dcs
from collections.abc import Mapping
from functools import cached_property
from typing import Mapping

from ...exception import TbErrorExt
from .._classdef import Containers
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_follow_forums/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping

from ...exception import TbErrorExt
from .._classdef import Containers
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_follows/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import dataclasses as dcs
from collections.abc import Mapping
from functools import cached_property
from typing import Mapping

from ...exception import TbErrorExt
from .._classdef import Containers
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_forum/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping

from ...exception import TbErrorExt

Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_god_threads/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping

from ...exception import TbErrorExt
from .._classdef import Containers
Expand Down
3 changes: 1 addition & 2 deletions aiotieba/api/get_posts/_classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from ...enums import Gender, PrivLike, PrivReply
from ...exception import TbErrorExt
from ...helper import removeprefix
from .._classdef import Containers, TypeMessage, VirtualImage, VoteInfo
from .._classdef.contents import (
_IMAGEHASH_EXP,
Expand Down Expand Up @@ -471,7 +470,7 @@ def from_tbdata(data_proto: TypeMessage) -> Comment_p:
contents.texts = contents.texts[2:]
if contents.texts:
first_text_frag = contents.texts[0]
first_text_frag.text = removeprefix(first_text_frag.text, ' :')
first_text_frag.text = first_text_frag.text.removeprefix(' :')

contents = contents

Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_rank_users/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping

import bs4

Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_recom_status/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping

from ...exception import TbErrorExt

Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_recovers/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import dataclasses as dcs
from collections.abc import Mapping
from functools import cached_property
from typing import Mapping

from ...exception import TbErrorExt
from .._classdef import Containers
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_self_follow_forums/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping

from ...exception import TbErrorExt
from .._classdef import Containers
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_selfinfo_initNickname/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import dataclasses as dcs
from collections.abc import Mapping
from functools import cached_property
from typing import Mapping


@dcs.dataclass
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_selfinfo_moindex/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import dataclasses as dcs
from collections.abc import Mapping
from functools import cached_property
from typing import Mapping

from ...enums import Gender

Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_statistics/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Sequence
from collections.abc import Sequence


@dcs.dataclass
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_uinfo_getUserInfo_web/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import dataclasses as dcs
from collections.abc import Mapping
from functools import cached_property
from typing import Mapping

from ...exception import TbErrorExt

Expand Down
5 changes: 2 additions & 3 deletions aiotieba/api/get_uinfo_panel/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from __future__ import annotations

import dataclasses as dcs
from collections.abc import Mapping
from functools import cached_property
from typing import Mapping

from ...enums import Gender
from ...exception import TbErrorExt
from ...helper import removesuffix


def _tbnum2int(tb_num: str) -> int:
if isinstance(tb_num, str):
return int(float(removesuffix(tb_num, '万')) * 1e4)
return int(float(tb_num.removesuffix('万')) * 1e4)
else:
return tb_num

Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_uinfo_user_json/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping

from ...exception import TbErrorExt

Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_unblock_appeals/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping

from ...exception import TbErrorExt
from .._classdef import Containers
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/login/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping


@dcs.dataclass
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/search_exact/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import dataclasses as dcs
from typing import Mapping
from collections.abc import Mapping

from ...exception import TbErrorExt
from .._classdef import Containers
Expand Down
9 changes: 5 additions & 4 deletions aiotieba/core/account.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

import random

from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC

from ..helper import randbytes_nosec
from ..helper.crypto import c3_aid, cuid_galaxy2


Expand Down Expand Up @@ -180,7 +181,7 @@ def android_id(self) -> str:
"""

if self._android_id is None:
self._android_id = randbytes_nosec(8).hex()
self._android_id = random.randbytes(8).hex()
return self._android_id

@android_id.setter
Expand Down Expand Up @@ -380,7 +381,7 @@ def aes_ecb_sec_key(self) -> bytes:
"""

if self._aes_ecb_sec_key is None:
self._aes_ecb_sec_key = randbytes_nosec(31)
self._aes_ecb_sec_key = random.randbytes(31)
return self._aes_ecb_sec_key

@aes_ecb_sec_key.setter
Expand Down Expand Up @@ -417,7 +418,7 @@ def aes_cbc_sec_key(self) -> bytes:
"""

if self._aes_cbc_sec_key is None:
self._aes_cbc_sec_key = randbytes_nosec(16)
self._aes_cbc_sec_key = random.randbytes(16)
return self._aes_cbc_sec_key

@aes_ecb_sec_key.setter
Expand Down
8 changes: 5 additions & 3 deletions aiotieba/core/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import binascii
import dataclasses as dcs
import gzip
import random
import time
import weakref
from typing import Awaitable, Callable
from collections.abc import Awaitable
from typing import Callable

import aiohttp
import yarl
Expand All @@ -15,7 +17,7 @@

from ..enums import WsStatus
from ..exception import HTTPStatusError
from ..helper import randbytes_nosec, timeout
from ..helper import timeout
from .account import Account
from .net import NetCore

Expand Down Expand Up @@ -306,7 +308,7 @@ async def connect(self) -> None:
from aiohttp import hdrs

ws_url = yarl.URL.build(scheme="ws", host="im.tieba.baidu.com", port=8000)
sec_key_bytes = binascii.b2a_base64(randbytes_nosec(16), newline=False)
sec_key_bytes = binascii.b2a_base64(random.randbytes(16), newline=False)
headers = {
hdrs.UPGRADE: "websocket",
hdrs.CONNECTION: "upgrade",
Expand Down
3 changes: 0 additions & 3 deletions aiotieba/helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
jsonlib,
pack_json,
parse_json,
randbytes_nosec,
removeprefix,
removesuffix,
timeout,
)
Loading

0 comments on commit e9ee6a2

Please sign in to comment.