本文整理汇总了Python中handler.Handler类的典型用法代码示例。如果您正苦于以下问题:Python Handler类的具体用法?Python Handler怎么用?Python Handler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Handler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
ops = ['list', 'info', 'create', 'get', 'update', 'create']
def msg(name=None):
return 'help message'
parser = argparse.ArgumentParser(usage=msg())
parser.add_argument('command', type=str, help='lots of help')
parser.add_argument('-f', '--file-name', type=str, help='gist file name', default=None)
parser.add_argument('-d', '--description', type=str, help='description of the gist', default=None)
parser.add_argument('-u', '--user', help='user help', default=None)
args = parser.parse_args()
try:
args.command = args.command.lower()
ops.index(args.command)
except:
didyoumean = difflib.get_close_matches(args.command, ops, 1)
if didyoumean:
print 'Did you mean: ' + didyoumean.pop() + '?'
sys.exit()
h = Handler()
print args
h.handle(args)
示例2: __init__
def __init__(self, dest=[]):
Handler.__init__(self, dest=dest)
self.last_stamp = 0.0
self.parsers = {}
self.available_parsers = { "stdtime": self._parse_std_time,
"spec1": self._parse_spec1_time,
"vsftpd": self._parse_vsftpd_time }
示例3: Daemon
class Daemon(object):
def __init__(self, debug=False):
self.input = []
self.running = False
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.log = logger.Logger('server', debug=debug)
self.handler = Handler(self)
self._notify = pynotify.Notification('', '')
self._state = 'running'
def connect(self, arg=None):
try:
self.log.info('try connect server to port %s', cst.PORT)
self.socket.bind((socket.gethostname(), cst.PORT))
self.log.info('server started')
self.socket.listen(3)
self.running = True
self.input = [self.socket]
self.handler.start()
th = threading.Thread(target=self.start)
th.start()
self.notify('server started')
return ''
except socket.error, msg:
self.log.warning('connection failed: %s', str(msg))
return msg
示例4: main
def main():
args_handler = Handler()
ip = args_handler.parsing_ip()
tgt.send('1.1.1.1')
scan = Scanner(tgt)
scan.scan_ports()
示例5: read
def read(self):
line = self.file.readline()
while line:
self.count += 1
Handler.push(self, {'type': 'line',
'raw': line.strip(),
'source': self.name })
line = self.file.readline()
reactor.callLater(1, self.read)
示例6: __init__
def __init__(self, config):
"""
Create a new instance of the ArchiveHandler class
"""
# Initialize Handler
Handler.__init__(self, config)
# Create Archive Logger
self.archive = logging.getLogger('autmon')
示例7: push
def push(self, data):
if (data.has_key('timestamp')):
print("%s - %s : %s" % (data['timestamp'],
data['source'],
data['raw']))
else:
print("unknown - %s : %s" % (data['source'],
data['raw']))
Handler.push(self, data)
示例8: __init__
def __init__(self, source_name, filename, dest=[]):
Handler.__init__(self, dest=dest)
self.info("Initializing filereader at %s" % (filename))
self.name = source_name
self.count = 0
self.last_report = time.time()
self.file = open(filename)
self.read()
self.report()
示例9: push
def push(self, data):
match = data['raw'].find("ERROR")>=0
if not self.match and match:
self.info("Detected ERROR")
data['type'] = 'event'
data['raw'] = "@type:\"line\" AND @timestamp:[\"%s\" *] - %s" % (
data['timestamp'], data['raw'])
Handler.push(self, data)
self.match = match
示例10: run
def run(self):
while True:
try:
conn, addr = self.ssock.accept()
self.logger.debug("Client {} connected".format(utils.addr_to_ident(addr)))
hdl = Handler(conn, addr)
hdl.start()
except KeyboardInterrupt:
self.logger.critical("Interrupted by user. Exiting.")
self.ssock.shutdown(socket.SHUT_RDWR)
self.ssock.close()
sys.exit(0)
示例11: __init__
def __init__(self, source_name, path, dest=[]):
Handler.__init__(self, dest=dest)
self.childrens = []
self.name = source_name
for f in os.listdir(path):
if os.path.isfile("%s/%s" % (path, f)):
self.childrens.append(
FileReader(f, "%s/%s" % (path, f), dest = dest))
else:
self.childrens.append(
DirReader(f, "%s/%s" % (path, f), dest))
示例12: __init__
def __init__(self, filter, startpage, maxpages):
self.filter = filter
self.startpage = startpage
self.maxpages = maxpages
filter = Filter(self.filter, self.startpage, self.maxpages)
self.search_url = filter.create_filter_url(self.startpage)
handler = Handler(self.search_url)
self.search_results = handler.init()
if self.search_results["pages"] < startpage:
raise Exception("Error: startpage exceeds available pages [pages=" + str(self.search_results["pages"]) + "]")
if self.search_results["pages"] < startpage + maxpages:
self.maxpages = self.search_results["pages"]
示例13: __init__
def __init__(self):
'''Init game.'''
Handler.__init__(self)
self.turns = 0
'''Holds the number of turns that have passed. Ticks up every time
Game.input is called.'''
self.actor = None
'''Default actor to pass input to.'''
if self.script != None:
s = self.script.read()
self.script.close()
self.script = s
self.scoreList = {}
示例14: push
def push(self, data):
self.debug("Parsing time in data %s" % (data))
try:
parser = self.parsers.get(data['source'])
if not parser:
parser = self.parsers[data['source']] = self._autodetect(
data['raw'])
stamp = parser(data['raw'])
stamp = self._format_time(self._adjust_time(stamp))
data['timestamp'] = stamp
except Exception as e:
self.warning("Failed to parse time in %s" % (data['raw']))
Handler.push(self, data)
示例15: handle
def handle(self):
#得到log
logging.config.fileConfig("log.conf")
log=logging.getLogger("simpleExample")
#初始化处理
cf=ConfigParser.ConfigParser()
cf.read('xb.ini')
root_data=cf.get("path","data_path")
addr=int(cf.get("host","addr"))
log.info("ROOT_DATA is %s"%root_data)
h=Handler(self.request,self.client_address,threading.current_thread(),log,root_data,addr)
log.info("{} New Client!".format(self.client_address))
#主处理程序
h.handle()