2
This commit is contained in:
@ -16,8 +16,11 @@ You should have received a copy of the GNU General Public License along with
|
||||
this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import zipfile
|
||||
from typing import Any, ClassVar, Optional
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, ClassVar
|
||||
|
||||
from typeguard import typechecked
|
||||
|
||||
from .assets import (
|
||||
ArcaeaApkAsset,
|
||||
@ -26,6 +29,9 @@ from .assets import (
|
||||
ArcaeaApkAssetPartnerIcon,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import zipfile
|
||||
|
||||
__all__ = ["ArcaeaApkAssetsProcessor"]
|
||||
|
||||
|
||||
@ -36,14 +42,8 @@ class ArcaeaApkAssetsProcessor:
|
||||
ArcaeaApkAssetList,
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def _check_zipfile(value: Any):
|
||||
if not isinstance(value, zipfile.ZipFile):
|
||||
msg = f"{value!r} is not a ZipFile!"
|
||||
raise TypeError(msg)
|
||||
|
||||
@classmethod
|
||||
def get_asset(cls, asset_zip_filename: str) -> Optional[ArcaeaApkAsset]:
|
||||
def get_asset(cls, asset_zip_filename: str) -> ArcaeaApkAsset | None:
|
||||
asset = None
|
||||
for asset_type in cls.ASSET_TYPES:
|
||||
if asset_ := asset_type.from_zip_filename(asset_zip_filename):
|
||||
@ -57,9 +57,8 @@ class ArcaeaApkAssetsProcessor:
|
||||
return cls.get_asset(asset_zip_filename) is not None
|
||||
|
||||
@classmethod
|
||||
@typechecked
|
||||
def get_assets(cls, zf: zipfile.ZipFile) -> dict[zipfile.ZipInfo, ArcaeaApkAsset]:
|
||||
cls._check_zipfile(zf)
|
||||
|
||||
matches = {}
|
||||
for info in zf.infolist():
|
||||
filename = info.filename
|
||||
|
Reference in New Issue
Block a user