
    ~hSF                        d dl Z d dlZd dlZd dlmZmZmZ d dlmZ	 d dl
mZ d dlmZ 	 d dlZ eej                   j                        sdZd dlmZ dZ G d d	e      Z G d
 de      Z G d de      Zd ZddZdedddddfdZd Z	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddZd Z d Z!d Z"y# e$ r dZY rw xY w)    N)MappingMutableMappingSequence)parse)unquote)urlopen)	LazyProxyz1.1.0c                        e Zd ZddZd Zd Zy)JsonRefErrorNc                 f    || _         || _        || _        || _        || _        |x| _        | _        y N)message	referenceuribase_uripathcause	__cause__)selfr   r   r   r   r   r   s          C/opt/mcp/mcp-sentiment/venv/lib/python3.12/site-packages/jsonref.py__init__zJsonRefError.__init__   s3    " 	&++
T^    c                 P    d| j                   j                  d| j                  dS )N<: >)	__class____name__r   r   s    r   __repr__zJsonRefError.__repr__    s    !^^44dllCCr   c                 ,    t        | j                        S r   )strr   r   s    r   __str__zJsonRefError.__str__#   s    4<<  r   ) r$    N)r   
__module____qualname__r   r    r#   r%   r   r   r   r      s    ,D!r   r   c                   x    e Zd ZdZdZe	 dd       Z	 	 	 	 	 	 	 ddZed        Z	ed        Z
d Zd	 Zdd
Zd Zy)JsonRefzc
    A lazy loading proxy to the dereferenced data pointed to by a JSON
    Reference object.

    )__reference__Nc                 "    t        |||||      S )a  
        .. deprecated:: 0.4
            Use :func:`replace_refs` instead.

        Returns a deep copy of `obj` with all contained JSON reference objects
        replaced with :class:`JsonRef` instances.

        :param obj: If this is a JSON reference object, a :class:`JsonRef`
            instance will be created. If `obj` is not a JSON reference object,
            a deep copy of it will be created with all contained JSON
            reference objects replaced by :class:`JsonRef` instances
        :param base_uri: URI to resolve relative references against
        :param loader: Callable that takes a URI and returns the parsed JSON
            (defaults to global ``jsonloader``)
        :param jsonschema: Flag to turn on `JSON Schema mode
            <http://json-schema.org/latest/json-schema-core.html#anchor25>`_.
            'id' keyword changes the `base_uri` for references contained within
            the object
        :param load_on_repr: If set to ``False``, :func:`repr` call on a
            :class:`JsonRef` object will not cause the reference to be loaded
            if it hasn't already. (defaults to ``True``)

        )r   loader
jsonschemaload_on_repr)replace_refs)clsobjr   r,   r-   r.   s         r   r/   zJsonRef.replace_refs0   s     6 !%
 	
r   c	                    t        |j                  d      t              st        d|z        || _        || _        |xs t        | _        || _        || _	        || _
        || _        || _        | j                  t               | _        y y )N$refz%Not a valid json reference object: %s)
