Beispiel #1
0
def create_bidtree(text):
    global clipboard, vulnerability, seat
    root = Node('root', 'root', -1)
    root.vul = vulnerability
    root.seat = seat
    lastnode = root

    # breaks when no more CUT in bidtable
    while True:
        cut = re.search(r'^(\s*)#\s*CUT\s+(\S+)\s*\n(.*)#ENDCUT[ ]*\n?',
                         text, flags=re.DOTALL|re.MULTILINE)
        if not cut:
            break
        value = cut.group(3).split('\n')
        for i in range(len(value)):
            value[i] = value[i][len(cut.group(1)):]
        value = '\n'.join(value)
        clipboard[cut.group(2)] = value # group2=key
        text = text[:cut.start()]+text[cut.end():]

    # breaks when no more COPY in bidtable
    while True:
        copy = re.search(r'^(\s*)#\s*COPY\s+(\S+)\s*\n(.*)#ENDCOPY[ ]*\n?',
                         text, flags=re.DOTALL|re.MULTILINE)
        if not copy:
            break
        value = copy.group(3).split('\n')
        for i in range(len(value)):
            value[i] = value[i][len(copy.group(1)):]
        value = '\n'.join(value)
        clipboard[copy.group(2)] = value # group2=key
        text = text[:copy.end(3)]+text[copy.end():]
        text = text[:copy.start()]+text[copy.start(3):]
        
    # breaks when no more PASTE in bidtable
    while True:
        paste = re.search(r'^(\s*)#\s*PASTE\s+(\S+)\s*(.*)\n?', text, flags=re.MULTILINE)
        if not paste:
            break
        indentation = paste.group(1)
        lines = clipboard[paste.group(2)]
        for r in paste.group(3).split():
            target, replacement = r.split('=')
            lines = lines.replace(target, replacement)
        lines = lines.split('\n')
        for l in range(len(lines)):
            lines[l] = indentation + lines[l]
        text = text[:paste.start()] + '\n'.join(lines) + text[paste.end():]
        
    hide = re.search(r'^\s*#\s*HIDE\s*\n', text, flags=re.MULTILINE)
    if hide:
        root.export = False
        text = text[:hide.start()]+text[hide.end():]

    if text.strip() == '':
        return None

    for row in text.split('\n'):
        if row.strip() == '':
            continue # could perhaps be nicer by stripping spaces resulting from copy/paste
        indentation = len(row) - len(row.lstrip())
        row = row.strip()
        bid = row.split(' ')[0]
        desc = ' '.join(row.split(' ')[1:]).strip()
        while indentation < lastnode.indentation:
            lastnode = lastnode.parent
        if indentation > lastnode.indentation:
            lastnode = lastnode.add_child(bid, desc, indentation)
        elif indentation == lastnode.indentation:
            lastnode = lastnode.parent.add_child(bid, desc, indentation)
    return root
Beispiel #2
0
def create_bidtree(text):
    global clipboard, vulnerability, seat
    root = Node('root', 'root', -1)
    root.vul = vulnerability
    root.seat = seat
    lastnode = root

    # breaks when no more CUT in bidtable
    while True:
        cut = re.search(r'^(\s*)#\s*CUT\s+(\S+)\s*\n(.*)#ENDCUT[ ]*\n?',
                        text,
                        flags=re.DOTALL | re.MULTILINE)
        if not cut:
            break
        value = cut.group(3).split('\n')
        for i in range(len(value)):
            value[i] = value[i][len(cut.group(1)):]
        value = '\n'.join(value)
        clipboard[cut.group(2)] = value  # group2=key
        text = text[:cut.start()] + text[cut.end():]

    # breaks when no more COPY in bidtable
    while True:
        copy = re.search(r'^(\s*)#\s*COPY\s+(\S+)\s*\n(.*)#ENDCOPY[ ]*\n?',
                         text,
                         flags=re.DOTALL | re.MULTILINE)
        if not copy:
            break
        value = copy.group(3).split('\n')
        for i in range(len(value)):
            value[i] = value[i][len(copy.group(1)):]
        value = '\n'.join(value)
        clipboard[copy.group(2)] = value  # group2=key
        text = text[:copy.end(3)] + text[copy.end():]
        text = text[:copy.start()] + text[copy.start(3):]

    # breaks when no more PASTE in bidtable
    while True:
        paste = re.search(r'^(\s*)#\s*PASTE\s+(\S+)\s*(.*)\n?',
                          text,
                          flags=re.MULTILINE)
        if not paste:
            break
        indentation = paste.group(1)
        lines = clipboard[paste.group(2)]
        for r in paste.group(3).split():
            target, replacement = r.split('=')
            lines = lines.replace(target, replacement)
        lines = lines.split('\n')
        for l in range(len(lines)):
            lines[l] = indentation + lines[l]
        text = text[:paste.start()] + '\n'.join(lines) + text[paste.end():]

    hide = re.search(r'^\s*#\s*HIDE\s*\n', text, flags=re.MULTILINE)
    if hide:
        root.export = False
        text = text[:hide.start()] + text[hide.end():]

    text = re.sub(r'^\s*#\s*BIDTABLE\s*\n', '', text)

    if text.strip() == '':
        return None

    for row in text.split('\n'):
        original_row = row
        if row.strip() == '':
            continue  # could perhaps be nicer by stripping spaces resulting from copy/paste
        indentation = len(row) - len(row.lstrip())

        # If the indentation is at the same level as the last bids
        # description indentation, the description should just
        # continue but with a line break
        if indentation > 0 and indentation == lastnode.desc_indentation:
            lastnode.desc += '\\n' + row.lstrip()
            continue
        row = row.strip()
        bid = row.split(' ')[0]
        desc = ' '.join(row.split(' ')[1:]).strip()
        desc_indentation = original_row.find(desc)
        # removes equal signs at the beginning of the description
        new_desc = re.sub(r'^=\s*', '', desc)
        desc_indentation += len(desc) - len(new_desc)
        desc = new_desc
        while indentation < lastnode.indentation:
            lastnode = lastnode.parent
        if indentation > lastnode.indentation:
            lastnode = lastnode.add_child(bid, desc, indentation,
                                          desc_indentation)
        elif indentation == lastnode.indentation:
            lastnode = lastnode.parent.add_child(bid, desc, indentation,
                                                 desc_indentation)
    return root
