Skip to content

Commit

Permalink
Improve the way strings are handled when writing to files (#118)
Browse files Browse the repository at this point in the history
* check the returned data type (str, bytes)

* revert api_client chnages

* added str response

* fix

* changelog

* gen-doce

* backslash

* code commit

* cr

* cr

* path
  • Loading branch information
MosheEichler authored Sep 21, 2023
1 parent f44bd0d commit 42f5bf8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
[PyPI History][1]
[1]: https://pypi.org/project/demisto-py/#history

## 3.2.12
* Fixed an issue where download command would fail when trying to convert bytes types to string.

## 3.2.11
* Added advanced key authentication support for XSIAM and XSOAR 8+.
* Added support for `DEMISTO_API_KEY_ID` and deprecated old `XSIAM_AUTH_ID`.
Expand Down
8 changes: 6 additions & 2 deletions demisto_client/demisto_api/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,12 @@ def __deserialize_file(self, response):
content_disposition).group(1)
path = os.path.join(os.path.dirname(path), filename)

with open(path, "wb") as f:
f.write(response.data)
if isinstance(response.data, str):
with open(path, 'w') as f:
f.write(response.data)
elif isinstance(response.data, bytes):
with open(path, 'wb') as f:
f.write(response.data)

return path

Expand Down
12 changes: 12 additions & 0 deletions gen-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ from hashlib import sha256\\
\\
NONCE_POSSIBLE_VALUES = string.ascii_letters + string.digits/" demisto_client/demisto_api/api_client.py
# End fix return partial errors
# Fix return str response
select_start_line=`grep 'with open(path, "wb") as f:' demisto_client/demisto_api/api_client.py -n | cut -f1 -d: | tail -1 | tr -d "\\n"`
select_end_line=$((select_start_line + 1))
sed -i "${INPLACE[@]}" -e "${select_start_line},${select_end_line}d" demisto_client/demisto_api/api_client.py
sed -i "${INPLACE[@]}" -e "${select_start_line}i\\
\ \ \ \ \ \ \ \ if isinstance(response.data, str):\\
\ \ \ \ \ \ \ \ \ \ \ \ with open(path, 'w') as f:\\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f.write(response.data)\\
\ \ \ \ \ \ \ \ elif isinstance(response.data, bytes):\\
\ \ \ \ \ \ \ \ \ \ \ \ with open(path, 'wb') as f:\\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f.write(response.data)" demisto_client/demisto_api/api_client.py
# End fix return str response
# remove files not used
rm .travis.yml
rm git_push.sh
Expand Down

0 comments on commit 42f5bf8

Please sign in to comment.