本文整理汇总了Python中ujson.decode函数的典型用法代码示例。如果您正苦于以下问题:Python decode函数的具体用法?Python decode怎么用?Python decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_encodeDictConversion
def test_encodeDictConversion(self):
input = { "k1": 1, "k2": 2, "k3": 3, "k4": 4 }
output = ujson.encode(input)
self.assertEquals(input, json.loads(output))
self.assertEquals(input, ujson.decode(output))
self.assertEquals(input, ujson.decode(output))
pass
示例2: test_dynamic_by_name
def test_dynamic_by_name(self):
VISITOR_ID_1 = uuid.uuid4().hex
EVENT_1 = "Event 1 %s" % uuid.uuid4().hex
EVENT_2 = "Event 2 %s" % uuid.uuid4().hex
yield self.post_event(VISITOR_ID_1, EVENT_1)
yield self.post_event(VISITOR_ID_1, EVENT_2)
events = yield self.get_event_dict()
event_id_1 = events[EVENT_1]
event_id_2 = events[EVENT_2]
qs = urlencode([("event", EVENT_1), ("event", EVENT_2)])
result = yield request(
"GET",
"%s/funnel?%s" % (self.url, qs),
username=self.username,
password=self.password)
self.assertEqual(result.code, 200)
returned_event_ids = ujson.decode(result.body)["event_ids"]
self.assertTrue(event_id_1 in returned_event_ids)
self.assertTrue(event_id_2 in returned_event_ids)
funnel = ujson.decode(result.body)["funnel"]
unique_funnel = ujson.decode(result.body)["unique_funnel"]
self.assertEqual(funnel[0][0], event_id_1)
self.assertEqual(funnel[1][0], event_id_2)
self.assertEqual(funnel[0][1], 1)
self.assertEqual(funnel[1][1], 1)
self.assertEqual(unique_funnel[0][0], event_id_1)
self.assertEqual(unique_funnel[1][0], event_id_2)
self.assertEqual(unique_funnel[0][1], 1)
self.assertEqual(unique_funnel[1][1], 1)
示例3: is_valid_json
def is_valid_json(json: str) -> bool:
try:
ujson.decode(json)
except:
return False
else:
return True
示例4: test_decodeJibberish
def test_decodeJibberish(self):
input = "fdsa sda v9sa fdsa"
try:
ujson.decode(input)
assert False, "Expected exception!"
except(ValueError):
return
assert False, "Wrong exception"
示例5: test_decodeWithTrailingNonWhitespaces
def test_decodeWithTrailingNonWhitespaces(self):
try:
input = "{}\n\t a"
ujson.decode(input)
except ValueError:
pass
else:
assert False, "expected ValueError"
示例6: test_decodeNullBroken
def test_decodeNullBroken(self):
input = "n"
try:
ujson.decode(input)
assert False, "Expected exception!"
except(ValueError):
return
assert False, "Wrong exception"
示例7: test_decodeStringUnterminated
def test_decodeStringUnterminated(self):
input = "\"TESTING"
try:
ujson.decode(input)
assert False, "Expected exception!"
except(ValueError):
return
assert False, "Wrong exception"
示例8: test_decodeStringBadEscape
def test_decodeStringBadEscape(self):
input = "\"TESTING\\\""
try:
ujson.decode(input)
assert False, "Expected exception!"
except(ValueError):
return
assert False, "Wrong exception"
示例9: test_decodeBrokenObjectStart
def test_decodeBrokenObjectStart(self):
input = "{"
try:
ujson.decode(input)
assert False, "Expected exception!"
except(ValueError):
return
assert False, "Wrong exception"
示例10: test_decodeTooBigValue
def test_decodeTooBigValue(self):
try:
input = "9223372036854775808"
ujson.decode(input)
except ValueError as e:
pass
else:
assert False, "expected ValueError"
示例11: test_decodeVeryTooBigValue
def test_decodeVeryTooBigValue(self):
try:
input = "18446744073709551616"
ujson.decode(input)
except ValueError:
pass
else:
assert False, "expected ValueError"
示例12: test_decodeArrayOnlyCommaFail
def test_decodeArrayOnlyCommaFail(self):
input = "[,]"
try:
ujson.decode(input)
except ValueError:
pass
else:
assert False, "expected ValueError"
示例13: test_decodeArrayUnmatchedBracketFail
def test_decodeArrayUnmatchedBracketFail(self):
input = "[]]"
try:
ujson.decode(input)
except ValueError:
pass
else:
assert False, "expected ValueError"
示例14: test_decodeStringUntermEscapeSequence
def test_decodeStringUntermEscapeSequence(self):
input = '"TESTING\\"'
try:
ujson.decode(input)
assert False, "Expected exception!"
except (ValueError):
return
assert False, "Wrong exception"
示例15: test_goodreads
def test_goodreads(self):
def autogenerate_goodreads(*args, **kwargs):
autogenerator = delta.Autogenerator(paths="books", includes="books/id")
return [x.data for x in autogenerator(*args, **kwargs)]
from ujson import decode
old = decode(read("%s/goodreads/old.json" % DATAPATH))
new = decode(read("%s/goodreads/new.json" % DATAPATH))
self.assertEqual(autogenerate_goodreads(old, new), [])