How to use the simplejson.JSONDecoder function in simplejson

To help you get started, we’ve selected a few simplejson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wallnerryan / floodlight-qos-beta / apps / qos / qospath.py View on Github external
print "Trying to delete QoSPath %s" % name
	# circuitpusher --controller {IP:REST_PORT} --delete --name {CIRCUIT_NAME}
	try:
		print "Deleting circuit"
		cmd = "./circuitpusher.py --controller %s:%s --delete --name %s" % (c_ip,port,name)
		subprocess.Popen(cmd,shell=True).wait()
	except Exception as e:
		print "Error deleting circuit, Error: %s" % str(e)
		exit()
	
	qos_s = os.popen("./qosmanager.py list policies %s %s" %(c_ip,port)).read()
	qos_s = qos_s[qos_s.find("[",qos_s.find("[")+1):qos_s.rfind("]")+1]
	#print qos_s
	data = simplejson.loads(qos_s)
	sjson = simplejson.JSONEncoder(sort_keys=False,indent=3).encode(data)
	jsond = simplejson.JSONDecoder().decode(sjson)
	#find policies that start with "."
	l = len(jsond)
	for i in range(l):
		n = jsond[i]['name']
		if name in n:
			pol_id =  jsond[i]['policyid']
			try:
				cmd = "./qosmanager.py delete policy '{\"policy-id\":\"%s\"}' %s %s " % (pol_id,c_ip,port)
				print cmd
				subprocess.Popen(cmd,shell=True).wait() 
			except Exception as e:
				print "Could not delete policy in path: %s" % str(e)
github OpenSextant / Xponents / Examples / XTax / lib / pysolr.py View on Github external
def __init__(self, url, decoder=None, timeout=60):
        self.decoder = decoder or json.JSONDecoder()
        self.url = url
        self.scheme, netloc, path, query, fragment = urlsplit(url)
        self.base_url = urlunsplit((self.scheme, netloc, '', '', ''))
        netloc = netloc.split(':')
        self.host = netloc[0]
        if len(netloc) == 1:
            self.host, self.port = netloc[0], None
        else:
            self.host, self.port = netloc[0], int(netloc[1])
        self.path = path.rstrip('/')
        self.timeout = timeout
        self.log = self._get_log()
github alerta / alerta / contrib / experimental / alert-receiver.py View on Github external
ADDR = (HOST, PORT)
                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.connect((ADDR))
                sock.append(s)
                logging.info('Connecting to %s port %s' % (HOST, PORT))
                break
            except socket.error, e:
                if e.errno == errno.ECONNREFUSED :
                    logging.error('Server %s is not ready. Retrying later in 20 seconds.' % HOST)
                    time.sleep(20)
                    continue
                else:
                    logging.error('Connection error to %s port %s' % (HOST, PORT))
                    sys.exit(2)

class ConcatJSONDecoder(json.JSONDecoder):

    FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
    WHITESPACE = re.compile(r'[ \t\n\r]*', FLAGS)

    def decode(self, s, _w=WHITESPACE.match):
        s_len = len(s)

        objs = []
        end = 0
        while end != s_len:
            obj, end = self.raw_decode(s, idx=_w(s, end).end())
            end = _w(s, end).end()
            objs.append(obj)
        return objs

def main():
github turbulenz / turbulenz_local / turbulenz_local / controllers / apiv1 / store.py View on Github external
from turbulenz_local.lib.validation import ValidationException
from turbulenz_local.lib.servicestatus import ServiceStatus
from turbulenz_local.lib.money import get_currency_meta
from turbulenz_local.decorators import jsonify, postonly, secure_post

from turbulenz_local.controllers import BaseController

from turbulenz_local.models.gamesessionlist import GameSessionList
from turbulenz_local.models.apiv1.store import StoreList, StoreError, StoreUnsupported, \
                                                   Transaction, ConsumeTransaction, UserTransactionsList

from turbulenz_local.models.gamelist import get_game_by_slug
from turbulenz_local.models.userlist import get_current_user

# pylint: disable=C0103
_json_decoder = JSONDecoder(encoding='utf-8')
# pylint: enable=C0103


class StoreController(BaseController):
    """ StoreController consists of all the store methods
    """

    store_service = ServiceStatus.check_status_decorator('store')
    game_session_list = GameSessionList.get_instance()

    @classmethod
    @store_service
    @jsonify
    def get_currency_meta(cls):
        return {'ok': True, 'data': get_currency_meta()}
github Fogapod / VKBot / vk / utils.py View on Github external
def json_iter_parse(response_text):
    decoder = json.JSONDecoder(strict=False)
    idx = 0
    while idx < len(response_text):
        obj, idx = decoder.raw_decode(response_text, idx)
        yield obj
github DataDog / dd-agent / checks.d / riakcs.py View on Github external
    @classmethod
    def load_json(cls, text):
        return json.JSONDecoder(object_pairs_hook=multidict).decode(text)
github sickill / rubytime-plasmoid / contents / code / main.py View on Github external
def fetchActivitiesResult(self, job):
    success = self.processResult(job)
    if not success: return
    if job.isErrorPage():
      self.showError("Error while fetching activities.")
      return
    activitiesData = simplejson.JSONDecoder().decode(str(job.data()))
    self.updateActivities(activitiesData)
github buu700 / Site / make.py View on Github external
def decode(str):
	return json.JSONDecoder().decode(curl(str))
github OpenTreeMap / otm-legacy / treemap / views.py View on Github external
def clean_diff(jsonstr):
    #print jsonstr
    diff = simplejson.JSONDecoder().decode(jsonstr)
    diff_no_old = {}
    for key in diff:
        if not key.startswith('old_'):
            diff_no_old[key] = diff[key]
    return diff_no_old
github OpenMTC / OpenMTC / common / openmtc-onem2m / src / openmtc_onem2m / client / mqtt.py View on Github external
parsed_url = urlparse(m2m_ep)
        self._default_target_id = parsed_url.fragment

        def _default(x):
            if isinstance(x, datetime):
                try:
                    isoformat = x.isoformat
                except AttributeError:
                    raise TypeError("%s (%s)" % (x, type(x)))

                return isoformat()
            else:
                return x

        self._encode = JSONEncoder(default=_default).encode
        self._decode = JSONDecoder().decode

        self._handle_request_func = handle_request_func

        self._processed_request_ids = deque([], maxlen=200)
        self._request_promises = LRUCache(threadsafe=False, max_items=200)

        if client_id is None:
            import random
            import string
            client_id = ''.join(random.sample(string.letters, 16))
        else:
            client_id = self._get_client_id_from_originator(client_id)

        self._client = mqtt.Client(
            clean_session=False,
            client_id='::'.join([