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


Python anytree.RenderTree方法代码示例

本文整理汇总了Python中anytree.RenderTree方法的典型用法代码示例。如果您正苦于以下问题:Python anytree.RenderTree方法的具体用法?Python anytree.RenderTree怎么用?Python anytree.RenderTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在anytree的用法示例。


在下文中一共展示了anytree.RenderTree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gen_table

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def gen_table(johnnydist, extra_cols=()):
    extra_cols = OrderedDict.fromkeys(extra_cols)  # de-dupe and preserve ordering
    extra_cols.pop("name", None)  # this is always included anyway, no need to ask for it
    johnnydist.log.debug("generating table")
    for pre, _fill, node in anytree.RenderTree(johnnydist):
        row = OrderedDict()
        name = str(node.req)
        if "specifier" in extra_cols:
            name = wimpy.strip_suffix(name, str(node.specifier))
        row["name"] = pre + name
        for col in extra_cols:
            val = getattr(node, col, "")
            if isinstance(val, list):
                val = ", ".join(val)
            row[col] = val
        yield row 
开发者ID:wimglenn,项目名称:johnnydep,代码行数:18,代码来源:lib.py

示例2: process

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def process(self, data):
        root = anytree.Node('None', decoded = data)
        prev = root

        for (name, curr, branch) in self.generateEncodingTree(data):
            ReEncoder.log('[*] Generator returned: ("{}", "{}", {})'.format(
                name, curr[:20], str(branch)
            ))

            currNode = anytree.Node(name, parent = prev, decoded = curr)
            if branch:
                pass
            else:
                prev = currNode

        for pre, fill, node in anytree.RenderTree(root):
            if node.name != 'None':
                ReEncoder.log("%s%s (%s)" % (pre, node.name, node.decoded[:20].decode('ascii', 'ignore')))

        self.encodings = self.getWinningDecodePath(root)
        ReEncoder.log('[+] Selected encodings: {}'.format(str(self.encodings))) 
开发者ID:StevenDias33,项目名称:Offensive-Security-Certified-Professional,代码行数:23,代码来源:reencode.py

示例3: format_tree

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def format_tree(self, show_key=False, show_status=False):
        log.info(f"Formatting tree...")
        tree_string = ""
        key = {
            "project": (Fore.CYAN + "◉" + Fore.RESET + " = Project".ljust(12)),
            "dataset": (Fore.YELLOW + "◉" + Fore.RESET + " = Dataset".ljust(12)),
            "table": (Fore.RED + "◉" + Fore.RESET + " = Table".ljust(12)),
            "view": (Fore.GREEN + "◉" + Fore.RESET + " = View".ljust(12)),
        }
        if show_key:
            tree_string += "Key:\n{}{}\n{}{}\n\n".format(
                key["project"], key["table"], key["dataset"], key["view"]
            )
        for pre, _, node in RenderTree(self.tree):
            tree_string += "%s%s\n" % (
                pre,
                node.pretty_name(show_authorization_status=show_status),
            )
        return tree_string 
开发者ID:servian,项目名称:bigquery-view-analyzer,代码行数:21,代码来源:analyzer.py

示例4: _render_ascii

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def _render_ascii(self, starting_node, attr):
        """Render an ascii representation of the tree structure.

        Args:
            starting_node: The starting node to render the ascii.

        Returns:
            attr: String of the attribute to render.
        """
        rows = []
        for pre, fill, node in anytree.RenderTree(starting_node,
                                                  style=anytree.AsciiStyle()):
            value = getattr(node, attr, "")
            if isinstance(value, (list, tuple)):
                lines = value
            else:
                lines = str(value).split("\n")
            rows.append(u"%s%s" % (pre,
                                   json.dumps(lines[0], sort_keys=True)))
            for line in lines[1:]:
                rows.append(u"%s%s" % (fill,
                                       json.dumps(line, sort_keys=True)))

        return '\n'.join(rows) 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:26,代码来源:groups_scanner_test.py