isinstancegetr"   
ValueErrorr*   r   
jsonloaderr,   r-   r.   merge_propsr   storeURIDict)	r   refobjr   r,   r-   r.   r8   _path_stores	            r   r   zJsonRef.__init__S   s     &**V,c2DvMNN# *
$(&	
:: DJ r   c           	          t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                        S )N)r   r,   r-   r.   r8   r   r9   )dictr   r,   r-   r.   r8   r   r9   r   s    r   _ref_kwargszJsonRef._ref_kwargsk   sD    ]];;**((**
 	
r   c                 \    t        j                  | j                  | j                  d         S )Nr3   )urlparseurljoinr   r*   r   s    r   full_urizJsonRef.full_uriw   s$    t/A/A&/IJJr   c                    t        j                  | j                        \  }}|| j                  vr0	 | j	                  |      }t        |fi i | j                  |dd}n| j                  |   }| j                  ||      }|| u r| j                  d      t        |d      r|j                  }| j                  r`t!        |t"              rPt%        | j&                        dkD  r8i || j&                  j)                         D ci c]  \  }}|dk7  s|| c}}}|S # t
        $ r;}| j                  |j                  j                  dt        |      |      |d }~ww xY wc c}}w )	Nr   r   F)r   	recursingz$Reference refers directly to itself.__subject__   r3   )rB   	urldefragrD   r9   r,   	Exception_errorr   r   r"   _replace_refsr@   resolve_pointerhasattrrH   r8   r4   r   lenr*   items)r   r   fragmentbase_doceresultkvs           r   callbackzJsonRef.callback{   se    **4==9X djj ;;s+
 %Ut//USuUH zz#H%%h9T>++DEE6=)''F67+D&&'!+$($6$6$<$<$>NDAq!v+1a4NF /  kk ! 4 4c!f=Q " * Os#   D E$E$	E!&6EE!c                    |r)t        |j                  d            j                  d      ng }|D ]V  }|j                  dd      j                  dd      }t	        |t
              r	 t        |      }|| u r| j                  }	 ||   }X |S # t        $ r Y %w xY w# t        t        f$ r}| j                  d|z  |      |d}~ww xY w)z
        Resolve a json pointer ``pointer`` within the referenced ``document``.

        :argument document: the referent document
        :argument str pointer: a json pointer URI fragment to resolve within it

        /z~1z~0~zUnresolvable JSON pointer: %rrF   N)r   lstripsplitreplacer4   r   intr6   r*   	TypeErrorLookupErrorrL   )r   documentpointerpartspartrT   s         r   rN   zJsonRef.resolve_pointer   s     <Cs+,2237 	D<<c*224=D(H-t9D 4--#D>	$  "  {+ kk3g=Q " s*   &BB	BBC)C  Cc                     dj                  | j                  |      }t        || j                  | j                  | j                  | j
                  |      S )NzError while resolving `{}`: {})r   r   r   r   )formatrD   r   r*   r   r   )r   r   r   s      r   rL   zJsonRef._error   sI    299$--Q]]
 	
r   c                 z    t        | d      s| j                  rt        | j                        S d| j                  z  S )NcachezJsonRef(%r))rO   r.   reprrH   r*   r   s    r   r    zJsonRef.__repr__   s6    4!T%6%6(())t1111r   )r$   NFT)r$   NFTFr%   Nr   )r   r&   r'   __doc____notproxied__classmethodr/   r   propertyr@   rD   rX   rN   rL   r    r%   r   r   r)   r)   '   s     (NKO 
  
J #0 	
 	
 K KB<	
2r   r)   c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)r:   z8
    Dictionary which uses normalized URIs as keys.
    c                 H    t        j                  |      j                         S r   )rB   urlsplitgeturlr   r   s     r   	normalizezURIDict.normalize   s      %,,..r   c                 Z    t               | _         | j                  j                  |i | y r   )r?   r9   update)r   argskwargss      r   r   zURIDict.__init__   s$    V


4*6*r   c                 >    | j                   | j                  |         S r   r9   rt   rs   s     r   __getitem__zURIDict.__getitem__   s    zz$..-..r   c                 @    || j                   | j                  |      <   y r   rz   )r   r   values      r   __setitem__zURIDict.__setitem__   s    */

4>>#&'r   c                 <    | j                   | j                  |      = y r   rz   rs   s     r   __delitem__zURIDict.__delitem__   s    JJt~~c*+r   c                 ,    t        | j                        S r   )iterr9   r   s    r   __iter__zURIDict.__iter__       DJJr   c                 ,    t        | j                        S r   )rP   r9   r   s    r   __len__zURIDict.__len__   s    4::r   c                 ,    t        | j                        S r   )rj   r9   r   s    r   r    zURIDict.__repr__   r   r   N)r   r&   r'   rk   rt   r   r{   r~   r   r   r   r    r%   r   r   r:   r:      s/    /+/0,  r   r:   c                    t        j                  |       j                  }|dv r@t        r:t        j                  |       }|j                          	  |j                  di |}|S t        |       5 }t        j                  |j                         j                  d      fi |}ddd       |S # t        $ r) t        j                  d       |j                         }Y |S w xY w# 1 sw Y   S xY w)z
    Provides a callable which takes a URI, and returns the loaded JSON referred
    to by that URI. Uses :mod:`requests` if available for HTTP URIs, and falls
    back to :mod:`urllib`.
    )httphttpsz7requests >=1.2 required for custom kwargs to json.loadszutf-8Nr%   )rB   rq   schemerequestsr5   raise_for_statusjsonr`   warningswarnr   loadsreaddecode)r   rx   r   resprU   contents         r   r7   r7      s     s#**F""x||C  		!TYY((F M S\ 	JWZZ 5 5g >I&IF	J M  	!MMSTYY[F M	!
	J Ms   B- /4C"-.CC"C,Fc                    |xs i }t        |       }||v r||   S t        |       t        u r ||       }|r|n| } | ||<   t        | t              r1| j                         D ]  \  }}t        ||||      }|s|| |<    | S t        | t              r:t        | t              s*t        |       D ]  \  }}t        ||||      }|s|| |<    | S )N)r^   
