
    jKj                        d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddl	m
Z
 ddl	mZ ee
e   ee   f   Z eh d	      Zdd
Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZddZ e        y)a  Compatibility shim for the ``referencing`` library's private API.

This module is the *only* place in jsonschema-path that touches
``referencing._core`` internals (the ``_base_uri``, ``_registry``, and
``_previous`` attributes on ``Resolver``). Every other module must go
through the helpers here.

The motivation is firewalling: if a future ``referencing`` release
reshapes those internals, the breakage is contained to this file. The
``assert_referencing_layout`` call at import time also converts what
would otherwise be silent wrong-results into a loud ``ImportError`` that
names the issue, so version-skew bugs surface immediately.

The helpers intentionally use ``Any``-typed generics because
``referencing`` does not expose ``Resolver`` / ``Resolved`` as
``attrs``-typed classes to type checkers, and ``Resolver._evolve``
itself is declared ``**kwargs: Any``. The runtime invariants are
enforced by ``assert_referencing_layout``; ``mypy`` is asked to trust
this single module.

Supported ``referencing`` versions: the upper bound is pinned in
``pyproject.toml``; the lower bound is implied by these internals being
``attrs`` fields named ``_base_uri``, ``_registry``, and ``_previous``.
    )annotations)Any)UnionN)Registry)Resolved)Resolver>   	_base_uri	_previous	_registryc                     t        j                  t              D  ch c]  } | j                   }} t        |z
  }|r(t        dt        t               dt        |       d      yc c} w )a  Verify ``referencing.Resolver`` exposes the attrs fields we rebind.

    Called once at import time. Raises ``ImportError`` if the installed
    ``referencing`` is incompatible, instead of allowing rebind operations
    to silently produce wrong results.
    zyjsonschema-path is incompatible with the installed version of `referencing`. Expected `Resolver` attrs fields to include z
; missing zX. Pin `referencing` to a supported version (see jsonschema_path/_referencing_compat.py).N)attrsfieldsr   name_REQUIRED_RESOLVER_FIELDSImportErrorsorted)fieldr   missings      t/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/jsonschema_path/_referencing_compat.pyassert_referencing_layoutr   )   s     \\(++E 	

+   (&0G789g  DD
 	
 s   A%c                0    t        j                  | |      S )a  Return a new resolver identical to *resolver* but with *registry*.

    ``referencing.Registry`` instances are immutable and grow
    monotonically via ``with_resource``. A cached ``Resolver`` captured
    before the registry grew can be cheaply rebound to the latest
    registry without re-walking the schema, because:

    * The resolver's ``base_uri`` describes a document scope that the
      newer registry, being a superset, still contains.
    * ``Resolver._previous`` holds URIs (not resolver snapshots), and
      ``Resolver.dynamic_scope`` re-uses ``self._registry`` for every
      frame, so swapping the top resolver's registry rebinds the entire
      dynamic scope in one shot.

    Uses ``attrs.evolve`` rather than ``Resolver._evolve`` because the
    latter pushes onto the dynamic-scope stack when called with a
    differing ``base_uri``. We want a pure field replacement.
    )registry)r   evolve)resolverr   s     r   rebind_registryr   ?   s    , <<844    c                X    t        | j                  t        | j                  |            S )u  Return a new ``Resolved`` with the same ``contents`` but a
    resolver rebound to *registry*.

    Centralizing the ``Resolved(...)`` construction here keeps the
    ``call-arg`` type-ignore confined to a single line — production
    callers (``SchemaAccessor.get_resolved`` and
    ``CachedPathResolver._resolve_with_prefix_cache``) work in terms of
    this helper and don't have to construct ``Resolved`` themselves.
    )contentsr   )r   r   r   r   )resolvedr   s     r   rebind_resolvedr    X   s*     "" !2!2H= r   c                f    t        | t              r| j                  j                  S | j                  S )z3Return the registry backing a Resolved or Resolver.)
isinstancer   r   r   targets    r   registry_ofr%   k   (    &(#(((r   c                f    t        | t              r| j                  j                  S | j                  S )z.Return the base URI of a Resolved or Resolver.)r"   r   r   r	   r#   s    r   base_uri_ofr(   r   r&   r   )returnNone)r   Resolver[Any]r   Registry[Any]r)   r+   )r   Resolved[Any]r   r,   r)   r-   )r$   ResolvedOrResolverr)   r,   )r$   r.   r)   str)__doc__
__future__r   typingr   r   r   referencingr   referencing._corer   r   r.   	frozensetr   r   r   r    r%   r(    r   r   <module>r7      s   2 #      & &8C=(3-78 %&MN 
,555 52 &  r   