Skip to content
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

[pull] master from stefankoegl:master #1

Open
wants to merge 167 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
70306fa
Fix build failure on Travis CI with Python 3.2
selurvedu Oct 18, 2015
a2ba02f
Merge pull request #45 from selurvedu/py32_coverage
stefankoegl Oct 22, 2015
0ae80ba
Allow running certain tests separately
selurvedu Aug 14, 2015
99bf616
Merge pull request #43 from selurvedu/separate-tests
stefankoegl Oct 28, 2015
3f2328e
Fix bug in _split_by_common_seq using wrong range in right subtree
Nov 3, 2015
2a02d21
Add failing test for #40
stefankoegl Nov 3, 2015
46ad04c
Merge pull request #46 from apinkney97/master, fixes #40
stefankoegl Nov 3, 2015
d877f1d
bump version to 1.12
stefankoegl Nov 3, 2015
5c2a9b9
Add encoding info to setup.py
stefankoegl Feb 13, 2016
32dcbb0
Create "universal" wheel packages
stefankoegl Feb 13, 2016
a33021b
Optimize "deep" ``replace`` operation, fixes #36
stefankoegl Feb 13, 2016
4443d32
Make ``move`` operation with from == path a no-op
stefankoegl Feb 13, 2016
cf0da04
Print test comments when external tests fail
stefankoegl Feb 13, 2016
9ce8487
Remove import of ``pudb``
stefankoegl Feb 13, 2016
b15d8f1
bump version to 1.13
stefankoegl Feb 13, 2016
5cc9bee
Update trove classification to include Python 3.5
stefankoegl Feb 13, 2016
282beba
Extend tests that check list patching
selurvedu Aug 14, 2015
c106735
Allow longer patches in test_use_move_...
selurvedu Aug 19, 2015
6761340
added error-prone cases to default tests
tyerq Aug 18, 2015
0734d45
Update tests from ea80865 to run on Python 3.2
selurvedu Oct 18, 2015
73acf7f
Move list-related testcases into separate class
selurvedu Apr 8, 2016
a2cd6da
Merge branch '[email protected]' into [email protected]
selurvedu Apr 8, 2016
72a90e3
Fix KeyError in add/remove optimization
go1dshtein May 4, 2016
c9ac1d9
Merge pull request #50 from go1dshtein/master
stefankoegl May 31, 2016
d6e9a00
Use inspect.signature() on Python 3
vstinner Jun 29, 2016
55e0c43
Merge pull request #52 from haypo/signature
stefankoegl Jul 22, 2016
4e95310
If there is no diff print nothing; exit 1 if a diff is found (#53)
gergnz Oct 2, 2016
1dbc03c
Run tests with Python 3.6
Dec 30, 2016
a01bec7
Update trove classification to include Python 3.6
stefankoegl Jan 12, 2017
8b46602
bump version to 1.14
stefankoegl Jan 12, 2017
27f1f98
bump version to 1.15
stefankoegl Jan 12, 2017
d1f317a
Fix: optimization bugs #55, #54, add more tests
mrhadenough Mar 8, 2017
05d9ace
Fix: python 3.2 tests
mrhadenough Mar 8, 2017
e18a131
don't apply patch optimization when it's incorrect
mrhadenough Apr 27, 2017
18887df
Merge branch 'mrhadenough-fix_optimization_bugs'
stefankoegl Jun 15, 2017
1fc5e20
Bump version to 1.16
stefankoegl Jun 15, 2017
e8fbd18
Avoid double work (#62)
mithrandi Jul 9, 2017
4d9adf1
Merge commit '1fc5e2022ff2c5796bd28af56646b135ede4ee71'
stefankoegl Jul 17, 2017
b878d85
fixing array diff bug (issue #30)
velislavgerov Jul 26, 2017
845cf4a
added a test case for issue #30
velislavgerov Jul 26, 2017
717b0db
Merge branch '[email protected]' into list_tests
stefankoegl Sep 3, 2017
fbc904f
Disable tests for disabled optimizations
stefankoegl Sep 3, 2017
f0a4f51
Merge branch 'list_tests'
stefankoegl Sep 3, 2017
7583258
Merge pull request #65 from thunderstruck47/master
stefankoegl Sep 10, 2017
e649871
Remove trailing whitespace
stefankoegl Sep 10, 2017
d778745
Remove support for Python 3.2
stefankoegl Sep 10, 2017
1964607
Drop in patch creation from jsondiff
stefankoegl Sep 10, 2017
82ac779
Remove re-creation of no-optimization patch
stefankoegl Sep 10, 2017
2f45e50
Re-enable previously disabled optimization tests
stefankoegl Sep 10, 2017
03aa14e
Merge _op_base classes into PatchOperation classes
stefankoegl Sep 10, 2017
73daf9b
Break long lines
stefankoegl Sep 10, 2017
098c7c7
Redefine _compare_info class as DiffBuilder
stefankoegl Sep 10, 2017
7387d20
Simplify compatibility code
stefankoegl Sep 10, 2017
2d9a565
Rename old{path,key} to from_{path,key}
stefankoegl Sep 10, 2017
462c9cb
Code style
stefankoegl Sep 10, 2017
3cec8a0
Improve optimizations
stefankoegl Sep 10, 2017
d602f5e
Fix unicode dict keys in Python 2
stefankoegl Sep 10, 2017
4351804
Remove support for Python 3.2
stefankoegl Sep 10, 2017
7079bdc
Remove support for Python 2.6
stefankoegl Oct 21, 2017
b6514dd
Update supported versions in docs
stefankoegl Oct 21, 2017
074f937
Avoid overriding json.load (fixes #37)
stefankoegl Oct 21, 2017
6b777b7
Show coverage report after tests
stefankoegl Oct 29, 2017
7b4fb66
Merge branch 'master' into jsondiff
stefankoegl Nov 25, 2017
7465c1b
Merge branch 'jsonload-no-override'
stefankoegl Nov 25, 2017
66c2e50
Merge branch 'jsondiff'
stefankoegl Nov 25, 2017
ae15a3b
Reformat .travis.yml
stefankoegl Nov 25, 2017
5ea6224
Deploy to PyPI from Travis-CI
stefankoegl Nov 25, 2017
e066c28
Disable tests for Python 2.6
stefankoegl Nov 25, 2017
d8c54d6
Bump version to 1.20
stefankoegl Nov 25, 2017
04596b8
Add test case for issue reported in #74
stefankoegl Nov 25, 2017
ae895f7
Add test case for issue reported in #41
stefankoegl Nov 25, 2017
62db640
Update ext_tests.py for current versions of coverage
stefankoegl Nov 25, 2017
df0c56d
Remove broken badges from README
stefankoegl Nov 25, 2017
aae6082
Expect path/from attributes also as JsonPoiner instances (#60)
stefankoegl Dec 3, 2017
e500b4d
Remove extraneous 'value' field for op:remove (#76)
ostackbrian Dec 4, 2017
cfd69e5
Merge pull request #77 from ostackbrian/issue-76
stefankoegl Dec 30, 2017
4ff7398
Bump version to 1.21
stefankoegl Dec 30, 2017
71bdeed
Drop support for EOL Python 3.3
hugovk Jan 16, 2018
d5a7aed
Remove ununsed imports and variables
hugovk Jan 16, 2018
02fa1f8
Update badges and fix typos
hugovk Jan 16, 2018
0642254
Merge pull request #81 from hugovk/rm-3.3
stefankoegl Jan 16, 2018
7b664c4
Add tests.js to MANIFEST.in, fixes #82
stefankoegl Mar 11, 2018
7e55ad6
Bump version to 1.22
stefankoegl Apr 2, 2018
3c621da
Add project URLs to setup.py
stefankoegl Apr 2, 2018
0c96a53
Merge pull request #75 from stefankoegl/jsonptr
stefankoegl Apr 2, 2018
36b245a
Bump version to 1.23
stefankoegl Apr 2, 2018
4c6f547
better exception when unable to fully resolve a jsonpointer on add or…
guillp Jul 17, 2018
2990bb3
Merge pull request #89 from guillp/patch-1
stefankoegl Aug 1, 2018
0410363
Ensure an item is within the upper array boundaries before replacing it
May 16, 2019
1b83d63
Fix move for numeric dictionary keys (issue #97)
Jun 28, 2019
b5141ab
Merge tag 'v1.23'
Jul 22, 2019
53817c0
bump version
Jul 22, 2019
33e630e
Merge pull request #99 from itkach/master
stefankoegl Jul 28, 2019
abf27f2
Support Python 3.7, test with Python 3.8 dev
stefankoegl Jul 28, 2019
911b79f
Merge pull request #100 from stefankoegl/python-3.8
stefankoegl Jul 28, 2019
2f2790b
Travis CI: Add Python 3.8 production release
cclauss Nov 9, 2019
9ca2e21
fixup! setup.py: Add Python 3.8 and remove 3.4
cclauss Nov 9, 2019
3e44e04
Merge pull request #104 from cclauss/patch-1
stefankoegl Nov 13, 2019
ed43114
Test to reproduce:
Jan 28, 2020
028089d
Flagging type-only changes with DiffBuilder
Jan 28, 2020
97e18f3
Changing previous type comparison to just comparing how json.dumps re…
Jan 28, 2020
b3726f3
Merge pull request #96 from gdraynz/replace-array-indexerror
stefankoegl Jan 28, 2020
c1fce71
Added comment.
Jan 28, 2020
91f6124
Merge pull request #106 from blakehilliard/only-type-diff
stefankoegl Jan 29, 2020
e99d178
Make it possible for from_diff to support custom types (issue #107)
clj Jan 31, 2020
8fbed9b
Fixed some typos and wording
vavanade Feb 27, 2020
9e4d423
Merge pull request #109 from vavanade/patch-1
stefankoegl Mar 2, 2020
0167d34
Subclassing can override json dumper and loader
clj Mar 6, 2020
1457aaf
Merge branch 'master' into custom-types
clj Mar 6, 2020
29c989e
Make DiffBuilder's dumps argument optional
clj Mar 16, 2020
1015d7f
fix #111: optimizing exception message
Alanscut May 23, 2020
86f82be
fix #102: optimize error handling
Alanscut Jun 9, 2020
625555e
Merge pull request #113 from Alanscut/issue-102
stefankoegl Jun 22, 2020
4fe5c2c
Merge pull request #112 from Alanscut/issue-111
stefankoegl Jun 22, 2020
ab775d1
feat: add custom json pointer support
Nov 12, 2020
bb4ea7b
test: custo json pointer
Nov 12, 2020
124eb76
doc: fix docstrings
Nov 12, 2020
fb04fcc
test: add more tests
Nov 15, 2020
0b680ea
chore: bump version
Nov 16, 2020
c37b40f
test: update
Nov 16, 2020
0994bfe
test: add toy jsonpointer example
Nov 17, 2020
d24fa96
test: fix for py27
Nov 17, 2020
4d07392
style: fix typo
Nov 17, 2020
c9613e3
chore: revert version bump
Nov 17, 2020
bfc0f5a
Update coveragerc and require coverage.
dave-shawley Nov 17, 2020
a7ef7e8
fix #110: Validate patch documents during creation.
dave-shawley Nov 17, 2020
b44e7a2
Add tests for operation doc structure.
dave-shawley Nov 17, 2020
50fb942
tests: moar
Nov 17, 2020
511cbc2
Merge pull request #108 from paperlessreceipts/custom-types
stefankoegl Nov 20, 2020
3bb3351
Explain the call to _get_operation in __init__.
dave-shawley Nov 20, 2020
24b5e86
Merge pull request #116 from dave-shawley/validate-patch-doc
stefankoegl Nov 20, 2020
eca4f8a
Merge branch 'master' into feature/custom-pointer
Nov 23, 2020
3a95635
Merge pull request #114 from tzoiker/feature/custom-pointer
stefankoegl Nov 23, 2020
3972a8e
Update Python to 3.9
stefankoegl Nov 23, 2020
f3c46e8
Merge pull request #117 from stefankoegl/py3.9
stefankoegl Nov 23, 2020
b8083d7
feat: make operations class-based
Nov 23, 2020
1268e09
test: custom operations
Nov 23, 2020
9310d48
test: fix
Nov 24, 2020
57e4273
Merge pull request #118 from tzoiker/fix/json-patch-ops
stefankoegl Dec 1, 2020
a9a83b5
Bump version to 1.28
stefankoegl Dec 1, 2020
8d15ed5
Fix make_patch
RyanSept Feb 1, 2021
78abec1
Add comment
RyanSept Feb 18, 2021
f6b26b2
Update comment
RyanSept Feb 18, 2021
25762af
Merge pull request #122 from RyanSept/119-120-fix-diffbuilder
stefankoegl Mar 2, 2021
dbea3db
Fix version number v1.30
stefankoegl Mar 2, 2021
974d54f
Add support for preserving Unicode characters in jsonpatch CLI
Genzer Mar 3, 2021
cc37e25
Merge pull request #127 from Genzer/master
stefankoegl Mar 4, 2021
7a6d76a
Remove failing pypy build
stefankoegl Mar 4, 2021
d1cfec3
Bump version to 1.31
stefankoegl Mar 4, 2021
5cdb066
closes #129
Penguin2600 Mar 12, 2021
ce15b23
Merge pull request #130 from Penguin2600/master
stefankoegl Mar 13, 2021
fd9fa23
Merge branch 'master' of github.com:stefankoegl/python-json-patch
stefankoegl Mar 13, 2021
55d4816
Bump version to 1.32
stefankoegl Mar 13, 2021
c9bfb91
FIX: TypeError when one forgot to put its operation in a list.
JulienPalard Mar 16, 2021
a652648
Merge pull request #132 from JulienPalard/mdk/TypeError
stefankoegl Mar 29, 2021
db194f8
fix invalid remove index
Apr 6, 2021
46eef55
remove unused import
Apr 6, 2021
e0b3a9b
Merge pull request #134 from Ventilateur/b/fix-invalid-remove-index
stefankoegl Apr 12, 2021
714df3c
docs: fix simple typo, raies -> raise (#135)
timgates42 Sep 14, 2021
a76f742
feat(jsondiff): Add support for preserving Unicode characters (#145)
hirmiura Jun 16, 2023
33562b0
Update license text to match official 3-clause-BSD (#142)
skypanther Jun 16, 2023
45cfe90
Switch to GitHub actions (#144)
stefankoegl Jun 16, 2023
0b05203
bump version to 1.33
stefankoegl Jun 16, 2023
e5a007a
add .readthedocs.yaml
stefankoegl Jun 16, 2023
73c36f2
Update documentation to include a link to the GitHub repo and install…
werdnum Jun 28, 2023
a22e05a
chore: add Python 3.10-3.12 as supported versions (#156)
hf-kklein Feb 24, 2024
d8e1a6e
Fix tests for Python 3.12 (#162)
CyrilRoelandteNovance Aug 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# .coveragerc to control coverage.py
[run]
branch = True
source = jsonpatch

[report]
show_missing = True
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Python package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["2.7", "3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install coveralls
# - name: Lint with flake8
# run: |
# stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test
run: |
coverage run --source=jsonpointer tests.py
22 changes: 22 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: doc/conf.py

# We recommend specifying your dependencies to enable reproducible builds:
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

26 changes: 0 additions & 26 deletions COPYING

This file was deleted.

11 changes: 11 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright (c) 2011 Stefan Kögl <[email protected]>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ include README.md
include tests.py
include ext_tests.py
include AUTHORS
include tests.js
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
python-json-patch [![Build Status](https://secure.travis-ci.org/stefankoegl/python-json-patch.png?branch=master)](https://travis-ci.org/stefankoegl/python-json-patch) [![Coverage Status](https://coveralls.io/repos/stefankoegl/python-json-patch/badge.png?branch=master)](https://coveralls.io/r/stefankoegl/python-json-patch?branch=master) ![Downloads](https://pypip.in/d/jsonpatch/badge.png) ![Version](https://pypip.in/v/jsonpatch/badge.png)
python-json-patch
=================

[![PyPI version](https://img.shields.io/pypi/v/jsonpatch.svg)](https://pypi.python.org/pypi/jsonpatch/)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/jsonpatch.svg)](https://pypi.python.org/pypi/jsonpatch/)
[![Build Status](https://travis-ci.org/stefankoegl/python-json-patch.png?branch=master)](https://travis-ci.org/stefankoegl/python-json-patch)
[![Coverage Status](https://coveralls.io/repos/stefankoegl/python-json-patch/badge.png?branch=master)](https://coveralls.io/r/stefankoegl/python-json-patch?branch=master)

Applying JSON Patches in Python
-------------------------------

Library to apply JSON Patches according to
[RFC 6902](http://tools.ietf.org/html/rfc6902)

See Sourcecode for Examples
See source code for examples

* Website: https://github.com/stefankoegl/python-json-patch
* Repository: https://github.com/stefankoegl/python-json-patch.git
* Documentation: https://python-json-patch.readthedocs.org/
* PyPI: https://pypi.python.org/pypi/jsonpatch
* Travis-CI: https://travis-ci.org/stefankoegl/python-json-patch
* Travis CI: https://travis-ci.org/stefankoegl/python-json-patch
* Coveralls: https://coveralls.io/r/stefankoegl/python-json-patch

Running external tests
Expand Down
8 changes: 5 additions & 3 deletions bin/jsondiff
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import print_function

import sys
import os.path
import json
import jsonpatch
import argparse
Expand All @@ -15,6 +14,8 @@ parser.add_argument('FILE1', type=argparse.FileType('r'))
parser.add_argument('FILE2', type=argparse.FileType('r'))
parser.add_argument('--indent', type=int, default=None,
help='Indent output by n spaces')
parser.add_argument('-u', '--preserve-unicode', action='store_true',
help='Output Unicode character as-is without using Code Point')
parser.add_argument('-v', '--version', action='version',
version='%(prog)s ' + jsonpatch.__version__)

Expand All @@ -32,8 +33,9 @@ def diff_files():
doc1 = json.load(args.FILE1)
doc2 = json.load(args.FILE2)
patch = jsonpatch.make_patch(doc1, doc2)
print(json.dumps(patch.patch, indent=args.indent))

if patch.patch:
print(json.dumps(patch.patch, indent=args.indent, ensure_ascii=not(args.preserve_unicode)))
sys.exit(1)

if __name__ == "__main__":
main()
7 changes: 4 additions & 3 deletions bin/jsonpatch
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ parser.add_argument('-i', '--in-place', action='store_true',
help='Modify ORIGINAL in-place instead of to stdout')
parser.add_argument('-v', '--version', action='version',
version='%(prog)s ' + jsonpatch.__version__)

parser.add_argument('-u', '--preserve-unicode', action='store_true',
help='Output Unicode character as-is without using Code Point')

def main():
try:
Expand Down Expand Up @@ -72,8 +73,8 @@ def patch_files():

# By this point we have some sort of file object we can write the
# modified JSON to.

json.dump(result, fp, indent=args.indent)
json.dump(result, fp, indent=args.indent, ensure_ascii=not(args.preserve_unicode))
fp.write('\n')

if args.in_place:
Expand Down
19 changes: 11 additions & 8 deletions doc/commandline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The JSON patch package contains the commandline utilities ``jsondiff`` and
The program ``jsondiff`` can be used to create a JSON patch by comparing two
JSON files ::

usage: jsondiff [-h] [--indent INDENT] [-v] FILE1 FILE2
usage: jsondiff [-h] [--indent INDENT] [-u] [-v] FILE1 FILE2

Diff two JSON files

Expand All @@ -19,9 +19,10 @@ JSON files ::
FILE2

optional arguments:
-h, --help show this help message and exit
--indent INDENT Indent output by n spaces
-v, --version show program's version number and exit
-h, --help show this help message and exit
--indent INDENT Indent output by n spaces
-u, --preserve-unicode Output Unicode character as-is without using Code Point
-v, --version show program's version number and exit

Example
^^^^^^^
Expand Down Expand Up @@ -74,10 +75,12 @@ The program ``jsonpatch`` is used to apply JSON patches on JSON files. ::
PATCH Patch file

optional arguments:
-h, --help show this help message and exit
--indent INDENT Indent output by n spaces
-v, --version show program's version number and exit

-h, --help show this help message and exit
--indent INDENT Indent output by n spaces
-b, --backup Back up ORIGINAL if modifying in-place
-i, --in-place Modify ORIGINAL in-place instead of to stdout
-v, --version show program's version number and exit
-u, --preserve-unicode Output Unicode character as-is without using Code Point

Example
^^^^^^^
Expand Down
13 changes: 9 additions & 4 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
python-json-patch
=================

*python-json-patch* is a Python library for applying JSON patches (`RFC
6902 <http://tools.ietf.org/html/rfc6902>`_). Python 2.6, 2.7, 3.2, 3.3
and PyPy are supported.

`python-json-patch <https://github.com/stefankoegl/python-json-patch>`_
is a Python library for applying JSON patches (`RFC 6902
<http://tools.ietf.org/html/rfc6902>`_). Python 2.7 and 3.4+ are
supported. Tests are run on both CPython and PyPy.

**Installation**
.. code-block:: bash
$ pip install jsonpatch
..

**Contents**

Expand Down
52 changes: 52 additions & 0 deletions doc/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,55 @@ explicitly.
# or from a list
>>> patch = [{'op': 'add', 'path': '/baz', 'value': 'qux'}]
>>> res = jsonpatch.apply_patch(obj, patch)


Dealing with Custom Types
-------------------------

Custom JSON dump and load functions can be used to support custom types such as
`decimal.Decimal`. The following examples shows how the
`simplejson <https://simplejson.readthedocs.io/>`_ package, which has native
support for Python's ``Decimal`` type, can be used to create a custom
``JsonPatch`` subclass with ``Decimal`` support:

.. code-block:: python

>>> import decimal
>>> import simplejson

>>> class DecimalJsonPatch(jsonpatch.JsonPatch):
@staticmethod
def json_dumper(obj):
return simplejson.dumps(obj)

@staticmethod
def json_loader(obj):
return simplejson.loads(obj, use_decimal=True,
object_pairs_hook=jsonpatch.multidict)

>>> src = {}
>>> dst = {'bar': decimal.Decimal('1.10')}
>>> patch = DecimalJsonPatch.from_diff(src, dst)
>>> doc = {'foo': 1}
>>> result = patch.apply(doc)
{'foo': 1, 'bar': Decimal('1.10')}

Instead of subclassing it is also possible to pass a dump function to
``from_diff``:

>>> patch = jsonpatch.JsonPatch.from_diff(src, dst, dumps=simplejson.dumps)

a dumps function to ``to_string``:

>>> serialized_patch = patch.to_string(dumps=simplejson.dumps)
'[{"op": "add", "path": "/bar", "value": 1.10}]'

and load function to ``from_string``:

>>> import functools
>>> loads = functools.partial(simplejson.loads, use_decimal=True,
object_pairs_hook=jsonpatch.multidict)
>>> patch.from_string(serialized_patch, loads=loads)
>>> doc = {'foo': 1}
>>> result = patch.apply(doc)
{'foo': 1, 'bar': Decimal('1.10')}
29 changes: 16 additions & 13 deletions ext_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
""" Script to run external tests, eg from
https://github.com/json-patch/json-patch-tests """

from functools import partial
import doctest
import unittest
import jsonpatch
Expand All @@ -60,12 +59,15 @@ def _test(self, test):
)

else:
res = jsonpatch.apply_patch(test['doc'], test['patch'])
try:
res = jsonpatch.apply_patch(test['doc'], test['patch'])
except jsonpatch.JsonPatchException as jpe:
raise Exception(test.get('comment', '')) from jpe

# if there is no 'expected' we only verify that applying the patch
# does not raies an exception
# does not raise an exception
if 'expected' in test:
self.assertEquals(res, test['expected'])
self.assertEqual(res, test['expected'], test.get('comment', ''))


def make_test_case(tests):
Expand Down Expand Up @@ -112,24 +114,25 @@ def get_suite(filenames):

try:
import coverage
cov = coverage.Coverage()
except ImportError:
coverage = None
cov = None

if coverage is not None:
coverage.erase()
coverage.start()
if cov is not None:
cov.erase()
cov.start()

result = runner.run(suite)

if not result.wasSuccessful():
sys.exit(1)

if coverage is not None:
coverage.stop()
coverage.report(coverage_modules)
coverage.erase()
if cov is not None:
cov.stop()
cov.report(coverage_modules)
cov.erase()

if coverage is None:
if cov is None:
sys.stderr.write("""
No coverage reporting done (Python module "coverage" is missing)
Please install the python-coverage package to get coverage reporting.
Expand Down
Loading