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


Python Tree.append方法代码示例

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


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

示例1: TreeTest

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
class TreeTest(unittest.TestCase):

    def setUp(self):
        self.t = Tree(0)
        self.val = 1
        self.LEFT = 0
    
    def append_test(self):
        self.t.append(self.val)
        self.assertEquals(self.val, self.t.ptr.children[0].data)

    def forward_test(self):
        self.t.append(self.val)
        self.t.forward(self.LEFT)
        self.assertEquals(self.val, self.t.ptr.data)
    
    def back_test(self):
        self.t.append(self.val)
        self.t.forward(self.LEFT)
        self.t.back()
        self.assertEquals(self.t.root, self.t.ptr)

    def reset_test(self):
        self.t.append(self.val)
        self.t.forward(self.LEFT)
        self.t.append(self.val)
        self.t.forward(self.LEFT)
        self.t.reset()
        self.assertEquals(self.t.root, self.t.ptr)
开发者ID:zgmartin,项目名称:near-n,代码行数:31,代码来源:tree_test.py

示例2: filelists_from_spec

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
def filelists_from_spec(spec, specpath):
    res = Tree()
    for pkg in spec.packages:
        name = "%s.install.in" % mappkgname.map_package_name(pkg.header)
        res.append("debian/%s" % name, 
                   files_from_pkg(spec.sourceHeader['name'], pkg, specpath))
    return res
开发者ID:BATYD-Turksat,项目名称:xenserver-core,代码行数:9,代码来源:debianmisc.py

示例3: p_doc

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
def p_doc(p):
    '''doc : sect1s
           | sect2s 
           | sect3s 
           | sect4s 
           | sect5s 
           | contents 
    '''
    doc = Tree('doc')
    for c in p[1]: doc.append(c)
    p[0] = doc
开发者ID:fhopecc,项目名称:stxt,代码行数:13,代码来源:booker.py

示例4: conffiles_from_spec

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
def conffiles_from_spec(spec, specpath):
    # Configuration files, not to be overwritten on upgrade.
    # Files in /etc are automatically marked as config files,
    # so we only need to list files here if they are in a 
    # different place.
    res = Tree()
    pkgname = mappkgname.map_package_name(spec.sourceHeader)
    files = rpmextra.files_from_spec(pkgname, specpath)
    if files.has_key( pkgname + "-%config" ):
        for filename in files[pkgname + "-%config"]:
            res.append('debian/conffiles', "%s\n" % filename)
    return res
开发者ID:BATYD-Turksat,项目名称:xenserver-core,代码行数:14,代码来源:debianmisc.py

示例5: patches_from_spec

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
def patches_from_spec(spec, src_dir):
    res = Tree()
    patches = [(seq, name) for (name, seq, typ) in spec.sources 
               if typ == 2]
    patches = [name for (seq, name) in sorted(patches)]
    for patch in patches:
        with open(os.path.join(src_dir, patch)) as patchfile:
            contents = patchfile.read()
            permissions = os.fstat(patchfile.fileno()).st_mode
        res.append(os.path.join("debian/patches", patch),
                   contents, permissions)
        res.append("debian/patches/series", "%s\n" % patch)
    return res
开发者ID:BATYD-Turksat,项目名称:xenserver-core,代码行数:15,代码来源:debianmisc.py

示例6: p_sect_with_contents_and_quote

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
def p_sect_with_contents_and_quote(p):
    '''sect1 : H1 subdoc contents sect2s
       sect2 : H2 subdoc contents sect3s
       sect3 : H3 subdoc contents sect4s
       sect4 : H4 subdoc contents sect5s
    '''
    quote = Tree('quote')
    for c in p[2]: quote.append(c)
    p[1].append(quote)
    for c in p[3]: p[1].append(c)
    for s in p[4]: p[1].append(s)
    p[1].timestamp = p[2]
    p[0] = p[1]
开发者ID:fhopecc,项目名称:stxt,代码行数:15,代码来源:booker.py

示例7: p_sect_with_quote

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
def p_sect_with_quote(p):
    '''sect1 : H1 subdoc contents
             | H1 subdoc sect2s
       sect2 : H2 subdoc contents
             | H2 subdoc sect3s
       sect3 : H3 subdoc contents
             | H3 subdoc sect4s
       sect4 : H4 subdoc contents
             | H4 subdoc sect5s
       sect5 : H5 subdoc contents
    '''
    quote = Tree('quote')
    for c in p[2]: quote.append(c)
    p[1].append(quote)
    for c in p[3]:
        p[1].append(c)
    p[0] = p[1]
开发者ID:fhopecc,项目名称:stxt,代码行数:19,代码来源:booker.py

