async def run(loop): c = asyncmrws.Client() await c.connect(io_loop=loop, servers=[("127.0.0.1", 7100)]) # Test fetch if 0: print(mrpacker.unpack(await c.get(0, mrpacker.pack([1, 2, 3])))) # Push some work if 1: msg = mrpacker.pack([22] * 100) while 1: await c.push(0, msg, len(msg)) await asyncio.sleep(1) await c.close()
async def run(loop): c = asyncmrws.Client() #await c.connect(io_loop=loop,servers=[("127.0.0.1",7100),("127.0.0.1",7002)]) await c.connect(io_loop=loop, servers=[("127.0.0.1", 7100)]) #sc = ssl.create_default_context(ssl.Purpose.SERVER_AUTH) #sc.load_verify_locations('cert/server.crt') #await c.connect(io_loop=loop,servers=[("127.0.0.1",7100)],ssl=sc) if 1: await c.set(0, mrpacker.pack(["key", "val"])) await asyncio.sleep(0.5, loop=loop) await c.close() exit() #await c.push( 0, 0, m, l ) #await asyncio.sleep(0.5, loop=loop) #await c.close() #return if 0: print(mrpacker.unpack(await c.get(0, mrpacker.pack([1, 2, 3])))) if 0: l = [] l.append(c.get(0, mrpacker.pack([1, 2, 3]))) l.append(c.get(0, mrpacker.pack([1, 2, 3, 4]))) l.append(c.get(0, mrpacker.pack([5]))) print(await asyncio.gather(*l)) for x in range(100): m = mrpacker.pack(x) l = len(m) if await c.push(x, m, l): print(x, "droppped") else: print(x) await asyncio.sleep(0.5, loop=loop) await asyncio.sleep(0.5, loop=loop) #msgs = await c.pull( 0, 0 ) #print(msgs) await c.close()
def parsepacker(r): o = mrpacker.unpack(r.body) return o["name"]
def set_usermrp(self, j): try: self.user = mrpacker.unpack(j) except: pass
{ "A": [{}, [], {}], "b": { "1": 1, "2": 2, "3": 3 } }, ] o = {} for x in range(100000): o[x] = x objs.append(o) # NaN != Nan so check str rep o = j.unpack(j.pack(float('nan'))) eq(str(o), 'nan') for o in objs: try: eq(o, j.unpack(j.pack(o))) except Exception as e: print("ERROR", str(e), o) from os import walk for (dirpath, dirnames, filenames) in walk("test_data"): for fn in filenames: f = open("test_data/" + fn, "rb") o = json.load(f) try: eq(o, j.unpack(j.pack(o)))