o
    i                     @  s   d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z ddlmZ ddlmZ ddlmZmZmZ dd	lmZ d
gZeeef ZG dd
 d
eZdS )a  
This is a rdflib plugin for parsing NQuad files into Conjunctive
graphs that can be used and queried. The store that backs the graph
*must* be able to handle contexts.

>>> from rdflib import ConjunctiveGraph, URIRef, Namespace
>>> g = ConjunctiveGraph()
>>> data = open("test/data/nquads.rdflib/example.nquads", "rb")
>>> g.parse(data, format="nquads") # doctest:+ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> assert len(g.store) == 449
>>> # There should be 16 separate contexts
>>> assert len([x for x in g.store.contexts()]) == 16
>>> # is the name of entity E10009 "Arco Publications"?
>>> #   (in graph http://bibliographica.org/entity/E10009)
>>> # Looking for:
>>> # <http://bibliographica.org/entity/E10009>
>>> #   <http://xmlns.com/foaf/0.1/name>
>>> #   "Arco Publications"
>>> #   <http://bibliographica.org/entity/E10009>
>>> s = URIRef("http://bibliographica.org/entity/E10009")
>>> FOAF = Namespace("http://xmlns.com/foaf/0.1/")
>>> assert(g.value(s, FOAF.name).eq("Arco Publications"))
    )annotations)	getreader)AnyMutableMappingOptional)ParserError)ConjunctiveGraph)InputSource)W3CNTriplesParserr_tailr_wspace)BNodeNQuadsParserc                   @  s&   e Zd Z	ddddZddddZdS )r   Ninputsourcer	   sinkr   bnode_contextOptional[_BNodeContextType]kwargsr   returnc              
   K  s   |j jsJ dt|j |jd| _| }|s!| }td|}t|ds*t	d|| _
d| _	 |   | _}| jdu rA	 | jS z| | W n t	y\ } zt	d	||f d}~ww q1)
a  
        Parse inputsource as an N-Quads file.

        :type inputsource: `rdflib.parser.InputSource`
        :param inputsource: the source of N-Quads-formatted data
        :type sink: `rdflib.graph.Graph`
        :param sink: where to send parsed triples
        :type bnode_context: `dict`, optional
        :param bnode_context: a dict mapping blank node identifiers to `~rdflib.term.BNode` instances.
                              See `.W3CNTriplesParser.parse`
        z1NQuadsParser must be given a context aware store.)store
identifierzutf-8readz)Item to parse must be a file-like object. TNzInvalid line (%s):
%r)r   context_awarer   r   r   getCharacterStreamgetByteStreamr   hasattr
ParseErrorfilebufferreadlineline	parseline)selfr   r   r   r   source_NQuadsParser__linemsg r'   X/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/rdflib/plugins/parsers/nquads.pyparse-   s4   


zNQuadsParser.parseNonec                 C  s   |  t | jr| jdrd S | |}|  t |  }|  t | |}|  t |  p9| |p9| j	j
}|  t | jrFtd| j	||||f d S )N#zTrailing garbage)eatr   r!   
startswithsubject	predicateobjecturirefnodeidr   r   r   r   get_contextadd)r#   r   r.   r/   objcontextr'   r'   r(   r"   \   s   






zNQuadsParser.parseline)N)
r   r	   r   r   r   r   r   r   r   r   )r   r   r   r*   )__name__
__module____qualname__r)   r"   r'   r'   r'   r(   r   +   s    /N)__doc__
__future__r   codecsr   typingr   r   r   rdflib.exceptionsr   r   rdflib.graphr   rdflib.parserr	   rdflib.plugins.parsers.ntriplesr
   r   r   rdflib.termr   __all__str_BNodeContextTyper   r'   r'   r'   r(   <module>   s    