
    4YshS                        d Z ddl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 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZ ddlmZ g dZeZej:                  ej<                  ej>                  ej@                  ejB                  dZ"ej                  ej<                  ej:                  ejB                  ej@                  ejF                  ejH                  gZ%e%ejL                  ejN                  gz   Z( ed       ed       ed      gZ)e%ejN                  gz   e)z   Z*ej<                  ejF                  ej:                  gZ+e%ejL                  gz   e)z   Z,e%ejL                  ejN                  gz   e)z   Z-ej<                  ej@                  ejF                  gZ.dZ/e/dfZ0e/dfZ1 G d de      Z2 G d de3      Z4 G d dejj                        Z6dejn                  fdZ8 G d de      Z9y )!z
An RDF/XML parser for RDFLib
    )make_parserhandler	xmlreader)ErrorHandler)	quoteattrescape)	urldefragurljoin)	is_ncname)RDF)RDFVOC)URIRef)BNode)Literal)ParserErrorError)Parser)create_parserBagIDElementHandlerRDFXMLHandlerRDFXMLParser)aboutIDtyperesource	parseTypez4http://www.w3.org/1999/02/22-rdf-syntax-ns#aboutEachz:http://www.w3.org/1999/02/22-rdf-syntax-ns#aboutEachPrefixz0http://www.w3.org/1999/02/22-rdf-syntax-ns#bagID$http://www.w3.org/XML/1998/namespacebaselangc                   *     e Zd ZdgZ fdZd Z xZS )r   lic                 :    t         t        |   |       d| _        y Nr   )superr   __init__r"   )selfval	__class__s     }/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/parsers/rdfxml.pyr&   zBagID.__init__T   s    fd$S)    c                 X    | xj                   dz  c_         t        d| j                   z     S N   z_%s)r"   RDFNSr'   s    r*   next_lizBagID.next_liX   s"    1UTWW_%%r+   )__name__
__module____qualname__	__slots__r&   r1   __classcell__)r)   s   @r*   r   r   Q   s    I&r+   r   c                        e Zd Zg dZd Zd Zy)r   )startcharendr"   idr   subject	predicateobjectlistlanguagedatatypedeclareddatac                     d | _         d | _        d | _        d| _        d | _        d | _        d | _        d | _        d | _        d | _	        d | _
        d | _        d | _        y r$   )r8   r9   r:   r"   r;   r   r<   r>   r?   r@   rA   rB   rC   r0   s    r*   r&   zElementHandler.__init__o   s]    
				r+   c                 X    | xj                   dz  c_         t        d| j                   z     S r-   )r"   r   r0   s    r*   r1   zElementHandler.next_li~   s"    1edggo&&r+   N)r2   r3   r4   r5   r&   r1    r+   r*   r   r   ]   s    I"'r+   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Z ee      Zd Z ee      Zd Z ee      Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"y)r   c                 @    || _         d| _        | j                          y )NF)storepreserve_bnode_idsreset)r'   rI   s     r*   r&   zRDFXMLHandler.__init__   s    
"'

r+   c                     t               }| j                  |_        d |_        d |g| _        i | _        i | _        i g| _        | j                  d   | _        y )Nc                      y NrF   )nameqnames     r*   <lambda>z%RDFXMLHandler.reset.<locals>.<lambda>   s    r+   )	r   document_element_startr8   r:   stackidsbnode_ns_contexts_current_context)r'   document_elements     r*   rK   zRDFXMLHandler.reset   s_    )+!%!<!<7

 
D $ 1 1" 5r+   c                     || _         y rN   )locator)r'   r[   s     r*   setDocumentLocatorz RDFXMLHandler.setDocumentLocator   s	    r+   c                      y rN   rF   r0   s    r*   startDocumentzRDFXMLHandler.startDocument       r+   c                     | j                   j                  | j                  j                                || j                  |<   | j                  j                  ||xs dd       y )N F)override)rW   appendrX   copyrI   bind)r'   prefix	namespaces      r*   startPrefixMappingz RDFXMLHandler.startPrefixMapping   sO      !6!6!;!;!=>+1i(

	R%@r+   c                 F    | j                   d   | _        | j                   d= y NrR   )rW   rX   )r'   rf   s     r*   endPrefixMappingzRDFXMLHandler.endPrefixMapping   s#     $ 1 1" 5b!r+   c                    | j                   }|j                  t                      | j                  }| j                  }|j                  t        d       }|xt        |      \  }}|r#|j                  rt        |j                  |      }n| j                  j                         xs | j                  j                         }	|	rct        |	|      }nV|r|j                  }|F| j                  j                         xs | j                  j                         }	|	rt        |	      \  }}||_        |j                  t        d       }
