From 86f3bf1edb7981ba9defa7819a613a3052cbb67b Mon Sep 17 00:00:00 2001 From: Joao Meyer <1994meyer@gmail.com> Date: Mon, 7 Sep 2020 18:10:51 -0300 Subject: [PATCH 1/3] Added optional arguments --- ipfshttpclient/client/dag.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ipfshttpclient/client/dag.py b/ipfshttpclient/client/dag.py index 715b8d7f..69e8d5c5 100644 --- a/ipfshttpclient/client/dag.py +++ b/ipfshttpclient/client/dag.py @@ -40,7 +40,8 @@ def get(self, cid: base.cid_t, **kwargs: base.CommonArgs): return self._client.request('/dag/get', args, decoder='json', **kwargs) @base.returns_single_item(base.ResponseBase) - def put(self, data: utils.clean_file_t, **kwargs: base.CommonArgs): + def put(self, data: utils.clean_file_t, format: str = 'cbor', + input_enc: str = 'json', **kwargs: base.CommonArgs): """Decodes the given input file as a DAG object and returns their key .. code-block:: python @@ -69,9 +70,11 @@ def put(self, data: utils.clean_file_t, **kwargs: base.CommonArgs): dict Cid with the address of the dag object """ + opts = {'format': format, 'input-enc': input_enc} + kwargs.setdefault('opts', {}).update(opts) body, headers = multipart.stream_files(data, chunk_size=self.chunk_size) return self._client.request('/dag/put', decoder='json', data=body, - headers=headers, **kwargs) + headers=headers, **kwargs) @base.returns_single_item(base.ResponseBase) def resolve(self, cid: base.cid_t, **kwargs: base.CommonArgs): @@ -128,7 +131,7 @@ def imprt(self, data: utils.clean_file_t, **kwargs: base.CommonArgs): """ body, headers = multipart.stream_files(data, chunk_size=self.chunk_size) return self._client.request('/dag/import', decoder='json', data=body, - headers=headers, **kwargs) + headers=headers, **kwargs) def export(self, cid: str, **kwargs: base.CommonArgs): """Exports a DAG into a .car file format From 6f6d6d00dcd090bdba2a60d62214d3ba204bb8be Mon Sep 17 00:00:00 2001 From: Joao Meyer <1994meyer@gmail.com> Date: Mon, 7 Sep 2020 19:59:39 -0300 Subject: [PATCH 2/3] Fixed style check --- ipfshttpclient/client/dag.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ipfshttpclient/client/dag.py b/ipfshttpclient/client/dag.py index 69e8d5c5..00f8a2f5 100644 --- a/ipfshttpclient/client/dag.py +++ b/ipfshttpclient/client/dag.py @@ -41,7 +41,7 @@ def get(self, cid: base.cid_t, **kwargs: base.CommonArgs): @base.returns_single_item(base.ResponseBase) def put(self, data: utils.clean_file_t, format: str = 'cbor', - input_enc: str = 'json', **kwargs: base.CommonArgs): + input_enc: str = 'json', **kwargs: base.CommonArgs): """Decodes the given input file as a DAG object and returns their key .. code-block:: python @@ -74,7 +74,7 @@ def put(self, data: utils.clean_file_t, format: str = 'cbor', kwargs.setdefault('opts', {}).update(opts) body, headers = multipart.stream_files(data, chunk_size=self.chunk_size) return self._client.request('/dag/put', decoder='json', data=body, - headers=headers, **kwargs) + headers=headers, **kwargs) @base.returns_single_item(base.ResponseBase) def resolve(self, cid: base.cid_t, **kwargs: base.CommonArgs): @@ -108,7 +108,7 @@ def imprt(self, data: utils.clean_file_t, **kwargs: base.CommonArgs): .. code-block:: python >>> with open('data.car', 'rb') as file - ... client.dag.imprt(file) + ... client.dag.imprt(file) {'Root': { 'Cid': { '/': 'bafyreidepjmjhvhlvp5eyxqpmyyi7rxwvl7wsglwai3cnvq63komq4tdya' @@ -131,7 +131,7 @@ def imprt(self, data: utils.clean_file_t, **kwargs: base.CommonArgs): """ body, headers = multipart.stream_files(data, chunk_size=self.chunk_size) return self._client.request('/dag/import', decoder='json', data=body, - headers=headers, **kwargs) + headers=headers, **kwargs) def export(self, cid: str, **kwargs: base.CommonArgs): """Exports a DAG into a .car file format From 6bfcece83d11925fb153799976fc3cfea0cf2c30 Mon Sep 17 00:00:00 2001 From: Joao Meyer <1994meyer@gmail.com> Date: Sat, 12 Sep 2020 17:34:15 -0300 Subject: [PATCH 3/3] Added docs for new args I just copied from `ipfs dag put --help` --- ipfshttpclient/client/dag.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ipfshttpclient/client/dag.py b/ipfshttpclient/client/dag.py index 00f8a2f5..97e49281 100644 --- a/ipfshttpclient/client/dag.py +++ b/ipfshttpclient/client/dag.py @@ -64,6 +64,10 @@ def put(self, data: utils.clean_file_t, format: str = 'cbor', ---------- data IO stream object of path to a file containing the data to put + format + Format that the object will be added as. Default: cbor + input_enc + Format that the input object will be. Default: json Returns -------