Package advene :: Package model :: Package core :: Module element :: Class PackageElement
[hide private]
[frames] | no frames]

Class PackageElement

source code

                object --+    
                         |    
        meta.WithMetaMixin --+
                             |
                object --+   |
                         |   |
    events.WithEventsMixin --+
                             |
                object --+   |
                         |   |
tales.WithAbsoluteUrlMixin --+
                             |
                    object --+
                             |
                            PackageElement
Known Subclasses:


I am the common subclass of all package element.


Package elements are unique volatile instances:

* unique, because it is enforced that the same element will never
  be represented at a given time by two distinct instances; hence,
  elements can be compared with the ``is`` operator as well as
  ``==``

* volatile, because it is not guaranteed that, at two instants, the
  instance representing a given element will be the same; unused instances
  may be freed at any time, and a new instance will be created on demand.

This should normally normally be transparent for the user.

Developper note
===============
So that volatility is indeed transparent to users, the `__setattr__` method
has been overridden: since custom attributes are not stored in the backend,
the instance should be kept in memory as long as it has custom attributes.

As a consequence, all "non-custom" attributes (i.e. those that will be
correctly re-generated when the element is re-instantiated) must be
declared as class attribute (usually with None as their default value).

This must also be true of subclasses of elements (NB: mixin classes should
normally already do that).

Instance Methods [hide private]
 
__init__(self, owner, id)
Must not be used directly, nor overridden.
source code
 
__setattr__(self, name, value)
Make instance heavier when a new custom attribute is created.
source code
 
__delattr__(self, name)
Make instance lighter when a custom attribute is deleted.
source code
 
make_id_in(self, pkg)
Compute an id-ref for this element in the context of the given package.
source code
 
iter_references(self, package=None)
Iter over all references that are made to this element.
source code
 
delete(self)
Delete this element.
source code
 
_get_id(self)
The identifier of this element in the context of its owner package.
source code
 
_set_id(self, new_id)
Rename this element to `new_id`, if it is not already in use in the package, else raises an AssertionError.
source code
 
_update_caches(self, old_idref, new_idref, element, relation)
This cooperative method is used to update all caches when an element in the cache is renamed.
source code
 
_get_uriref(self)
The URI-ref identifying this element.
source code
 
_get_owner(self)
The package containing (or owner package) this element.
source code
 
iter_my_tags(self, package=None, inherited=True)
Iter over the tags associated with this element in ``package``.
source code
 
iter_my_tag_ids(self, package=None, inherited=True, _get=0)
Iter over the id-refs of the tags associated with this element in ``package``.
source code
 
_iter_my_tags_or_tag_ids(self, package=None, inherited=True, _get=0)
Iter over the id-refs of the tags associated with this element in ``package``.
source code
 
iter_taggers(self, tag, package=None)
Iter over all the packages associating this element to ``tag``.
source code
 
has_tag(self, tag, package=None, inherited=True)
Is this element associated to ``tag`` by ``package``.
source code
 
_increase_weight(self)
Elements are created with weight 0.
source code
 
_decrease_weight(self)
:see: _increase_weight
source code
 
_make_event_delegate(self)
Required by WithEventsMixin
source code
 
emit(self, detailed_signal, *args)
Override WithEventsMixin.emit in order to automatically emit the package signal corresponding to each element signal.
source code
 
connect(self, detailed_signal, handler, *args)
Connect a handler to a signal.
source code
 
disconnect(self, handler_id)
Disconnect a handler from a signal.
source code
 
_self_connect(self, detailed_signal, handler, *args)
This alternative to `connect` can only be used by the element itself.
source code
 
_tales_my_tags(self, context_package) source code
 
_compute_absolute_url(self, aliases) source code
 
_tales_representation(self, context)
Return a concise representation for the element.
source code
 
_tales_color(self, context)
Return the color of the element.
source code

Inherited from object: __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __str__

    Inherited from meta.WithMetaMixin
 
_get_meta_id_or_ref(self, key, default=_RAISE, _return_id=True)
Return the metadata id (string or element) associated to the given key.
source code
 
_get_ns_dict(self) source code
 
_tales_meta(self, context=None) source code
 
del_meta(self, key)
Delete the metadata.
source code
 
get_meta(self, key, default=_RAISE)
Return the metadata (string or element) associated to the given key.
source code
 
get_meta_id(self, key, default=_RAISE, _return_id=True)
Return the metadata id (string or element) associated to the given key.
source code
 
iter_meta(self)
Iter over all the metadata of this object.
source code
 
iter_meta_ids(self)
Iter over all the metadata of this object.
source code
 
