当前位置: 首页>>代码示例>>Python>>正文


Python tnetstring.dumps函数代码示例

本文整理汇总了Python中tnetstring.dumps函数的典型用法代码示例。如果您正苦于以下问题:Python dumps函数的具体用法?Python dumps怎么用?Python dumps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dumps函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: thrash_tnetstring

def thrash_tnetstring():
    for obj, tns, json, msh in TESTS:
        if TEST_DUMP_ONLY:
            tnetstring.dumps(obj)
        elif TEST_LOAD_ONLY:
            assert tnetstring.loads(tns) == obj
        else:
            assert tnetstring.loads(tnetstring.dumps(obj)) == obj
开发者ID:carlopires,项目名称:tnetstring3,代码行数:8,代码来源:shootout.py

示例2: _send_to_zmq

	def _send_to_zmq(self, content, channel):
		self._lock.acquire()
		if self._push_sock:
			content[_ensure_utf8('channel')] = channel
			self._push_sock.send(tnetstring.dumps(content))
		else:
			self._pub_controller.publish(channel,
					tnetstring.dumps(content))
		self._lock.release()
开发者ID:fanout,项目名称:pypubcontrol,代码行数:9,代码来源:zmqpubcontrolclient.py

示例3: test_unicode_handling

 def test_unicode_handling(self):
     self.assertRaises(ValueError,tnetstring.dumps,u"hello")
     self.assertEquals(tnetstring.dumps(u"hello","utf8"),"5:hello,")
     self.assertEquals(type(tnetstring.loads("5:hello,")),str)
     self.assertEquals(type(tnetstring.loads("5:hello,","utf8")),unicode)
     ALPHA = u"\N{GREEK CAPITAL LETTER ALPHA}lpha"
     self.assertEquals(tnetstring.dumps(ALPHA,"utf8"),"6:"+ALPHA.encode("utf8")+",")
     self.assertEquals(tnetstring.dumps(ALPHA,"utf16"),"12:"+ALPHA.encode("utf16")+",")
     self.assertEquals(tnetstring.loads("12:\xff\xfe\x91\x03l\x00p\x00h\x00a\x00,","utf16"),ALPHA)
开发者ID:jannic,项目名称:tnetstring,代码行数:9,代码来源:test_format.py

示例4: __init__

 def __init__ (self, sip_comm, sip_data, rtp_flow):
     for uuid, cnt in sip_comm.iteritems ():
         path = "%s/%s/"%(main_path, uuid)
         print 'Dumping SIP uuid:\'%s\' (%d packets) in %s'%(uuid, cnt, path)
         dialog, arr = sip_data [uuid]
         i = 0
         filearr = []
         try:
             os.makedirs (path)
         except OSError, e:
             # directory might already exist
             pass
         listpath = "%s/list.txt"%path
         listfd = open (listpath, "w+")
         listfd.write (
             "# This file contains the listing of %d's dumped packets\n"%cnt)
         listfd_legs = []
         for timestamp, addr, pkt, legs_n in arr:
             if not listfd_legs:
                 timestamppath = "%s/timestamp.txt"%path
                 timestampfd = open (timestamppath, "w+")
                 timestampfd.write (str (timestamp))
                 timestampfd.close ()
                 
             if legs_n in listfd_legs:
                 continue
             listfd_legs += [legs_n]
             src, dst = (addr [0], addr [1]), (addr [2], addr [3])
             listfd.write ("# legs_%d from %s to %s\n"%(legs_n,
                                                      str (src),
                                                      str (dst)))
         for timestamp, addr, pkt, legs_n in arr:
             src, dst = (addr [0], addr [1]), (addr [2], addr [3])
             dirpath = "%s/legs_%d"%(path, legs_n)
             filename = "%d.txt"%i
             filepath = "%s/%s"%(dirpath, filename)
             filearr += [tnetstring.dumps ([filepath, timestamp, 
                                            list (addr)])]
             listfd.write ("legs_%d/%d.txt\n"%(legs_n, i))
             try:
                 os.makedirs (dirpath)
             except OSError, e:
                 # directory might already exist
                 pass
             fd = open (filepath, "w+")
             fd.write (tnetstring.dumps ([timestamp, list (addr), str (pkt)],
                                         'iso-8859-15'))
             fd.close ()
             i += 1
开发者ID:sipdbg,项目名称:sipdbg,代码行数:49,代码来源:dumpinterface.py

示例5: _respond_error

	def _respond_error(self, condition):
		resp = dict()
		if self.req_id:
			resp['id'] = self.req_id
		resp['success'] = False
		resp['condition'] = ensure_utf8(condition)
		self.rep_sock.send(tnetstring.dumps(resp))
开发者ID:fanout,项目名称:scaledemo,代码行数:7,代码来源:rpc.py

示例6: server_rtp_create

 def server_rtp_create (_redis, ckey, s_id, port, bind_ip, rr):
     _redis.lpush (redis_server_inst%rr,
                   tnetstring.dumps (["CREATE_RTP_SOCK",
                                      [s_id,
                                       bind_ip, port], ckey],
                                     'iso-8859-15'))
     return
开发者ID:sipdbg,项目名称:sipdbg,代码行数:7,代码来源:RedisHelper.py

示例7: _respond

	def _respond(self, value):
		resp = dict()
		if self.req_id:
			resp['id'] = self.req_id
		resp['success'] = True
		resp['value'] = ensure_utf8(value)
		self.rep_sock.send(tnetstring.dumps(resp))
开发者ID:fanout,项目名称:scaledemo,代码行数:7,代码来源:rpc.py

示例8: publish

	def publish(self, channel, id, prev_id, rheaders=None, rbody=None, sbody=None, code=None, reason=None):
		self.lock.acquire()

		if self.pubs is None:
			self.pubs = list()
			for p in self.proxies:
				pub = gripcontrol.GripPubControl(p['control_uri'])
				if 'control_iss' in p:
					pub.set_auth_jwt({'iss': p['control_iss']}, p['key'])
				self.pubs.append(pub)

		formats = list()
		if rbody is not None:
			formats.append(gripcontrol.HttpResponseFormat(code=code, reason=reason, headers=rheaders, body=rbody))
		if sbody is not None:
			formats.append(gripcontrol.HttpStreamFormat(sbody))

		item = pubcontrol.Item(formats, id, prev_id)

		zitem = item.export()
		zitem['channel'] = channel
		zitem['http-response'] = convert_json_transport(zitem['http-response'])
		self.sock.send(tnetstring.dumps(zitem))

		for pub in self.pubs:
			pub.publish_async(channel, item)

		self.lock.release()
开发者ID:fanout,项目名称:scaledemo,代码行数:28,代码来源:grip.py

示例9: server_sip_create

 def server_sip_create (_redis, ckey, s_id, bind_ip, port, rr, transport):
     _redis.lpush (redis_server_inst%rr,
                   tnetstring.dumps (["CREATE_SIP%s_SOCK"%transport,
                                      [s_id,
                                       bind_ip, port], ckey],
                                     'iso-8859-15'))
     return
开发者ID:sipdbg,项目名称:sipdbg,代码行数:7,代码来源:RedisHelper.py

示例10: _send_to_zmq

	def _send_to_zmq(self, channel, item):
		self._lock.acquire()
		if self._zmq_pub_controller:
			channel = _ensure_utf8(channel)
			content = item.export(True, True)
			self._zmq_pub_controller.publish(channel,
					tnetstring.dumps(content))
		self._lock.release()
开发者ID:fanout,项目名称:pypubcontrol,代码行数:8,代码来源:pubcontrol.py

