Skip to content

Instantly share code, notes, and snippets.

@xarg
Created November 24, 2011 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xarg/1391210 to your computer and use it in GitHub Desktop.
Save xarg/1391210 to your computer and use it in GitHub Desktop.
Speach utility
from zope.component import getGlobalSiteManager
from zope.interface import Interface, implements
#It's is common practice to prefix interfaces with a big "i".
class ISpeach(Interface):
def say(text):
"""Say something"""
class Hello: # Our utility
#I promise that I implement ISpeach interface.
implements(ISpeach)
def say(self, name):
print "Hello", name
# Getting the global registry
gsm = getGlobalSiteManager()
gsm.registerUtility(Hello())
# Let's use our utility.
# Imagine that is somewhere else in your app.
my_utility = gsm.getUtility(ISpeach)
my_utility.say("Medved")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment