
    4Ysh                        d Z ddlZddl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 ddlmZmZmZ ddlmZ g d	Zdd
lmZ dWdZd Zd Zd ZdZdZ dZ!dZ"e e!e"fZ#ee e!e"fZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,e,dz   Z-e,dz   Z.e,dz   Z/dZ0dZ1dZ2e2dz   Z3e,dz   Z4dZ5e1Z6dZ7e%e6d z   fZ8e%e6d!z   fZ9e%e6d"z   fZ:e%e6d#z   fZ;e%e6d$z   fZ<e%e6d%z   fZ=da>d& Z?da@d' ZAd(ZBd)ZCd* ZDd+ ZEe.ZFe/ZGd,ZHe%e0fZIe%e3fZJd-ZKed.z   ZLed/z   ZMed0z   ZNed1z   ZOed2z   ZPdZQ eRd3      ZSeSd4hz  ZTeSd5hz  ZUdZV eRd6      ZW eRd7      ZX eRd8      ZYeYd9d4hz  ZZd: Z[ ej                  d;      Z] ej                  d<      Z^d,Z_ ej                  d=      Z` ej                  d>      Za ej                  d?      Zb ej                  d@      Zc ej                  d@      Zd ej                  dA      Ze ej                  dB      Zf ej                  dC      Zg ej                  dD      Zh ej                  dE      Zi G dF dG      Zj G dH dIek      Zl G dJ dKem      Zn ej                  dL      Zo G dM dNem      ZpdO Zq G dP dQe      Zr G dR dSer      ZsdT ZtdU ZuevdVk(  r eu        yy)Xa  
notation3.py - Standalone Notation3 Parser
Derived from CWM, the Closed World Machine

Authors of the original suite:

* Dan Connolly <@@>
* Tim Berners-Lee <@@>
* Yosi Scharf <@@>
* Joseph M. Reagle Jr. <reagle@w3.org>
* Rich Salz <rsalz@zolera.com>

http://www.w3.org/2000/10/swap/notation3.py

Copyright 2000-2007, World Wide Web Consortium.
Copyright 2001, MIT.
Copyright 2001, Zolera Systems Inc.

License: W3C Software License
http://www.w3.org/Consortium/Legal/copyright-software

Modified by Sean B. Palmer
Copyright 2007, Sean B. Palmer.

Modified to work with rdflib by Gunnar Aastrand Grimnes
Copyright 2010, Gunnar A. Grimnes

    N)Decimal)uuid4)ParserError)URIRefBNodeLiteralVariable_XSD_PFX
_unique_id)QuotedGraphConjunctiveGraphGraph)	long_type)		BadSyntaxN3ParserTurtleParser
splitFragPjoinbaserunNamespace	uniqueURIhexify)Parserc                 J    | j                  d      }|dk\  r
| d| | |d fS | dfS )zsplit a URI reference before the fragment

    Punctuation is kept.

    e.g.

    >>> splitFragP("abc#def")
    ('abc', '#def')

    >>> splitFragP("abcdef")
    ('abcdef', '')

    #r   N )rfind)urirefpunctis      /var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/parsers/notation3.pyr   r   ;   s:     	SAAvbqz6!":%%rz    c                    |j                  d      }|j                  d      }|dk\  r|dk  s||k  r|S | j                  d      }|dk\  s
J d| z         t        |      \  }}|s| |z   S | |dz      dk7  rt        d| d|d      | |dz   |d	z    d
k(  r| j                  d|d	z         }n|dz   }|dk  rt        |       }| dz   } |dd d
k(  r| d|dz    |z   S |dd dk(  r| d| |z   S | j	                  d      }	 |dd dk(  r|dd }|dk(  rd}n6|dd	 dk(  s|dk(  r(|d	d }| j	                  d||      }	|	dk\  r| d|	dz    } |	}nnL| d|dz    |z   |z   S )a  join an absolute URI and URI reference
    (non-ascii characters are supported/doctested;
    haven't checked the details of the IRI spec though)

    ``here`` is assumed to be absolute.
    ``there`` is URI reference.

    >>> join('http://example/x/y/z', '../abc')
    'http://example/x/abc'

    Raise ValueError if there uses relative path
    syntax but here has no hierarchical path.

    >>> join('mid:foo@example', '../foo') # doctest: +NORMALIZE_WHITESPACE
    Traceback (most recent call last):
        raise ValueError(here)
    ValueError: Base <mid:foo@example> has no slash
    after colon - with relative '../foo'.

    >>> join('http://example/x/y/z', '')
    'http://example/x/y/z'

    >>> join('mid:foo@example', '#foo')
    'mid:foo@example#foo'

    We grok IRIs

    >>> len(u'Andr\xe9')
    5

    >>> join('http://example.org/', u'#Andr\xe9')
    u'http://example.org/#Andr\xe9'
    /:r   zBase uri '%s' is not absolute   zBase <z,> has no slash after colon - with relative 'z'.   z//N   z./.r   z../z..)findr   
ValueErrorlenr   )
herethereslashlcolonlbcolonlpathfragbpathslashrr    s
             r!   r   r   Q   s   L ZZ_FZZ_F {
fvoiinGa< '$.< E"JD$d{ GaKC-15:
 	

 GaK'A+&$.		#w{+! qyD	cz RayDMgk"U** RayCFU|e##ZZ_F
8t8D3;D"1X$$,8D

3v.AAvGa!e}  &1*$t++r"   c                  H    dt        t        j                               z   dz   S )a  The base URI for this process - the Web equiv of cwd

    Relative or absolute unix-standard filenames parsed relative to
    this yield the URI of the file.
    If we had a reliable way of getting a computer name,
    we should put it in the hostname just to prevent ambiguity

    file://r$   )	_fixslashosgetcwd r"   r!   r   r      s     y--33r"   c                 T    | j                  dd      } | d   dk7  r| d   dk(  r| dd } | S )z7Fix windowslike filename to unixlike - (#ifdef WINDOWS)\r$   r   r&   r%   r(   N)replace)ss    r!   r8   r8      s7    			$Ats{qts{abEHr"   r&   r(   r'            z#http://www.w3.org/2000/10/swap/log#isforSomeforAllz/http://www.w3.org/1999/02/22-rdf-syntax-ns#typez+http://www.w3.org/1999/02/22-rdf-syntax-ns#zhttp://www.w3.org/2002/07/owl#sameAsparsesToz$http://www.w3.org/TR/REC-rdf-syntax/z&http://www.w3.org/2000/10/swap/log.n3#firstrestlinilListEmptyc                  X    t         t        t               t                     dz   a t         S )z;Returns a URI suitable as a namespace for run-local objectsr   )runNamespaceValuer   r   r   r;   r"   r!   r   r      s&       6<r"   c                  N    t         dz  a t               dz   t        t               z   S )zA unique URIr&   u_)nextur   strr;   r"   r!   r   r      s#     
