def __init__(self, decoded=None, encoded=None): """for the Yamaha we only use the machine form, its readability is acceptable""" encoded = encoded or decoded decoded = None Message.__init__(self, decoded, encoded) self.isQuestion = self.value() == '?'
def test_message_expires(self): new = Message('abc') new.save('123') cache.clear() new = Message('abc') eq_(new.get(), None)
def loop(self): while 1: self.buffer += self.irc.recv(4096) temp_buffer = self.buffer.split("\n") self.buffer = temp_buffer.pop() for line in temp_buffer: responses = [] # Stubbing out functionality for custom functions. Eventually the big block below will be gone. for function in flatten(self.functions): try: responses.append(function(self, line)) except IndexError: # I put this in here just to be safe. (Dirk) pass # Standard control library try: message = Message(line) except IndexError: pass line = line.strip().split() if line[0] == "PING": self.irc.send("PONG %s\r\n" % line[1]) else: try: # Disconnect functionality (revisited) command = message.command(self.command) if command.__str__() == 'disconnect': if not message.argv(self.command) == self.password: if message.is_public(): koomar.send_message('Incorrect password.') else: koomar.send_private_message("Dear %s, you gave an invalid password." % message.sender, message.sender) else: koomar.send_message('Correct password. Disconnecting...') self.disconnect() return if line[3] == ":%s" % (self.command): if len(line) <= 4: self.send_message("Type `%s quote`" % (self.command)) else: pass #if line[4] == "disconnect": # if line[5] == self.password: # self.disconnect() # return # else: # if not line[2].startswith('#'): # matches = re.match(':([A-Za-z0-9_-]+)!', line[0]) # sender = matches.groups()[0] # self.send_private_message("Dear %s, you gave an invalid password." % sender, sender) # else: # self.send_message("Invalid password.") #if not responses.__contains__(True): #self.send_message("I don't know that command!") except IndexError: pass # Each line may not be a conversation
def quote_parser(koomar, line): message = Message(line) command = message.command(koomar.command) if command == 'quote': rand = random.randint(0, len(quotes)-1) quote = quotes[rand] if message.is_public(): koomar.send_message("\"%s\"" % quote) else: koomar.send_private_message("\"%s\"" % quote, message.sender) return True
def help_parser(koomar, line): message = Message(line) command = message.command(koomar.command) help = \ """Koomar is a currently in development IRC bot. Type in 'koomar quote' to get a random Futurama quote.""" if command == 'help': if message.is_public(): for line in help.split('\n'): koomar.send_message(line) else: for line in help.split('\n'): koomar.send_private_message(line, message.sender) return True
def answerMatches(self, answer): """does the answer match this message?""" if self.encoded.startswith('PSMODE:CINEMA'): return answer.encoded.startswith('MS') and answer.encoded.endswith('C') elif self.encoded.startswith('PSMODE:MUSIC'): return answer.encoded.startswith('MS') and answer.encoded.endswith('M') else: return Message.answerMatches(self, answer)
def loop(self): while 1: self.buffer += self.irc.recv(4096) temp_buffer = self.buffer.split("\n") self.buffer = temp_buffer.pop() for line in temp_buffer: # First make sure if its a PING request. parts = line.strip().split() if parts[0] == "PING": self.irc.send("PONG %s\r\n" % parts[1]) continue try: message = Message(line) except IndexError: pass # Now move on to the main functionality. responses = [] # Stubbing out functionality for custom functions. Eventually the big block below will be gone. for function in flatten(self.functions): # Making it very verbose just to be safe. response = function(self, message) if not response == "disconnect": responses.append({"function": function, "response": response}) elif response == "disconnect": # If the function returns False, it is telling koomar to kill itself. self.send_message("%s is disconnecting..." % self.nickname) self.disconnect() return # Checks to see if at least one of the parsers responded with either true or a string. def check(r): # The old algorithm, I'm keeping it here just for good times' sake. # (r['response'] == True or (not type(r['response']) == bool and r['response'].isalnum())) if r == True or type(r) == str: return True return False if not [check(r["response"]) for r in responses].__contains__(True): # and... if message.is_command(self.command, sender_exceptions): if message.is_public(): self.send_message("I don't know that command!") else: self.send_private_message("I don't know that command!", message.sender)
def test_message_get_delete(self): new = Message('abc') new.save('123') new = Message('abc') eq_(new.get(delete=False), '123') eq_(new.get(delete=True), '123') eq_(new.get(), None)
def answerMatches(self, answer): """does the answer match this message?""" if self.encoded.startswith('PSMODE:CINEMA'): return answer.encoded.startswith('MS') and answer.encoded.endswith( 'C') elif self.encoded.startswith('PSMODE:MUSIC'): return answer.encoded.startswith('MS') and answer.encoded.endswith( 'M') else: return Message.answerMatches(self, answer)
def run(): saver1 = Saver() path = saver1.get_filename() if path is not None: message1 = Message(path) message1.to_transfer() message1.to_user() print("Project's Path: " + path)
def __runScript(self): io = IO.InputOutput() # pass the script to EDEX runner = self.commands.get('runner') service = config.endpoint.get(runner) # submit the input to the server and obtain result connection = str( os.getenv("DEFAULT_HOST", "localhost") + ":" + os.getenv("DEFAULT_PORT", "9581")) ch = CH.CommHandler(connection, service) ch.process(self.script) # expect message 200, if not print error message and return error code if not ch.isGoodStatus(): util.reportHTTPResponse(ch.formatResponse()) return 1 if 'fullMessage' in self.commands: # Return the full XML message to the appropriate stream io.setStream(sys.stdout) io.writeln(data=ch.getContents()) retVal = 0 else: # Pull the responses element out of the xml msg = MSG.Message() msg.parse(ch.getContents()) # process the response and send results to the appropriate stream error, hdr, resp = self.__getResponse(msg) if error: io.setStream(sys.stderr) retVal = 1 else: io.setStream(sys.stdout) retVal = 0 io.writeln(data=hdr) io.writeln(data=resp) return retVal
def __init__(self, decoded=None, encoded=None): self.raw = None self.repeat = '00' self.button = None self.remote = None Message.__init__(self, decoded, encoded)
def __init__(self, decoded=None, encoded=None): self.setID = '01' Message.__init__(self, decoded, encoded)
def __init__(self, decoded=None, encoded=None): """for the Denon we only use the machine form, its readability is acceptable""" Message.__init__(self, decoded, encoded)
sock_alice = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock_tracker = socket.socket(socket.AF_INET, socket.SOCK_STREAM) IP_Alice = get_IP("alice") IP_Bob = get_IP("bob") IP_Tracker = get_IP("tracker") PORT_Alice = get_PORT("alice") PORT_Bob = get_PORT("bob") PORT_Tracker = get_PORT("tracker") #Connecte au tracker pour avoir file info sock_tracker.connect((IP_Tracker, PORT_Tracker)) #MAUVAIS MESSAGE send_Message(Message(12), sock_tracker) print("Send request: NOTHING") mess_ans = receive_Message(sock_tracker) if message_format(mess_ans) == 3: print("The answer is a FILE_INFO\n") chunks_count, filename_length, filename, chunk_list = DECODE_FILE_INFO( mess_ans) print("\nchunks_count\n", chunks_count) print("\nfilename\n", filename) #ici ce n'est pas la forme "standard" comme avec get_chunks_list(),get_chunks_peers() chunks_list, chunks_peers = make_standard(chunk_list, PORT_Alice, PORT_Bob) else: print("The answer is not a FILE_INFO")
def __init__(self, decoded=None, encoded=None): self.outlet = None Message.__init__(self, decoded, encoded)
def test_message_save(self): new = Message('abc') new.save('123') new = Message('abc') eq_(new.get(), '123')
def answerMatches(self, answer): return Message.answerMatches(self, answer) and self.isQuestion
f"Could not bind socket, waiting {TIMEOUT} seconds before retrying..." ) time.sleep(TIMEOUT) sock.listen() # connection loop while True: logger.debug("socket is listening on 55555") # accept a new client (the node server) client, address = sock.accept() logger.debug(f"client from {address} connected") # message loop while True: # get data from client data = MSG.getMsg(client) if not data: client.close() logger.debug("client disconnected") break # parse data if data["type"] == "colorwheel": # if rainbow runs, we need to terminate it if rainbow and rainbow.is_alive(): logger.debug("stopping rainbow...") rainbow.terminate() # set the LED color = data["args"] LED.setColor(color)