|
|r|j                  }
|
|_        |j                  |||       y rN   )rT   rc   r   currentparentgetBASEr	   r   r
   r[   getPublicIdgetSystemIdLANGr@   r8   )r'   rO   rP   attrsrT   rm   rn   r   fragsystemIdr@   s              r*   startElementNSzRDFXMLHandler.startElementNS   s"   

^%&,,yyt$"4JD$&++v{{D1<<335S9Q9Q9S"8T2D{{|<<335S9Q9Q9S!*8!4JD$99T4(!??#dE5)r+   c                 p    | j                   j                  ||       | j                  j                          y rN   )rm   r:   rT   popr'   rO   rP   s      r*   endElementNSzRDFXMLHandler.endElementNS   s$    u%

r+   c                 F    | j                   j                  }|r	 ||       y y rN   )rm   r9   )r'   contentr9   s      r*   
characterszRDFXMLHandler.characters   s     ||  M r+   c                      y rN   rF   )r'   r}   s     r*   ignorableWhitespacez!RDFXMLHandler.ignorableWhitespace   r_   r+   c                      y rN   rF   )r'   targetrC   s      r*   processingInstructionz#RDFXMLHandler.processingInstruction   r_   r+   c                    |\  }}}| j                   j                  |t        j                  t        j                  f       | j                   j                  |t        j
                  |f       | j                   j                  |t        j                  |f       | j                   j                  |t        j                  |f       y rN   )rI   addr   r   	Statementr<   r=   r>   )r'   sidspospos         r*   add_reifiedzRDFXMLHandler.add_reified   s}    1a

SXXs}}56

S[[!,-

S]]A./

SZZ+,r+   c                     | j                   }|j                         d|j                         d|j                         d}t	        ||z         )N:z: )r[   rr   getLineNumbergetColumnNumberr   )r'   messager[   infos       r*   errorzRDFXMLHandler.error   sG    ,,!!!###%

 $.))r+   c                      | j                   d   S )NrT   r0   s    r*   get_currentzRDFXMLHandler.get_current       zz"~r+   c                      | j                   d   S rj   r   r0   s    r*   get_nextzRDFXMLHandler.get_next   r   r+   c                      | j                   d   S )Nr   r0   s    r*   
get_parentzRDFXMLHandler.get_parent   r   r+   c                     t        | j                  j                  |d      }|r|d   dk(  r|d   dk7  rd|z  }t        |      S )Nr.   )allow_fragmentsrR   #z%s#)r
   rm   r   r   )r'   uriresults      r*   
absolutizezRDFXMLHandler.absolutize   sE    **CC3r7c>fRjC&7V^Ff~r+   c                 p   |d   t        |d         }nt        dj                  |            }i }|j                         D ]p  \  }}|d   |d   }ndj                  |      }|j                  t              s|dd j                         dk(  rN|t        v r||t        |   <   c||t        |      <   r ||fS )Nr   r.   ra      xml)r   joinitems
startswithXMLNSlowerUNQUALIFIEDr/   )r'   rO   rP   rt   attsnvatts           r*   convertzRDFXMLHandler.convert   s    7?$q'?D"''$-(Dkkm 	&FQt|dggaj~~e$Aa(8E(A##$U3Z $%VC[!	& Tzr+   c                     |d   rZt        dj                  |            t        j                  k(  r/t	        | d      }| j
                  |_        | j                  |_        y | j                  |||       y )Nr   ra   next)	r   r   r   r   getattrnode_element_startr8   node_element_endr:   )r'   rO   rP   rt   r   s        r*   rS   z$RDFXMLHandler.document_element_start  sY    7vbggdm,