_processed)
idtyper)   r4   r   rQ   
_walk_refsr   r"   	enumerate)	r1   funcr^   r   oidrrV   rW   is	            r   r   r     s    !rJ
S'C
j#CyGIaJsO#wIIK 	DAq1dG
KAA	 J 
C	":c3+?cN 	DAq1dG
KAA	 Jr   r$   Tc                     t        | |||||t               dd	      }|st        |d d       |S |st        |d        |S )a  
    Returns a deep copy of `obj` with all contained JSON reference objects
    replaced with :class:`JsonRef` instances.

    :param obj: If this is a JSON reference object, a :class:`JsonRef`
        instance will be created. If `obj` is not a JSON reference object,
        a deep copy of it will be created with all contained JSON
        reference objects replaced by :class:`JsonRef` instances
    :param base_uri: URI to resolve relative references against
    :param loader: Callable that takes a URI and returns the parsed JSON
        (defaults to global ``jsonloader``, a :class:`JsonLoader` instance)
    :param jsonschema: Flag to turn on `JSON Schema mode
        <http://json-schema.org/latest/json-schema-core.html#anchor25>`_.
        'id' or '$id' keyword changes the `base_uri` for references contained
        within the object
    :param load_on_repr: If set to ``False``, :func:`repr` call on a
        :class:`JsonRef` object will not cause the reference to be loaded
        if it hasn't already. (defaults to ``True``)
    :param merge_props: When ``True``, JSON reference objects that
        have extra keys other than '$ref' in them will be merged into the
        document resolved by the reference (if it is a dictionary.) NOTE: This
        is not part of the JSON Reference spec, and may not behave the same as
        other libraries.
    :param proxies: If `True`, references will be replaced with transparent
        proxy objects. Otherwise, they will be replaced directly with the
        referred data. (defaults to ``True``)
    :param lazy_load: When proxy objects are used, and this is `True`, the
        references will not be resolved until that section of the JSON
        document is accessed. (defaults to ``True``)

    r%   Fr   r,   r-   r.   r8   r9   r   rG   c                     | j                   S r   rH   r   s    r   <lambda>zreplace_refs.<locals>.<lambda>Q  
    Q]] r   T)r^   c                     | j                   S r   r   r   s    r   r   zreplace_refs.<locals>.<lambda>S  r   r   )rM   r:   r   )	r1   r   r,   r-   r.   r8   proxies	lazy_loadrU   s	            r   r/   r/     sZ    R !i
F 62DA M 623Mr   c                   t        j                  |      \  }}	d }
|	s|s|}
|r\t        | t              rL| j	                  d      xs | j	                  d      }t        |t
              rt        j                  ||      }|}
t        | t              r:| j                         D ci c]  \  }}|t        |||||||||fz   d	        } }}nSt        | t              rCt        | t
              s3t        |       D cg c]  \  }}t        |||||||||fz   d	       } }}t        | t              r2t        | j	                  d      t
              rt        | |||||||      } |
| ||
<   | S c c}}w c c}}w )Nz$idr   Tr   r3   )r   r,   r-   r.   r8   r<   r=   )rB   rJ   r4   r   r5   r"   rC   rQ   rM   r   r   r)   )r1   r   r,   r-   r.   r8   r9   r   rG   frag	store_uriid_rV   rW   r   s                  r   rM   rM   W  s    ''1NHdI		jg.ggen-c3''#6H I #w 		
 1 }!%)'QD[
 

 
 
C	":c3+? "#
 1 !%)'QD[

 
  #wJswwv$D!%#	
 iJ_

