Пример #1
0
def loadSettings():
    with open('../public/api/v1/data/system/sysinfo.json') as config_file:
        content = config_file.read()
        config = microjson.from_json(content)
        msg_data = {}
        msg_data['name'] = config['name']
        msg_data['location'] = config['location']
        return microjson.to_json(msg_data)
Пример #2
0
def loadSettings():
    with open('config.json') as config_file:
        content = config_file.read()
        config = microjson.from_json(content)
        msg_data = {}
        msg_data['name'] = config['name']
        msg_data['location'] = config['location']
        return microjson.to_json(msg_data)
Пример #3
0
    def parseresponse(self, response):
        # Trim callback
        result = str(response)[len(self.config['callback']) + 1: -1]
        # print result
        try:
            obj = microjson.from_json(result)
        except microjson.JSONError:
            QgsMessageLog.logMessage(
                'Invalid JSON response from server: ' + result, __package__
            )
            # Check if we have an auth error
            if 'User not found' in response or \
                    'User not authenticated' in response:
                title = self.trUtf8(u'Bruger afvist af Kortforsyningen')
                msg = self.trUtf8(u'Manglende eller ukorrekt brugernavn og password til Kortforsyningen.\n\nKortforsyningen svarede:\n')
                QMessageBox.warning( None, title, msg + str(response))
                # Now show settings dialog
                self.show_settings_dialog()
            return None

        if 'status' not in obj:
            QgsMessageLog.logMessage(
                'Unexpected result from server: ' + result, __package__
            )
            return None

        if not obj['status'] == 'OK':
            QgsMessageLog.logMessage(
                'Server reported an error: ' + obj['message'], __package__
            )
            return None

        if not obj.has_key("data"):
            return None
        data = obj['data']
        if not data:
            return [(self.trUtf8("Ingen resultater"),None)]

        # Make tuple with ("text", object) for each result
        return [(e['presentationString'], e) for e in data]
Пример #4
0
    def parseresponse(self, response):
        # Trim callback
        result = str(response)[len(self.config['callback']) + 1:-1]
        # print result
        try:
            obj = microjson.from_json(result)
        except microjson.JSONError:
            QgsMessageLog.logMessage(
                'Invalid JSON response from server: ' + result, __package__)
            # Check if we have an auth error
            if 'User not found' in response or \
                    'User not authenticated' in response:
                title = self.trUtf8(u'Bruger afvist af Kortforsyningen')
                msg = self.trUtf8(
                    u'Manglende eller ukorrekt brugernavn og password til Kortforsyningen.\n\nKortforsyningen svarede:\n'
                )
                QMessageBox.warning(None, title, msg + str(response))
                # Now show settings dialog
                self.show_settings_dialog()
            return None

        if 'status' not in obj:
            QgsMessageLog.logMessage(
                'Unexpected result from server: ' + result, __package__)
            return None

        if not obj['status'] == 'OK':
            QgsMessageLog.logMessage(
                'Server reported an error: ' + obj['message'], __package__)
            return None

        if not obj.has_key("data"):
            return None
        data = obj['data']
        if not data:
            return [(self.trUtf8("Ingen resultater"), None)]

        # Make tuple with ("text", object) for each result
        return [(e['presentationString'], e) for e in data]
Пример #5
0
 def _run_cases(self, cases):
     for js, py in cases:
         r = microjson.from_json(js)
         self.assertEquals(r, py)
Пример #6
0
        Log.info("Sending message: "+message)
        self._socket.send(message+"\n")


    def read(self):
        if self.live:
            # Log.info("reading")
            try:
                msg = self._socket.recv(4096)
            except socket.timeout, e:
                Log.info(e)
            except socket.error, e:
                return
            else:
                Log.info("Received: "+msg)
                data = microjson.from_json(msg)
                evt = data["evt"]
                if evt in self._callbacks:
                    self._callbacks[evt](data["data"])
                else:
                    Log.info("No supe que hacer con "+evt)

    def _start_socket(self, port):
        self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._socket.connect(('', port))
        self._socket.setblocking(0)

        self.live = True;
        Log.info("Server started")

Пример #7
0
 def _run_cases(self, cases):
     for js, py in cases:
         r = microjson.from_json(js)
         self.assertEqual(r, py)
Пример #8
0
 def _run_cases(self, cases):
     for js, py in cases:
         r = microjson.from_json(js)
Пример #9
0
	print "Compiled to:", bytes
	print "Executing"

	vm.Memory.write(bytes)

	j = time.time()
	vm.Cpu.run()
	clvmDecodeTime = time.time() - j

	if tryUjson:
		j = time.time()
		ujson.loads(asuson)
		usonDecodeTime = time.time() - j

	j = time.time()
	microjson.from_json(asjson)
	jsonDecodeTime = time.time() - j

	print "Registers", vm.Cpu.Registers
	print "Stack", vm.Memory.Stack

	print vm.Cpu.Registers[0]

	if tryUjson:
		print "UJSON"
		print asuson

	print "JSON"
	print asjson

Пример #10
0
import microjson
import induce

myfile = induce.slurparg()
with induce.Tracer(myfile):
    microjson.from_json(myfile)