Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

christopherjwhite
Copy link
Contributor

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.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 4e75498 on riverbed:master into 48dce31 on stefankoegl:master.

@stefankoegl
Copy link
Owner

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)

@christopherjwhite
Copy link
Contributor Author

Hmm. The doctests are failing. In 2.7 the strings embedded in the
objects are converted to unicode, thus come out with u'anArray' whereas
in 3.x they just print out as strings without the u prefix.

I don't have a lot of experience with 3.2. The simple fix is to drop
the examples from the docstrings, but not sure if that means I'm hiding
something.

I'll research further. Let me know if you have encountered this before
and have a better solution.

...cj

On 9/21/13 2:28 PM, Stefan Kögl wrote:

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)


Reply to this email directly or view it on GitHub
#5 (comment).

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 0f873fd on riverbed:master into 48dce31 on stefankoegl:master.

@christopherjwhite
Copy link
Contributor Author

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.

@stefankoegl
Copy link
Owner

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

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 69db17b on riverbed:master into 48dce31 on stefankoegl:master.

@christopherjwhite
Copy link
Contributor Author

Good suggestion, that seems to work well!

...cj

On 9/22/13 5:22 AM, Stefan Kögl wrote:

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


Reply to this email directly or view it on GitHub
#5 (comment).

@stefankoegl
Copy link
Owner

I've squashed your commits into one, fixed some whitespace-only changes, and merged everything into master: 19f9f21.

Thanks :)

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

Successfully merging this pull request may close these issues.

3 participants