Package twisted :: Package python :: Module components :: Class Componentized

[show private | hide private]
[frames | no frames]

## Class Componentized

    Versioned --+
                |
               Componentized

Known Subclasses:
  `ManholeWindow`, `Request`, `Session`, `Registry`, `GuardSession`

I am a mixin to allow you to be adapted in various ways persistently.

I define a list of persistent adapters. This is to allow adapter classes to store system-specific state, and initialized on demand. The getComponent method implements this. You must also register adapters for this class for the interfaces that you wish to pass to getComponent.

Many other classes and utilities listed here are present in Zope3; this one is specific to Twisted.

Method Summary
| `__init__(self)`
| ``__getstate__`(self, dict)` Get state, adding a version number to it on its way out. (inherited from `Versioned`)
| `__setstate__(self, state)` (inherited from `Versioned`)
| ``addAdapter`(self, adapterClass, ignoreClass, registry)` Utility method that calls addComponent.
| ``addComponent`(self, component, ignoreClass, registry)` Add a component to me, for all appropriate interfaces.
| ``getComponent`(self, interface, registry, default)` Create or retrieve an adapter for the given interface.
| `locateAdapterClass(self, klass, interfaceClass, default, registry)`
| ``removeComponent`(self, component)` Remove the given component from me entirely, for all interfaces which it has been registered.
| `setAdapter(self, interfaceClass, adapterClass)`
| `setComponent(self, interfaceClass, component)`
| ``unsetComponent`(self, interfaceClass)` Remove my component specified by the given interface class.
| `upgradeToVersion1(self)`
| ``versionUpgrade`(self)` (internal) Do a version upgrade. (inherited from `Versioned`)

Class Variable Summary
`int` | `persistenceVersion`

Method Details

### addAdapter(self, adapterClass, ignoreClass=0, registry=None)

Utility method that calls addComponent. I take an adapter class and instantiate it with myself as the first argument.

Returns the adapter instantiated.

### addComponent(self, component, ignoreClass=0, registry=None)

Add a component to me, for all appropriate interfaces.

In order to determine which interfaces are appropriate, the component's __implements__ attribute will be scanned.

If the argument 'ignoreClass' is True, then all interfaces are considered appropriate.

Otherwise, an 'appropriate' interface is one for which its class has been registered as an adapter for my class according to the rules of getComponent.

  Returns:
    the list of appropriate interfaces

### getComponent(self, interface, registry=None, default=None)

Create or retrieve an adapter for the given interface.

If such an adapter has already been created, retrieve it from the cache that this instance keeps of all its adapters. Adapters created through this mechanism may safely store system-specific state.

If you want to register an adapter that will be created through getComponent, but you don't require (or don't want) your adapter to be cached and kept alive for the lifetime of this Componentized object, set the attribute 'temporaryAdapter' to True on your adapter class.

If you want to automatically register an adapter for all appropriate interfaces (with addComponent), set the attribute 'multiComponent' to True on your adapter class.

### removeComponent(self, component)

Remove the given component from me entirely, for all interfaces which it has been registered.

  Returns:
    a list of the interfaces that were removed.

### unsetComponent(self, interfaceClass)

Remove my component specified by the given interface class.

Class Variable Details

### persistenceVersion

  Type:
    `int`
  Value:

        1

Generated by Epydoc 1.1 on Thu May 8 13:18:56 2003 | http://epydoc.sf.net