
    4Ysh!                         d 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 dd	lmZ dd
lmZ ddlmZ g dZ ed      Z ed      Z G d dej,                        Zd Z G d de      Zy)z
A TriX parser for RDFLib
    )	Namespace)URIRef)BNode)Literal)Graph)ParserError)Parser)handler)make_parser)ErrorHandler)create_parserTriXHandler
TriXParserz&http://www.w3.org/2004/03/trix/trix-1/$http://www.w3.org/XML/1998/namespacec                   ^    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y)r   z6An Sax Handler for TriX. See http://sw.nokia.com/trix/c                 @    || _         d| _        | j                          y )NF)storepreserve_bnode_idsreset)selfr   s     {/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/parsers/trix.py__init__zTriXHandler.__init__   s    
"'

    c                 X    i | _         d | _        d | _        d| _        d | _        d | _        y )Nr   )bnodegraphtriplestatelangdatatyper   s    r   r   zTriXHandler.reset    s,    


	r   c                     || _         y N)locator)r   r$   s     r   setDocumentLocatorzTriXHandler.setDocumentLocator*   s	    r   c                      y r#    r!   s    r   startDocumentzTriXHandler.startDocument-       r   c                      y r#   r'   )r   prefix	namespaces      r   startPrefixMappingzTriXHandler.startPrefixMapping0   r)   r   c                      y r#   r'   )r   r+   s     r   endPrefixMappingzTriXHandler.endPrefixMapping3   r)   r   c                 0   |d   t        t              k7  r| j                  d|d   dt               |d   dk(  r7| j                  dk(  rd| _        d| _        y | j                  d       d| _        y |d   dk(  r7| j                  dk(  rd| _        d| _        y | j                  d	       d| _        y |d   d
