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.


I launch KTBS as a standalone HTTP server.


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

Parameters:options – Command line options.
Returns:Configuration object.

I build ktbs command line options.


I parse sys.argv for the main.

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

I manage options -R, -1 and -2


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


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


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


I convert from milliseconds to timedelta


I convert from timedelta to milliseconds


I convert from seconds to timedelta


I convert from timedelta to seconds


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.


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)


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.

  • 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

a URI not present in target.state

Return type:



InvalidDataError if uri is provided and not acceptable


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