Actually, it was more that I never had a need for it, but yes, it would be
one of the few data types where the lexical and value space Python types
might naturally be the same.

What I would probably try is using str as the value space type, and as
unicode as the lexical space type.  Validate the lexical space
representation by ensuring it passes base64.b64decode() without throwing a
TypeError.  Add str as a parent class of base64Binary.   XsdLiteral becomes
a call to base64.b64encode(self).  __new__ converts unicode via
base64.b64decode, leaves str alone, and (gut reaction) raises
BadTypeValueError on other types.

This should be adequate when generating and parsing documents, because in
that case you know you're transitioning between lexical and value spaces.  I
suspect the tricky part you're referring to is when operating in Python in a
context where PyXB tries to convert lexical representations to value
representation.  Ideally, I've quashed most of those cases because they
turned out to be a bad idea, but if any remain I would make the assumption
that values that come from user Python code were raw binary, stored as
instances of str.

Of course, without trying it, I have no idea what pitfalls might occur, but
if you care to give it a shot and can include both a unit test (flesh out
tests/datatypes/test-base64Binary.py) and something that works on real
documents, I'll be happy to accept the patch for integration.  Feel free to
base your work off the next branch in the git repository, if you're
git-inclined.

And thanks for using and contributing to PyXB.

Peter

On Sun, May 2, 2010 at 12:24 PM, Michael van der Westhuizen <
r1mi...@gmail.com> wrote:

> Hi Peter,
>
> I've been testing PyXB with a SAMLv2 document and run into the
> unimplemented base64Binary binding.
>
> After taking a stab at implementing this binding I've realised that the
> reason the code is unimplemented is likely because there's no clear way to
> differentiate between raw binary data and a string in Python 2.x.
>
> What's the thinking around this sort of binding (where the encoded and
> decoded data are to all intents and purposes indistinguishable from each
> other)? Any thoughts on a clean approach? I'm happy to do the implementation
> work, but I'd like some input on the design.
>
> I'm happy to just go with an approach that insists on the data being base64
> encoded prior to binding and simply checks that the encoding is valid -
> would this be OK as a patch?
>
> Michael
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> pyxb-users mailing list
> pyxb-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyxb-users
>
>
------------------------------------------------------------------------------
_______________________________________________
pyxb-users mailing list
pyxb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyxb-users

Reply via email to