Example #1
0
 def loads(self, s):
     # type: (str) -> Any
     data = s[len(self.PREFIX):-len(self.SUFFIX)]
     if not data or not s.startswith(self.PREFIX) or not \
        s.endswith(self.SUFFIX):
         raise ValueError('invalid data')
     return jsdump.loads(data)
Example #2
0
 def loads(self, s):
     # type: (str) -> Any
     data = s[len(self.PREFIX):-len(self.SUFFIX)]
     if not data or not s.startswith(self.PREFIX) or not \
        s.endswith(self.SUFFIX):
         raise ValueError('invalid data')
     return jsdump.loads(data)
Example #3
0
def test_objects_are_escaped(app, status, warning):
    app.builder.build_all()
    searchindex = (app.outdir / 'searchindex.js').text()
    assert searchindex.startswith('Search.setIndex(')

    index = jsdump.loads(searchindex[16:-2])
    assert 'n::Array&lt;T, d&gt;' in index.get('objects').get('')  # n::Array<T,d> is escaped
Example #4
0
def test_objects_are_escaped(app, status, warning):
    app.builder.build_all()
    searchindex = (app.outdir / 'searchindex.js').text()
    assert searchindex.startswith('Search.setIndex(')

    index = jsdump.loads(searchindex[16:-2])
    assert 'n::Array&lt;T, d&gt;' in index.get('objects').get('')  # n::Array<T,d> is escaped
Example #5
0
def test_jsdump():
    data = {'1a': 1}
    assert dumps(data) == '{"1a":1}'
    assert data == loads(dumps(data))

    data = {'a1': 1}
    assert dumps(data) == '{a1:1}'
    assert data == loads(dumps(data))

    data = {u'a\xe8': 1}
    assert dumps(data) == '{"a\\u00e8":1}'
    assert data == loads(dumps(data))

    data = {'_foo': 1}
    assert dumps(data) == '{_foo:1}'
    assert data == loads(dumps(data))
Example #6
0
def jsload(path):
    searchindex = path.text()
    assert searchindex.startswith('Search.setIndex(')

    return jsdump.loads(searchindex[16:-2])
Example #7
0
 def loads(self, s):
     data = s[len(self.PREFIX) : -len(self.SUFFIX)]
     if not data or not s.startswith(self.PREFIX) or not s.endswith(self.SUFFIX):
         raise ValueError("invalid data")
     return jsdump.loads(data)
Example #8
0
def jsload(path):
    searchindex = path.text()
    assert searchindex.startswith('Search.setIndex(')

    return jsdump.loads(searchindex[16:-2])
Example #9
0
def jsload(path):
    searchindex = path.read_text()
    assert searchindex.startswith('Search.setIndex(')
    assert searchindex.endswith(')')

    return jsdump.loads(searchindex[16:-1])