:4(D00DJ,,DH##D%7r+   c                    | j                  |||      \  }}| j                  }| j                  }t        | d      }| j                  |_        | j                  |_        |t        v r| j                  d|z         t        j                  |v rt        j                  |v st        j                  |v r| j                  d       |t        j                     }t        |      s| j                  d|z          |d|z        }	|	| j                  v r| j                  d|	z         d| j                  |	<   n6t        j                  |v rt        j                  |v st        j                  |v r| j                  d       |t        j                     }
t        |
      s| j                  d|
z         | j                   d	u r8|
| j"                  v r| j"                  |
   }	nt%               }	|	| j"                  |
<   nwt%        |
      }	nkt        j                  |v rOt        j                  |v st        j                  |v r| j                  d        ||t        j                           }	n
t%               }	|t        j&                  k7  r2| j(                  j+                  |	t,        j.                   ||      f       |j0                  }|D ]  }|j3                  t5        t6                    s ||      }	 t9        ||   |      }n{|t,        j.                  k(  r*t,        j.                  } ||t,        j.                           }n>|t>        v r|t@        v r| j                  d
|z          ||      }	 t9        ||   |      }| j(                  j+                  |	|f        |	|_!        y # t:        $ r%}| j                  |j<                         Y d }~Qd }~ww xY w# t:        $ r%}| j                  |j<                         Y d }~d }~ww xY w)Nr   zInvalid node element URI: %sz9Can have at most one of rdf:ID, rdf:about, and rdf:nodeIDz&rdf:ID value is not a valid NCName: %s#%sz)two elements cannot use the same ID: '%s'r.   *rdf:nodeID value is not a valid NCName: %sF"Invalid property attribute URI: %s)"r   rm   r   r   property_element_startr8   property_element_endr:   NODE_ELEMENT_EXCEPTIONSr   r   r   r   nodeIDr   rU   rJ   rV   r   DescriptionrI   r   r   r   r@   r   strr/   r   r   msgNODE_ELEMENT_ATTRIBUTESPROPERTY_ATTRIBUTE_EXCEPTIONSr<   )r'   rO   rP   rt   r   rm   r   r   r;   r<   r   r@   r   r=   r>   es                   r*   r   z RDFXMLHandler.node_element_start  s6   \\$u5
d,,__
 tV$00
,,**JJ5<=99||t#v}}'<

VWfiiBR=

CbHI ,G$(("

FPQ !DHHW]]d"yyD FLLD$8

VW&--(FV$

G&PQ&&%/TZZ'"jj0G#gG)0DJJv&-\\T!yyD FMMT$9

VW fll!34GgG6%%%JJNNGSXXz$/?@A## 	9C>>#e*-&sO	&$T#Y9F HH	#DN3//55

?#EF&sO	&$T#Y9F JJNNGY78+	9. "%  &JJquu%%&  &JJquu%%&s0   #NO	ON??O	O5O00O5c                     | j                   j                  r?| j                  | j                  d   k7  r#| j	                  ddj                  |      z         | j                  j                  | j                   _        y )N   z1Repeat node-elements inside property elements: %sra   )rn   r>   rm   rT   r   r   r<   rz   s      r*   r   zRDFXMLHandler.node_element_endh  sX     ;;$,,$**Q-"?JJCbggdmS "\\11r+   c                 
   | j                  |||      \  }}| j                  }| j                  }t        | d      }d }d |_        d |_        |j                  t        t                    s ||      |_	        nS|t        j                  k(  r|j                         |_	        n*|t        v r| j                  d|z         n ||      |_	        |j                  t        j                   d       }	|	0t#        |	      s| j                  d|	z          |d|	z        |_        nd |_        |j                  t        j&                  d       }
|j                  t        j(                  d       }|j                  t        j*                  d       }|
|| j                  d       |
, ||
      }| j,                  |_        | j0                  |_        n'|t#        |      s| j                  d|z         | j4                  du r:|| j6                  v r| j6                  |   }n)t9               }|| j6                  |<   |}nt9        |      x}}| j,                  |_        | j0                  |_        n|U|D ]>  }|t        j*                  k7  s|t        j                   k7  s+| j                  d|z         @ |d	k(  rLt9               x|_        }| j<                  |_        | j@                  |_        | jB                  |_        ||_,        y |d
