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


Python anytree.AnyNode方法代码示例

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


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

示例1: create_tree

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def create_tree(root_json, root_node):
    con_name = root_json['name']

    if con_name is None:
        con_name = 'container'

    if con_name in ['__i3', 'topdock', 'bottomdock']:
        return None
    else:
        this_node = at.AnyNode(id=con_name,
                               parent=root_node,
                               con_id=root_json['id'],
                               workspace=False,
                               container=False)

    if con_name == 'container':
        this_node.container = True

    for a_node in root_json['nodes']:
        create_tree(a_node, this_node) 
开发者ID:sainathadapa,项目名称:i3-wm-multi-disp-scripts,代码行数:22,代码来源:bring_container_to_current_workspace.py

示例2: __init__

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def __init__(
        self, hierarchy_jsonpath: str, nms_threshold: float = 0.85, max_given_constraints: int = 3
    ):
        def __read_hierarchy(node: anytree.AnyNode, parent: Optional[anytree.AnyNode] = None):
            # Cast an ``anytree.AnyNode`` (after first level of recursion) to dict.
            attributes = dict(node)
            children = attributes.pop("Subcategory", [])

            node = anytree.AnyNode(parent=parent, **attributes)
            for child in children:
                __read_hierarchy(child, parent=node)
            return node

        # Read the object class hierarchy as a tree, to make searching easier.
        self._hierarchy = __read_hierarchy(json.load(open(hierarchy_jsonpath)))

        self._nms_threshold = nms_threshold
        self._max_given_constraints = max_given_constraints 
开发者ID:nocaps-org,项目名称:updown-baseline,代码行数:20,代码来源:constraints.py

示例3: __init__

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def __init__(self, nodecls=AnyNode):
        u"""
        Import Tree from dictionary.

        Every dictionary is converted to an instance of `nodecls`.
        The dictionaries listed in the children attribute are converted
        likewise and added as children.

        Keyword Args:
            nodecls: class used for nodes.

        >>> from anytree.importer import DictImporter
        >>> from anytree import RenderTree
        >>> importer = DictImporter()
        >>> data = {
        ...     'a': 'root',
        ...     'children': [{'a': 'sub0',
        ...                   'children': [{'a': 'sub0A', 'b': 'foo'}, {'a': 'sub0B'}]},
        ...                  {'a': 'sub1'}]}
        >>> root = importer.import_(data)
        >>> print(RenderTree(root))
        AnyNode(a='root')
        ├── AnyNode(a='sub0')
        │   ├── AnyNode(a='sub0A', b='foo')
        │   └── AnyNode(a='sub0B')
        └── AnyNode(a='sub1')
        """
        self.nodecls = nodecls 
开发者ID:c0fec0de,项目名称:anytree,代码行数:30,代码来源:dictimporter.py

示例4: test_dict_exporter

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def test_dict_exporter():
    """Dict Exporter."""
    root = AnyNode(id="root")
    s0 = AnyNode(id="sub0", parent=root)
    s0b = AnyNode(id="sub0B", parent=s0)
    s0a = AnyNode(id="sub0A", parent=s0)
    s1 = AnyNode(id="sub1", parent=root, foo="bar")
    s1a = AnyNode(id="sub1A", parent=s1)
    s1b = AnyNode(id="sub1B", parent=s1)
    s1c = AnyNode(id="sub1C", parent=s1)
    s1ca = AnyNode(id="sub1Ca", parent=s1c)

    exporter = DictExporter()
    eq_(exporter.export(root),
        {'id': 'root', 'children': [
            {'id': 'sub0', 'children': [
                {'id': 'sub0B'},
                {'id': 'sub0A'}
            ]},
            {'id': 'sub1', 'foo': 'bar', 'children': [
                {'id': 'sub1A'},
                {'id': 'sub1B'},
                {'id': 'sub1C', 'children': [
                    {'id': 'sub1Ca'}
                ]}
            ]}
        ]}
        ) 
