summaryrefslogtreecommitdiff
path: root/gitlab/objects.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2016-07-17 19:13:10 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2016-07-17 19:13:10 +0200
commit832ed9f4c23ba3cb4fba68f1083dbabfa9fe32a7 (patch)
tree4c889fef2e726c1c1ee40cb231fc2a50393bdcb5 /gitlab/objects.py
parent3198eadb748593de5ac803bc49926300c2849a4f (diff)
downloadgitlab-832ed9f4c23ba3cb4fba68f1083dbabfa9fe32a7.tar.gz
Replace Snippet.Content() with a new content() method
This new method use the standard lowercase name and implements data streaming.
Diffstat (limited to 'gitlab/objects.py')
-rw-r--r--gitlab/objects.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/gitlab/objects.py b/gitlab/objects.py
index fd622cf..9bfb6ec 100644
--- a/gitlab/objects.py
+++ b/gitlab/objects.py
@@ -1539,11 +1539,9 @@ class ProjectSnippet(GitlabObject):
[('project_id', 'project_id'), ('snippet_id', 'id')])]
def Content(self, **kwargs):
- url = ("/projects/%(project_id)s/snippets/%(snippet_id)s/raw" %
- {'project_id': self.project_id, 'snippet_id': self.id})
- r = self.gitlab._raw_get(url, **kwargs)
- raise_error_from_response(r, GitlabGetError)
- return r.content
+ warnings.warn("`Content` is deprecated, use `content` instead",
+ DeprecationWarning)
+ return self.content()
def Note(self, id=None, **kwargs):
warnings.warn("`Note` is deprecated, use `notes` instead",
@@ -1554,6 +1552,30 @@ class ProjectSnippet(GitlabObject):
snippet_id=self.id,
**kwargs)
+ def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
+ """Return the raw content of a snippet.
+
+ Args:
+ streamed (bool): If True the data will be processed by chunks of
+ `chunk_size` and each chunk is passed to `action` for
+ treatment.
+ action (callable): Callable responsible of dealing with chunk of
+ data.
+ chunk_size (int): Size of each chunk.
+
+ Returns:
+ str: The snippet content
+
+ Raises:
+ GitlabConnectionError: If the server cannot be reached.
+ GitlabGetError: If the server fails to perform the request.
+ """
+ url = ("/projects/%(project_id)s/snippets/%(snippet_id)s/raw" %
+ {'project_id': self.project_id, 'snippet_id': self.id})
+ r = self.gitlab._raw_get(url, **kwargs)
+ raise_error_from_response(r, GitlabGetError)
+ return utils.response_content(r, streamed, action, chunk_size)
+
class ProjectSnippetManager(BaseManager):
obj_cls = ProjectSnippet