wotpy.wot.servient

Class that represents a WoT servient.

Classes

Servient([hostname, catalogue_port, …]) An entity that is both a WoT client and server at the same time.
TDCatalogueHandler(application, request, …) Handler that returns the entire catalogue of Things contained in this servient.
TDHandler(application, request, **kwargs) Handler that returns the TD document of a given Thing.

Exceptions

ServientStateException Exception raised when the user modifies the Servient while the Servient is in an inappropriate state.
class wotpy.wot.servient.Servient(hostname=None, catalogue_port=9090, clients=None, clients_config=None, dnssd_enabled=False, dnssd_instance_name=None)

Bases: object

An entity that is both a WoT client and server at the same time. WoT servers are Web servers that possess capabilities to access underlying IoT devices and expose a public interface named the WoT Interface that may be used by other clients. WoT clients are entities that are able to understand the WoT Interface to send requests and interact with IoT devices exposed by other WoT servients or servers using the capabilities of a Web client such as Web browser.

add_client(client)

Adds a new Protocol Binding client to this servient.

add_exposed_thing(exposed_thing)

Adds an ExposedThing to this Servient. ExposedThings are disabled by default.

add_server(server)

Adds a new Protocol Binding server to this servient.

catalogue_port

Returns the current port of the HTTP Thing Description catalogue service.

clients

Returns the dict of Protocol Binding clients attached to this servient.

disable_exposed_thing(thing_id)

Disables the ExposedThing with the given ID. This is, the servers will not listen for requests for this thing.

disable_td_catalogue()

Disables the servient TD catalogue.

dnssd

Returns the DNS-SD instance linked to this Servient (if enabled and started).

dnssd_instance_name

Returns the user-given DNS-SD service instance name.

enable_exposed_thing(thing_id)

Enables the ExposedThing with the given ID. This is, the servers will listen for requests for this thing.

enabled_exposed_things

Returns an iterator for the enabled ExposedThings contained in this Servient.

exposed_thing_set

Returns the ExposedThingSet instance that contains the ExposedThings of this servient.

exposed_things

Returns an iterator for the ExposedThings contained in this Servient.

get_exposed_thing(thing_id)

Finds and returns an ExposedThing contained in this servient by Thing ID. Raises ValueError if the ExposedThing is not present.

get_thing_base_url(exposed_thing)

Return the base URL for the given ExposedThing for one of the currently active servers.

hostname

Hostname attached to this servient.

is_running

Returns True if the Servient is currently running (i.e. the attached servers have been started).

refresh_forms()

Cleans and regenerates Forms for all the ExposedThings and servers contained in this servient.

remove_client(protocol)

Removes the Protocol Binding client with the given protocol from this servient.

remove_exposed_thing(thing_id)

Disables and removes an ExposedThing from this Servient.

remove_server(protocol)

Removes the Protocol Binding server with the given protocol from this servient.

select_client(td, name)

Returns the Protocol Binding client instance to communicate with the given Interaction.

servers

Returns the dict of Protocol Binding servers attached to this servient.

shutdown()

Stops the server configured under this servient.

start()

Starts the servers and returns an instance of the WoT object.

exception wotpy.wot.servient.ServientStateException

Bases: Exception

Exception raised when the user modifies the Servient while the Servient is in an inappropriate state.

class wotpy.wot.servient.TDCatalogueHandler(application, request, **kwargs)

Bases: tornado.web.RequestHandler

Handler that returns the entire catalogue of Things contained in this servient. May return TDs in expanded format or URL pointers to the individual TDs.

get()
initialize(servient)

Hook for subclass initialization. Called for each request.

A dictionary passed as the third argument of a url spec will be supplied as keyword arguments to initialize().

Example:

class ProfileHandler(RequestHandler):
    def initialize(self, database):
        self.database = database

    def get(self, username):
        ...

app = Application([
    (r'/user/(.*)', ProfileHandler, dict(database=database)),
    ])
class wotpy.wot.servient.TDHandler(application, request, **kwargs)

Bases: tornado.web.RequestHandler

Handler that returns the TD document of a given Thing.

get(thing_url_name)
initialize(servient)

Hook for subclass initialization. Called for each request.

A dictionary passed as the third argument of a url spec will be supplied as keyword arguments to initialize().

Example:

class ProfileHandler(RequestHandler):
    def initialize(self, database):
        self.database = database

    def get(self, username):
        ...

app = Application([
    (r'/user/(.*)', ProfileHandler, dict(database=database)),
    ])