Ideenklau erwünscht: Konzepte aus der Zope-Welt

71229c0167172520e0582dbf29cbd88f?s=47 wosc
October 05, 2011

Ideenklau erwünscht: Konzepte aus der Zope-Welt

71229c0167172520e0582dbf29cbd88f?s=128

wosc

October 05, 2011
Tweet

Transcript

  1. 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
  2. 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
  3. 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
  4. None
  5. Traversal Routing /users/edit/14 /users/edit/joe@example.org /users/joe@example.org/edit Wolfgang Schnerring Zope-Ideen 06.10.2011 5

    / 39
  6. 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
  7. Traversal Traversal / users / joe@example.org / edit Wolfgang Schnerring

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

    Zope-Ideen 06.10.2011 6 / 39
  9. None
  10. Erweiterbarkeit Zusätzliche Views Wolfgang Schnerring Zope-Ideen 06.10.2011 8 / 39

  11. 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
  12. None
  13. Zope Component Architecture Adapter-Pattern Wolfgang Schnerring Zope-Ideen 06.10.2011 11 /

    39
  14. 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
  15. 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
  16. 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
  17. 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
  18. Zope Component Architecture Zusätzliche Views Wolfgang Schnerring Zope-Ideen 06.10.2011 16

    / 39
  19. 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
  20. 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
  21. None
  22. Model-based Security view-based Wolfgang Schnerring Zope-Ideen 06.10.2011 20 / 39

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

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

  25. 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
  26. 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
  27. None
  28. Transaktionen 2-Phase-Commit Wolfgang Schnerring Zope-Ideen 06.10.2011 25 / 39

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

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

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

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

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

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

  35. 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
  36. Transaktionen Beispiel Wolfgang Schnerring Zope-Ideen 06.10.2011 27 / 39

  37. None
  38. 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
  39. Test-Setup gemeinsames setUp Wolfgang Schnerring Zope-Ideen 06.10.2011 30 / 39

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

  41. 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
  42. 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
  43. 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
  44. None
  45. Testbrowser Beispiel Wolfgang Schnerring Zope-Ideen 06.10.2011 36 / 39

  46. 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
  47. Ressourcen http://pypi.python.org/pypi/<package> 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
  48. 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