示例11: test_send_to_zmq

	def test_send_to_zmq(self):
		client = ZmqPubControlClientTestClass2('uri')
		client._push_sock = ZmqSocketTestClass()
		client._send_to_zmq({'content'.encode('utf-8'):
				'content'.encode('utf-8')}, 'chan'.encode('utf-8'))
		self.assertEqual(client._push_sock.send_data, tnetstring.dumps(
				{'content'.encode('utf-8'): 'content'.encode('utf-8'),
				'channel'.encode('utf-8'): 'chan'.encode('utf-8')}))
		client = ZmqPubControlClientTestClass2('uri')
		client._pub_controller = ZmqPubControllerTestClass()
		client._send_to_zmq({'content'.encode('utf-8'):
				'content'.encode('utf-8')}, 'chan'.encode('utf-8'))
		self.assertEqual(client._pub_controller.publish_channel,
				'chan'.encode('utf-8'))
		self.assertEqual(client._pub_controller.publish_content,
				tnetstring.dumps({'content'.encode('utf-8'):
				'content'.encode('utf-8')}))
开发者ID:fanout,项目名称:pypubcontrol,代码行数:17,代码来源:zmqpubcontrolclient_tests.py

示例12: add_test

def add_test(v):
    #  These modules have a few round-tripping problems...
    try:
        assert cjson.decode(cjson.encode(v)) == v
        assert yajl.loads(yajl.dumps(v)) == v
    except Exception:
        pass
    else:
        TESTS.append((v,tnetstring.dumps(v),cjson.encode(v)))
开发者ID:Tordek,项目名称:tnetstring,代码行数:9,代码来源:shootout.py

示例13: makePickle

 def makePickle(self, record):
     """ Create message in TNetStrings format.
     """
     msg = {}
     self.format(record) # render 'message' attribute and others
     for k in self.send_fields:
         msg[k] = record.__dict__[k]
     tnetstr = tnetstrings.dumps(msg)
     return tnetstr
开发者ID:cesterlizi,项目名称:skytools,代码行数:9,代码来源:skylog.py

示例14: call

	def call(self, method, args=dict()):
		req = dict()
		req['id'] = str(uuid.uuid4())
		req['method'] = ensure_utf8(method)
		req['args'] = ensure_utf8(args)
		req_raw = tnetstring.dumps(req)
		try:
			if not self.sock.poll(30000, zmq.POLLOUT):
				raise CallError('send-timeout')
			m_list = list()
			m_list.append('')
			m_list.append(req_raw)
			self.sock.send_multipart(m_list)
		except zmq.ZMQError as e:
			raise CallError('send-failed', e.message)
		start = int(time.clock() * 1000)
		while True:
			elapsed = max(int(time.clock() * 1000) - start, 0)
			try:
				if not self.sock.poll(max(30000 - elapsed, 0), zmq.POLLIN):
					raise CallError('receive-timeout')
				m_list = self.sock.recv_multipart()
			except zmq.ZMQError as e:
				raise CallError('receive-failed', e.message)
			if len(m_list) != 2:
				print "response has wrong number of parts, skipping"
				continue
			if len(m_list[0]) > 0:
				print "response first part is not empty, skipping"
				continue
			resp_raw = m_list[1]
			try:
				resp = tnetstring.loads(resp_raw)
			except:
				print "failed to parse response as tnetstring, skipping"
				continue
			if 'id' not in resp:
				print "response missing id field, skipping"
				continue
			if resp['id'] != req['id']:
				print "unexpected response id, skipping"
				continue
			break
		if 'success' not in resp:
			raise CallError('invalid-response', 'missing success field')
		if resp['success']:
			if 'value' not in resp:
				raise CallError('invalid-response', 'missing value field')
			return resp['value']
		else:
			if 'condition' not in resp:
				raise CallError('invalid-response', 'missing condition field')
			raise CallError(resp['condition'])
开发者ID:fanout,项目名称:scaledemo,代码行数:53,代码来源:rpc.py

示例15: keepalive_worker

def keepalive_worker():
	lock.acquire()
	for id, s in sessions.iteritems():
		resp = dict()
		resp['from'] = client_id
		resp['id'] = id
		resp['seq'] = s.out_seq
		s.out_seq += 1
		resp['type'] = 'credit'
		resp['credits'] = 0

		print 'OUT %s' % resp
		out_sock.send(s.to_address + ' T' + tnetstring.dumps(resp))
	lock.release()
开发者ID:fanout,项目名称:pushpin,代码行数:14,代码来源:keephandler.py


注:本文中的tnetstring.dumps函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。