Try to do this
json.write({ 'a': 'asd"fg'})
and you will have an exception
also it's opaque, how writting of unicode is occurred
i think it can be fixed by following
#At the beginning of json.py
#table of conversation as in a standart:
change=
{'"':'\\"','/':'\\/','\\':'\\\\','\b':'\\b','\f':'\\f','\n':'\\n','\r':'\\r','\t':'\\t'}
#And may be this:
#for i in xrange(128,256):
# change[chr(i)]="\\u%04x"%i
# change[unichr(i)]="\\u%04x"%i
#custom represantation of strings
def repr_str_json(ins):
outs=[];
for i in ins:
if i in change:
outs.append(change[i])
elif ord(i)>=256:
outs.append(i.encode('unicode_escape'))
else:
outs.append(chr(ord(i)))
outs="".join(outs)
return outs
#in JsonReader._hexDigitToInt
def _hexDigitToInt(self, ch):
try:
result =
{'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,
'a': 10,'A': 10,
'b': 11,'B': 11,
'c': 12,'C': 12,
'd': 13,'D': 13,
'e': 14,'E': 14,
'f': 15,'F': 15
}[ch]
except KeyError:
# try:
# result = int(ch)
# except ValueError:
# raise ReadException, "The character %
s is not a hex digit." % ch
raise ReadException, "The character %s
is not a hex digit." % ch
return result
#in JsonWriter._write
elif ty is types.StringType or ty is
types.UnicodeType:
self._append('"')
self._append(repr_str_json(obj))
self._append('"')
elif ty is types.IntType or ty is types.LongType:
self._append(str(obj))
Logged In: YES
user_id=661556
Longs are now written and json.write({ 'a': 'asd"fg'}) is
written correctly escaping the embedded double quote.
The unicode stuff needs work.