[Ironpython-users] bytearray encoding issue

Slide slide.o.mix at gmail.com
Mon Aug 18 17:22:22 CEST 2014


I agree, I think we need to determine the best way to implement this so we
match CPython more. I think if we just patch the stdlib though, we may run
into other cases in the future that we would need to fix, but if we
determine how to make it work inside IronPython, it would be better.


On Mon, Aug 18, 2014 at 12:45 AM, Pawel Jasinski <pawel.jasinski at gmail.com>
wrote:

> I personally vote for as close to cpython as possible. This is based on
> porting experience with python packages. It is really a lot of effort
> effort to find the places where it trips in other packages, get the 'if'
> around it and get it accepted upstream.
> This appears to fix it:
> https://github.com/paweljasinski/IronLanguages/commit/f0c8b64c14e1ea088715cd1aeed1b058c61f00d3
> --pawel
>
>
>
> On Mon, Aug 18, 2014 at 5:08 AM, Daniel Fernandez <
> fernandez_dan2 at hotmail.com> wrote:
>
>> Hi Alex,
>>
>> Oh wow I didn't know that, interesting question. If CPython is wrong for
>> bytearray, should IronPython follow the same, unless you think CPython will
>> fix it?
>>
>> Thanks.
>>
>> Danny
>>
>> ------------------------------
>> Date: Sun, 17 Aug 2014 19:13:59 -0700
>> Subject: Re: [Ironpython-users] bytearray encoding issue
>> From: slide.o.mix at gmail.com
>> To: fernandez_dan2 at hotmail.com
>>
>> You are probably running into this
>> http://ironpython.codeplex.com/workitem/21334. As is mentioned in the
>> issue, I believe this shouldn't really work in cpython, but does because
>> str implements the buffer interface.
>> On Aug 17, 2014 5:21 PM, "Daniel Fernandez" <fernandez_dan2 at hotmail.com>
>> wrote:
>>
>>  Hi All,
>>
>> I ran into an issue bytearray with encoding. The scenario I am using it
>> is with read/writing data over the serial com port. I notice in CPython
>> 2.7.8 the following works
>>
>> >>> bytearray('Michael Gilfix was here\n')
>> bytearray(b'Michael Gilfix was here\n')
>>
>>
>> In IronPython 2.7.5 beta I get the following
>> >>> b = bytearray('Michael Gilfix was here\n')
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> TypeError: unicode argument without an encoding
>>
>> I can get it to work if I do the following
>> b = bytearray(b'Michael Gilfix was here\n')
>>
>> does the bytearray in CPython do an implicit encoding if not specific to
>> binary?
>>
>>
>> I am trying to use hex with bytearray but I see issues with that as well
>> with encoding. Here is an example
>>
>> CPython 2.7.8
>> >>> hex_string = "deadbeef"
>> >>> hex_data = hex_string.decode("hex")
>> >>> hex_data
>> '\xde\xad\xbe\xef'
>> >>> bytearray(hex_data)
>> bytearray(b'\xde\xad\xbe\xef')
>>
>> IronPython 2.7.5 Beta
>>  >>> hex_string = "deadbeef"
>> >>> hex_data = hex_string.decode("hex")
>> >>> hex_data
>> u'\xde\xad\xbe\xef'
>> >>> bytearray(hex_data)
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> TypeError: unicode argument without an encoding
>>
>> >>> bytearray(hex_data, 'hex')
>> bytearray(b'deadbeef')
>>
>>
>> Thanks
>>
>> Danny
>>
>> _______________________________________________
>> Ironpython-users mailing list
>> Ironpython-users at python.org
>> https://mail.python.org/mailman/listinfo/ironpython-users
>>
>>
>> _______________________________________________
>> Ironpython-users mailing list
>> Ironpython-users at python.org
>> https://mail.python.org/mailman/listinfo/ironpython-users
>>
>>
>


-- 
Website: http://earl-of-code.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20140818/bf7f316e/attachment.html>


More information about the Ironpython-users mailing list