Package sword2 :: Module collection :: Class SDCollection
[hide private]
[frames] | no frames]

Class SDCollection

source code


`Collection` - holds, parses and presents simple attributes with information taken from a collection entry within a SWORD2 Service Document.

This will be instanciated by a `sword2.Service_Document` and as such, is unlikely to be called explicitly.

Usage:

>>> from sword2 import SDCollection
>>> c = SDCollection()

.... pull an `etree.SubElement` from a service document into `collection_node`

>>> c.load_from_etree(collection_node)
>>> c.collectionPolicy
"This collection has the following policy for deposits"
>>> c.title
"Thesis Deposit"
Instance Methods [hide private]
 
__init__(self, title=None, href=None, accept=[], accept_multipart=[], categories=[], collectionPolicy=None, description=None, mediation=None, treatment=None, acceptPackaging=[], service=[], dom=None)
Creates a `Collection` object - as used by `sword2.Service_Document`
source code
 
_reset(self)
Blank this instance of `SDCollection`
source code
 
load_from_etree(self, collection)
Parse an `etree.SubElement` into attributes in this object.
source code
 
__str__(self)
Provides a simple display of the pertinent information in this object suitable for CLI logging.
source code
 
__repr__(self)
Provides the atom.title of the collection as part of the repr reply
source code
 
to_json(self)
Provides a simple means to turn the important parsed information into a simple JSON-encoded form.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, title=None, href=None, accept=[], accept_multipart=[], categories=[], collectionPolicy=None, description=None, mediation=None, treatment=None, acceptPackaging=[], service=[], dom=None)
(Constructor)

source code 

Creates a `Collection` object - as used by `sword2.Service_Document`

#BETASWORD2URL
See http://sword-app.svn.sourceforge.net/viewvc/sword-app/spec/trunk/SWORDProfile.html?revision=HEAD#protocoloperations_retreivingservicedocument
for more details about the SWORD2 Service Document.

Usage:

Read useful information from the attributes of this object once loaded.

Attributes::

title                --  <atom:title> - Title of collection, (`str`)
href                 --  <collection href=... > - Collection IRI (`str`)
accept               --  <accept>*</accept> - the formats which this collection can take in (`list` of `str`)
accept_multipart     --  <accept alternate="multipart-related">*</accept> - the formats which this collection can take
                                                                                       in via multipart-related (`list` of `str`)
categories           --  <atom:catogory> - Collection category (`list` of `sword2.Category`'s)
collectionPolicy     --  <sword:collectionPolicy> - Collection policy (`str`)
description          --  <dcterms:description> - Collection descriptive text (`str`)
mediation            --  <sword:mediation> - Support for mediated deposit (`True` or `False`)
treatment            --  <sword:treatment> - from the SWORD2 specifications:
                                    ".. either a human-readable statement describing treatment the deposited resource 
                                    has received or a IRI that dereferences to such a description."
acceptPackaging      --  <sword:acceptPackaging> - Accepted package types (`list` of `str`)
                                    from the SWORD2 specifications: "The value SHOULD be a IRI for a known packaging format"
service              --  <sword:service> - References to nested service descriptions (`list` of `str`)

Example XML fragment that is expected:  (xmlns="http://www.w3.org/2007/app")
    
...

<collection href="http://swordapp.org/col-iri/43">
    <atom:title>Collection 43</atom:title>
    <accept>*/*</accept>
    <accept alternate="multipart-related">*/*</accept>
    <sword:collectionPolicy>Collection Policy</sword:collectionPolicy>
    <dcterms:abstract>Collection Description</dcterms:abstract>
    <sword:mediation>false</sword:mediation>
    <sword:treatment>Treatment description</sword:treatment>
    <sword:acceptPackaging>http://purl.org/net/sword/package/SimpleZip</sword:acceptPackaging>
    <sword:acceptPackaging>http://purl.org/net/sword/package/METSDSpaceSIP</sword:acceptPackaging>
    <sword:service>http://swordapp.org/sd-iri/e4</sword:service>
</collection>
...

Parsing this fragment:

Again, this step is done by the `sword2.Service_Document`, but if the above XML was in the `doc` variable:

    # Get an etree-compatible library, such as from `lxml.etree`, `xml.etree` or `elementtree.ElementTree`
    >>> from sword2.compatible_libs import etree
    >>> from sword2 import SDCollection
    >>> dom = etree.fromstring(doc)

    # create an `SDCollection` instance from this XML document
    >>> c = SDCollection(dom = dom)

    # query it
    >>> c.treatment
    "Treatment description"
    # Non-unique elements, for example:
    >>> c.service
    ["http://swordapp.org/sd-iri/e4"]
    >>> c.accept
    ["*/*"]

Overrides: object.__init__

load_from_etree(self, collection)

source code 

Parse an `etree.SubElement` into attributes in this object.

Also, caches the most recently used DOM object it is passed in `self.dom`

__str__(self)
(Informal representation operator)

source code 

Provides a simple display of the pertinent information in this object suitable for CLI logging.

Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 

Provides the atom.title of the collection as part of the repr reply

Overrides: object.__repr__

to_json(self)

source code 

Provides a simple means to turn the important parsed information into a simple JSON-encoded form.

NB this uses the attributes of the object, not the cached DOM object, so information can be altered/added on the fly.