QJE>D 3u:--r"   F2   c                       y Nr;   argskargss     r!   BecauseOfDatarZ         r"   c                       y rV   r;   rW   s     r!   becauseSubexpressionr]     r[   r"   r   z*http://www.w3.org/2000/10/swap/log#impliesbooleandecimaldoublefloatintegerz	
 !"#$&'()*,+/;<=>?@[\]^`{|}~r)   r%   ABCDEFabcdef0123456789z(_~.-!$&'()*+,;=/?#@%)z0123456789-+c                     	 t        t        | j                  d      d            S #  t        d| j                  d      z         xY w)Nr&      zInvalid unicode code point: )chrintgroup	Exception)ms    r!   unicodeExpandrl   9  sC    E3qwwqz2&''E6CDDs	   #& Az\\u([0-9a-fA-F]{4})z\\U([0-9a-fA-F]{8})z[ \t]*(#[^\n]*)?\r?\nz[ \t]*(#[^\n]*)?$z[ \t]*z[-+]?[0-9]+z[-+]?[0-9]*\.[0-9]+z9[-+]?(?:[0-9]+\.[0-9]*|\.[0-9]+|[0-9]+)(?:e|E)[-+]?[0-9]+z[0-9]+z[\\\r\n\"\']z[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*c                      e Zd Z	 	 	 	 	 	 d,dZd Zd Zd Zd Zd Zd Z	d-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.dZd Zd Zd.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)d) Z*d* Z+d+ Z,y)/
SinkParserNc                 X   i | _         |dk7  r d|v s
J d|z         |dz   | j                   d<   || _        |r|j                  |       || _        d| _        d| _        || _        g d| _        d| _        i | _	        i | _
        i | _        || _        || _        |rdnd| _        d	| _        t         r+t#        |j%                  |      | j                  
      | _        |r|| _        n|r|| _        nd	| _        | j&                  rd| j&                  v sJ | j                  s0| j                  r| j                  dz   | _        nt)               | _        |>|s<| j                  r|j+                  |dz         | _        n|j+                         | _        n|| _        | j,                  | _        d	| _        y	)zdnote: namespace names should *not* end in  # ;
        the  # will get added during qname processingr   r%   zDocument URI not absolute: <%s>r   r   )athisbindhasrC   oftruefalse)"')rw   N)becausez#_gz	#_formula)	_bindings_storesetGenPrefix_thisDoclinesstartOfLine
_genPrefixkeywordskeywordsSet_anonymousNodes
_variables_parentVariables_reasonturtlestring_delimiters_reason2trackingrZ   	newSymbol_baseURIr   
newFormula_formula_context_parentContext)selfstoreopenFormulathisDocbaseURI	genPrefixwhyr   s           r!   __init__zSinkParser.__init__X  s    b='>N#Dw#NN>!(3DNN2y)
#Q! " 066)($,,DM #DM ' $==C4==$888}}"&--%"7"++v}} % 0 0;1F G % 0 0 2'DM"r"   c                 Z    d| j                   | j                  || j                  z
  dz   fz  S )a)  String generated from position in file

        This is for repeatability when referring people to bnodes in a document.
        This has diagnostic uses less formally, as it should point one to which
        bnode the arbitrary identifier actually is. It gives the
        line and character number of the '[' charcacter or path character
        which introduced the blank node. The first blank node is boringly
        _L1C1. It used to be used only for tracking, but for tests in general
        it makes the canonical ordering of bnodes repeatable.z	%s_L%iC%ir&   )r   r~   r   )r   r    s     r!   r-   zSinkParser.here  s/     dootzz1t?O?O;ORS;STTTr"   c                     | j                   S rV   )r   r   s    r!   formulazSinkParser.formula  s    }}r"   c                 @    | j                  |j                               S rV   )loadBufread)r   streams     r!   
loadStreamzSinkParser.loadStream  s    ||FKKM**r"   c                 d    | j                          | j                  |       | j                         S )z1Parses a buffer and returns its top level formula)startDocfeedendDoc)r   bufs     r!   r   zSinkParser.loadBuf  s"    		#{{}r"   c                 \   t        |t              sJ|j                  d      }t        |      dkD  r-|d   t        j
                  j                  d      k(  r|dd }n|}d}|dk\  rI| j                  ||      }|dk  ry| j                  ||      }|dk  r| j                  ||d       |dk\  rHyy)a  Feed an octet stream to the parser

        if BadSyntax is raised, the string
        passed in the exception object is the
        remainder after any statements have been parsed.
        So if there is more data to feed to the
        parser, it should be straightforward to recover.utf-8r   r&   Nzexpected directive or statement)	
isinstancerS   decoder,   codecsBOM_UTF8	skipSpacedirectiveOrStatementr   )r   octetsr?   r    js        r!   r   zSinkParser.feed  s     &#&g&A1vzadfoo&<&<W&EEabEA1fq!$A1u))!Q/A1uq!%FG 1fr"   c                 &   | j                  ||      }|dk  r|S | j                  r| j                  ||      }|dk\  r|S | j                  ||      }|dk\  r| j	                  ||      S | j                  ||      }|dk\  r| j	                  ||      S |S Nr   )r   r   sparqlDirective	directivecheckDot	statement)r   argstrhr    r   s        r!   r   zSinkParser.directiveOrStatement  s    NN61%q5H;;$$VQ/AAvNN61%6==++NN61%6==++r"   c                     |d   t         vsJ ||   dk(  r|dz  }n|| j                  vry|t        |      z   }||| |k(  r||   t        v s
|r
||   dk(  r|S y)zCheck for keyword.  Space must have been stripped on entry and
        we must not be at end of file.

        if colon, then keyword followed by colon is ok
        (@prefix:<blah> is ok, rdf:type shortcut a must be followed by ws)
        r   @r&   r%   )_notNameCharsr   r,   _notKeywordsChars)r   tokr   r    coloni_plus_len_toks         r!   r   zSinkParser.tok  s|     1v]***!9FA$--'SX1^$+'+<<&0C7!!r"   c                     |d   t         vsJ t        |      }||||z    j                         |j                         k(  r|||z      t        v r||z  }|S y)zCheck for SPARQL keyword.  Space must have been stripped on entry
        and we must not be at end of file.
        Case insensitive and not preceded by @
        r   r   )r   r,   lower_notQNameChars)r   r   r   r    len_toks        r!   	sparqlTokzSinkParser.sparqlTok  sc     1v]***c(!a'k"((*ciik91w;>1LAHr"   c                 z   | j                  ||      }|dk  r|S g }| j                  d||      }|dkD  r| j                  ||d       | j                  d||      }|dkD  rk| j                  r| j                  ||d       | j	                  |||| j
                        }|dk  r| j                  ||d       | j                  |d d         |S | j                  d||      }|dkD  r| j                  r| j                  ||d       | j	                  |||| j                        }|dk  r| j                  ||d	       |D ]G  }|| j                  vs|| j                  v s | j                  j                  |      | j                  |<   I |S | j                  d
