
    i              	      L   U d Z ddlmZ ddlZddlZ	 ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZmZmZ dd	lmZ dd
lmZmZ ddlmZmZmZ erddl m!Z! ddl"m#Z# g dZ$ ejJ                  e&      Z' G d de(      Z) G d de(      Z*h dZ+de,d<   ddhZ-de,d<    G d de.      Z/ G d de/      Z0 G d de)      Z1 e)d       Z2erdd!l3m4Z4 d"Z5 G d# d$      Z6g d%Z7e7d&gz   Z8e7g d'z   Z9g d(Z:d^d)Z;e8f	 	 	 	 	 d_d*Z<	 	 	 	 	 	 d`d+Z=dad,Z>dbd-Z?dd.l@mAZA dd/lBmCZC dd0lDmEZE dd1lFmGZG dd2lHmIZI dd3lJmKZK dd4lLmMZM dd5lNmOZO dd6lPmQZQ dd7lRmSZS dd8lTmUZU dd9lVmWZW dd:lXmYZY dd;lZm[Z[ dd<l\m]Z] dd=l^m_Z_ dd>l`maZa dd?lbmcZc dd@ldmeZe ddAlfmgZg ddBlhmiZi ddCljmkZk ddDllmmZm ddElnmoZo ddFlpmqZq ddGlrmsZs ddHltmuZu ddIlvmwZw eYeaecewe2dJZxi dKeAdLeCdMeEdNeIdOeKdPeMdQeGdReOdSeQdTeSdUeUdVeWdWe[dXe]dYe_dZeed[egeiekemeoeqeseud\Zyy# e$ r 	 ddlmZ n# e$ r d]dZY nw xY wY 	w xY w)ca  
===================
Namespace Utilities
===================

RDFLib provides mechanisms for managing Namespaces.

In particular, there is a :class:`~rdflib.namespace.Namespace` class
that takes as its argument the base URI of the namespace.

.. code-block:: pycon

    >>> from rdflib.namespace import Namespace
    >>> RDFS = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")

Fully qualified URIs in the namespace can be constructed either by attribute
or by dictionary access on Namespace instances:

.. code-block:: pycon

    >>> RDFS.seeAlso
    rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#seeAlso')
    >>> RDFS['seeAlso']
    rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#seeAlso')


Automatic handling of unknown predicates
-----------------------------------------

As a programming convenience, a namespace binding is automatically
created when :class:`rdflib.term.URIRef` predicates are added to the graph.

Importable namespaces
-----------------------

The following namespaces are available by directly importing from rdflib:

* BRICK
* CSVW
* DC
* DCAT
* DCMITYPE
* DCTERMS
* DCAM
* DOAP
* FOAF
* ODRL2
* ORG
* OWL
* PROF
* PROV
* QB
* RDF
* RDFS
* SDO
* SH
* SKOS
* SOSA
* SSN
* TIME
* VANN
* VOID
* WGS
* XSD

.. code-block:: pycon

    >>> from rdflib.namespace import RDFS
    >>> RDFS.seeAlso
    rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#seeAlso')
    )annotationsN)get_annotationsc                    | j                   S N)__annotations__)things    HC:\Projects\mas-dev\.venv\Lib\site-packages\rdflib/namespace/__init__.pyr   r   Y   s    (((    )	lru_cache)Path)	TYPE_CHECKINGAnyDictIterableListOptionalSetTupleUnion)category)	urldefragurljoin)URIRefVariable_is_valid_uri)Graph)Store)"	is_ncname	split_uri	NamespaceClosedNamespaceDefinedNamespaceNamespaceManagerBRICKCSVWDCDCAMDCATDCMITYPEDCTERMSDOAPFOAFGEOODRL2ORGOWLPROFPROVQBRDFRDFSSDOSHSKOSSOSASSNTIMEVANNVOIDWGSXSDc                  ^     e Zd ZdZd	dZed
