本文整理汇总了Python中pygments.formatters.terminal.TerminalFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python terminal.TerminalFormatter方法的具体用法?Python terminal.TerminalFormatter怎么用?Python terminal.TerminalFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.formatters.terminal
的用法示例。
在下文中一共展示了terminal.TerminalFormatter方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: androaxml_main
# 需要导入模块: from pygments.formatters import terminal [as 别名]
# 或者: from pygments.formatters.terminal import TerminalFormatter [as 别名]
def androaxml_main(inp, outp=None, resource=None):
ret_type = androconf.is_android(inp)
if ret_type == "APK":
a = apk.APK(inp)
if resource:
if resource not in a.files:
print("The APK does not contain a file called '{}'".format(resource), file=sys.stderr)
sys.exit(1)
axml = AXMLPrinter(a.get_file(resource)).get_xml_obj()
else:
axml = a.get_android_manifest_xml()
elif ".xml" in inp:
axml = AXMLPrinter(read(inp)).get_xml_obj()
else:
print("Unknown file type")
sys.exit(1)
buff = etree.tostring(axml, pretty_print=True, encoding="utf-8")
if outp:
with open(outp, "wb") as fd:
fd.write(buff)
else:
sys.stdout.write(highlight(buff.decode("UTF-8"), get_lexer_by_name("xml"), TerminalFormatter()))
示例2: __init__
# 需要导入模块: from pygments.formatters import terminal [as 别名]
# 或者: from pygments.formatters.terminal import TerminalFormatter [as 别名]
def __init__(self, context, listener=None, style=None):
super(ExecutionVisitor, self).__init__()
self.context = context
self.context_override = Context(context.url)
self.method = None
self.tool = None
self._output = Printer()
# If there's a pipe, as in "httpie post | sed s/POST/GET/", this
# variable points to the "sed" Popen object. The variable is necessary
# because the we need to redirect Popen.stdout to Printer, which does
# output pagination.
self.pipe_proc = None
self.listener = listener or DummyExecutionListener()
# Last response object returned by HTTPie
self.last_response = None
# Pygments formatter, used to render output with colors in some cases
if style:
self.formatter = TerminalFormatter(style=style)
else:
self.formatter = None
示例3: androarsc_main
# 需要导入模块: from pygments.formatters import terminal [as 别名]
# 或者: from pygments.formatters.terminal import TerminalFormatter [as 别名]
def androarsc_main(arscobj, outp=None, package=None, typ=None, locale=None):
package = package or arscobj.get_packages_names()[0]
ttype = typ or "public"
locale = locale or '\x00\x00'
# TODO: be able to dump all locales of a specific type
# TODO: be able to recreate the structure of files when developing, eg a
# res folder with all the XML files
if not hasattr(arscobj, "get_{}_resources".format(ttype)):
print("No decoder found for type: '{}'! Please open a bug report."
.format(ttype),
file=sys.stderr)
sys.exit(1)
x = getattr(arscobj, "get_" + ttype + "_resources")(package, locale)
buff = etree.tostring(etree.fromstring(x),
pretty_print=True,
encoding="UTF-8")
if outp:
with open(outp, "wb") as fd:
fd.write(buff)
else:
sys.stdout.write(highlight(buff.decode("UTF-8"), get_lexer_by_name("xml"), TerminalFormatter()))
示例4: _pretty_format_sql
# 需要导入模块: from pygments.formatters import terminal [as 别名]
# 或者: from pygments.formatters.terminal import TerminalFormatter [as 别名]
def _pretty_format_sql(text: str):
import pygments
from pygments.formatters.terminal import TerminalFormatter
from pygments.lexers.sql import SqlLexer
text = pygments.highlight(
code=text, formatter=TerminalFormatter(), lexer=SqlLexer()
).rstrip()
return text
示例5: show_config
# 需要导入模块: from pygments.formatters import terminal [as 别名]
# 或者: from pygments.formatters.terminal import TerminalFormatter [as 别名]
def show_config(args):
"""Show current application configuration"""
with io.StringIO() as output:
conf.write(output)
code = output.getvalue()
if should_use_colors(args):
code = pygments.highlight(
code=code, formatter=TerminalFormatter(), lexer=IniLexer()
)
print(code)
示例6: _highlight
# 需要导入模块: from pygments.formatters import terminal [as 别名]
# 或者: from pygments.formatters.terminal import TerminalFormatter [as 别名]
def _highlight(self, source: str) -> str:
"""Highlight the given source code if we have markup support."""
if not self.hasmarkup or not self.code_highlight:
return source
try:
from pygments.formatters.terminal import TerminalFormatter
from pygments.lexers.python import PythonLexer
from pygments import highlight
except ImportError:
return source
else:
highlighted = highlight(
source, PythonLexer(), TerminalFormatter(bg="dark")
) # type: str
return highlighted
示例7: highlight_xml
# 需要导入模块: from pygments.formatters import terminal [as 别名]
# 或者: from pygments.formatters.terminal import TerminalFormatter [as 别名]
def highlight_xml(xml_str):
# Highlights a string containing XML, using terminal color codes
return highlight(xml_str, XmlLexer(), TerminalFormatter())
示例8: output_why_test_failed
# 需要导入模块: from pygments.formatters import terminal [as 别名]
# 或者: from pygments.formatters.terminal import TerminalFormatter [as 别名]
def output_why_test_failed(self, test_result: TestResult):
err = test_result.error
if isinstance(err, TestFailure):
src_lines, line_num = inspect.getsourcelines(test_result.test.fn)
# TODO: Only include lines up to where the failure occurs
if src_lines[-1].strip() == "":
src_lines = src_lines[:-1]
gutter_width = len(str(len(src_lines) + line_num))
def gutter(i):
offset_line_num = i + line_num
rv = f"{str(offset_line_num):>{gutter_width}}"
if offset_line_num == err.error_line:
return colored(f"{rv} ! ", color="red")
else:
return lightblack(f"{rv} | ")
if err.operator in Comparison:
src = "".join(src_lines)
src = highlight(src, PythonLexer(), TerminalFormatter())
src = f"".join(
[gutter(i) + l for i, l in enumerate(src.splitlines(keepends=True))]
)
print(indent(src, DOUBLE_INDENT))
if err.operator == Comparison.Equals:
self.print_failure_equals(err)
else:
self.print_traceback(err)
print(Style.RESET_ALL)
示例9: pretty
# 需要导入模块: from pygments.formatters import terminal [as 别名]
# 或者: from pygments.formatters.terminal import TerminalFormatter [as 别名]
def pretty(self) -> str:
lines = list(self.lines)
lines[0] += f" {self.target}" # include target name in comments
return pygments.highlight("\n".join(lines), DiffLexer(), TerminalFormatter())
示例10: get_instance_details
# 需要导入模块: from pygments.formatters import terminal [as 别名]
# 或者: from pygments.formatters.terminal import TerminalFormatter [as 别名]
def get_instance_details(caller):
"""
Return detailed info in JSON format about a particular instance.
:param caller: The menu that called this function.
:return: None
"""
global my_aws_creds
global ec2instances
global INSTANCESIDCOMMANDS
INSTANCESIDCOMMANDS = []
mysession = ''
try:
mysession = my_aws_creds['session']
possible_regions = my_aws_creds['possible_regions']
except:
puts(color("[!] Error! No EC2 credentials set. Call setprofile first!"))
go_to_menu(caller)
try:
puts(color(
'[*] Your collected EC2 instances, if you want an updated list, invoke attacksurface:'))
instances_table = PrettyTable()
possible_regions = []
instances_table.field_names = ['Instance ID', 'Platform', 'Region', 'State', 'Public IP', 'Public DNS name',
'Profile']
if len(ec2instances['instances']) == 0:
puts(color(
'[!] You have no stored EC2 instances. Run the command attacksurface to discover them'))
go_to_menu(caller)
for ins in ec2instances['instances']:
INSTANCESIDCOMMANDS.append(ins['id'])
instances_table.add_row([ins.get('id'), ins.get('platform'), ins.get('region'), ins.get('state'),
ins.get('public_ip_address'),
ins.get('public_dns_name'), ins.get('iam_profile', '')])
except Exception as e:
print(e)
puts(color(
'[!] You have no stored EC2 instances. Run the command attacksurface to discover them'))
go_to_menu(caller)
print(instances_table)
puts(color('[*] Target Options:'))
# paster
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
readline.set_completer(instanceidcomplete)
target = prompt.query('Type/Paste your target EC2 ID:')
region = ''
for ins in ec2instances['instances']:
if ins['id'] == target:
region = ins['region']
break
ec2client = mysession.client('ec2', region_name=region)
result = ec2client.describe_instances(InstanceIds=[target, ])
jsonstr = json.dumps(
result['Reservations'][0]['Instances'][0], indent=4, sort_keys=True, default=str)
print(highlight(jsonstr, JsonLexer(), TerminalFormatter()))
go_to_menu(caller)