Package amplee :: Package atompub :: Module collection :: Class AtomPubCollection
[hide private]
[frames] | no frames]

Class AtomPubCollection

source code

object --+
         |
        AtomPubCollection

Instance Methods [hide private]
 
__init__(self, workspace, name_or_id, title, base_uri, base_edit_uri, base_media_edit_uri=None, xml_attrs=None, member_extension=u'atom', member_media_type=u'application/atom+xml;type=entry', accept_media_types=None, categories=None, fixed_categories=None, favorite=False, editable_media_types=None)
Atom Publishing Protocol collection handler.
source code
AtomPubStore
store_container(self)
Returns the store carrying this collection
source code
 
set_member_class(self, member_class=<class 'amplee.atompub.member.MemberResource'>)
Sets the class to be used when (re)loading members from the store.
source code
 
attach(self, member, member_content=None, member_id=None, member_info=None, media_id=None, media_info=None, media_content=None, check_media_type=True)
Adds a member to this collection by
source code
 
prune(self, member_id=None, media_id=None)
Removes a member from a collection and the underlying storage.
source code
tuple
convert_id(self, id)
Takes the parameter and returns a tuple such as (member_id, media_id).
source code
bool
contains(self, info, as_media=False)
Does a resource belong to the storage?
source code
StorageResourceInfo subclass
get_meta_data_info(self, id)
Constructs and returns the info to the member pointed by the id parameter.
source code
StorageResourceInfo subclass
get_content_info(self, id)
Constructs and returns the info to the resource pointed by the id parameter.
source code
object
get_meta_data(self, info)
Returns the resource represented by the info parameter.
source code
object
get_content(self, info)
Returns the resource represented by the info parameter.
source code
string
get_xml_base(self)
Returns the first available xml:base value from either the collection, its workspace or service.
source code
string
get_base_uri(self)
Returns the absolute URI to the collection public face based on the xml:base value and the self.base_uri.
source code
string
get_base_edit_uri(self)
Returns the absolute URI to the collection for editing operations
source code
string
get_base_media_edit_uri(self)
Returns the absolute URI to the collection for media-editing operations
source code
amara.bindery.root_base
to_feed(self, members=None, prefix=u'atom', namespace=u'http://www.w3.org/2005/Atom', limit=-1, mint=None)
Generates an atom feed from the list of members provided, or if not provided, from the store directly up to the limit provided.
source code
amara.bindery.root_base
to_collection(self, prefix=u'app', namespace=u'http://www.w3.org/2007/app')
Returns a amara instance of the collection
source code
MemberResource or subclass or None
get_member(self, member_id)
Returns the requested member or None if not found.
source code
MemberResource or subclass or None
load_member(self, member_id, member_info=None)
Loads a member from its storage and returns it or None if not found.
source code
list
reload_members(self, start=0, limit=None)
Reloads all or part of existing members.
source code
member
iter_members(self, start=0, limit=0)
Reloads all or part of existing members by yielding each one.
source code
list
reload_members_from_feed(self, source)
Reloads members from a an atom feed.
source code
list
reload_members_from_list(self, member_ids)
Given a list of member_ids this will return a list of loaded members.
source code
 
enable_cache(self)
Enables the internal cache.
source code
 
disable_cache(self)
Disables the internal cache.
source code
 
clear_cache(self)
Clears all items from the internal cache.
source code
 
add_indexer(self, indexer)
Add an initialized Indexer instance to the collection.
source code
 
clear_indexers(self)
Removes all registered index instances from this collection.
source code

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

Properties [hide private]
AtomPubStore store
Returns the store carrying this collection
amara.bindery.root_base feed
Generates an atom feed from the list of members provided, or if not provided, from the store directly up to the limit provided.

Inherited from object: __class__

Method Details [hide private]

__init__(self, workspace, name_or_id, title, base_uri, base_edit_uri, base_media_edit_uri=None, xml_attrs=None, member_extension=u'atom', member_media_type=u'application/atom+xml;type=entry', accept_media_types=None, categories=None, fixed_categories=None, favorite=False, editable_media_types=None)
(Constructor)

source code 

Atom Publishing Protocol collection handler.

