Bug in C Extension?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug in C Extension?

ducky427
(Apologise for bug report here. I was unable to register on the website).

Hello,
I have come across a bug in the development version of PyAMF (r3404).
The bug happens only if I install the C-Extensions for PyAMF.

The program listing is:
---------
import pyamf
t = {u'hello': 'world'}
print pyamf.encode(t).getvalue()
--------

The error stack trace is:
----------
Traceback (most recent call last):
  File "test_pyamf.py", line 6, in <module>
    print pyamf.encode(t).getvalue()
  File "/Library/Python/2.6/site-packages/PyAMF-0.6b1dev_r3398-py2.6-macosx-10.4-universal.egg/pyamf/__init__.py",
line 1431, in encode
    encoder.writeElement(el)
  File "amf3.pyx", line 1235, in cpyamf.amf3.Encoder.writeElement
(cpyamf/amf3.c:13763)
  File "amf3.pyx", line 1272, in cpyamf.amf3.Encoder.writeElement
(cpyamf/amf3.c:13225)
  File "amf3.pyx", line 1101, in cpyamf.amf3.Encoder.writeObject
(cpyamf/amf3.c:11350)
TypeError: Expected str, got unicode
-----------

Thanks
Rohit
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Bug in C Extension?

Rob Harvey
A lot of C modules can't handle unicode. You've got it right there (it
is the "hello" key). Change that to a string and it will work.

 -rob

On Tue, Jun 22, 2010 at 12:03 PM, Rohit Aggarwal
<[hidden email]> wrote:

> (Apologise for bug report here. I was unable to register on the website).
>
> Hello,
> I have come across a bug in the development version of PyAMF (r3404).
> The bug happens only if I install the C-Extensions for PyAMF.
>
> The program listing is:
> ---------
> import pyamf
> t = {u'hello': 'world'}
> print pyamf.encode(t).getvalue()
> --------
>
> The error stack trace is:
> ----------
> Traceback (most recent call last):
>  File "test_pyamf.py", line 6, in <module>
>    print pyamf.encode(t).getvalue()
>  File "/Library/Python/2.6/site-packages/PyAMF-0.6b1dev_r3398-py2.6-macosx-10.4-universal.egg/pyamf/__init__.py",
> line 1431, in encode
>    encoder.writeElement(el)
>  File "amf3.pyx", line 1235, in cpyamf.amf3.Encoder.writeElement
> (cpyamf/amf3.c:13763)
>  File "amf3.pyx", line 1272, in cpyamf.amf3.Encoder.writeElement
> (cpyamf/amf3.c:13225)
>  File "amf3.pyx", line 1101, in cpyamf.amf3.Encoder.writeObject
> (cpyamf/amf3.c:11350)
> TypeError: Expected str, got unicode
> -----------
>
> Thanks
> Rohit
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users
>
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Bug in C Extension?

ducky427
In reply to this post by ducky427
Thanks Rob. I did notice that the problem was the unicode key and I
could simply convert the keys to string to get around the problem.

I was able to encode  unicode strings on their own using the
C-Extension which leads me to suspect that the way dict objects are
encoded in C-Extension is not the same manner as the pure Python
encoder.

I think having the same behaviour for pure Python and the C-Extension
should be the desired goal. Or perhaps the difference(s) should be
documented.

Cheers
Rohit
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Bug in C Extension?

Nick Joyce
In reply to this post by ducky427
On 23 Jun 2010, at 05:03, Rohit Aggarwal wrote:

> (Apologise for bug report here. I was unable to register on the website).

It appears that you are registered on Trac, I did try it myself and came up against up with an error. I'll do some investigating and see how to resolve this.

Can you try logging in?

>
> Hello,
> I have come across a bug in the development version of PyAMF (r3404).
> The bug happens only if I install the C-Extensions for PyAMF.
>
> The program listing is:
> ---------
> import pyamf
> t = {u'hello': 'world'}
> print pyamf.encode(t).getvalue()
> --------
>
> The error stack trace is:
> ----------
> Traceback (most recent call last):
>  File "test_pyamf.py", line 6, in <module>
>    print pyamf.encode(t).getvalue()
>  File "/Library/Python/2.6/site-packages/PyAMF-0.6b1dev_r3398-py2.6-macosx-10.4-universal.egg/pyamf/__init__.py",
> line 1431, in encode
>    encoder.writeElement(el)
>  File "amf3.pyx", line 1235, in cpyamf.amf3.Encoder.writeElement
> (cpyamf/amf3.c:13763)
>  File "amf3.pyx", line 1272, in cpyamf.amf3.Encoder.writeElement
> (cpyamf/amf3.c:13225)
>  File "amf3.pyx", line 1101, in cpyamf.amf3.Encoder.writeObject
> (cpyamf/amf3.c:11350)
> TypeError: Expected str, got unicode

This is a regression, I have created http://dev.pyamf.org/ticket/786 to track this issue.

Correct me if I'm wrong, but I believe that ActionScript instance attributes can only be ascii strings, no unicode/utf-8 data? Same goes for Dictionary etc. objects? Any Flash/Flex gurus wanna jump in here?

If thats the case then unicode dictionary keys should be converted to ascii, otherwise raise an appropriate error?

How did you come across this error - just general poking or something more involved? Are you using SQLAlchemy/Django ORM for example, which would mean that we need to handle that edge case specifically ..

Thanks!

Nick


_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Bug in C Extension?

Simon Bierbaum-2
Hi,

Am 23.06.2010 um 10:42 schrieb Nick Joyce:

> Correct me if I'm wrong, but I believe that ActionScript instance attributes can only be ascii strings, no unicode/utf-8 data? Same goes for Dictionary etc. objects? Any Flash/Flex gurus wanna jump in here?

In AS3, attribute names can at the very least contain umlauts and accented characters (äöüëé etc.), which are not in ASCII, though I get a syntax error when using the euro sign €. The Dictionary class uses objects for keys, so you can use any UTF-8 encoded string (the default in Flex Builder). If the usual dotted notation for attribute access (obj.attrName) throws a syntax error, you can always use obj['attrName'].

Cheers, Simon
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Bug in C Extension?

Nick Joyce
On 23 Jun 2010, at 19:03, Simon Bierbaum wrote:

> Hi,
>
> Am 23.06.2010 um 10:42 schrieb Nick Joyce:
>
>> Correct me if I'm wrong, but I believe that ActionScript instance attributes can only be ascii strings, no unicode/utf-8 data? Same goes for Dictionary etc. objects? Any Flash/Flex gurus wanna jump in here?
>
> In AS3, attribute names can at the very least contain umlauts and accented characters (äöüëé etc.), which are not in ASCII, though I get a syntax error when using the euro sign €. The Dictionary class uses objects for keys, so you can use any UTF-8 encoded string (the default in Flex Builder). If the usual dotted notation for attribute access (obj.attrName) throws a syntax error, you can always use obj['attrName'].

Good to know, I'll add that to the ticket - thanks.

> Cheers, Simon
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users