KTBS auxiliary modules

KTBS Namespace

I contain useful namespace objects, as well as the definition of the kTBS vocabulary.

This module can be run as a program to generate the description:

  • with no argument, it will output the original version (Turtle, with a reader-friendly layout);
  • with an rdflib format as its argument, it will first convert it to that format, but the result might not be as reader-friendly.

KTBS Standalone

This is a standalone version of an HTTP-based KTBS.

ktbs.standalone.main()[source]

I launch KTBS as a standalone HTTP server.

ktbs.standalone.parse_configuration_options(options=None)[source]

I get kTBS default configuration options and override them with command line options.

Parameters:options – Command line options.
Returns:Configuration object.
ktbs.standalone.build_cmdline_options()[source]

I build ktbs command line options.

ktbs.standalone.parse_options()[source]

I parse sys.argv for the main.

ktbs.standalone.number_callback(_option, opt, _value, parser)[source]

I manage options -R, -1 and -2

ktbs.standalone.make_server_class(ktbs_config)[source]

We define this closure so that MyWSGIServer class can access the configuration options.

class ktbs.standalone.NoCache[source]

A strawman cache doing no real caching, used for debugging.

static get(_key)[source]

Always return None

class ktbs.standalone.FlashAllower(app, *domains)[source]

I wrap a WSGI application in order to make it accessible to Flash applets.

This is done by serving /crossdomain.xml .

KTBS Time library

I provide time management for kTBS.

I provide a mechanism for registering time units.

ktbs.time.register_unit(uri, unit2timedelta, timedelta2unit)[source]

I register converter functions for a unit URI.

TODO DOC document signature and semantics of converter functions

ktbs.time.get_converter_from_unit(uri)[source]

I return a converter function from the given unit to timedelta.

ktbs.time.get_converter_to_unit(uri)[source]

I return a converter function from timedelta to the given unit.

ktbs.time.ms2timedelta(a_int)[source]

I convert from milliseconds to timedelta

ktbs.time.timedelta2ms(a_timedelta)[source]

I convert from timedelta to milliseconds

ktbs.time.sec2timedelta(a_int)[source]

I convert from seconds to timedelta

ktbs.time.timedelta2sec(a_timedelta)[source]

I convert from timedelta to seconds

ktbs.time.lit2datetime(literal)[source]

Convert literal to datetime if possible, else return None.

If literal is None, also return None.

KTBS utilities

I provide utility functions for pythonic interfaces.

ktbs.utils.extend_api(cls)[source]

I extend cls according to the design rationale of the kTBS abstract API.

More precisely: * for every get_x(...) method I add a ‘x’ property (if it accepts 0 args) * for every set_x(...) method I add a setter to the ‘x’ property * for every iter_xs(...) method I add a list_xs(...) method * for every iter_xs(...) method I add a ‘xs’ property (if it accepts 0 args)

ktbs.utils.extend_api_ignore(func)[source]

I decorate functions that must be ignored by extend_api().

ktbs.utils.mint_uri_from_label(label, target, uri=None, suffix='')[source]

Mint a URI for a resource posted to target based on label.

Parameters:
  • label – the label for the resource to create
  • target – the resource “containing” the resource to create
  • uri – if provided, will be used instead (must be fresh)
  • suffix – if provided, will be added to the end of the URI
Returns:

a URI not present in target.state

Return type:

rdflib.URIRef

Raise:

InvalidDataError if uri is provided and not acceptable

ktbs.utils.short_name(uri)[source]

Return the last part of the URI (fragment or path element).