||      }|dkD  ry| j                  r| j                  ||d       | j	                  |||| j                        }|dk  r| j                  ||d       |D ]  }| j                  j                  |        |S | j                  d||d      }|dk\  rg }| j                  |||      }|dk  r| j                  ||d       | j                  |||      }|dk  r| j                  ||d       | j                  |d         }| j                  rt!        | j                  |      }nd|vr| j                  ||d| d       d|v sJ || j"                  |d   d   <   | j%                  |d   d   t'        |             |S | j                  d||      }|dk\  rg }| j                  |||      }|dk  r| j                  ||d       | j                  |d         }| j                  rt!        | j                  |      }n| j                  ||d|z   dz          d|v sJ || _        |S y)Nr   rr   z%keyword bind is obsolete: use @prefixr   z%Found 'keywords' when in Turtle mode.z/'@keywords' needs comma separated list of wordsrE   z#Found 'forAll' when in Turtle mode.zBad variable list after @forAllrD   z$Found 'forSome' when in Turtle mode.z Bad variable list after @forSomeprefixT)r   expected qname after @prefix'expected <uriref> after @prefix _qname_r&   r%   6With no base URI, cannot use relative URI in @prefix <>r   expected <uri> after @base >With no previous base URI, cannot use relative URI in @base  <r   )r   r   r   r   commaSeparatedListbareWordsetKeywordsuri_ref2r   r   r   newUniversaldeclareExistentialqnameuriOfr   r   rz   rr   r   )r   r   r    r   resxtnss           r!   r   zSinkParser.directive  s   NN61%q5HHHVVQ'q5NN61&MNHHZ+q5{{vq*QR''3FA1uAP SV$HHHXvq)q5{{vq*OP''3FA1uvq*KL GDOO+qD4I4I/I)-)C)CA)FDOOA&G HHHY*q5{{vq*PQ''3FA1uvq*LM 40034HHHXvqH56A

