Skip to content

Commit 5a97cdb

Browse files
committed
Revert "feat(downloads): allow streaming downloads access to response iterator"
This reverts commit 4f9807f.
1 parent 7e5f4ee commit 5a97cdb

File tree

10 files changed

+38
-106
lines changed

10 files changed

+38
-106
lines changed

gitlab/mixins.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
Any,
2121
Callable,
2222
Dict,
23-
Iterator,
2423
List,
25-
Literal,
2624
Optional,
2725
Tuple,
2826
Type,
@@ -659,10 +657,10 @@ class DownloadMixin(_RestObjectBase):
659657
def download(
660658
self,
661659
streamed: bool = False,
662-
action: Optional[Union[Callable, Literal["iterator"]]] = None,
660+
action: Optional[Callable] = None,
663661
chunk_size: int = 1024,
664662
**kwargs: Any,
665-
) -> Optional[Union[bytes, Iterator[Any]]]:
663+
) -> Optional[bytes]:
666664
"""Download the archive of a resource export.
667665
668666
Args:

gitlab/utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import traceback
2020
import urllib.parse
2121
import warnings
22-
from typing import Any, Callable, Dict, Iterator, Literal, Optional, Type, Union
22+
from typing import Any, Callable, Dict, Optional, Type, Union
2323

2424
import requests
2525

@@ -32,18 +32,15 @@ def __call__(self, chunk: Any) -> None:
3232
def response_content(
3333
response: requests.Response,
3434
streamed: bool,
35-
action: Optional[Union[Callable, Literal["iterator"]]],
35+
action: Optional[Callable],
3636
chunk_size: int,
37-
) -> Optional[Union[bytes, Iterator[Any]]]:
37+
) -> Optional[bytes]:
3838
if streamed is False:
3939
return response.content
4040

4141
if action is None:
4242
action = _StdoutStream()
4343

44-
if action == "iterator":
45-
return response.iter_content(chunk_size=chunk_size)
46-
4744
for chunk in response.iter_content(chunk_size=chunk_size):
4845
if chunk:
4946
action(chunk)

gitlab/v4/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import argparse
2020
import operator
2121
import sys
22-
from typing import Any, Dict, Iterator, List, Optional, Type, TYPE_CHECKING, Union
22+
from typing import Any, Dict, List, Optional, Type, TYPE_CHECKING, Union
2323

2424
import gitlab
2525
import gitlab.base
@@ -123,7 +123,6 @@ def do_project_export_download(self) -> None:
123123
data = export_status.download()
124124
if TYPE_CHECKING:
125125
assert data is not None
126-
assert not isinstance(data, Iterator)
127126
sys.stdout.buffer.write(data)
128127

129128
except Exception as e:

gitlab/v4/objects/artifacts.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
GitLab API:
33
https://docs.gitlab.com/ee/api/job_artifacts.html
44
"""
5-
from typing import Any, Callable, Iterator, Literal, Optional, TYPE_CHECKING, Union
5+
from typing import Any, Callable, Optional, TYPE_CHECKING
66

77
import requests
88

