>From: Oeg Bizz
>Sent: Tue, November 30, 2010 4:14:34 AM

> Dave,
> 
> I see your point, what about something like;
> 
> def get_xx(encoded=GetEncodedValue):
>             if GetEncodedValue: return xxx.encode(ExternalEncoding)
>             else: return xxx
> 
> and the flag can be set from an option when generating code,
> something like --get-encoded-value
> 

Oscar -

Rats.  I wish I'd thought of that.  Good idea.

So, GetEncodedValue is a global variable, right?  It would have a
default value:

    GetEncodedValue = False

then in your code you would do:

    import mygeneratedlib
    o
    o
    o
    def test():
        mygeneratedlib.GetEncodedValue = True
        mygeneratedlib.parse('someinstancedoc.xml')
        o
        o
        o

This, by the way, would eliminate the need for YACLO (yet another
command line option), I believe.  Do you agree?

If you want to do a parse and export without modifying the
generated code, then use a small app/script like the one I've
attached.

This approach gives you flexibility in the following ways:

1. Do nothing extra and you get the default (old) behavior.

2. Set GetEncodedValue to True and the generated getters return
   encoded values (always).

3. Turn GetEncodedValue on and off (True and False) and you can
   switch back and forth between encoded and un-encoded values.

4. Call individual getter methods as follows -- to get encoded
   string::

        value = obj.get_xxx(getencodedvalue=True)

   or, to get un-encoded string::

        value = obj.get_xxx()
        value = obj.get_xxx(getencodedvalue=False)

Does this get you what you need?

The one down-side to this strategy would be that it adds code bulk
to the generated modules.  The additional amount of code bulk per
individual getter method would be small, but since there are *lots*
of getters, it would add up.  Perhaps a call to a single method in
the common super-class GeneratedsSuper would reduce this.  For
example::

    class GeneratedsSuper(object):
        o
        o
        o
        def getter_(self, invalue, getencodedvalue):
            if getencodedvalue:
                return invalue.encode(ExternalEncoding)
            else:
                return invalue

And, in each getter method::

    def get_xxxx(self, getencodedvalue=GetEncodedValue):
        return self.getter_(self.xxxx, getencodedvalue=getencodedvalue)

By the way, you have a use case for this I'm sure, but, I don't
know what it is.  My understanding is that it is almost always
better to manipulate unicode in your Python code.  Why is it that
you want to get the encoded (utf-8 ?) string?

I'll do a little more investigation on this tomorrow.

Thanks for explaining this.  That's been very helpful.

- Dave

> 
> From: Dave Kuhlman <dkuhl...@rexx.com>
> To: Oeg Bizz <oegb...@yahoo.com>
> Sent: Mon, November 29, 2010 10:38:47 PM
> Subject: Re: encoding type problem
> 
> >From: Oeg Bizz
> >Sent: Mon, November 29, 2010 12:56:16 PM
> >
> > Dave,
> >
> > I used the changes a little bit more today and found 2 problems
> > with my previous solution; not considering the case where the
> > element is None, and not considering the case where there are more
> > than 1 element of the same type (list).  I fixed that by adding
> > some if conditions, but I wanted to make sure I mention that to you
> > ASAP just in case.  Thanks for all your help,
> >
> 
> Oscar -
> 
> First, thanks for your work on this.
> 
> I apologize for being slow in responding.  I've been working on a
> few other things.
> 
> I'll look more closely at your suggested changes tomorrow.  In the
> meantime here is a question -- Since users might expect to get
> un-encode text, is it possible that we should generate *two* get-
> methods, one that returns the "raw" value and the other that
> returns the value encoded.  For example we might want to generate
> *both* of the following:
> 
>       def get_xxx(): return self.xxx
>       def getencoded_xxx(): return self.xxx.encode(ExternalEncoding)
> 
> What do you think?
> 
> - Dave
> 
> >
> >
> > From: Oeg Bizz <oegb...@yahoo.com>
> > To: Dave Kuhlman <dkuhl...@rexx.com>
> > Sent: Fri, November 26, 2010 5:04:48 PM
> > Subject: Re: encoding type problem
> >
> > Dave,
> >
> >    generateDs uses the ExternalEncoding only when writing to a
> > file and not when using the getters.  I looked a the code and
> > made the following changes to the generateGettersAndSetters on
> > line ~3067:
> >
> > if childType in StringType or \
> >    childType == TokenType or \
> >    childType == DateTimeType or \
> >    childType == DateType:
> >    s1 = '    def get%s(self): return self.%s.encode(ExternalEncoding)\n' %
> >(capName, name)
> > else:
> >      s1 = '    def get%s(self): return self.%s\n' % (capName, name)
> >
> > This made the get methods to return the value modified using the
> > ExternalEncoding.  Please let me know if you believe I may have
> > broken the code with this changes.  Thanks in advance,
> >
> > Oscar
> 
> 
> -- 
> 
> 
> Dave Kuhlman
> http://www.rexx.com/~dkuhlman
> 
> 

 -- 


Dave Kuhlman
http://www.rexx.com/~dkuhlman

Attachment: test1.py
Description: Binary data

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to