Skip to content

Commit

Permalink
Bugfix(libs&web): 🐛 修复 py3.9 兼容问题
Browse files Browse the repository at this point in the history
Fixed #508
  • Loading branch information
a76yyyy committed Mar 3, 2024
1 parent ab30c54 commit 742b5d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions libs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def int2ip(addr):
return str(ipaddress.ip_address(addr))


def varbinary2ip(addr: bytes | int | str):
def varbinary2ip(addr: Union[bytes, int, str]):
if isinstance(addr, int):
return int2ip(addr)
if isinstance(addr, str):
Expand Down Expand Up @@ -872,7 +872,7 @@ def switch_mode(mode):
raise Exception(f'Invalid AES mode: {mode}')


def _aes_encrypt(word: str, key: str, mode='CBC', iv: str | bytes | None = None, output_format='base64', padding=True, padding_style='pkcs7', no_packb=True):
def _aes_encrypt(word: str, key: str, mode='CBC', iv: Union[str, bytes, None] = None, output_format='base64', padding=True, padding_style='pkcs7', no_packb=True):
if key is None:
raise Exception('key is required')
if isinstance(iv, str):
Expand All @@ -881,7 +881,7 @@ def _aes_encrypt(word: str, key: str, mode='CBC', iv: str | bytes | None = None,
return aes_encrypt(word.encode("utf-8"), key.encode("utf-8"), mode=mode, iv=iv, output=output_format, padding=padding, padding_style=padding_style, no_packb=no_packb)


def _aes_decrypt(word: str, key: str, mode='CBC', iv: str | bytes | None = None, input_format='base64', padding=True, padding_style='pkcs7', no_packb=True):
def _aes_decrypt(word: str, key: str, mode='CBC', iv: Union[str, bytes, None] = None, input_format='base64', padding=True, padding_style='pkcs7', no_packb=True):
if key is None:
raise Exception('key is required')
if isinstance(iv, str):
Expand Down
4 changes: 2 additions & 2 deletions web/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def permission(self, obj, mode='r'):
return True
return False

def data_received(self, chunk: bytes) -> Awaitable[None] | None:
def data_received(self, chunk: bytes) -> Union[Awaitable[None], None]:
return super().data_received(chunk)


Expand Down Expand Up @@ -152,7 +152,7 @@ def check_permission(self, obj, mode='r'):
def get_compression_options(self):
return {}

def on_message(self, message: str | bytes) -> Awaitable[None] | None:
def on_message(self, message: Union[str, bytes]) -> Union[Awaitable[None], None]:
return super().on_message(message)


Expand Down

0 comments on commit 742b5d1

Please sign in to comment.