Package jsondata :: Module jsonpatch :: Class JSONPatchItem
[hide private]
[frames] | no frames]

Class JSONPatchItem

[apisource code


Record entry for list of patch tasks.

Attributes:
    **op**:
        operations: ::

           add, copy, move, remove, replace, test

    **target**:
        JSONPointer for the modification target, see RFC6902.

    **value**:
        Value, either a branch, or a leaf of the JSON data structure.

    **src**:
        JSONPointer for the modification source, see RFC6902.

Instance Methods [hide private]
 
__init__(self, op, target, param=None, **kargs)
Create an entry for the patch list.
[apisource code
 
__add__(self, x=None) [apisource code
 
__call__(self, jdata)
Evaluates the related task for the provided data.
[apisource code
 
__eq__(self, x=None)
Compares this pointer with x.
[apisource code
 
__getitem__(self, key)
Support of various mappings.
[apisource code
 
__ne__(self, x)
Compares this pointer with x.
[apisource code
 
__radd__(self, x=None) [apisource code
 
__repr__(self)
Prints the patch string in accordance to RFC6901.
[apisource code
 
__str__(self)
Prints the patch string in accordance to RFC6901.
[apisource code
 
apply(self, jsondata, **kargs)
Applies the present patch list on the provided JSON document.
[apisource code
 
repr_export(self)
Prints the patch string for export in accordance to RFC6901.
[apisource code
 
str_export(self)
Pretty prints the patch string for export in accordance to RFC6901.
[apisource code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, op, target, param=None, **kargs)
(Constructor)

[apisource code 
Create an entry for the patch list.

Args:
    **op**:
        Operation: ::

           add, copy, move, remove, replace, test

    **target**:
        Target node. ::

           target := (
               <rfc6901-string>
               | JSONPointer
               | <path-items-list>
               )

    **param**:
        Specific parameter for the operation.

        +-------+--------------------+
        | type  | operation          |
        +=======+====================+
        | value | add, replace, test |
        +-------+--------------------+
        | src   | copy, move         |
        +-------+--------------------+
        | param | None for 'remove'  |
        +-------+--------------------+

    kargs:
        **replace**:
            Replace masked characters in *target* specification. ::

               replace := (
                    True    # replaces rfc6901 escape sequences: ~0 and ~1
                  | False   # omit unescaping
               )

            .. note::
            
               Match operations are proceeded literally, thus the
               escaped characters should be consistent,
               see rfc6901, Section 3.

            default := False

Returns:
    When successful returns 'True', else returns either 'False', or
    raises an exception.
    Success is the complete addition only, thus one failure returns
    False.

Raises:
    JSONDataPatchItemError

Overrides: object.__init__

__call__(self, jdata)
(Call operator)

[apisource code 
Evaluates the related task for the provided data.

Args:
    **jdata**:
        JSON data the task has to be 
        applied on.

Returns:
    Returns a tuple of: ::

       (n,lerr): 

       n:    number of present active entries
       lerr: list of failed entries

Raises:
    JSONDataPatchError:

__eq__(self, x=None)
(Equality operator)

[apisource code 
Compares this pointer with x.

Args:
    **x**:
        A valid Pointer.

Returns:
    *True* or *False*.

Raises:
    JSONPointerError

__getitem__(self, key)
(Indexing operator)

[apisource code 

Support of various mappings.

#. self[key]

#. self[i:j:k]

#. x in self

#. for x in self

__ne__(self, x)

[apisource code 
Compares this pointer with x.

Args:
    **x**: A valid Pointer.

Returns:
    *True* or *False*.

Raises:
    JSONPointerError

__repr__(self)
(Representation operator)

[apisource code 

Prints the patch string in accordance to RFC6901.

Overrides: object.__repr__

__str__(self)
(Informal representation operator)

[apisource code 

Prints the patch string in accordance to RFC6901.

Overrides: object.__str__

apply(self, jsondata, **kargs)

[apisource code 
Applies the present patch list on the provided JSON document.

Args:
    **jsondata**:
        Document to be patched.

    kargs:
        **replace**:
            Replace masked characters in *target* specification. ::

               replace := (
                    True    # replaces rfc6901 escape sequences: ~0 and ~1
                  | False   # omit unescaping
               )

            .. note::
            
               Match operations are proceeded literally, thus the
               escaped characters should be consistent,
               see rfc6901, Section 3.

               If already decoded e.g. by the constructor, than should be
               *FALSE*, is not idempotent.

            default := False
    
Returns:
    When successful returns 'True', else raises an exception.
    Or returns a tuple: ::

       (n,lerr): 

       n:    number of present active entries
       lerr: list of failed entries

Raises:
    JSONDataPatchError: