| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5370979 commit 4f9807f
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,9 @@ | |||
| 20 | 20 | Any, | |
| 21 | 21 | Callable, | |
| 22 | 22 | Dict, | |
| 23 | + Iterator, | ||
| 23 | 24 | List, | |
| 25 | + Literal, | ||
| 24 | 26 | Optional, | |
| 25 | 27 | Tuple, | |
| 26 | 28 | Type, | |
@@ -657,10 +659,10 @@ class DownloadMixin(_RestObjectBase): | |||
| 657 | 659 | def download( | |
| 658 | 660 | self, | |
| 659 | 661 | streamed: bool = False, | |
| 660 | - action: Optional[Callable] = None, | ||
| 662 | + action: Optional[Union[Callable, Literal["iterator"]]] = None, | ||
| 661 | 663 | chunk_size: int = 1024, | |
| 662 | 664 | **kwargs: Any, | |
| 663 | - ) -> Optional[bytes]: | ||
| 665 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 664 | 666 | """Download the archive of a resource export. | |
| 665 | 667 | ||
| 666 | 668 | Args: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ | |||
| 19 | 19 | import traceback | |
| 20 | 20 | import urllib.parse | |
| 21 | 21 | import warnings | |
| 22 | - from typing import Any, Callable, Dict, Optional, Type, Union | ||
| 22 | + from typing import Any, Callable, Dict, Iterator, Literal, Optional, Type, Union | ||
| 23 | 23 | ||
| 24 | 24 | import requests | |
| 25 | 25 | ||
@@ -32,15 +32,18 @@ def __call__(self, chunk: Any) -> None: | |||
| 32 | 32 | def response_content( | |
| 33 | 33 | response: requests.Response, | |
| 34 | 34 | streamed: bool, | |
| 35 | - action: Optional[Callable], | ||
| 35 | + action: Optional[Union[Callable, Literal["iterator"]]], | ||
| 36 | 36 | chunk_size: int, | |
| 37 | - ) -> Optional[bytes]: | ||
| 37 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 38 | 38 | if streamed is False: | |
| 39 | 39 | return response.content | |
| 40 | 40 | ||
| 41 | 41 | if action is None: | |
| 42 | 42 | action = _StdoutStream() | |
| 43 | 43 | ||
| 44 | + if action == "iterator": | ||
| 45 | + return response.iter_content(chunk_size=chunk_size) | ||
| 46 | + | ||
| 44 | 47 | for chunk in response.iter_content(chunk_size=chunk_size): | |
| 45 | 48 | if chunk: | |
| 46 | 49 | action(chunk) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ | |||
| 19 | 19 | import argparse | |
| 20 | 20 | import operator | |
| 21 | 21 | import sys | |
| 22 | - from typing import Any, Dict, List, Optional, Type, TYPE_CHECKING, Union | ||
| 22 | + from typing import Any, Dict, Iterator, List, Optional, Type, TYPE_CHECKING, Union | ||
| 23 | 23 | ||
| 24 | 24 | import gitlab | |
| 25 | 25 | import gitlab.base | |
@@ -123,6 +123,7 @@ def do_project_export_download(self) -> None: | |||
| 123 | 123 | data = export_status.download() | |
| 124 | 124 | if TYPE_CHECKING: | |
| 125 | 125 | assert data is not None | |
| 126 | + assert not isinstance(data, Iterator) | ||
| 126 | 127 | sys.stdout.buffer.write(data) | |
| 127 | 128 | ||
| 128 | 129 | except Exception as e: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | GitLab API: | |
| 3 | 3 | https://docs.gitlab.com/ee/api/job_artifacts.html | |
| 4 | 4 | """ | |
| 5 | - from typing import Any, Callable, Optional, TYPE_CHECKING | ||
| 5 | + from typing import Any, Callable, Iterator, Literal, Optional, TYPE_CHECKING, Union | ||
| 6 | 6 | ||
| 7 | 7 | import requests | |
| 8 | 8 | ||
@@ -32,7 +32,7 @@ def __call__( | |||
| 32 | 32 | self, | |
| 33 | 33 | *args: Any, | |
| 34 | 34 | **kwargs: Any, | |
| 35 | - ) -> Optional[bytes]: | ||
| 35 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 36 | 36 | utils.warn( | |
| 37 | 37 | message=( | |
| 38 | 38 | "The project.artifacts() method is deprecated and will be removed in a " | |
@@ -71,10 +71,10 @@ def download( | |||
| 71 | 71 | ref_name: str, | |
| 72 | 72 | job: str, | |
| 73 | 73 | streamed: bool = False, | |
| 74 | - action: Optional[Callable] = None, | ||
| 74 | + action: Optional[Union[Callable, Literal["iterator"]]] = None, | ||
| 75 | 75 | chunk_size: int = 1024, | |
| 76 | 76 | **kwargs: Any, | |
| 77 | - ) -> Optional[bytes]: | ||
| 77 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 78 | 78 | """Get the job artifacts archive from a specific tag or branch. | |
| 79 | 79 | ||
| 80 | 80 | Args: | |
@@ -86,7 +86,8 @@ def download( | |||
| 86 | 86 | `chunk_size` and each chunk is passed to `action` for | |
| 87 | 87 | treatment | |
| 88 | 88 | action: Callable responsible of dealing with chunk of | |
| 89 | - data | ||
| 89 | + data. May also be the string "iterator" to directly return | ||
| 90 | + the response iterator | ||
| 90 | 91 | chunk_size: Size of each chunk | |
| 91 | 92 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 92 | 93 | ||
@@ -115,10 +116,10 @@ def raw( | |||
| 115 | 116 | artifact_path: str, | |
| 116 | 117 | job: str, | |
| 117 | 118 | streamed: bool = False, | |
| 118 | - action: Optional[Callable] = None, | ||
| 119 | + action: Optional[Union[Callable, Literal["iterator"]]] = None, | ||
| 119 | 120 | chunk_size: int = 1024, | |
| 120 | 121 | **kwargs: Any, | |
| 121 | - ) -> Optional[bytes]: | ||
| 122 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 122 | 123 | """Download a single artifact file from a specific tag or branch from | |
| 123 | 124 | within the job's artifacts archive. | |
| 124 | 125 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,16 @@ | |||
| 1 | 1 | import base64 | |
| 2 | - from typing import Any, Callable, cast, Dict, List, Optional, TYPE_CHECKING | ||
| 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 | + ) | ||
| 3 | 14 | ||
| 4 | 15 | import requests | |
| 5 | 16 | ||
@@ -217,10 +228,10 @@ def raw( | |||
| 217 | 228 | file_path: str, | |
| 218 | 229 | ref: str, | |
| 219 | 230 | streamed: bool = False, | |
| 220 | - action: Optional[Callable[..., Any]] = None, | ||
| 231 | + action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None, | ||
| 221 | 232 | chunk_size: int = 1024, | |
| 222 | 233 | **kwargs: Any, | |
| 223 | - ) -> Optional[bytes]: | ||
| 234 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 224 | 235 | """Return the content of a file for a commit. | |
| 225 | 236 | ||
| 226 | 237 | Args: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,14 @@ | |||
| 1 | - from typing import Any, Callable, cast, Dict, Optional, TYPE_CHECKING, Union | ||
| 1 | + from typing import ( | ||
| 2 | + Any, | ||
| 3 | + Callable, | ||
| 4 | + cast, | ||
| 5 | + Dict, | ||
| 6 | + Iterator, | ||
| 7 | + Literal, | ||
| 8 | + Optional, | ||
| 9 | + TYPE_CHECKING, | ||
| 10 | + Union, | ||
| 11 | + ) | ||
| 2 | 12 | ||
| 3 | 13 | import requests | |
| 4 | 14 | ||
@@ -116,10 +126,10 @@ def delete_artifacts(self, **kwargs: Any) -> None: | |||
| 116 | 126 | def artifacts( | |
| 117 | 127 | self, | |
| 118 | 128 | streamed: bool = False, | |
| 119 | - action: Optional[Callable[..., Any]] = None, | ||
| 129 | + action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None, | ||
| 120 | 130 | chunk_size: int = 1024, | |
| 121 | 131 | **kwargs: Any, | |
| 122 | - ) -> Optional[bytes]: | ||
| 132 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 123 | 133 | """Get the job artifacts. | |
| 124 | 134 | ||
| 125 | 135 | Args: | |
@@ -152,10 +162,10 @@ def artifact( | |||
| 152 | 162 | self, | |
| 153 | 163 | path: str, | |
| 154 | 164 | streamed: bool = False, | |
| 155 | - action: Optional[Callable[..., Any]] = None, | ||
| 165 | + action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None, | ||
| 156 | 166 | chunk_size: int = 1024, | |
| 157 | 167 | **kwargs: Any, | |
| 158 | - ) -> Optional[bytes]: | ||
| 168 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 159 | 169 | """Get a single artifact file from within the job's artifacts archive. | |
| 160 | 170 | ||
| 161 | 171 | Args: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,16 @@ | |||
| 5 | 5 | """ | |
| 6 | 6 | ||
| 7 | 7 | from pathlib import Path | |
| 8 | - from typing import Any, Callable, cast, Optional, TYPE_CHECKING, Union | ||
| 8 | + from typing import ( | ||
| 9 | + Any, | ||
| 10 | + Callable, | ||
| 11 | + cast, | ||
| 12 | + Iterator, | ||
| 13 | + Literal, | ||
| 14 | + Optional, | ||
| 15 | + TYPE_CHECKING, | ||
| 16 | + Union, | ||
| 17 | + ) | ||
| 9 | 18 | ||
| 10 | 19 | import requests | |
| 11 | 20 | ||
@@ -103,10 +112,10 @@ def download( | |||
| 103 | 112 | package_version: str, | |
| 104 | 113 | file_name: str, | |
| 105 | 114 | streamed: bool = False, | |
| 106 | - action: Optional[Callable] = None, | ||
| 115 | + action: Optional[Union[Callable, Literal["iterator"]]] = None, | ||
| 107 | 116 | chunk_size: int = 1024, | |
| 108 | 117 | **kwargs: Any, | |
| 109 | - ) -> Optional[bytes]: | ||
| 118 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 110 | 119 | """Download a generic package. | |
| 111 | 120 | ||
| 112 | 121 | Args: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,15 @@ | |||
| 1 | - from typing import Any, Callable, cast, Dict, List, Optional, TYPE_CHECKING, Union | ||
| 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 | + ) | ||
| 2 | 13 | ||
| 3 | 14 | import requests | |
| 4 | 15 | ||
@@ -457,10 +468,10 @@ def snapshot( | |||
| 457 | 468 | self, | |
| 458 | 469 | wiki: bool = False, | |
| 459 | 470 | streamed: bool = False, | |
| 460 | - action: Optional[Callable] = None, | ||
| 471 | + action: Optional[Union[Callable, Literal["iterator"]]] = None, | ||
| 461 | 472 | chunk_size: int = 1024, | |
| 462 | 473 | **kwargs: Any, | |
| 463 | - ) -> Optional[bytes]: | ||
| 474 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 464 | 475 | """Return a snapshot of the repository. | |
| 465 | 476 | ||
| 466 | 477 | Args: | |
@@ -562,7 +573,7 @@ def artifact( | |||
| 562 | 573 | self, | |
| 563 | 574 | *args: Any, | |
| 564 | 575 | **kwargs: Any, | |
| 565 | - ) -> Optional[bytes]: | ||
| 576 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 566 | 577 | utils.warn( | |
| 567 | 578 | message=( | |
| 568 | 579 | "The project.artifact() method is deprecated and will be " | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,17 @@ | |||
| 3 | 3 | ||
| 4 | 4 | Currently this module only contains repository-related methods for projects. | |
| 5 | 5 | """ | |
| 6 | - from typing import Any, Callable, Dict, List, Optional, TYPE_CHECKING, Union | ||
| 6 | + from typing import ( | ||
| 7 | + Any, | ||
| 8 | + Callable, | ||
| 9 | + Dict, | ||
| 10 | + Iterator, | ||
| 11 | + List, | ||
| 12 | + Literal, | ||
| 13 | + Optional, | ||
| 14 | + TYPE_CHECKING, | ||
| 15 | + Union, | ||
| 16 | + ) | ||
| 7 | 17 | ||
| 8 | 18 | import requests | |
| 9 | 19 | ||
@@ -107,10 +117,10 @@ def repository_raw_blob( | |||
| 107 | 117 | self, | |
| 108 | 118 | sha: str, | |
| 109 | 119 | streamed: bool = False, | |
| 110 | - action: Optional[Callable[..., Any]] = None, | ||
| 120 | + action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None, | ||
| 111 | 121 | chunk_size: int = 1024, | |
| 112 | 122 | **kwargs: Any, | |
| 113 | - ) -> Optional[bytes]: | ||
| 123 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 114 | 124 | """Return the raw file contents for a blob. | |
| 115 | 125 | ||
| 116 | 126 | Args: | |
@@ -192,11 +202,11 @@ def repository_archive( | |||
| 192 | 202 | self, | |
| 193 | 203 | sha: str = None, | |
| 194 | 204 | streamed: bool = False, | |
| 195 | - action: Optional[Callable[..., Any]] = None, | ||
| 205 | + action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None, | ||
| 196 | 206 | chunk_size: int = 1024, | |
| 197 | 207 | format: Optional[str] = None, | |
| 198 | 208 | **kwargs: Any, | |
| 199 | - ) -> Optional[bytes]: | ||
| 209 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 200 | 210 | """Return an archive of the repository. | |
| 201 | 211 | ||
| 202 | 212 | Args: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,14 @@ | |||
| 1 | - from typing import Any, Callable, cast, List, Optional, TYPE_CHECKING, Union | ||
| 1 | + from typing import ( | ||
| 2 | + Any, | ||
| 3 | + Callable, | ||
| 4 | + cast, | ||
| 5 | + Iterator, | ||
| 6 | + List, | ||
| 7 | + Literal, | ||
| 8 | + Optional, | ||
| 9 | + TYPE_CHECKING, | ||
| 10 | + Union, | ||
| 11 | + ) | ||
| 2 | 12 | ||
| 3 | 13 | import requests | |
| 4 | 14 | ||
@@ -28,10 +38,10 @@ class Snippet(UserAgentDetailMixin, SaveMixin, ObjectDeleteMixin, RESTObject): | |||
| 28 | 38 | def content( | |
| 29 | 39 | self, | |
| 30 | 40 | streamed: bool = False, | |
| 31 | - action: Optional[Callable[..., Any]] = None, | ||
| 41 | + action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None, | ||
| 32 | 42 | chunk_size: int = 1024, | |
| 33 | 43 | **kwargs: Any, | |
| 34 | - ) -> Optional[bytes]: | ||
| 44 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 35 | 45 | """Return the content of a snippet. | |
| 36 | 46 | ||
| 37 | 47 | Args: | |
@@ -102,10 +112,10 @@ class ProjectSnippet(UserAgentDetailMixin, SaveMixin, ObjectDeleteMixin, RESTObj | |||
| 102 | 112 | def content( | |
| 103 | 113 | self, | |
| 104 | 114 | streamed: bool = False, | |
| 105 | - action: Optional[Callable[..., Any]] = None, | ||
| 115 | + action: Optional[Union[Callable[..., Any], Literal["iterator"]]] = None, | ||
| 106 | 116 | chunk_size: int = 1024, | |
| 107 | 117 | **kwargs: Any, | |
| 108 | - ) -> Optional[bytes]: | ||
| 118 | + ) -> Optional[Union[bytes, Iterator[Any]]]: | ||
| 109 | 119 | """Return the content of a snippet. | |
| 110 | 120 | ||
| 111 | 121 | Args: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments