lakesuperior.util package¶
Submodules¶
lakesuperior.util.benchmark module¶
lakesuperior.util.generators module¶
lakesuperior.util.ingest_random_image module¶
lakesuperior.util.locustfile module¶
lakesuperior.util.toolbox module¶
Utility to translate and generate strings and other objects.
-
class
lakesuperior.util.toolbox.
RequestUtils
[source]¶ Bases:
object
Utilities that require access to an HTTP request context.
Initialize this within a Flask request context.
-
globalize_string
(s)[source]¶ Convert URNs into URIs in a string using the application base URI.
Parameters: s (string) – Input string. Return type: string
-
globalize_term
(urn)[source]¶ Convert an URN into an URI using the application base URI.
Parameters: urn (rdflib.URIRef) – Input URN. Return type: rdflib.URIRef
-
globalize_triple
(trp)[source]¶ Globalize terms in a triple.
Parameters: trp (tuple(rdflib.URIRef)) – The triple to be converted Return type: tuple(rdflib.URIRef)
-
localize_ext_str
(s, urn)[source]¶ Convert global URIs to local in a SPARQL or RDF string.
Also replace empty URIs (<>) with a fixed local URN and take care of fragments and relative URIs.
This is a 3-pass replacement. First, global URIs whose webroot matches the application ones are replaced with internal URIs. Then, relative URIs are converted to absolute using the internal URI as the base; finally, the root node is appropriately addressed.
-
localize_payload
(data)[source]¶ Localize an RDF stream with domain-specific URIs.
Parameters: data (bytes) – Binary RDF data. Return type: bytes
-
localize_term
(uri)[source]¶ Localize an individual term.
Parameters: rdflib.URIRef – urn Input URI. Return type: rdflib.URIRef
-
localize_triple
(trp)[source]¶ Localize terms in a triple.
Parameters: trp (tuple(rdflib.URIRef)) – The triple to be converted Return type: tuple(rdflib.URIRef)
-
-
lakesuperior.util.toolbox.
fsize_fmt
(num, suffix='b')[source]¶ Format an integer into 1024-block file size format.
Adapted from Python 2 code on https://stackoverflow.com/a/1094933/3758232
Parameters: Return type: Returns: Formatted size to largest fitting unit.
-
lakesuperior.util.toolbox.
get_tree_size
(path, follow_symlinks=True)[source]¶ Return total size of files in given path and subdirs.
Ripped from https://www.python.org/dev/peps/pep-0471/
-
lakesuperior.util.toolbox.
parse_rfc7240
(h_str)[source]¶ Parse
Prefer
header as per https://tools.ietf.org/html/rfc7240The
cgi.parse_header
standard method does not work with all possible use cases for this header.Parameters: h_str (str) – The header(s) as a comma-separated list of Prefer statements, excluding the Prefer:
token.
-
lakesuperior.util.toolbox.
rel_uri_to_urn
(uri, uid)[source]¶ Convert a URIRef with a relative location (e.g.
<>
) to an URN.Parameters: - uri (URIRef) – The URI to convert.
- uid (str) – Resource UID that the URI should be relative to.
Returns: Converted URN if the input is relative, otherwise the unchanged URI.
Return type: URIRef
-
lakesuperior.util.toolbox.
rel_uri_to_urn_string
(string, uid)[source]¶ Convert relative URIs in a SPARQL or RDF string to internal URNs.
Parameters: string (str) – Input string. :param str uid Resource UID to build the base URN from.
Return type: str Returns: Modified string.