Created
July 18, 2013 09:03
-
-
Save mvmocanu/6027868 to your computer and use it in GitHub Desktop.
This file contains 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
import zope.component as c | |
from zca import render, User, Lion, Kitty, Tiger, AnimalToID | |
from zca import TigerToID | |
c.provideAdapter(TigerToID) | |
c.provideAdapter(AnimalToID) | |
render(User('User', 'http://example.com/user.jpg', 20)) | |
render(Lion('Lion', 'http://example.com/lion.jpg')) | |
render(Kitty('Kitty')) | |
render(Tiger('T', 'http://example.com/t1.jpg', 'http://example.com/t2.jpg')) |
This file contains 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
import zope.interface as i | |
import zope.component as c | |
class IIdentificationCard(i.Interface): | |
url = i.Attribute("""Subject picture URL.""") | |
name = i.Attribute("""The name of the subject.""") | |
def render(obj): | |
obj = IIdentificationCard(obj) | |
print '<img src="%s" alt="%s">' % (obj.url, obj.name) | |
@i.implementer(IIdentificationCard) | |
class User(object): | |
def __init__(self, name, url, age): | |
self.name = name | |
self.url = url | |
self.age = age | |
class IAnimal(i.Interface): | |
growling = i.Attribute("""The guttural vocalization of the animal.""") | |
name = i.Attribute("""The name of the animal.""") | |
picture = i.Attribute("""The URL of a picture of the animal.""") | |
# def f(a, b): | |
# """Docstring""" | |
@i.implementer(IAnimal) | |
class Lion(object): | |
growling = 'Rarr!' | |
def __init__(self, name, picture): | |
self.name = name | |
self.picture = picture | |
@i.implementer(IAnimal) | |
class Kitty(object): | |
growling = 'Meew...' | |
def __init__(self, name): | |
self.name = name | |
self.picture = '/kitty.jpeg' | |
@i.implementer(IAnimal) | |
class Tiger(object): | |
growling = '?!?' | |
def __init__(self, name, pic1, pic2): | |
self.name = name | |
self.picture = pic1 | |
self.picture2 = pic2 | |
@c.adapter(IAnimal) | |
@i.implementer(IIdentificationCard) | |
class AnimalToID(object): | |
def __init__(self, context): | |
self.url = context.picture | |
self.name = context.name | |
@c.adapter(Tiger) | |
@i.implementer(IIdentificationCard) | |
class TigerToID(object): | |
def __init__(self, context): | |
self.url = context.picture2 | |
self.name = context.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment