Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time, re, timeit
- def dataReceived(data):
- """Parses the data into a dict named info"""
- blahbuffer = ""
- error = 0
- lines = data.replace("\r", "").split("\n")
- lines[0] = blahbuffer + lines[0]
- blahbuffer = lines[-1]
- for line in lines[:-1] :
- if line != "" :
- try:
- #blah = line.split(" ")
- #if blah == "PING" : self.rawsend("PONG %s\n" % (blah[1]))
- info = {}
- info["raw"] = line
- info["words"] = line[1:].split(" ")
- #if info["words"][1] == "001" :
- #self.rawsend("MODE %s +B\n" % (self.nick))
- #self.pm("NickServ", "IDENTIFY %s" % (self.password))
- #for i in self.channels :
- # self.rawsend("JOIN %s \n" % (i))
- #if self.host in conf.connectcommands :
- # for command in conf.connectcommands[self.host] :
- # exec(command)
- info["whois"] = info["words"][0]
- info["sender"] = info["whois"].split("!")[0]
- except : traceback.print_exc()
- try :
- info["hostname"] = info["whois"].split("@")[1]
- #self.hostnames[info["sender"]] = info["hostname"]
- except : info["hostname"] = "Unknown"
- try : info["mode"] = info["words"][1]
- except : info["mode"] = "Unknown"
- try :
- if info["words"][2] == self.nick :
- info["channel"] = info["sender"]
- else : info["channel"] = info["words"][2].replace(":", "").lower()
- except : info["channel"] = "Unknown"
- try :
- if info["mode"] == "PRIVMSG" or info["mode"] == "TOPIC" :
- if ":" in info["words"][3] : info["message"] = " ".join(info["words"][3:])[1:]
- else : info["message"] = " ".join(info["words"][3:])
- else : info["message"] = "Unknown"
- except : error = 1
- def regexdata(data, regex) :
- error = 0
- blahbuffer = ""
- lines = data.replace("\r", "").split("\n")
- lines[0] = blahbuffer + lines[0]
- blahbuffer = lines[-1]
- for line in lines[:-1] :
- if line != "" :
- x = regex.match(line).groups()
- info = {"raw":line, "line":line[1:], "whois":"%s!%s@%s" % (x[0],x[1],x[2]), "sender":x[0], "ident":x[1], "hostname":x[2], "mode":x[3], "channel":x[4], "message":x[5], "words":line[1:].split(" ")}
- rawin = ':sonicrules1234!~sonicrule@botters/sonicrules1234 PRIVMSG ##BrokenDream :;eval info["raw"]\r\n'
- regex = re.compile("\:(.*)\!(.*)\@(.*) (.*) (.*) [\:]{0,1}(.*)")
- print timeit.Timer('regexdata(rawin, regex)', """rawin = ':sonicrules1234!~sonicrule@botters/sonicrules1234 PRIVMSG ##BrokenDream :;eval info["raw"]\\r\\n'\n""" + 'from __main__ import regexdata\nimport re\nregex = re.compile("\:(.*)\!(.*)\@(.*) (.*) (.*) [\:]{0,1}(.*)")').timeit(100000)
- print timeit.Timer('dataReceived(rawin)',"""rawin = ':sonicrules1234!~sonicrule@botters/sonicrules1234 PRIVMSG ##BrokenDream :;eval info["raw"]\\r\\n'\n""" + 'from __main__ import dataReceived').timeit(100000)
Add Comment
Please, Sign In to add comment