
    giSF                        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n# e$ r dZY nw xY w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"dS )    N)MappingMutableMappingSequence)parse)unquote)urlopen)	LazyProxyz1.1.0c                   "    e Zd ZddZd Zd ZdS )JsonRefError  Nc                 h    || _         || _        || _        || _        || _        |x| _        | _        d S N)message	referenceuribase_uripathcause	__cause__)selfr   r   r   r   r   r   s          _/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/jsonref.py__init__zJsonRefError.__init__   s7    " 	&++
T^^^    c                 2    d| j         j        d| j        dS )N<: >)	__class____name__r   r   s    r   __repr__zJsonRefError.__repr__    s      !^444dlllCCr   c                 *    t          | j                  S r   )strr   r!   s    r   __str__zJsonRefError.__str__#   s    4<   r   )r   r   r   N)r    
__module____qualname__r   r"   r%   r   r   r   r   r      sI        , , , ,D D D! ! ! ! !r   r   c                       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dS )JsonRefzc
    A lazy loading proxy to the dereferenced data pointed to by a JSON
    Reference object.

    )__reference__r   NFTc                 *    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   r   c	                 0   t          |                    d          t                    st          d|z            || _        || _        |pt          | _        || _        || _	        || _
        || _        || _        | j        t                      | _        d S d S )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2 	ODvMNNN# *
$(&	
: DJJJ r   c           	      t    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   s>    ];*(*
 
 
 	
r   c                 L    t          j        | j        | j        d                   S )Nr3   )urlparseurljoinr   r*   r!   s    r   full_urizJsonRef.full_uriw   s    t/A&/IJJJr   c                    t          j        | j                  \  }}|| j        vrw	 |                     |          }nF# t
          $ r9}|                     |j        j        dt          |          |          |d }~ww xY wt          |fi i | j        |dd}n| j        |         }|                     ||          }|| u r|                     d          t          |d          r|j        }| j        rTt!          |t"                    r?t%          | j                  dk    r'i |d | j                                        D             }|S )	Nr   r   F)r   	recursingz$Reference refers directly to itself.__subject__   c                 &    i | ]\  }}|d k    ||S )r3   r   ).0kvs      r   
<dictcomp>z$JsonRef.callback.<locals>.<dictcomp>   s#    NNNDAq!v++1a+++r   )rB   	urldefragrD   r9   r,   	Exception_errorr   r    r$   _replace_refsr@   resolve_pointerhasattrrH   r8   r4   r   lenr*   items)r   r   fragmentbase_doceresults         r   callbackzJsonRef.callback{   s    *4=99X dj  ;;s++   kk ! 4 4 4c!fff=Q "   % Ut/USuUUU HH z#H%%h99T>>++DEEE6=)) 	('F	67++	 D&''!++NND$6$<$<$>$>NNNF s   = 
B 4A;;B c                    |r5t          |                    d                                        d          ng }|D ]}|                    dd                              dd          }t	          |t
                    r!	 t          |          }n# t          $ r Y nw xY w|| u r| j        }	 ||         }w# t          t          f$ r }|                     d|z  |          |d}~ww xY w|S )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LookupErrorrQ   )r   documentpointerpartspartrY   s         r   rS   zJsonRef.resolve_pointer   s$    <CJs++,,223777 	 	D<<c**224==D(H-- t99DD!   D 4-#D>{+   kk3g=Q "   s*   >B
BB*B33C$CC$c                     d                     | 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   rQ   zJsonRef._error   sK    299$-QQ]
 
 
 	
r   c                 l    t          | d          s| j        rt          | j                  S d| j        z  S )NcachezJsonRef(%r))rT   r.   reprrH   r*   r!   s    r   r"   zJsonRef.__repr__   s=    4!! 	*T%6 	*()))t111r   )r   NFT)r   NFTFr   Nr   )r    r&   r'   __doc____notproxied__classmethodr/   r   propertyr@   rD   r[   rS   rQ   r"   r   r   r   r)   r)   '   s          (NKO 
  
  
 [ 
J # # # #0 	
 	
 X	
 K K XK  B  <	
 	
 	
 	
2 2 2 2 2r   r)   c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )r:   z8
    Dictionary which uses normalized URIs as keys.
    c                 N    t          j        |                                          S r   )rB   urlsplitgeturlr   r   s     r   	normalizezURIDict.normalize   s     %%,,...r   c                 P    t                      | _         | j        j        |i | d S r   )r?   r9   update)r   argskwargss      r   r   zURIDict.__init__   s-    VV

4*6*****r   c                 B    | j         |                     |                   S r   r9   rw   rv   s     r   __getitem__zURIDict.__getitem__   s    z$..--..r   c                 @    || j         |                     |          <   d S r   r}   )r   r   values      r   __setitem__zURIDict.__setitem__   s     */
4>>#&&'''r   c                 <    | j         |                     |          = d S r   r}   rv   s     r   __delitem__zURIDict.__delitem__   s    Jt~~c**+++r   c                 *    t          | j                  S r   )iterr9   r!   s    r   __iter__zURIDict.__iter__       DJr   c                 *    t          | j                  S r   )rU   r9   r!   s    r   __len__zURIDict.__len__   s    4:r   c                 *    t          | j                  S r   )rm   r9   r!   s    r   r"   zURIDict.__repr__   r   r   N)r    r&   r'   rn   rw   r   r~   r   r   r   r   r"   r   r   r   r:   r:      s         / / /+ + +/ / /0 0 0, , ,                r   r:   c                    t          j        |           j        }|dv rvt          rot          j        |           }|                                 	  |j        di |}n# t          $ r+ t          j	        d           |                                }Y nbw xY wt          |           5 }t          j        |                                                    d          fi |}ddd           n# 1 swxY w Y   |S )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   rt   schemerequestsr5   raise_for_statusjsonrc   warningswarnr   loadsreaddecode)r   r{   r   resprZ   contents         r   r7   r7      sJ    s##*F"""x"|C   		!TY((((FF 	! 	! 	!MSTTTYY[[FFF	!
 S\\ 	JWZ 5 5g > >II&IIF	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J Ms$   A 2BB#8C''C+.C+Fc                    |pi }t          |           }||v r||         S t          |           t          u r ||           }|r|n| } | ||<   t          | t                    r5|                                 D ]\  }}t          ||||          }|r|| |<    nYt          | t                    rDt          | t                    s/t          |           D ]\  }}t          ||||          }|r|| |<    | S )N)ra   