示例5: _build_group_tree

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def _build_group_tree(self):
        """Build a tree of all the groups in the organization.

        Returns:
            node: The tree structure of all the groups in the organization.
        """
        root = MemberNode(MY_CUSTOMER, MY_CUSTOMER)
        model_manager = self.service_config.model_manager
        scoped_session, data_access = model_manager.get(self.model_name)
        with scoped_session as session:
            all_groups = data_access.iter_groups(session)

            for group in all_groups:
                group_node = MemberNode(group.name,
                                        group.member_name,
                                        group.type,
                                        'ACTIVE',
                                        root)
                self._get_recursive_members(group_node)

        LOGGER.debug(anytree.RenderTree(
            root, style=anytree.AsciiStyle()).by_attr('member_email'))

        return root 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:26,代码来源:groups_scanner.py

示例6: test_stackoverflow

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def test_stackoverflow():
    """Example from stackoverflow."""
    udo = Node("Udo")
    marc = Node("Marc", parent=udo)
    Node("Lian", parent=marc)
    dan = Node("Dan", parent=udo)
    Node("Jet", parent=dan)
    Node("Jan", parent=dan)
    joe = Node("Joe", parent=dan)

    eq_(str(udo), "Node('/Udo')")
    eq_(str(joe), "Node('/Udo/Dan/Joe')")

    eq_(["%s%s" % (pre, node.name) for pre, fill, node in RenderTree(udo)], [
        u"Udo",
        u"├── Marc",
        u"│   └── Lian",
        u"└── Dan",
        u"    ├── Jet",
        u"    ├── Jan",
        u"    └── Joe",
    ])
    eq_(str(dan.children),
        "(Node('/Udo/Dan/Jet'), Node('/Udo/Dan/Jan'), Node('/Udo/Dan/Joe'))") 
开发者ID:c0fec0de,项目名称:anytree,代码行数:26,代码来源:test_examples.py

示例7: test_render

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def test_render():
    """Render string cast."""
    root = MyNode("root")
    s0 = MyNode("sub0", parent=root)
    MyNode("sub0B", parent=s0)
    MyNode("sub0A", parent=s0)
    MyNode("sub1", parent=root)
    r = at.RenderTree(root)

    expected = u"\n".join([
        u"MyNode('|root')",
        u"├── MyNode('|root|sub0')",
        u"│   ├── MyNode('|root|sub0|sub0B')",
        u"│   └── MyNode('|root|sub0|sub0A')",
        u"└── MyNode('|root|sub1')",
    ])
    if six.PY2:
        eq_(str(r).decode('utf-8'), expected)
    else:
        eq_(str(r), expected) 
开发者ID:c0fec0de,项目名称:anytree,代码行数:22,代码来源:test_node_sep.py

示例8: test_maxlevel

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def test_maxlevel():
    root = anytree.Node("root", lines=["c0fe", "c0de"])
    s0 = anytree.Node("sub0", parent=root, lines=["ha", "ba"])
    s0b = anytree.Node("sub0B", parent=s0, lines=["1", "2", "3"])
    s0a = anytree.Node("sub0A", parent=s0, lines=["a", "b"])
    s1 = anytree.Node("sub1", parent=root, lines=["Z"])

    r = anytree.RenderTree(root, maxlevel=2)
    result = [(pre, node) for pre, _, node in r]
    expected = [
        (u'', root),
        (u'├── ', s0),
        (u'└── ', s1),
    ]
    print(expected)
    print(result)
    eq_(result, expected) 
开发者ID:c0fec0de,项目名称:anytree,代码行数:19,代码来源:test_render.py

示例9: get_all_checker_names_as_tree_string

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def get_all_checker_names_as_tree_string(self):
        return RenderTree(self.get_all_checker_names_as_tree(), style=ContStyle(), childiter=lambda items: sorted(items, key=lambda item: item.name)).by_attr("name") 
