本文整理汇总了Python中console.Console.write方法的典型用法代码示例。如果您正苦于以下问题:Python Console.write方法的具体用法?Python Console.write怎么用?Python Console.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类console.Console
的用法示例。
在下文中一共展示了Console.write方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import write [as 别名]
def start(self):
Console.write("fireherd starting up", Console.Style.Important)
try:
self._start()
except KeyboardInterrupt as e:
Console.write("Interrupted by user.", Console.Style.Error)
except Exception as e:
msg = e.message if e.message!="" else "Unknown error!"
Console.write(msg, Console.Style.Error)
Console.write(traceback.format_exc(), Console.Style.Error)
示例2: _analyzeFile
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import write [as 别名]
def _analyzeFile(self, filename):
Console.write("Analyzing '{}'".format(filename), Console.Style.Important)
# prepare a packet data source
source = OfflineSource(filename)
# init the PacketProcessor, which will dissect each packet and retrieve
# some information from them.
pproc = PacketProcessor()
pproc.show_packets = Settings.options['debug.show_packets']
# init the TCPManager, which will reconstruct TCP connections from
# previously dissected TCP packets
tcpman = TCPManager()
# this tells the TCPManager which analyzers should create for
# each TCP thread that is opened
tcpman.analyzer_classes = [HTTPAnalyzer]
# init some counters that will be later used for statistics
count = 0
last_count = 0
msg_period = 3.0
start_time = time.time()
# start obtaining and processing network packets
for packet in source:
# dissect this packet, then use this packet
# to reassemble tcp threads
pproc.run(packet)
tcpman.run(packet)
count += 1
# if count > 100000:
# Console.write("Packet limit has been reached")
# break;
# show a message if msg_period has passed so that the user
# does not get bored to death
if Console.timeSinceLast()>msg_period:
speed = (count - last_count)/msg_period
last_count = count
Console.write("Analyzed {} packets at {:.2f} p/sec.".format(count, speed))
# after completion show elapsed time, number of packets and number of threads
stop_time = time.time()
Console.write("Analyzed {} packets in {:.2f} seconds".format(count, stop_time - start_time))
Console.write("Found {} TCP threads".format(tcpman.total_count))
示例3: ConsoleFormatter
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import write [as 别名]
class ConsoleFormatter(object):
def __init__(self, stream, theme, tab=8, showgutter=True):
self._c = Console(stream)
self._theme = theme
self._tabstop = u' ' * tab
self._lineno = 1
self._showgutter = showgutter
self._gutter = (
Color(theme.gutter[u'foreground']),
Color(theme.gutter[u'background']),
Color(theme.gutter[u'divider'])
)
def start_document(self, name):
theme = self._theme.theme_for_scope(u'')
fg = Color(theme[u'foreground'])
bg = Color(theme[u'background'])
self._c.pset(fg=fg, bg=bg).clear_line()
self.gutter()
def end_document(self):
self._c.pop()
self._c.reset().write(u'\n')
def start_scope(self, name, off, line):
theme = self._theme.theme_for_scope(name)
fg = None
if u'foreground' in theme:
fg = Color(theme[u'foreground'])
bg = None
if u'background' in theme:
bg = Color(theme[u'background'])
self._c.pset(fg=fg, bg=bg)
def end_scope(self, off, line):
self._c.pop()
def characters(self, str):
last = 0
str = str.replace(u'\t', self._tabstop)
idx = str.find('\n', last)
while idx != -1:
self._c.write(str[last:idx+1])
self._c.clear_line()
self.gutter()
last = idx+1
idx = str.find(u'\n', last)
self._c.write(str[last:])
def gutter(self):
if self._showgutter == True:
self._c.pset(fg=self._gutter[0], bg=self._gutter[1])
self._c.write(u'%4u' % self._lineno).set(fg=self._gutter[2]).write(u'│')
self._c.pop().write(u' ')
self._lineno += 1
示例4: _start
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import write [as 别名]
def _start(self):
Settings.get_arguments()
Console.show_debug = Settings.options['debug.show_messages']
for filename in Settings.filenames:
self._analyzeFile(filename)
Console.write("'{}' analysis completed".format(filename))
示例5: DebugFormatter
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import write [as 别名]
class DebugFormatter(object):
def __init__(self, stream, tab=8, theme=None):
self._stream = stream
self._c = None
self._tabstop = u' ' * tab
self._content = u''
if theme is not None:
self._c = Console(sys.stdout)
self._theme = theme
self._lineno = 1
self._gutter = (
Color(theme.gutter[u'foreground']),
Color(theme.gutter[u'background']),
Color(theme.gutter[u'divider'])
)
@property
def content(self):
return self._content
def start_document(self, name):
if self._c is not None:
theme = self._theme.theme_for_scope(u'')
fg = Color(theme[u'foreground'])
bg = Color(theme[u'background'])
self._c.pset(fg=fg, bg=bg)
self._c.clear_line()
self.gutter()
self._c.write(u'@%s{' % name)
self._stream.write(u'@%s{' % name)
def end_document(self):
if self._c is not None:
self._c.write(u'}')
self._c.pop()
self._c.reset()
self._c.write(u'\n')
self._stream.write(u'}')
def start_scope(self, name, off, line):
if self._c is not None:
theme = self._theme.theme_for_scope(name)
fg = None
if u'foreground' in theme:
fg = Color(theme[u'foreground'])
bg = None
if u'background' in theme:
bg = Color(theme[u'background'])
self._c.pset(fg=fg, bg=bg)
self._c.write(u'@%s(%u,%u){' % (name, off, line))
self._stream.write(u'@%s(%u,%u){' % (name, off, line))
def end_scope(self, off, line):
if self._c is not None:
self._c.write(u'}(%u,%u)' % (off, line))
self._c.pop()
self._stream.write(u'}(%u,%u)' % (off, line))
def characters(self, str):
self._content += str
last = 0
str = str.replace(u'\t', self._tabstop)
idx = str.find('\n', last)
while idx != -1:
self._stream.write(str[last:idx+1])
if self._c is not None:
self._c.write(str[last:idx+1])
self._c.clear_line()
self.gutter()
last = idx+1
idx = str.find(u'\n', last)
self._stream.write(str[last:])
if self._c is not None:
self._c.write(str[last:])
def gutter(self):
self._c.pset(fg=self._gutter[0], bg=self._gutter[1])
self._c.write(u'%4u' % self._lineno).set(fg=self._gutter[2]).write(u'│')
self._c.pop().write(u' ')
self._lineno += 1
示例6: _set_option
# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import write [as 别名]
def _set_option(self, arg):
assert arg in self._arg_map, "{} is not a recognized option".format(arg)
key, value, detail = self._arg_map[arg]
self.options[key] = value
if detail:
Console.write(detail)