Skip to content

bpo-30193: Allow to load buffer objects with json.loads() #14977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

flavianh
Copy link

@flavianh flavianh commented Jul 27, 2019

Revival of #1334 updated to current master

https://bugs.python.org/issue30193

Co-authored-by: Nikolay Kim  <fafhrd91@gmail.com>
@flavianh
Copy link
Author

flavianh commented Aug 2, 2019

@nascheme Fixed!

@CuriousLearner
Copy link
Member

CuriousLearner commented Aug 10, 2019

Hi @flavianh ,

Thanks for your contribution!

I think it is better to carry on your changes on the earlier pull request ( in order to keep track of the reviews and changes). It is difficult to hop on to different pull requests and referring to what actually has been already reviewed & addressed.

In case you prefer rebasing, you can do a force push to update your branch and that should update your old PR.

@csabella
Copy link
Contributor

csabella commented Feb 6, 2020

Have @serhiy-storchaka's comments from the bug tracker been addressed?

@csabella
Copy link
Contributor

Requesting reviews from those who had commented on the original PR.

Comment on lines +345 to +346
raise TypeError('the JSON object must be str, bytes or '
'bytearray or memoryview compatible object, '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise TypeError('the JSON object must be str, bytes or '
'bytearray or memoryview compatible object, '
raise TypeError('the JSON object must be str, bytes, '
'bytearray, or a memoryview-compatible object, '

self.assertEqual(self.loads(data), {"key": "val"})

def test_buffer(self):
data = array.array('B')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use different encodings with BOM. Test also with array.array('H').

@@ -20,6 +21,15 @@ def test_empty_objects(self):
self.assertEqual(self.loads('[]'), [])
self.assertEqual(self.loads('""'), "")

def test_memoryview(self):
data = memoryview(b'{"key": "val"}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use different encodings with BOM. Test also with memoryview(...).cast('H').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants