franz.openrdf.util package

Submodules

franz.openrdf.util.contexts module

Utilities related to context managers.

class franz.openrdf.util.contexts.BinWrapper(target)

Bases: object

__init__(target)
write(byte_string)
franz.openrdf.util.contexts.output_to(target)

Returns a file-like object constructed from target.

Target can be:

  • None: the returned stream will ignore all data

  • True: data will be written to stdout.

  • a string: a file will be opened (in binary mode)

  • a file-like object: will be returned as is.

  • an int - a file descriptor.

Parameters:

target – File path, None or a file-like object.

franz.openrdf.util.contexts.wrap_context(value)

Wrap a no-op context around an arbitrary value, so that it can be used in a with statement.

Parameters:

value – Value to be returned by the context manager.

Returns:

A context manager wrapping value.

franz.openrdf.util.http module

franz.openrdf.util.http.merge_headers(headers, extra_headers)

Merge two sets of HTTP headers.

Each set can be either a dictionary, a list of strings or None. The returned set is either a dictionary or None.

note that the returned set might be one of the original sets, so it should not be modified later.

Parameters:
  • headers (Iterable[string] | dict[string, string] | None) – The first set of headers.

  • extra_headers (Iterable[string] | dict[string, string] | None) – The second set of headers.

Returns:

A merged set of headers.

Return type:

Iterable[string] | dict[string, string] | None

franz.openrdf.util.http.normalize_headers(headers)
Create a dictionary of headers from:
  • A list of curl-style headers

  • None

  • a dictionary (return a copy).

Parameters:

headers (Iterable[string] | dict[string, string] | None) – List or dict of header (may also be None).

Returns:

A dictionary of headers suitable for requests.

Return type:

dict[string,string]

franz.openrdf.util.strings module

A strings utility module for helper functions.

franz.openrdf.util.strings.encode_ntriple_string(string)

Return a unicode string escaped according to N-Triples canonical encoding rules.

franz.openrdf.util.strings.encode_ntriple_uri(uri)

Converts a string URI to ntriples by adding angle brackets and escaping special characters.

franz.openrdf.util.strings.literal(string)

If string is a valid literal in NTriples syntax, return its value, lang tag and type. Use None if there is no language tag or no datatype. If string is not a valid literal return None.

franz.openrdf.util.strings.nodeid(string)

If string is a valid NTriples BNode reference, extract and return the node id. Otherwise return None.

franz.openrdf.util.strings.ntriples_unescape(text)

Decodes ntriples escape sequences in a string.

Actually decodes a superset of said sequences.

franz.openrdf.util.strings.to_bytes(text)

If TEXT is a Unicode string, return a byte string in utf-8. Otherwise simply return TEXT.

Parameters:

text (str|bytes|unicode) – Text to be converted.

Return type:

bytes

franz.openrdf.util.strings.to_native_string(text)

Converts text to the native string type of the Python version used. UTF-8 encoding is used if the text needs to be encoded or decoded.

Parameters:

text (str|bytes|unicode) – Text to be converted (either Unicode or bytes).

Return type:

str

franz.openrdf.util.strings.uri_escape_match(match)

Converts a Match object representing a single character into an ntriple escape sequence.

franz.openrdf.util.strings.uriref(string)

If string is a valid NTriples URI reference, extract and return the URI (as a string). Otherwise return None.

franz.openrdf.util.triples_buffer module

class franz.openrdf.util.triples_buffer.TriplesBuffer(conn: RepositoryConnection, limit: int = 1000)

Bases: object

__init__(conn: RepositoryConnection, limit: int = 1000)

Cosntruct an instance of TriplesBuffer.

Parameters

connRepositoryConnection

an instance of RepositoryConnection

limitint

size limit for the triples buffer

append(triple)

Add a triple to the buffer.

flush()

Flush all the pending triples in the buffer by calling “addTriples”, and then reset the buffer.

franz.openrdf.util.triples_buffer.buffered_triples(conn: RepositoryConnection, limit: int = 1000)

Construct an instance of TriplesBuffer that automatically flushes before the end of with statement.

franz.openrdf.util.uris module

franz.openrdf.util.uris.asURIString(value)
franz.openrdf.util.uris.getLocalNameIndex(uri)

Module contents