Package amplee :: Package atompub :: Package member :: Class MemberResource
[hide private]
[frames] | no frames]

Class MemberResource

source code

object --+
         |
        MemberResource

Instance Methods [hide private]
 
__init__(self, collection, id=None, atom=None, media_type=None)
Represents in amplee an AtomPub member resource and provides a fairly extensive API to manipulate it.
source code
int
__cmp__(self, other)
By default members are compared following their app:edited element, but you can change that behavior by setting the self.comparer attribute to a callable that will perform the comparison.
source code
 
_getentry(self) source code
 
_setentry(self, entry) source code
 
_delentry(self) source code
 
_getmediacontent(self) source code
 
_setmediacontent(self, entry) source code
 
_delmediacontent(self) source code
 
__getstate__(self) source code
 
__setstate__(self, state) source code
 
from_entry(self, entry, info=None)
Allows the filling of the current instance from an Atom entry.
source code
 
set_xslt(self, path)
Sets the XSLT to associate to the Atom entry.
source code
string
xml(self, indent=False)
Serializes the entry as a string.
source code
 
load_document(self, source)
Loads a source document into an amara instance or throws a ResourceOperationException if the operation failed.
source code
 
inherit_categories_from_collection(self)
Inserts the collection categories into the Atom entry.
source code
 
use_published_date_from(self, other_member)
Sets the current instance atom entry published element value to the one from the provided member.
source code
 
update_dates(self)
Sets the updated and edited date values to the current UTC time.
source code
 
merge_dates(self, new_member)
Sets the updated and edited date values to the values from the member provided.
source code
amara.bindery.root_base
prepare_for_public(self, content=None, external_content=False, rel=u'alternate', media_type=u'text/html', xslt_path=None)
Generates and returns an atom entry that is appropriate to be used in a public atom feed while retaining information from the member atom entry.
source code
 
index(self)
Passes the member to the collection indexers.
source code
string or NoneType
get_public_uri(self)
Returns a URI suitable for public feed and independent from the collection URI.
source code
string or NoneType
get_public_stripped_uri(self)
Returns a URI suitable for public feed and independent from the collection URI.
source code
string or NoneType
get_edit_uri(self)
Returns the URI of the member resource.
source code
string or NoneType
get_edit_media_uri(self)
Returns the URI of the media link entry (MLE)
source code
bool
is_draft(self)
Returns True is the entry has a app:control element with an app:draft element which has a text value set to yes.
source code
 
set_draft_status(self, status=False)
Changes the draft status of this member.
source code
amara.bindery.root_base
create_entry(self, source, **kwargs)
Generates the member atom entry from the provided source (an atom entry) and slug.
source code
amara.bindery.root_base
create_entry_from(self, source, existing_member, **kwargs)
Called to generate the new member entry from the atom entry provided in the source parameter as well as from the existing member in the store.
source code
amara.bindery.root_base
generate_entry(self, source, existing_member=None, **kwargs)
Generates the member atom entry from the provided source (an atom entry) Returns the content of source as a string.
source code
same as source
create_mle(self, source, **kwargs)
Creates the Media Link Entry (MLE) associated with the media resource.
source code
same as source
create_mle_from(self, source, existing_member, **kwargs)
Create the Media Link Entry (MLE) associated with the media resource extracting some meta-data from the provided ``existing_member``.
source code
same as source
generate_mle(self, source, existing_member=None, **kwargs)
Create the Media Link Entry (MLE) associated with the media resource, and if existing_member is provided, some of the atom entry meta-data are extrected from it.
source code
bool
is_entry_mimetype(self, media_type)
Checks that media_type belongs to ['application/atom+xml;type=entry', 'application/atom+xml'].
source code
object
generate(self, media_type, source, existing_member=None, **kwargs)
Wraps the generate_entry and generate_mle calls into one single call that applies either one depending on the media_type.
source code
unicode
generate_atom_id(self, entry=None, slug=None)
Called to generate a valid atom identifier (a valid URI) which will be used within the Atom entry itself.
source code
unicode
generate_resource_id(self, entry=None, slug=None, info=None)
Called to generate a token that will be used as the internal identifier for this member within its collection.
source code

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

