
    4Ysh2                     
   d dl mZmZmZmZ d dlm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mZmZmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZmZ d dlZddl m!Z! g dZ" G d de      Z#dZ$dZ% ed      Z&d Z' G d de      Z(y)    )IODictOptionalSet)	XMLWriter)	NamespaceRDFRDFS)RDFVOC)Graph)
IdentifierURIRefLiteralBNode)first	more_than)
Collection)
Serializer)	quoteattrescapeN   )ESCAPE_ENTITIES)fixXMLSerializerPrettyXMLSerializerc                   f     e Zd Zdef fdZd Z	 	 d
dee   dee	   dee	   fdZ
ddZdd	Z xZS )r   storec                 ,    t         t        |   |       y N)superr   __init__)selfr   	__class__s     /var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/serializers/rdfxml.pyr!   zXMLSerializer.__init__   s    mT+E2    c              #   :  K   | j                   }|j                  }i }t        |j                               D ]%  }|j	                  |      \  }}}t        |      ||<   ' t        d      }d|v r
|d   |k(  sJ ||d<   |j                         D ]  \  }}||f  y w)N+http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf)r   namespace_managerset
predicatescompute_qname_strictr   items)	r"   r   nmbindings	predicateprefix	namespacenameRDFNSs	            r$   
__bindingszXMLSerializer.__bindings   s     

$$U--/0 	1I&(&=&=i&H#FIt%i0HV	1 DEHE?e+++#HUO!)!1 	$FI)##	$s   BBstreambaseencodingc                    ||| _         n1| j                  j                   | j                  j                   | _         | _        i | _        | j                  fdx| _        } |d| j                  z          |d       d|v r |d|d   z         n!| j                   r |d| j                   z         t        | j                               }|j                          |D ]"  \  }}|r |d|d|d        |d	|z         $  |d
       | j                  j                         D ]  }	| j                  |	d         |d       | `y )Nc                 F    j                  | j                  d            S )Nreplace)writeencode)unir8   r6   s    r$   <lambda>z)XMLSerializer.serialize.<locals>.<lambda>;   s    cjj96U)V r%   z$<?xml version="1.0" encoding="%s"?>
z	<rdf:RDF
xml_basez   xml:base="%s"
z	   xmlns:z="z"
z   xmlns="%s"
>
r   z</rdf:RDF>
)r7   r   _XMLSerializer__stream_XMLSerializer__serializedr8   r<   list_XMLSerializer__bindingssortsubjectssubject)
r"   r6   r7   r8   argsr<   r/   r1   r2   rH   s
    ` `      r$   	serializezXMLSerializer.serialize,   s<    DIZZ__(

DI35==VV
U 	5EF 	l &j)99:YY&23 )*!) 	5FIfi@A')34		5
 	e zz**, 	%GLL!$	% 	n r%   c                    || j                   vrd| j                   |<   t        |t        t        f      r| j                  }d|z  }d}t        |t              r ||d|d|d       n*t        | j                  |            } ||d|d|       |d d f| j                  v rP |d       | j                  j                  |      D ]  \  }}| j                  |||dz            ||d	|d       y  |d
       y y y )Nr     zrdf:Description< rdf:nodeID=""z rdf:about=rA   <//>
)
rC   
isinstancer   r   r<   r   
relativizer   predicate_objectsr0   )	r"   rH   depthr<   indentelement_nameurir0   objects	            r$   rH   zXMLSerializer.subject`   s    $+++)*Dg&'E6?3

0gu-V\7ST#DOOG$<=C&,LMT4(DJJ6%L-1ZZ-I-I'-R E)	6y&%!)DE>? &M' 4 ,r%   c                    | j                   }d|z  }| j                  j                  j                  |      }t	        |t
              rcd}|j                  r|d|j                  z  z  }|j                  r|d|j                  z  z  } ||d||dt        |t              d|d	       y t	        |t              r ||d|d	|d
       y  ||d|dt        | j                  |            d       y )NrL    z xml:lang="%s"z rdf:datatype="%s"rM   >rP   rA   rN   z"/>