d       ZddZddZddZ	d fdZ
ddZ xZS )r    a  
    Utility class for quickly generating URIRefs with a common prefix

    >>> from rdflib.namespace import Namespace
    >>> n = Namespace("http://example.org/")
    >>> n.Person # as attribute
    rdflib.term.URIRef('http://example.org/Person')
    >>> n['first-name'] # as item - for things that are not valid python identifiers
    rdflib.term.URIRef('http://example.org/first-name')
    >>> n.Person in n
    True
    >>> n2 = Namespace("http://example2.org/")
    >>> n.Person in n2
    False
    c                    	 t         j                  | |      }|S # t        $ r t         j                  | |d      }Y |S w xY wNzutf-8)str__new__UnicodeDecodeErrorclsvaluerts      r	   rD   zNamespace.__new__   sF    	2S%(B 	 " 	2S%1B		2s     >>c                    t        | dz         S )Ntitle)r   selfs    r	   rK   zNamespace.title   s     dWn%%r
   c                N    t        | t        |t              r|z         S dz         S )N )r   
isinstancerC   rM   names     r	   termzNamespace.term   s&    djs&;dDEEDEEr
   c                $    | j                  |      S r   rS   rM   keys     r	   __getitem__zNamespace.__getitem__       yy~r
   c                R    |j                  d      rt        | j                  |      S N__)
startswithAttributeErrorrS   rQ   s     r	   __getattr__zNamespace.__getattr__   s"    ??4   yyr
   c                (    dt         |           dS )N
Namespace()super__repr__rM   	__class__s    r	   re   zNamespace.__repr__   s    EG,./q11r
   c                $    |j                  |       S )a  Allows to check if a URI is within (starts with) this Namespace.

        >>> from rdflib import URIRef
        >>> namespace = Namespace('http://example.org/')
        >>> uri = URIRef('http://example.org/foo')
        >>> uri in namespace
        True
        >>> person_class = namespace['Person']
        >>> person_class in namespace
        True
        >>> obj = URIRef('http://not.example.org/bar')
        >>> obj in namespace
        False
        r]   rM   refs     r	   __contains__zNamespace.__contains__   s     ~~d##r
   )rH   Union[str, bytes]returnr    rn   r   rR   rC   rn   r   rW   rC   rn   r   rn   rC   rk   rC   rn   bool)__name__
__module____qualname____doc__rD   propertyrK   rS   rX   r_   re   rl   __classcell__rg   s   @r	   r    r       s;      & &F
2$r
   r    c                  D     e Zd ZdZddZd fdZd fdZd fdZ xZS )	
URIPatterna8  
    Utility class for creating URIs according to some pattern
    This supports either new style formatting with .format
    or old-style with % operator

    >>> u=URIPattern("http://example.org/%s/%d/resource")
    >>> u%('books', 12345)
    rdflib.term.URIRef('http://example.org/books/12345/resource')

    c                    	 t         j                  | |      }|S # t        $ r3 t        rt	        |t
              sJ t         j                  | |d      }Y |S w xY wrB   )rC   rD   rE   r   rP   bytesrF   s      r	   rD   zURIPattern.__new__   sY    	2S%(B
 		 " 	2!%///S%1B			2s    8AAc                4    t        t        |   |i |      S r   )r   rd   __mod__rM   argskwargsrg   s      r	   r   zURIPattern.__mod__   s    egot6v677r
   c                4    t        t        |   |i |      S r   )r   rd   formatr   s      r	   r   zURIPattern.format   s    egnd5f566r
   c                (    dt         |           dS )NzURIPattern(rb   rc   rf   s    r	   re   zURIPattern.__repr__   s    UW-/022r
   )rH   rm   rn   r}   ro   rr   )	ru   rv   rw   rx   rD   r   r   re   rz   r{   s   @r	   r}   r}      s!    	873 3r
   r}   >   _NS_fail_warn_extras	__slots___underscore_numzSet[str]_DFNS_RESERVED_ATTRS_pytestfixturefunction_partialmethod_IGNORED_ATTR_LOOKUPc                       e Zd ZU dZ e       Zded<   ded<   dZded<   d	Zded
<   g Z	ded<   d	Z
ded<    ed      ddd       Zd fdZddZddZddZddZddZddZ xZS ) DefinedNamespaceMetaz>Utility metaclass for generating URIRefs with a common prefix.Tuple[str, ...]r   r    r   Trt   r   Fr   	List[str]r   r   N)maxsizec                \   t        |      }|t        v rt        d|      |t        v r
t               | j                  s| j
                  rS|| vrO| j
                  rt        d| d| j                   d      t        j                  d| d| j                   d       | j                  |   S )	Nz6DefinedNamespace like object has no access item named term '' not in namespace ''zCode: z is not defined in namespace    )
stacklevel)rC   r   KeyErrorr   r   r   r^   r   warningswarnru   )rG   rR   defaults      r	   rX   z DefinedNamespaceMeta.__getitem__  s    4y''HQ  ))*IICyy$vdV3GyPQ%RSSTF"?~N  wwt}r
   c                    |t         v r
t               |t        v rt        d|      |j                  d      rt        t
        |   |      S | j                  |      S )Nz.DefinedNamespace like object has no attribute r\   )r   r^   r   r]   rd   r   __getattribute__rX   )rG   rR   rg   s     r	   r_   z DefinedNamespaceMeta.__getattr__$  se    '' "")) @I  __T"-sDTJJt$$r
   c                \    	 t        | j                        }d| dS # t        $ r d}Y w xY w)N<DefinedNamespace>ra   rb   )reprr   r^   )rG   ns_reprs     r	   re   zDefinedNamespaceMeta.__repr__/  s;    	+377mG G9A&&  	+*G	+s    ++c                L    	 t        | j                        S # t        $ r Y yw xY w)Nr   )rC   r   r^   )rG   s    r	   __str__zDefinedNamespaceMeta.__str__6  s'    	(sww< 	('	(s    	##c                $    | j                  |      S r   )rX   )rG   others     r	   __add__zDefinedNamespaceMeta.__add__<  s    u%%r
   c                     	  j                   }t        |      j                  t        |            rt	        t        |            d t         fd j                         D              S # t        $ r Y yw xY w)zGDetermine whether a URI or an individual item belongs to this namespaceFNc              3     K   | ]^  }t        |t              rLt        |      v xs; |j                  v xs+ j                  xr d    dk(  xr dd j                          ` yw)r   _   N)
issubclassr"   r   r   r   isdigit).0crG   item_strs     r	   	<genexpr>z4DefinedNamespaceMeta.__contains__.<locals>.<genexpr>H  s{      
 !-.	 ** W199$W##Us(:Ux|?S?S?UW s   A$A')r   r^   rC   r]   lenanymro)rG   itemthis_nsr   s   `  @r	   rl   z!DefinedNamespaceMeta.__contains__?  sz    	ggG t9s7|,CL 1 34H 
 WWY	
 
 	
  		s   A/ /	A;:A;c                    t        |       D ch c]  }t        |       }}|j                  t               |D ch c]  }| t        |          }}|S c c}w c c}w r   )r   rC   difference_updater   )rG   xattrsvaluess       r	   __dir__zDefinedNamespaceMeta.__dir__P  s[    !0!56!5AQ!56 45',-u!#c!f+u-	 7 .s
   AAc                    |t        | j                        i}t        |       j                         D ]   \  }}t	        |t
              s| d| ||<   " d|iS )z;Returns this DefinedNamespace as a JSON-LD 'context' object:z@context)rC   r   r   itemsr   r   )rM   pfxtermsrW   rS   s        r	   as_jsonld_contextz&DefinedNamespaceMeta.as_jsonld_contextW  sZ    c$((m$(.446IC$' #uAcU^c
 7 E""r
   r   rp   )rR   rC   rr   )r   rC   rn   r   )r   rC   rn   rt   )rn   zIterable[str])r   rC   rn   dict)ru   rv   rw   rx   tupler   r   r   r   r   r   r   rX   r_   re   r   r   rl   r   r   rz   r{   s   @r	   r   r     sy    H!&I(	NE4E4GY!OT!t &	%'(&
"#r
   r   c                  0    e Zd ZU dZ e       Zded<   d Zy)r"   z
    A Namespace with an enumerated list of members.
    Warnings are emitted if unknown members are referenced if _warn is True
    r   r   c                    t        d      )Nz!namespace may not be instantiated)	TypeErrorrL   s    r	   __init__zDefinedNamespace.__init__i  s    ;<<r
   N)ru   rv   rw   rx   r   r   r   r    r
   r	   r"   r"   a  s    
 "'I(=r
   r"   )	metaclassc                  z     e Zd ZU dZded<   d fdZedd       ZddZddZ	ddZ
dd	Zdd
ZddZddZ xZS )r!   zf
    A namespace with a closed list of members

    Trying to create terms not listed is an error
    zDict[str, URIRef]_ClosedNamespace__urisc                v    t         |   | |      }|D ci c]  }|t        ||z          c}|_        |S c c}w r   )rd   rD   r   r   )rG   urir   rI   trg   s        r	   rD   zClosedNamespace.__new__v  s@    W_S#&0561QrAv&6		 7s   6c                    t        |       S r   )rC   rL   s    r	   r   zClosedNamespace.uri{  s    4yr
   c                d    | j                   j                  |      }|t        d| d|  d      |S )Nr   r   r   )r   getr   )rM   rR   r   s      r	   rS   zClosedNamespace.term  s9    kkood#;VD6)=dV1EFF
r
   c                $    | j                  |      S r   rU   rV   s     r	   rX   zClosedNamespace.__getitem__  rY   r
   c                    |j                  d      rt        	 | j                  |      S # t        $ r}t        |      d }~ww xY wr[   )r]   r^   rS   r   )rM   rR   es      r	   r_   zClosedNamespace.__getattr__  sB    ??4   (yy& ($Q''(s   * 	A>Ac                f    | j                    d| j                  j                   dt        |       dS )N.(rb   )rv   rg   ru   rC   rL   s    r	   re   zClosedNamespace.__repr__  s/    //"!DNN$;$;#<Ac$i]!LLr
   c                ,    t        | j                        S r   )listr   rL   s    r	   r   zClosedNamespace.__dir__  s    DKK  r
   c                :    || j                   j                         v S r   )r   r   rj   s     r	   rl   zClosedNamespace.__contains__  s    4;;%%''	
r
   c                    t        |       S r   )dirrL   s    r	   _ipython_key_completions_z)ClosedNamespace._ipython_key_completions_  s    4yr
   )r   rC   r   r   rr   rp   rq   )rn   r   rs   )ru   rv   rw   rx   r   rD   ry   r   rS   rX   r_   re   r   rl   r   rz   r{   s   @r	   r!   r!   m  sM     
  (M!

r
   r!   z$http://www.w3.org/XML/1998/namespace)_NamespaceSetStringTc                      e Zd ZdZdddZddZddZedd       ZddZ	dddZ
ddZdd	Zddd
Z	 d	 	 	 	 	 ddZddZddZ	 	 d	 	 	 	 	 	 	 	 	 d dZd!dZd"d#dZy)$r#   a  Class for managing prefix => namespace mappings

    This class requires an RDFlib Graph as an input parameter and may optionally have
    the parameter bind_namespaces set. This second parameter selects a strategy which
    is one of the following:

    * core:
        * binds several core RDF prefixes only
        * owl, rdf, rdfs, xsd, xml from the NAMESPACE_PREFIXES_CORE object
    * rdflib:
        * binds all the namespaces shipped with RDFLib as DefinedNamespace instances
        * all the core namespaces and all the following: brick, csvw, dc, dcat
        * dcmitype, dcterms, dcam, doap, foaf, geo, odrl, org, prof, prov, qb, schema
        * sh, skos, sosa, ssn, time, vann, void
        * see the NAMESPACE_PREFIXES_RDFLIB object for the up-to-date list
        * this is default
    * none:
        * binds no namespaces to prefixes
        * note this is NOT default behaviour
    * cc:
        * using prefix bindings from prefix.cc which is a online prefixes database
        * not implemented yet - this is aspirational

    .. attention::

        The namespaces bound for specific values of ``bind_namespaces``
        constitute part of RDFLib's public interface, so changes to them should
        only be additive within the same minor version. Removing values, or
        removing namespaces that are bound by default, constitutes a breaking
        change.

    See the
    Sample usage

    .. code-block:: pycon

        >>> import rdflib
        >>> from rdflib import Graph
        >>> from rdflib.namespace import Namespace, NamespaceManager
        >>> EX = Namespace('http://example.com/')
        >>> namespace_manager = NamespaceManager(Graph())
        >>> namespace_manager.bind('ex', EX, override=False)
        >>> g = Graph()
        >>> g.namespace_manager = namespace_manager
        >>> all_ns = [n for n in g.namespace_manager.namespaces()]
        >>> assert ('ex', rdflib.term.URIRef('http://example.com/')) in all_ns
        >>>
    c                   || _         i | _        i | _        d | _        i | _        i | _        |dk(  ry |dk(  r]t        j                         D ]  \  }}| j                  ||        t        j                         D ]  \  }}| j                  ||        y |dk(  rt        d      |dk(  r/t        j                         D ]  \  }}| j                  ||        y t        d|       )NnonerdflibcczHaven't got to this option yetcorezunsupported namespace set )graph_NamespaceManager__cache_NamespaceManager__cache_strict_NamespaceManager__log_NamespaceManager__strie_NamespaceManager__trie_NAMESPACE_PREFIXES_RDFLIBr   bind_NAMESPACE_PREFIXES_CORENotImplementedError