Properties [hide private]
  atom
  content
  public_uri
Returns a URI suitable for public feed and independent from the collection URI.
  public_uri_stripped
Returns a URI suitable for public feed and independent from the collection URI.
  member_uri
Returns the URI of the member resource.
  media_uri
Returns the URI of the media link entry (MLE)

Inherited from object: __class__

Method Details [hide private]

__init__(self, collection, id=None, atom=None, media_type=None)
(Constructor)

source code 
Represents in amplee an AtomPub member resource and provides a fairly extensive API to manipulate it.
Parameters:
  • collection (AtomPubCollection) - collection holding the reference to this member
  • id (string) - identifier for this member
  • atom (amara.bindery.root_base) - amara instance representing the Atom entry
  • media_type (string) - media type of the associated resource
Overrides: object.__init__

__cmp__(self, other)
(Comparison operator)

source code 
By default members are compared following their app:edited element, but you can change that behavior by setting the self.comparer attribute to a callable that will perform the comparison.
Returns: int

from_entry(self, entry, info=None)

source code 

Allows the filling of the current instance from an Atom entry.

This will lookup for two links:
  • rel='edit'
  • rel='edit-media'
Parameters:
  • entry (amara.bindery.root_base) - atom entry attached to the MemberResource instance. Sets the instance attribute to the values extracted from the entry.

set_xslt(self, path)

source code 
Sets the XSLT to associate to the Atom entry. A processing instruction will be inserted when the self.xml() method is called.
Parameters:
  • path (string) - URI to the the XSLT resource

xml(self, indent=False)

source code 
Serializes the entry as a string.
Parameters:
  • indent (bool) - indicates if the serialization should be indented
Returns: string
serialized representation of the atom entry

load_document(self, source)

source code 
Loads a source document into an amara instance or throws a ResourceOperationException if the operation failed.
Parameters:
  • source (string or file-like object) - amara.bindery.root_base instance of the document

use_published_date_from(self, other_member)

source code 
Sets the current instance atom entry published element value to the one from the provided member.
Parameters:
  • other_member (MemberResource or subclass) - member from which the published date value must be taken from

merge_dates(self, new_member)

source code 
Sets the updated and edited date values to the values from the member provided.
Parameters:
  • new_member (MemberResource or subclass) - member from which the date values must be taken from

prepare_for_public(self, content=None, external_content=False, rel=u'alternate', media_type=u'text/html', xslt_path=None)

source code 
Generates and returns an atom entry that is appropriate to be used in a public atom feed while retaining information from the member atom entry.
Parameters:
  • content (string (not unicode)) - the XHTML content, as a string, to be set as the atom:content value
  • external_content (bool) - if True, the atom:content element will have a src attribute and no body. The URI is generated automatically.
  • rel (string) - defines the rel attribute of the atom:link element
  • media_type (string) - defines the type attribute value of the atom:link element
  • xslt_path (string) - URI of the XSLT associated with the entry as a processing-instruction
Returns: amara.bindery.root_base
the amara instance representing the atom entry

get_public_uri(self)

source code 
Returns a URI suitable for public feed and independent from the collection URI.
Returns: string or NoneType
the URI appropriate for the public feed

get_public_stripped_uri(self)

source code 
Returns a URI suitable for public feed and independent from the collection URI. It removes any trailing extension there may be.
Returns: string or NoneType
the URI appropriate for the public feed

get_edit_uri(self)

source code 
Returns the URI of the member resource.
Returns: string or NoneType
the URI to the resource within the collection

get_edit_media_uri(self)

source code 
Returns the URI of the media link entry (MLE)
Returns: string or NoneType
the URI to the resource within the collection

is_draft(self)

source code 
Returns True is the entry has a app:control element with an app:draft element which has a text value set to yes. Returns False otherwise.
Returns: bool
True if the member is a draft, False otherwise.

set_draft_status(self, status=False)

source code 
Changes the draft status of this member.
Parameters:
  • status (bool) - the new draft status to set

create_entry(self, source, **kwargs)

source code 

Generates the member atom entry from the provided source (an atom entry) and slug. Returns the content of course as a string.

