The steward.lib Module

We are modules that implement internal funcionalities specific to Steward.

The:Steward.lib.app_globals Module

The application’s Globals object

class steward.lib.app_globals.Globals
Globals acts as a container for objects available throughout the life of the application

The:Steward.lib.base Module

class steward.lib.base.BaseController
class steward.lib.base.BaseControllerWithUi
ui()
I parse the form and call it on to the right function in the controller. uses is a dictionary with the different uses with the name as the key and a tuple (funcion, success status, success message) as value.

The:Steward.lib.eventcollection Module

class steward.lib.eventcollection.EventCollection

I am responsable for storing and recovering events.

There are two types of events the ones that change the store and ones that do not. The events that change the contents of the store are collectively called “change-events”.

buildList(next=None, prev=None, firstId=None, size=None, actions=None, orderReverse=False, filterDeleted=False)
Build a list of events. This is the workhorse method called by other methods that want a list of events.
getAllChanges(next, prev, size)
Get all events that modify the store.
getAllEvents(next, prev, size)
Get all the events.
getCreationEventOfEvidence(id)
Return the creation event of a object with id.
getLatestAdditions()
Get the latest objects addded to the store.
getListOfEvents(id)
Get the events that are asociated with object id
markCheck(id, user)
Mark a check event in the collection.
markDelete(id, user)
Mark a delete event in the collection.
markGet(id, user)
Mark a get event in the collection.
markPurged(id, user)
Mark a purge event in the collection.
markSave(id, user)
Mark a save event in the collection.
class steward.lib.eventcollection.EventList(pageSize, nextLink, prevLink)

I am responsable for maintaining a subset of events. I am a list with additional behaviour.

toChangesXml(baseUrl)
Return a changelist as XML
toEventsXml(baseUrl)
Return a event list as XML
toXml(baseUrl, xmltype)
Generic XML generation method.

The:Steward.lib.evidencecollection Module

class steward.lib.evidencecollection.EvidenceCollection

I am responsable for registring the objects and know how to access them.

getEvidence(id)
Through me you can recieve an object which represents the data in the store. If you receive this object the store has the id available.
listDeletedEvidences()
Generate a list of deleted objects.
purgeEvidence(id)
Change the status of id to “purged” meaning that the object has been removed from the store.
removeEvidence(id)
I make sure the id is made un-available in the store.
saveEvidence(dataStream, mimetype)
You can pass me an evidence (a datastream) and I will save it for you. I’ll return you a Registry object that represents that object in the data store.

The:Steward.lib.exceptions Module

exception steward.lib.exceptions.DatabaseHasAlienDataException
I am raised when there is data in te database that is not part of the application
exception steward.lib.exceptions.EvidenceNotAvailableException
The Evidence object was not available. This can happen when the give ID does not correspond to a known evidence.
exception steward.lib.exceptions.FileMissingFromStoreException
Accoding to the registry the file should be there, but it cannot be found in the store.
exception steward.lib.exceptions.FileObjectWasEmptyExeception
I am raised when a file object unexpectedly did not contain any data
exception steward.lib.exceptions.InternalInconsistencyException
Something is wrong. I should generate a http error 500.
exception steward.lib.exceptions.NotSupportedConfigurationException
I am raised when a configuration is not possible
exception steward.lib.exceptions.PublishingFormatNotSupportedException
I am raised when I cannot decode a document send to me for storage.
exception steward.lib.exceptions.SchemaNeedsUpgradeException
I get raised when the schema of the database should be updated.
exception steward.lib.exceptions.StoreDirectoryException
I get raised when there is a problem with the store directory.
exception steward.lib.exceptions.StoreNeedsUpgradeException
I get raised when the store needs updating.
exception steward.lib.exceptions.UnexpectedVersionException
I get raised when a schema is found that’s not expected version and we do not know what to do about it.
exception steward.lib.exceptions.UpgradeException
Generic exception when something needs upgrading

The:Steward.lib.helpers Module

Helper functions

Consists of functions to typically be used within templates, but also available to Controllers. This module is available to both as ‘h’.

steward.lib.helpers.AbsoluteHostUrl(req)

Returns the absolute base url. Prefer the configuration over the data from the request object. >>> orig_base_url = config[‘base_url’] >>> class Req(object): ... pass >>> req = Req() >>> req.scheme = “https” >>> req.host = “foo.com” >>> config[‘base_url’] = ‘http://example.com:1234‘ >>> AbsoluteHostUrl(req) ‘http://example.com:1234‘ >>> config[‘base_url’] = ‘http://example.com:1234/‘ >>> AbsoluteHostUrl(req) ‘http://example.com:1234‘ >>> config[‘base_url’] = ‘http://example.com:1234/media‘ >>> AbsoluteHostUrl(req) ‘http://example.com:1234‘ >>> config[‘base_url’] = ‘https://example.com:1234/media/‘ >>> AbsoluteHostUrl(req) ‘https://example.com:1234

When the base_url is not set, get it from the request it self. >>> del config[‘base_url’] >>> AbsoluteHostUrl(req) ‘https://foo.com‘ >>> req.host = “foo.com:8443” >>> AbsoluteHostUrl(req) ‘https://foo.com:8443’ >>> config[‘base_url’] = orig_base_url

steward.lib.helpers.BaseUrlPath()

Generate the path part of the base url.

>>> orig_base_url = config['base_url']
>>> config['base_url'] = 'http://example.com:1234'
>>> BaseUrlPath()
'/'
>>> config['base_url'] = 'http://example.com:1234/'
>>> BaseUrlPath()
'/'
>>> config['base_url'] = 'http://example.com:1234/media'
>>> BaseUrlPath()
'/media/'
>>> config['base_url'] = 'https://example.com:1234/media/'
>>> BaseUrlPath()
'/media/'

When the base_url is not set it should always be / >>> del config[‘base_url’] >>> BaseUrlPath() ‘/’ >>> config[‘base_url’] = orig_base_url

The:Steward.lib.middleware Module

The:Steward.lib.namespaces Module

I define common namespace static variables for the Steward application. They are mostly internet Standards.

The:Steward.lib.rfc3339 Module

The function rfc3339 formats dates according to the RFC 3339. rfc3339 tries to have as much as possible sensible defaults.

steward.lib.rfc3339.rfc3339(date, utc=False, use_system_timezone=True)

Return a string formatted according to the RFC 3339. If called with utc=True, it normalizes date to the UTC date. If date does not have any timezone information, uses the local timezone:

>>> date = datetime.datetime(2008, 4, 2, 20)
>>> rfc3339(date, utc=True, use_system_timezone=False)
'2008-04-02T20:00:00Z'
>>> rfc3339(date) # doctest: +ELLIPSIS
'2008-04-02T20:00:00...'

If called with user_system_time=False don’t use the local timezone if date does not have timezone informations and consider the offset to UTC to be zero:

>>> rfc3339(date, use_system_timezone=False)
'2008-04-02T20:00:00+00:00'

date must be a datetime.datetime, datetime.date or a timestamp as returned by time.time():

>>> rfc3339(0, utc=True, use_system_timezone=False)
'1970-01-01T00:00:00Z'
>>> rfc3339(datetime.date(2008, 9, 6), utc=True,
...         use_system_timezone=False)
'2008-09-06T00:00:00Z'
>>> rfc3339(datetime.date(2008, 9, 6),
...         use_system_timezone=False)
'2008-09-06T00:00:00+00:00'
>>> rfc3339('foo bar')
...
TypeError: excepted datetime, got str instead

The:Steward.lib.store Module

class steward.lib.store.Store(baseDir)

I am responsable for saving and recovering files from disk. I also generate the IDs of the objects saved. I never read an entire object to memory.

Parameters:
  • baseDir – The directory under which I store all the files.
Check

I check if the store is good to start up. I will raised exceptions when this is not the case.

Parameters:
  • conf – the configuration dictionary to check the Store.
Returns:

True if all is okay.

Setup

I create the initial basic store structure.

Parameters:
  • conf – The configuration dictionary to setup the Store.
open(id)

When I get an id I will retreive the corresponding object from disk. If I cannot find it, i will raise a FileMissingFromStoreException .

Parameters:
  • id – The identifier of the object in the store.
Raises FileMissingFromStoreException:
 

If object cannot be found in the store.

purge(id)

I remove objects from the store. When trying to delete an object not in the store, I do not complain.

Parameters:
  • id – Identifier of the object to be removed.
save(src)

They give me a file object and I save it to the store. When everything is savely stored I return the ID of the object and it’s size in bytes.

First I save it in a temporary file and only when everything has been receive I move it to it’s final location. I do not raise an exception when I receive twice the same file.

Parameters:
  • src – File-like object that will be saved into the store.
Returns:

Identifier of the object stored, Length in bytes.

Return type:

String, integer

Raises FileObjectWasEmptyExeception:
 

When reading from src doesn’t product any bytes.

The:Steward.lib.service Module

class steward.lib.service.Service(name, desc='Unknown')

One service. Each service can have multiple use-cases.

addFormInterface(serviceUrl)
If the service has a interface for posting forms, the URL of that service should be added here.
addUsage(name, routeName, meth, desc)
Through me you can add a new use case to the service.
class steward.lib.service.ServiceUsage(name, routeName, meth, desc)
I am a simple container object for a service use case.
class steward.lib.service.Services(storeTitle)

I maintain the list of services that steward clams to support. All other modules that have external interfaces should notify me so that I can update my service list document.

addService(serviceList)
Add a new service to my service page. I take a serviceList as input. This should have all the details of the service.
toXml(xslUrl=None)
Build a XML document for the service.

The:Steward.lib.users Module

class steward.lib.users.StewardUsers(model, enc)
I am the interface between the user-model and authkit

The:Steward.lib.utils Module

Misc Utilities

steward.lib.utils.BuildXml(doc, xslUrl=None)
I Build a string from a xml tree. Optionally I include a xsl Processing Instruction

The:Steward.lib.wsse Module

class steward.lib.wsse.AuthWsseAuthenticator(realm, authfunc, withBasic=False)
WSSE authentication middleware.
class steward.lib.wsse.WsseHandler(application, realm, authfunc, withBasic=False)
Hander for Webservice Security Extension
class steward.lib.wsse.WsseUserSetter(application, realm, authfunc, users, withBasic=False)
Sets the user object if authentication was sucessful