Skip to content

Commit

Permalink
fix: CloudFile.put_json not operative
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Aug 24, 2023
1 parent 8ffe5b1 commit 29e73c6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CHANGES
=======

4.20.0
------

* fix(cli): missing part\_bytes argument in a few placs
* test: add CF.get\_json test
* feat: add CloudFile.get\_json
* feat: add --part-bytes to cp CLI
* fixtest: tigerdata -> td

4.19.2
------

Expand Down
1 change: 1 addition & 0 deletions automated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def test_read_write(s3, protocol, num_threads, green):
assert results == { 'omg': 'wow' }

cf = CloudFile(cf.join(url, "info"))
cf.put_json({ 'omg': 'wow' }, cache_control='no-cache')
results = cf.get_json()
assert results == { 'omg': 'wow' }

Expand Down
15 changes: 14 additions & 1 deletion cloudfiles/cloudfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,20 @@ def put(self, content:bytes, *args, **kwargs):

def put_json(self, content, *args, **kwargs):
"""Upload a file as JSON."""
return self.put(self.filename, content, *args, **kwargs)
content = jsonify(content)

content_type = "application/json"
if content_type not in args:
kwargs["content_type"] = "application/json"

try:
return self.cf.put(self.filename, content, *args, **kwargs)
finally:
if hasattr(content, "__len__"):
self._size = len(content)
else:
content.seek(0, os.SEEK_END)
self._size = content.tell()

def head(self) -> dict:
"""Get the file metadata."""
Expand Down

0 comments on commit 29e73c6

Please sign in to comment.