当前位置: 首页>>代码示例>>Python>>正文


Python data.JsonLexer方法代码示例

本文整理汇总了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) 
开发者ID:lightning-power-users,项目名称:node-launcher,代码行数:15,代码来源:console.py

示例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
        } 
开发者ID:crate,项目名称:crash,代码行数:17,代码来源:outputs.py

示例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)) 
开发者ID:roglew,项目名称:pappy-proxy,代码行数:35,代码来源:view.py

示例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) 
开发者ID:roglew,项目名称:guppy-proxy,代码行数:14,代码来源:hexteditor.py

示例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) 
开发者ID:Voulnet,项目名称:barq,代码行数:60,代码来源:barq.py


注:本文中的pygments.lexers.data.JsonLexer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。