z rdf:resource=rQ   )r<   r   r)   qname_strictrR   r   languagedatatyper   r   r   r   rS   )r"   r0   rY   rU   r<   rV   qname
attributess           r$   r0   zXMLSerializer.predicatey   s    



,,99)Dfg&J.@@
2V__DD
5*fV_.MuV &%(VUFKLui0G&HJr%   NNr   )__name__
__module____qualname__r   r!   rE   r   bytesr   strrJ   rH   r0   __classcell__r#   s   @r$   r   r      sT    3e 3$, #"&	25	2 sm2 3-	2h"2r%   r   z(http://www.w3.org/XML/1998/namespacelangz(http://www.w3.org/XML/1998/namespacebasezhttp://www.w3.org/2002/07/owl#c                 2    | j                  d      r| dd S | S )z:strip off _: from nodeIDs... as they are not valid NCNamesz_:   N)
startswith)vals    r$   r   r      s    
~~d12w
r%   c                   l     e Zd Zddef fdZ	 	 ddee   dee   dee   fdZ	dde
defd	Zdd
Z xZS )r   r   c                 J    t         t        |   |       t               | _        y r   )r    r   r!   r*   forceRDFAbout)r"   r   	max_depthr#   s      r$   r!   zPrettyXMLSerializer.__init__   s    !41%8*-%r%   r6   r7   r8   c                     i | _         | j                  }||| _        n|j                  |j                  | _        |j                  dd      | _        | j                  dkD  sJ d       |j
                  x| _        }t        |||      x| _        }i }t        |j                               j                  |j                  d t        j                              }	|	D ]  }
|j                  |
      \  }}}|||<    d|d<   |j!                  t"        j                         d|v r|j%                  t&        |d          n,| j                  r |j%                  t&        | j                         |j)                  |j+                                |j-                         D ]6  }d d |f|v r|d |f|v s| j/                  |d       %| j/                  |d       8 t               }|j-                         D ]6  }t1        |t2              r|j5                  |       %| j/                  |d       8 |D ]#  }|| j                   vs| j/                  d       % |j7                  t"        j                         |j9                  d	j;                  d
             d | _         y )Nrr      r   z max_depth must be greater than 0r'   r(   r@   r   
zlatin-1) _PrettyXMLSerializer__serializedr   r7   getrr   r)   r.   r   writerr*   r+   unionobjectsr	   typer,   pushr   	attributeXMLBASE
namespacesr-   rG   rH   rR   r   addpopr<   r=   )r"   r6   r7   r8   rI   r   r.   rx   r   possibler0   r1   r2   localrH   bnodesbnodes                    r$   rJ   zPrettyXMLSerializer.serialize   sL    46

DIZZ#

DI+q1~~!E#EE!..."(X>>f
u'')*00tSXX1NO! 	+I')'>'>y'I$FIu!*Jv	+ J
5FJJWd:&67YYWdii0***,- ~~' 	)GdG$-T7+u4LL!,Wa(	) ~~' 	%G'5)

7#LL!$		%  	)ED---Wa(	) 	

