本文整理汇总了Python中ujson.loads函数的典型用法代码示例。如果您正苦于以下问题:Python loads函数的具体用法?Python loads怎么用?Python loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loads函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(j, args, params, tags, tasklet):
doc = args.doc
nid = args.getTag('nid')
nidstr = str(nid)
rediscl = j.clients.redis.getByInstance('system')
out = list()
out.append('||Port||Status||Memory Used||')
rstatus = rediscl.hget('healthcheck:monitoring', 'results')
errors = rediscl.hget('healthcheck:monitoring', 'errors')
rstatus = ujson.loads(rstatus) if rstatus else dict()
errors = ujson.loads(errors) if errors else dict()
for data in [rstatus, errors]:
if nidstr in data:
if 'redis' in data.get(nidstr, dict()):
rnstatus = data[nidstr].get('redis', dict())
for stat in rnstatus:
if 'state' not in stat:
continue
state = j.core.grid.healthchecker.getWikiStatus(stat.get('state', 'UNKNOWN'))
usage = "%s / %s" % (stat.get('memory_usage', ''), stat.get('memory_max', ''))
out.append('|%s|%s|%s|' % (stat.get('port', -1), state, usage))
out = '\n'.join(out)
params.result = (out, doc)
return params
示例2: test_ReadBadObjectSyntax
def test_ReadBadObjectSyntax(self):
try:
ujson.loads('{"age", 44}')
except ValueError:
pass
else:
assert False, "expected ValueError"
示例3: test_decodeArrayFaultyUnicode
def test_decodeArrayFaultyUnicode(self):
try:
ujson.loads('[18446744073709551616]')
except ValueError:
pass
else:
assert False, "expected ValueError"
示例4: test_set_active
def test_set_active(self):
# type: () -> None
self.login("[email protected]")
client = 'website'
self.client_post("/json/users/me/presence", {'status': 'idle'})
result = self.client_post("/json/get_active_statuses", {})
self.assert_json_success(result)
json = ujson.loads(result.content)
self.assertEqual(json['presences']["[email protected]"][client]['status'], 'idle')
email = "[email protected]"
self.login("[email protected]")
self.client_post("/json/users/me/presence", {'status': 'idle'})
result = self.client_post("/json/get_active_statuses", {})
self.assert_json_success(result)
json = ujson.loads(result.content)
self.assertEqual(json['presences'][email][client]['status'], 'idle')
self.assertEqual(json['presences']['[email protected]'][client]['status'], 'idle')
self.client_post("/json/users/me/presence", {'status': 'active'})
result = self.client_post("/json/get_active_statuses", {})
self.assert_json_success(result)
json = ujson.loads(result.content)
self.assertEqual(json['presences'][email][client]['status'], 'active')
self.assertEqual(json['presences']['[email protected]'][client]['status'], 'idle')
示例5: post
def post(request):
"""Sets a key to a value on the currently logged in users preferences
:param key: Key to set
:type key: str
:param val: Value to set
:type val: primitive
:returns: json
"""
data = request.POST or json.loads(request.body)['body']
key = data.get('key', None)
val = data.get('val', None)
res = Result()
if key is not None and val is not None:
obj, created = UserPref.objects.get_or_create(user=request.user)
if created:
obj.data = json.dumps(DefaultPrefs.copy())
obj.save()
try:
val = json.loads(val)
except (TypeError, ValueError):
pass
obj.setKey(key, val)
obj.save()
res.append(obj.json())
return JsonResponse(res.asDict())
示例6: from_json
def from_json(text):
# Skip lines containing nothing but whitespace and lines that contain just
# a hexadecimal number. The latter arises when the tweet stream is using
# "Transfer-Encoding: chunked" and the chunk delimeters made their way into
# the output file (i.e., before issue #92 was fixed).
if (re.search(r'^[0-9a-f\s]*$', text)):
raise Nothing_To_Parse_Error()
try:
j = json.loads(text.replace(r'\\"', r'\"')) # Isaac: was having problems parsing PostgreSQL JSONs
except ValueError:
j = json.loads(text) # raises ValueError on parse failure
if ('delete' in j):
return Deletion_Notice.from_json(j)
elif ('limit' in j):
return Limit_Notice.from_json(j)
elif ('scrub_geo' in j):
return Scrub_Geo_Notice.from_json(j)
elif ('status_withheld' in j):
return Status_Withheld.from_json(j)
elif ('text' in j):
return Tweet.from_json(j)
elif ('warning' in j):
return Warning.from_json(j)
else:
raise Unknown_Object_Error()
示例7: loads
def loads(*args, **kwargs):
try:
if json.__name__ == "ujson":
return json.loads(*args, **kwargs)
return json.loads(strict=False, *args, **kwargs)
except ValueError:
raise ResultParseError("The JSON result could not be parsed")
示例8: test_get_samples
def test_get_samples(self):
res = mock.Mock()
req = mock.Mock()
def _side_effect(arg):
if arg == 'name':
return 'tongli'
elif arg == 'dimensions':
return 'key1:100, key2:200'
req.get_param.side_effect = _side_effect
req_result = mock.Mock()
req_result.json.return_value = json.loads(self.response_str)
req_result.status_code = 200
with mock.patch.object(requests, 'post', return_value=req_result):
self.dispatcher.get_samples(req, res)
# test that the response code is 200
self.assertEqual(res.status, getattr(falcon, 'HTTP_200'))
obj = json.loads(res.body)
self.assertEqual(obj[0]['meter'], 'BABMGD')
self.assertEqual(obj[0]['id'], 'AVOziWmP6-pxt0dRmr7j')
self.assertEqual(obj[0]['type'], 'metrics')
self.assertEqual(obj[0]['user_id'],
'efd87807-12d2-4b38-9c70-5f5c2ac427ff')
self.assertEqual(obj[0]['project_id'],
'35b17138-b364-4e6a-a131-8f3099c5be68')
self.assertEqual(obj[0]['timestamp'], 1461337094000)
self.assertEqual(obj[0]['volume'], 4)
self.assertEqual(len(obj), 1)
示例9: loadFromFilesystem
def loadFromFilesystem(self):
if os.path.isfile(PROFILE_DIR+'UserProfile/UserProfile.json'):
# We already have a JSON file. Load the details from the file at the start.
with open(PROFILE_DIR+'UserProfile/UserProfile.json', 'rb') as f:
self.__settingsAndProfile = ujson.loads(f.read())
# Check for old version.
if 'selectedTopics' in self.__settingsAndProfile:
# This is a 1.1.2 JSON file. needs to be migrated.
migrationResult = self.__migrateFrom112to120(self.__settingsAndProfile)
with open(PROFILE_DIR+'UserProfile/UserProfile.json', 'wb') as f:
f.write(ujson.encode(migrationResult))
self.__settingsAndProfile = ujson.loads(f.read())
else:
# The main
self.__updateBootStatus()
else:
# We don't have a JSON file. This means it's not created yet. Create it.
with open(PROFILE_DIR+'UserProfile/UserProfile.json', 'wb') as f:
# Now, time to set some defaults.
newProfileFile = self.__produceProfileWithDefaults()
newProfileFile['machineDetails']['listeningPort'] = self.__getRandomOpenPort()
f.write(ujson.encode(newProfileFile))
# This is the first load ever.
with open(PROFILE_DIR+'UserProfile/UserProfile.json', 'rb') as f:
self.__settingsAndProfile = ujson.loads(f.read())
示例10: init_thread_proc
def init_thread_proc(self):
try:
if os.path.isfile(DUMP_PATH + '/' + DUMP_FILE):
fpdump = open(DUMP_PATH + '/' + DUMP_FILE)
totaldict = pickle.load(fpdump)
fpdump.close()
self._spellcitydict = totaldict['spellcitydict']
self._citydict = totaldict['citydict']
else:
self.get_city_service()
except:
pass
self._selfparmeter = sys.argv
post_service_data('192.168.0.24', '8030', 'register', sys.argv)
rawretdata = get_active_service('192.168.0.24', '8030', 'getinstance')
retdata = json.loads(rawretdata)
self._totalservicelist = retdata['data']
if len(retdata['data']) != 1:
tempnode = retdata['data'][0]
rawtotaldict = get_active_service(tempnode['host'], tempnode['port'], 'othersget')
totaldict = json.loads(rawtotaldict)['data']
self._citydict = totaldict['citydict']
self._spellcitydict = totaldict['spellcitydict']
self.set_auto_update(1)
return {'result' : '0'}
示例11: get_updated_account_data_for_user_txn
def get_updated_account_data_for_user_txn(txn):
sql = (
"SELECT account_data_type, content FROM account_data"
" WHERE user_id = ? AND stream_id > ?"
)
txn.execute(sql, (user_id, stream_id))
global_account_data = {
row[0]: json.loads(row[1]) for row in txn.fetchall()
}
sql = (
"SELECT room_id, account_data_type, content FROM room_account_data"
" WHERE user_id = ? AND stream_id > ?"
)
txn.execute(sql, (user_id, stream_id))
account_data_by_room = {}
for row in txn.fetchall():
room_account_data = account_data_by_room.setdefault(row[0], {})
room_account_data[row[1]] = json.loads(row[2])
return (global_account_data, account_data_by_room)
示例12: main
def main(j, args, params, tags, tasklet):
doc = args.doc
nid = args.getTag('nid')
nidstr = str(nid)
rediscl = j.clients.redis.getGeventRedisClient('127.0.0.1', 9999)
out = list()
disks = rediscl.hget('healthcheck:monitoring', 'results')
errors = rediscl.hget('healthcheck:monitoring', 'errors')
disks = ujson.loads(disks) if disks else dict()
errors = ujson.loads(errors) if errors else dict()
out.append('||Disk||Free Space||Status||')
for type, data in (('error', errors), ('disk', disks)):
if nidstr in data:
if 'disks' in data.get(nidstr, dict()):
ddata = data[nidstr].get('disks', list())
for diskstat in ddata:
if type == 'error':
diskstat = diskstat.values()[0]
if 'state' not in diskstat:
continue
state = j.core.grid.healthchecker.getWikiStatus(diskstat.get('state', 'UNKNOWN'))
out.append('|%s|%s|%s|' % (diskstat.get('path', ''), diskstat.get('message', ''), state))
out.append('\n')
out = '\n'.join(out)
params.result = (out, doc)
return params
示例13: list_of_all_data_in_bioactivities
def list_of_all_data_in_bioactivities(request):
"""Lists all requested data for filtering bioactivities"""
exclude_questionable = json.loads(request.GET.get('exclude_questionable'))
pubchem = json.loads(request.GET.get('pubchem'))
target_types = json.loads(request.GET.get('target_types'))
organisms = json.loads(request.GET.get('organisms'))
desired_target_types = [
x.get(
'name'
) for x in target_types
if x.get(
'is_selected'
) is True
]
desired_organisms = [
x.get(
'name'
) for x in organisms
if x.get(
'is_selected'
) is True
]
return JSONResponse(
generate_list_of_all_data_in_bioactivities(
exclude_questionable,
pubchem,
desired_organisms,
desired_target_types
)
)
示例14: thread_main
def thread_main():
delta = None
rpc_count = 0
while True:
want = self.want_axis_video
req = {
'__type': 'AxisCameraDaemonReq',
'traceSpec': {
'__type': 'VideoTraceSpec',
'traceDir': path.join(remote_traces_dir, self.trace_name),
'traceName': self.trace_name,
'timeseqName': timeseq_name,
},
'cameraConfig': {
'__type': 'AxisCameraConfig',
'ipaddr': ipaddr,
'url': '/axis-cgi/mjpg/video.cgi?compression=30&rotation=0&resolution=' + resolution,
'authHeader': auth_header,
},
'txTime': time.time(),
'recordFor': 10.0 if want else 0.0,
}
rpc_id = 'rpc%d' % rpc_count
rpc_count += 1
tx = ['record', rpc_id, ujson.dumps(req, escape_forward_slashes=False)]
if 1: logger.info('camera %s < %s', daemon_endpoint, tx)
self.sock.send_multipart(tx, flags=0, copy=True, track=False)
rx = self.sock.recv_multipart(flags=0, copy=True, track=False)
rx_time = time.time()
if 1: logger.info('%s > %s %s', daemon_endpoint, rx[1], rx[2])
rpc_id2 = rx[0]
rpc_err = ujson.loads(rx[1])
rpc_result = ujson.loads(rx[2])
if rpc_err:
logger.info('%s > error %s', daemon_endpoint, rpc_err)
break
min_delta = rpc_result['txTime'] - rx_time
max_delta = rpc_result['txTime'] - rpc_result['reqTxTime']
if delta is None:
delta = (min_delta + max_delta) * 0.5
delta = max(min_delta, min(max_delta, delta))
if 0: logger.info("timing %0.6f %+0.6f %+0.6f min_delta=%+0.6f max_delta=%+0.6f delta=%+0.6f",
rpc_result['reqTxTime'], rpc_result['txTime'], rx_time, min_delta, max_delta, delta)
rep_times = rpc_result['times']
rep_samples = rpc_result['samples']
for ts, sample in zip(rep_times, rep_samples):
self.add(ts - delta, timeseq_name, sample)
rep_chunks = rpc_result['chunks']
for chunk_ts in rep_chunks:
chunk_fn = 'chunk_%s_%.0f.video' % (timeseq_name, chunk_ts)
chunk_path = path.join(self.trace_dir, chunk_fn)
src_file = path.join(local_link_prefix, self.trace_name, chunk_fn)
logger.info('Create symlink(%s, %s) llp=%s rtd=%s', src_file, chunk_path, local_link_prefix, remote_traces_dir)
os.symlink(src_file, chunk_path)
if not want: break
time.sleep(0.1)
示例15: notify
def notify(result):
stream = result.get("events")
if stream:
max_position = stream["position"]
for row in stream["rows"]:
position = row[0]
internal = json.loads(row[1])
event_json = json.loads(row[2])
event = FrozenEvent(event_json, internal_metadata_dict=internal)
extra_users = ()
if event.type == EventTypes.Member:
extra_users = (event.state_key,)
notifier.on_new_room_event(
event, position, max_position, extra_users
)
notify_from_stream(
result, "push_rules", "push_rules_key", user="user_id"
)
notify_from_stream(
result, "user_account_data", "account_data_key", user="user_id"
)
notify_from_stream(
result, "room_account_data", "account_data_key", user="user_id"
)
notify_from_stream(
result, "tag_account_data", "account_data_key", user="user_id"
)
notify_from_stream(
result, "receipts", "receipt_key", room="room_id"
)
notify_from_stream(
result, "typing", "typing_key", room="room_id"
)