An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture...
Transcript of An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture...
![Page 1: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/1.jpg)
An Introductionto the Zope 3 Component
ArchitectureBrandon Craig Rhodes
Georgia Tech
NOLA Plone Symposium 2008
![Page 2: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/2.jpg)
This talk, on the whole, is divided into four parts
![Page 3: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/3.jpg)
1. Enhancing objects
![Page 4: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/4.jpg)
1. Enhancing objects2. Adapting objects
![Page 5: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/5.jpg)
1. Enhancing objects2. Adapting objects
3. Component framework
![Page 6: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/6.jpg)
1. Enhancing objects2. Adapting objects
3. Component framework4. Adapting for the web
![Page 7: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/7.jpg)
Let's go!
![Page 8: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/8.jpg)
Many programminglanguages use static
typing
![Page 9: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/9.jpg)
float half(int n){ return n / 2.0;}
![Page 10: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/10.jpg)
float half(int n){ return n / 2.0;}
![Page 11: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/11.jpg)
Python typing is dynamic
![Page 12: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/12.jpg)
def half(n): return n / 2.0
![Page 13: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/13.jpg)
You don't worry about whether an object is of
the right type
![Page 14: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/14.jpg)
You simply try using it
![Page 15: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/15.jpg)
“Duck Typing”
(Alex Martelli)
![Page 16: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/16.jpg)
“Duck Typing”
Walks like a duck?Quacks like a duck?
It's a duck!
![Page 17: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/17.jpg)
def half(n): return n / 2.0
![Page 18: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/18.jpg)
def half(n): return n / 2.0
(Is n willing to be divided by two?Then it's numberish enough for us!)
![Page 19: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/19.jpg)
Now, imagine...
![Page 20: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/20.jpg)
Imagine a wonderful duckprocessing library to which you want to pass
an object
![Page 21: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/21.jpg)
But...
The object you want to pass isn't a duck?
![Page 22: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/22.jpg)
What if it doesn'talready quack?
![Page 23: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/23.jpg)
What if it bearsnot the least resemblance
to a duck!?
![Page 24: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/24.jpg)
Example!
![Page 25: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/25.jpg)
You have a “Message” object from the Python
“email” module
![Page 26: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/26.jpg)
>>> from email import message_from_file>>> e = message_from_file(open('msg.txt'))>>> print e<email.message.Message instance at ...>>>> e.is_multipart()True>>> for part in e.get_payload():... print part.get_content_type()text/plaintext/html
![Page 27: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/27.jpg)
multipart/mixed
text/plain
multipart/alternative
text/plain text/html
image/jpeg
Messagescan be
recursive
![Page 28: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/28.jpg)
Imagine that we are writing a GUI email client
![Page 29: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/29.jpg)
And we want to show the parts in a TreeWidget
![Page 30: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/30.jpg)
The Tree widget needs:
method name() - returns name under which this tree node should be displayed
method children() - returns list of child nodes in the tree
method __len__() - returns number of child nodes beneath this one
![Page 31: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/31.jpg)
How can we add these behaviors to our
Message?
![Page 32: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/32.jpg)
(How can we make an object which is not a duck
behave like a duck?)
![Page 33: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/33.jpg)
1. Subclassing
![Page 34: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/34.jpg)
Create a “TreeMessage” class that inherits from the “Message” class...
![Page 35: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/35.jpg)
class TreeMessage(Message):
def name(self): return self.get_content_type()
def children(self): if not self.is_multipart(): return [] return [ TreeMessage(part) for part in self.get_payload() ]
def __len__(self): return len(self.children())
![Page 36: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/36.jpg)
What will the test suite look like?
![Page 37: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/37.jpg)
Remember:
“Untested code is broken code”— Philipp von Weitershausen,
Martin Aspeli
![Page 38: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/38.jpg)
Your test suitemust instantiate a
“TreeMessage” and verify its treelike behavior...
![Page 39: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/39.jpg)
txt = “ ” ” From: [email protected]: [email protected]: what an article!
Did you read Arts & Letters Daily today?“ ” ”m = message_from_string(txt, TreeMessage)assert m.name() == 'text/plain'assert m.children == []assert m.__len__() == 0
![Page 40: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/40.jpg)
We were lucky!
![Page 41: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/41.jpg)
Our test can cheaply instantiate Messages.
![Page 42: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/42.jpg)
txt = “ ” ” From: [email protected]: [email protected]: what an article!
Did you read Arts & Letters Daily today?“ ” ”m = message_from_string(txt, TreeMessage)assert m.name() == 'text/plain'assert m.children == []assert m.__len__() == 0
![Page 43: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/43.jpg)
What if we were subclassing an LDAP
connector?!
We'd need an LDAP server just to run unit tests!
![Page 44: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/44.jpg)
We were lucky (#2)!
![Page 45: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/45.jpg)
The “message_from_string()” method let us specify an
alternate factory!
![Page 46: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/46.jpg)
txt = “ ” ” From: [email protected]: [email protected]: what an article!
Did you read Arts & Letters Daily today?“ ” ”m = message_from_string(txt, TreeMessage)assert m.name() == 'text/plain'assert m.children == []assert m.__len__() == 0
![Page 47: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/47.jpg)
Final note: we have just broken the “Message”
class's behavior!
![Page 48: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/48.jpg)
Python library manual7.1.1 defines “Message”:__len__():
Return the total number of headers, including duplicates.
![Page 49: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/49.jpg)
>>> t = “ ” ” From: [email protected]: [email protected]: what an article!
Did you read Arts & Letters Daily today?“ ” ”>>> m = message_from_file(t, Message)>>> print len(m)3>>> m = message_from_file(t, TreeMessage)>>> print len(m)0
![Page 50: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/50.jpg)
So how doessubclassing
score?
![Page 51: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/51.jpg)
No harm to base class
![Page 52: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/52.jpg)
No harm to base classCannot test in isolation
![Page 53: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/53.jpg)
No harm to base class
Need control of factoryCannot test in isolation
![Page 54: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/54.jpg)
No harm to base class
Breaks if names collideNeed control of factoryCannot test in isolation
![Page 55: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/55.jpg)
No harm to base class
Breaks if names collideNeed control of factoryCannot test in isolation
Subclassing: D
![Page 56: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/56.jpg)
2. Using a mixin
![Page 57: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/57.jpg)
Create a “TreeMessage” class that inherits from both “Message” and a
“Mixin”...
![Page 58: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/58.jpg)
class Mixin(object): def name(self): return self.get_content_type() def children(self): if not self.is_multipart(): return [] return [ TreeMessage(part) for part in self.get_payload() ] def __len__(self): return len(self.children())
class TreeMessage(Message, Mixin): pass
![Page 59: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/59.jpg)
Your test suite can then inherit from a mockedup
“message”...
![Page 60: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/60.jpg)
class FakeMessage(Mixin): def get_content_type(self): return 'text/plain' def is_multipart(self): return False def get_payload(self): return ''
m = FakeMessage()
assert m.name() == 'text/plain'assert m.children() == []assert m.__len__() == 0
![Page 61: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/61.jpg)
How doesa mixin rate?
![Page 62: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/62.jpg)
No harm to base class
![Page 63: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/63.jpg)
No harm to base classCan test mixin by itself
![Page 64: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/64.jpg)
No harm to base class
Need control of factoryCan test mixin by itself
![Page 65: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/65.jpg)
No harm to base class
Breaks if names collideNeed control of factoryCan test mixin by itself
![Page 66: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/66.jpg)
No harm to base class
Breaks if names collideNeed control of factoryCan test mixin by itself
Mixin: C
![Page 67: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/67.jpg)
3. Monkey patching
![Page 68: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/68.jpg)
To “monkey patch” a class, you add or change
its methods dynamically...
![Page 69: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/69.jpg)
def name(self): return self.get_content_type()def children(self): if not self.is_multipart(): return [] return [ Message(part) for part in self.get_payload() ]def __len__(self): return len(self.children())
Message.name = nameMessage.children = childrenMessage.__len__ = __len__
![Page 70: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/70.jpg)
Is this desirable?
![Page 71: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/71.jpg)
Don't care about factory
![Page 72: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/72.jpg)
Changes class itselfDon't care about factory
![Page 73: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/73.jpg)
Changes class itselfBroken by collisions
Don't care about factory
![Page 74: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/74.jpg)
Changes class itselfBroken by collisions
Don't care about factory
Patches fight each other
![Page 75: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/75.jpg)
Changes class itselfBroken by collisions
Don't care about factory
Ruby people do thisPatches fight each other
![Page 76: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/76.jpg)
Changes class itselfBroken by collisions
Don't care about factory
Ruby people do thisMonkey patching: F
Patches fight each other
![Page 77: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/77.jpg)
4. Adapter
![Page 78: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/78.jpg)
Touted in the Gang of Four book
(1994)
![Page 79: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/79.jpg)
Idea: provide “Tree” functions through an entirely separate class
Message MessageTreeAdapter
get_content_type() name()is_multipart() call children()get_payload() __len__()
![Page 80: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/80.jpg)
class MessageTreeAdapter(object): def __init__(self, message): self.m = message def name(self): return self.m.get_content_type() def children(self): if not self.m.is_multipart(): return [] return [ TreeMessageAdapter(part) for part in self.m.get_payload() ] def __len__(self): return len(self.children())
![Page 81: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/81.jpg)
How does wrapping look in your code?
![Page 82: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/82.jpg)
IMAP library (or whatever)
TreeWidget
tw = TreeWidget(MessageTreeAdapter(msg))
Message object
Adapted object
![Page 83: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/83.jpg)
Test suite can try adapting a mockup object
![Page 84: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/84.jpg)
class FakeMessage(object): def get_content_type(self): return 'text/plain' def is_multipart(self): return True def get_payload(self): return []
m = MessageTreeAdapter(FakeMessage())assert m.name() == 'text/plain'assert m.children == []assert m.__len__() == 0
![Page 85: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/85.jpg)
How does the Adapterdesign pattern stack up?
![Page 86: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/86.jpg)
No harm to base class
![Page 87: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/87.jpg)
No harm to base classCan test with mockup
![Page 88: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/88.jpg)
No harm to base class
Don't need factoriesCan test with mockup
![Page 89: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/89.jpg)
No harm to base class
Don't need factoriesCan test with mockup
No collision worries
![Page 90: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/90.jpg)
No harm to base class
Don't need factoriesCan test with mockup
Wrapping is annoyingNo collision worries
![Page 91: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/91.jpg)
No harm to base class
Don't need factoriesCan test with mockup
Wrapping is annoyingAdapter: B
No collision worries
![Page 92: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/92.jpg)
Q: Why call wrapping“annoying”?
![Page 93: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/93.jpg)
The example makesit look so easy!
![Page 94: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/94.jpg)
IMAP library (or whatever)
TreeWidget
tw = TreeWidget(TreeMessageAdapter(msg))
Message object
Adapted object
![Page 95: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/95.jpg)
A: The example looks easy because it only does
adaptation once!
![Page 96: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/96.jpg)
But in a real application,it happens all through
your code...
![Page 97: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/97.jpg)
C(msg)
DBGUI
A(famtree)objects objectsIMAP
msg
Web
WidgetB(msg)Genealogy
3rd partyProducers
Adapters
A B C
3rd partyConsumers
C(msg)
Your application
![Page 98: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/98.jpg)
How can you avoid repeating yourself, and scattering information
about adapters and consumers everywhere?
![Page 99: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/99.jpg)
IMAP library (or whatever)
TreeWidget
tw = TreeWidget(TreeMessageAdapter(msg))
Message object
Adapted object
![Page 100: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/100.jpg)
tw = TreeWidget(TreeMessageAdapter(msg))
![Page 101: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/101.jpg)
tw = TreeWidget(TreeMessageAdapter(msg))
The key is seeing that this code conflates two issues!
![Page 102: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/102.jpg)
tw = TreeWidget(TreeMessageAdapter(msg))
Why does this line work?
![Page 103: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/103.jpg)
tw = TreeWidget(TreeMessageAdapter(msg))
It works because a TreeWidget needs what our adapter provides.
![Page 104: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/104.jpg)
tw = TreeWidget(TreeMessageAdapter(msg))
But if we call the adapter then the need = want is hidden inside of our head!
![Page 105: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/105.jpg)
We need to define what the TreeWidget needs that
our adapter provides!
![Page 106: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/106.jpg)
An interface is how we
specify a set of behaviors
![Page 107: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/107.jpg)
(1988)
(1995)
An interface is how we
specify a set of behaviors
![Page 108: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/108.jpg)
![Page 109: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/109.jpg)
For the moment, forget Zopethewebframework
![Page 110: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/110.jpg)
Instead, look at Zope the component framework:
zope.interfacezope.component
![Page 111: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/111.jpg)
With three simple steps, Zope will rid your code of
manual adaptation
![Page 112: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/112.jpg)
1. Define an interface2. Register our adapter3. Request adaptation
![Page 113: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/113.jpg)
from zope.interface import Interface
class ITree(Interface): def name(): “ ” ” Return this tree node's name.” ” ” def children(): “ ” ” Return this node's children.” ” ” def __len__(): “ ” ” Return how many children.” ” ”
Define
![Page 114: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/114.jpg)
from zope.component import provideAdapter
provideAdapter(MessageTreeAdapter, adapts=Message, provides=ITree)
Register
![Page 115: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/115.jpg)
from your_interfaces import ITreeclass TreeWidget(...): def __init__(self, arg): tree = ITree(arg) ...
Request
![Page 116: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/116.jpg)
from your_interfaces import ITreeclass TreeWidget(...): def __init__(self, arg): tree = ITree(arg) ... Zope will: 1. Recognize need 2. Find the registered adapter 3. Wrap and return the Message
Request
![Page 117: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/117.jpg)
from your_interfaces import ITreeclass TreeWidget(...): def __init__(self, arg): tree = ITree(arg) ... (Look! Zope is Pythonic!) i = int(32.1) l = list('abc') f = float(1024)
Request
![Page 118: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/118.jpg)
And that's it!
![Page 119: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/119.jpg)
And that's it!
Define an interfaceRegister our adapterRequest adaptation
![Page 120: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/120.jpg)
No harm to base class
Don't need factoriesCan test with mockup
Adapters now dynamic!Registered adapter: A
No collision worries
![Page 121: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/121.jpg)
C(msg)
DBGUI
A(famtree)objects objectsIMAP
msg
Web
WidgetB(msg)Genealogy
3rd partyProducers
Adapters
A B C
3rd partyConsumers
C(msg)
Your application
![Page 122: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/122.jpg)
C(msg)
DBGUI
A(famtree)IMAP
msg
Web
WidgetB(msg)Genealogy
A B C
C(msg)
Whatadaptersprovide
Whatconsumers
need
![Page 123: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/123.jpg)
DBGUI
IMAP
Web
WidgetGenealogy
A B C
![Page 124: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/124.jpg)
The finale
Adapting for the Web
![Page 125: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/125.jpg)
dum ... dum ... dum ...
DAH DUM!
![Page 126: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/126.jpg)
![Page 127: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/127.jpg)
Grok
![Page 128: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/128.jpg)
Web frameworkbuilt atop Zope 3
component architecture
![Page 129: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/129.jpg)
Grok makesZope 3 simple to use
(and to present!)
![Page 130: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/130.jpg)
Imagine a Person class
![Page 131: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/131.jpg)
The Person class was written by someone else
![Page 132: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/132.jpg)
The Person class is full of business logic, and stores instances in a database
![Page 133: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/133.jpg)
We want to browse Person objects on the Web
![Page 134: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/134.jpg)
What might the Webneed the object to do?
![Page 135: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/135.jpg)
<HTML><HEAD><TITLE>Person JOE</TITLE></HEAD><BODY> This page presents the basic data we have regarding Joe. ...
Person
1. What's at a URL
3. What is its URL
2. HTML document
http://person_app/Joe
http://person_app/Joe
![Page 136: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/136.jpg)
1.
![Page 137: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/137.jpg)
What's at this URL?
![Page 138: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/138.jpg)
What's at this URL?http://person_app/Joe
# how Zope processes this URL:r = rootj = ITraverser(r).traverse('person_app')k = ITraverser(j).traverse('Joe')return k
![Page 139: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/139.jpg)
# what we write:class PersonTraverser(grok.Traverser): grok.context(PersonApp) def traverse(self, name): if person_exists(name): return get_person(name) return None
What's at this URL?http://person_app/Joe
![Page 140: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/140.jpg)
# what we write:class PersonTraverser(grok.Traverser): grok.context(PersonApp) def traverse(self, name): if person_exists(name): return get_person(name) return None
What's at this URL?http://person_app/Joe
![Page 141: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/141.jpg)
# what we write:class PersonTraverser(grok.Traverser): grok.context(PersonApp) def traverse(self, name): if person_exists(name): return get_person(name)
What's at this URL?http://person_app/Joe
![Page 142: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/142.jpg)
2.
![Page 143: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/143.jpg)
How does a Person render?
![Page 144: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/144.jpg)
app.pyclass PersonIndex(grok.View): grok.context(Person) grok.name('index')
app_templates/personindex.pt<html><head><title>All about <tal tal:replace=” context/name” /></title></head>...
How does a Person render?
![Page 145: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/145.jpg)
3.
![Page 146: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/146.jpg)
What is a person's URL?
![Page 147: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/147.jpg)
class PersonURL(grok.MultiAdapter): grok.adapts(Person, IHTTPRequest) grok.implements(IAbsoluteURL) def __init__(self, person, req): self.person, self.req = person, req def __call__(self): base = grok.url(grok.getSite()) return base + '/' + self.person.name
What is a person's URL?
![Page 148: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/148.jpg)
5 + 3 + 8 = 16 lines
![Page 149: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/149.jpg)
<HTML><HEAD><TITLE>Person JOE</TITLE></HEAD><BODY> This page presents the basic data we have regarding Joe. ...
Person
1. What's at a URL
3. What is its URL
2. HTML Document
http://person_app/Joe
http://person_app/Joe
PersonTraverser
PersonURL
PersonIndex
![Page 150: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/150.jpg)
Other Zope adapter uses
![Page 151: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/151.jpg)
Other Zope adapter usesIndexing — Index, Query, Search, ...Data schemas — Schema, Vocabulary, DublinCore ...Form generation — AddForm, EditForm, ...Security — SecurityPolicy, Proxy, Checker, ...Authentication — Login, Logout, Allow, Require, ...Copy and paste — ObjectMover, ObjectCopier, ...I18n — TranslationDomain, Translator, ...Appearance — Skins, macros, viewlets, ...
Much, much more!
![Page 152: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/152.jpg)
Adapters can be local!
Global adapters
http://person_app/Joe
http:// person_app Joe
Local adapters
![Page 153: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/153.jpg)
Coming Attraction
![Page 154: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/154.jpg)
five.grok
![Page 155: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/155.jpg)
five.grokLennart Regebro
![Page 156: An Introduction to the Zope 3 Component Architecture · to the Zope 3 Component Architecture Brandon Craig Rhodes Georgia Tech NOLA Plone Symposium 2008. This talk, on the whole,](https://reader034.fdocuments.us/reader034/viewer/2022042315/5f0326e77e708231d407cbb3/html5/thumbnails/156.jpg)
Thank you!
http://zope.org/Products/Zope3http://grok.zope.org/http://rhodesmill.org/brandon/adaptershttp://regebro.wordpress.com/zope[email protected] mailing listgrok[email protected] mailing listWeb Component Development with Zope 3 by PvW