本文整理汇总了Python中blessed.Terminal.blue方法的典型用法代码示例。如果您正苦于以下问题:Python Terminal.blue方法的具体用法?Python Terminal.blue怎么用?Python Terminal.blue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blessed.Terminal
的用法示例。
在下文中一共展示了Terminal.blue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: day
# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import blue [as 别名]
def day(args, *extra, **kwargs):
parser = argparse.ArgumentParser()
parser.add_argument(
'username',
help='The MyFitnessPal username for which to delete a stored password.'
)
parser.add_argument(
'date',
nargs='?',
default=datetime.now().strftime('%Y-%m-%d'),
type=lambda datestr: dateparse(datestr).date(),
help='The date for which to display information.'
)
args = parser.parse_args(extra)
password = get_password_from_keyring_or_interactive(args.username)
client = Client(args.username, password)
day = client.get_date(args.date)
t = Terminal()
print(t.blue(args.date.strftime('%Y-%m-%d')))
for meal in day.meals:
print(t.bold(meal.name.title()))
for entry in meal.entries:
print('* {entry.name}'.format(entry=entry))
print(
t.italic_bright_black(
' {entry.nutrition_information}'.format(entry=entry)
)
)
print('')
print(t.bold("Totals"))
for key, value in day.totals.items():
print(
'{key}: {value}'.format(
key=key.title(),
value=value,
)
)
print("Water: {amount}".format(amount=day.water))
if day.notes:
print(t.italic(day.notes))
示例2: Terminal
# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import blue [as 别名]
return text
try:
from blessed import Terminal
except ImportError, exc:
Terminal = FakeTerminal
TERMINAL = Terminal()
FLAGS = {
'done': TERMINAL.green('done'),
'orphan': TERMINAL.standout(TERMINAL.red('ORPHAN')),
'outdated_fs_version': TERMINAL.standout(
TERMINAL.red('FS-VERSION-OUTDATED')),
'deferrable': TERMINAL.standout(TERMINAL.blue('DEFERRABLE')),
'proposed': TERMINAL.blue('proposed')}
def print_table(data, titles=None, colspace=1):
if titles:
data.insert(0, map(TERMINAL.bright_black, titles))
column_lengths = map(max, zip(*map(
lambda row: map(TERMINAL.length, row), data)))
for row in data:
for col_num, cell in enumerate(row):
print TERMINAL.ljust(cell, column_lengths[col_num] + colspace),
print ''
示例3: __call__
# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import blue [as 别名]
def __call__(self, text):
return text
try:
from blessed import Terminal
except ImportError, exc:
Terminal = FakeTerminal
TERMINAL = Terminal()
FLAGS = {
"done": TERMINAL.green("done"),
"orphan": TERMINAL.standout(TERMINAL.red("ORPHAN")),
"outdated_fs_version": TERMINAL.standout(TERMINAL.red("FS-VERSION-OUTDATED")),
"proposed": TERMINAL.blue("proposed"),
}
def print_table(data, titles=None, colspace=1):
if titles:
data.insert(0, map(TERMINAL.bright_black, titles))
column_lengths = map(max, zip(*map(lambda row: map(TERMINAL.length, row), data)))
for row in data:
for col_num, cell in enumerate(row):
print TERMINAL.ljust(cell, column_lengths[col_num] + colspace),
print ""
def upgrade_id_with_flags(upgrade, omit_flags=()):
示例4: Terminal
# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import blue [as 别名]
try:
from blessed import Terminal
except ImportError, exc:
import sys
print >>sys.stderr, 'WARNING: Terminal colorization disabled' + \
' because of ImportError: {0}'.format(exc)
Terminal = FakeTerminal
TERMINAL = Terminal()
FLAGS = {
'done': TERMINAL.green('done'),
'orphan': TERMINAL.standout(TERMINAL.red('ORPHAN')),
'outdated_fs_version': TERMINAL.standout(
TERMINAL.red('FS-VERSION-OUTDATED')),
'proposed': TERMINAL.blue('proposed')}
def print_table(data, titles=None, colspace=1):
if titles:
data.insert(0, map(TERMINAL.bright_black, titles))
column_lengths = map(max, zip(*map(
lambda row: map(TERMINAL.length, row), data)))
for row in data:
for col_num, cell in enumerate(row):
print TERMINAL.ljust(cell, column_lengths[col_num] + colspace),
print ''
def upgrade_id_with_flags(upgrade, omit_flags=()):
示例5: threaded_sniff
# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import blue [as 别名]
def threaded_sniff():
q = Queue()
sniffer = Thread(target = threaded_sniff_target, args = (q,))
sniffer.daemon = True
sniffer.start()
time.sleep(1)
t = Terminal()
pkt_type = ""
ip_src = None
while True:
try:
pkt = q.get(timeout = 1)
if pkt.haslayer(Ether):
ethsrc = pkt.getlayer(Ether).src
ethdst = pkt.getlayer(Ether).dst
else:
# Skip non-Ethernet packets
pass
if pkt.haslayer(IP):
ipsrc = pkt.getlayer(IP).src
ipdst = pkt.getlayer(IP).dst
ttl = pkt.getlayer(IP).ttl
else:
# Skip non-IP packets
pass
if pkt.haslayer(TCP):
sport = pkt.getlayer(TCP).sport
dport = pkt.getlayer(TCP).dport
pkt_type = "TCP"
elif pkt.haslayer(UDP):
sport = pkt.getlayer(UDP).sport
dport = pkt.getlayer(UDP).dport
pkt_type = "UDP"
if pkt.haslayer(DNS):
pkt_type = "DNS"
if pkt.haslayer(NTP):
pkt_type = "NTP"
if pkt.haslayer(ICMP):
pkt_type = "ICMP"
if pkt.haslayer(http.HTTP):
pkt_type = "HTTP"
if pkt.haslayer(TLS):
pkt_type = "TLS"
if not dbconn.isipaddrindb(ipsrc):
# OS detection based on TTL
ret_ttl = getttl(ttl)
if ret_ttl is None:
if pkt.haslayer(TCP) or pkt.haslayer(UDP):
print "T", t.blue("%s" % datetime.datetime.now().strftime('%H:%M:%S')), t.bold_magenta("{:>4}".format(pkt_type)), "MAC src addr", t.cyan("%s" % ethsrc), "MAC dst addr", t.cyan("%s" % ethdst), "TTL", t.red("{:>7}".format(ttl)), "IP src addr", t.green("{:>15}".format(ipsrc)), "IP dst addr", t.green("{:>15}".format(ipdst)), "src port", t.yellow("{:>5}".format(sport)), "dst port", t.yellow("{:>5}".format(dport))
elif pkt.haslayer(ICMP):
print "T", t.blue("%s" % datetime.datetime.now().strftime('%H:%M:%S')), t.bold_magenta("{:>4}".format(pkt_type)), "MAC src addr", t.cyan("%s" % ethsrc), "MAC dst addr", t.cyan("%s" % ethdst), "TTL", t.red("{:>7}".format(ttl)), "IP src addr", t.green("{:>15}".format(ipsrc)), "IP dst addr", t.green("{:>15}".format(ipdst))
if pkt.getlayer(ICMP).type == 0x08:
print t.move_right, t.move_right, t.move_right, t.move_right, "ICMP Message type", t.green("Echo request"), "Sequence number", t.cyan("%s" % pkt.getlayer(ICMP).seq)
elif pkt.getlayer(ICMP).type == 0x00:
print t.move_right, t.move_right,t.move_right, t.move_right, "ICMP Message type", t.green("Echo response"), "Sequence number", t.cyan("%s" % pkt.getlayer(ICMP).seq)
else:
if pkt.haslayer(TCP) or pkt.haslayer(UDP):
print "T", t.blue("%s" % datetime.datetime.now().strftime('%H:%M:%S')), t.bold_magenta("{:>4}".format(pkt_type)), "MAC src addr", t.cyan("%s" % ethsrc), "MAC dst addr", t.cyan("%s" % ethdst), "OSv", t.red("%s" % ret_ttl), "IP src addr", t.green("{:>15}".format(ipsrc)), "IP dst addr", t.green("{:>15}".format(ipdst)), "src port", t.yellow("{:>5}".format(sport)), "dst port", t.yellow("{:>5}".format(dport))
elif pkt.haslayer(ICMP):
print "T", t.blue("%s" % datetime.datetime.now().strftime('%H:%M:%S')), t.bold_magenta("{:>4}".format(pkt_type)), "MAC src addr", t.cyan("%s" % ethsrc), "MAC dst addr", t.cyan("%s" % ethdst), "OSv", t.red("%s" % ret_ttl), "IP src addr", t.green("{:>15}".format(ipsrc)), "IP dst addr", t.green("{:>15}".format(ipdst))
if pkt.getlayer(ICMP).type == 0x08:
print t.move_right, t.move_right,t.move_right, t.move_right, "ICMP Message type", t.green("Echo request"), "Sequence number", t.cyan("%s" % pkt.getlayer(ICMP).seq)
elif pkt.getlayer(ICMP).type == 0x00:
print t.move_right, t.move_right,t.move_right, t.move_right, "ICMP Message type", t.green("Echo response"), "Sequence number", t.cyan("%s" % pkt.getlayer(ICMP).seq)
# Print out additional information if the packet contains HTTP requests or responses
if pkt.haslayer(DNS):
dns_layer = pkt.getlayer(DNS)
if 'an' in dns_layer.fields:
if dns_layer.fields['an'] is not None:
if dns_layer.fields['an'].fields['type'] == 0x01:
print t.move_right, t.move_right, "DNS response", t.yellow("A"), "record for hostname", t.cyan("%s" % dns_layer.fields['an'].fields['rrname'][:-1]), "has IP address", t.green("%s" % str(dns_layer.fields['an'].fields['rdata']))
elif 'qd' in dns_layer.fields:
if dns_layer.fields['qd'].fields['qtype'] == 0x01:
print t.move_right, t.move_right, "DNS request", t.yellow("A"), "record for hostname", t.cyan("%s" % dns_layer.fields['qd'].fields['qname'][:-1])
# Print out additional information if the packet contains HTTP requests or responses
if pkt.haslayer(http.HTTPRequest):
http_pkt = pkt.getlayer(http.HTTPRequest)
print t.move_right, t.move_right, "HTTP Method", t.yellow("%s" % http_pkt.fields['Method']), "Host", t.cyan("%s" % http_pkt.fields['Host']), "Path", t.green("%s" % http_pkt.fields['Path']),"User-Agent", t.blue("%s" % http_pkt.fields['User-Agent'])
elif pkt.haslayer(http.HTTPResponse):
http_pkt = pkt.getlayer(http.HTTPResponse)
try:
print t.move_right, t.move_right, "HTTP Response from", t.green("%s" % http_pkt.fields['Server']), "Date", t.yellow("%s" % http_pkt.fields['Date'])
except:
pass
# Print out additional information if the packet is part of a TLS connection
if pkt.haslayer(TLS):
try:
tls_packet = pkt.getlayer(TLS)
tls_record = tls_packet.fields['records'][0]
tls_record_type = tls_packet.fields['records'][0].fields['content_type']
if tls_record_type == 0x17:
#.........这里部分代码省略.........