61a(A1uvq*HIfa+A1uvq*STAaD!B}}$--,BLRDPQR
 "99&(DNN1Q47#IIad1gvbz*HHHVVQ'6Afa+A1uvq*GHAaD!B}}$--,1  "99DMHr"   c                    | j                  ||      }|dk  r|S | j                  d||      }|dk\  rg }| j                  |||      }|dk  r| j                  ||d       | j	                  |||      }|dk  r| j                  ||d       | j                  |d         }| j                  rt        | j                  |      }nd|vr| j                  ||d|z   dz          d|v sJ || j                  |d   d   <   | j                  |d   d   t        |             |S | j                  d	||      }|dk\  rg }| j	                  |||      }|dk  r| j                  ||d
       | j                  |d         }| j                  rt        | j                  |      }n| j                  ||d|z   dz          d|v sJ || _        |S y)za
        turtle and trig support BASE/PREFIX without @ and without
        terminating .
        r   PREFIXr   r   r&   r%   r   r   BASEr   r   r   )r   r   r   r   r   r   r   r   rz   rr   r   )r   r   r    r   r   r   s         r!   r   zSinkParser.sparqlDirective{  s    NN61%q5HNN8VQ/6A

61a(A1uvq*HIfa+A1uvq*STAaD!B}}$--,B2  "99&(DNN1Q47#IIad1gvbz*HNN661-6Afa+A1uvq*GHAaD!B}}$--,1  "99DMHr"   c                     t        |t              sJ d       |dk(  r| j                  j                  |       y | j                  j	                  ||       y )Nz&Any unicode must be %x-encoded alreadyr   )r   bytesr{   setDefaultNamespacerr   )r   qnuris      r!   rr   zSinkParser.bind  sE    #u%O'OO%8KK++C0KKR%r"   c                 4    |d| _         y|| _        d| _         y)zTakes a list of stringsNr   r&   )r   r   )r   ks     r!   r   zSinkParser.setKeywords  s    9 DDM Dr"   c                 N    | j                   j                  | j                         y rV   )r{   r   r   r   s    r!   r   zSinkParser.startDoc  s    T]]+r"   c                 d    | j                   j                  | j                         | j                  S )z8Signal end of document and stop parsing. returns formula)r{   r   r   r   s    r!   r   zSinkParser.endDoc  s"    4==)}}r"   c                 R    | j                   j                  || j                         y Nr   )r{   makeStatementr   )r   	quadruples     r!   r   zSinkParser.makeStatement  s     	!!)!?r"   c                     g }| j                  |||      }|dk  r|S | j                  |||d         }|dk  r| j                  ||d       |S )Nr   zexpected propertylist)objectproperty_listr   )r   r   r    rr   s        r!   r   zSinkParser.statement  sZ    KK1%q5Hvq!A$/q5NN61&=>r"   c                 (    | j                  |||      S rV   itemr   r   r    r   s       r!   subjectzSinkParser.subject      yyC((r"   c                 F   | j                  ||      }|dk  r|S g }| j                  d||      }|dk\  rb| j                  r| j                  ||d       | j	                  |||      }|dk  r| j                  ||d       |j                  d|d   f       |S | j                  d||      }|dk\  r| j                  r| j                  ||d       | j	                  |||      }|dk  r| j                  ||d       | j                  ||      }|dk  r| j                  ||d	       |}| j                  d
||      }|dk  r| j                  ||d       |j                  d|d   f       |S | j                  d||      }|dk\  r|j                  dt        f       |S |||dz    dk(  rW| j                  r| j                  ||d       |j                  d| j                  j                  t        dz         f       |dz   S ||   dk(  r~| j                  r| j                  ||d       ||dz      dk(  r8|j                  d| j                  j                  t        dz         f       |dz   S |j                  dt        f       |dz   S |||dz    dk(  r>| j                  r| j                  ||d       |j                  dt        dz   f       |dz   S | j	                  |||      }|dk\  r|j                  d|d   f       |S |||dz    dk(  s|||dz    dk(  r| j                  ||d       y)z{has _prop_
        is _prop_ of
        a
        =
        _prop_
        >- prop ->
        <- prop -<
        _operator_r   rs   z"Found 'has' keyword in Turtle modezexpected property after 'has'->rC   z!Found 'is' keyword in Turtle modezexpected <property> after 'is'z/End of file found, expected property after 'is'rt   zexpected 'of' after 'is' <prop>z<-rp   r(   z<=zFound '<=' in Turtle mode. implies=zFound '=' in Turtle moder&   r   z:=zFound ':=' in Turtle modebecomesz>-z>- ... -> syntax is obsolete.r   )r   r   r   r   propappendRDF_typer{   r   Logic_NSDAML_sameAs)r   r   r    r   r   r   s         r!   verbzSinkParser.verb  s$    NN61%q5HHHUFA&6{{vq*NO		&!Q'A1uvq*IJJJad|$HHHT61%6{{vq*MN		&!Q'A1uvq*JKvq)A1uAP Avq)A1uvq*KLJJad|$HHHS&!$6JJh'(H!a!e${{vq*GHJJdkk33Hy4HIJKq5L!9{{vq*DEa!e}#

D$++"7"798L"MNO1uJJk*+q5L!a!e${{vq*EF JJh234q5LIIfa#6JJad|$H!a!e$q1q5(9T(ANN61&EFr"   c                 (    | j                  |||      S rV   r   r   s       r!   r   zSinkParser.prop<  r   r"   c                 (    | j                  |||      S rV   )r2   r   s       r!   r   zSinkParser.item?  r   r"   c                 f    | j                   j                  | j                  || j                        S r   )r{   newBlankNoder   r   )r   r   s     r!   	blankNodezSinkParser.blankNodeB  s&    {{''s'NNr"   c                    | j                  |||      }|dk  r|S ||   dv r||   }|j                         }| j                  | j                  |            }| j	                  ||dz   |      }|dk  r| j                  ||d       |j                         }|dk(  r | j                  | j                  |||f       n| j                  | j                  |||f       |j                  |       ||   dv r|S )zParse the path production.r   >   !^r   r&   z"EOF found in middle of path syntaxr  )	nodeOrLiteralpopr  r-   noder   r   r   r   )	r   r   r    r   r   chsubjobjpreds	            r!   r2   zSinkParser.pathE  s    vq#.q5HQi:%B779D..TYYq\.2C		&!a%-A1uvq*NO779DSy""DMM4d#CD""DMM4s#CDJJsO Qi:% r"   c                     | j                   j                  |d      }||S | j                  j                  | j                  | j
                        }|| j                   |<   |S )z?Remember or generate a term for one of these _: anonymous nodesNr   )r   getr{   r  r   r   )r   lnterms      r!   anonymousNodezSinkParser.anonymousNodeZ  s[    ##''D1K{{''4=='I#'R r"   c                     |}| j                  ||      }|dk  r|S |}||   }|dk(  r| j                  |      }| j                  ||dz         }|dk  r| j                  ||d       ||   dk(  r| j                  r| j                  ||d       |dz   }g }	| j	                  |||	      }|dk\  ru|	d   }t        |	      dkD  r*|	D ]%  }
| j                  | j                  t        ||
f       ' | j                  ||      }|dk  r| j                  ||d       ||   dk(  r|dz  }n| j                  ||d	       || j                  |
      }| j                  |||      }|dk  r| j                  ||d       | j                  ||      }|dk  r| j                  ||d       ||   dk7  r| j                  ||d       |j                  |       |dz   S | j                  s|dk(  r~||dz      }|dk(  r|dz  }|dz   }g }d}	 | j                  ||      }|dk  r| j                  ||d       |||dz    dk(  r|dz   }n|s"||   dk(  r|dz  }n| j                  ||d       nd}g }| j                  |||      }|dk  r| j                  ||d       |j                  | j                  j                  |d                |j                  | j                  j                  || j                               |S |dz   }| j                   }| j                  | _        | j"                  }| j$                  }| j&                  | _        i | _        | j&                  j)                         | _        | j*                  }t,        | _        || j                  j/                         }|| _        	 | j                  ||      }|dk  r| j                  ||d       ||   dk(  r|dz   }n+| j1                  ||      }|dk  r| j                  ||d       c|| _        | j$                  | _        || _        | j                   | _        || _        || _        |j                  |j3                                |S |dk(  r| j                  j4                  }||dz      }|dk(  r| j                  j                  }|dz  }|dz   }g }	 | j                  ||      }|dk  r| j                  ||d       ||   dk(  r|dz   }n[g }| j                  |||      }|dk  r| j                  ||d       |j                  | j                  j                  |d                |j                   ||| j                               |S | j7                  d ||      }|dk\  r| j                  ||d!       | j7                  d"||      }|dk\  r|j                  d       |S | j7                  d#||      }|dk\  r|j                  d       |S || j9                  |||      }|dk\  r|S y$)%zParse the <node> production.
        Space is now skipped once at the beginning
        instead of in multiple calls to self.skipSpace().
        r   [r&   zEOF after '['r   z(Found '[=' or '[ =' when in turtle mode.z'EOF when objectList expected after [ = ;zobjectList expected after [= r  zproperty_list expectedz,EOF when ']' expected after [ <propertyList>]z']' expected{$Tzneeded '$}', found end.r(   z$},zexpected: ','Fzexpected item in set or '$}'zneeded '}', found end.}zexpected statement or '}'(zneeded ')', found end.)zexpected item in list or ')'rq   zEKeyword 'this' was ancient N3. Now use @forSome and @forAll keywords.ru   rv   r   )r   r-   r   r   
objectListr,   r   r   r   r  r   r   r   r{   internnewSetr   r   r   r   copyr   r]   r   r   closenewListr   r   )r   r   r    r   subjectAlreadyr  r   r  bnodeIDobjsr  ch2rL   	first_runr   oldParentContextparentAnonymousNodesgrandParentVariablesreason2
thing_types                       r!   r  zSinkParser.nodec  s+   
 NN61%q5HAY9iilGvq1u-A1uvq/:ayC;;NN#M EOOFAt467D4y1}#' XC ..{DRU/VWXvq1A1u"A'P ayC'QNN61.MN|~~'~2""61d3A1uvq*BCvq)A1uAM ayCvq.9JJtq5L{{rSy Q-CczQE 	vq1A1uvq2KLa!a%(D0E$!!9+FA NN61oF$)	D		&!T2A1uvq2PQKK 2 247 ;<) * 

4;;--dDMMBC E#'#6#6 &*mm#'+';';$'+'<'<$(,%')$"&//"6"6"8-- 4<;;113D $vq1A1uvq2JKayC'E11&!<A1uvq2MN  (<$"&"7"7(<% $ 3 3 '&6#