Parameters:
  • workspace (AtomPubWorkspace) - parent workspace of this collection
  • name_or_id (string) - identifier by which you reference this collection within the store [eg: 'audio']
  • base_uri (string) - base URI of the content used in links and external content
  • base_edit_uri (string) - base URI used for the edit links
  • xml_attrs (dict) - dictionary of XML attributes belonging to the xml namespace (http://www.w3.org/XML/1998/namespace). They will be passed to the top level Atom elements (feed, entry, etc.)
  • member_extension (string) - extension used for the Atom entries representing the member resource
  • member_media_type (string) - media-type for the Atom entries representing the member resource
  • accept_media_types (list) - list of a strings of acceptable media-types for this collection
  • accept_media_types (list) - list of strings of acceptable media-types to be created within this collection
  • editable_media_types (list) - list of strings of acceptable media-types to be editable within this collection. If not provided it defaults to accept_media_types.
  • categories (list) - list of dictionnaries of any of 'term', 'label', 'scheme'
  • fixed_categories (bool) - True => 'yes', False => 'no', None => undefined, ie the attribute won't appear
  • favorite (bool) - if True means this collection is the preferred one in the workspace
  • base_media_edit_uri (string)
Overrides: object.__init__

store_container(self)

source code 

Returns the store carrying this collection

Returns: AtomPubStore
the store to which this collection is attached.

set_member_class(self, member_class=<class 'amplee.atompub.member.MemberResource'>)

source code 

Sets the class to be used when (re)loading members from the store. It defaults to MemberResource.

This is required when your application has particular needs for the resource identifier generation different from the default one.

Parameters:

attach(self, member, member_content=None, member_id=None, member_info=None, media_id=None, media_info=None, media_content=None, check_media_type=True)

source code 

Adds a member to this collection by

  • adding it to the store
  • adding it to the internal cache if it is enabled

You are not forced to pass the resource content through this method if you prefer storing it in a different location without using amplee.

The member will be automatically indexed if any indexes have been set on the collection.

Parameters:
  • member (MemberResource) - an instance of MemberResource or a sub-class
  • member_content (string or file-like object) - content to be persisted into the storage. Usually an XML string of the Atom entry.
  • member_id (string) - internal identifier used to reference this member. Usually equals to the resource_name + collection.member_extension
  • member_info (StorageResourceInfo) - StorageResourceInfo instance or one of its subclasses representing the object by which the storage handles the resource.
  • media_id (string) - internal identifier used to reference the resource associated to this member.
  • media_info (StorageResourceInfo) - -- StorageResourceInfo instance or one of its subclasses representing the object by which the storage handles the media resource.
  • media_content (string or file-like object) - resource content
  • check_media_type (bool) - if False the resource media type will not be checked against collection.accept_media_types

prune(self, member_id=None, media_id=None)

source code 

Removes a member from a collection and the underlying storage. Removes only objects passed in the id parameters.

Parameters:
  • member_id (string) - identifier of the member
  • media_id (string) - identifier of the media resource

convert_id(self, id)

source code 

Takes the parameter and returns a tuple such as (member_id, media_id). This method is useful when your HTTP handler accepts both the media resource and the media link entry.

>>> member_id, media_id = collection.convert_id('some-super-article')
>>> member_id
some-super-article.atom
>>> media_id
some-super-article
Parameters:
  • id (string) - can either be member_id or media_id
Returns: tuple
a two item tuple of the form (member_id, media_id)

contains(self, info, as_media=False)

source code 

Does a resource belong to the storage?

Parameters:
Returns: bool
True if the resource represented by info exists in that storage, False otherwise.

get_meta_data_info(self, id)

source code 

Constructs and returns the info to the member pointed by the id parameter.

>>> member_id, media_id = collection.convert_id(some_id)
>>> info = collection.get_meta_data_info(member_id)
Parameters:
  • id (string) - internal identifier of the member to retrieve within the storage
Returns: StorageResourceInfo subclass
StorageResourceInfo subclass depending on the type of the storage used.

get_content_info(self, id)

source code 

Constructs and returns the info to the resource pointed by the id parameter.

>>> member_id, media_id = collection.convert_id(some_id)
>>> info = collection.get_content_info(media_id)
Parameters:
  • id (string) - internal identifier of the media resource to retrieve within the storage
Returns: StorageResourceInfo subclass
StorageResourceInfo subclass depending on the type of the storage used.

get_meta_data(self, info)

source code 

Returns the resource represented by the info parameter. The type returned depends on the choice of underlying storage. Does not check the existence of the resource.

>>> member_id, media_id = collection.convert_id(some_id)
>>> info = collection.get_meta_data_info(member_id)
>>> obj = collection.get_meta_data(info)
Parameters:
Returns: object
whatever object is returned by the member storage

get_content(self, info)

source code 

Returns the resource represented by the info parameter. The type returned depends on the choice of underlying storage. Does not check the existence of the resource.

>>> member_id, media_id = collection.convert_id(some_id)
>>> info = collection.get_content_info(media_id)
>>> obj = collection.get_content(info)
Parameters:
Returns: object
whatever object is returned by the media storage

get_xml_base(self)

source code 

Returns the first available xml:base value from either the collection, its workspace or service. If none is found it returns an empty string

Returns: string
the first found xml:base construct or an empty string

get_base_uri(self)

source code 

Returns the absolute URI to the collection public face based on the xml:base value and the self.base_uri.

Returns: string
absolute URI of the the collection public face

get_base_edit_uri(self)

source code 

Returns the absolute URI to the collection for editing operations

Returns: string
absolute URI to the collection for editing operations

get_base_media_edit_uri(self)

source code 

Returns the absolute URI to the collection for media-editing operations

Returns: string
absolute URI to the collection for media-editing operations

to_feed(self, members=None, prefix=u'atom', namespace=u'http://www.w3.org/2005/Atom', limit=-1, mint=None)

source code 

Generates an atom feed from the list of members provided, or if not provided, from the store directly up to the limit provided.

The atom:id element's value will be computed from the collection edit URI, and if provided, the mint value, which therefore must be string or None.

Parameters:
  • members (list or NoneType) - list of members to generate the feed from. If the provided value is None, the function will call Store.list_members to load the members from the member storage.
  • namespace (string) - XML namespace for Atom
  • limit (int) - upper limit of atom entries to add to the feed. The default None means as many as members contains.
  • mint (NoneType or string) - value used to generate the atom:id element's value
  • prefix (string)
Returns: amara.bindery.root_base
an amara instance representing the feed

to_collection(self, prefix=u'app', namespace=u'http://www.w3.org/2007/app')

source code 

Returns a amara instance of the collection

Parameters:
  • namespace (string) - XML namespace for Atom
  • prefix (string)
Returns: amara.bindery.root_base
an amara instance representing the collection element

get_member(self, member_id)

source code 

Returns the requested member or None if not found. If the member is not in the collection cache, amplee attempts to load it from the storage.

>>> member_id, media_id = collection.convert_id(some_id)
>>> member = collection.get_member(member_id)
Parameters:
  • member_id (string) - identifier of the member as returned by convert_id
Returns: MemberResource or subclass or None
member instance matching the provided identifier in this collection or None

load_member(self, member_id, member_info=None)

source code 

Loads a member from its storage and returns it or None if not found. The member is not added to the collection cache at this stage.

Note that if the MLE has been deleted but not the media resource this method will still return None as if both didn't exist anymore. It's up to the application to cleanup the storages from time to time.

Parameters:
Returns: MemberResource or subclass or None
member instance matching the provided identifier in this collection or None

reload_members(self, start=0, limit=None)

source code 

Reloads all or part of existing members. Call this at server startup to refresh the collection. Careful as this could be a fairly long process.

Each loaded member is (re)indexed.

Parameters:
  • start (int) - indicates where to start loading members. By default 0 means from the beginning.
  • limit (int) - indicates how many members you want to load By default None means all of them.
Returns: list
loaded members

iter_members(self, start=0, limit=0)

source code 

Reloads all or part of existing members by yielding each one.

Each loaded member is (re)indexed.

Parameters:
  • start (int) - indicates where to start yelding members. By default 0 means from the beginning.
  • limit (int) - indicates how many members you want to load By default None means no limit is set.
Returns: member
loaded member

reload_members_from_feed(self, source)

source code 

Reloads members from a an atom feed. This can be useful if you want to keep in the collection cache some given entries. You can construct a feed of those member entries and provide it to this method.

Be aware that the internal member identifier is extracted from the last segment of the rel='edit' link found in each entry.

Each loaded member is (re)indexed.

Parameters:
  • source (string or file-like object) - can be a string, a path or a file object representing the feed
Returns: list
loaded members

reload_members_from_list(self, member_ids)

source code 

Given a list of member_ids this will return a list of loaded members.

Each loaded member is (re)indexed.

Parameters:
  • member_ids (list) - list of member identifiers
Returns: list
loaded members

disable_cache(self)

source code 

Disables the internal cache.

Not thread-safe.

clear_cache(self)

source code 

Clears all items from the internal cache.

Thread safe.

clear_indexers(self)

source code 

Removes all registered index instances from this collection.

This is not thread-safe.


Property Details [hide private]

store

Returns the store carrying this collection

Get Method:
store_container(self) - Returns the store carrying this collection
Type:
AtomPubStore

feed

Generates an atom feed from the list of members provided, or if not provided, from the store directly up to the limit provided.

The atom:id element's value will be computed from the collection edit URI, and if provided, the mint value, which therefore must be string or None.

Get Method:
to_feed(self, members=None, prefix=u'atom', namespace=u'http://www.w3.org/2005/Atom', limit=-1, mint=None) - Generates an atom feed from the list of members provided, or if not provided, from the store directly up to the limit provided.
Type:
amara.bindery.root_base