def index(): response = None format = "json" if request.method == "POST": format = request.form["format"] data = request.form["data"] try: if format == "vdf": response = json.dumps( vdf.loads(data), indent=4 ) elif format == "json": _response = json.loads(data) response = vdf.dumps(_response).decode("utf-16") except ValueError: flash("ValueError: Your {} may not be valid.".format(format), "danger") response = "{}" if format == "json" else "" return render_template("vdfjson.html", response=response, format=format, title="vdfjson")
def test_macro_quoted(self): self.assertEqual(self.EXPECTED_DICT, vdf.loads(self.MACRO_QUOTED_VDF))
def test_quoted(self): self.assertEqual(self.EXPECTED_DICT, vdf.loads(self.QUOTED_VDF))
def test_multikey_knode(self): self.maxDiff = 80 * 80 self.assertEqual(self.EXPECTED_MULTIKEY_KNODE, vdf.loads(self.MULTIKEY_KNODE))
def test_numerical_dict(self): self.assertEqual(self.EXPECTED_NUMERICAL_DICT, vdf.loads(vdf.dumps(self.NUMERICAL_DICT)))
def test_subnode_dict(self): self.assertEqual(self.EXPECTED_SUBNODE_DICT, vdf.loads(vdf.dumps(self.SUBNODE_DICT)))
def test_multikey_knode(self): self.maxDiff = 80*80 self.assertEqual(self.EXPECTED_MULTIKEY_KNODE, vdf.loads(self.MULTIKEY_KNODE))
def test_mixed(self): self.assertEqual(self.EXPECTED_MIXED_DICT, vdf.loads(self.MIXED_VDF))
def test_simple_dict(self): self.assertEqual(self.EXPECTED_SIMPLE_DICT, vdf.loads(vdf.dumps(self.SIMPLE_DICT)))
def test_subnode_quoted(self): self.assertEqual(self.EXPECTED_SUBNODE_DICT, vdf.loads(self.SUBNODE_QUOTED_VDF))
def test_comment_quoted(self): self.assertEqual(self.EXPECTED_DICT, vdf.loads(self.COMMENT_QUOTED_VDF))
def test_multikey_kv(self): self.assertEqual(self.EXPECTED_MULTIKEY_KV, vdf.loads(self.MULTIKEY_KV))
def test_array_dict(self): self.assertEqual(self.EXPECTED_ARRAY_DICT, vdf.loads(vdf.dumps(self.ARRAY_DICT)))
def test_combination_dict(self): self.assertEqual(self.EXPECTED_COMBINATION_DICT, vdf.loads(vdf.dumps(self.COMBINATION_DICT)))