I would humbly suggest that if you were to use adodbapi for your database
access, the adapter would take care of all of  this for you, and will also
work in Python 3.0. Unfortunatly, the last remaining bug in adodbapi (caused
by a bug in the IronPython COM interface) is in this exact area -- binary
buffers.  If you are actually using only string (or unicode) data, passed as
such, it would work perfectly for you.
  I was hoping to provide you with examples from the adodbapi source code of
how to work around this problem (since your application is doing basically
the same thing.) On reviewing the code, though, I find that I there are no
longer any visible examples of str vs. unicode incompatibily fixes. Iron
Python does that good a job at masking the difference!
  Nevertheless, I can point to a code fragment which handles the difference
between python 2 and python 3, which may be instructive.  The method I used
is to create a local object which is used as if it were a type. That
definition is done once, at import time, and then freely used in the classes
below. You could use a similar construct based on whether IronPython or
CPython were in use.

The following snippet runs in CPython versions 2.3 thru 2.6 and IronPython,
and, after being processed by 2to3.py runs on Python 3.0. Both CPython 2.x
and IronPython use the "else" branch for their object definitions in this
case.

<code -- NOTE: this is the source BEFORE 2to3.py is run>
# --- define objects to smooth out Python3000 <-> Python 2.x differences
unicodeType = unicode  #this line will be altered by 2to3.py to '= str'
longType = long        #thil line will be altered by 2to3.py to '= int'
memoryViewType = types.BufferType #will be altered to '= memoryview'
if sys.version[0] == '3':
    StringTypes = [str]
    makeByteBuffer = bytes
else:
    makeByteBuffer = buffer
    bytes = str
    StringTypes = types.StringTypes    # will be messed up by 2to3 but never
used
</code>

So the code to create a binary blob (as required by PEP 249) becomes:
<code>
def Binary(aString):
    """This function constructs an object capable of holding a binary (long)
string value. """
    return makeByteBuffer(aString)
</code>

Hope this helps some.
--
Vernon Cole
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to