Listing 3. smallhello/__init__.py
# Import the class file
import smallhello
# Define a method that creates a new instance
# of smallhello
def initialize(context):
"Create a new instance of our product"
# Register our class (product) in the current
# acquisition context, indicating what method
# (or methods) should be invoked when someone
# adds a new instance of our product.
# We'll use the trick from the "Boring" sample
# product, which uses exceptions to trap any
# problems that might occur with our product
# registration.
try:
context.registerClass(
# What object do we want to add?
smallhello.smallhello,
# What methods should be called when we want
# to create a new instance of smallhello?
constructors = (smallhello.manage_smallhello,)
)
except:
# If something goes wrong, then report it on
# stderr (as demonstrated in the Boring
# demonstration product)
# Import modules that give us full debugging
# information
import sys, traceback, string
# Find out what went wrong
type, val, tb = sys.exc_info()
# Tell the user what went wrong
sys.stderr.write(string.join(
traceback.format_exception(type, val, tb), ''))
del type, val, tb