[Ironpython-users] IronPython, Daily Digest 5/7/2014

CodePlex no_reply at codeplex.com
Thu May 8 09:24:23 CEST 2014


Hi ironpython,

Here's your Daily Digest of new issues for project "IronPython".

In today's digest:ISSUES

1. [New comment] Implement standard python encodings
2. [New issue] ensurepip support
3. [New issue] Using str() on non-ASCII string throws Exception: Unable to translate bytes from specified code page to Unicode
4. [New issue] %f directive does not work with datetime/time.strptime/strftime
5. [New issue] Specific case causes traceback to be incomplete

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

ISSUES

1. [New comment] Implement standard python encodings
http://ironpython.codeplex.com/workitem/1214
User jdhardy has commented on the issue:

"<p>See IronPython.Modules\binascii.cs and IronPython.Modules\_codecs.cs. Also see https://ironpython.codeplex.com/workitem/15507, and https://ironpython.codeplex.com/workitem/15506, and many others (search for "encoding").</p>"-----------------

2. [New issue] ensurepip support
http://ironpython.codeplex.com/workitem/35198
User objarni has proposed the issue:

"It would be swell if IronPython, out of the box, could have pip available to it's users. 

"ensurepip (https://docs.python.org/3/library/ensurepip.html) provides
support for having a bundled version of pip, which is then used to install
the current version of pip in a matter that's transparent to the user.
Jython simply needs to bundle the required pip and setuptools wheels and
the ensurepip package in stdlib."
"-----------------

3. [New issue] Using str() on non-ASCII string throws Exception: Unable to translate bytes from specified code page to Unicode
http://ironpython.codeplex.com/workitem/35199
User acl2 has proposed the issue:

"I am hosting IronPython (IronPython.dll 2.7.4.1000; Microsoft.Scripting.dll 1.1.0.21) inside a .NET 4.0 application.

The IronPyhton.Runtime throws a System.Text.DecoderFallbackException whenever I use the built-in Python str() function on a non-ASCII string.

So basically, when I execute the following python code:
s = str("ä")

I get a System.Text.DecoderFallbackException "Unable to translate bytes [E4] at index 0 from specified code page to Unicode.".

This is problematic, since I use str() almost everywhere to convert various types (unknown at rutime) to strings.

Here is the complete exception info:
System.Text.DecoderFallbackException was unhandled by user code
  HResult=-2147024809
  Index=0
  Message=Unable to translate bytes [E4] at index 0 from specified code page to Unicode.
  Source=mscorlib
  StackTrace:
       at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
       at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)
       at IronPython.Runtime.PythonAsciiEncoding.GetCharCount(Byte[] bytes, Int32 index, Int32 count)
       at System.Text.Encoding.GetChars(Byte[] bytes, Int32 index, Int32 count)
       at System.Text.Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
       at IronPython.Runtime.Operations.StringOps.DoDecode(CodeContext context, String s, String errors, String encoding, Encoding e)
       at IronPython.Runtime.Operations.StringOps.RawDecode(CodeContext context, String s, Object encodingType, String errors)
       at IronPython.Runtime.Operations.StringOps.decode(CodeContext context, String s, Object encoding, String errors)
       at IronPython.Runtime.Operations.StringOps.__new__(CodeContext context, PythonType cls, Object string, String encoding, String errors)
       at IronPython.Runtime.Operations.StringOps.CheckAsciiString(CodeContext context, String s)
       at IronPython.Runtime.Operations.StringOps.__new__(CodeContext context, PythonType cls, String object)
       at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)
       at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
       at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
       at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
       at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
       at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
       at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
       at IronPython.Compiler.PythonCallTargets.OriginalCallTarget0(PythonFunction function)
       at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
       at _Scripting_(Object[] )
       at App.Test.Misc.IronPythonUmlautTest() in C:\Dev\App\Test\Misc.vb:line 79
  InnerException: 