s   "#E'7"E-c           
          |t        j                  t        fi |}t        t	        j
                  | fi ||||||||      S )a^  
    Drop in replacement for :func:`json.load`, where JSON references are
    proxied to their referent data.

    :param fp: File-like object containing JSON document
    :param **kwargs: This function takes any of the keyword arguments from
        :func:`replace_refs`. Any other keyword arguments will be passed to
        :func:`json.load`

    r   r,   r-   r.   r8   r   r   )	functoolspartialr7   r/   r   load)	fpr   r,   r-   r.   r8   r   r   rx   s	            r   r   r     sQ    , ~"":88		"!	 	r   c           
          |t        j                  t        fi |}t        t	        j
                  | fi ||||||||      S )aU  
    Drop in replacement for :func:`json.loads`, where JSON references are
    proxied to their referent data.

    :param s: String containing JSON document
    :param **kwargs: This function takes any of the keyword arguments from
        :func:`replace_refs`. Any other keyword arguments will be passed to
        :func:`json.loads`

    r   )r   r   r7   r/   r   r   )	sr   r,   r-   r.   r8   r   r   rx   s	            r   r   r     sQ    , ~"":88

1!	 	r   c           
      L    |t         }|| }t         ||       |||||||      S )z
    Load JSON data from ``uri`` with JSON references proxied to their referent
    data.

    :param uri: URI to fetch the JSON from
    :param **kwargs: This function takes any of the keyword arguments from
        :func:`replace_refs`

    r   )r7   r/   )r   r   r,   r-   r.   r8   r   r   s           r   load_urir     sB    ( ~s!	 	r   c                 :    |j                  t        | fi |       y)au  
    Serialize `obj`, which may contain :class:`JsonRef` objects, as a JSON
    formatted stream to file-like `fp`. `JsonRef` objects will be dumped as the
    original reference object they were created from.

    :param obj: Object to serialize
    :param fp: File-like to output JSON string
    :param kwargs: Keyword arguments are the same as to :func:`json.dump`

    N)writedumps)r1   r   rx   s      r   dumpr     s     HHU3!&!"r   c                     t        |j                  dt        j                              |d<   t        j                  | fi |S )a5  
    Serialize `obj`, which may contain :class:`JsonRef` objects, to a JSON
    formatted string. `JsonRef` objects will be dumped as the original
    reference object they were created from.

    :param obj: Object to serialize
    :param kwargs: Keyword arguments are the same as to :func:`json.dumps`

    r0   )_ref_encoder_factoryr5   r   JSONEncoderr   )r1   rx   s     r   r   r   !  s7     )E4;K;K)LMF5M::c$V$$r   c                 &      G  fdd       S )Nc                   <     e Zd Z fdZ fdZ fdZ xZS ),_ref_encoder_factory.<locals>.JSONRefEncoderc                 R    t        |d      r|j                  S t          |      S Nr*   )rO   r*   superdefault)r   oJSONRefEncoderr   r0   s     r   r   z4_ref_encoder_factory.<locals>.JSONRefEncoder.default1  s)    q/*&5a88r   c                 Z    t        |d      r|j                  }t        |   |g|i |S r   )rO   r*   r   _iterencoder   r   rw   rx   r   r   s       r   r   z8_ref_encoder_factory.<locals>.JSONRefEncoder._iterencode7  s2    q/*OO:1NtNvNNr   c                 Z    t        |d      r|j                  }t        |   |g|i |S r   )rO   r*   r   _encoder   s       r   r   z4_ref_encoder_factory.<locals>.JSONRefEncoder._encode=  s2    q/*OO6qJ4J6JJr   )r   r&   r'   r   r   r   __classcell__)r   r   r0   s   @r   r   r   0  s    	9	O	K 	Kr   r   r%   )r0   r   s   `@r   r   r   /  s    K K$ r   )FN)r$   NFTFTT)NNFTFTT)#r   r   r   collections.abcr   r   r   urllibr   rB   urllib.parser   urllib.requestr   r   callableResponseImportError
proxytypesr	   __version__rK   r   r)   r:   r7   r   r/   rM   r   r   r   r   r   r   r%   r   r   <module>r      s      = = $   "H%%**+ !!9 ! a2i a2H n  >62 8vHZ "N "N "J# %A  Hs   "B5 5B?>B?