def evaluate(self, output=None, output_format=RDFFormat.TABLE): """ Execute the embedded query against the RDF store. :param output: A file name, file descriptor or a file-like object to save the results to (optional). ``True`` can be used as a synonym for stdout. :type output: str|file|int|bool :param output_format: Serialization format for ``output``. The default is TABLE. :type output_format: RDFFormat :return: An iterator over statements or None (if ``output`` is used).. :rtype: GraphQueryResult """ with output_to(output) as out: callback = None if output is None else out.write accept = None if output is None else RDFFormat.mime_type_for_format( output_format) response = self.evaluate_generic_query(accept=accept, callback=callback) if output is None: return GraphQueryResult(response) else: return None
def evaluate(self, output=None, output_format=RDFFormat.NQUADS): """ Execute the embedded query against the RDF store. Return a graph. """ with output_to(output) as out: callback = None if output is None else out.write accept = None if output is None else RDFFormat.mime_type_for_format(output_format) response = self.evaluate_generic_query(accept=accept, callback=callback) if output is None: return GraphQueryResult(response) else: return None
def evaluate(self, count=False, output=None, output_format=TupleFormat.TABLE): """Execute the embedded query against the RDF store. Return an iterator that produces for each step a tuple of values (resources and literals) corresponding to the variables or expressions in a 'select' clause (or its equivalent). :param count: If ``True`` return the number of result rows instead of the usual iterator. :type count: bool :param output: A file name, file descriptor or a file-like object to save the results to (optional). ``True`` can be used as a synonym for stdout. :type output: str|file|int|bool :param output_format: Serialization format for ``output``. The default is TABLE. :type output_format: RDFFormat :return: Either an iterator over results, an integer (the number of results, if ``count`` is used) or ``None`` (if ``output`` is used). :rtype: TupleQueryResult|int """ with output_to(output) as out: callback = None if output is None else out.write accept = None if output is None else TupleFormat.mime_type_for_format( output_format) response = self.evaluate_generic_query(count=count, accept=accept, callback=callback) if count: return response if output is not None: return None return TupleQueryResult(response['names'], response['values'], response.get('queryInfo'))
def evaluate(self, count=False, output=None, output_format=TupleFormat.CSV): """ Execute the embedded query against the RDF store. Return an iterator that produces for each step a tuple of values (resources and literals) corresponding to the variables or expressions in a 'select' clause (or its equivalent). """ with output_to(output) as out: callback = None if output is None else out.write accept = None if output is None else TupleFormat.mime_type_for_format(output_format) response = self.evaluate_generic_query( count=count, accept=accept, callback=callback) if count: return response if output is not None: return None return TupleQueryResult(response['names'], response['values'])
def evaluate(self, count=False, output=None, output_format=TupleFormat.TABLE): """Execute the embedded query against the RDF store. Return an iterator that produces for each step a tuple of values (resources and literals) corresponding to the variables or expressions in a 'select' clause (or its equivalent). :param count: If ``True`` return the number of result rows instead of the usual iterator. :type count: bool :param output: A file name, file descriptor or a file-like object to save the results to (optional). ``True`` can be used as a synonym for stdout. :type output: str|file|int|bool :param output_format: Serialization format for ``output``. The default is TABLE. :type output_format: RDFFormat :return: Either an iterator over results, an integer (the number of results, if ``count`` is used) or ``None`` (if ``output`` is used). :rtype: TupleQueryResult|int """ with output_to(output) as out: callback = None if output is None else out.write accept = None if output is None else TupleFormat.mime_type_for_format(output_format) response = self.evaluate_generic_query( count=count, accept=accept, callback=callback) if count: return response if output is not None: return None return TupleQueryResult(response['names'], response['values'])
def evaluate(self, output=None, output_format=RDFFormat.TABLE): """ Execute the embedded query against the RDF store. :param output: A file name, file descriptor or a file-like object to save the results to (optional). ``True`` can be used as a synonym for stdout. :type output: str|file|int|bool :param output_format: Serialization format for ``output``. The default is TABLE. :type output_format: RDFFormat :return: An iterator over statements or None (if ``output`` is used).. :rtype: GraphQueryResult """ with output_to(output) as out: callback = None if output is None else out.write accept = None if output is None else RDFFormat.mime_type_for_format(output_format) response = self.evaluate_generic_query(accept=accept, callback=callback) if output is None: return GraphQueryResult(response) else: return None
def test_output_to_stderr(capfd): with output_to(2) as f: f.write(b'test') out, err = capfd.readouterr() assert err == 'test'
def test_output_to_true(capfd): with output_to(True) as f: f.write(b'test') out, err = capfd.readouterr() assert out == 'test'