Here is a unit test that reproduces the issue (sorry it's in VB.NET):
    <TestMethod()> _
    Public Sub IronPythonUmlautTest()
        Dim e = IronPython.Hosting.Python.CreateEngine()
        Dim s As Microsoft.Scripting.Hosting.ScriptScope
        Dim code As String
        Dim f As Func(Of Object)

        ' TEST 1: Returning string directly works
        s = e.CreateScope()
        code = "def somefunction():      " & vbCrLf & _
               "    s = ""ä""            " & vbCrLf & _
               "    return s             "

        e.CreateScriptSourceFromString(code).Execute(s)
        f = s.GetVariable(Of Func(Of Object))("somefunction")

        ' Ok
        Assert.IsTrue(CStr(f()) = "ä")


        ' TEST 2: Returning string set via .NET
        s = e.CreateScope()
        s.SetVariable("astring", "ä")
        code = "def somefunction():      " & vbCrLf & _
               "    return astring       "

        e.CreateScriptSourceFromString(code).Execute(s)
        f = s.GetVariable(Of Func(Of Object))("somefunction")

        ' Ok
        Assert.IsTrue(CStr(f()) = "ä")


        ' TEST 3: Running string to python str() function
        s = e.CreateScope()
        code = "def somefunction():      " & vbCrLf & _
               "    s = ""ä""            " & vbCrLf & _
               "    return str(s)        "

        e.CreateScriptSourceFromString(code).Execute(s)
        f = s.GetVariable(Of Func(Of Object))("somefunction")

        ' The following line throws a System.Text.DecoderFallbackException: 
        ' Unable to translate bytes [E4] at index 0 from specified code page to Unicode.
        Assert.IsTrue(CStr(f()) = "ä")


        ' TEST 3: Running string from .NET to python str() function
        s = e.CreateScope()
        s.SetVariable("astring", "ä")
        code = "def somefunction():      " & vbCrLf & _
               "    return str(astring)  "

        e.CreateScriptSourceFromString(code).Execute(s)
        f = s.GetVariable(Of Func(Of Object))("somefunction")

        ' The following line throws a System.Text.DecoderFallbackException: 
        ' Unable to translate bytes [E4] at index 0 from specified code page to Unicode.
        Assert.IsTrue(CStr(f()) = "ä")
    End Sub


"-----------------

4. [New issue] %f directive does not work with datetime/time.strptime/strftime
http://ironpython.codeplex.com/workitem/35202
User pekkaklarck has proposed the issue:

"CPython supports %f directive (microseconds) with time.strptime and datetime.strptime since version 2.6. With IronPython 2.7 you get ValueError with a very confusing message:
IronPython 2.7.3 (2.7.0.40) on .NET 4.0.30319.18444 (32-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> import time, datetime
>>> time.strptime('123', '%f')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot parse %j, %W, or %U w/ other values
>>> datetime.datetime.strptime('123', '%f')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot parse %j, %W, or %U w/ other values
>>> ^Z

Additionally, datetime.strftime doesn't work correctly either:
>>> from datetime import datetime
>>> d = datetime.now()
>>> d.microsecond
377000
>>> d.strftime('%f')
'000000'
"-----------------

5. [New issue] Specific case causes traceback to be incomplete
http://ironpython.codeplex.com/workitem/35204
User kliberty has proposed the issue:

"from traceback import print_exc
def foo():
    return 1[0]
    
try:
    try:
        foo()
    except:
        raise
except:
    print_exc()

ipy64 bug_bad.py
TypeError: 'int' object is unsubscriptable
"
----------------------------------------------



----------------------------------------------
You are receiving this email because you subscribed to notifications on CodePlex.

To report a bug, request a feature, or add a comment, visit IronPython Issue Tracker. You can unsubscribe or change your issue notification settings on CodePlex.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20140508/4ff2dd70/attachment.html>


More information about the Ironpython-users mailing list