开发者ID:koenbuyens,项目名称:securityheaders,代码行数:4,代码来源:securityheader.py

示例10: display_tree

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def display_tree(tree):
    anytree = convert_tree_to_anytree(tree)
    for pre, fill, node in RenderTree(anytree):
        pre = pre.encode(encoding='UTF-8', errors='strict')
        print("%s%s" % (pre, node.name))

# A simple textual output of a tree without the visualization. 
开发者ID:PacktPublishing,项目名称:Data-Science-Algorithms-in-a-Week-Second-Edition,代码行数:9,代码来源:decision_tree.py

示例11: __init__

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def __init__(
        self,
        dpt_ip_address=None,
        dpt_serial_number=None,
        dpt_key=None,
        dpt_client_id=None,
        uid=None,
        gid=None,
    ):
        self.dpt_ip_address = dpt_ip_address
        self.dpt_serial_number = dpt_serial_number
        self.dpt_key = os.path.expanduser(dpt_key)
        self.dpt_client_id = os.path.expanduser(dpt_client_id)
        self.uid = uid
        self.gid = gid
        self.__authenticate__()

        # Create root node
        self.__init_empty_tree()

        # Cache this for the session
        logger.info("Loading initial document list")
        self._load_document_list()
        logger.debug(anytree.RenderTree(self.root))

        self.handle = {}
        self.files = {}
        self.fd = 0 
开发者ID:janten,项目名称:dpt-rp1-py,代码行数:30,代码来源:dptmount.py

示例12: _log_tree

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def _log_tree(self, program_node):
        if self.logger:
            self.logger.debug('program_node tree: "{}"'.format(self.name))
            self.logger.debug(anytree.RenderTree(program_node)) 
开发者ID:OasisLMF,项目名称:OasisLMF,代码行数:6,代码来源:reinsurance_layer.py

示例13: render

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def render(stree):
    return RenderTree(stree, style=ContStyle()).by_attr('__repr_render__') 
开发者ID:devitocodes,项目名称:devito,代码行数:4,代码来源:tree.py

示例14: pretty_print

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def pretty_print(node):
        """漂亮地打印一个节点

        Args:
            node (TYPE): Description
        """
        for pre, _, node in RenderTree(node):
            print('{}{}'.format(pre, node.name)) 
开发者ID:mikusjelly,项目名称:apkutils,代码行数:10,代码来源:__init__.py

示例15: test_dict_importer

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import RenderTree [as 别名]
def test_dict_importer():
    """Dict Importer."""
    importer = DictImporter()
    exporter = DictExporter()
    refdata = {
        'id': 'root', 'children': [
            {'id': 'sub0', 'children': [
                {'id': 'sub0B'},
                {'id': 'sub0A'}
            ]},
            {'id': 'sub1', 'children': [
                {'id': 'sub1A'},
                {'id': 'sub1B'},
                {'id': 'sub1C', 'children': [
                    {'id': 'sub1Ca'}
                ]}
            ]}
        ]}
    data = deepcopy(refdata)
    root = importer.import_(data)
    eq_(data, refdata)
    eq_(exporter.export(root), data)
    r = RenderTree(root)
    expected = u"\n".join([
        u"AnyNode(id='root')",
        u"├── AnyNode(id='sub0')",
        u"│   ├── AnyNode(id='sub0B')",
        u"│   └── AnyNode(id='sub0A')",
        u"└── AnyNode(id='sub1')",
        u"    ├── AnyNode(id='sub1A')",
        u"    ├── AnyNode(id='sub1B')",
        u"    └── AnyNode(id='sub1C')",
        u"        └── AnyNode(id='sub1Ca')",
    ])
    eq_str(str(r), expected) 
开发者ID:c0fec0de,项目名称:anytree,代码行数:37,代码来源:test_dictimporter.py


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