model
index
/web/script/jcgregorio/bitworking.org/projects/apptestsuite/client/atompubbase/model.py

There are four classes that make up the core
of the atompub model.
 
class Context
class Service
class Collection
class Entry
 
Context represents the current state, as represented
by a service document, a collection and an entry.
 
Each atompub object (ServiceCollection, or Entry
is just instantiated with a URI (or with a Context)
that it then uses to perform its work. Each object can produce
a list of URIs (actually Context objects) (possibly filtered) 
for the next level down. The only parsing done will be xpaths to
pick out URIs, e.g. collections from service documents. 
Here is an example of how the classes are used together:
 
    # Note that httplib2.Http is passed in so you 
    # can pass in your own instrumented version, etc.
    from httplib2 import Http
    h = httplib2.Http()
    c = Context(h, service_document_uri)
    service = Service(c)
 
    collection = Collection(service.iter()[0]) 
    entry = Entry(collection.iter()[0])
    (headers, body) = entry.get()
    body = "<entry>...some updated stuff </entry>"
    entry.put(body)
 
    # saving and restoring is a matter of pickling/unpickling the Context.
    import pickle
    f = file("somefile", "w")
    pickle.dump(entry.context(), f)
 
    import pickle
    f = file("somefile", "r")
    context = pickle.load(f)
    # You pass the class names into restore() for it to use to restore the context.
    (service, collection, entry) = context.restore(ServiceCollectionEntry)
 
    # You don't have to use the context, Entries
    # and Collections can be instantiated from URIs instead
    # of Context instances.
    entry = Entry(entry_edit_uri)

 
Modules
       
copy
events
httplib2
mimeparse.mimeparse
urlparse

 
Classes
       
__builtin__.object
Collection
Context
Entry
Service

 
class Collection(__builtin__.object)
     Methods defined here:
__init__(self, context_or_uri)
Create a Collection from either the URI of the
collection, or from a Context object.
context(self)
The Context associated with this Collection.
create(self, headers=None, body=None)
Create a new member in the collection.
Can be used to create members of regular
and media collections. Be sure to set the 
'content-type' header appropriately.
 
Returns a tuple of the HTTP response headers
and the body.
entry_create(self, headers=None, body=None)
Convenience method that returns an Entry object
if the create has succeeded, or None if it fails.
etree(self)
Returns an ElementTree representation of the 
current page of the collection.
get(self, headers=None, body=None)
Retrieves the first feed in a paged series of 
collection documents.
 
Returns a tuple of the HTTP response headers
and the body.
get_next(self, headers=None, body=None)
Collections can be paged across many
Atom feeds. Get's the next feed in the
paging.
 
Returns a tuple of the HTTP response headers
and the body.
has_next(self)
Collections can be paged across many
Atom feeds. Returns True if there is a 
'next' feed we can get.
iter(self)
Returns in iterable that produces a Context 
object for every Entry in the collection.
iter_entry(self)
Returns in iterable that produces an elementtree
Entry for every Entry in the collection. Note that this
Entry is the possibly incomplete Entry in the collection
feed.

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Collection' objects>
list of weak references to the object (if defined)

 
class Context(__builtin__.object)
    Encapsulates the current service documents,
the current collection and the current 
entry. Can be picked and un-pickled to
achieve persistence of context.
 
  Methods defined here:
__init__(self, http=None, service=None, collection=None, entry=None)
http is either an instance of httplib2.Http() or something that 
acts like it. For this module the only tow functions that need to 
be implemented are request() and add_credentials().
collpop(self)
See collpush.
collpush(self, uri)
The collpush and collpop members are similar to the
command line 'pushd' and 'popd' commands. They let you
change to a different collection and then pop back
to the older collection when you are done.
restore(self, service_type, collection_type, entry_type)
Restore the state from a Context. The types of the objects
to be instantiated for the service, collection and entry 
are passed in. If no URI is set for a specific level 
then None is returned for that instance.

Properties defined here:
collection
The URI of the collection. None if not set yet.
get = _get_collection(self)
set = _set_collection(self, collection)
entry
The URI of the entry. None if not set yet.
get = _get_entry(self)
set = _set_entry(self, entry)
service
The URI of the Service Document. None if not set yet.
get = _get_service(self)
set = _set_service(self, service)

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Context' objects>
list of weak references to the object (if defined)
http = None

 
class Entry(__builtin__.object)
     Methods defined here:
__init__(self, context_or_uri)
Create an Entry from either the URI of the
entry edit URI, or from a Context object.
context(self)
delete(self, headers=None, body=None)
Delete the entry from the server.
etree(self)
Returns an ElementTree representation of the Entry.
get(self, headers=None, body=None)
Retrieve the representation for this entry.
get_media(self, headers=None, body=None)
If this entry is a Media Link Entry, then retrieve
the associated media.
has_media(self)
Returns True if this is a Media Link Entry.
put(self, headers=None, body=None)
Update the entry on the server. If the body to send
is not supplied then the internal elementtree element
will be serialized and sent to the server.
put_media(self, headers=None, body=None)
If this entry is a Media Link Entry, then update 
the associated media.

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Entry' objects>
list of weak references to the object (if defined)

 
class Service(__builtin__.object)
    An Atom Publishing Protocol Service Document.
 
  Methods defined here:
__init__(self, context_or_uri)
context(self)
Get the curent Context associated with this Service Document.
etree(self)
Returns an ElementTree representation of the Service Document.
get(self, headers=None, body=None)
Retrieve the current Service Document from the server.
 
Returns a tuple of the HTTP response headers
and the body.
iter(self)
Returns a generator that iterates over all
the collections in the service document.
iter_match(self, mimerange)
Returns a generator that iterates over 
the collections in the service document 
that accept the given mimerange. The mimerange
can be a specific mimetype - "image/png" - or 
a range - "image/*".

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Service' objects>
list of weak references to the object (if defined)

 
Functions
       
absolutize(baseuri, uri)
Given a baseuri, return the absolute
version of the given uri. Works whether
uri is relative or absolute.
init_event_handlers()
Add in hooks to the ServiceCollection
and Entry classes to enable Events.
link_value(etree, xpath, relation)
Given and elementtree element 'etree', find all link
elements under the given xpath and return the @href
of the link of the given relation.

 
Data
        APP = 'http://www.w3.org/2007/app'
APP_COLL = '{http://www.w3.org/2007/app}collection'
APP_MEMBER_TYPE = '{http://www.w3.org/2007/app}accept'
ATOM = 'http://www.w3.org/2005/Atom'
ATOM_ENTRY = '{http://www.w3.org/2005/Atom}entry'
ATOM_TITLE = '{http://www.w3.org/2005/Atom}title'
LINK = '{http://www.w3.org/2005/Atom}link'
XHTML = 'http://www.w3.org/1999/xhtml'