From: Ryan <ryle...@gmail.com> To: Dave Kuhlman <dkuhl...@rexx.com> Sent: Tuesday, April 21, 2009 8:59:01 AM Subject: Re: generateDS
> Hi Dave, [snip] > > I was OK with this, however, since it can be argued that it's not > the job of generateDS to validate, as long as the user has the > necessary type information to implement their own validation > strategy. So, what I did was use the extra methods feature to > add a staticmethod wrapper to each class called init() which in > addition to accepting keyword arguments to be fowarded to > __init__(), takes a "validator" object. The validator object is > able to do its work by being passed the following information: > the name of the object, its value, and its expected type. The > expected types are quite conveniently stored as _MemberSpec > objects in _member_data_items for each class. Your use of user methods sounds like a neat idea for validation. I'm glad that feature was of use to you. > > This strategy worked great for my purposes until I ran into > elements which contain attributes. I found that for attributes > no such spec was created by generateDS and so the type > information was effectively lost. Thus at runtime there was no > convenient way to do my custom validation/coercion of attribute > values without having to hardcode the expected types! > > I found that by simply adding a little bit of code to > generateMemberSpec() I was able to have _MemberSpec objects > created for attributes: > > for attrName, attrDef in element.getAttributeDefs().items(): > item1 = attrName > item2 = attrDef.getType() > item3 = 0 > item = " _MemberSpec('%s', '%s', %d)," % (item1, item2, item3, > ) > add(item) > > This seems to work well, and I believe in attrDefs you have even > already taken care of the possibility for name collisions between > attribute names and child element names. This looks good to me. I added your code (above) to the current version. Thanks for fixing this. > > I would definitely love to see support for the attribute types in > a future version of generateDS, though I realize you may want to > see it implemented differently. Done. In another message from Ryan: > I think there is an issue with hasContent_() It doesn't seem to > check against None like exportChildren() does. For instance, if an > element has children NumOne, and NumTwo which are both are > explicitly set to 0 (which may be a legit value), then > hasContent_() would falsely report that there is no content, since > it only does if NumOne or NumTwo rather than if NumOne is not None > or NumTwo is not None. I agree. The intent of the hasContent_() methods should be to check whether the value has been set. And, None indicates that there is no value other than the default used by the constructor. So, I've changed generation of the hasContent_() methods so that they all use: xxx is not None or ... as you suggested. Thanks for catching this. And in yet another message from Ryan: > 5) I had issues with schemas that include other schemas. One of > the > problems seems to be that process_includes.py doesn't seem to > check for ElementTree in the standard location, xml.etree. > I believe that I've fixed this in the current version, maybe. Thanks for pointing it out to me. *However*, I've left it so that it refuses to do the conversion unless you have Lxml installed. This can be changed easily by commenting out a bit of code in process_includes.py. I believe that ElementTree does not quite handle the XML namespace prefixes the way we want it to. What do you think? And, I added the code back in to support --external-encoding. There is some information about it in the documentation. Thanks for catching this. There is a new version (generateDS-1.16e) at SourceForge and also here: http://www.rexx.com/~dkuhlman/generateDS-1.16e.tar.gz If you try it, please let me know how it works for you. Thanks again for your help. I appreciate it. - Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman ------------------------------------------------------------------------------ Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users