4::<(9,,JQ-Ccz![[//
QAADNN61-q5NN61.FG!9#AAIIfa.q5NN61.LMDKK..tAw78  JJz$67HHHVVQ'6NN3 HHVVQ'6JJtHHHWfa(6JJuH<fa-AAvr"   c                    	 	 | j                  ||      }|dk  r| j                  ||d       ||   dk7  rn|dz   }9|||dz    dk(  rU| j                  r| j                  ||d       |dz   }g }| j                  ||||      }|dk  r| j                  ||d       |}|}g }| j	                  |||      }|dk  r|S g }| j                  |||      }|dk  r| j                  ||d	       |D ]N  }|d   \  }	}
|	d
k(  r | j                  | j                  |
||f       0| j                  | j                  |
||f       P | j                  ||      }|dk  r| j                  ||d       ||   dk7  r|S |dz  }s)zUParse property list
        Leaves the terminating punctuation in the buffer
        r&   r   z-EOF found when expected verb in property listr  r(   z:-zFound in ':-' in Turtle modez!bad {} or () or [] node after :- zobjectList expectedr   zEOF found in list of objects)r   r   r   r  r   r  r   r   )r   r   r    r  r   r   vr'  r  dirasyms              r!   r   zSinkParser.property_list  s    NN61-q5NN#R !9#E  a!a% D(;;NN61.LMEIIfad3q5NN61.QRAA		&!Q'AAvD40A1uvq*?@ HaD	c4<&&sD#'FG&&sC'FGH vq)A1uvq*HIayCFAW r"   c                 .   | j                  ||      }|dk  r| j                  ||d       ||   dk(  r|S  ||||      }|dk  ry	 | j                  ||      }|dk  r|S ||   }|dk7  r|dk7  ry|S  |||dz   |      }|dk  r| j                  ||d       Q)zereturn value: -1 bad syntax; >1 new position in argstr
        res has things found appended
        r   z"EOF found expecting comma sep listr)   r   r&   r  zbad list contentr   r   )r   r   r   r   whatr    r  s          r!   r   zSinkParser.commaSeparatedListJ  s     NN61%q5NN61&JK!9HC q5vq)A1uBSy9VQUC(A1uvq*<= r"   c                     | j                  |||      }|dk  ry	 | j                  ||      }|dk  r| j                  ||d       ||   dk7  r|S | j                  ||dz   |      }|dk  r|S R)Nr   r   r&   zEOF found after objectr  )r   r   r   )r   r   r    r   r   s        r!   r  zSinkParser.objectListd  s    KK3'q5vq)A1uvq*BCayCFAE3/A1u r"   c                     | j                  ||      }|dk  r|S ||   }|dk(  r|dz   S |dk(  r|S |dk(  r|S | j                  ||d       y )Nr   r)   r&   r  r  z.expected '.' or '}' or ']' at end of statementr4  )r   r   r    r   r  s        r!   r   zSinkParser.checkDotr  s`    NN61%q5HAY9q5L9H9Hvq"RSr"   c                    g }| j                  |||      }|dk\  rl|d   \  }}|J d       	 | j                  |   }| j                  j                  |z         }	|j                  | j                  j                  |	|	             |S | j                  ||      }|dk  ry||   d	k(  r1g }
| j                  |||
      }|dkD  r|j                  |
d          |S y||   d
k(  r|dz   }|j!                  d|      }|dk\  r||| }t"        j%                  t&        |      }t(        j%                  t&        |      }| j                  rt        | j                  |      }nd|v sJ d       ||dz
     dk(  r|dd dk(  s|dz  }| j                  j                  |      }	|j                  | j                  j                  |	|	             |dz   S | j                  ||d       y| j*                  rg }
| j-                  |||
      }|dk  ry|
d   | j.                  v r| j                  ||d|
d   z         |j                  | j                  j                  | j                  d   |
d   z                |S y# t        $ ro |dk(  r$|j                  | j                  |             |cY S | j                  s |dk(  rt        | j                  xs dd      }n| j                  ||d|z         Y w xY w)zGenerate uri from n3 representation.

        Note that the RDF convention of directly concatenating
        NS and local name is now used though I prefer inserting a '#'
        to make the namesapces look more like what XML folks expect.
        r   Nz	not used?_r   r   zPrefix "%s:" not boundr   ?<r&   r   r%   z0With no base URI, cannot deal with relative URIszunterminated URI referencezKeyword "%s" not allowed here.)r   r   
ADDED_HASHrz   KeyErrorr   r  r   r   r   r{   r   r   r  r   variabler*   unicodeEscape8subrl   unicodeEscape4r   r   r   )r   r   r    r   r   r   pfxr  r   symbr0  sturefs                r!   r   zSinkParser.uri_ref2  s    JJvq"%6eGC{%+%q	T,B ;;((b1DJJt**467HNN61%q5!9Afa+A1u

1Q4 AY#QBC$AAvb| &))->%))->==t4D tJIJ#!a%=C'RS	S0@CKD{{,,T2

4??..tT:;1uNN61&BCAfa+A1utt}}$vq*JQqT*QRJJt{{,,T^^B-?!A$-FGHHs   Tcz

4#5#5b#9: ;;3"9!$--"52s;vq2Jc2RSTs   I+ +0K#AK#"K#c                 f   	 	 ||   }|dv r|dz  }|dvr|S 	 	 t        j                  ||      }|n-| xj                  dz  c_        |j	                         x| _        }Ft        j                  ||      }||j	                         }t        j                  ||      }||S dS # t         $ r Y yw xY w)zjSkip white space, newlines and comments.
        return -1 if EOF, else position of first non-ws character>   	 r&   >   
r   r   )
IndexErroreolmatchr~   endr   wseof)r   r   r    r  rk   s        r!   r   zSinkParser.skipSpace  s    

	AY$FA00H 		&!$AyJJ!OJ#$557*Dq  HHVQ=AIIfa Iq%2%  		s   B$ $	B0/B0c                 T   | j                  ||      }|dk  ry||   dk7  ry|dz  }|}||   t        v r| j                  ||d||   z         t        |      }||k  r!||   t        vr|dz  }||k  r||   t        vr| j
                  | j                  j                  | j                  dz   ||| z         }|| j                  vr4| j                  j                  || j                        | j                  |<   |j                  | j                  |          |S | j                  j                  | j                  dz   ||| z         }|| j                  vr4| j
                  j                  || j                        | j                  |<   |j                  | j                  |          |S )z?abc -> variable(:abc)r   r   r:  r&   z#Variable name can't start with '%s'r   r   )r   numberCharsr   r,   r   r   r{   r   r   r   r   r   r   r   r   )r   r   r    r   r   
len_argstrvarURIs          r!   r>  zSinkParser.variable  s    NN61%q5!9	Q!9#NN61&KfUVi&WX[
*n2C!CFA *n2C!C&[[**4==3+>!+LMFT__,*.--*D*D +E +' JJtv./H
 &&t}}s':VAa['HI...,0,?,?,L,LDMM -M -D!!&) 	

4((01r"   c                     | j                  ||      }|dk  ry||   t        v s||   t        v ry|}t        |      }||k  r!||   t        vr|dz  }||k  r||   t        vr|j	                  |||        |S )zabc -> :abcr   r   r&   )r   rR  r   r,   r   )r   r   r    r   r   rS  s         r!   r   zSinkParser.bareWord  s    NN61%q5!9#vay4E'E[
*n2C!CFA *n2C!C

6!A;r"   c                    | j                  ||      }|dk  ry||   }|t        v ryt        |      }|t        vr@|}|dz  }	 ||   t        vr|dz  }||   t        vr||dz
     dk(  r|dz  }||k(  ry||| }nd}||k  rE||   dk(  r<|}|dk(  rt        }	nt
        }	|dz  }d}
