using schemaish/convertish without formish

2 views
Skip to first unread message

Chris McDonough

unread,
Feb 26, 2010, 8:35:27 AM2/26/10
to is...@googlegroups.com
Hi all,

I'm keen to find and use something which will allow me to validate and convert
an arbitrary-depth dictionary outside the forms realm, eg.

class GlobalObject(schemaish.attr.LeafAttribute):
# some code here that i don't have yet

class Directive(schemaish.Structure):
# some code here that i dont have yet

class Subscriber(Directive):
event_type = GlobalObject()
subscriber = GlobalObject()

structure = {'event_type':'mypackage.MyClass',
'subscriber':'mypackage.myfunction'}

directive = Subscriber()
converted = directive.convert(structure)
print converted
{'event_type':<class MyClass>, 'subscriber':<function myfunction>}

E.g. the above converts a string to a global Python object via __import__.

I realize this is a small matter of coding and so forth. Has anyone started
down such a path already?

--
Chris McDonough
Agendaless Consulting, Fredericksburg VA
The repoze.bfg Web Application Framework Book: http://bfg.repoze.org/book

Tim Parkin

unread,
Feb 26, 2010, 1:00:00 PM2/26/10
to is...@googlegroups.com
On Fri, Feb 26, 2010 at 1:35 PM, Chris McDonough <chr...@plope.com> wrote:
Hi all,

I'm keen to find and use something which will allow me to validate and convert an arbitrary-depth dictionary outside the forms realm, eg.

class GlobalObject(schemaish.attr.LeafAttribute):
   # some code here that i don't have yet

class Directive(schemaish.Structure):
   # some code here that i dont have yet

class Subscriber(Directive):
   event_type = GlobalObject()
   subscriber = GlobalObject()

structure = {'event_type':'mypackage.MyClass',
             'subscriber':'mypackage.myfunction'}

directive = Subscriber()
converted = directive.convert(structure)
print converted
{'event_type':<class MyClass>, 'subscriber':<function myfunction>}

E.g. the above converts a string to a global Python object via __import__.

I realize this is a small matter of coding and so forth.  Has anyone started down such a path already?


I'm just trying to get my head around this... Sounds like you need to create some new schema types (which you have at the top). You also then need to register some string converters (using convertish) so that you can cast from strings to and from the schema types you have. Then it should be a simple matter of calling convert on the data like you have here..

I started writing a generic data manipulation library called dataish but it's a little out of date with convertish so I'm having a quick look at getting the tests working again

http://github.com/ish/dataish

I'll ping you when I've got the tests working (or if I have to move onto something else for a bit).

Tim
 
Reply all
Reply to author
Forward
0 new messages