Created
November 24, 2011 12:11
-
-
Save xarg/1391210 to your computer and use it in GitHub Desktop.
Speach utility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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