@@ -32,7 +32,7 @@ def __call__(
3232
self,
3333
*args: Any,
3434
**kwargs: Any,
35-
) -> Optional[Union[bytes, Iterator[Any]]]:
35+
) -> Optional[bytes]:
3636
utils.warn(
3737
message=(
3838
"The project.artifacts() method is deprecated and will be removed in a "
@@ -71,10 +71,10 @@ def download(
7171
ref_name: str,
7272
job: str,
7373
streamed: bool = False,
74-
action: Optional[Union[Callable, Literal["iterator"]]] = None,
74+
action: Optional[Callable] = None,
7575
chunk_size: int = 1024,
7676
**kwargs: Any,
77-
) -> Optional[Union[bytes, Iterator[Any]]]:
77+
) -> Optional[bytes]:
7878
"""Get the job artifacts archive from a specific tag or branch.
7979
8080
Args:
@@ -86,8 +86,7 @@ def download(
8686
`chunk_size` and each chunk is passed to `action` for
8787
treatment
8888
action: Callable responsible of dealing with chunk of
89-
data. May also be the string "iterator" to directly return
90-
the response iterator
89+
data
9190
chunk_size: Size of each chunk
9291
**kwargs: Extra options to send to the server (e.g. sudo)
9392
@@ -116,10 +115,10 @@ def raw(
116115
artifact_path: str,
117116
job: str,
118117
streamed: bool = False,
119-
action: Optional[Union[Callable, Literal["iterator"]]] = None,
118+
action: Optional[Callable] = None,
120119
chunk_size: int = 1024,
121120
**kwargs: Any,
122-
) -> Optional[Union[bytes, Iterator[Any]]]:
121+
) -> Optional[bytes]:
123122
"""Download a single artifact file from a specific tag or branch from
124123
within the job's artifacts archive.
125124

gitlab/v4/objects/files.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
import base64
2-
from typing import (
3-
Any,
4-
Callable,
5-
cast,
6-
Dict,
7-
Iterator,
8-
List,
9-
Literal,
10-
Optional,
11-
TYPE_CHECKING,
12-
Union,
13-
)
2+
from typing import Any, Callable, cast, Dict, List, Optional, TYPE_CHECKING
143

154
import requests
165

@@ -228,10 +217,10 @@ def raw(
228217
file_path: str,
229218
ref: str,
230219
streamed: bool = False,
231-
action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None,
220+
action: Optional[Callable[..., Any]] = None,
232221
chunk_size: int = 1024,
233222
**kwargs: Any,
234-
) -> Optional[Union[bytes, Iterator[Any]]]:
223+
) -> Optional[bytes]:
235224
"""Return the content of a file for a commit.
236225
237226
Args:

gitlab/v4/objects/jobs.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
from typing import (
2-
Any,
3-
Callable,
4-
cast,
5-
Dict,
6-
Iterator,
7-
Literal,
8-
Optional,
9-
TYPE_CHECKING,
10-
Union,
11-
)
1+
from typing import Any, Callable, cast, Dict, Optional, TYPE_CHECKING, Union
122

133
import requests
144

@@ -126,10 +116,10 @@ def delete_artifacts(self, **kwargs: Any) -> None:
126116
def artifacts(
127117
self,
128118
streamed: bool = False,
129-
action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None,
119+
action: Optional[Callable[..., Any]] = None,
130120
chunk_size: int = 1024,
131121
**kwargs: Any,
132-
) -> Optional[Union[bytes, Iterator[Any]]]:
122+
) -> Optional[bytes]:
133123
"""Get the job artifacts.
134124
135125
Args:
@@ -162,10 +152,10 @@ def artifact(
162152
self,
163153
path: str,
164154
streamed: bool = False,
165-
action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None,
155+
action: Optional[Callable[..., Any]] = None,
166156
chunk_size: int = 1024,
167157
**kwargs: Any,
168-
) -> Optional[Union[bytes, Iterator[Any]]]:
158+
) -> Optional[bytes]:
169159
"""Get a single artifact file from within the job's artifacts archive.
170160
171161
Args:

gitlab/v4/objects/packages.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@
55
"""
66

77
from pathlib import Path
8-
from typing import (
9-
Any,
10-
Callable,
11-
cast,
12-
Iterator,
13-
Literal,
14-
Optional,
15-
TYPE_CHECKING,
16-
Union,
17-
)
8+
from typing import Any, Callable, cast, Optional, TYPE_CHECKING, Union
189

1910
import requests
2011

@@ -112,10 +103,10 @@ def download(
112103
package_version: str,
113104
file_name: str,
114105
streamed: bool = False,
115-
action: Optional[Union[Callable, Literal["iterator"]]] = None,
106+
action: Optional[Callable] = None,
116107
chunk_size: int = 1024,
117108
**kwargs: Any,
118-
) -> Optional[Union[bytes, Iterator[Any]]]:
109+
) -> Optional[bytes]:
119110
"""Download a generic package.
120111
121112
Args:

gitlab/v4/objects/projects.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
from typing import (
2-
Any,
3-
Callable,
4-
cast,
5-
Dict,
6-
Iterator,
7-
List,
8-
Literal,
9-
Optional,
10-
TYPE_CHECKING,
11-
Union,
12-
)
1+
from typing import Any, Callable, cast, Dict, List, Optional, TYPE_CHECKING, Union
132

143
import requests
154

@@ -468,10 +457,10 @@ def snapshot(
468457
self,
469458
wiki: bool = False,
470459
streamed: bool = False,
471-
action: Optional[Union[Callable, Literal["iterator"]]] = None,
460+
action: Optional[Callable] = None,
472461
chunk_size: int = 1024,
473462
**kwargs: Any,
474-
) -> Optional[Union[bytes, Iterator[Any]]]:
463+
) -> Optional[bytes]:
475464
"""Return a snapshot of the repository.
476465
477466
Args:
@@ -573,7 +562,7 @@ def artifact(
573562
self,
574563
*args: Any,
575564
**kwargs: Any,
576-
) -> Optional[Union[bytes, Iterator[Any]]]:
565+
) -> Optional[bytes]:
577566
utils.warn(
578567
message=(
579568
"The project.artifact() method is deprecated and will be "

gitlab/v4/objects/repositories.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,7 @@
33
44
Currently this module only contains repository-related methods for projects.
55
"""
6-
from typing import (
7-
Any,
8-
Callable,
9-
Dict,
10-
Iterator,
11-
List,
12-
Literal,
13-
Optional,
14-
TYPE_CHECKING,
15-
Union,
16-
)
6+
from typing import Any, Callable, Dict, List, Optional, TYPE_CHECKING, Union
177

188
import requests
199

@@ -117,10 +107,10 @@ def repository_raw_blob(
117107
self,
118108
sha: str,
119109
streamed: bool = False,
120-
action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None,
110+
action: Optional[Callable[..., Any]] = None,
121111
chunk_size: int = 1024,
122112
**kwargs: Any,
123-
) -> Optional[Union[bytes, Iterator[Any]]]:
113+
) -> Optional[bytes]:
124114
"""Return the raw file contents for a blob.
125115
126116
Args:
@@ -202,11 +192,11 @@ def repository_archive(
202192
self,
203193
sha: str = None,
204194
streamed: bool = False,
205-
action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None,
195+
action: Optional[Callable[..., Any]] = None,
206196
chunk_size: int = 1024,
207197
format: Optional[str] = None,
208198
**kwargs: Any,
209-
) -> Optional[Union[bytes, Iterator[Any]]]:
199+
) -> Optional[bytes]:
210200
"""Return an archive of the repository.
211201
212202
Args:

gitlab/v4/objects/snippets.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
from typing import (
2-
Any,
3-
Callable,
4-
cast,
5-
Iterator,
6-
List,
7-
Literal,
8-
Optional,
9-
TYPE_CHECKING,
10-
Union,
11-
)
1+
from typing import Any, Callable, cast, List, Optional, TYPE_CHECKING, Union
122

133
import requests
144

@@ -38,10 +28,10 @@ class Snippet(UserAgentDetailMixin, SaveMixin, ObjectDeleteMixin, RESTObject):
3828
def content(
3929
self,
4030
streamed: bool = False,
41-
action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None,
31+
action: Optional[Callable[..., Any]] = None,
4232
chunk_size: int = 1024,
4333
**kwargs: Any,
44-
) -> Optional[Union[bytes, Iterator[Any]]]:
34+
) -> Optional[bytes]:
4535
"""Return the content of a snippet.
4636
4737
Args:
@@ -112,10 +102,10 @@ class ProjectSnippet(UserAgentDetailMixin, SaveMixin, ObjectDeleteMixin, RESTObj
112102
def content(
113103
self,
114104
streamed: bool = False,
115-
action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None,
105+
action: Optional[Callable[..., Any]] = None,
116106
chunk_size: int = 1024,
117107
**kwargs: Any,
118-
) -> Optional[Union[bytes, Iterator[Any]]]:
108+
) -> Optional[bytes]:
119109
"""Return the content of a snippet.
120110
121111
Args:

0 commit comments

Comments
 (0)