k(  rHd |_        tD        jF                  x}|_        | j,                  |_        | jH                  |_        ||_,        y tK        dt        jL                        }| jN                  |_        tP        di|_)        | jT                  |_        | jN                  |_        | jV                  |_        ||_,        y d }| j<                  |_        | j,                  |_        | j0                  |_        |j                  t        jZ                  d       x}|_-        |j\                  }|	 ||      }n|D ]  }|j                  t        t                    s	 ||      }n.|t^        v r3|t`        v r| j                  d|z         n ||      }|tD        jb                  k(  rte        ||         }n|d }tK        ||   ||      }|
t9               }| jf                  ji                  ||f        |d|_        d |_,        y d |_        ||_,        y )Nr   z Invalid property element URI: %sz&rdf:ID value is not a value NCName: %sr   z=Property element cannot have both rdf:nodeID and rdf:resourcer   Fz#Property attr '%s' now allowed hereResource
Collectionra   )rA   r   r   )5r   rm   r   r   rC   r?   r   r   r/   r=   r   r"   r1   PROPERTY_ELEMENT_EXCEPTIONSr   ro   r   r   r;   r   r   r   r   r8   r   r:   rJ   rV   r   r<   property_element_charr9   r   r   r   nillist_node_element_endr   
XMLLiteralliteral_element_charr   rB   literal_element_startliteral_element_endr>   rA   r@   PROPERTY_ELEMENT_ATTRIBUTESr   r   r   rI   r   )r'   rO   rP   rt   r   rm   r   r   r>   r;   r   r   
parse_typer<   r   rA   r@   r=   r   s                      r*   r   z$RDFXMLHandler.property_element_startt  sg   \\$u5
d,,__
 tV$s5z* *4 0GVYY ' 1G00JJ9D@A *4 0GXXfii&>R=

CbHI#EBJ/GJGJ88FOOT2&--.XXf..5
F$6JJVW)F00DJ,,DHV$

G&PQ&&%/TZZ'!ZZ/F#gG)0DJJv&$F#(=000DJ,,DH% PCf...3&))3C

#H3#NOP +/4w6GOf#'#=#=GL!%!<!<DJ#88DH" "(#  </#'GL,/GG3FW\!%!8!8DJ#99DH "( %R&2C2CDF#'#<#<GL(-u~G$!%!;!;DJ $ 9 9DI#77DH!'#99!44
00&*hhv&EE7###!(+H 7~~c%j1 *3I7799JJG#MN *3I#((?tCy)A+#'S	8X>A>"WF

	156'7( >GL!GNGL#GNr+   c                 `    | j                   }|j                  |xj                  |z  c_        y y rN   )rm   rC   )r'   rC   rm   s      r*   r   z#RDFXMLHandler.property_element_char  s(    ,,<<#LLD L $r+   c                 :   | j                   }|j                  S|j                  G|j                  }|j                  d }t        |j                  ||j                        |_        d |_        | j                  j                  | j                  k(  ra|j                  t        j                  k7  rD| j                  j                  |j                  t        j                  t        j                  f       |j                  | j                  j                  | j                  j                   |j"                  |j                  f       |j$                  G| j'                  |j$                  | j                  j                   |j"                  |j                  f       d |_        y rN   )rm   rC   r>   r@   rA   r   r   r:   r   r   r   rI   r   r?   restrn   r<   r=   r;   r   )r'   rO   rP   rm   literalLangs        r*   r   z"RDFXMLHandler.property_element_end  s   ,,<<#(>!**K+"$W\\;@P@PQGNGL99==D666~~(

chh@A>>%JJNNDKK//1B1BGNNSTzz%  JJ!4!4g6G6G X r+   c                    | j                   }| j                  j                  t        j                  k(  rt               }|| j                  _        | j                  j                  | j                  j                  t        j                  |j                  f       || j                  _
        d | j                  _        y t               }| j                  j                  | j                  j                  t        j                  |f       | j                  j                  |t        j                  |j                  f       || j                  _        y rN   )rm   rn   r?   r   r   r   rI   r   firstr<   r>   r9   r   )r'   rO   rP   rm   r?   s        r*   r   z#RDFXMLHandler.list_node_element_end  s    ,,;;sww&7D  $DKKJJNNDKK,,ciiIJ!%DKK#DKK7D JJNNDKK,,chh=>JJNND#))W__=>#DKKr+   c           	         | j                   }| j                  | j                  _        | j                  | j                  _        | j                  | j                  _        | j                  j                  j                         |_	        |d   r| j                  |d      }|rd|d|d   |_        nd|d   z  |_        |d   |j                  vr]||j                  |d   <   |r |xj                  d|d|d   dz  c_        n)|xj                  d	|d   z  z  c_        nd|d   z  |_        |j                         D ]  \  }}|d   rO|d   |j                  vr"| j                  |d      |j                  |d   <   |j                  |d      dz   |d   z   }n|d   }|xj                  d
