
    01i                         S SK r S SKJr  S SKJr  S SKJrJr  / SQr " S S5      r	 " S S	\	5      r
 " S
 S\	5      r " S S\	5      r " S S\5      rg)    N)randint)RDF)BNodeURIRef)	ContainerBagSeqAltNoElementExceptionc                   z    \ rS rSrSr/ S4S jrS rS rS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rSrg)r   
   a  A class for constructing RDF containers, as per <https://www.w3.org/TR/rdf11-mt/#rdf-containers>

Basic usage, creating a `Bag` and adding to it:

```python
>>> from rdflib import Graph, BNode, Literal, Bag
>>> g = Graph()
>>> b = Bag(g, BNode(), [Literal("One"), Literal("Two"), Literal("Three")])
>>> print(g.serialize(format="turtle"))
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<BLANKLINE>
[] a rdf:Bag ;
    rdf:_1 "One" ;
    rdf:_2 "Two" ;
    rdf:_3 "Three" .
<BLANKLINE>
<BLANKLINE>

>>> # print out an item using an index reference
>>> print(b[2])
Two

>>> # add a new item
>>> b.append(Literal("Hello")) # doctest: +ELLIPSIS
<rdflib.container.Bag object at ...>
>>> print(g.serialize(format="turtle"))
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<BLANKLINE>
[] a rdf:Bag ;
    rdf:_1 "One" ;
    rdf:_2 "Two" ;
    rdf:_3 "Three" ;
    rdf:_4 "Hello" .
<BLANKLINE>
<BLANKLINE>

```
r   c                 
   Xl         U=(       d
    [        5       U l        SU l        X@l        U R                  U5        U R                   R                  U R                  [        R                  [        U R                     45        g)zCreates a Container

Args:
    graph: a Graph instance
    uri: URI or Blank Node of the Container
    seq: the elements of the Container
    rtype: the type of Container, one of "Bag", "Seq" or "Alt"
r   N)	graphr   uri_len_rtypeappend_multipleaddr   type)selfr   r   seqrtypes        J/home/james-whalen/.local/lib/python3.13/site-packages/rdflib/container.py__init__Container.__init__2   sZ     
>%'	S! 	

#((C,<=>    c                     / n[        [        U 5      5       H  nXS-      nUR                  U5        M     SSR                  U Vs/ s H  oDR	                  5       PM     sn5      -  $ s  snf )N   z( %s ) )rangelenappendjoinn3)r   itemsivas        r   r$   Container.n3F   s\    s4y!AUALLO " #((E#:EqDDFE#:;;;#:s   A(
c                     U R                   $ )z Returns the URI of the container)r   r   s    r   _get_containerContainer._get_containerN   s     xxr   c                     U R                   $ )zNumber of items in container)r   r+   s    r   __len__Container.__len__S   s     yyr   c                 N    [         R                  " S[        SS9  U R                  $ )Nzardflib.container.Container.type_of_conatiner is deprecated. Use type_of_container method instead.   )
stacklevel)warningswarnDeprecationWarningr   r+   s    r   type_of_conatinerContainer.type_of_conatinerX   s%    4		
 {{r   c                     U R                   $ N)r   r+   s    r   type_of_containerContainer.type_of_containera   s    {{r   c                    U R                   R                  U R                  U5      nU(       d  [        U< SS< 35      e[	        [        [        5      S-   5      nSnU H  n[        UR                  US5      5      nM      U$ )z@Returns the 1-based numerical index of the item in the containerz is not in 	container_N )	r   
predicatesr   
ValueErrorr   strr   intreplace)r   itempredli_indexr&   ps         r   indexContainer.indexd   sl     zz$$TXXt4$DEE#c(S.)AAIIh+,A r   c                 >   U R                  5       n[        U[        5      (       d   e[        [        5      S-   [        U5      -   nUS::  d  U[        U 5      :  a  [        U5      eU R                  R                  U[        U5      5      nU(       a  U$ [        U5      e)z*Returns item of the container at index keyr?   r   )
r,   
isinstancerD   rC   r   r!   KeyErrorr   valuer   )r   keycelem_urir'   s        r   __getitem__Container.__getitem__q   s     !#s####s8c>CH,!8sSY3-JJQx 01H3-r   c                    [        U[        5      (       d   eU R                  5       n[        [        5      S-   [        U5      -   nUS::  d  U[        U 5      :  a  [        U5      eU R                  R                  U[        U5      U45        g)zJSets the item at index key or predicate rdf:_key of the container to valuer?   r   N)
rM   rD   r,   rC   r   r!   rN   r   setr   )r   rP   rO   rQ   rR   s        r   __setitem__Container.__setitem__   sr     #s####!s8c>CH,!8sSY3-

6(+U34r   c                    [        U[        5      (       d   eUS::  d  U[        U 5      :  a  [        U5      eU R                  nU R
                  n[        [        5      S-   [        U5      -   nUR                  U[        U5      S45        [        US-   [        U 5      S-   5       H  n[        [        5      S-   [        U5      -   nUR                  U[        U5      5      nUR                  U[        U5      U45        [        [        5      S-   [        US-
  5      -   nUR                  U[        U5      U45        M     U =R                  S-  sl        g)z6Removing the item with index key or predicate rdf:_keyr   r?   Nr   )rM   rD   r!   rN   r   r   rC   r   remover   r    rO   r   r   )r   rP   r   r>   rR   jr'   s          r   __delitem__Container.__delitem__   s    #s####!8sSY3-

HH	s8c>CH,i!1489sQwD	A.A3x#~A.HIvh'78ALL)VH%5q9:3x#~AE
2HIIy&"2A67 / 			Q	r   c                    / nU R                   nSn [        [        5      S-   [        U5      -   nU[        U5      S4U R                  ;   a:  US-  nUR                  U R                  R                  U[        U5      5      5        O U$ My  )z,Returns a list of all items in the containerr   r?   N)r   rC   r   r   r   r"   rO   )r   l_r>   r&   rR   s        r   r%   Container.items   s     HH	3x#~A.H6(+T2djj@Q		$****9fX6FGH	 r   c                     U R                   nSn [        [        5      S-   [        U5      -   nU[        U5      S 4U R                  ;   a  US-  nOUS-
  $ MG  )Nr   r?   )r   rC   r   r   r   )r   r>   r&   rR   s       r   endContainer.end   sZ     HH	3x#~A.H6(+T2djj@Q1u r   c                     U R                  5       n[        [        5      S-   [        US-   5      -   nU R                  nU R                  R                  U[        U5      U45        U =R                  S-  sl        U $ )z'Adding item to the end of the containerr?   r   )rb   rC   r   r   r   r   r   r   )r   rF   rb   rR   r>   s        r   r"   Container.append   s`     hhjs8c>CaL0HH	

	6(#3T:;		Q	r   c                    U R                  5       nU R                  nU Hb  nUS-  nU =R                  S-  sl        [        [        5      S-   [        U5      -   nU R
                  R                  U[        U5      U45        Md     U $ )zSAdding multiple elements to the container to the end which are in python list otherr   r?   )rb   r   r   rC   r   r   r   r   )r   otherrb   r>   rF   rR   s         r   r   Container.append_multiple   sq     hhjHH	D1HCIINI3x#~C0HJJNNIvh'7>?	  r   c                 
   U R                   nU R                  nSn [        [        5      S-   [        U5      -   nU[	        U5      S4U R                  ;   a#  UR                  U[	        U5      S45        US-  nOOM`  SU l        U $ )z(Removing all elements from the containerr   r?   Nr   )r   r   rC   r   r   rZ   r   )r   r>   r   r&   rR   s        r   clearContainer.clear   s     HH	

3x#~A.H6(+T2djj@i)94@AQ  	r   )r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r$   r,   r/   r7   r;   rJ   rS   rW   r\   r%   rb   r"   r   rj   __static_attributes__ r   r   r   r   
   sZ    %N (* ?(<

 
5( 	r   r   c                   $    \ rS rSrSr/ 4S jrSrg)r      z5Unordered container (no preference order of elements)c                 2    [         R                  XX#S5        g )Nr   r   r   r   r   r   r   s       r   r   Bag.__init__       4%8r   rr   N)rl   rm   rn   ro   rp   r   rq   rr   r   r   r   r      s    ?') 9r   r   c                   &    \ rS rSr/ 4S jrS rSrg)r
      c                 2    [         R                  XX#S5        g )Nr
   rv   rw   s       r   r   Alt.__init__   ry   r   c                     [        U 5      S:X  a
  [        5       e[        S[        U 5      5      nU R                  U5      nU$ )Nr   r   )r!   r   r   rS   )r   rI   rF   s      r   anyone
Alt.anyone   s;    t9>$&&3t9%A##A&DKr   rr   N)rl   rm   rn   ro   r   r   rq   rr   r   r   r
   r
      s    ') 9r   r
   c                   &    \ rS rSr/ 4S jrS rSrg)r	      c                 2    [         R                  XX#S5        g )Nr	   rv   rw   s       r   r   Seq.__init__   ry   r   c                 <   [        U[        5      (       d   eUS::  d  U[        U 5      S-   :  a  [        S5      eU[        U 5      S-   :X  a  U R	                  U5        U $ [        [        U 5      US-
  S5       H  nU R                  5       n[        [        5      S-   [        U5      -   nU R                  R                  U[        U5      5      nU R                  R                  U[        U5      U45        [        [        5      S-   [        US-   5      -   nU R                  R                  U[        U5      U45        M     [        [        5      S-   [        U5      -   nU R                  R                  W[        U5      U45        U =R                  S-  sl        U $ )Nr   r   z1Invalid Position for inserting element in rdf:Seqr?   )rM   rD   r!   rB   r"   r    r,   rC   r   r   rO   r   rZ   r   r   )r   posrF   r[   r>   rR   r'   elem_uri_poss           r   add_at_positionSeq.add_at_position   sP   #s####!8sSY]*PQQ#d)a-KK  3t9cAgr2 //1	s8c>CF2JJ$$Yx0@A

!!9fX.>"BCs8c>CAJ6

	6(+;Q?@ 3 s8c>CH4LJJNNIvl';TBCIINIr   rr   N)rl   rm   rn   ro   r   r   rq   rr   r   r   r	   r	      s    ') 9r   r	   c                   $    \ rS rSrSS jrS rSrg)r   i  c                     Xl         g r:   message)r   r   s     r   r   NoElementException.__init__  s    r   c                     U R                   $ r:   r   r+   s    r   __str__NoElementException.__str__  s    ||r   r   N)zrdf:Alt Container is empty)rl   rm   rn   ro   r   r   rq   rr   r   r   r   r     s    r   r   )r4   randomr   rdflib.namespacer   rdflib.termr   r   __all__r   r   r
   r	   	Exceptionr   rr   r   r   <module>r      sS        %
BZ Zz9) 9
) 
) 2 r   