3 �1V�$ � @ s d dl mZ yd dlmZmZ W n$ ek rD d dlmZmZ Y nX dZdZdZ dZ y d dlmZ d dl mZ eZW n$ ek r� d dlmZ eZY nX d d l mZ d d lZd d lZejd�ZG dd � d e�ZG dd� de�Ze� Zefdd�Zddd�ZG dd� de�Zdd� Z d S )� )�unicode_literals)�Mapping�Sequenceu Stefan Kögl <stefan@skoegl.net>z1.10z2https://github.com/stefankoegl/python-json-pointerzModified BSD License)�unquote)�izip)�teeNz0|[1-9][0-9]*$c @ s e Zd ZdS )�JsonPointerExceptionN)�__name__� __module__�__qualname__� r r �!/usr/lib/python3.6/jsonpointer.pyr B s r c @ s e Zd ZdZdd� Zdd� ZdS )� EndOfListz+ Result of accessing element "-" of a list c C s || _ d S )N)�list_)�selfr r r r �__init__I s zEndOfList.__init__c C s dj | jjt| j�d�S )Nz{cls}({lst}))�clsZlst)�format� __class__r �reprr )r r r r �__repr__M s zEndOfList.__repr__N)r r r �__doc__r r r r r r r F s r c C s t |�}|j| |�S )an Resolves pointer against doc and returns the referenced object >>> obj = {"foo": {"anArray": [ {"prop": 44}], "another prop": {"baz": "A string" }}} >>> resolve_pointer(obj, '') == obj True >>> resolve_pointer(obj, '/foo') == obj['foo'] True >>> resolve_pointer(obj, '/foo/another%20prop') == obj['foo']['another prop'] True >>> resolve_pointer(obj, '/foo/another%20prop/baz') == obj['foo']['another prop']['baz'] True >>> resolve_pointer(obj, '/foo/anArray/0') == obj['foo']['anArray'][0] True >>> resolve_pointer(obj, '/some/path', None) == None True )�JsonPointer�resolve)�doc�pointer�defaultr r r �resolve_pointerU s r Tc C s t |�}|j| ||�S )aV Resolves pointer against doc and sets the value of the target within doc. With inplace set to true, doc is modified as long as pointer is not the root. >>> obj = {"foo": {"anArray": [ {"prop": 44}], "another prop": {"baz": "A string" }}} >>> set_pointer(obj, '/foo/anArray/0/prop', 55) == {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}} True >>> set_pointer(obj, '/foo/yet%20another%20prop', 'added prop') == {'foo': {'another prop': {'baz': 'A string'}, 'yet another prop': 'added prop', 'anArray': [{'prop': 55}]}} True )r �set)r r �value�inplacer r r �set_pointerr s r! c @ s� e Zd ZdZdd� Zdd� Zefdd�ZeZdd d �Z dd� Z d d� Zdd� Zdd� Z edd� �Zdd� Zdd� Zedd� �ZdS )r z= A JSON Pointer that can reference parts of an JSON document c C sP |j d�}|jd�dkr td��tt|�}dd� |D �}dd� |D �}|| _d S )N�/r � zlocation must starts with /c S s g | ]}|j d d��qS )z~1r"