franz.openrdf.util package


franz.openrdf.util.contexts module

Utilities related to context managers.

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

Bases: object


Initialize self. See help(type(self)) for accurate signature.


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.

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.

  • 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.

A merged set of headers.

Return type:

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

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


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


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


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.


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


Decodes ntriples escape sequences in a string.

Actually decodes a superset of said sequences.


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

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

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


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

franz.openrdf.util.uris module


Module contents