本文整理汇总了Python中logger.Log.log方法的典型用法代码示例。如果您正苦于以下问题:Python Log.log方法的具体用法?Python Log.log怎么用?Python Log.log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logger.Log
的用法示例。
在下文中一共展示了Log.log方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from logger import Log [as 别名]
# 或者: from logger.Log import log [as 别名]
def send(self, data):
header = Header()
header.size = len(data)
header.sequence_number = self.send_sequence
data = header.to_bytes() + data
while True:
#TODO: this could be done more elegantly
if(len(self.workers) == 0):
Log.log("Shutdown multiplexer. No workers found")
self.cleanup()
sys.exit(0)
worker = self.workers[self.send_index][0]
#Increment the sequence number and the send_index to send along another worker
self.send_index = (1 + self.send_index) % len(self.workers)
try:
worker.write(data)
worker.flush()
break
except IOError as e:
if e.errno == 11:
#TODO: whut. Why did I do this?
pass
else:
raise e
self.send_sequence = self.send_sequence + 1
示例2: poll
# 需要导入模块: from logger import Log [as 别名]
# 或者: from logger.Log import log [as 别名]
def poll(self):
self.target_open = True
while(True):
if len(self.workers) == 0 and not self.received_packets:
Log.log("Shutting down. No workers. No received_packets")
self.cleanup()
sys.exit(0)
vals = self.poller.poll()
for fd, event in vals:
if fd == self.target_out.fileno():
if(event & select.POLLIN):
data = self.target_out.read(Multiplexer.MAX_READ_SIZE)
if data:
self.send(data)
elif event & (select.POLLHUP | select.POLLERR):
self.poller.unregister(self.target_out)
self.target_open = False
if not self.received_packets:
Log.log("Shutting down. No received_packets")
self.cleanup()
sys.exit(0)
elif fd == self.target_in.fileno():
self.attempt_send_to_target()
else:
#This is expensive O(n^2) when combined with outer loop, could use a map instead, but with 5 workers
#It's really not worth it
for worker in self.workers:
if worker[1].fileno() == fd:
if event & select.POLLIN:
#header = self.handle_header(worker[1].readline())
header = self.handle_header(worker[1].read(Header.HEADER_SIZE))
if header:
self.receive(worker[1], header)
else:
#TODO: investigate. Is this what I really want to do?
self.poller.unregister(worker[1])
self.workers.remove(worker)
示例3: handle_header
# 需要导入模块: from logger import Log [as 别名]
# 或者: from logger.Log import log [as 别名]
def handle_header(self, line):
if not line:
Log.log("Shutting down. Unknown error")
self.cleanup()
sys.exit(0)
header = Header(line)
if not header.valid:
return None
if header.create:
return None
return header
示例4: attempt_send_to_target
# 需要导入模块: from logger import Log [as 别名]
# 或者: from logger.Log import log [as 别名]
def attempt_send_to_target(self):
while True:
#Check if the next sequence number is in the map, if it is send it and try the next one
#Otherwise we exit
#If the buffer to target_in is full then we need to wait, in which case we
#Add target_in to the polling object until we can send
data = self.received_packets.get(self.receive_sequence)
if data:
try:
self.target_in.write(data)
self.target_in.flush()
del self.received_packets[self.receive_sequence]
except IOError as e:
if e.errno == 11:
self.poller.register(self.target_in, select.POLLOUT)
return
else:
raise e
else:
#TODO: try without the keyerror catch
try:
if not self.target_open:
Log.log("Shutting down. Target not open")
self.cleanup()
sys.exit(0)
self.poller.unregister(self.target_in)
except KeyError:
pass
break
self.receive_sequence += 1
示例5: main
# 需要导入模块: from logger import Log [as 别名]
# 或者: from logger.Log import log [as 别名]
def main():
launcher = Launcher(sys.argv)
obj = launcher.launch()
Log.log(sys.argv)
try:
obj.poll()
except BaseException as e:
#This is here for debugging purposes
if isinstance(e, Exception):
Log.log(e)
my_log = open(Log.log_file, 'a')
traceback.print_exc(file=my_log)
obj.cleanup()
sys.exit(0)
示例6: getuser
# 需要导入模块: from logger import Log [as 别名]
# 或者: from logger.Log import log [as 别名]
print_enabled = False
if getuser() != 'root':
print("Must be run as root...")
exit(1)
config = None
set_args(sys.argv[1:])
if config != None:
load_config(config)
BASE_URL = "http://" + BASE_IP + ":" + BASE_PORT
print BASE_URL
if WIFI_PASS == "":
print("No password was entered, please specify with '-p <password>'")
exit(2)
if BLACK_BOX == "":
print("No UID for the black box was entered...exiting")
exit(2)
log = Log(print_enabled=print_enabled)
log.log("Starting connect.py")
res = connect_to_ap(log)
while not res:
res = connect_to_ap(log)
res = activate(log)
persist_connection(log)
# YOU WILL NEVER GET PASSED THIS
示例7: __init__
# 需要导入模块: from logger import Log [as 别名]
# 或者: from logger.Log import log [as 别名]
class Bot:
"""the bot class"""
def __init__(self, server = 'irc.freenode.net', port=6667):
self.MeetingMode = False
self.sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.connection = self.sock.connect_ex((server, port))
self.input = self.sock.makefile('rb',0)
self.output = self.sock.makefile('wb',0)
if self.connection is 0:
print "Connected"
def identify(self, nick = 'pelly', realname = 'Pelly The Bot'):
"passes nickname and username to the server"
self.nick = nick
#self.output.write('PASS botmaker\r\n')
self.output.write('NICK '+nick+'\r\n')
self.output.write('USER '+nick+' 8 * :'+realname+'\r\n')
def join_channel(self, channel='#aymer'):
"Joins a channel by passing 'JOIN <channel>'"
self.channel = channel
done = True
while done :
text = self.input.readline().strip()
print text
#if text.find('End of /MOTD command') == -1:
if text.find('PRIVMSG') == -1:
done = True
else:
self.output.write('JOIN '+channel+'\r\n')
done = False
print self.input.readline().strip()
self.logmessage = Log(channel)
return 0
def work(self):
"Stay in the channel"
message = self.input.readline().strip()
self.left_nicks = []
while True :
new = True
#print message
if self.MeetingMode : #executes this set only if the meeting mode is on
if message.find('JOIN :'+self.channel) != -1:
new_comer = message.split('!')[0][1:]
#print new_comer
if len(self.left_nicks) is not 0 :
for nick in self.left_nicks:
if nick == new_comer or nick+'_' == new_comer or nick+'__' == new_comer :
print "Not a new guy"
new = False
if new :
self.output.write('PRIVMSG '+self.channel+' :'+new_comer+': Welcome to '+self.channel+', Please Introduce Yourself\r\n')
if message.find('QUIT :') != -1 or message.find('PART') != -1:
self.left_nicks.append(message.split('!')[0][1:])
if message.find('PRIVMSG')!=-1:
self.parseMessage(message)
message = message.split()
if message[0] is 'PING':
self.output.write('PONG '+message[1]+'\n')
message = self.input.readline().strip()
def parseMessage(self,message):
" Using a series of if commands finds and does the corresponding actions for commands "
#msg=message.split(' ')[2]
parser = parse.Parse()
msg = ' '.join(message.strip().split(' ')[3:])[1:]
author = message.split(':')[1].split('!')[0]
if author != 'freenode-connect':
self.logmessage.log("%s : %s " % (author,msg))
print "%s : %s " % (author,msg)
msgl=msg.lower()
if msgl.find('hi '+self.nick) != -1 or msgl.find(self.nick+', hi') != -1 or msgl.find('hello '+self.nick) != -1 or msgl.find(self.nick+': hello') != -1 or msgl.find(self.nick+': hi') != -1 :
res=author+', hi'
self.logmessage.log(self.nick+' : '+res)
self.output.write('PRIVMSG '+self.channel+' : '+res+'\r\n')
elif msgl.find('yo '+self.nick) != -1 or msgl.find(self.nick+': yo') != -1 or msgl.find(self.nick+', yo') != -1 :
res='yo '+author
self.logmessage.log(self.nick+' : '+res)
self.output.write('PRIVMSG '+self.channel+' : '+res+'\r\n')
elif msgl.find('bye') != -1 and msgl.find(self.nick) != -1:
res='see ya '+author
self.logmessage.log(self.nick+' : '+res)
self.output.write('PRIVMSG '+self.channel+' : '+res+'\r\n')
if msg[0] is '~' and msg[1:].strip() != '' :
#parser.Parse(msg[1:])
if msgl[1:] == 'fsf':
news = parser.FSFnewsCommand()
if news is None:
self.output.write('PRIVMSG '+author+' : Sorry unable to retrieve data due to net problems \r\n')
return
self.output.write('PRIVMSG '+author+' :=============Top 5 fsf news=========== \r\n')
for i in range(5):
self.output.write('PRIVMSG '+author+' : '+str(i+1)+'] '+news[i]+'\r\n')
#.........这里部分代码省略.........