Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@request_method_decorator
def _delete(resource, *args, **kwargs):
"""Generate a DELETE request on a resource."""
return HttpRequest(resource._links['delete']['href'], method='DELETE',
query_args=kwargs)
@request_method_decorator
def get_next(self, **kwargs):
if 'next' not in self._links:
raise StopIteration()
return HttpRequest(self._links['next']['href'], query_args=kwargs)
@request_method_decorator
def upload_screenshot(self, filename, content, caption=None, **kwargs):
"""Uploads a new screenshot.
The content argument should contain the body of the screenshot
to be uploaded, in string format.
"""
request = HttpRequest(self._url, method=b'POST', query_args=kwargs)
request.add_file('path', filename, content)
if caption:
request.add_field('caption', caption)
return request
@request_method_decorator
def get_patch(self, **kwargs):
"""Retrieves the actual diff file contents."""
request = HttpRequest(self._url, query_args=kwargs)
request.headers['Accept'] = 'text/x-patch'
return request
@request_method_decorator
def _update(resource, data=None, query_args={}, *args, **kwargs):
"""Generate a PUT request on a resource.
Unlike other methods, any additional query args must be passed in
using the 'query_args' parameter, since kwargs is used for the
fields which will be sent.
Review Board expects ``extra_data`` fields to be sent as
``extra_data.field_name``, which cannot be passed as a raw literal in
Python. Fields like this would have to be added to a dict and splatted.
However, this function also accepts keyword arguments of the form
``extra_data__field_name``, which will be rewritten to fields of the form
``extra_data.field_name``.
"""
request = HttpRequest(resource._links['update']['href'], method='PUT',
query_args=query_args)
@request_method_decorator
def upload_diff(self, diff, parent_diff=None, base_dir=None,
base_commit_id=None, **kwargs):
"""Upload a diff to the resource.
The diff and parent_diff arguments should be strings containing the
diff output.
"""
return self.prepare_upload_diff_request(
diff,
parent_diff=parent_diff,
base_dir=base_dir,
base_commit_id=base_commit_id,
**kwargs)
@request_method_decorator
def validate_diff(self, repository, diff, parent_diff=None, base_dir=None,
base_commit_id=None, **kwargs):
"""Validate a diff."""
request = self.prepare_upload_diff_request(
diff,
parent_diff=parent_diff,
base_dir=base_dir,
base_commit_id=base_commit_id,
**kwargs)
request.add_field('repository', repository)
if base_commit_id:
request.add_field('base_commit_id', base_commit_id)
return request
@request_method_decorator
def get_prev(self, **kwargs):
if 'prev' not in self._links:
raise StopIteration()
return HttpRequest(self._links['prev']['href'], query_args=kwargs)
@request_method_decorator
def get_self(self, **kwargs):
"""Generate an GET request for the resource list.
This will return an HttpRequest to retrieve the list resource
which this resource is a count for. Any query arguments used
in the request for the count will still be present, only the
'counts-only' argument will be removed
"""
# TODO: Fix this. It is generating a new request
# for a URL with 'counts-only' set to False, but
# RB treats the argument being set to any value
# as true.
kwargs.update({'counts_only': False})
return HttpRequest(self._url, query_args=kwargs)
@request_method_decorator
def _get_url(self, url, **kwargs):
return HttpRequest(url, query_args=kwargs)