Beispiel #3
0
def create_bidtree(text):
    global clipboard, vulnerability, seat
    root = Node("root", "root", -1)
    root.vul = vulnerability
    root.seat = seat
    lastnode = root

    # breaks when no more CUT in bidtable
    while True:
        cut = re.search(r"^(\s*)#\s*CUT\s+(\S+)\s*\n(.*)#ENDCUT[ ]*\n?", text, flags=re.DOTALL | re.MULTILINE)
        if not cut:
            break
        value = cut.group(3).split("\n")
        for i in range(len(value)):
            value[i] = value[i][len(cut.group(1)) :]
        value = "\n".join(value)
        clipboard[cut.group(2)] = value  # group2=key
        text = text[: cut.start()] + text[cut.end() :]

    # breaks when no more COPY in bidtable
    while True:
        copy = re.search(r"^(\s*)#\s*COPY\s+(\S+)\s*\n(.*)#ENDCOPY[ ]*\n?", text, flags=re.DOTALL | re.MULTILINE)
        if not copy:
            break
        value = copy.group(3).split("\n")
        for i in range(len(value)):
            value[i] = value[i][len(copy.group(1)) :]
        value = "\n".join(value)
        clipboard[copy.group(2)] = value  # group2=key
        text = text[: copy.end(3)] + text[copy.end() :]
        text = text[: copy.start()] + text[copy.start(3) :]

    # breaks when no more PASTE in bidtable
    while True:
        paste = re.search(r"^(\s*)#\s*PASTE\s+(\S+)\s*(.*)\n?", text, flags=re.MULTILINE)
        if not paste:
            break
        indentation = paste.group(1)
        lines = clipboard[paste.group(2)]
        for r in paste.group(3).split():
            target, replacement = r.split("=")
            lines = lines.replace(target, replacement)
        lines = lines.split("\n")
        for l in range(len(lines)):
            lines[l] = indentation + lines[l]
        text = text[: paste.start()] + "\n".join(lines) + text[paste.end() :]

    hide = re.search(r"^\s*#\s*HIDE\s*\n", text, flags=re.MULTILINE)
    if hide:
        root.export = False
        text = text[: hide.start()] + text[hide.end() :]

    text = re.sub(r"^\s*#\s*BIDTABLE\s*\n", "", text)

    if text.strip() == "":
        return None

    for row in text.split("\n"):
        original_row = row
        if row.strip() == "":
            continue  # could perhaps be nicer by stripping spaces resulting from copy/paste
        indentation = len(row) - len(row.lstrip())

        # If the indentation is at the same level as the last bids
        # description indentation, the description should just
        # continue but with a line break
        if indentation > 0 and indentation == lastnode.desc_indentation:
            lastnode.desc += "\\n" + row.lstrip()
            continue
        row = row.strip()
        bid = row.split(" ")[0]
        desc = " ".join(row.split(" ")[1:]).strip()
        desc_indentation = original_row.find(desc)
        # removes equal signs at the beginning of the description
        new_desc = re.sub(r"^=\s*", "", desc)
        desc_indentation += len(desc) - len(new_desc)
        desc = new_desc
        while indentation < lastnode.indentation:
            lastnode = lastnode.parent
        if indentation > lastnode.indentation:
            lastnode = lastnode.add_child(bid, desc, indentation, desc_indentation)
        elif indentation == lastnode.indentation:
            lastnode = lastnode.parent.add_child(bid, desc, indentation, desc_indentation)
    return root