def process_message(self, message, sock): logging.info('Received %s', message['data']) try: obj = util.parse(message['data']) except: logging.error('Message parsing failed') return # Convert serialized ref objects to callable references serializer.unserialize(self.bridge, obj['args']) # Extract RPC destination address destination = obj.get('destination', None) if not destination: logging.warning('No destination in message %s', obj) return if 'source' in message: self.bridge._context = client.Client(message['source']) self.bridge._execute(destination['ref'], obj['args'])
def redirector(self): client = HTTPClient() try: res = client.fetch('%s/redirect/%s' % ( self.options['redirector'], self.options['api_key'] )) except: logging.error('Unable to contact redirector') client.close() return try: body = util.parse(res.body).get('data') except: logging.error('Unable to parse redirector response %s', res.body) return if not ('bridge_port' in body and 'bridge_host' in body): logging.error('Could not find host and port in JSON body') else: self.options['host'] = body.get('bridge_host') self.options['port'] = int(body.get('bridge_port')) self.establish_connection() client.close()
def redirector(self): client = HTTPClient() try: res = client.fetch( '%s/redirect/%s' % (self.options['redirector'], self.options['api_key'])) except: logging.error('Unable to contact redirector') client.close() return try: body = util.parse(res.body).get('data') except: logging.error('Unable to parse redirector response %s', res.body) return if not ('bridge_port' in body and 'bridge_host' in body): logging.error('Could not find host and port in JSON body') else: self.options['host'] = body.get('bridge_host') self.options['port'] = int(body.get('bridge_port')) self.establish_connection() client.close()
def test_stringify_and_parse(self): data = {'a': 1, 'b': 'test code', 'c': {}, 'd': [1,False,None,'asdf',{'a': 1, 'b': 2}]} self.assertEqual(util.parse(util.stringify(data)), data)