|dt        |      z  c_         |xj                  dz  c_        y )Nr   <r   r.   z<%sz xmlns:z=""z xmlns="%s" =>)rm   r   r   r8   r   r9   r   r:   rn   rB   rd   rX   r>   r   r   )r'   rO   rP   rt   rm   rf   values          r*   r   z#RDFXMLHandler.literal_element_start  s   ,,44		22		00		;;//4467**473F-3T!W!=!&a7g...,2  a)NN&$q'&JJNNNmd1g&==N"T!W_GN"[[] 	BMT5AwAw'"2"22040E0Ed1g0NG$$T!W-''Q036a@AwNN$	%0@AAN	B 	#r+   c                 T    | j                   xj                  t        |      z  c_        y rN   )rm   r>   r   )r'   rC   s     r*   r   z"RDFXMLHandler.literal_element_char3  s    vd|+r+   c                     |d   r*| j                   |d      }|rd|d|d   d}nd|d   z  }nd|d   z  }| j                  xj                  | j                  j                  |z   z  c_        y )Nr   z</r   r.   r   z</%s>)rX   rn   r>   rm   )r'   rO   rP   rf   r:   s        r*   r   z!RDFXMLHandler.literal_element_end6  sn    7**473F$*DG4Q'DG#Cdll11C77r+   N)#r2   r3   r4   r&   rK   r\   r^   rh   rk   rw   r{   r~   r   r   r   r   r   propertyrm   r   r   r   rn   r   r   rS   r   r   r   r   r   r   r   r   r   rF   r+   r*   r   r      s    
6A
"*:
-*
 {#G
 HD
 j!F(8H"T
2t$l!
&$$>,	8r+   r   returnc                 *   t               }	 |j                  dd       |j                  t        j
                  d       t        |      }|j                  |        |j                  |       |j                  t                      |S # t        $ r Y sw xY w)Nr   r   r.   )r   start_namespace_declAttributeError
setFeaturer   feature_namespacesr   r\   setContentHandlersetErrorHandlerr   )r   rI   parserrdfxmls       r*   r   r   B  s    ]F 	##E+QR g00!45!F
f%
V$
<>*M  s   B 	BBc                       e Zd Zd Zd Zy)r   c                      y rN   rF   r0   s    r*   r&   zRDFXMLParser.__init__T  r_   r+   c                     t        ||      | _        | j                  j                         }|j                  dd       }|||_        | j                  j                  |       y )NrJ   )r   _parsergetContentHandlerro   rJ   parse)r'   sourcesinkargscontent_handlerrJ   s         r*   r   zRDFXMLParser.parseW  sV    $VT2,,88:!XX&:DA)1CO. 	6"r+   N)r2   r3   r4   r&   r   rF   r+   r*   r   r   S  s    	#r+   r   N):__doc__xml.saxr   r   r   xml.sax.handlerr   xml.sax.saxutilsr   r   urllib.parser	   r
   rdflib.namespacer   r   rdflib.plugins.parsers.RDFVOCr   rdflib.termr   r   r   rdflib.exceptionsr   r   rdflib.parserr   __all__r/   r   r   r   r   r   r   r   rA   CORE_SYNTAX_TERMSr   r"   SYNTAX_TERMS	OLD_TERMSr   r   r   r   r   r   rp   rs   r   r>   r   ContentHandlerr   	XMLReaderr   r   rF   r+   r*   <module>r     s   4 3 ( . , &   0    0  
W
 \\
))KK!! JJ
II
LL

OO
MM
OO  !F$6$6		#BB AB
GH
=>	 		 	  "99fmmV\\B   	  ++VYY77)C   &yy&//6==I .vv	&F 	&#'V #'L|8G** |8~I$7$7 "#6 #r+   