diff options
author | Nejc Habjan <nejc.habjan@siemens.com> | 2023-02-12 12:30:29 +0100 |
---|---|---|
committer | Nejc Habjan <nejc.habjan@siemens.com> | 2023-03-12 09:39:54 +0100 |
commit | ab089fbf04d8946a4748723dfd3029a943a43b2f (patch) | |
tree | 26a7d0c534abfbeffbe54808ffa3e755db85479e /gitlab/utils.py | |
parent | 07d03dc959128e05d21e8dfd79aa8e916ab5b150 (diff) | |
download | gitlab-refactor/response-content-backend.tar.gz |
refactor: move response_content into backend coderefactor/response-content-backend
Diffstat (limited to 'gitlab/utils.py')
-rw-r--r-- | gitlab/utils.py | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/gitlab/utils.py b/gitlab/utils.py index 9317535..3d40606 100644 --- a/gitlab/utils.py +++ b/gitlab/utils.py @@ -2,39 +2,20 @@ import pathlib import traceback import urllib.parse import warnings -from typing import Any, Callable, Dict, Iterator, Optional, Tuple, Type, Union +from typing import Any, Dict, Iterator, Optional, Tuple, Type, Union -import requests - -from gitlab import types - - -class _StdoutStream: - def __call__(self, chunk: Any) -> None: - print(chunk) +from gitlab import _backends, types def response_content( - response: requests.Response, - streamed: bool, - action: Optional[Callable[[bytes], None]], - chunk_size: int, - *, - iterator: bool, + *args: Any, **kwargs: Any ) -> Optional[Union[bytes, Iterator[Any]]]: - if iterator: - return response.iter_content(chunk_size=chunk_size) - - if streamed is False: - return response.content - - if action is None: - action = _StdoutStream() - - for chunk in response.iter_content(chunk_size=chunk_size): - if chunk: - action(chunk) - return None + warn( + "`utils.response_content()` is deprecated and will be removed in a future" + "version.\nUse the current backend's `response_content()` method instead.", + category=DeprecationWarning, + ) + return _backends.DefaultBackend.response_content(*args, **kwargs) def _transform_types( |