set_meta(self, key, val, val_is_idref=False)
Set the metadata.
source code
    Inherited from events.WithEventsMixin
 
block_handler(self, handler_id)
Prevent the handler identified by handler_id to be invoked until it is unblocked.
source code
 
emit_lazy(self, lazy_params)
Like emit, but lazy_params is assumed to be a function returning an iterable of the params to send to emit.
source code
 
enter_no_event_section(self)
Disable all event emission for this object, until `exit_no_event_section` is called.
source code
 
exit_no_event_section(self)
Re-enables all event emission for this object.
source code
 
handler_block(self, handler_id)
Prevent the handler identified by handler_id to be invoked until it is unblocked.
source code
 
handler_is_connected(self, handler_id)
Return True iff the given handler_id represents a connected handler.
source code
 
handler_unblock(self, handler_id)
Unblock the blocked handler identified by handler_id so it can be invoked again.
source code
 
has_handler(self, handler_id)
Return True iff the given handler_id represents a connected handler.
source code
 
stop_emission(self, detailed_signal)
Stop the current emission of the signal specified by detailed_signal.
source code
 
unblock_handler(self, handler_id)
Unblock the blocked handler identified by handler_id so it can be invoked again.
source code
    Inherited from tales.WithAbsoluteUrlMixin
 
_absolute_url_fail(self, msg='') source code
 
_tales_absolute_url(self, context)
See class documentation.
source code
Class Methods [hide private]
 
instantiate(cls, owner, id, *args)
Factory method to create an instance from backend data.
source code
 
create_new(cls, owner, id)
Factory method to create a new instance both in memory and backend.
source code
    Inherited from meta.WithMetaMixin
 
make_metadata_property(cls, key, alias=None, default=_RAISE, doc=None)
Attempts to create a python property in cls mapping to metadata key.
source code
Static Methods [hide private]
 
_check_reference(pkg, element, type=None, required=False)
Raise a ModelError if element is not referenceable by pkg, and (if provided) if it has not the given type.
source code
Class Variables [hide private]
  _id = None
  _owner = None
  _weight = 0
Properties [hide private]
  id
The identifier of this element in the context of its owner package.
  owner
The package containing (or owner package) this element.
  uriref
The URI-ref identifying this element.

Inherited from object: __class__

    Inherited from meta.WithMetaMixin
  meta
Method Details [hide private]

__init__(self, owner, id)
(Constructor)

source code 

Must not be used directly, nor overridden. Use class methods instantiate or create_new instead.

Overrides: object.__init__

instantiate(cls, owner, id, *args)
Class Method

source code 

Factory method to create an instance from backend data.

This method expect the exact data from the backend, so it does not need to be tolerant or to check consistency (the backend is assumed to be sane).

__setattr__(self, name, value)

source code 

Make instance heavier when a new custom attribute is created.

Overrides: object.__setattr__

__delattr__(self, name)

source code 

Make instance lighter when a custom attribute is deleted.

Overrides: object.__delattr__

create_new(cls, owner, id)
Class Method

source code 

Factory method to create a new instance both in memory and backend.

This method will usually perform checks and conversions from its actual arguments to the data expected to the backend. It is responsible for 1/ storing the data in the backend and 2/ initializing the instance (for which it should reuse instantiate to reduce redundancy).

Note that this method *should* be tolerant w.r.t. its parameters, especially accepting both element instances or ID-refs.

NB: this method does nothing and must not be invoked by superclasses (indeed, it raises an exception).

_check_reference(pkg, element, type=None, required=False)
Static Method

source code 

Raise a ModelError if element is not referenceable by pkg, and (if provided) if it has not the given type. Furthermore, if required is set to True, raise a ModelError if element is None (else None is silently ignored).

Note that element may be a strict ID-ref, in which case this method will do its best to check its type, but will *succeed silently* if the element is unreachable (because parsers need to be able to add unreachable elements).

Also, return the ID-ref of that element in this element's owner package, for this information is usually useful in the situations where a check is performed. If element is None, return "".

iter_references(self, package=None)

source code 

Iter over all references that are made to this element.

A reference is represented by a tuple of the form * ('item', list) * ('member', relation) * ('meta', package_or_element, key) * ('tagged', package, tag) * ('tagging', package, element) -- for tags only * (attribute_name, other_element)

References are searched in the given package. If no package is given, references are searched in this element's owner package and in all packages that are currently loaded and directly importing this packages.

delete(self)

source code 

Delete this element.

If the element is known to be referenced by other elements, all remaining references are cut (but the referer elements are not deleted). Note that this does not guarantees that some references the the deleted element will not continue to exist in packages that are not currently loaded.

_get_id(self)

source code 

