"Bobo and Principia: An Object-Based Web Application Platform" by Amos Latteier Web Techniques, January 1999 Web Techniques grants permission to use these listings (and code) for private or commercial use provided that credit to Web Techniques and the author is maintained within the comments of the source. For questions, contact editors@web-techniques.com. [LISTING ONE] # Acquisition of a phone number import Acquisition # define empty classes that use acquisition class Location(Acquisition.Implicit): pass class Individual(Acquisition.Implicit): pass # create home, work and me objects home=Location() home.phone="555-1212" work=Location() work.phone="123-4567" me=Individual() # locate me at home home.resident=me print home.resident.phone # prints "555-1212" # locate me at work work.worker=me print work.worker.phone # prints "123-4567" [LISTING TWO] # Basic persistence and object database use import BoboPOS class Customer(BoboPOS.Persistent): "A persistent class" def __init__(self,name): self.name=name def set_favorite(self,food): self.favorite_food=food # open the object store db=BoboPOS.PickleDictionary("customers.bbb") # if amos is not already in the object store if not db.has_key("amos"): # create a Customer instance in the object store db["amos"]=Customer("Amos") # change an attribute of the persistent object db["amos"].set_favorite("spam") # commit the change get_transaction().commit() # prints "Amos' favorite food is spam" print "Amos' favorite food is", db["amos"].favorite_food [LISTING THREE] # Templates are used to display an object in HTML import DocumentTemplate class Food: "Something edible" def __init__(self,name,calories): self.name=name self.calories=calories def is_fattening(self): if self.calories > 100: return 1 index_html=DocumentTemplate.HTML("""\ <html> <p>Food: <!--#var name--></p> <p>Calories: <!--#var calories--></p> <!--#if is_fattening--> <p><blink>Warning: Do Not Eat!</blink></p> <!--#/if--> </html>""") # create a Food object, spam spam=Food("SPAM",250) # display it with its template print spam.index_html(spam)