Package jsondata :: Module jsonpointer
[hide private]
[frames] | no frames]

Module jsonpointer

source code

Provides classes for the JSONPointer definition in accordance to RFC6901 and relative pointers draft-1/2018.


Version: 0.2.21

Author: Arno-Can Uestuensoez

Copyright: Copyright (C) 2015-2016 Arno-Can Uestuensoez @Ingenieurbuero Arno-Can Uestuensoez

License: Artistic-License-2.0 + Forced-Fairplay-Constraints

Classes [hide private]
  unicode
str(object='') -> string
  JSONPointer
Represents exactly one JSONPointer in compliance with IETF RFC6901 and relative-pointer/draft-1/2018
Functions [hide private]
 
fetch_pointerpath(node, base, restype=1)
Converts the address of *node* within the data structure *base* into a corresponding pointer path.
[apisource code
Variables [hide private]
  __maintainer__ = 'Arno-Can Uestuensoez'
  __uuid__ = '63b597d6-4ada-4880-9f99-f5e0961351fb'
  _interactive = False
  VALID_NODE_TYPE = (<type 'dict'>, <type 'list'>, <type 'str'>,...
Valid types of in-memory JSON node types.
  CHARSET_UTF = 0
Unicode.
  CHARSET_STR = 1
Python string.
  _RELPOINTER = re.compile(r'(0|[1-9][0-9]*)((#$)|(/.*$)|($))')
  _unescaped = re.compile(r'/|~[^01]')
  _privattr = {'isfragment': '__isfragment', 'isrel': '__isrel',...
private attributes accessible by __steattr__ and __getattr__ only
  VALID_NODE_TYPE_X = (<type 'dict'>, <type 'list'>, <type 'str'...
Valid types of in-memory JSON node types for processing.
  __package__ = None
hash(x)
Function Details [hide private]

fetch_pointerpath(node, base, restype=1)

[apisource code 
Converts the address of *node* within the data structure
*base* into a corresponding pointer path.
The current implementation is search based, thus
may cause performance issues when frequently applied,
or processing very large structures.

For example: ::

   nodex = {'a': 'pattern'}
   data = {0: nodex, 1: [{'x':[nodex}]]}

   res = fetch_pointerpath(nodex, data)

   res = [
      [0],
      [1, 0, 'x', 0]
   ]

Args:

    **node**:
        Address of Node to be searched for.

    **base**:
        A tree top node to search the subtree for node.

    **restype**:
        Type of search. ::

           M_FIRST: The first match only.
           M_LAST: The first match only.
           M_ALL: All matches.

Returns:

    Returns a list of lists, where the contained
    lists are pointer pathlists for matched elements.

    * restype:=M_FIRST: '[[<first-match>]]',

    * restype:=M_LAST: '[[<last-match>]]',

    * restype:=M_ALL: '[[<first-match>],[<second-match>],...]'

Raises:

    JSONDataError


Variables Details [hide private]

VALID_NODE_TYPE

Valid types of in-memory JSON node types.

Value:
(<type 'dict'>,
 <type 'list'>,
 <type 'str'>,
 <type 'unicode'>,
 <type 'int'>,
 <type 'float'>,
 <type 'bool'>,
 None)

_privattr

private attributes accessible by __steattr__ and __getattr__ only

Value:
{'isfragment': '__isfragment',
 'isrel': '__isrel',
 'raw': '__raw',
 'relupidx': '__relupidx',
 'start': '__start',
 'startrel': '__startrel'}

VALID_NODE_TYPE_X

Valid types of in-memory JSON node types for processing.

Value:
(<type 'dict'>,
 <type 'list'>,
 <type 'str'>,
 <type 'unicode'>,
 <type 'int'>,
 <type 'float'>,
 <type 'bool'>,
 None,
...