[Dev] Easier access to parcel contents

Phillip J. Eby pje at telecommunity.com
Tue Jul 26 15:44:42 PDT 2005


Yesterday I added a new feature that lets you conveniently access items 
contained in parcels without needing to directly use repository paths, 
UUIDs, or other mechanisms.  It works similarly to an "xmlns" declaration 
in parcel.xml, except you use it in Python code.

I originally wrote it to experiment with ways to speed up the parcel 
loader, but from discussion during some of today's meetings I gather that 
other people are interested in knowing about it.

The feature is ``schema.ns``, and you can use it something like this:

     from application import schema

     ...

     # code that needs access to items in the "osaf.current" parcel
     current = schema.ns('osaf.current', repoView)
     current_contact = current.Contact.item

Basically, it makes the named parcel accessible via dotted attribute 
access, giving you either the contents of the module (classes, methods, 
etc.), or the contents of the parcel (i.e. items).  It is considerably 
faster than access via absolute repository paths such as 
"//parcels/osaf/current/Contact".

In any case, we want to stop using paths as a primary access method, so 
that we can get rid of kludges like __parcel__, and so that developers only 
have to learn and remember one kind of "address" for parcel items.  Over 
time, we'll hopefully be able to remove all parcel path dependencies from 
the Chandler code base, which will also be helpful in flattening the 
currently very deep package hierarchy.




More information about the Dev mailing list