6::T[[+, !r%   rH   rU   c                 ^   | j                   }| j                  }|| j                  v r|j                  t        j
                         |j                  t        j                  | j                  |             |j                  t        j
                         | j                  j                  |       y || j                  vrNd| j                  |<   t        |j                  |t        j                              }	 | j                   j#                  |       |xs t        j
                  }|j                  |       t%        |t&              r5d } |d      rY|j                  t        j(                  t+        |             n/|j                  t        j                  | j                  |             |d d f|v rH|j-                  |      D ]4  \  }}	|t        j                  k(  r|	|k(  r| j/                  ||	|dz          6 |j                  |       y || j                  v r|j                  t        j
                         |j                  t        j                  | j                  |             |j                  t        j
                         | j                  j                  |       y y #  d }Y xY w)Nr   c                      y)NT )ceils    r$   subj_as_obj_more_thanz:PrettyXMLSerializer.subject.<locals>.subj_as_obj_more_than  s    r%   )r   rx   rq   r|   r   Descriptionr}   aboutrS   r   removerv   r   rz   r	   r{   r.   r`   rR   r   nodeIDr   rT   r0   )
r"   rH   rU   r   rx   r{   elementr   r0   rY   s
             r$   rH   zPrettyXMLSerializer.subject   s	   

d(((KK**+V\\4??7+CDJJv))*%%g.D---)*Dg&w9:Dd# 0f00GKK '5)  )+$$V]]CLA   tw/GHt$-).)@)@)I E%Iv%1fny&%!)DE JJw***KK**+V\\4??7+CDJJv))*%%g. +9s   8J% %J,c                    | j                   }| j                  }|j                  |       t        |t              r|j
                  r |j                  t        |j
                         |j                  t        j                  k(  rt        |j                  t        j                  j                  j                        rN|j                  t         j"                  d       |j%                  d       |j&                  j)                  |       nF|j                  r*|j                  t         j                  |j                         |j%                  |       n|| j*                  v s|d d f|vrt        |t,              rJt/        |j1                  d d |f      d      r|j                  t         j2                  t5        |             n|j                  t         j6                  | j9                  |             n]t;        |j=                  |t        j:                              rd| j*                  |<   dd l}|jA                  dtC        |      z  dz   tD        d       |j                  t         j"                  d	       tG        ||      }|D ]^  }t        |tH              r| jJ                  jM                  |       | jO                  |       t        |tH              rPd| j*                  |<   ` nit;        |jQ                  |t        jR                  tT        jV                  tX        jV                  gf            r@t        |tH              r0|j                  t         j6                  | j9                  |             n|| jZ                  k  r| jO                  ||dz          nt        |t,              r||| j*                  vrD|d d f|v r=t]        t_        |ja                  |
                  dk(  r| jO                  ||dz          nY|j                  t         j2                  t5        |             n/|j                  t         j6                  | j9                  |             |jc                  |       y )Nr   r[   r   r   z&Assertions on %s other than RDF.first z/and RDF.rest are ignored ... including RDF.Listrl   )
stacklevelr   )rY   )2rx   r   r|   rR   r   r^   r}   XMLLANGr_   r	   
XMLLiteralvaluexmldomminidomDocumentr   	parseTypetextr6   r<   rv   r   r   triplesr   r   resourcerS   r   rz   warningswarnreprUserWarningr   r   rq   r   rH   triples_choicesr{   OWL_NSClassr
   rr   lenrD   rG   r   )	r"   r0   rY   rU   rx   r   r   colitems	            r$   r0   zPrettyXMLSerializer.predicate   s2   

Ifg&  &//:#..0Zcggoo666   !1!19=B##F+??$$V__fooFF#t(((t0D0M&%(U]]D$+?@!D$$V]]CK@  $//&2IJ U]]639956 -.!!&)  <tF|KGH 	     !1!1<@ / 4D!$/**..t4LL&%dF323))$/4 ))FLL$**+EF !0$$V__doof6MNdnn,LL3. d&7&77#T40E9U^^6^%B CDI VUQY7((FD $$V__doof6MN

9r%   )rt   rb   rc   )rd   re   rf   r   r!   r   rg   r   rh   rJ   r   intrH   r0   ri   rj   s   @r$   r   r      sc    0e 0 #"&	B!5	B! smB! 3-	B!H1/z 1/# 1/fSr%   r   ))typingr   r   r   r   $rdflib.plugins.serializers.xmlwriterr   rdflib.namespacer   r	   r
   rdflib.plugins.parsers.RDFVOCr   rdflib.graphr   rdflib.termr   r   r   r   rdflib.utilr   r   rdflib.collectionr   rdflib.serializerr   xml.sax.saxutilsr   r   xml.dom.minidomr   	xmlwriterr   __all__r   r   r~   r   r   r   r   r%   r$   <module>r      sp    * * : 1 1 0  : : ( ( ( .  &
9~J ~B 5
4	3	4O* Or%   