本文整理汇总了Python中pygments.lexers.data.JsonLexer方法的典型用法代码示例。如果您正苦于以下问题:Python data.JsonLexer方法的具体用法?Python data.JsonLexer怎么用?Python data.JsonLexer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.lexers.data
的用法示例。
在下文中一共展示了data.JsonLexer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_cli_output
# 需要导入模块: from pygments.lexers import data [as 别名]
# 或者: from pygments.lexers.data import JsonLexer [as 别名]
def handle_cli_output(self, cli_process: QProcess):
output: QByteArray = cli_process.readAllStandardOutput()
message = output.data().decode('utf-8').strip()
if message.startswith('{') or message.startswith('['):
formatter = HtmlFormatter()
formatter.noclasses = True
formatter.linenos = False
formatter.nobackground = True
message = highlight(message, JsonLexer(), formatter)
self.output_area.insertHtml(message)
else:
self.output_area.append(message)
示例2: __init__
# 需要导入模块: from pygments.lexers import data [as 别名]
# 或者: from pygments.lexers.data import JsonLexer [as 别名]
def __init__(self, writer, is_tty):
self.is_tty = is_tty
self._json_lexer = JsonLexer()
self._formatter = TerminalFormatter()
self.writer = writer
self._output_format = 'tabular'
self._formats = {
'tabular': self.tabular,
'json': self.json,
'csv': self.csv,
'raw': self.raw,
'mixed': self.mixed,
'dynamic': self.dynamic,
'json_row': self.json_row
}
示例3: pretty_print_body
# 需要导入模块: from pygments.lexers import data [as 别名]
# 或者: from pygments.lexers.data import JsonLexer [as 别名]
def pretty_print_body(fmt, body):
try:
bstr = body.decode()
if fmt.lower() == 'json':
d = json.loads(bstr.strip())
s = json.dumps(d, indent=4, sort_keys=True)
print(pygments.highlight(s, JsonLexer(), TerminalFormatter()))
elif fmt.lower() == 'form':
qs = parse_qs(bstr, keep_blank_values=True)
for k, vs in qs.items():
for v in vs:
s = Colors.GREEN
s += '%s: ' % unquote(k)
s += Colors.ENDC
if v == '':
s += Colors.RED
s += 'EMPTY'
s += Colors.ENDC
else:
s += unquote(v)
print(s)
elif fmt.lower() == 'text':
print(bstr)
elif fmt.lower() == 'xml':
import xml.dom.minidom
xml = xml.dom.minidom.parseString(bstr)
print(pygments.highlight(xml.toprettyxml(), XmlLexer(), TerminalFormatter()))
else:
raise CommandError('"%s" is not a valid format' % fmt)
except CommandError as e:
raise e
except Exception as e:
raise CommandError('Body could not be parsed as "{}": {}'.format(fmt, e))
示例4: fill_json
# 需要导入模块: from pygments.lexers import data [as 别名]
# 或者: from pygments.lexers.data import JsonLexer [as 别名]
def fill_json(self):
from .decoder import pp_json
with DisableUpdates(self.json_widg):
self.json_widg.setPlainText("")
if not self.data:
return
try:
j = pp_json(self.data.decode())
except Exception:
return
highlighted = textedit_highlight(j, JsonLexer())
self.json_widg.setHtml(highlighted)
示例5: get_instance_details
# 需要导入模块: from pygments.lexers import data [as 别名]
# 或者: from pygments.lexers.data import JsonLexer [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)