Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def fetch_schema(conn):
"""
Fetch the Solr schema in JSON format via the provided pysolr
connection object (`conn`).
"""
jsn = conn._send_request('get', 'schema/fields?wt=json')
return ujson.loads(jsn)
elif options.get('ping'):
for num in range(0, args.ttl):
ret = cli.ping()
print("roundtrip: %s ms" % ret)
select.select([], [], [], 1)
elif options.get('submit'):
if not sys.stdin.isatty():
stdin = sys.stdin.read()
else:
logger.error("No data passed via STDIN")
raise SystemExit
try:
data = json.loads(stdin)
try:
ret = cli.submit(data)
print('submitted: {0}'.format(ret))
except Exception as e:
logger.error(e)
raise SystemExit
except Exception as e:
logger.error(e)
raise SystemExit
else:
logger.warning('operation not supported')
p.print_help()
raise SystemExit
def _tryJson(data, raw=True):
'''internal'''
if raw:
return data
try:
return json.loads(data)
except ValueError:
return data
async def create_device(self, request):
try:
device_data = await self._read_data(request)
device_dict = json.loads(device_data)
logger.debug('new device arg=%s', device_dict)
found = self.redis_client.exists('HS:DEVICE:{}'.format(device_dict['id']))
if found:
return web.Response(status=409, text='device already exists!')
self.redis_client.hmset('HS:DEVICE:{}'.format(device_dict['id']), device_dict)
self.redis_client.sadd('SET:DEVICE', device_dict['id'])
self.redis_client.publish('CHANNEL:DEVICE_ADD', json.dumps(device_dict))
return web.Response()
except Exception as e:
logger.error('create_device failed: %s', repr(e), exc_info=True)
return web.Response(status=400, text=repr(e))
def json(self):
import ujson
return ujson.loads(self.content)
#!/usr/bin/env python
#
# Copyright (C) 2017 Sean D'Epagnier
#
# This Program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
try:
import ujson
loads, dumps = ujson.loads, ujson.dumps
except Exception as e:
print('WARNING: python ujson library failed, parsing will consume more cpu', e)
import json as kjson
loads, dumps = json.loads, json.dumps
def api_pivotal_webhook_v5(request, user_profile, stream):
payload = ujson.loads(request.body)
event_type = payload["kind"]
project_name = payload["project"]["name"]
project_id = payload["project"]["id"]
primary_resources = payload["primary_resources"][0]
story_url = primary_resources["url"]
story_type = primary_resources["story_type"]
story_id = primary_resources["id"]
story_name = primary_resources["name"]
performed_by = payload.get("performed_by", {}).get("name", "")
story_info = "[%s](https://www.pivotaltracker.com/s/projects/%s): [%s](%s)" % (project_name, project_id, story_name, story_url)
def get_beer():
global bar, stock
LED(LED.RED).on()
try:
bar_json = http.get("https://bar.emf.camp/location/Bar.json").raise_for_status().content
stock_json = http.get("https://bar.emf.camp/stock.json").raise_for_status().content
bar = ujson.loads(bar_json)
stock = ujson.loads(stock_json)
except:
print('oh poop')
LED(LED.RED).off()
draw_screen()
def index(cls, field, start_value, end_value=None, **args):
_ensure_indexdb_exists(cls)
indexdb = cls._leveldb_meta["indexdb"]
if end_value is None:
ik = index_key(field, start_value)
v = indexdb.get(ik)
if v is None:
keys = []
else:
keys = json.loads(v)
for k in keys:
v, o = get(cls, k)
yield k, v, o
else:
it = indexdb.iterator(start=index_key(field, start_value),
stop=index_key(field, end_value),
include_stop=True,
include_key=False)
# to avoid awkward scenarios where two index values have the same obj
keys_iterated = set()
for keys in it:
for k in json.loads(keys):
if k not in keys_iterated:
keys_iterated.add(k)
queueLen = redisConn.llen(RIDE_REQUEST)
onlineDriverCount = redisConn.hlen(DRIVER_LOCATION)
if queueLen==0 or onlineDriverCount==0:
continue
requests = []
drivers = []
# get all requests
rideRequest = redisConn.lrange(RIDE_REQUEST, 0, -1)
numOfReq = len(rideRequest)
# remove the received request
redisConn.ltrim(RIDE_REQUEST, numOfReq, -1)
requests = [ ujson.loads(r) for r in rideRequest ]
# get all driver locations
driverLocationDict = redisConn.hgetall(DRIVER_LOCATION)
for (driverId, locationJson) in driverLocationDict.items():
location = ujson.loads( locationJson )
if( isDriverOnline(location) ):
ongoingRideListJson = redisConn.hget(DRIVER_ON_GOING_RIDE, driverId)
if(ongoingRideListJson!=None):
ongoingRideList = ujson.loads(ongoingRideListJson)
else:
ongoingRideList = []
# print(len(ongoingRideList))
driver = {
"userId": driverId,