k(  rO| j                  dk(  rd| _        d| _        y | j                  dk(  r		 d| _        y | j                  d       d| _        y |d   dk(  re| j                  dk(  r=| j                  t        | j                        | _        g | _        d| _        d| _        y | j                  d       d| _        y |d   dk(  r{| j                  dk(  rSd | _        d | _	        	 |j                  t        t              df      | _        	 |j                  d      | _	        d| _        y | j                  d       d| _        y |d   dk(  rd| j                  dk(  r<d | _        d | _	        	 |j                  t        t              df      | _        d| _        y | j                  d       d| _        y |d   dk(  rO| j                  dk(  rd| _        d| _        y | j                  dk(  r		 d| _        y | j                  d       d| _        y | j                  d|d   z         d| _        y #  Y xY w# t        $ r | j                  d       Y d| _        y w xY w#  Y d| _        y xY w)Nr   1Only elements in the TriX namespace are allowed. !=   TriXzUnexpected TriX elementr      zUnexpected graph elementuri      zUnexpected uri elementr   )r   zUnexpected triple elementtypedLiteralr   r    z No required attribute 'datatype'zUnexpected typedLiteral elementplainLiteralzUnexpected plainLiteral elementidzUnexpected id elementz$Unknown element %s in TriX namespace )strTRIXNSerrorr   r   r   r   r   r   r    getValueXMLNSgetValueByQNameKeyErrorchars)r   nameqnameattrss       r   startElementNSzTriXHandler.startElementNS6   s    7c&k!JJ7F$
 7fzzQ
Z 
W 

45V 
S !WzzQ
N 
K 

56J 
G !WzzQ
@ 
 qz 
w 

34v 
s !W zzQ::%!&TZZ!8DJ 
d 
a 

67` 
] !W&zzQ 	 $ %E
F/C DDIC$)$9$9*$EDMD 
= 

<=< 
9 !W&zzQ 	 $ %E
F/C DDI, 
! 

<=  
 !W_zzQ
 
 q 
 

23
 
 JJ=QGH
M   CJJAB@ 
CC& 
s*   %K K# %L
 K #LL
Lc                    |d   t        t              k7  r| j                  d|d   dt               |d   dk(  r| j                  dk(  rEt	        | j
                  t        | j                  j                                     | _	        d| _        y | j                  d	k(  r8| xj                  t        | j                  j                               gz  c_
        y | j                  d
       y |d   dk(  r| j                  dk(  rKt	        | j
                  | j                  | j                  j                                     | _	        d| _        y | j                  d	k(  r>| xj                  | j                  | j                  j                               gz  c_
        y | j                  d
       y |d   dk(  s|d   dk(  rb| j                  d	k(  rA| xj                  t        | j                  | j                  | j                        gz  c_
        y | j                  d       y |d   dk(  r| j                  d	k(  rxt        | j                        dk7  r3| j                  dt        | j                        | j                  fz         | j                  j!                  | j                         d| _        y | j                  d       y |d   dk(  rd | _	        d| _        y |d   dk(  rd| _        y | j                  d       y )Nr   r1   r2   r3   r6   r7   )r   
identifierr5   r8   zgIllegal internal self.state - This should never happen if the SAX parser ensures XML syntax correctnessr;   )rJ   r:   r9   )r   r    zIThis should never happen if the SAX parser ensures XML syntax correctnessr   z,Triple has wrong length, got %d elements: %sr   r4   zUnexpected close element)r=   r>   r?   r   r   r   r   rD   stripr   r   	get_bnoder   r   r    lenadd)r   rE   rF   s      r   endElementNSzTriXHandler.endElementNS   sh   7c&k!JJ7F$
 7ezzQ"**

8H8H8J1K
 
qtzz'7'7'9 :;;

P
 !W_zzQ"JJ4>>$**:J:J:L+M
 
qtzz/?/?/A BCC

P
 !W&$q'^*CzzQDJJTYYO   

7
 !W zzQt{{#q(JJFt{{+T[[9:
 

t{{+ 


7
 !WDJDJ!WDJ JJ12r   c                     | j                   rt        |      }|S || j                  v r| j                  |   }|S t        |      }|| j                  |<   |S r#   )r   r   r   )r   labelbns      r   rL   zTriXHandler.get_bnode   s\    ""uB 	 

"ZZ& 	 5\$&

5!	r   c                 .    | xj                   |z  c_         y r#   )rD   r   contents     r   
characterszTriXHandler.characters   s    

g
r   c                      y r#   r'   rT   s     r   ignorableWhitespacezTriXHandler.ignorableWhitespace   r)   r   c                      y r#   r'   )r   targetdatas      r   processingInstructionz!TriXHandler.processingInstruction   r)   r   c                     | j                   }|j                         d|j                         d|j                         d}t	        ||z         )N:z: )r$   getSystemIdgetLineNumbergetColumnNumberr   )r   messager$   infos       r   r?   zTriXHandler.error   sG    ,,!!!###%

 $.))r   N)__name__
__module____qualname____doc__r   r   r%   r(   r-   r/   rH   rO   rL   rV   rX   r\   r?   r'   r   r   r   r      sJ    @
WrH3T	*r   r   c                    t               }	 |j                  dd       |j                  t        j
                  d       t        |       }|j                  |       |j                  t                      |S # t        $ r Y bw xY w)Nxmlr   r3   )
r   start_namespace_declAttributeError
setFeaturer
   feature_namespacesr   setContentHandlersetErrorHandlerr   )r   parsertrixs      r   r   r      sz    ]F 	##E+QR g00!4uD
T"
<>*M  s   A5 5	B Bc                       e Zd ZdZd Zd Zy)r   z0A parser for TriX. See http://sw.nokia.com/trix/c                      y r#   r'   r!   s    r   r   zTriXParser.__init__	  r)   r   c                    |j                   j                  sJ d       t        |j                         | _        | j                  j	                         }|j                  dd       }|||_        | j                  j                  |       y )Nz/TriXParser must be given a context aware store.r   )r   context_awarer   _parsergetContentHandlergetr   parse)r   sourcesinkargscontent_handlerr   s         r   ry   zTriXParser.parse  sw    JJ$$	=<	=$ %TZZ0,,88:!XX&:DA)1CO. 	6"r   N)rd   re   rf   rg   r   ry   r'   r   r   r   r     s    :#r   r   N)rg   rdflib.namespacer   rdflib.termr   r   r   rdflib.graphr   rdflib.exceptionsr   rdflib.parserr	   xml.sax.saxutilsr
   xml.saxr   xml.sax.handlerr   __all__r>   rA   ContentHandlerr   r   r   r'   r   r   <module>r      so    '     )   %  (
8 
;	<89\*'(( \*~# #r   