ValueError)rM   r   bind_namespacesprefixnss        r	   r   zNamespaceManager.__init__  s    
;=BD
')&( f$ (8>>@
		&"% A 7<<>
		&"% ?$
 &&FGG&6<<>
		&"% ? 9/9JKLLr
   c                H    t        fd| j                         D              S )Nc              3  F   K   | ]  \  }}j                  |        y wr   ri   )r   r   r   rk   s      r	   r   z0NamespaceManager.__contains__.<locals>.<genexpr>  s!     J8I*&"3>>"%8Is   !)r   
namespacesrj   s    `r	   rl   zNamespaceManager.__contains__  s    
 J8IJJJr
   c                    i | _         i | _        i | _        | j                         D ]$  \  }}t	        | j                  t        |             & y r   )r   r   r   r   insert_trierC   )rM   pns      r	   resetzNamespaceManager.reset  s>    OO%DAqSV, &r
   c                .    | j                   j                  S r   )r   storerL   s    r	   r  zNamespaceManager.store  s    zzr
   c                `    | j                  |      \  }}}|dk(  r|S dj                  ||f      S NrO   r   compute_qnamejoinrM   r   r   	namespacerR   s        r	   qnamezNamespaceManager.qname  s8    "&"4"4S"9	4R<K88VTN++r
   c                V    | j                  ||      \  }}}dj                  ||f      S )a  
        From a URI, generate a valid CURIE.

        Result is guaranteed to contain a colon separating the prefix from the
        name, even if the prefix is an empty string.

        .. warning::

            When ``generate`` is `True` (which is the default) and there is no
            matching namespace for the URI in the namespace manager then a new
            namespace will be added with prefix ``ns{index}``.

            Thus, when ``generate`` is `True`, this function is not a pure
            function because of this side-effect.

            This default behaviour is chosen so that this function operates
            similarly to `NamespaceManager.qname`.

        :param uri: URI to generate CURIE for.
        :param generate: Whether to add a prefix for the namespace if one doesn't
            already exist.  Default: `True`.
        :return: CURIE for the URI.
        :raises KeyError: If generate is `False` and the namespace doesn't already have
            a prefix.
        )generater   r  )rM   r   r  r   r  rR   s         r	   curiezNamespaceManager.curie  s3    4 #'"4"4S8"4"L	4xx''r
   c                `    | j                  |      \  }}}|dk(  r|S dj                  ||f      S r  )compute_qname_strictr  r  s        r	   qname_strictzNamespaceManager.qname_strict5  s8    "&";";C"@	4R<K88VTN++r
   c                   	 t        |      \  }}|| j                  vr*t        | j                  | j                  t	        |             t        t	        |            }| j                  j                  |      }|t        |t              rd|z  S |d|z  S | j                  |      }dj                  |d   |d   g      S # t        $ r t        |t              rd|z  cY S d|z  cY S w xY w)z
        Takes an RDF Term and 'normalizes' it into a QName (using the
        registered prefix) or (unlike compute_qname) the Notation 3
        form for URIs: <...URI...>
        z?%sz<%s>r   r   )r   r   insert_strier   rC   r   	ExceptionrP   r   r  r   r  r  )rM   rdfTermr  rR   r   
qNamePartss         r	   normalizeUrizNamespaceManager.normalizeUri<  s    		('0OIt,T\\4;;IGs9~.I ""9->j(;7?"^G##++G4J88Z]JrN;<<  	('8,w&''		(s   AB? ?C'C'&C'c                "   || j                   vr/t        |      st        dj                  |            	 t	        |      \  }}|| j                  vr!t        | j                  | j                  |       | j                  |   r+t        | j                  |   |      }||}|t        |      d  }t        |      }| j                  j                  |      }|X|st        dj                  |            d}	 d|z  }| j                  j                  |      sn|dz  }'| j                  ||       |||f| j                   |<   | j                   |   S # t        $ r7}t        |      }| j                  j                  |      }d}|s|Y d }~Ed }~ww xY w)NzY"{}" does not look like a valid URI, cannot serialize this. Did you want to urlencode it?rO   )No known prefix for {} and generate=Falser   ns%s)r   r   r   r   r   r   r  r   r   r  r   get_longest_namespacer   r   r  r   )	rM   r   r  r  rR   r   r   pl_namespacenums	            r	   r  zNamespaceManager.compute_qnameU  s   dll" % ovv "+C.	4 ,T\\4;;	B||I&4T\\)5LcR+ ,Is9~/0Dy)IZZ&&y1F~"CJJ9U  #c\F:://71HC	 
 		&),!'D 9DLL||C  ?  "3K	**95G 	s   E 	F,F		Fc                   | j                  ||      \  }}}t        t        |            r|||fS || j                  vr	 t	        |t
              \  }}|| j                  vr!t        | j                  | j                  |       t        |      }| j                  j                  |      }|X|st        dj                  |            d}	 d|z  }| j                  j                  |      sn|dz  }'| j!                  ||       |||f| j                  |<   | j                  |   S # t        $ r dj                  |      }t        |      w xY w)Nz^This graph cannot be serialized to a strict format because there is no valid way to shorten {}r  r   r  )r  r   rC   r   r   NAME_START_CATEGORIESr   r   r   r  r   r   r  r   r   r  r   )rM   r   r  r   r  rR   messager  s           r	   r  z%NamespaceManager.compute_qname_strict  sh    #'"4"4S("C	4SY9d**$---.&/5J&KOIt DLL0 t{{IF #9-	** >#&GNN ) 
 C!'##zz33F;!q	 
 IIfi0,2It+D##C(&&s++W " .FFLfSk  %W--.s   D" "&Ec                v   t        |      t        ur"t        dt        |      j                   d      |j	                  dd      }t        |      dk7  rt        d      | j                  j                  |d         }|t        t        |       |d          S t        d|j	                  d      d    d	      )
aw  
        Expand a CURIE of the form <prefix:element>, e.g. "rdf:type"
        into its full expression:

        >>> import rdflib
        >>> g = rdflib.Graph()
        >>> g.namespace_manager.expand_curie("rdf:type")
        rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')

        Raises exception if a namespace is not bound to the prefix.

        zArgument must be a string, not r   r   r      u@   Malformed curie argument, format should be e.g. “foaf:name”.r   zPrefix "z" not bound to any namespace.)
typerC   r   ru   splitr   r   r  r  r   )rM   r  partsr   s       r	   expand_curiezNamespaceManager.expand_curie  s     E{c!=d5k>R>R=SSTUVVC#u:?R  ZZ!!%(+>SWIeAhZ011EKK,Q/00NO r
   c                b   t         s| j                  j                  ||      S 	 | j                  j                  |||      S # t        $ rc}dt	        |      v rLt
        j                  dt        | j                        d       | j                  j                  ||      cY d }~S Y d }~y d }~ww xY w)Noverrider(  z}caught a TypeError, retrying call to %s.bind without override, see https://github.com/RDFLib/rdflib/issues/1880 for more infoT)exc_info)_with_bind_override_fixr  r   r   rC   loggerdebugr"  )rM   r   r  r(  errors        r	   _store_bindzNamespaceManager._store_bind  s    &::??6955	:::??69x?HH 		:SZ'U $!   zzvy99 (		:s   A 	B.AB)B.)B.c                   t        t        |            }|d}nd|v rt        d      | j                  j	                  |      }|rt        |      }|r||k7  r|r4| j                  |||       t        | j                  t        |             y|sd}d}	 ||}| j                  j	                  |      }|r|t        |      k(  ry| j                  j	                  |      sn|dz  }T| j                  |||       n_| j                  j                  |      }	|	| j                  |||       n-|	|k(  rn'|s|	j                  d      r| j                  |||       t        | j                  t        |             y)	zBind a given namespace to the prefix

        If override, rebind, even if the given namespace is already
        bound to another prefix.

        If replace, replace any existing prefix with the new namespace

        NrO    z Prefixes may not contain spaces.r'  r   r   r   )
r   rC   r   r  r  r.  r   r   r   r]   )
rM   r   r  r(  replacebound_namespacer  
new_prefix
tnamespacebound_prefixs
             r	   r   zNamespaceManager.bind  sx     3y>*	>FF]=>>**..v6 $_5O);  X FDKKY8
 "C'-s3
!ZZ11*=
)vj/A"A zz++J7q  ZXF::,,Y7L#  X F'|66s;$$VY$JDKKY0r
   c              #  r   K   | j                   j                         D ]  \  }}t        |      }||f  y wr   )r  r   r   )rM   r   r  s      r	   r   zNamespaceManager.namespaces-  s7     !%!6!6!8FIy)I)## "9s   57c                    t        j                         j                         }t        d|z  ||       }|rt	        |      d   }|s|r|d   dk(  r|d   dk7  rd|z  }t        |      S )Nz%s/)allow_fragmentsr   r  #z%s#)r   cwdas_urir   r   r   )rM   r   defragbaseresults        r	   
absolutizezNamespaceManager.absolutize2  sj    xxz  "sJGv&q)Fs2w#~&**;f~r
   N)r   )r   r   r   r   rs   )rn   None)rn   r   )r   rC   rn   rC   )T)r   rC   r  rt   rn   rC   )r  rC   rn   rC   )r   rC   r  rt   rn   zTuple[str, URIRef, str])r   rC   r  rt   rn   zTuple[str, str, str])r  rC   rn   r   )r   rC   r  r   r(  rt   rn   r@  )TF)
r   Optional[str]r  r   r(  rt   r1  rt   rn   r@  )rn   zIterable[Tuple[str, URIRef]])r   )r   rC   r<  intrn   r   )ru   rv   rw   rx   r   rl   r   ry   r  r	  r  r  r  r  r  r%  r.  r   r   r?  r   r
   r	   r#   r#     s    /b#MJK-    ,(:,=2+!\ *.:,:,"&:,	:,x8:( A1A1 A1 	A1
 A1 
A1F$
r
   r#   )LlLuLoLtNlNd)McMeMnLmrH  )   ·u   ·-r   r   %r   rb   c                    | rW| d   }|dk(  st        |      t        v r<t        dt        |             D ]#  }| |   }t        |      t        vs|t
        v r# y yy)Nr   r   r   )r   r  ranger   NAME_CATEGORIESALLOWED_NAME_CHARS)rR   firstir   s       r	   r   r   l  sb    QC<8E?.CC1c$i(G{o5..  ) r
   c                   | j                  t              rt        | j                  t              d   fS t        |       }t	        d|      D ]i  }| | dz
     }t        |      t        vs|t        v r't	        d|z
  |      D ]0  }t        | |         |v s	| |   dk(  s| d | }|s n| |d  }||fc c S   n t        dj                  |             )Nr   r   r  r   zCan't split '{}')
r]   XMLNSr#  r   rQ  r   rR  rS  r   r   )r   split_startlengthrU  r   jr   lns           r	   r   r     s     ~~esyy'*++XF1fQK{o-&&266*CF#{2c!fmRaBQRB8O +   '..s3
44r
   c                J   || v r| |   S d}t        | j                               D ]o  }t        |      t        |      kD  r"|j                  |      rt	        | |   |      c S |j                  |      sN|si | |<   d}| j                  |      }|| |   |<   q || vri | |<   | |   S )zInsert a value into the trie if it is not already contained in the trie.
    Return the subtree for the value regardless of whether it is a new value
    or not.FT)r   keysr   r]   r   pop)trierH   multi_checkrW   dict_s        r	   r   r     s     }E{KTYY[!u:C U%5%5c%:tCy%00^^E" U"HHE  %DK " DU;r
   c                ,    || vrt        ||      | |<   y y r   )r   )strier_  rH   s      r	   r  r    s    E"4/e r
   c                f    | D ],  }|j                  |      st        | |   |      }||c S |c S  y r   )r]   r  )r_  rH   rW   outs       r	   r  r    s>    C 'S	59C{

  r
   )r$   )r%   )r&   )r'   )r(   )r)   )r*   )r+   )r,   )r-   )r.   )r/   )r0   )r1   )r2   )r3   )r4   )r5   )r6   )r7   )r8   )r9   )r:   )r;   )r<   )r=   )r>   )r?   )owlrdfrdfsxsdxmlbrickcsvwdcdcatdcmitypedctermsdcamdoapfoafgeoodrlorgprofprovqbschemash)skossosassntimevannvoidwgs)r   r   rn   r   )rR   rC   rn   rB  )r   rC   rX  r   rn   zTuple[str, str])r_  Dict[str, Any]rH   rC   rn   r  )rc  r  r_  r  rH   rC   rn   r@  )r_  r  rH   rC   rn   rA  )zrx   
__future__r   loggingr   annotationlibr   ImportErrorinspect	functoolsr   pathlibr   typingr   r   r   r   r   r   r   r   r   unicodedatar   urllib.parser   r   rdflib.termr   r   r   rdflib.graphr   rdflib.storer   __all__	getLoggerru   r+  rC   r    r}   r   r   r   r"  r   r"   r!   rW  rdflib._type_checkingr   r*  r#   r  SPLIT_START_CATEGORIESrR  rS  r   r   r   r  r  rdflib.namespace._BRICKr$   rdflib.namespace._CSVWr%   rdflib.namespace._DCr&   rdflib.namespace._DCAMr'   rdflib.namespace._DCATr(   rdflib.namespace._DCMITYPEr)   rdflib.namespace._DCTERMSr*   rdflib.namespace._DOAPr+   rdflib.namespace._FOAFr,   rdflib.namespace._GEOr-   rdflib.namespace._ODRL2r.   rdflib.namespace._ORGr/   rdflib.namespace._OWLr0   rdflib.namespace._PROFr1   rdflib.namespace._PROVr2   rdflib.namespace._QBr3   rdflib.namespace._RDFr4   rdflib.namespace._RDFSr5   rdflib.namespace._SDOr6   rdflib.namespace._SHr7   rdflib.namespace._SKOSr8   rdflib.namespace._SOSAr9   rdflib.namespace._SSNr:   rdflib.namespace._TIMEr;   rdflib.namespace._VANNr<   rdflib.namespace._VOIDr=   rdflib.namespace._WGSr>   rdflib.namespace._XSDr?   r   r   r   r
   r	   <module>r     s  FP #  )    X X X   + 7 7""#J 
		8	$<$ <$~3 3F" h  " h Y#4 Y#x	=!5 	=0i 0f 	899 R Rn 7 .$7 '*HHG ( (>5	5$55.
!$20
 * ' # ' ' / - ' ' % ) % % ' ' # % ' % # ' ' % ' ' ' % %  U
D 	" D	
  w D D D 
3 E 
3 D D 	"  c!" 	"#$ 1 k  ))+ )	))	)s5   H H#	HH#	HH#HH#"H#