Esempio n. 1
0
 def assertMessageEqual(self, message_text, expected,
                        retrieve_url_titles=True):
     """
     Parse message string and compare to expected result.
     """
     parsed = message.parse(message_text, retrieve_url_titles)
     self.assertMessageDictsEqual(parsed, expected)
Esempio n. 2
0
	def process_line(self,line):
		"""
		Processes a new line of data received from the TCC
		"""
		if not line.strip(): # ignore blank lines
			return (None,None,None)
		try:
			(mystery_num,user_num,status,keywords) = message.parse(line)
			print '%2d %10s %s' % (user_num,status,keywords)
			if status == 'Done' and 'Cmd' in keywords:
				logging.info('user %d issued %s',user_num,keywords['Cmd'][0])
			elif 'UserAdded' in keywords:
				logging.warn('connected new user number %d' % user_num)

			# update records based on this message
			'''
			if 'AzStat' in keywords:
				try:
					(pos,vel,tai,stat) = keywords['AzStat']
					print (pos,vel,tai,stat)
					archiving.update(self.timestamp(tai),'AzStat',{
						'pos': float(pos),
						'vel': float(vel),
						'stat': int(stat,16)
					})
				except ValueError:
					logging.warn('unable to parse AzStat values: %r',keywords['AzStat'])
			'''

			return (user_num,status,keywords)
		except message.MessageError,e:
			logging.warn('unable to parse line >>%r<<',line)
			return (None,None,None)
Esempio n. 3
0
def router():
    isForm = False;
    isUpload = False;
    if request.method != 'POST':
        response_content = json.dumps({'router':request.method})
    else:
        if request.json is not None:
            content_type = 'text/javascript'
            data = request.json   
        elif request.form.has_key('extAction'):
            isForm = True;
            isUpload = request.form['extUpload'] == 'true';
            # data = BogusAction();
            # data.action = request.form['extAction'];
            # data.method = request.form['extMethod'];
            # data.tid = request.form['extTID'] if request.form.has_key('extTID') else None # not set for upload
            # data.data = [request.form, request.files]
        else:
            raise Exception('Invalid request.')
        local_response = None;
        if type(data) is list:
            local_response = []
            for item in data:
                msg = message.parse(item)
                local_response.append(something(msg))   
        else:
            local_response = something(data)
        if isForm and isUpload:
            response_content = '<html><body><textarea>' 
            response_content += json.dumps(local_response)
            response_content += '</textarea></body></html>'
        else:
            response_content = json.dumps(local_response)
        
    return current_app.response_class(response_content, mimetype='application/json')
Esempio n. 4
0
	def send(self, params='', quiet=False):
		if not params:
			if not quiet: print "send: %s" % self.language["Specify message to send"]
		else:
			self.bot.connection.send(params+'\r\n')
			try:
				self.bot.lastMessage = message.parse('%s!%s@%s %s' % (self.bot.configuration['nick'], self.bot.configuration['username'], self.bot.configuration['hostname'], params))
			except:
				pass
Esempio n. 5
0
def something(cdata):
    if type(cdata) is not DirectRequest:
        # log deprecated call (we shouldn't be parsing here)
        # this creates a Message from cdata
        msg = message.parse(cdata)
    else:
        msg = cdata

    delegate = action.create_from(msg, cdata)

    return make_response(cdata, delegate(cdata))
Esempio n. 6
0
def something(cdata):
    if type(cdata) is not DirectRequest:
        # log deprecated call (we shouldn't be parsing here)
        # this creates a Message from cdata
        msg = message.parse(cdata)
    else:
        msg = cdata
    
    delegate = action.create_from(msg, cdata)
    
    return make_response(cdata, delegate(cdata))
Esempio n. 7
0
 def rcv(self):
     raw = b''
     while len(raw) < 4:
         raw += self.sock.recv(4)
     length = 28 if raw == b'P2PF' else int.from_bytes(raw, 'big')
     while len(raw) < 4 + length:
         raw += self.sock.recv(length)
     msg = message.parse(raw)
     print(
         f'Peer {self.peer.peer_id} received {msg.get_type()} from Peer {self.other_peer_id}'
     )
     return msg
Esempio n. 8
0
    def on_receive(self, message):
        message = parse(message)
        print('DownloadActor Received ' + message.get_event_name() + ' ' +
              message.get_message())

        if message.get_event_name() == 'download':
            url = message.get_message()
            file_name = download_file(url)
            unzip(file_name)
            os.remove('./' + file_name)
            return file_name

        return True
Esempio n. 9
0
    def on_receive(self, message):
        message = parse(message)
        print('Received ' + message.get_event_name() + ' ' +
              message.get_message())

        if message.get_event_name() == 'close':
            return self.kill_processes()

        if message.get_event_name() == 'reasoned':
            c = message.get_message()

            for process in self.__processes:
                p = process.stdin.write((c + '\n').encode())

        return True