开发者ID:c0fec0de,项目名称:anytree,代码行数:30,代码来源:test_dictexporter.py

示例5: test_anynode_children_init

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def test_anynode_children_init():
    """Anynode With Children Attribute."""
    root = AnyNode(foo="root", children=[
        AnyNode(foo="a", children=[
            AnyNode(foo="aa")
        ]),
        AnyNode(foo="b")
    ])
    eq_(repr(root.descendants),
        "(AnyNode(foo='a'), AnyNode(foo='aa'), AnyNode(foo='b'))") 
开发者ID:c0fec0de,项目名称:anytree,代码行数:12,代码来源:test_node.py

示例6: test_any_node_parent_error

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def test_any_node_parent_error():
    """Any Node Parent Error."""

    with assert_raises(TreeError, "Parent node 'r' is not of type 'NodeMixin'."):
        AnyNode("r") 
开发者ID:c0fec0de,项目名称:anytree,代码行数:7,代码来源:test_node.py

示例7: test_any_node

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def test_any_node():
    """Any Node."""
    r = AnyNode()
    a = AnyNode()
    b = AnyNode(foo=4)
    eq_(r.parent, None)
    eq_(a.parent, None)
    eq_(b.parent, None)
    a.parent = r
    b.parent = r
    eq_(r.children, (a, b))
    eq_(repr(r), "AnyNode()")
    eq_(repr(a), "AnyNode()")
    eq_(repr(b), "AnyNode(foo=4)") 
开发者ID:c0fec0de,项目名称:anytree,代码行数:16,代码来源:test_node.py

示例8: main

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def main(ioc_file, output_dir):

    with open(ioc_file) as csvfile:
        iocreader = csv.reader(csvfile, delimiter=',')
        for row in iocreader:
            root = AnyNode(id=row[1], type=row[0])

            logger.info('=========Start to explore IOC: %s', root.id)

            ioc_list = build_ioc_relation(root)

            timestamp = datetime.now().strftime('%Y%m%d%H%M')
            query_depth = config.get('general','depth')

            txtfile = output_dir + root.id + '_depth_'+ query_depth + '_'+timestamp + '.txt'
            file = open(txtfile, "w")
            file.write(str(RenderTree(root)))
            file.close()

            logger.info('Export IOCs to TXT file: %s', txtfile)

            jsonfile = output_dir + root.id + '_depth_'+ query_depth + '_'+timestamp + '.json'
            file = open(jsonfile, "w")
            exporter = JsonExporter(indent=2, sort_keys=False)
            exporter.write(root, file)
            file.close()

            logger.info('Export IOCs to JSON file: %s', jsonfile)

            logger.info('=========Done exploration for IOC: %s', root.id)

    return 
开发者ID:lion-gu,项目名称:ioc-explorer,代码行数:34,代码来源:explorer.py

示例9: new_top_node

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def new_top_node(self):
        '''create a new top node'''
        return anytree.AnyNode(name=self.TOPNAME, type=self.TYPE_TOP) 
开发者ID:deadc0de6,项目名称:catcli,代码行数:5,代码来源:noder.py

示例10: update_metanode

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def update_metanode(self, top):
        '''create or update meta node information'''
        meta = self._get_meta_node(top)
        epoch = int(time.time())
        if not meta:
            attr = {}
            attr['created'] = epoch
            attr['created_version'] = VERSION
            meta = anytree.AnyNode(name=self.METANAME, type=self.TYPE_META,
                                   attr=attr)
        meta.attr['access'] = epoch
        meta.attr['access_version'] = VERSION
        return meta 
开发者ID:deadc0de6,项目名称:catcli,代码行数:15,代码来源:noder.py

示例11: storage_node

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def storage_node(self, name, path, parent, attr=None):
        '''create a new node representing a storage'''
        path = os.path.abspath(path)
        free = shutil.disk_usage(path).free
        total = shutil.disk_usage(path).total
        epoch = int(time.time())
        return anytree.AnyNode(name=name, type=self.TYPE_STORAGE, free=free,
                               total=total, parent=parent, attr=attr, ts=epoch) 