|}d}||k  r||   }|d	k(  r|
sd
}
||k  r|||| z  }|dz   }n||	vs|
rz|
r.|t        vrmt        | j                  | j                  ||d|z         |dk(  rB||dz      t        vs||dz      t        vr&t        | j                  | j                  ||d|z         d}
nn|dz  }||k  r|
r#t        | j                  | j                  ||d      ||dz
     dk(  rt        |      dk(  r||k(  ry|dz  }||k  r|||| z  }|j                  ||f       |S |r/| j                  r#|| j                  vr|j                  d|f       |S y# t        $ r Y w xY w)z
        xyz:def -> ('xyz', 'def')
        If not in keywords and keywordsSet: def -> ('', 'def')
        :def -> ('', 'def')
        r   r   r&   r)   r   r%   r9  Fr=   Tzillegal escape %r(   zillegal hex escape zqname cannot end with \)r   numberCharsPlusr,   r   rK  r   escapeCharsr   r}   linehexCharsr   r   r   )r   r   r    r   crS  r   r  rB  allowedChars	lastslashstarts               r!   r   zSinkParser.qname  s    NN61%q51I[
M!AFAQi}4FA Qi}4
 a!e}#Q6!B Bz>fQi3.Ccz,-FAIEBj.1I9Y $IqyfU1o-EEl*i K/"+ $ $		 & ! 1A 5#  c"1q5M9%a!e}H<"+ $ $		 & ! 5 9#  !&IQA j.D MM499fa9S  a!e}#r7a<EQJQqyfU1o%JJRy!H d&&2T]]+B

B8$_  s   G9 9	HHc                 T   | j                  |||      }|dk\  r|S | j                  ||      }|dk  ry|}||   }|| j                  v ra|dz  }|||dz    |k(  r|}|dz  }n|}|dz  }| j                  |||      \  }}|j	                  | j
                  j                  |             |S y)Nr   r   r'   r&   )r   r   r   strconstr   r{   
newLiteral)	r   r   r    r   r   r  ch_threedelimr?   s	            r!   r   zSinkParser.object  s    LLC(6Hvq)A1uBT+++6!a!e$0$EFAEFA}}VQ61

4;;11!45r"   c                 .   | j                  |||      }| j                  }|dk\  r|S | j                  ||      }|dk  ry|}||   }|t        v rt        j                  ||      }|r/|j                         }|j                  t        |||              |S t        j                  ||      }|r/|j                         }|j                  t        |||              |S t        j                  ||      }|r/|j                         }|j                  t        |||              |S |dz  }|| j                  v r|||dz    |k(  r|}	|dz  }n|}	|dz  }d }
| j                  |||	      \  }}d }||   dk(  rNt        j                  ||dz         }|t!        | j"                  |||d      |j                         }||dz   | }|}|||dz    dk(  rg }| j%                  ||dz   |      }|d   }
|j                  | j&                  j)                  ||
|             |S y)	Nr   r   r'   r&   r   z3Bad language code syntax on string literal, after @r(   z^^)r  r~   r   rX  exponent_syntaxrM  rN  r   ra   decimal_syntaxr   integer_syntaxr   r   ra  langcoder   r}   r   r{   rb  )r   r   r    r   r   	startliner  rk   rc  rd  dtr?   langres2s                 r!   r	  zSinkParser.nodeOrLiteral  s:   IIfa%JJ	6Hvq)A1uB_$#))&!4AJJuVAa[12H"((3AJJwva{34H"((3AJJy!56H AvHT+++!a!e$0$EFAEFA}}VQ61!9# vq1u5Ay' MM%"V  A!!a%!,DA!a!e$,Dfa!eT:AaB

4;;11!R>?r"   c                 0    t        |t              r|d   S |S )Nr&   )r   tuple)r   r2  s     r!   r   zSinkParser.uriOf  s    c5!q6M
r"   c                 *   |d   }|dz  |dz  |dz  |dz  f\  }}}}|}	d}
| j                   }t        |      }|	|k  r||	   |k(  rd||k(  r	|	dz   }||
fS ||k(  rQ||	|	dz    |k(  r|	dz   }|
|z  }
||
fS ||	|	dz    |k(  r|	dz   }|
|z  }
||
fS ||	|	dz    |k(  r	|	dz   }||
fS |	dz  }	|
|z  }
rt        j                  ||	      }|sJ d||	d	z
  |	 d
