It's me again... And, while we're at it, shouldn't the test of "isinstance(o, XmlComponent)" actually be "issubclass(o.__class__, XmlComponent)?" The former fails on all of the helpers which are subclasses of DIV because "isinstance" only checks the direct parent, it does not check up the "tree". And all of the helpers are subclasses of DIV, which itself is a subclass of XmlComponent.
Just askin'... On Friday, May 26, 2017 at 12:05:25 PM UTC-7, Joe Barnhart wrote: > > I dunno how this affects me and not everyone else who uses this tool. It > looks like the default JSON serializer for web2py has a huge flaw. But if > that were true, it would have been noticed by lots 'o people before. So it > must be impure thinking on my part. > > My objects are being serialized with long ints. The long ints are > rendered as Python long ints with an "L" at the end, such as "110L". This > is illegal in Javascript and results in a fatal error. > > I examined the code behind the gluon.serializers and found the default > serializer used: > > def custom_json(o): > if hasattr(o, 'custom_json') and callable(o.custom_json): > return o.custom_json() > if isinstance(o, (datetime.date, > datetime.datetime, > datetime.time)): > return o.isoformat()[:19].replace('T', ' ') > elif isinstance(o, (int, long)): > return int(o) > elif isinstance(o, decimal.Decimal): > return str(o) > elif isinstance(o, lazyT): > return str(o) > elif isinstance(o, XmlComponent): > return str(o) > elif isinstance(o, set): > return list(o) > elif hasattr(o, 'as_list') and callable(o.as_list): > return o.as_list() > elif hasattr(o, 'as_dict') and callable(o.as_dict): > return o.as_dict() > else: > raise TypeError(repr(o) + " is not JSON serializable") > > Yep. There it is. Give it a long instance of 110 and it returns 110L > every time. Javascript responds with "SyntaxError: No identifiers allowed > directly after numeric literal" every time. > > Where am I going wrong? > > -- Joe > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.