# -*- coding: utf-8 -*- from __future__ import annotations from typing import TYPE_CHECKING from ..FileContext import FileContext as Base from ..base import Result if TYPE_CHECKING: from ..ExecContext import ExecContext from ..Uri import Uri class Curl(Base): def __init__(self, uri: str|Uri, *args, ec: ExecContext|None=None, **kwargs) -> None: super().__init__(uri=uri, *args, **kwargs) self.__ec: ExecContext|None = ec if ec is None: from .Local import Local self.__ec = Local(interactive=False, *args, **kwargs) 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.url.to_string + self._chroot(path)) return await self.__ec.run(cmd, throw=throw, verbose=verbose)