from __future__ import annotations from typing import TYPE_CHECKING, Any, override from ..FileContext import FileContext as Base if TYPE_CHECKING: from ..base import Result from ..ExecContext import ExecContext from ..Uri import Uri from .Local import Local class Curl(Base): def __init__( self, uri: str | Uri, *args: Any, ec: ExecContext | None = None, **kwargs: Any ) -> None: def __local() -> Local: from .Local import Local return Local(interactive = False, *args, **kwargs) # MyPy complains for reasons I don't understand: # E: "__init__" of "FileContext" gets multiple values for keyword # argument # "uri" [misc] super().__init__(uri = uri, *args, **kwargs) # type: ignore[misc] self.__ec = ec if ec else __local() @override async def _get( self, path: str, wd: str | None, throw: bool, verbose: bool | None, title: str ) -> Result: cmd = ['curl'] if verbose is None: verbose = self.__ec.verbose_default if not verbose: cmd.append('-s') cmd.append('--follow') if wd is not None: path = wd + '/' + path if not len(path) or path[0] != '/': path = '/' + path cmd.append(self.uri.to_string + self._chroot(path)) return await self.__ec.run(cmd, throw = throw, verbose = verbose)