开发者ID:deadc0de6,项目名称:catcli,代码行数:10,代码来源:noder.py

示例12: archive_node

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def archive_node(self, name, path, parent, archive):
        '''crete a new node for archive data'''
        return anytree.AnyNode(name=name, type=self.TYPE_ARC, relpath=path,
                               parent=parent, size=0, md5=None,
                               archive=archive) 
开发者ID:deadc0de6,项目名称:catcli,代码行数:7,代码来源:noder.py

示例13: _node

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def _node(self, name, type, relpath, parent,
              size=None, md5=None, maccess=None):
        '''generic node creation'''
        return anytree.AnyNode(name=name, type=type, relpath=relpath,
                               parent=parent, size=size,
                               md5=md5, maccess=maccess)

    ###############################################################
    # printing
    ############################################################### 
开发者ID:deadc0de6,项目名称:catcli,代码行数:12,代码来源:noder.py

示例14: vt_ip_to_file

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def vt_ip_to_file(parent):
    """
    Files downloaded from the IP address

    Output is a list of file nodes with sha256 value

    Example: 192.99.142.235

    https://developers.virustotal.com/v3.0/reference#domains-relationships

    """

    result = []

    if parent.type != 'ip_address':
        return result

    ip_address = parent.id

    headers = {'x-apikey': config.get('VirusTotal','api_key')}
    params = {'limit': int(config.get('VirusTotal', 'limit'))}
    re_url = config.get('VirusTotal', 'ip_downloaded_files').replace('{ip}', ip_address)

    try:
        logger.debug('[Processing] Relationship query - VT: IP to downloaded files - %s', ip_address)
        r = requests.get(re_url, headers=headers, params=params, timeout=5)

    except:
        logger.debug('[Error] Relationship query - VT: IP to downloaded files - %s', ip_address)
        return result

    logger.debug('[Done] Relationship query - VT: IP to downloaded files - %s', ip_address)

    if r.status_code == 200 and len(r.json()['data']) > 0:
        for i in r.json()['data']:

            if 'attributes' in i:
                child_node = AnyNode(id=i['attributes']['sha256'],
                                     type='file',
                                     relation='VT: IP to downloaded file',
                                     parent=parent)

                result.append(child_node)

    return result 
开发者ID:lion-gu,项目名称:ioc-explorer,代码行数:47,代码来源:relationship.py

示例15: vt_domain_to_file

# 需要导入模块: import anytree [as 别名]
# 或者: from anytree import AnyNode [as 别名]
def vt_domain_to_file(parent):
    """
    Files downloaded from the domain

    Output is a list of file nodes with sha256 value

    Example: xnz.freetzi.com

    https://developers.virustotal.com/v3.0/reference#domains-relationships

    """

    result = []

    if parent.type != 'domain':
        return result

    domain = parent.id

    headers = {'x-apikey': config.get('VirusTotal','api_key')}
    params = {'limit': int(config.get('VirusTotal', 'limit'))}
    re_url = config.get('VirusTotal', 'domain_downloaded_files').replace('{domain}', domain)

    try:
        logger.debug('[Processing] Relationship query - VT: domain to downloaded files - %s', domain)
        r = requests.get(re_url, headers=headers, params=params, timeout=5)

    except:
        logger.debug('[Error] Relationship query - VT: domain to downloaded files - %s', domain)
        return result

    logger.debug('[Done] Relationship query - VT: domain to downloaded files - %s', domain)

    if r.status_code == 200 and len(r.json()['data']) > 0:
        for i in r.json()['data']:

            if 'attributes' in i:
                child_node = AnyNode(id=i['attributes']['sha256'],
                                     type='file',
                                     relation='VT: domain to downloaded file',
                                     parent=parent)

                result.append(child_node)

    return result 
开发者ID:lion-gu,项目名称:ioc-explorer,代码行数:47,代码来源:relationship.py


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