sgzwiz / brython

Automatically exported from code.google.com/p/brython
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Local storage only stores strings #66

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
local_storage["foo"] = [1,2,3]
print(local_storage["foo"][2])

What is the expected output? What do you see instead?
Should be "3", I get ",". Brython should serialize and deserialize 
local_storage values.

Original issue reported on code.google.com by j...@jsantos.eu on 4 Feb 2013 at 5:32

GoogleCodeExporter commented 9 years ago
Enclosed is an attachment that should fix this issue.

Original comment by billy.earney@gmail.com on 9 Feb 2013 at 7:06

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the report and the proposed implementation by Bill
It's fine for me, but I am going to post a message on the forum to see if all 
agree on local_storage using JSON transparently, or if we should let it store 
strings and ask the programmer to explicitely "stringify" and "parse" using JSON
Anyway, with this issue in mind, I recently added a built-in module json.js 
that implements these functions :

import json
x = json.stringify([1,2])
print(json.parse(x))

You can test it in the console on the Brython site

Original comment by pierre.q...@gmail.com on 17 Feb 2013 at 9:04

GoogleCodeExporter commented 9 years ago
Bill, Pierre thanks for the answers, Bill solution is nice but only works for 
lists (it doesn't work for strings). The built-in json.js seems nice but it 
isn't capable of deserializing dicts, for example. I think local_storage should 
be transparent so it could be more reliable.

Original comment by j...@jsantos.eu on 18 Feb 2013 at 8:36