_processed)
idtyper)   r4   r   rV   
_walk_refsr   r$   	enumerate)	r1   funcra   r   oidrrL   rM   is	            r   r   r     s&   !rJ
S''C
j#CyyGDII#aaJsO#w 	IIKK 	 	DAq1dG
KKKA A	 
C	"	" :c3+?+? cNN 	 	DAq1dG
KKKA AJr   r   Tc                     t          | |||||t                      dd	  	        }|st          |d d           n|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)ra   c                     | j         S r   r   r   s    r   r   zreplace_refs.<locals>.<lambda>S  r   r   )rR   r:   r   )	r1   r   r,   r-   r.   r8   proxies	lazy_loadrZ   s	            r   r/   r/     s    R !ii
 
 
F  4622DAAAAA 4622333Mr   c          
         t          j                  \  }	d }
|	s|s}
rkt          | t                    rV|                     d          p|                     d          }t          |t
                    rt          j        |          }
t          | t                    r'fd|                                 D             } nKt          | t                    r6t          | t
                    s!fdt          |           D             } t          | t                    r?t          |                     d          t
                    rt          |           } |
| |
<   | S )Nz$idr   c                 P    i | ]"\  }}|t          |	|fz   d 	  	        #S Tr   rR   )
rK   rL   rM   r   r-   r.   r,   r8   r   r9   s
      r   rN   z!_replace_refs.<locals>.<dictcomp>p  sa     
 
 
 1 }!%)'QD[
 
 

 
 
r   c                 N    g | ]!\  }}t          |	|fz   d 	  	        "S r   r   )
rK   r   rM   r   r-   r.   r,   r8   r   r9   s
      r   
<listcomp>z!_replace_refs.<locals>.<listcomp>  s_     
 
 
 1 !%)'QD[
 
 

 
 
r   r3   )r   r,   r-   r.   r8   r<   r=   )rB   rO   r4   r   r5   r$   rC   rV   r   r   r)   )r1   r   r,   r-   r.   r8   r9   r   rG   frag	store_uriid_s    ```````    r   rR   rR   W  s    '11NHdI 	 	 !jg.. !ggenn-c3 	!'#66H I #w 

 
 
 
 
 
 
 
 
 
 		
 
 
 
C	"	" 
:c3+?+? 

 
 
 
 
 
 
 
 
 
 "#
 
 
  #w 

Jswwv$D$D 

!%#	
 	
 	
 iJr   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`

    Nr   r,   r-   r.   r8   r   r   )	functoolspartialr7   r/   r   load)	fpr   r,   r-   r.   r8   r   r   r{   s	            r   r   r     sb    , ~":88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`

    Nr   )r   r   r7   r/   r   r   )	sr   r,   r-   r.   r8   r   r   r{   s	            r   r   r     sb    , ~":8888
1!	 	 	 	r   c           
      \    |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`

    Nr   )r7   r/   )r   r   r,   r-   r.   r8   r   r   s           r   load_urir     sP    ( ~s!	 	 	 	r   c                 F    |                     t          | fi |           dS )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   r{   s      r   dumpr     s,     HHU3!!&!!"""""r   c                     t          |                    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   r{   s     r   r   r   !  s>     )E4;K)L)LM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                 x    t          |d          r|j        S t                                        |          S Nr*   )rT   r*   superdefault)r   oJSONRefEncoderr   r0   s     r   r   z4_ref_encoder_factory.<locals>.JSONRefEncoder.default1  s;    q/** '&--55a888r   c                 p    t          |d          r|j        } t          |           j        |g|R i |S r   )rT   r*   r   _iterencoder   r   rz   r{   r   r   s       r   r   z8_ref_encoder_factory.<locals>.JSONRefEncoder._iterencode7  sI    q/** $O:5..:1NtNNNvNNNr   c                 p    t          |d          r|j        } t          |           j        |g|R i |S r   )rT   r*   r   _encoder   s       r   r   z4_ref_encoder_factory.<locals>.JSONRefEncoder._encode=  sI    q/** $O65..6qJ4JJJ6JJJr   )r    r&   r'   r   r   r   __classcell__)r   r   r0   s   @r   r   r   0  s        	9 	9 	9 	9 	9 	9 	9	O 	O 	O 	O 	O 	O	K 	K 	K 	K 	K 	K 	K 	K 	K 	Kr   r   r   )r0   r   s   `@r   r   r   /  sP    K K K K K K K K K 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__rP   r   r)   r:   r7   r   r/   rR   r   r   r   r   r   r   r   r   r   <module>r      s         = = = = = = = = = = $ $ $ $ $ $             " " " " " "OOO8H%*++    HHH !          ! ! ! ! !9 ! ! ! a2 a2 a2 a2 a2i a2 a2 a2H         n      >  6   2 8 8 8 8vH H HZ " " " "N " " " "N " " " "J# # # % % %    s   A AA