Thanks for explaining.

--------------------------------------------------
From: "Michael Foord" <[email protected]>
Sent: Thursday, March 26, 2009 1:33 AM
To: "Discussion of IronPython" <[email protected]>
Subject: Re: [IronPython] Embedding & Charsets

Igor Elyas wrote:
Interesting info:
1. Calling unicode('russian symbols') throws "'ascii' codec can't decode byte 0 in position 0: ordinal not in range"
In IronPython calling unicode is the same as calling str. Calling unicode on a bytestring with non-ascii characters in it would also blow up in CPython.

Michael

2.
IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3082
Type "help", "copyright", "credits" or "license" for more information.
str(u''russian symbols'.encode('cp1251'))
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "mscorlib", line unknown, in GetString
 File "mscorlib", line unknown, in GetChars
 File "mscorlib", line unknown, in Fallback
 File "mscorlib", line unknown, in Throw
UnicodeDecodeError: ('unknown', u'\xef', 0, 1, '')

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
str(u''russian symbols'.encode('cp1251'))
'\xef\xf0\xe8\xe2\xe5\xf2'

--------------------------------------------------
From: "Michael Foord" <[email protected]>
Sent: Wednesday, March 25, 2009 10:03 PM
To: "Discussion of IronPython" <[email protected]>
Subject: Re: [IronPython] Embedding & Charsets

Igor Elyas wrote:
Ops
Deep in code on returned value used Python str() function and looks like:
 str(self._reader.GetString(self._idx))


You can't call str on a string if it contains non-ascii characters. :-)

(and why would you need to...)

Michael

That correct situation ?

*From:* Igor Elyas <mailto:[email protected]>
*Sent:* Wednesday, March 25, 2009 9:17 PM
*To:* [email protected] <mailto:[email protected]>
*Subject:* [IronPython] Embedding & Charsets

Hello
I'm use IronPython 2.0.1 as embedded interpreter for read data from database.
Code for create Engine:
 fEngine = Python.CreateEngine();
            Ops = fEngine.CreateOperations();
            // core libs
            fEngine.Runtime.LoadAssembly(typeof(Decimal).Assembly);
fEngine.Runtime.LoadAssembly(typeof(IValue).Assembly); // loading ADO.NET driver assemblies LoadAssemblies(from v in EtlBaseCfg.BaseCfg.Element("dlls").Elements("dll") select v.Value); After that, I use generated Ipy class for read one value from specific IDbDataReader:
 from ETL.Common.pipes import IValuePipe
class SelectExtractor(IValuePipe):
    def __init__(self,adoreader,originId,storage):
        self._name = originId
        self._reader = adoreader
        self._idx = adoreader.GetOrdinal(self._name)
        self._transport = storage
    def Do(self, pydict):
        val = self._transport.Clone()
        if not self._reader.IsDBNull(self._idx):
            val.Data = self._reader.GetString(self._idx)
        if pydict.ContainsKey(self._name):
            pydict[self._name] = val
        else:
            pydict.Add(self._name,val)
This operation return string with Russian symbols and I get Exception: "'ascii' codec can't decode byte 0 in position 0: ordinal not in range"
How I can enable unicode .NET strings ?
Looks like I not initialize IronPython correctly, because this code in Ipy console work fine with Russian charset (Russian Windows), but not sure about other charsets. I need use .NET unicode strings.

Best regards

Igor Elyas

------------------------------------------------------------------------

_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
------------------------------------------------------------------------


_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



--
http://www.ironpythoninaction.com/

_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


--
http://www.ironpythoninaction.com/

_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to