[Zope-dev] A modest marshalling/validation proposal

Phillip J. Eby pje@telecommunity.com
Wed, 28 Apr 1999 19:22:20 -0500


What if ZPublisher's REQUEST object were to do the following:

1. Perform type conversion dynamically upon being requested for an
attribute, instead of statically during creation.

2. Look up and call a method 'marshal_type_x' from the published object
when doing said dynamic type conversion, falling back to the built-in type
converters if the marshalling function doesn't exist.

3. For performance's sake, cache the result of type conversion once the
publishing traversal has completely finished.

Now it would be possible, by adding External methods to a Folder, or adding
type conversion methods to a class, or any of the other ways to add these
marshal_type_x methods, to have specialized validation or marshalling on a
local basis, without futzing up too much of ZPublisher's logic.

Or...  here's another alternative, one which I've implemented in certain of
my own ZPublished systems...  let DTML methods (SQL methods, External
Methods, really any methods) do this 'marshal_type_x' lookup on their own
parameters using types specified in their argument specifiers.  I.e., if
method foo has an arg string "bar:int baz:wumpus spam:cabbage", then forms
submitting to method foo would leave off the type specifiers, and foo
itself would call marshal_type_int, marshal_type_wumpus, and
marshal_type_cabbage before proceeding to the body of the method.  This
bypasses ZPublisher's marshalling altogether except for :list, :tuple, and
:method, which still get used in forms.  All other form field names remain
untyped at the ZPublisher level and get handled by the published object
instead.