Esempio n. 10
0
 def work(self):
     """ Start main loop.
     Listen for incoming messages and resend them to subscribers.
     
     """
     print 'Starting work'
     while not self.stopped():
         try:
             socks = dict(self.poller.poll(5))
             if socks.get(self.message_recv_socket) == zmq.POLLIN:
                 # received message from client
                 address = self.message_recv_socket.recv()
                 _ = self.message_recv_socket.recv()
                 msg = self.message_recv_socket.recv()            
                 try:
                     msg = message.parse(msg)
                     if self.verbose:
                         print 'Got message: %s' % str(msg)
                 except:
                     print 'ERROR: Could not parse message: %s' % str(msg)
                     continue
                 if msg['name'] == 'ack':
                     # message is ack for previous sent message, checksum for ack:ed message is in payload
                     try:
                         if self.verbose:
                             print 'Got ack for message: %s' % msg['payload']
                         self.msg_collection.pop(msg['payload'])
                         if self.persist_file:
                             self._flush_saved_messages()
                     except KeyError:
                         pass
                 if int(msg['ack']) > 0:
                     # save message and make sure server receive ack
                     if self.verbose:
                         print 'Delivery of message with ack: %s' % msg['checksum']
                     self.msg_collection[msg['checksum']] = (time.time(), msg)
                     if self.persist_file:
                         self._flush_saved_messages()
                 self.message_recv_socket.send(address, zmq.SNDMORE)
                 self.message_recv_socket.send('', zmq.SNDMORE)
                 self.message_recv_socket.send('OK')
                 if msg['name'] == 'ping':
                     continue
                 self.message_socket_pub.send(msg.serialize())
         except zmq.ZMQError:
             self.connect()
     self._close_sockets()
     print 'Exiting work'
Esempio n. 11
0
	def send_msgs(self, msgs):
		"""Sends on or more messages to the IRC server.

		This method gets as a parameter list of messages (list of strings)
		or just one message (string).

		Important! See also send() method description!
		"""
		if type(msgs) == str:
			msgs = [msgs]
		for msg in msgs:
			self.send(msg)
			msg = ':%s!%s@%s %s' % (self.bot.configuration['nick'],
						self.bot.configuration['username'],
						self.bot.configuration['hostname'],
						msg.rstrip('\r\n'))
			self.bot.currentMessage = message.parse(msg)
Esempio n. 12
0
 def run(self):
     """ Main loop.
     Listens for incoming messages.
     
     """
     while not self.stopped():
         socks = dict(self.msg_poller.poll(2000))
         if socks.get(self.msg_sub_socket) == zmq.POLLIN:
             msg = self.msg_sub_socket.recv()
             try:
                 msg = message.parse(msg)
             except Exception, e:
                 raise MezzengerException('Could not parse message: %s, %s' % (str(msg), e))
             if msg['name'] in self.msg_map:
                 if self.verbose:
                     print 'Got message: %s' % str(msg)
                 self.msg_map[msg['name']](msg['payload'], msg)
                 if msg['ack'] > 0:
                     # send back ack to server
                     if self.verbose:
                         print 'Ack-ing message: %s' % msg['checksum']
                     self.send_message('ack', msg['checksum'])
Esempio n. 13
0
File: bot.py Progetto: barteqx/Yaib
	def run(self):
		while self.working:
			time.sleep(0.01)
			try:
				self.currentMessage = self.bot.connection.receive()
				for element in self.currentMessage:
					self.bot.currentMessage = message.parse(element)
					for elem in self.bot.connection.channels.values():
						elem.getMessage(self.bot.currentMessage)
					self.bot.messagesMgmt.manage(self.bot.currentMessage)
					self.bot.console.pluginApi.getMessage(self.bot.currentMessage)

					if self.writing == True:
						try:
							print "%s: %s: %s" % (self.bot.currentMessage['hostname'], self.bot.currentMessage['msgtype'], self.bot.currentMessage['params'])
						except:
							print "%s: %s" % (self.bot.currentMessage['msgtype'], self.bot.currentMessage['params'])
					if self.bot.currentMessage['msgtype'] in ('372', 'ERROR'):
						self.writing = False

			except (connection.NotConnectedToServerError, connection.IRCConnectionError):
				pass
			self.bot.lastMessage = self.bot.currentMessage
Esempio n. 14
0
 def onData(self, data):
     """解包json-streaming"""
     msg = message.parse(data)
     if not msg:
         return
     self.onMessage(msg)
Esempio n. 15
0
# meddelanden per person (respektive)
# meddelanden per datum (inte snitt) + plot

DBCONF = {
    "host":
    "localhost",
    "user": "******",
    "db": "FBMSG",
    "use_unicode": True,
    "charset": "utf8",
}

if __name__ == '__main__':
    filename = sys.argv[1]
    print("Parsing message file %s..." % filename)
    threads = message.parse(filename)
    print("Message file parsed, begin database upload.")

    with MySQLdb.connect(**DBCONF) as cursor:
        for thread in threads:
            # Add thread to database:
            cursor.execute(
                u"""
                INSERT IGNORE INTO thread (title)
                VALUES (%s)
                """, [thread.name])

            thread_id = cursor.lastrowid

            if thread_id == 0:
                cursor.execute("""