After this method is called, self.entry is set.
Parameters:
  • source (string or file object) - resource string or file object wto handle. If it is a file object and self.raw_headers doesn't have a content-length key, then the file object MUST implement __len__ so that the correct amount can be read from it.
  • slug (string) - hint on how to generate the name of the resource and used as the last part of the edit and edit-media IRIs (default: None)
  • length (int) - if source is a file object, sets this value to tell amplee the amount to read from source (default: 0)
  • media_type (string) - mime-type to use for the atom entry (default: application/atom+xml;type=entry)
  • include_content (bool) - if set to False the atom:content won't be copied from the source at all. (default: True)
  • as_media (bool) - when True the processed Atom entry will be dealt with as a media member resource (default: False)
  • preserve_id (bool) - when True the original posted ID will be kept on update (default: False)
  • preserve_dates (bool) - when True the dates from source will be kept, otherwise they will be overridden by amplee with the current datetime. (default: True)
Returns: amara.bindery.root_base
the amara instance representing the atom entry

create_entry_from(self, source, existing_member, **kwargs)

source code 

Called to generate the new member entry from the atom entry provided in the source parameter as well as from the existing member in the store.

More specifically, the atom:id elements for instance will be taken from the existing member as well as a set of other elements.

Returns the content of source as a string.
Parameters:
  • source (string or file object) - resource to handle. If it is a file object and self.raw_headers doesn't have a content-length key, then the file object MUST implement __len__ so that the correct amount can be read from it.
  • existing_member (MemberResource or a subclass) - member instance of an existing member resource
  • length (int) - if source is a file object, sets this value to tell amplee the amount to read from source (default: 0)
  • include_content (bool) - if set to False the atom:content won't be copied from the source at all. (default: True)
  • as_media (bool) - when True the processed Atom entry will be dealt with as a media member resource (default: False)
  • preserve_id (bool) - when True the original posted ID will be kept on update (default: False)
  • preserve_dates (bool) - when True the dates from source will be kept, otherwise they will be overridden by amplee with the current datetime. (default: True)
Returns: amara.bindery.root_base
the amara instance representing the atom entry

generate_entry(self, source, existing_member=None, **kwargs)

source code 

Generates the member atom entry from the provided source (an atom entry) Returns the content of source as a string.

After this method is called, self.entry is set.

If existing_member is set, some of the self.entry meta-data will be generated from the existing entry such as the atom:id value.
Parameters:
  • source (string or file object) - resource to handle. If it is a file object and self.raw_headers doesn't have a content-length key, then the file object MUST implement __len__ so that the correct amount can be read from it.
  • existing_member (MemberResource or a subclass) - member instance of an existing member resource
  • slug (string) - hint on how to generate the name of the resource and used as the last part of the edit and edit-media IRIs (default: None)
  • length (int) - if source is a file object, sets this value to tell amplee the amount to read from source (default: 0)
  • media_type (string) - mime-type to use for the atom entry (default: application/atom+xml;type=entry)
  • include_content (bool) - if set to False the atom:content won't be copied from the source at all. (default: True)
  • as_media (bool) - when True the processed Atom entry will be dealt with as a media member resource (default: False)
  • preserve_id (bool) - when True the original posted ID will be kept on update (default: False)
  • preserve_dates (bool) - when True the dates from source will be kept, otherwise they will be overridden by amplee with the current datetime. (default: True)
Returns: amara.bindery.root_base
the amara instance representing the atom entry

create_mle(self, source, **kwargs)

source code 

Creates the Media Link Entry (MLE) associated with the media resource.

After this method is called, self.entry is set. Returns the content of course as it was provided and doesn't actually read it but allows for sub-classes to do so if they wish to.
Parameters:
  • source (string or file object) - resource to handle. If it is a file object and self.raw_headers doesn't have a content-length key, then the file object MUST implement __len__ so that the correct amount can be read from it (in case a sub-class wished to read it).
  • slug (string) - hint on how to generate the name of the resource and used as the last part of the edit and edit-media IRIs (default: None)
  • length (int) - the media resource size that will be happended to the edit-media link as the length attribute.
Returns: same as source
the source as it was provided, unless a subclass changes that behavior

create_mle_from(self, source, existing_member, **kwargs)

source code 

Create the Media Link Entry (MLE) associated with the media resource extracting some meta-data from the provided ``existing_member``.

Returns the content of course as it was provided.
Parameters:
  • source (string or file object) - resource to handle. If it is a file object and self.raw_headers doesn't have a content-length key, then the file object MUST implement __len__ so that the correct amount can be read from it (in case a sub-class wished to read it).
  • existing_member (MemberResource or a subclass) - member instance of an existing member resource
Returns: same as source
the source as it was provided, unless a subclass changes that behavior

generate_mle(self, source, existing_member=None, **kwargs)

source code 

Create the Media Link Entry (MLE) associated with the media resource, and if existing_member is provided, some of the atom entry meta-data are extrected from it.

After this method is called, self.entry is set. Returns the content of course as it was provided.
Parameters:
  • source (string or file object) - resource to handle. If it is a file object and self.raw_headers doesn't have a content-length key, then the file object MUST implement __len__ so that the correct amount can be read from it (in case a sub-class wished to read it).
  • slug (string) - hint on how to generate the name of the resource and used as the last part of the edit and edit-media IRIs (default: None)
  • length (int) - the media resource size that will be happended to the edit-media link as the length attribute.
  • existing_member (MemberResource or a subclass) - member instance of an existing member resource
Returns: same as source
the source as it was provided, unless a subclass changes that behavior

is_entry_mimetype(self, media_type)

source code 
Checks that media_type belongs to ['application/atom+xml;type=entry', 'application/atom+xml']. The value is first lowered case, its spaces are removed and trailing and leading spaces are stripped.
Parameters:
  • media_type (string) - the mime-type to test
Returns: bool
True if it belongs and False otherwise.

generate(self, media_type, source, existing_member=None, **kwargs)

source code 
Wraps the generate_entry and generate_mle calls into one single call that applies either one depending on the media_type. If is_entry_mimetype returns True then generate_entry is called.
Returns: object
whatever is returned by the inner call.

generate_atom_id(self, entry=None, slug=None)

source code 

Called to generate a valid atom identifier (a valid URI) which will be used within the Atom entry itself.

Override this method to generate appropriate atom:id values. You MUST return unicode objects.
Parameters:
  • entry (amara.binder.root_base) - the atom entry instance
  • slug (string) - hint on how to generate the atom id
Returns: unicode
a UUID value

generate_resource_id(self, entry=None, slug=None, info=None)

source code 

Called to generate a token that will be used as the internal identifier for this member within its collection. Also used as the identifier within the storage it will be added to which means the returned value should be valid for the chosen storage.

Override this method to generate appropriate values as identifier for the resources within the storage.
Parameters:
  • entry (amara.binder.root_base) - the atom entry instance
  • slug (string) - hint on how to generate the atom id
  • info (StorageResourceInfo subclass) - object representing the resource within the storage
Returns: unicode
atom:id value of the member entry.

Property Details [hide private]

atom

Get Method:
amplee.atompub.member.MemberResource._getentry(self)
Set Method:
amplee.atompub.member.MemberResource._setentry(self, entry)
Delete Method:
amplee.atompub.member.MemberResource._delentry(self)

content

Get Method:
amplee.atompub.member.MemberResource._getmediacontent(self)
Set Method:
amplee.atompub.member.MemberResource._setmediacontent(self, entry)
Delete Method:
amplee.atompub.member.MemberResource._delmediacontent(self)

public_uri

Returns a URI suitable for public feed and independent from the collection URI.
Get Method:
amplee.atompub.member.MemberResource.get_public_uri(self) - Returns a URI suitable for public feed and independent from the collection URI.

public_uri_stripped

Returns a URI suitable for public feed and independent from the collection URI.
Get Method:
amplee.atompub.member.MemberResource.get_public_uri(self) - Returns a URI suitable for public feed and independent from the collection URI.

member_uri

Returns the URI of the member resource.
Get Method:
amplee.atompub.member.MemberResource.get_edit_uri(self) - Returns the URI of the member resource.

media_uri

Returns the URI of the media link entry (MLE)
Get Method:
amplee.atompub.member.MemberResource.get_edit_media_uri(self) - Returns the URI of the media link entry (MLE)