-
Notifications
You must be signed in to change notification settings - Fork 41
Support for set_pointer and indexing arbitrary objects via __getitem__/_setitem__ #5
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
Conversation
The patch looks good in general, but please fix the tests for Python 3.2 and 3.3 (see https://travis-ci.org/stefankoegl/python-json-pointer/builds/11633865) |
Hmm. The doctests are failing. In 2.7 the strings embedded in the I don't have a lot of experience with 3.2. The simple fix is to drop I'll research further. Let me know if you have encountered this before ...cj On 9/21/13 2:28 PM, Stefan Kögl wrote:
|
This is apparently a somewhat known issue and I could find no clean solution. It apparently looks better in Python 3.3. As such, I took the easy route and simply commented out those example commands so that they don't run at all, thus cannot fail. Unfortunate, but other solutions look rather horribly complex just for 2 examples. Hopefully you're cool with it this way. |
Commenting out docstrings is not really a nice solution... Instead of >>> set_pointer(obj, '/foo/anArray/0/prop', 55)
{'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}} please try something like >>> set_pointer(obj, '/foo/anArray/0/prop', 55) == {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}}
True |
Good suggestion, that seems to work well! ...cj On 9/22/13 5:22 AM, Stefan Kögl wrote:
|
I've squashed your commits into one, fixed some whitespace-only changes, and merged everything into master: 19f9f21. Thanks :) |
This adds support to modify documents based on jsonpointers as well as support for any object whose class supports the necessary methods getitem (for resolving pointers to get data), and setitem (for the set_pointer operation).
See the tests for an example.
I considered wrapping the support for non-dict/list types via getitem with a boolean "check_getitem", but in the end I figured it was unnecessary complexity.