diff options
| author | Stefan Kögl <stefan@skoegl.net> | 2012-09-28 19:01:27 +0200 |
|---|---|---|
| committer | Stefan Kögl <stefan@skoegl.net> | 2012-09-28 19:06:08 +0200 |
| commit | 33ad0dc629b7802fa084afa2a23a9599c224fc40 (patch) | |
| tree | b703f489fbb76f297d82ed50edf0e248dbf0fccd /jsonpatch.py | |
| parent | d935044158c3bdcd2ca1014166d7ca323cd57c27 (diff) | |
| download | python-json-patch-33ad0dc629b7802fa084afa2a23a9599c224fc40.tar.gz | |
implement __has__, __eq__ for JsonPatch, PatchOperation
Diffstat (limited to 'jsonpatch.py')
| -rw-r--r-- | jsonpatch.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/jsonpatch.py b/jsonpatch.py index 6aa4878..1244d60 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -191,6 +191,18 @@ class JsonPatch(object): def __iter__(self): return iter(self.patch) + + def __hash__(self): + return hash(frozenset(self.operations)) + + + def __eq__(self, other): + if not isinstance(other, JsonPatch): + return False + + return self.patch == other.patch + + @classmethod def from_string(cls, patch_str): """Creates JsonPatch instance from string source. @@ -354,6 +366,17 @@ class PatchOperation(object): return obj, part_variants[0] + def __hash__(self): + return hash(frozenset(self.operation.items())) + + + def __eq__(self, other): + if not isinstance(other, PatchOperation): + return False + + return self.operation == other.operation + + class RemoveOperation(PatchOperation): """Removes an object property or an array element.""" |
