Re: RFC: Proposal Dexterity API - two variants

Dylan Jay <djay-n0pU0XVUApFWk0Htik3J/[email protected]>
Newsgroups gmane.comp.web.zope.plone.devel
Message-ID <[email protected]>
Any api that has attribute assignment ie context.blah = 'value' will not work in restricted python and can't be used in ZPT, python scripts or Plomino plus a few dozen other places where restricted python is used. 


~~~~~~~~~~~~~~~~~~~~~~~~~~
Dylan Jay
Chief Technology Officer
PretaGov AU - Open Source CMS SaaS for government
Sydney | London

A: Level 6, 99 York St, Sydney, 2000
P: +61-2-9955-2830
Skype ID: dylan_jay


On 5 Nov 2014, at 4:44 pm, Jens W. Klein <jens-/[email protected]> wrote:

> ======================
> Proposal Dexterity API
> ======================
> 
> We, Robert Niederreiter and Jens Klein, wrote this proposal as an entry 
> to a discussion for an future Dexterity API (read: Dexterity 3). We 
> followed two different pathes and we are curios which one gets more +1 ;)
> 
> Both of them are implementable and also both are in the perspective of 
> speed almost the same.
> 
> 
> Explicit behaviors proposal: expose behaviors explicitly
> ========================================================
> 
> Basic principles
> ----------------
> 
> * Duplicate attribute names are allowed by different behaviors
> * Programmer always addresses effected behavior explicit
> 
> 
> Pros
> ----
> 
> * More reliable and readable code
> * Explicitness
> * Easy migration
> 
> 
> Cons
> ----
> 
> * Steeper learning curve (developer needs to learn which behaviors exists)
> * More code
> 
> Implementation implications
> ---------------------------
> 
> * think of behavior inheritance and how default behaviors can be overwritten
> 
> 
> API usage example
> -----------------
> 
> Read Attribute::
>>>> context.behavior('basic').title
> 
> Write Attribute::
>>>> context.behavior('basic').title = u'My Title'
> 
> Behavior information::
>>>> context.behaviors
> {
>     'basic': {
>         'title': 'Basic',
>         'description': 'Foo',
>         'attributes': {
>             'title': {
>                 'label': 'Title',
>                 'description': 'Title of the object',
>                 '...'
>             },
>             ...
>         }
>     }
>     ...
> }
> 
>>>> repr(context.behaviors)
> - basic
>     -title
>     -description
> ...
> 
> Unrestricted access::
>>>> context.behavior('basic').unrestricted('title')
> 
> 
> Shadowed Behaviors Proposal: Simplified value access
> ====================================================
> 
> Basic principles
> ----------------
> 
> * implemented as one property directly on 
> plone.dexterity.content.DexterityContent which acts as a 
> zope.interface.mapping.IFullMapping (read: dict-like) to work with all 
> values and methods coming from the main schema, behavior schemas and 
> behavior factories.
> * Programmer does not need to know about behavior names when accessing data
> * Set/get of main schema values is same as schemas form behaviors.
> * Duplicate attribute names are NOT allowed any more and enforced 
> (checked on FTI creation time, i.e. XML import, TTW setting) This is 
> important!
> * factory methods/properties from behaviors are exposed when a factory 
> is given instaed of direct attribute access.
> 
> 
> Pros
> ----
> 
> * Simple entry for new developers
> * pythonic
> * natural dict-like API is first principle
> * no accicdential override of attributes stored
> * behavior inheritance (i.e.IDublicCoreMetadata is not a problem at all)
> 
> 
> Cons
> ----
> 
> * duplicate fieldnames in existing code needs migration (not in core)
> * behaviors are kind of hidden to developers, so misunderstandings may 
> occur (needs good documentation)
> 
> 
> Open for discussion
> -------------------
> 
> * should validation be enforced?
> 
> 
> Important
> ---------
> 
> * lots of caching of schemas and intermeidate results
> 
> 
> API usage example
> -----------------
> 
>>>> context.values['title']
> 'My Document'
> 
>>>> context.values['title'] = 'Jensens Document'
>>>> context.values['some_factory_property'] = 'Foo'
>>>> context.values['some_factory_property']
> 'Foo'
> 
>>>> context.values['some_factory_method'](param1, param2='foo')
> ...
> 
>>>> context.values.keys()
> ['title', 'description', ....]
> 
>>>> context.update({'title': 'Jensens Updated Document', 'description': 
> 'A new easy to understand API for dx'}
>>>> context.values.items()
> [('title': 'Jensens Updated Document', 'description': 'A new easy ...', 
> ....)]
> 
> other dict-api methods are implemented too (need to finish this, but you 
> can imagine how it looks like, )
> active access to restricted values which checks the read/write permission!
> 
>>>> context.restricted_values['title']
> Traceback ...
> ....
> Unauthorized(...)
> 
> 
> Legacy Proposal
> ------------------------
> 
> * rename dexterity to devilstick
> * use wording molecule instead of behavior
> * the values are atoms
> * ignore this legacy proposal ;D
> 
> -------------------------------------------------------------------------
> 
> happy commenting
> 
> Jens and Robert
> -- 
> BlueDynamics Alliance
> 
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> Plone-developers mailing list
> Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/plone-developers


------------------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.