Skip to content

Commit

Permalink
Defer imports
Browse files Browse the repository at this point in the history
  • Loading branch information
layday committed May 13, 2024
1 parent b7d78f4 commit 4b3738e
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/instawow/_sources/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from .._utils.web import as_plain_text_data_url, extract_byte_range_offset
from ..catalogue.cataloguer import AddonKey, CatalogueEntry
from ..definitions import ChangelogFormat, Defn, SourceMetadata, Strategy
from ..matchers.addon_toc import TocReader
from ..pkg_archives import find_archive_addon_tocs
from ..resolvers import BaseResolver, HeadersIntent, PkgCandidate
from ..wow_installations import Flavour, FlavourVersionRange

Expand Down Expand Up @@ -126,6 +124,15 @@ async def __find_match_from_zip_contents(
assets: list[_GithubRelease_Asset],
desired_flavours: tuple[Flavour, ...] | None,
):
import zipfile
from io import BytesIO

from aiohttp import hdrs

from ..matchers import NORMALISED_FLAVOUR_TOC_SUFFIXES
from ..matchers.addon_toc import TocReader
from ..pkg_archives import find_archive_addon_tocs

candidates = [
a
for a in assets
Expand All @@ -138,13 +145,6 @@ async def __find_match_from_zip_contents(
if not candidates:
return None

import zipfile
from io import BytesIO

from aiohttp import hdrs

from ..matchers import NORMALISED_FLAVOUR_TOC_SUFFIXES

download_headers = await self.make_request_headers(HeadersIntent.Download)

if desired_flavours is None:
Expand Down Expand Up @@ -181,10 +181,7 @@ async def __find_match_from_zip_contents(
async with shared_ctx.web_client.get(
download_url,
expire_after=http.CACHE_INDEFINITELY,
headers={
**download_headers,
hdrs.RANGE: f'bytes={directory_offset}',
},
headers=download_headers | {hdrs.RANGE: f'bytes={directory_offset}'},
) as directory_range_response:
if not directory_range_response.ok:
# File size under 25 KB.
Expand Down Expand Up @@ -271,10 +268,8 @@ async def __find_match_from_zip_contents(
async with shared_ctx.web_client.get(
download_url,
expire_after=http.CACHE_INDEFINITELY,
headers={
**download_headers,
hdrs.RANGE: f'bytes={main_toc_file_offset}-{following_file_offset}',
},
headers=download_headers
| {hdrs.RANGE: f'bytes={main_toc_file_offset}-{following_file_offset}'},
raise_for_status=True,
) as toc_file_range_response:
addon_zip_stream.seek(main_toc_file_offset)
Expand Down

0 comments on commit 4b3738e

Please sign in to comment.