||	|	d	z           |j	                         }	 |
||	| z  }
||   }||k(  r|}	|dv r||k7  r|
|z  }
|dz   }	|dv rE||k(  rt        | j                  |||d      | xj                   dz  c_         |
|z  }
|dz   }	|	| _        n|dk(  r|dz   }	||	   }|st        | j                  |||d      dj                  |      }|dk\  rd|   }|
|z  }
|	dz  }	n[|dk(  r| j                  ||	dz   |      \  }	}|
|z  }
n7|dk(  r| j                  ||	dz   |      \  }	}|
|z  }
n| j                  ||d       |	|k  r| j                  ||d       y# t
        $ re d}||	| D ]  }|dt        |      z  z   } t        j                         d   j                         }t        | j                  |||	dd|d|z         w xY w)zRparse an N3 string constant delimited by delim.
        return index, val
        r   r(   r'         r   r&   z!Quote expected in string at ^ in    r  z %02xz"Unicode error appending charactersrH  z to string, because
	>   rw   rx   >   rI  rJ  znewline found in string literalr=   zunterminated string literal (2)z
abfrtvn\"'z
	
\"'uUz
bad escapezunterminated string literalN)r~   r,   interestingsearchr_  UnicodeErrorordsysexc_info__str__r   r}   r   r*   uEscapeUEscape)r   r   r    rd  delim1delim2delim3delim4delim5r   ustrrj  rS  rk   errr\  streasonr  r   uchs                       r!   ra  zSinkParser.strconst  s    q)/!VaZ!VVWZ)W&JJ	[
*nayF"F?AAd7NVOa!a%(F2E $wa!a%(F2E $wa!a%(F2E $w FAFND""61-A q2v"q1r6" 1
 	Aq#" BV|z!bFl
E|#F?#!9  

a

E#$ tEAY#!9  #''+6/2CCKDFA3Y LLQ	BEArBJD3Y LLQ	BEArBJDNN61l;A *nD 	vq"?@   ! 3A3q6!12C3<<>!,446MM88;XFG s   ,H$ $A.Jc                     t        |      ||z   k  rt        | j                  |||d      	 ||z   |j                  t        d|z   ||||z    z         fS #  t        | j                  |||d||||z    z         xY w)Nzunterminated string literal(3)r=   zbad string literal hex escape: )r,   r   r}   r@  rl   )r   r   r    rj  regnr   s          r!   _unicodeEscapezSinkParser._unicodeEscapeW  s    v;Qy&!5U 		q5#''-APQEAR1RSSS	1F1q1u4EE s   &A $A7c                 6    | j                  |||t        dd      S )Nrq  rt  )r  rA  r   r   r    rj  s       r!   r}  zSinkParser.uEscapeg      ""61iCPPr"   c                 6    | j                  |||t        dd      S )N   ru  )r  r?  r  s       r!   r~  zSinkParser.UEscapej  r  r"   c                 H    t        | j                  | j                  |||      rV   )r   r}   r~   )r   r   r    msgs       r!   r   zSinkParser.BadSyntaxm  s    tzz61cBBr"   )Nr   Nr   NF)FrV   )-__name__
__module____qualname__r   r-   r   r   r   r   r   r   r   r   r   rr   r   r   r   r   r   r   r   r   r   r  r2   r  r  r   r   r  r   r   r   r>  r   r   r   r	  r   ra  r  r}  r~  r   r;   r"   r!   rn   rn   W  s    G#RU+H802"`D=~&!,
@

)Tl))O*tl/b>4TJX&:"HeN8BHmA^ QQCr"   rn   c                   (    e Zd Zd Zd Zed        Zy)r   c                 h    |j                  d      | _        || _        || _        || _        || _        y Nr   )encode_str_i_whyr~   _uri)r   r   r~   r   r    r   s         r!   r   zBadSyntax.__init__v  s.    MM'*		
	r"   c           
          | j                   }| j                  }d}|dkD  rd}|dz
  }nd}t        |      |z
  dkD  rd}nd}d| j                  dz   | j                  | j
                  |||| |||dz    |fz  S )Nr   <   z...r   z8at line %i of <%s>:
Bad syntax (%s) at ^ in:
"%s%s^%s%s"r&   )r  r  r,   r~   r  r  )r   r   r    rD  preposts         r!   r|  zBadSyntax.__str__}  s    GGr6CRBCv;?RDDKJJNIIII2aL1q2vO
 
 	
r"   c                     t        |       S rV   )rS   r   s    r!   messagezBadSyntax.message  s    4yr"   N)r  r  r  r   r|  propertyr  r;   r"   r!   r   r   u  s     
0  r"   r   c                   >    e Zd ZdZd Zd Zd Zd
dZddZd Z	d	 Z
y)Formular   c                    t               j                  | _        d| _        t        xj
                  dz  c_        t        j
                  | _        i | _        i | _        t        |j                  | j                               | _        y )Nr   r&   )r   
identifier)r   hexuuidcounterr  numberexistentials
universalsr   r   idquotedgraph)r   parents     r!   r   zFormula.__init__  sW    GKK	!nn&V\\dggiPr"   c                      d| j                   z  S Nz_:Formula%s)r  r   s    r!   r|  zFormula.__str__  s    t{{**r"   c                 2    t        d| j                  z        S r  )r   r  r   s    r!   r  z
Formula.id  s    ]T[[011r"   Nc                     |<| xj                   dz  c_         t        d| j                  d| j                         }|S t        |j                  d      j	                         j                  dd            }|S )Nr&   fbr   r9  )r  r   r  splitr
  r>   )r   r   r   bns       r!   r  zFormula.newBlankNode  sb    ;LLAL499dll;<B 	 syy~))+33C=>B	r"   c                 R    t        |j                  d      j                               S )Nr   )r	   r  r
  )r   r   r   s      r!   r   zFormula.newUniversal  s    		#**,--r"   c                 >    | j                         | j                  |<   y rV   )r  r  )r   r   s     r!   r   zFormula.declareExistential  s    #002!r"   c                     | j                   S rV   )r  r   s    r!   r#  zFormula.close  s    r"   )NNrV   )r  r  r  r  r   r|  r  r  r   r   r#  r;   r"   r!   r  r    s+    FQ+2.3 r"   r  z([\x80-\xff])c                   j    e Zd Zd Zd Zd Zd ZddZd Zd Z	d	 Z
d
 ZddZd Zd Zd Zd Zd Zy)RDFSinkc                 `    d | _         t               j                  | _        d| _        || _        y r   )rootFormular   r  r  r  graph)r   r  s     r!   r   zRDFSink.__init__  s%    GKK	
r"   c                     t        | j                  j                  dd      }|st        d      t	        | j                        }|S )Nformula_awareFz:Cannot create formula parser with non-formula-aware store.)getattrr  r   r   r  )r   far  s      r!   r   zRDFSink.newFormula  sB    TZZ%%>L  DJJr"   c                 B    t        | j                  j                  |      S rV   )r   r  r   )r   r  s     r!   newGraphzRDFSink.newGraph  s    TZZ%%z22r"   c                     t        |d         S r   )r   r   rX   s     r!   r   zRDFSink.newSymbol  s    d1gr"   Nc                 l   t        |t              r|j                  |      S t        |t              s|<| xj                  dz  c_        t        d| j                  d| j                        }|S t        t        |d         j                  d      j                         j                  dd            }|S )Nr&   r  r  r   r   r9  )r   r  r  r   r  r   r  rS   r  r
  r>   )r   argr   r   r  s        r!   r  zRDFSink.newBlankNode  s    c7###C((U#s{LLAL499dll;<B 	 s3q6{((-113;;CEFB	r"   c                 :    |rt        ||      S t        ||      S )Ndatatype)rl  )r   )r   r?   rk  rl  s       r!   rb  zRDFSink.newLiteral  s    1r**14((r"   c                    | j                  d      }|s|S | j                  d      }| j                  d      }| j                  |      x}}|d d D ]?  }| j                  ||||f       | j                  |      }	| j                  ||||	f       |	}A | j                  ||||d   f       | j                  ||||f       |S )Nz.http://www.w3.org/1999/02/22-rdf-syntax-ns#nilz0http://www.w3.org/1999/02/22-rdf-syntax-ns#firstz/http://www.w3.org/1999/02/22-rdf-syntax-ns#restr   )r   r  r   )
r   r  r  rK   rH   rI   afrp   neans
             r!   r$  zRDFSink.newList  s    nnMNJQR~~OP""1%%QCR& 	B5!R01""1%B4B/0A		
 	Aua2/0AtQ,-	r"   c                     t        |      S rV   )setr  s     r!   r!  zRDFSink.newSet  s    4yr"   c                 2    dj                  d |D              S )Nr%   c              3   2   K   | ]  }t        |        y wrV   )repr).0r  s     r!   	<genexpr>z.RDFSink.setDefaultNamespace.<locals>.<genexpr>   s     .AQ.s   )r   r  s     r!   r   zRDFSink.setDefaultNamespace  s    xx....r"   c                    |\  }}}}t        |d      rt        d      | j                  ||      }| j                  ||      }| j                  ||      }|| j                  k(  r| j                  j                  |||f       y t        |t              r|j                  j                  |||f       y |j                  |||f       y )Nr   zFormula used as predicate)	hasattrr   	normaliser  r  addr   r  r  )r   r   r   r  pr?   os          r!   r   zRDFSink.makeStatement  s    
