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)
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<T, d>' in index.get('objects').get('') # n::Array<T,d> is escaped
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))
def jsload(path): searchindex = path.text() assert searchindex.startswith('Search.setIndex(') return jsdump.loads(searchindex[16:-2])
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)
def jsload(path): searchindex = path.read_text() assert searchindex.startswith('Search.setIndex(') assert searchindex.endswith(')') return jsdump.loads(searchindex[16:-1])