From f03466629f787f6ba6df599d624a105a0ae5d2e9 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Thu, 31 Jul 2014 19:18:26 +0200 Subject: [PATCH] Fix several bugs in lslbasefuncs; change InternalJsonScanMatching strategy. Fix bug: add(Key, Key) is not valid. Fix bug: llList2CSV was raising an exception always. Fix bug in test program: llDumpList2String requires Unicode separator. Patch test program to not output the passed tests. --- lslopt/lslbasefuncs.py | 4 ++-- lslopt/lsljson.py | 29 ++++++++++------------------- testfuncs.py | 8 ++++---- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index 3e5109e..63ee8ed 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -476,7 +476,7 @@ def add(a, b, f32=True): if ta == tb in (list, unicode): return a + b # string + key, key + string are allowed here - if ta in (unicode, Key) and tb in (unicode, Key): + if ta in (unicode, Key) and tb in (unicode, Key) and not (ta == tb == Key): return a + b if ta == list: return a + [b] @@ -931,7 +931,7 @@ def llIntegerToBase64(x): def llList2CSV(lst): assert islist(lst) ret = [] - for elem in val: + for elem in lst: # This always uses LSO rules for float to string. if type(elem) == float: ret.append(u'%.6f' % elem) diff --git a/lslopt/lsljson.py b/lslopt/lsljson.py index 421bdfb..cd3e907 100644 --- a/lslopt/lsljson.py +++ b/lslopt/lsljson.py @@ -143,19 +143,11 @@ def InternalJsonF2S(f): def InternalJsonScanMatching(json, idx): """Shortcut: scan for a matching pair of {} or [] with proper nesting and string handling, with no validity check other than well-formedness, - meaning all {} and [] must match. + meaning all {} or [] must match. """ - # TODO: InternalJsonScanMatching: Decide whether to use two nesting level variables rather than a stack. - # That would mean that a nested malformed string like [{]} would be valid. SL may accept that. - # (Or maybe even just ONE nesting level variable for the current element, - # disregarding the nesting of the other, e.g. if we're on an object, - # the [] are not tracked thus {[} would be valid. That sounds like LSL. - # Or track [] and {} as the same, distinguishing whether - # the one at nesting level 0 matches the first (e.g. {[{}}} would be valid) - # Or just track the current one and screw the other (e.g. {{]]][]{}][}} - # would be valid). That sounds even more like LSL. - # Experiments are advisable. - stk = [json[idx]] + matching = json[idx] + matching += '}' if json[idx] == '{' else ']' + level = 1 str = False esc = False for i in xrange(idx+1, len(json)): @@ -169,13 +161,12 @@ def InternalJsonScanMatching(json, idx): str = False elif c == u'"': str = True - elif c in u'{[': - stk.append(c) - elif c in u']}': - if stk[-1] != (u'{' if c == u'}' else u'['): - return None # bad nesting - stk = stk[:-1] - if stk == []: + elif c in matching: + if c == matching[0]: + level += 1 + else: + level -= 1 + if not level: return i+1 return None diff --git a/testfuncs.py b/testfuncs.py index 6829ba7..98e6720 100644 --- a/testfuncs.py +++ b/testfuncs.py @@ -62,7 +62,7 @@ def test(fn, expected): errors += 1 #raise ETestFailed else: - sys.stdout.write("PASSED! %s == %s\n" % (fn, repr(expected))) + pass#sys.stdout.write("PASSED! %s == %s\n" % (fn, repr(expected))) def shouldexcept(txt, exc): global tests @@ -78,7 +78,7 @@ def shouldexcept(txt, exc): try: eval(txt) except exc: - sys.stdout.write("PASSED! %s on %s\n" % (exc.__name__, txt)) + #sys.stdout.write("PASSED! %s on %s\n" % (exc.__name__, txt)) return werr = sys.stderr.write @@ -130,7 +130,7 @@ def verify(msg, result, expected): werr("Expect: " + repr(expected) + '\n') #return 0 else: - sys.stdout.write("PASSED! %s, expect=actual=%s\n" % (msg, repr(expected))) + pass#sys.stdout.write("PASSED! %s, expect=actual=%s\n" % (msg, repr(expected))) #return 1 def verify_list(msg, result, expected): @@ -642,7 +642,7 @@ def do_tests(): u"9999999933815812510711506376257961984.000000, " u"99999996802856924650656260769173209088.000000") - test('llDumpList2String([F32(1e11)], "/")', u'100000000000.000000') + test('llDumpList2String([F32(1e11)], u"/")', u'100000000000.000000') # Inputs inp = [F32(i) for i in [1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14,