How to use the jsonlib.write function in jsonlib

To help you get started, we’ve selected a few jsonlib 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 tkopczuk / ATP_Performance_Test / ATP_Performance_Test / askthepony / __init__.py View on Github external
def sendOutIfFull():
        if MeasureIt.queue.qsize() < 1 or not UDP_IP:
            return
        with MeasureIt.lock:
            if MeasureIt.to_be_sent is None:
                MeasureIt.to_be_sent = "[ "
            try:
                while True:
                    item = MeasureIt.queue.get_nowait()
                    item_json = jsonlib.write(item)
                    if len(MeasureIt.to_be_sent) + len(item_json) + 2 > MAX_FRAME and len(MeasureIt.to_be_sent) > 2:
                      #  print "Sending..."
                        MeasureIt.to_be_sent = "%s%s" %(MeasureIt.to_be_sent[:-1], ",\"%s\",%.2f ]" % (API_KEY, time.time()))
                        sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) 
                        sock.sendto( zlib.compress(MeasureIt.to_be_sent), (UDP_IP, UDP_PORT) )
                     #   print "sent", MeasureIt.to_be_sent
                        #print len(zlib.compress(MeasureIt.to_be_sent))
                        MeasureIt.to_be_sent = "[ %s," % (item_json,)
                    else:
                        MeasureIt.to_be_sent =  "%s%s," %(MeasureIt.to_be_sent, item_json)
               #     print MeasureIt.to_be_sent
                    MeasureIt.queue.task_done()
            except:
                import sys
                print sys.exc_info()
                pass
github turian / common / json.py View on Github external
o = {k: obj[k]}
        # TODO: Make sure that dumps returns only one line?
        f.write(dumps(o) + "\n")

        if i % 1000000 == 0:
            print >> sys.stderr, "\t...dumponeperline wrote %s lines..." % percent(i, len(obj))
            print >> sys.stderr, "\t%s" % stats()
    if verbose:
        print >> sys.stderr, "...dumponeperline(%s)" % f
        print >> sys.stderr, stats()


try:
    import jsonlib
    def fastloads(str): return jsonlib.read(str, use_float=True)
    fastdumps = jsonlib.write
    def fastloadfile(filename): return jsonlib.read(myopen(filename).read(), use_float=True)
    def fastload(file): return jsonlib.read(file.read(), use_float=True)
except:
    pass

jsonlib

JSON serializer/deserializer for Python

GPL-3.0
Latest version published 15 years ago

Package Health Score

43 / 100
Full package analysis

Similar packages