On Jan 26, 2013, at 11:04 AM, wander.lair...@gmail.com wrote:

> From: Wander Lairson Costa <wander.lair...@gmail.com>
> 
> In usb/_interop.py in the as_array function, the array typecodes 'c' and
> 'u' are used. The 'c' typecode was removed from python 3.3 and 'u' will
> is deprecated. The solution is to use the fromstring array method, but
> it has the side effect of adding only the first byte of Unicode strings.
> ---
> usb/_interop.py |    7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/usb/_interop.py b/usb/_interop.py
> index 5abdcdb..d6d0a6c 100644
> --- a/usb/_interop.py
> +++ b/usb/_interop.py
> @@ -131,8 +131,7 @@ def as_array(data=None):
>     except TypeError:
>         # When you pass a unicode string or a character sequence,
>         # you get a TypeError if first parameter does not match
> -        try:
> -            return array.array('c', data)
> -        except TypeError:
> -            return array.array('u', data)
> +        a = array.array('B')
> +        a.fromstring(data)
> +        return a
> 

This code when run in python 2.7.4 raises an exception with unicode text as 
data.

In [12]: import array

In [13]: a=array.array('B')

In [14]: s=u"abcꬨ"

In [15]: a.fromstring(s)
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-15-19a810fd072a> in <module>()
----> 1 a.fromstring(s)

UnicodeEncodeError: 'ascii' codec can't encode character u'\uab28' in position 
3: ordinal not in range(128)

In [16]:

> -- 
> 1.7.10.4
> 
> 
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. ON SALE this month only -- learn more at:
> http://p.sf.net/sfu/learnnow-d2d
> _______________________________________________
> pyusb-users mailing list
> pyusb-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyusb-users


------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to