1a1i 9::NN1a NN1a NN1a    JJNNAq!9%7#MMq!Qi(EE1a)r"   c                 \   t        |t              rt        t        |d               S t        |t              r*t        t        |      j                         t              }|S t        |t              st        |t              rt        t        |      t              }|S t        |t              r%t        |      }|dk(  rd}t        |t              }|S t        |t              rt        t        |      t              }|S t        |t              r||j                   v r|j                   |   S |S )Nr&   r  z-00)r   ro  r   rS   boolr   r   BOOLEAN_DATATYPErh   r   INTEGER_DATATYPEr   DECIMAL_DATATYPEra   DOUBLE_DATATYPEr  r  )r   r  r  r?   values        r!   r  zRDFSink.normalise  s    a#ad)$$aA1ABAHaAy!9A)9:AHa!FE}(89AHaA9AHa!ANN"~~a(( r"   c                     |S rV   r;   )r   	somethings     r!   r   zRDFSink.intern9  s    r"   c                      y rV   r;   )r   rB  r   s      r!   rr   zRDFSink.bind<      r"   c                     || _         y rV   )r  r   r   s     r!   r   zRDFSink.startDoc?  s
    "r"   c                      y rV   r;   r  s     r!   r   zRDFSink.endDocB  r  r"   NNNrV   )r  r  r  r   r   r  r   r  rb  r$  r!  r   r   r  r   rr   r   r   r;   r"   r!   r  r    sN    3)$/(!F#r"   r  c                     d}| D ]@  }t        |      dkD  st        |      dk  rdt        |      z  }ndt        |      z  }||z   }B |j                  d      S )zUse URL encoding to return an ASCII string
    corresponding to the given UTF8 string

    >>> hexify("http://example/a b")
    b'http://example/a%20b'

    r   ~   !   z%%%02Xz%czlatin-1)ry  r  )r  r?   r  s      r!   r   r   L  sb     	A r7S=CGbLCG#BBBF 88Ir"   c                       e Zd ZdZd ZddZy)r   zK
    An RDFLib parser for Turtle

    See http://www.w3.org/TR/turtle/
    c                      y rV   r;   r   s    r!   r   zTurtleParser.__init__g  r  r"   c                    |dvrt        d|z        t        |      }|j                  |j                         xs |j	                         xs d      }t        |||      }|j                         }|s|j                         }|j                  |       |j                  j                         D ]  \  }	}
|j                  |	|
        y )Nr  z:N3/Turtle files are always utf-8 encoded, I was passed: %sr   )r   r   )r   r  
absolutizegetPublicIdgetSystemIdrn   getCharacterStreamgetByteStreamr   rz   itemsrr   )r   sourcer  encodingr   sinkr   r  r   r   	namespaces              r!   parsezTurtleParser.parsej  s    ?*LxW  u~""6#5#5#7#U6;M;M;O#USUVtWV<**,))+F	V!"!2!2!4 	*FIJJvy)	*r"   N)r   Tr  r  r  __doc__r   r   r;   r"   r!   r   r   _  s    *r"   r   c                       e Zd ZdZd ZddZy)r   z`
    An RDFLib parser for Notation3

    See http://www.w3.org/DesignIssues/Notation3.html

    c                      y rV   r;   r   s    r!   r   zN3Parser.__init__  r  r"   c                 $   t        |j                  dd      }t        |j                  dd      }|st        d      |st        d      t        |j                        }||_        |j
                  |_        t        j                  | |||d       y )Ncontext_awareFr  z-Cannot parse N3 into non-context-aware store.z-Cannot parse N3 into non-formula-aware store.)r   )r   )r  r   r   r   default_contextnamespace_managerr   r   )r   r  r  r  car  
conj_graphs          r!   r   zN3Parser.parse  s     U[[/59U[[/59MNNMNN%EKK8
%*
" (-'>'>
$4XeLr"   N)r   r  r;   r"   r!   r   r     s    Mr"   r   c                  ,    dd l } | j                          y r   )doctesttestmod)r  s    r!   _testr    s    OOr"   c                  *   t               } t        |       }dt        j                  j	                  t        j
                         t        j                  d         z   }t        ||      }|j                  dz   |j                  d<   |j                          t        t        j                  d   d      }|j                         }|j                          |j                  |       |j!                          | j#                  d      D ]  }t%        |        y )Nr7   r&   )r   r   r   rbr  )r   r  r9   r2   r   r:   rz  argvrn   r   rz   r   openr   r#  r   r   quadsprint)gr  base_urir  r  rdbytesr   s          r!   mainr    s    A1:D277<<		SXXa[AAH4*Ajj3&AKKOJJLSXXa[$AffhGGGIFF7OHHJWW'( ar"   __main__)r   )wr  rz  r9   rer   r_   r   r  r   rdflib.exceptionsr   rdflib.termr   r   r   r	   r
   r   rdflib.graphr   r   r   rdflib.compatr   __all__rdflib.parserr   r   r   r   r8   CONTEXTPREDSUBJOBJPARTSALL4SYMBOLFORMULALITERAL
LITERAL_DTLITERAL_LANG	ANONYMOUS
XMLLITERALr   NODE_MERGE_URI
forSomeSym	forAllSymRDF_type_URI
RDF_NS_URIOWL_NSDAML_sameAs_URIparsesTo_URIRDF_specList_NS_Old_Logic_NSN3_firstN3_restN3_liN3_nilN3_ListN3_EmptyrO   r   rR   r   r   chatty_flagrZ   r]   N3_forSome_URIN3_forAll_URIr<  r   r   LOG_implies_URIr  r  r  FLOAT_DATATYPEr  option_noregenr  r   r   r   _rdfnsr[  rY  rR  rX  rl   compilerA  r?  N3CommentCharacterrL  rP  rO  signed_integerrh  rg  rf  digitstringrv  ri  rn   SyntaxErrorr   r   r  r_hibyter  r   r   r   r  r  r  r;   r"   r!   <module>rL     s  8  	 	    ) N N = = #
 !,_,D
4 dCdC	



	
0D	!
x	@:
	)8#*$1
8Gg%&7V#
$	4 
'E/	"7V#
$Gg%&   	
. 
	
	
  
 L!'>i' i' X%G#i'  ;<"cU* #&	6'(*+- c
*E 2323  
 bjj)*bjj%&RZZ	N+N+23"**@ bjj#bjj,-2::56WC WC|(" "L# f # L 2::&'f P&*6 *@M| M>* zF r"   