coherence.upnp.devices.basics (module) — Cohen3 0.8.0 documentation

# coherence.upnp.devices.basics (module)

## Basics

This module contains two classes which will be used as a base classes which will be useful to create our device classes: MediaRenderer and MediaServer.

### `DeviceHttpRoot`

Inherits from `twisted.web.resource.Resource` and is used as a a base class by class the `HttpRoot`.

### `BasicDeviceMixin`

This is an EventDispatcher object used as a base class by the classes `MediaRenderer` and `MediaServer`. It contains some methods that will help us to initialize the backend as well as the methods `BasicDeviceMixin.register()` and `BasicDeviceMixin.unregister()` which will take care to register/unregister our device.

class `DeviceHttpRoot`(server)

  Bases: `twisted.web.resource.Resource`, `coherence.log.LogAble`

  `logCategory` = 'basicdevice'
  `getChildWithDefault`(path, request)

    Retrieve a static or dynamically generated child resource from me.

    First checks if a resource was added manually by putChild, and then call getChild to check for dynamic resources. Only override if you want to affect behaviour of all child lookups, rather than just dynamic ones.

    This will check to see if I have a pre-registered child resource of the given name, and call getChild if I do not.

    @see: L{IResource.getChildWithDefault}

  `getChild`(name, request)

    Retrieve a ‘child’ resource from me.

    Implement this to create dynamic resource generation – resources which are always available may be registered with self.putChild().

    This will not be called if the class-level variable ‘isLeaf’ is set in your subclass; instead, the ‘postpath’ attribute of the request will be left as a list of the remaining path elements.

    For example, the URL /foo/bar/baz will normally be:

        | site.resource.getChild('foo').getChild('bar').getChild('baz').

    However, if the resource returned by ‘bar’ has isLeaf set to true, then the getChild call will never be made on it.

    Parameters and return value have the same meaning and requirements as those defined by L{IResource.getChildWithDefault}.

  `listchilds`(uri)
  `render`(request)

    Render a given resource. See L{IResource}’s render method.

    I delegate to methods of self with the form ‘render_METHOD’ where METHOD is the HTTP that was used to make the request. Examples: render_GET, render_HEAD, render_POST, and so on. Generally you should implement those methods instead of overriding this one.

    render_METHOD methods are expected to return a byte string which will be the rendered page, unless the return value is C{server.NOT_DONE_YET}, in which case it is this class’s responsibility to write the results using C{request.write(data)} and then call C{request.finish()}.

    Old code that overrides render() directly is likewise expected to return a byte string or NOT_DONE_YET.

    @see: L{IResource.render}

class `BasicDeviceMixin`(coherence, backend, **kwargs)

  Bases: `eventdispatcher.eventdispatcher.EventDispatcher`

  This is used as a base class for the following classes:

  > - `MediaRenderer`
  > - `MediaServer`

  It contains some methods that will help us to initialize the backend (`on_backend()`, `init_complete()` and `init_failed()`). There is no need to call those methods, because it will be automatically triggered based on the backend status.

  Changed in version 0.9.0:

  - Introduced inheritance from EventDispatcher

  - Changed class variable `backend` to benefit from the EventDispatcher’s properties

  `backend`

    The device’s backend. When this variable is filled it will automatically trigger the method `on_backend()`.

  `on_backend`(*arsg)

    This function is automatically triggered whenever the `backend` class variable changes. Here we connect the backend initialization with the device.

    New in version 0.9.0.

  `init_complete`(backend)
  `init_failed`(backend, msg)
  `register`()
  `unregister`()