Skip to content

Commit 37dbc09

Browse files
committed
fix: response content is not async
1 parent 4352f9b commit 37dbc09

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

gitlab/tests/test_gitlab.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import unittest
2424

2525
import httpx
26-
import requests
2726
from httmock import HTTMock # noqa
2827
from httmock import response # noqa
2928
from httmock import urlmatch # noqa

gitlab/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def __call__(self, chunk):
2323
print(chunk)
2424

2525

26-
def response_content(response, streamed, action, chunk_size):
26+
async def response_content(response, streamed, action):
2727
if streamed is False:
2828
return response.content
2929

3030
if action is None:
3131
action = _StdoutStream()
3232

33-
for chunk in response.iter_content(chunk_size=chunk_size):
33+
async for chunk in response.aiter_bytes():
3434
if chunk:
3535
action(chunk)
3636

gitlab/v4/objects.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ async def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
15661566
result = await self.manager.gitlab.http_get(
15671567
path, streamed=streamed, raw=True, **kwargs
15681568
)
1569-
return utils.response_content(result, streamed, action, chunk_size)
1569+
return await utils.response_content(result, streamed, action)
15701570

15711571

15721572
class SnippetManager(CRUDMixin, RESTManager):
@@ -1905,7 +1905,7 @@ async def artifacts(self, streamed=False, action=None, chunk_size=1024, **kwargs
19051905
result = await self.manager.gitlab.http_get(
19061906
path, streamed=streamed, raw=True, **kwargs
19071907
)
1908-
return utils.response_content(result, streamed, action, chunk_size)
1908+
return await utils.response_content(result, streamed, action)
19091909

19101910
@cli.register_custom_action("ProjectJob")
19111911
@exc.on_http_error(exc.GitlabGetError)
@@ -1935,7 +1935,7 @@ async def artifact(
19351935
result = await self.manager.gitlab.http_get(
19361936
path, streamed=streamed, raw=True, **kwargs
19371937
)
1938-
return utils.response_content(result, streamed, action, chunk_size)
1938+
return await utils.response_content(result, streamed, action)
19391939

19401940
@cli.register_custom_action("ProjectJob")
19411941
@exc.on_http_error(exc.GitlabGetError)
@@ -1962,7 +1962,7 @@ async def trace(self, streamed=False, action=None, chunk_size=1024, **kwargs):
19621962
result = await self.manager.gitlab.http_get(
19631963
path, streamed=streamed, raw=True, **kwargs
19641964
)
1965-
return utils.response_content(result, streamed, action, chunk_size)
1965+
return await utils.response_content(result, streamed, action)
19661966

19671967

19681968
class ProjectJobManager(RetrieveMixin, RESTManager):
@@ -3260,14 +3260,14 @@ async def delete(self, name, **kwargs):
32603260
GitlabAuthenticationError: If authentication is not correct
32613261
GitlabDeleteError: If the server cannot perform the request
32623262
"""
3263-
self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs)
3263+
await self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs)
32643264

32653265

32663266
class ProjectFile(SaveMixin, ObjectDeleteMixin, RESTObject):
32673267
_id_attr = "file_path"
32683268
_short_print_attr = "file_path"
32693269

3270-
async def decode(self):
3270+
def decode(self):
32713271
"""Returns the decoded content of the file.
32723272
32733273
Returns:
@@ -3445,10 +3445,10 @@ async def raw(
34453445
file_path = file_path.replace("/", "%2F").replace(".", "%2E")
34463446
path = "%s/%s/raw" % (self.path, file_path)
34473447
query_data = {"ref": ref}
3448-
result = self.gitlab.http_get(
3448+
result = await self.gitlab.http_get(
34493449
path, query_data=query_data, streamed=streamed, raw=True, **kwargs
34503450
)
3451-
return utils.response_content(result, streamed, action, chunk_size)
3451+
return await utils.response_content(result, streamed, action)
34523452

34533453
@cli.register_custom_action("ProjectFileManager", ("file_path", "ref"))
34543454
@exc.on_http_error(exc.GitlabListError)
@@ -3758,7 +3758,7 @@ async def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
37583758
result = await self.manager.gitlab.http_get(
37593759
path, streamed=streamed, raw=True, **kwargs
37603760
)
3761-
return utils.response_content(result, streamed, action, chunk_size)
3761+
return await utils.response_content(result, streamed, action)
37623762

37633763

37643764
class ProjectSnippetManager(CRUDMixin, RESTManager):
@@ -4078,7 +4078,7 @@ async def download(self, streamed=False, action=None, chunk_size=1024, **kwargs)
40784078
result = await self.manager.gitlab.http_get(
40794079
path, streamed=streamed, raw=True, **kwargs
40804080
)
4081-
return utils.response_content(result, streamed, action, chunk_size)
4081+
return await utils.response_content(result, streamed, action)
40824082

40834083

40844084
class ProjectExportManager(GetWithoutIdMixin, CreateMixin, RESTManager):
@@ -4348,7 +4348,7 @@ async def repository_archive(
43484348
result = await self.manager.gitlab.http_get(
43494349
path, query_data=query_data, raw=True, streamed=streamed, **kwargs
43504350
)
4351-
return utils.response_content(result, streamed, action, chunk_size)
4351+
return await utils.response_content(result, streamed, action)
43524352

43534353
@cli.register_custom_action("Project", ("forked_from_id",))
43544354
@exc.on_http_error(exc.GitlabCreateError)
@@ -4628,7 +4628,7 @@ async def snapshot(
46284628
result = await self.manager.gitlab.http_get(
46294629
path, streamed=streamed, raw=True, **kwargs
46304630
)
4631-
return utils.response_content(result, streamed, action, chunk_size)
4631+
return await utils.response_content(result, streamed, action)
46324632

46334633
@cli.register_custom_action("Project", ("scope", "search"))
46344634
@exc.on_http_error(exc.GitlabSearchError)

0 commit comments

Comments
 (0)