The identifier of this element in the context of its owner package.

Decorators:
  • @autoproperty

_set_id(self, new_id)

source code 

Rename this element to `new_id`, if it is not already in use in the package, else raises an AssertionError.

Decorators:
  • @autoproperty

_update_caches(self, old_idref, new_idref, element, relation)

source code 

This cooperative method is used to update all caches when an element in the cache is renamed. The old_idref and new_idref are provided, as well as the relation (as represented by backend methods `iter_references` and `iter_references_with_import`) with this element. The renamed element may be provided or be None, depending on the situation.

Overrides: meta.WithMetaMixin._update_caches

_get_uriref(self)

source code 

The URI-ref identifying this element.

It is built from the URI of its owner package, suffixed with the id of the element as a fragment-id (#).

Decorators:
  • @autoproperty

_get_owner(self)

source code 

The package containing (or owner package) this element.

Decorators:
  • @autoproperty

iter_my_tags(self, package=None, inherited=True)

source code 

Iter over the tags associated with this element in ``package``.

If ``package`` is not set, the session variable ``package`` is used instead. If the latter is not set, a TypeError is raised.

If ``inherited`` is set to False, the tags associated by imported packages of ``package`` will not be yielded.

If a tag is unreachable, None is yielded.

See also `iter_my_tag_ids`.

iter_my_tag_ids(self, package=None, inherited=True, _get=0)

source code 

Iter over the id-refs of the tags associated with this element in ``package``.

If ``package`` is not set, the session variable ``package`` is used instead. If the latter is not set, a TypeError is raised.

If ``inherited`` is set to False, the tags associated by imported packages of ``package`` will not be yielded.

See also `iter_my_tags`.

_iter_my_tags_or_tag_ids(self, package=None, inherited=True, _get=0)

source code 

Iter over the id-refs of the tags associated with this element in ``package``.

If ``package`` is not set, the session variable ``package`` is used instead. If the latter is not set, a TypeError is raised.

If ``inherited`` is set to False, the tags associated by imported packages of ``package`` will not be yielded.

See also `iter_my_tags`.

iter_taggers(self, tag, package=None)

source code 

Iter over all the packages associating this element to ``tag``.

``package`` is the top-level package. If not provided, the ``package`` session variable is used. If the latter is unset, a TypeError is raised.

has_tag(self, tag, package=None, inherited=True)

source code 

Is this element associated to ``tag`` by ``package``.

If ``package`` is not provided, the ``package`` session variable is used. If the latter is unset, a TypeError is raised.

If ``inherited`` is set to False, only return True if ``package`` itself associates this element to ``tag``; else return True also if the association is inherited from an imported package.

_increase_weight(self)

source code 

Elements are created with weight 0. Increasing its weight is equivalent to creating a strong reference to it, making it not volatile. Once the reason for keeping the element is gone, the weight should be decreased again with `_decrease_weight`.

emit(self, detailed_signal, *args)

source code 

Override WithEventsMixin.emit in order to automatically emit the package signal corresponding to each element signal.

Overrides: events.WithEventsMixin.emit

connect(self, detailed_signal, handler, *args)

source code 

Connect a handler to a signal.

Note that an element with connected signals becomes heavier (i.e. less volatile).

:see: `WithEventsMixin.connect`

Overrides: events.WithEventsMixin.connect

disconnect(self, handler_id)

source code 

Disconnect a handler from a signal.

:see: `connect` :see: `WithMetaMixin.disconnect`

Overrides: events.WithEventsMixin.disconnect

_self_connect(self, detailed_signal, handler, *args)

source code 

This alternative to `connect` can only be used by the element itself. It connects the handler to the signal but *does not* make the element heavier (since if the handler will disappear at the same time as the element...).

_tales_my_tags(self, context_package)

source code 
Decorators:
  • @tales_property
  • @tales_use_as_context("package")

_tales_representation(self, context)

source code 

Return a concise representation for the element.

Decorators:
  • @tales_property

_tales_color(self, context)

source code 

Return the color of the element.

Decorators:
  • @tales_property

Property Details [hide private]

id

The identifier of this element in the context of its owner package.

Get Method:
_get_id(self) - The identifier of this element in the context of its owner package.
Set Method:
_set_id(self, new_id) - Rename this element to `new_id`, if it is not already in use in the package, else raises an AssertionError.

owner

The package containing (or owner package) this element.

Get Method:
_get_owner(self) - The package containing (or owner package) this element.

uriref

The URI-ref identifying this element.

It is built from the URI of its owner package, suffixed with the id of the element as a fragment-id (#).

Get Method:
_get_uriref(self) - The URI-ref identifying this element.