def detect(stream): """Returns True if given stream is valid JSON.""" try: json.loads(stream) return True except ValueError: return False
def import_book(dbook, in_stream): """Returns databook from JSON stream.""" dbook.wipe() for sheet in json.loads(in_stream): data = tablib.Dataset() data.title = sheet['title'] data.dict = sheet['data'] dbook.add_sheet(data)
def import_set(dset, in_stream): """Returns dataset from JSON stream.""" dset.wipe() dset.dict = json.loads(in_stream)