def copy(self, *remotepaths: str): """ Copy sources to destination sources, dest = remotepaths[:-1], remotepaths[-1] `dest` must be a directory """ assert len(remotepaths) > 1 and all( [p.startswith("/") for p in remotepaths]), "`sources`, `dest` must be absolute paths" sources, dest = remotepaths[:-1], remotepaths[-1] if self.is_file(dest): raise BaiduPCSError( "The remote `dest` is a file. It must be a directory.") if not self.is_dir(dest): self.makedir(dest) _sources = (Path(s) for s in sources) _dest = Path(dest) param = [ _from_to(s.as_posix(), (_dest / s.name).as_posix()) for s in _sources ] return self.file_operate("copy", param)
def _request( self, method: Method, url: str, params: Optional[Dict[str, str]] = {}, headers: Optional[Dict[str, str]] = None, data: Union[str, bytes, Dict[str, str], Any] = None, files: Optional[Dict[str, Any]] = None, **kwargs, ) -> requests.Response: if params is not None: app_id = self._app_id(url) params["app_id"] = app_id if not headers: headers = self._headers(url) if isinstance(data, (MultipartEncoder, MultipartEncoderMonitor)): assert headers headers["Content-Type"] = data.content_type try: resp = self._session.request( method.value, url, params=params, headers=headers, data=data, files=files, **kwargs, ) return resp except Exception as err: raise BaiduPCSError("BaiduPCS._request", cause=err)