Slide 1

Slide 1 text

Ideenklau erwünscht: Konzepte aus der Zope-Welt Wolfgang Schnerring gmbh & co. kg PyCon DE 2011, Leipzig Wolfgang Schnerring Zope-Ideen 06.10.2011 1 / 39

Slide 2

Slide 2 text

Einführung 1996 Z Object Publishing Environment: Application-Server als CGI-Alternative 2001 Plone CMS 2004 Rewrite: Zope 3 2009 Zope Toolkit Wolfgang Schnerring Zope-Ideen 06.10.2011 2 / 39

Slide 3

Slide 3 text

Agenda 1 Traversal 2 Erweiterbarkeit 3 Zope Component Architecture 4 Model-based Security 5 Transaktionen 6 Test-Setup 7 Testbrowser http://www.sxc.hu/photo/1149105 by nkzs Wolfgang Schnerring Zope-Ideen 06.10.2011 3 / 39

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Traversal Routing /users/edit/14 /users/edit/joe@example.org /users/joe@example.org/edit Wolfgang Schnerring Zope-Ideen 06.10.2011 5 / 39

Slide 6

Slide 6 text

Traversal Routing /users/edit/14 /users/edit/joe@example.org /users/joe@example.org/edit /users/{email}/edit → edit_user(email) Wolfgang Schnerring Zope-Ideen 06.10.2011 5 / 39

Slide 7

Slide 7 text

Traversal Traversal / users / joe@example.org / edit Wolfgang Schnerring Zope-Ideen 06.10.2011 6 / 39

Slide 8

Slide 8 text

Traversal Traversal / users / joe@example.org / edit Wolfgang Schnerring Zope-Ideen 06.10.2011 6 / 39

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Erweiterbarkeit Zusätzliche Views Wolfgang Schnerring Zope-Ideen 06.10.2011 8 / 39

Slide 11

Slide 11 text

Erweiterbarkeit Zusätzliche Daten # package1 class User(persistent.Persistent): pass user.firstname = ’Alice’ user.lastname = ’Random’ user.email = ’alice@example.org’ # package2 annotations = zope.annotation.interfaces.IAnnotations(user) annotations[’credit_card_ref’] = ’1234XAB’ Wolfgang Schnerring Zope-Ideen 06.10.2011 9 / 39

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Zope Component Architecture Adapter-Pattern Wolfgang Schnerring Zope-Ideen 06.10.2011 11 / 39

Slide 14

Slide 14 text

Zope Component Architecture Zusätzliche Operationen # package1 class User: # [...] # package2 class CreditCardHolder: adapts(User) implements(CreditCard) # client code CreditCard(user).add(’1234XAB’) Wolfgang Schnerring Zope-Ideen 06.10.2011 12 / 39

Slide 15

Slide 15 text

Zope Component Architecture Single Dispatch class Shape: def draw(self): raise NotImplementedError() class Circle(Shape): def draw(self): # [...] class Square(Shape): def draw(self): # [...] Wolfgang Schnerring Zope-Ideen 06.10.2011 13 / 39

Slide 16

Slide 16 text

Zope Component Architecture Multiple Dispatch class SVGCircle: adapts(Circle, SVGCanvas) implements(Drawable) class JPGCircle: adapts(Circle, JPGCanvas) implements(Drawable) # client code Drawable(shape, canvas).draw() Wolfgang Schnerring Zope-Ideen 06.10.2011 14 / 39

Slide 17

Slide 17 text

Zope Component Architecture Beispiel: Views # client code EditForm(user, request).render() class HTMLEditForm: adapts(User, HTTPRequest) implements(EditForm) class JSONEditForm: adapts(User, JSONRequest) implements(EditForm) Wolfgang Schnerring Zope-Ideen 06.10.2011 15 / 39

Slide 18

Slide 18 text

Zope Component Architecture Zusätzliche Views Wolfgang Schnerring Zope-Ideen 06.10.2011 16 / 39

Slide 19

Slide 19 text

Zope Component Architecture Beispiel: Traversal # /users/joe@example.org/edit class UserFolderTraverser: adapts(UserFolder) implements(zope.traversing.interfaces.ITraversable) def __init__(self, context, request): self.context = context self.request = request def traverse(self, name, remaining): return self.context.find_user_by_email(name) Wolfgang Schnerring Zope-Ideen 06.10.2011 17 / 39

Slide 20

Slide 20 text

Zope Component Architecture Beispiel: Events zope.event.notify(ObjectCreatedEvent(user)) # client code @subscribe(User, ObjectCreatedEvent) def send_welcome_email(user, event): # [...] Wolfgang Schnerring Zope-Ideen 06.10.2011 18 / 39

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Model-based Security view-based Wolfgang Schnerring Zope-Ideen 06.10.2011 20 / 39

Slide 23

Slide 23 text

Model-based Security view-based Wolfgang Schnerring Zope-Ideen 06.10.2011 20 / 39

Slide 24

Slide 24 text

Model-based Security model-based Wolfgang Schnerring Zope-Ideen 06.10.2011 21 / 39

Slide 25

Slide 25 text

Model-based Security API zope.security.checker.defineChecker(class_, checker) proxied = zope.security.checker.ProxyFactory(object) class Checker(object): def check_getattr(self, object, name): def check_setattr(self, object, name): # permission = [...] getInteraction().checkPermission(permission, object) Wolfgang Schnerring Zope-Ideen 06.10.2011 22 / 39

Slide 26

Slide 26 text

Model-based Security API class Interaction(object): def add(self, participation): def remove(self, participation): def checkPermission(self, permission, object): # [...] Wolfgang Schnerring Zope-Ideen 06.10.2011 23 / 39

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Transaktionen 2-Phase-Commit Wolfgang Schnerring Zope-Ideen 06.10.2011 25 / 39

Slide 29

Slide 29 text

Transaktionen 2-Phase-Commit Wolfgang Schnerring Zope-Ideen 06.10.2011 25 / 39

Slide 30

Slide 30 text

Transaktionen 2-Phase-Commit Wolfgang Schnerring Zope-Ideen 06.10.2011 25 / 39

Slide 31

Slide 31 text

Transaktionen 2-Phase-Commit Wolfgang Schnerring Zope-Ideen 06.10.2011 25 / 39

Slide 32

Slide 32 text

Transaktionen 2-Phase-Commit Fehlerfall Wolfgang Schnerring Zope-Ideen 06.10.2011 25 / 39

Slide 33

Slide 33 text

Transaktionen 2-Phase-Commit Wolfgang Schnerring Zope-Ideen 06.10.2011 25 / 39

Slide 34

Slide 34 text

Transaktionen 2-Phase-Commit Wolfgang Schnerring Zope-Ideen 06.10.2011 25 / 39

Slide 35

Slide 35 text

Transaktionen API transaction commit / abort savepoint get doom join DataManager tpc_begin – commit – tpc_vote – (tpc_finish | tpc_abort) Wolfgang Schnerring Zope-Ideen 06.10.2011 26 / 39

Slide 36

Slide 36 text

Transaktionen Beispiel Wolfgang Schnerring Zope-Ideen 06.10.2011 27 / 39

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Test-Setup unittest.TestCase class ExampleTest(unittest.TestCase): def setUp(self): def tearDown(self): def test_something(self): Wolfgang Schnerring Zope-Ideen 06.10.2011 29 / 39

Slide 39

Slide 39 text

Test-Setup gemeinsames setUp Wolfgang Schnerring Zope-Ideen 06.10.2011 30 / 39

Slide 40

Slide 40 text

Test-Setup Stacking Wolfgang Schnerring Zope-Ideen 06.10.2011 31 / 39

Slide 41

Slide 41 text

Test-Setup Layer class Layer(object): __bases__ = (OTHER_LAYER,) def setUp(self): def tearDown(self): def testSetUp(self): def testTearDown(self): Wolfgang Schnerring Zope-Ideen 06.10.2011 32 / 39

Slide 42

Slide 42 text

Test-Setup Beispiel class PersistenceTest(unittest.TestCase): layer = DB_LAYER def test_serializing_document_parameters(self): # [...] class IntegrationTest(unittest.TestCase): layer = COMBINED_LAYER def test_search_displays_suggestions_from_database(self): # [...] Wolfgang Schnerring Zope-Ideen 06.10.2011 33 / 39

Slide 43

Slide 43 text

Test-Setup Beispiel class DatabaseLayer(plone.testing.Layer): def setUp(self): self.connection = dbdriver.connect(os.environ[’DSN’]) def tearDown(self): self.connection.close() DB_LAYER = DatabaseLayer() HTTP_LAYER = HTTPServerLayer() COMBINED_LAYER = plone.testing.Layer( bases=(DatabaseLayer, HTTPServerLayer)) Wolfgang Schnerring Zope-Ideen 06.10.2011 34 / 39

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

Testbrowser Beispiel Wolfgang Schnerring Zope-Ideen 06.10.2011 36 / 39

Slide 46

Slide 46 text

Testbrowser Beispiel class SearchTest(unittest.TestCase): def test_advanced_search_filters_by_content_type(self): b = zope.testbrowser.wsgi.Browser( wsgi_app=my_wsgi_callable) b.open(’http://localhost’) b.getLink(’Advanced Search’).click() b.getControl(name=’q’).value = ’zope’ b.getControl(’Content type’).displayValue = [’HTML’] b.getControl(’Search’).click() self.assertEqual(’10’, b.getControl(’Results per page’)) self.assertIn(’fisch’, b.contents) # not released yet, unfortunately self.assertEllipsis(’...fisch...framework...’) Wolfgang Schnerring Zope-Ideen 06.10.2011 37 / 39

Slide 47

Slide 47 text

Ressourcen http://pypi.python.org/pypi/ http://www.sxc.hu/photo/1087620 by nkzs 1 zope.traversing 2 zope.configuration grokcore.component zope.annotation 3 zope.component, zope.interface, zope.event 4 zope.security 5 zope.testrunner, plone.testing 6 transaction, repoze.tm2 zope.sqlalchemy, zope.sendmail, gocept.amqprun 7 zope.testbrowser Wolfgang Schnerring Zope-Ideen 06.10.2011 38 / 39

Slide 48

Slide 48 text

Wir suchen Mitarbeiter in Halle! Softwareentwicklung Web Python TDD Systemadministration Gentoo/KVM Puppet Nagios Bei Interesse: mich ansprechen oder jobs@gocept.com Wolfgang Schnerring Zope-Ideen 06.10.2011 39 / 39