示例8: changelog_from_spec

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
def changelog_from_spec(spec, isnative):
    res = Tree()

    hdr = spec.sourceHeader
    log = ""
    for (name, timestamp, text) in zip(hdr['changelogname'], 
                                       hdr['changelogtime'], 
                                       hdr['changelogtext']):

        # A Debian package's version is defined by the version of the
        # first entry in the changelog, so we must get this right.
        # Most spec files have changelog entries starting "First Last
        # <[email protected]> - version" - this seems to be the standard
        # for Red Hat spec files.
        # Some of our changelos only have "First Last <[email protected]>".   
        # For these, we use the version from the spec. 
        match = re.match( "^(.+) - (\S+)$", name )
        if match:
            author = match.group(1)
            version = match.group(2)
            if isnative:
                version = re.sub('-', '.', version)
        else:
            author = name
            sep = '.' if isnative else '-'
            version = "%s%s%s" % (spec.sourceHeader['version'],
                                  sep,
                                  spec.sourceHeader['release'])
        print version

        package_name = mappkgname.map_package(hdr['name'])[0]
        log += "%s (%s) UNRELEASED; urgency=low\n" % (package_name, version)
        log += "\n"

        text = re.sub( "^-", "*", text, flags=re.MULTILINE )
        text = re.sub( "^", "  ", text, flags=re.MULTILINE )
        log += "%s\n" % text
        log += "\n"

        date_string =  time.strftime("%a, %d %b %Y %H:%M:%S %z", 
                                     time.gmtime(int(timestamp)))
        log += " -- %s  %s\n" % (author, date_string)
        log += "\n"

    res.append('debian/changelog', log)
    return res
开发者ID:BobBall,项目名称:buildroot,代码行数:48,代码来源:debianchangelog.py

示例9: testLoop

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
    def testLoop(self):

        # No Loops

        input1 = Tree(children=TreeTest.tree_layout)
        input2 = Tree(children=TreeTest.tree_layout_2)
        input3 = Tree(children=TreeTest.tree_layout_3)

        self.assertFalse(input1.has_loop())
        self.assertFalse(input2.has_loop())
        self.assertFalse(input3.has_loop())

        input1.append(input2)

        self.assertFalse(input1.has_loop())

        # Loops

        input2.append(input1)
        input1.append(input2)

        self.assertTrue(input1.has_loop())

        input4 = Tree(children=TreeTest.tree_layout)
        input5 = Tree(children=TreeTest.tree_layout_2)
        input6 = Tree(children=TreeTest.tree_layout_3)

        input6.append(input4)
        input4.append(input5)
        input5.append(input6)

        self.assertTrue(input4.has_loop())
        self.assertTrue(input5.has_loop())
        self.assertTrue(input6.has_loop())
开发者ID:rcludwick,项目名称:TreePy,代码行数:36,代码来源:test.py

示例10: Node

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
from tree import Tree
from linkedlists import Node
from time import time
import random
head = Node()
cur = head
tree = Tree()
for i in xrange(100):
    node = Node(i)
    cur.next = node
    cur = cur.next
    tree.append(random.randint(0,10000))

cur = head
start = time()
print "start linked list"
while cur:
    print cur
    cur = cur.next
linked_list_time = "linked list total time", time() - start

print "tree start"
start = time()
tree.pretty_print()
print linked_list_time
print "tree end", time() - start
开发者ID:EricSchles,项目名称:web_scraping,代码行数:28,代码来源:comparison.py

示例11: copyright_from_spec

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
def copyright_from_spec(_spec):
    res = Tree()
    res.append("debian/copyright", "FIXME")
    return res
开发者ID:BATYD-Turksat,项目名称:xenserver-core,代码行数:6,代码来源:debianmisc.py

示例12: format_from_spec

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
def format_from_spec(_spec, isnative):
    res = Tree()
    fmt = "native" if isnative else "quilt" 
    res.append("debian/source/format", "3.0 (%s)\n" % fmt)
    return res
开发者ID:BATYD-Turksat,项目名称:xenserver-core,代码行数:7,代码来源:debianmisc.py

示例13: compat_from_spec

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
def compat_from_spec(_spec):
    res = Tree()
    res.append("debian/compat", "8")
    return res
开发者ID:BATYD-Turksat,项目名称:xenserver-core,代码行数:6,代码来源:debianmisc.py

示例14: p_simple_table

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import append [as 别名]
def p_simple_table(p):
    """table : lines COLSEP lines COLSEP"""
    # parse header
    row = None
    for l in p[1]:
        if row:
            vals = parse_row(p[2], l)
            for i in range(0, len(row)):
                row[i] += vals[i]
        else:
            row = parse_row(p[2], l)
    header = Tree("tr", "")
    for v in row:
        th = Tree("th", v)
        if len(v) > 0:
            para = parser_node(p, 1, ntype="para", value=v)
            th.append(para)
        header.append(th)

    table = Tree("table", "")

    table.append(header)
    # parse row
    for l in p[3]:
        r = Tree("tr", "")
        table.append(r)
        for v in parse_row(p[2], l):
            td = Tree("td", v)
            if len(v) > 0:
                para = parser_node(p, 1, ntype="para", value=v)
                td.append(para)
            # if type(v) in [str, unicode]:
            #     para = parser_node(p, 1, ntype='para', value=v)
            # else:
            #    raise 'v is not string, it is %s' % type(v)

            td.append(para)
            r.append(td)
    p[0] = table
开发者ID:fhopecc,项目名称:stxt,代码行数:41,代码来源:tabler.py


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